diff --git a/headers/os/support/Errors.h b/headers/os/support/Errors.h index 4880d0dfbf..f2c202481f 100644 --- a/headers/os/support/Errors.h +++ b/headers/os/support/Errors.h @@ -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) diff --git a/headers/os/translation/TranslationDefs.h b/headers/os/translation/TranslationDefs.h index c433249c52..14edb70dbf 100644 --- a/headers/os/translation/TranslationDefs.h +++ b/headers/os/translation/TranslationDefs.h @@ -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 + #include #include -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; +#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) + + +extern const char* B_TRANSLATOR_MIME_TYPE; + +typedef unsigned long translator_id; + 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 */ + 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]; }; - -/* 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) */ +struct translator_info { + uint32 type; + translator_id translator; + uint32 group; + float quality; + float capability; 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_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 */ +#endif // _TRANSLATION_DEFS_H diff --git a/headers/os/translation/TranslationErrors.h b/headers/os/translation/TranslationErrors.h index e4965123e5..da20e45f94 100644 --- a/headers/os/translation/TranslationErrors.h +++ b/headers/os/translation/TranslationErrors.h @@ -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 -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 diff --git a/headers/os/translation/TranslationKit.h b/headers/os/translation/TranslationKit.h deleted file mode 100644 index c334eae58f..0000000000 --- a/headers/os/translation/TranslationKit.h +++ /dev/null @@ -1,18 +0,0 @@ -/*************************************************************** -/ -/ File: TranslationKit.h -/ -/ Copyright 1998, Be Incorporated. -/ -***************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -/* we do not include TranslatorAddOn.h because it's only used when building an add-on */ - diff --git a/headers/os/translation/TranslationUtils.h b/headers/os/translation/TranslationUtils.h index 40bfdce6a9..bcefc00fbb 100644 --- a/headers/os/translation/TranslationUtils.h +++ b/headers/os/translation/TranslationUtils.h @@ -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 #include +#include + class BBitmap; class BFile; @@ -20,52 +21,63 @@ struct entry_ref; class BTranslationUtils { - private: - BTranslationUtils(); - ~BTranslationUtils(); - BTranslationUtils(const BTranslationUtils &); - BTranslationUtils & operator=(const BTranslationUtils &); + BTranslationUtils(); + BTranslationUtils( + const BTranslationUtils& other); + ~BTranslationUtils(); - public: - // bitmap functions - 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, - BTranslatorRoster *roster = NULL); - static BBitmap *GetBitmapFile(const char *name, - BTranslatorRoster *roster = NULL); - static BBitmap *GetBitmap(const entry_ref *ref, - BTranslatorRoster *roster = NULL); - static BBitmap *GetBitmap(BPositionIO *stream, - BTranslatorRoster *roster = NULL); + BTranslationUtils& operator=(const BTranslationUtils& other); - // 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); +public: + enum { + B_TRANSLATION_MENU = 'BTMN' + }; - // misc. functions - static BMessage *GetDefaultSettings(translator_id forTranslator, - BTranslatorRoster *roster = NULL); - static BMessage *GetDefaultSettings(const char *translatorName, - int32 translatorVersion); + 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, + BTranslatorRoster* roster = NULL); + static BBitmap* GetBitmapFile(const char* name, + BTranslatorRoster* roster = NULL); + static BBitmap* GetBitmap(const entry_ref* ref, + BTranslatorRoster* roster = NULL); + static BBitmap* GetBitmap(BPositionIO* stream, + BTranslatorRoster* roster = NULL); - 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" - BTranslatorRoster *roster = NULL); + static void SetBitmapColorSpace(color_space space); + static color_space BitmapColorSpace(); + + 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 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 diff --git a/headers/os/translation/Translator.h b/headers/os/translation/Translator.h index 86345e6947..39d838e5cf 100644 --- a/headers/os/translation/Translator.h +++ b/headers/os/translation/Translator.h @@ -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 @@ -12,64 +12,66 @@ class BTranslator : public BArchivable { - public: - BTranslator(); +public: + BTranslator(); - BTranslator* Acquire(); - BTranslator* Release(); + BTranslator* Acquire(); + BTranslator* Release(); - int32 ReferenceCount(); - // returns the refcount, THIS IS NOT THREAD SAFE, ITS ONLY FOR "FUN" + int32 ReferenceCount(); - virtual const char *TranslatorName() const = 0; - virtual const char *TranslatorInfo() const = 0; - virtual int32 TranslatorVersion() const = 0; + 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; - protected: - virtual ~BTranslator(); - // this is protected because the object is deleted by the - // Release() function instead of being deleted directly by - // the user + 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); - private: - friend class BTranslatorRoster::Private; +protected: + virtual ~BTranslator(); + // this is protected because the object is deleted by the + // Release() function instead of being deleted directly by + // the user - virtual status_t _Reserved_Translator_0(int32, void *); - virtual status_t _Reserved_Translator_1(int32, void *); - virtual status_t _Reserved_Translator_2(int32, void *); - virtual status_t _Reserved_Translator_3(int32, void *); - virtual status_t _Reserved_Translator_4(int32, void *); - virtual status_t _Reserved_Translator_5(int32, void *); - virtual status_t _Reserved_Translator_6(int32, void *); - virtual status_t _Reserved_Translator_7(int32, void *); +private: + friend class BTranslatorRoster::Private; - BTranslatorRoster::Private* fOwningRoster; - translator_id fID; - int32 fRefCount; + virtual status_t _Reserved_Translator_0(int32, void*); + virtual status_t _Reserved_Translator_1(int32, void*); + virtual status_t _Reserved_Translator_2(int32, void*); + virtual status_t _Reserved_Translator_3(int32, void*); + virtual status_t _Reserved_Translator_4(int32, void*); + virtual status_t _Reserved_Translator_5(int32, void*); + virtual status_t _Reserved_Translator_6(int32, void*); + virtual status_t _Reserved_Translator_7(int32, void*); - uint32 _reserved[7]; + BTranslatorRoster::Private* fOwningRoster; + translator_id fID; + int32 fRefCount; + + 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; -// return 0 when you can't make another kind of translator (i.e. for n=1 +// return 0 when you can't make another kind of translator (i.e. for n = 1 // if you only implement one subclass of BTranslator). Ignore flags for now. -extern "C" BTranslator *make_nth_translator(int32 n, image_id you, +extern "C" BTranslator* make_nth_translator(int32 n, image_id you, uint32 flags, ...); -#endif /* _TRANSLATOR_H */ + +#endif // _TRANSLATOR_H diff --git a/headers/os/translation/TranslatorAddOn.h b/headers/os/translation/TranslatorAddOn.h index 5c336be982..84f177af60 100644 --- a/headers/os/translation/TranslatorAddOn.h +++ b/headers/os/translation/TranslatorAddOn.h @@ -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 + 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: user@mail.net) 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 diff --git a/headers/os/translation/TranslatorRoster.h b/headers/os/translation/TranslatorRoster.h index 8537761ea5..4d95853ed3 100644 --- a/headers/os/translation/TranslatorRoster.h +++ b/headers/os/translation/TranslatorRoster.h @@ -5,6 +5,7 @@ #ifndef _TRANSLATOR_ROSTER_H #define _TRANSLATOR_ROSTER_H + #include #include @@ -123,4 +124,5 @@ private: static BTranslatorRoster* sDefaultRoster; }; -#endif /* _TRANSLATOR_ROSTER_H */ + +#endif // _TRANSLATOR_ROSTER_H