diff --git a/src/add-ons/translators/stxttranslator/Jamfile b/src/add-ons/translators/stxttranslator/Jamfile index 53d1a44a5b..bff91949e8 100644 --- a/src/add-ons/translators/stxttranslator/Jamfile +++ b/src/add-ons/translators/stxttranslator/Jamfile @@ -1,6 +1,18 @@ SubDir OBOS_TOP src add-ons translators stxttranslator ; -Translator STXTTranslator : STXTMain.cpp STXTTranslator.cpp STXTView.cpp STXTWindow.cpp ; +# Include BaseTranslator code from shared directory +SEARCH_SOURCE += [ FDirName $(OBOS_TOP) src add-ons translators shared ] ; + +Translator STXTTranslator : + # shared classes + BaseTranslator.cpp + TranslatorSettings.cpp + TranslatorWindow.cpp + + # STXTTranslator classes + STXTMain.cpp + STXTTranslator.cpp + STXTView.cpp ; LinkSharedOSLibs STXTTranslator : be translation ; diff --git a/src/add-ons/translators/stxttranslator/STXTMain.cpp b/src/add-ons/translators/stxttranslator/STXTMain.cpp index 167c884b6c..be26f6d53a 100644 --- a/src/add-ons/translators/stxttranslator/STXTMain.cpp +++ b/src/add-ons/translators/stxttranslator/STXTMain.cpp @@ -33,11 +33,8 @@ /*****************************************************************************/ #include -#include -#include #include "STXTTranslator.h" -#include "STXTWindow.h" -#include "STXTView.h" +#include "TranslatorWindow.h" // --------------------------------------------------------------- // main @@ -56,48 +53,12 @@ int main() { BApplication app("application/x-vnd.obos-stxt-translator"); - STXTTranslator *ptranslator = new STXTTranslator; - BView *view = NULL; - BRect rect(0, 0, 225, 175); - if (ptranslator->MakeConfigurationView(NULL, &view, &rect)) { - BAlert *err = new BAlert("Error", - "Unable to create the STXTTranslator view.", "OK"); - err->Go(); + status_t result; + result = LaunchTranslatorWindow(new STXTTranslator, + "STXT Settings", BRect(0, 0, 225, 175)); + if (result == B_OK) { + app.Run(); + return 0; + } else return 1; - } - // release the translator even though I never really used it anyway - ptranslator->Release(); - ptranslator = NULL; - - STXTWindow *wnd = new STXTWindow(rect); - view->ResizeTo(rect.Width(), rect.Height()); - wnd->AddChild(view); - BPoint wndpt = B_ORIGIN; - { - BScreen scrn; - BRect frame = scrn.Frame(); - frame.InsetBy(10, 23); - // if the point is outside of the screen frame, - // use the mouse location to find a better point - if (!frame.Contains(wndpt)) { - uint32 dummy; - view->GetMouse(&wndpt, &dummy, false); - wndpt.x -= rect.Width() / 2; - wndpt.y -= rect.Height() / 2; - // clamp location to screen - if (wndpt.x < frame.left) - wndpt.x = frame.left; - if (wndpt.y < frame.top) - wndpt.y = frame.top; - if (wndpt.x > frame.right) - wndpt.x = frame.right; - if (wndpt.y > frame.bottom) - wndpt.y = frame.bottom; - } - } - wnd->MoveTo(wndpt); - wnd->Show(); - app.Run(); - - return 0; } diff --git a/src/add-ons/translators/stxttranslator/STXTTranslator.cpp b/src/add-ons/translators/stxttranslator/STXTTranslator.cpp index bf35135c9c..92cf570c75 100644 --- a/src/add-ons/translators/stxttranslator/STXTTranslator.cpp +++ b/src/add-ons/translators/stxttranslator/STXTTranslator.cpp @@ -34,9 +34,6 @@ #include "STXTTranslator.h" #include "STXTView.h" -#define min(x,y) ((x < y) ? x : y) -#define max(x,y) ((x > y) ? x : y) - #define READ_BUFFER_SIZE 2048 #define DATA_BUFFER_SIZE 64 @@ -80,6 +77,12 @@ translation_format gOutputFormats[] = { } }; +// Default settings for the Translator +TranSetting gDefaultSettings[] = { + {B_TRANSLATOR_EXT_HEADER_ONLY, TRAN_SETTING_BOOL, false}, + {B_TRANSLATOR_EXT_DATA_ONLY, TRAN_SETTING_BOOL, false} +}; + // --------------------------------------------------------------- // make_nth_translator // @@ -126,13 +129,14 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...) // Returns: // --------------------------------------------------------------- STXTTranslator::STXTTranslator() - : BTranslator() + : BaseTranslator("StyledEdit Files", "StyledEdit files translator", + STXT_TRANSLATOR_VERSION, + gInputFormats, sizeof(gInputFormats) / sizeof(translation_format), + gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format), + "STXTTranslator_Settings", + gDefaultSettings, sizeof(gDefaultSettings) / sizeof(TranSetting), + B_TRANSLATOR_TEXT, B_STYLED_TEXT_FORMAT) { - strcpy(fName, "StyledEdit Files"); - sprintf(fInfo, "StyledEdit file translator v%d.%d.%d %s", - static_cast(STXT_TRANSLATOR_VERSION >> 8), - static_cast((STXT_TRANSLATOR_VERSION >> 4) & 0xf), - static_cast(STXT_TRANSLATOR_VERSION & 0xf), __DATE__); } // --------------------------------------------------------------- @@ -152,119 +156,6 @@ STXTTranslator::~STXTTranslator() { } -// --------------------------------------------------------------- -// TranslatorName -// -// Returns the short name of the translator. -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: a const char * to the short name of the translator -// --------------------------------------------------------------- -const char * -STXTTranslator::TranslatorName() const -{ - return fName; -} - -// --------------------------------------------------------------- -// TranslatorInfo -// -// Returns a more verbose name for the translator than the one -// TranslatorName() returns. This usually includes version info. -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: a const char * to the verbose name of the translator -// --------------------------------------------------------------- -const char * -STXTTranslator::TranslatorInfo() const -{ - return fInfo; -} - -// --------------------------------------------------------------- -// TranslatorVersion -// -// Returns the integer representation of the current version of -// this translator. -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -int32 -STXTTranslator::TranslatorVersion() const -{ - return STXT_TRANSLATOR_VERSION; -} - -// --------------------------------------------------------------- -// InputFormats -// -// Returns a list of input formats supported by this translator. -// -// Preconditions: -// -// Parameters: out_count, The number of input formats -// support is returned here. -// -// Postconditions: -// -// Returns: the list of input formats and the number of input -// formats through the out_count parameter, if out_count is NULL, -// NULL is returned -// --------------------------------------------------------------- -const translation_format * -STXTTranslator::InputFormats(int32 *out_count) const -{ - if (out_count) { - *out_count = sizeof(gInputFormats) / - sizeof(translation_format); - return gInputFormats; - } else - return NULL; -} - -// --------------------------------------------------------------- -// OutputFormats -// -// Returns a list of output formats supported by this translator. -// -// Preconditions: -// -// Parameters: out_count, The number of output formats -// support is returned here. -// -// Postconditions: -// -// Returns: the list of output formats and the number of output -// formats through the out_count parameter, if out_count is NULL, -// NULL is returned -// --------------------------------------------------------------- -const translation_format * -STXTTranslator::OutputFormats(int32 *out_count) const -{ - if (out_count) { - *out_count = sizeof(gOutputFormats) / - sizeof(translation_format); - return gOutputFormats; - } else - return NULL; -} - // --------------------------------------------------------------- // identify_stxt_header // @@ -930,43 +821,10 @@ STXTTranslator::Translate(BPositionIO *inSource, return result; } -// --------------------------------------------------------------- -// MakeConfigurationView -// -// Makes a BView object for configuring / displaying info about -// this translator. -// -// Preconditions: -// -// Parameters: ioExtension, configuration options for the -// translator -// -// outView, the view to configure the -// translator is stored here -// -// outExtent, the bounds of the view are -// stored here -// -// Postconditions: -// -// Returns: B_BAD_VALUE if ioExtension or outView are NULL, -// B_NO_MEMORY if a view can't be allocated, -// B_OK if all goes well -// --------------------------------------------------------------- -status_t -STXTTranslator::MakeConfigurationView(BMessage *ioExtension, BView **outView, - BRect *outExtent) +BView * +STXTTranslator::NewConfigView(TranslatorSettings *settings) { - if (!outView || !outExtent) - return B_BAD_VALUE; - - STXTView *view = new STXTView(BRect(0, 0, 225, 175), - "STXTTranslator Settings", B_FOLLOW_ALL, B_WILL_DRAW); - if (!view) - return B_NO_MEMORY; - - *outView = view; - *outExtent = view->Bounds(); - - return B_OK; + return new STXTView(BRect(0, 0, 225, 175), "STXTTranslator Settings", + B_FOLLOW_ALL, B_WILL_DRAW, settings); } + diff --git a/src/add-ons/translators/stxttranslator/STXTTranslator.h b/src/add-ons/translators/stxttranslator/STXTTranslator.h index 2fad56afcc..fc11f8f25a 100644 --- a/src/add-ons/translators/stxttranslator/STXTTranslator.h +++ b/src/add-ons/translators/stxttranslator/STXTTranslator.h @@ -41,8 +41,9 @@ #include #include #include +#include "BaseTranslator.h" -#define STXT_TRANSLATOR_VERSION 0x100 +#define STXT_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VER(1,0,0) #define STXT_IN_QUALITY 0.5 #define STXT_IN_CAPABILITY 0.5 #define STXT_OUT_QUALITY 0.5 @@ -53,29 +54,10 @@ #define TEXT_OUT_QUALITY 0.4 #define TEXT_OUT_CAPABILITY 0.6 -class STXTTranslator : public BTranslator { +class STXTTranslator : public BaseTranslator { public: STXTTranslator(); - virtual const char *TranslatorName() const; - // returns the short name of the translator - - virtual const char *TranslatorInfo() const; - // returns a verbose name/description for the translator - - virtual int32 TranslatorVersion() const; - // returns the version of the translator - - virtual const translation_format *InputFormats(int32 *out_count) - const; - // returns the input formats and the count of input formats - // that this translator supports - - virtual const translation_format *OutputFormats(int32 *out_count) - const; - // returns the output formats and the count of output formats - // that this translator supports - virtual status_t Identify(BPositionIO *inSource, const translation_format *inFormat, BMessage *ioExtension, translator_info *outInfo, uint32 outType); @@ -89,10 +71,7 @@ public: // it translates the data in inSource to outDestination // using the format outType - virtual status_t MakeConfigurationView(BMessage *ioExtension, - BView **outView, BRect *outExtent); - // creates and returns the view for displaying information - // about this translator + virtual BView *NewConfigView(TranslatorSettings *settings); protected: virtual ~STXTTranslator(); @@ -101,8 +80,6 @@ protected: // the user private: - char fName[30]; - char fInfo[100]; }; #endif // #ifndef STXT_TRANSLATOR_H diff --git a/src/add-ons/translators/stxttranslator/STXTView.cpp b/src/add-ons/translators/stxttranslator/STXTView.cpp index 144ac04a0b..ca4c2941f2 100644 --- a/src/add-ons/translators/stxttranslator/STXTView.cpp +++ b/src/add-ons/translators/stxttranslator/STXTView.cpp @@ -47,10 +47,12 @@ // Returns: // --------------------------------------------------------------- STXTView::STXTView(const BRect &frame, const char *name, - uint32 resize, uint32 flags) + uint32 resize, uint32 flags, TranslatorSettings *settings) : BView(frame, name, resize, flags) { - SetViewColor(220,220,220,0); + fSettings = settings; + + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); } // --------------------------------------------------------------- @@ -68,6 +70,7 @@ STXTView::STXTView(const BRect &frame, const char *name, // --------------------------------------------------------------- STXTView::~STXTView() { + fSettings->Release(); } // --------------------------------------------------------------- @@ -104,9 +107,10 @@ STXTView::Draw(BRect area) char detail[100]; sprintf(detail, "Version %d.%d.%d %s", - static_cast(STXT_TRANSLATOR_VERSION >> 8), - static_cast((STXT_TRANSLATOR_VERSION >> 4) & 0xf), - static_cast(STXT_TRANSLATOR_VERSION & 0xf), __DATE__); + static_cast(B_TRANSLATION_MAJOR_VER(STXT_TRANSLATOR_VERSION)), + static_cast(B_TRANSLATION_MINOR_VER(STXT_TRANSLATOR_VERSION)), + static_cast(B_TRANSLATION_REVSN_VER(STXT_TRANSLATOR_VERSION)), + __DATE__); DrawString(detail, BPoint(xbold, yplain + ybold)); /* char copyright[] = "© 2002 OpenBeOS Project"; DrawString(copyright, BPoint(xbold, yplain * 2 + ybold)); diff --git a/src/add-ons/translators/stxttranslator/STXTView.h b/src/add-ons/translators/stxttranslator/STXTView.h index a03f3f1df4..35d64c5282 100644 --- a/src/add-ons/translators/stxttranslator/STXTView.h +++ b/src/add-ons/translators/stxttranslator/STXTView.h @@ -34,18 +34,21 @@ #include #include #include +#include "TranslatorSettings.h" class STXTView : public BView { public: STXTView(const BRect &frame, const char *name, uint32 resize, - uint32 flags); + uint32 flags, TranslatorSettings *settings); // sets up the view ~STXTView(); - // does nothing + // releases settings virtual void Draw(BRect area); // draws information about the STXTTranslator +private: + TranslatorSettings *fSettings; }; #endif // #ifndef STXTVIEW_H