1 /*****************************************************************************/ 2 // File: TranslationUtils.h 3 // Class: BTranslationUtils 4 // Reimplemented by: Michael Wilber, Translation Kit Team 5 // Reimplementation: 2002-04 6 // 7 // Description: Utility functions for the Translation Kit 8 // 9 // 10 // Copyright (c) 2002 OpenBeOS Project 11 // 12 // Original Version: Copyright 1998, Be Incorporated, All Rights Reserved. 13 // Copyright 1995-1997, Jon Watte 14 // 15 // Permission is hereby granted, free of charge, to any person obtaining a 16 // copy of this software and associated documentation files (the "Software"), 17 // to deal in the Software without restriction, including without limitation 18 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 19 // and/or sell copies of the Software, and to permit persons to whom the 20 // Software is furnished to do so, subject to the following conditions: 21 // 22 // The above copyright notice and this permission notice shall be included 23 // in all copies or substantial portions of the Software. 24 // 25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 26 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 28 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 30 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 31 // DEALINGS IN THE SOFTWARE. 32 /*****************************************************************************/ 33 34 #if !defined(_TRANSLATION_UTILS_H) 35 #define _TRANSLATION_UTILS_H 36 37 #include <TranslationDefs.h> 38 #include <SupportDefs.h> 39 40 class BBitmap; 41 class BTranslatorRoster; 42 class BPositionIO; 43 class BMenu; 44 45 // This class is a little different from many other classes. 46 // You don't create an instance of it; you just call its various 47 // static member functions for utility-like operations. 48 class BTranslationUtils { 49 BTranslationUtils(); 50 ~BTranslationUtils(); 51 BTranslationUtils(const BTranslationUtils &); 52 BTranslationUtils & operator=(const BTranslationUtils &); 53 54 public: 55 56 // BITMAP getters - allocate the BBitmap; you call delete on it! 57 58 static BBitmap *GetBitmap(const char *kName, BTranslatorRoster *roster = NULL); 59 // Get bitmap - first try as file name, then as B_TRANSLATOR_BITMAP 60 // resource type from app file -- can be of any kind for which a 61 // translator is installed (TGA, etc) 62 63 static BBitmap *GetBitmap(uint32 type, int32 id, 64 BTranslatorRoster *roster = NULL); 65 // Get bitmap - from app resource by id 66 67 static BBitmap *GetBitmap(uint32 type, const char *kName, 68 BTranslatorRoster *roster = NULL); 69 // Get Bitmap - from app resource by name 70 71 static BBitmap *GetBitmapFile(const char *kName, 72 BTranslatorRoster *roster = NULL); 73 // Get bitmap - from file only 74 75 static BBitmap *GetBitmap(const entry_ref *kRef, 76 BTranslatorRoster *roster = NULL); 77 // Get bitmap - from open file (or BMemoryIO) 78 79 static BBitmap *GetBitmap(BPositionIO *stream, 80 BTranslatorRoster *roster = NULL); 81 // Get bitmap - from open file or IO type object 82 // This function does the real work for the other GetBitmap functions 83 84 static status_t GetStyledText(BPositionIO *fromStream, BTextView *intoView, 85 BTranslatorRoster *roster = NULL); 86 // For styled text, we can translate from a stream 87 // directly into a BTextView 88 89 static status_t PutStyledText(BTextView *fromView, BPositionIO *intoStream, 90 BTranslatorRoster *roster = NULL); 91 // Saving is slightly different -- given the BTextView, a 92 // B_STYLED_TEXT_FORMAT stream is written to intoStream. You can then call 93 // Translate() yourself to translate that stream into something else if 94 // you want, if it is a temp file or a BMallocIO. It's also OK to write 95 // the B_STYLED_TEXT_FORMAT to a file, although the StyledEdit format 96 // (TEXT file + style attributes) is preferred. This convenience function 97 // is only marginally part of the Translation Kit, but what the hey :-) 98 99 static status_t WriteStyledEditFile(BTextView *fromView, BFile *intoFile); 100 // Writes the styled text data from fromView to intoFile 101 102 static BMessage *GetDefaultSettings(translator_id forTranslator, 103 BTranslatorRoster *roster = NULL); 104 // Get default settings for the translator with the id forTranslator 105 106 static BMessage *GetDefaultSettings(const char *kTranslatorName, 107 int32 translatorVersion); 108 // Get default settings for the translator with the name kTranslatorName 109 110 // Envious of that "Save As" menu in ShowImage? Well, you can have your own! 111 // AddTranslationItems will add menu items for all translations from the 112 // basic format you specify (B_TRANSLATOR_BITMAP, B_TRANSLATOR_TEXT etc). 113 // The translator ID and format constant chosen will be added to the message 114 // that is sent to you when the menu item is selected. 115 enum { 116 B_TRANSLATION_MENU = 'BTMN' 117 }; 118 static status_t AddTranslationItems(BMenu *intoMenu, uint32 fromType, 119 const BMessage *kModel = NULL, // default B_TRANSLATION_MENU 120 const char *kTranslatorIdName = NULL, // default "be:translator" 121 const char *kTranslatorTypeName = NULL, // default "be:type" 122 BTranslatorRoster *roster = NULL); 123 }; 124 125 #endif /* _TRANSLATION_UTILS_H */ 126 127