* Rewrote headers as needed.

* Cleaned up our own headers.
* Moved translator errors into Errors.h.
* Removed extra TranslationKit.h.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32755 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-08-27 14:20:56 +00:00
parent 5a73760650
commit d7571ebcf7
8 changed files with 171 additions and 252 deletions
+7 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2007, Haiku, Inc. All Rights Reserved.
* Copyright 2007-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _ERRORS_H
@@ -43,6 +43,7 @@
#define B_WOULD_BLOCK (B_GENERAL_ERROR_BASE + 11)
#define B_CANCELED (B_GENERAL_ERROR_BASE + 12)
#define B_NO_INIT (B_GENERAL_ERROR_BASE + 13)
#define B_NOT_INITIALIZED (B_GENERAL_ERROR_BASE + 13)
#define B_BUSY (B_GENERAL_ERROR_BASE + 14)
#define B_NOT_ALLOWED (B_GENERAL_ERROR_BASE + 15)
#define B_BAD_DATA (B_GENERAL_ERROR_BASE + 16)
@@ -282,6 +283,11 @@
#define B_DEV_MULTIPLE_ERRORS (B_DEVICE_ERROR_BASE + 29)
#define B_DEV_TOO_LATE (B_DEVICE_ERROR_BASE + 30)
/* Translation Kit Errors */
#define B_TRANSLATION_BASE_ERROR (B_TRANSLATION_ERROR_BASE + 0)
#define B_NO_TRANSLATOR (B_TRANSLATION_ERROR_BASE + 1)
#define B_ILLEGAL_DATA (B_TRANSLATION_ERROR_BASE + 2)
#define B_TO_POSITIVE_ERROR(error) _to_positive_error(error)
#define B_TO_NEGATIVE_ERROR(error) _to_negative_error(error)
+34 -52
View File
@@ -1,66 +1,48 @@
/********************************************************************************
/
/ File: TranslationDefs.h
/
/ Description: Miscellaneous basic definitions for the Translation Kit
/
/ Copyright 1998, Be Incorporated, All Rights Reserved.
/ Copyright 1995-1997, Jon Watte
/
/ 2002 - translation_data struct added by Michael Wilber, OBOS TransKit Team
********************************************************************************/
#if !defined(_TRANSLATION_DEFS_H)
/*
* Copyright 2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _TRANSLATION_DEFS_H
#define _TRANSLATION_DEFS_H
#include <BeBuild.h>
#include <SupportDefs.h>
#include <TranslationErrors.h>
typedef unsigned long translator_id;
/* when you export this struct, end with an empty */
/* record that has 0 for "type" */
/* These are defines, because they reflect the state at which the app was compiled */
#define B_TRANSLATION_CURRENT_VERSION B_BEOS_VERSION
#define B_TRANSLATION_MIN_VERSION 161
extern const char * B_TRANSLATOR_MIME_TYPE;
struct translation_format {
uint32 type; /* B_ASCII_TYPE, ...*/
uint32 group; /* B_TRANSLATOR_BITMAP, B_TRANSLATOR_TEXT, ...*/
float quality; /* ability of the format to retain the data of its group (0.0-1.0) */
float capability; /* ability of the translator to decode the format (0.0-1.0) */
char MIME[251]; /* MIME string*/
char name[251]; /* only descriptive */
};
/* This struct is different from the format struct for a reason: */
/* to separate the notion of formats from the notion of translations */
struct translator_info { /* Info about a specific translation*/
uint32 type; /* B_ASCII_TYPE, ...*/
translator_id translator; /* Filled in by BTranslationRoster*/
uint32 group; /* B_TRANSLATOR_BITMAP, B_TRANSLATOR_TEXT, ...*/
float quality; /* ability of the format to retain the data of its group (0.0-1.0) */
float capability; /* ability of the translator to decode the format (0.0-1.0) */
char name[251];
char MIME[251];
};
// BEGIN: Haiku R1 Extensions
#define B_TRANSLATION_MAKE_VERSION(major,minor,revision) ((major << 8) | ((minor << 4) & 0xf0) | (revision & 0x0f))
#define B_TRANSLATION_MAKE_VERSION(major, minor, revision) \
((major << 8) | ((minor << 4) & 0xf0) | (revision & 0x0f))
#define B_TRANSLATION_MAJOR_VERSION(v) (v >> 8)
#define B_TRANSLATION_MINOR_VERSION(v) ((v >> 4) & 0xf)
#define B_TRANSLATION_REVISION_VERSION(v) (v & 0xf)
// END: Haiku R1 Extensions
#endif /* _TRANSLATION_DEFS_H */
extern const char* B_TRANSLATOR_MIME_TYPE;
typedef unsigned long translator_id;
struct translation_format {
uint32 type; // type_code
uint32 group;
float quality; // between 0.0 and 1.0
float capability; // between 0.0 and 1.0
char MIME[251];
char name[251];
};
struct translator_info {
uint32 type;
translator_id translator;
uint32 group;
float quality;
float capability;
char name[251];
char MIME[251];
};
#endif // _TRANSLATION_DEFS_H
+7 -22
View File
@@ -1,27 +1,12 @@
/********************************************************************************
/
/ File: TranslationErrors.h
/
/ Description: Error codes for the Translation Kit
/
/ Copyright 1998, Be Incorporated, All Rights Reserved.
/ Copyright 1995-1997, Jon Watte
/
********************************************************************************/
#if !defined(_TRANSLATION_ERRORS_H)
/*
* Copyright 2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _TRANSLATION_ERRORS_H
#define _TRANSLATION_ERRORS_H
#include <Errors.h>
enum B_TRANSLATION_ERROR {
B_TRANSLATION_BASE_ERROR = B_TRANSLATION_ERROR_BASE,
B_NO_TRANSLATOR = B_TRANSLATION_BASE_ERROR, /* no translator exists for data */
B_ILLEGAL_DATA, /* data is not what it said it was */
/* aliases */
B_NOT_INITIALIZED = B_NO_INIT
};
#endif /* _TRANSLATION_ERRORS_H */
#endif // _TRANSLATION_ERRORS_H
-18
View File
@@ -1,18 +0,0 @@
/***************************************************************
/
/ File: TranslationKit.h
/
/ Copyright 1998, Be Incorporated.
/
***************************************************************/
#include <BitmapStream.h>
#include <TranslationDefs.h>
#include <TranslationErrors.h>
#include <TranslationUtils.h>
#include <TranslatorFormats.h>
#include <TranslatorRoster.h>
#include <Translator.h>
/* we do not include TranslatorAddOn.h because it's only used when building an add-on */
+41 -29
View File
@@ -1,13 +1,14 @@
/*
* Copyright 2002-2007, Haiku, Inc. All Rights Reserved.
* Copyright 2002-2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _TRANSLATION_UTILS_H
#define _TRANSLATION_UTILS_H
#include <TranslationDefs.h>
#include <SupportDefs.h>
#include <TranslationDefs.h>
class BBitmap;
class BFile;
@@ -20,15 +21,20 @@ struct entry_ref;
class BTranslationUtils {
private:
BTranslationUtils();
BTranslationUtils(
const BTranslationUtils& other);
~BTranslationUtils();
BTranslationUtils(const BTranslationUtils &);
BTranslationUtils & operator=(const BTranslationUtils &);
BTranslationUtils& operator=(const BTranslationUtils& other);
public:
// bitmap functions
static BBitmap *GetBitmap(const char *name, BTranslatorRoster *roster = NULL);
enum {
B_TRANSLATION_MENU = 'BTMN'
};
static BBitmap* GetBitmap(const char* name,
BTranslatorRoster* roster = NULL);
static BBitmap* GetBitmap(uint32 type, int32 id,
BTranslatorRoster* roster = NULL);
static BBitmap* GetBitmap(uint32 type, const char* name,
@@ -40,32 +46,38 @@ class BTranslationUtils {
static BBitmap* GetBitmap(BPositionIO* stream,
BTranslatorRoster* roster = NULL);
// text functions
static status_t GetStyledText(BPositionIO* fromStream, BTextView* intoView,
BTranslatorRoster *roster = NULL);
static status_t GetStyledText(BPositionIO* fromStream, BTextView* intoView,
const char* encoding, BTranslatorRoster* roster = NULL);
static status_t PutStyledText(BTextView *fromView, BPositionIO *intoStream,
BTranslatorRoster *roster = NULL);
static status_t WriteStyledEditFile(BTextView *fromView, BFile *intoFile);
static status_t WriteStyledEditFile(BTextView *fromView, BFile *intoFile,
const char* encoding);
static void SetBitmapColorSpace(color_space space);
static color_space BitmapColorSpace();
// misc. functions
static BMessage *GetDefaultSettings(translator_id forTranslator,
static status_t GetStyledText(BPositionIO* fromStream,
BTextView* intoView,
BTranslatorRoster* roster = NULL);
static BMessage *GetDefaultSettings(const char *translatorName,
int32 translatorVersion);
static status_t GetStyledText(BPositionIO* fromStream,
BTextView* intoView, const char* encoding,
BTranslatorRoster* roster = NULL);
static status_t PutStyledText(BTextView* fromView,
BPositionIO* intoStream,
BTranslatorRoster* roster = NULL);
static status_t WriteStyledEditFile(BTextView* fromView,
BFile* intoFile);
static status_t WriteStyledEditFile(BTextView* fromView,
BFile* intoFile, const char* encoding);
enum {
B_TRANSLATION_MENU = 'BTMN'
};
static status_t AddTranslationItems(BMenu *intoMenu, uint32 fromType,
const BMessage *model = NULL, // default B_TRANSLATION_MENU
const char *translatorIdName = NULL, // default "be:translator"
const char *translatorTypeName = NULL, // default "be:type"
static BMessage* GetDefaultSettings(translator_id translator,
BTranslatorRoster* roster = NULL);
static BMessage* GetDefaultSettings(const char* name,
int32 version);
static status_t AddTranslationItems(BMenu* intoMenu,
uint32 fromType,
const BMessage* model = NULL,
const char* idName = NULL,
const char* typeName = NULL,
BTranslatorRoster* roster = NULL);
private:
static color_space sBitmapSpace;
};
#endif /* _TRANSLATION_UTILS_H */
#endif // _TRANSLATION_UTILS_H
+18 -16
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007, Haiku, Inc. All Rights Reserved.
* Copyright 2002-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _TRANSLATOR_H
@@ -19,25 +19,25 @@ class BTranslator : public BArchivable {
BTranslator* Release();
int32 ReferenceCount();
// returns the refcount, THIS IS NOT THREAD SAFE, ITS ONLY FOR "FUN"
virtual const char* TranslatorName() const = 0;
virtual const char* TranslatorInfo() const = 0;
virtual int32 TranslatorVersion() const = 0;
virtual const translation_format *InputFormats(int32 *out_count)
const = 0;
virtual const translation_format *OutputFormats(int32 *out_count)
const = 0;
virtual status_t Identify(BPositionIO *inSource,
const translation_format *inFormat, BMessage *ioExtension,
translator_info *outInfo, uint32 outType) = 0;
virtual status_t Translate(BPositionIO *inSource,
const translator_info *inInfo, BMessage *ioExtension,
uint32 outType, BPositionIO *outDestination) = 0;
virtual status_t MakeConfigurationView(BMessage *ioExtension,
BView **outView, BRect *outExtent);
virtual status_t GetConfigurationMessage(BMessage *ioExtension);
virtual const translation_format* InputFormats(int32* _count) const = 0;
virtual const translation_format* OutputFormats(int32* _count) const = 0;
virtual status_t Identify(BPositionIO* source,
const translation_format* format,
BMessage* extension, translator_info* info,
uint32 outType) = 0;
virtual status_t Translate(BPositionIO* source,
const translator_info* info,
BMessage* extension, uint32 outType,
BPositionIO* destination) = 0;
virtual status_t MakeConfigurationView(BMessage* extension,
BView** _view, BRect* _extent);
virtual status_t GetConfigurationMessage(BMessage* extension);
protected:
virtual ~BTranslator();
@@ -64,6 +64,7 @@ class BTranslator : public BArchivable {
uint32 _reserved[7];
};
// The post-4.5 API suggests implementing this function in your translator
// add-on rather than the separate functions and variables of the previous
// API. You will be called for values of n starting at 0 and increasing;
@@ -72,4 +73,5 @@ class BTranslator : public BArchivable {
extern "C" BTranslator* make_nth_translator(int32 n, image_id you,
uint32 flags, ...);
#endif /* _TRANSLATOR_H */
#endif // _TRANSLATOR_H
+21 -73
View File
@@ -1,93 +1,41 @@
/********************************************************************************
/
/ File: TranslatorAddOn.h
/
/ Description: This header file defines the interface that should be
/ implemented and exported by a Tanslation Kit add-on.
/ You will only need to include this header when building
/ an actual add-on, not when just using the kit.
/
/ Copyright 1998, Be Incorporated, All Rights Reserved.
/ Copyright 1995-1997, Jon Watte
/
********************************************************************************/
/*
* Copyright 2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _TRANSLATOR_ADD_ON_H
#define _TRANSLATOR_ADD_ON_H
#include <TranslationDefs.h>
class BMessage;
class BView;
class BRect;
class BPositionIO;
/* This is the 4.0 and 4.5 compatible API. For later versions, use the */
/* BTranslator-based API (make_nth_translator) */
// Deprecated, use BTranslator API instead
extern char translatorName[];
extern char translatorInfo[];
extern int32 translatorVersion;
extern translation_format inputFormats[]; // optional
extern translation_format outputFormats[]; // optional
/* These variables and functions should be exported by a translator add-on */
extern "C" {
_EXPORT extern char translatorName[]; /* required, C string, ex "Jon's Sound" */
_EXPORT extern char translatorInfo[]; /* required, descriptive C string, ex "Jon's Sound Translator (shareware $5: [email protected]) v1.00" */
_EXPORT extern int32 translatorVersion; /* required, integer, ex 100 */
_EXPORT extern translation_format inputFormats[]; /* optional (else Identify is always called) */
_EXPORT extern translation_format outputFormats[]; /* optional (else Translate is called anyway) */
/* Translators that don't export outputFormats */
/* will not be considered by files looking for */
/* specific output formats. */
/* Return B_NO_TRANSLATOR if not handling this data. */
/* Even if inputFormats exists, may be called for data without hints */
/* Ff outType is not 0, must be able to export in wanted format */
_EXPORT extern status_t Identify( /* required */
BPositionIO * inSource,
const translation_format * inFormat, /* can beNULL */
BMessage * ioExtension, /* can be NULL */
translator_info * outInfo,
uint32 outType);
/* Return B_NO_TRANSLATOR if not handling the output format */
/* If outputFormats exists, will only be called for those formats */
_EXPORT extern status_t Translate( /* required */
BPositionIO * inSource,
const translator_info * inInfo,
BMessage * ioExtension, /* can be NULL */
uint32 outType,
BPositionIO * outDestination);
/* The view will get resized to what the parent thinks is */
/* reasonable. However, it will still receive MouseDowns etc. */
/* Your view should change settings in the translator immediately, */
/* taking care not to change parameters for a translation that is */
/* currently running. Typically, you'll have a global struct for */
/* settings that is atomically copied into the translator function */
/* as a local when translation starts. */
/* Store your settings wherever you feel like it. */
_EXPORT extern status_t MakeConfig( /* optional */
BMessage * ioExtension, /* can be NULL */
BView * * outView,
BRect * outExtent);
/* Copy your current settings to a BMessage that may be passed */
/* to BTranslators::Translate at some later time when the user wants to */
/* use whatever settings you're using right now. */
_EXPORT extern status_t GetConfigMessage( /* optional */
BMessage * ioExtension);
extern status_t Identify(BPositionIO* source, const translation_format* format,
BMessage* extension, translator_info* info, uint32 outType);
extern status_t Translate(BPositionIO* source, const translator_info* info,
BMessage* extension, uint32 outType,
BPositionIO* destination);
extern status_t MakeConfig(BMessage* extension, BView** _view, BRect* _frame);
extern status_t GetConfigMessage(BMessage* extension);
}
#endif /* _TRANSLATOR_ADD_ON_H */
#endif //_TRANSLATOR_ADD_ON_H
+3 -1
View File
@@ -5,6 +5,7 @@
#ifndef _TRANSLATOR_ROSTER_H
#define _TRANSLATOR_ROSTER_H
#include <Archivable.h>
#include <TranslationDefs.h>
@@ -123,4 +124,5 @@ private:
static BTranslatorRoster* sDefaultRoster;
};
#endif /* _TRANSLATOR_ROSTER_H */
#endif // _TRANSLATOR_ROSTER_H