diff --git a/src/add-ons/translators/bmp/BMPView.cpp b/src/add-ons/translators/bmp/BMPView.cpp index a37b2a4a28..ba15f82e0f 100644 --- a/src/add-ons/translators/bmp/BMPView.cpp +++ b/src/add-ons/translators/bmp/BMPView.cpp @@ -1,116 +1,71 @@ -/*****************************************************************************/ -// BMPView -// BMPView.cpp -// -// This BView based object displays information about the BMPTranslator. -// -// -// Copyright (c) 2002 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ +/* + * Copyright 2002-2006, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Michael Wilber + * Axel Dörfler, axeld@pinc-software.de + */ + +/*! A view with information about the BMPTranslator. */ + -#include -#include #include "BMPView.h" #include "BMPTranslator.h" -// --------------------------------------------------------------- -// Constructor -// -// Sets up the view settings -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -BMPView::BMPView(const BRect &frame, const char *name, - uint32 resize, uint32 flags, TranslatorSettings *settings) - : BView(frame, name, resize, flags) +#include + +#include + + +BMPView::BMPView(const BRect &frame, const char *name, uint32 resizeMode, + uint32 flags, TranslatorSettings *settings) + : BView(frame, name, resizeMode, flags) { fSettings = settings; - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + font_height fontHeight; + be_bold_font->GetHeight(&fontHeight); + float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; + + BRect rect(10, 10, 200, 10 + height); + BStringView *stringView = new BStringView(rect, "title", "BMP Image Translator"); + stringView->SetFont(be_bold_font); + stringView->ResizeToPreferred(); + AddChild(stringView); + + float maxWidth = stringView->Bounds().Width(); + + rect.OffsetBy(0, height + 10); + char version[256]; + snprintf(version, sizeof(version), "Version %d.%d.%d, %s", + int(B_TRANSLATION_MAJOR_VERSION(BMP_TRANSLATOR_VERSION)), + int(B_TRANSLATION_MINOR_VERSION(BMP_TRANSLATOR_VERSION)), + int(B_TRANSLATION_REVISION_VERSION(BMP_TRANSLATOR_VERSION)), + __DATE__); + stringView = new BStringView(rect, "version", version); + stringView->ResizeToPreferred(); + AddChild(stringView); + + if (stringView->Bounds().Width() > maxWidth) + maxWidth = stringView->Bounds().Width(); + + GetFontHeight(&fontHeight); + height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; + + rect.OffsetBy(0, height + 5); + stringView = new BStringView(rect, "Copyright", B_UTF8_COPYRIGHT "2002-2006 Haiku Inc."); + stringView->ResizeToPreferred(); + AddChild(stringView); + + if (maxWidth + 20 > Bounds().Width()) + ResizeTo(maxWidth + 20, Bounds().Height()); } -// --------------------------------------------------------------- -// Destructor -// -// Releases the translator settings -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- + BMPView::~BMPView() { fSettings->Release(); } -// --------------------------------------------------------------- -// Draw -// -// Draws information about the BMPTranslator to this view. -// -// Preconditions: -// -// Parameters: area, not used -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -void -BMPView::Draw(BRect area) -{ - SetFont(be_bold_font); - font_height fh; - GetFontHeight(&fh); - float xbold, ybold; - xbold = fh.descent + 1; - ybold = fh.ascent + fh.descent * 2 + fh.leading; - - char title[] = "OpenBeOS BMP Image Translator"; - DrawString(title, BPoint(xbold, ybold)); - - SetFont(be_plain_font); - font_height plainh; - GetFontHeight(&plainh); - float yplain; - yplain = plainh.ascent + plainh.descent * 2 + plainh.leading; - - char detail[100]; - sprintf(detail, "Version %d.%d.%d %s", - static_cast(B_TRANSLATION_MAJOR_VERSION(BMP_TRANSLATOR_VERSION)), - static_cast(B_TRANSLATION_MINOR_VERSION(BMP_TRANSLATOR_VERSION)), - static_cast(B_TRANSLATION_REVISION_VERSION(BMP_TRANSLATOR_VERSION)), - __DATE__); - DrawString(detail, BPoint(xbold, yplain + ybold)); - - char writtenby[] = "Written by the OBOS Translation Kit Team"; - DrawString(writtenby, BPoint(xbold, yplain * 7 + ybold)); -} diff --git a/src/add-ons/translators/bmp/BMPView.h b/src/add-ons/translators/bmp/BMPView.h index dc8a2b3d3a..1316f074ef 100644 --- a/src/add-ons/translators/bmp/BMPView.h +++ b/src/add-ons/translators/bmp/BMPView.h @@ -1,52 +1,28 @@ -/*****************************************************************************/ -// BMPView -// BMPView.h -// -// This BView based object displays information about the BMPTranslator. -// -// -// Copyright (c) 2002 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ +/* + * Copyright 2002-2006, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Michael Wilber + * Axel Dörfler, axeld@pinc-software.de + */ +#ifndef BMP_VIEW_H +#define BMP_VIEW_H -#ifndef BMPVIEW_H -#define BMPVIEW_H -#include -#include -#include #include "TranslatorSettings.h" -class BMPView : public BView { -public: - BMPView(const BRect &frame, const char *name, uint32 resize, - uint32 flags, TranslatorSettings *settings); - // sets up the view - - ~BMPView(); - // releases settings +#include - virtual void Draw(BRect area); - // draws information about the BMPTranslator -private: - TranslatorSettings *fSettings; + +class BMPView : public BView { + public: + BMPView(const BRect &frame, const char *name, uint32 resizeMode, + uint32 flags, TranslatorSettings *settings); + virtual ~BMPView(); + + private: + TranslatorSettings *fSettings; }; -#endif // #ifndef BMPVIEW_H +#endif // BMP_VIEW_H diff --git a/src/add-ons/translators/png/PNGView.cpp b/src/add-ons/translators/png/PNGView.cpp index d299ea5150..77d1b8fe42 100644 --- a/src/add-ons/translators/png/PNGView.cpp +++ b/src/add-ons/translators/png/PNGView.cpp @@ -1,189 +1,157 @@ -/*****************************************************************************/ -// PNGView -// Written by Michael Wilber, OBOS Translation Kit Team -// -// PNGView.cpp -// -// This BView based object displays information about the PNGTranslator. -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ +/* + * Copyright 2003-2006, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Michael Wilber + * Axel Dörfler, axeld@pinc-software.de + */ + -#include -#include -#include -#include #include "PNGView.h" #include "PNGTranslator.h" -BMessage * -interlace_msg(int option) -{ - BMessage *pmsg = new BMessage(M_PNG_SET_INTERLACE); - pmsg->AddInt32(PNG_SETTING_INTERLACE, option); - return pmsg; -} +#include +#include +#include +#include +#include +#include -// --------------------------------------------------------------- -// Constructor -// -// Sets up the view settings -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -PNGView::PNGView(const BRect &frame, const char *name, - uint32 resize, uint32 flags, TranslatorSettings *settings) - : BView(frame, name, resize, flags) +#include +#include + + +PNGView::PNGView(const BRect &frame, const char *name, uint32 resizeMode, + uint32 flags, TranslatorSettings *settings) + : BView(frame, name, resizeMode, flags | B_FRAME_EVENTS) { fSettings = settings; - - SetViewColor(220,220,220,0); - - // setup PNG interlace options menu - fpmnuInterlace = new BPopUpMenu("Interlace Option"); - BMenuItem *pitmNone, *pitmAdam7; - pitmNone = new BMenuItem("None", interlace_msg(PNG_INTERLACE_NONE)); - pitmAdam7 = new BMenuItem("Adam7", interlace_msg(PNG_INTERLACE_ADAM7)); - fpmnuInterlace->AddItem(pitmNone); - fpmnuInterlace->AddItem(pitmAdam7); - - fpfldInterlace = new BMenuField(BRect(20, 50, 200, 70), - "PNG Interlace Menu", "Interlacing Type", fpmnuInterlace); - fpfldInterlace->SetViewColor(ViewColor()); - AddChild(fpfldInterlace); - - // set Interlace option to show the current configuration + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + font_height fontHeight; + be_bold_font->GetHeight(&fontHeight); + float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; + + BRect rect(10, 10, 200, 10 + height); + BStringView *stringView = new BStringView(rect, "title", "PNG Image Translator"); + stringView->SetFont(be_bold_font); + stringView->ResizeToPreferred(); + AddChild(stringView); + + float maxWidth = stringView->Bounds().Width(); + + rect.OffsetBy(0, height + 10); + char version[256]; + snprintf(version, sizeof(version), "Version %d.%d.%d, %s", + int(B_TRANSLATION_MAJOR_VERSION(PNG_TRANSLATOR_VERSION)), + int(B_TRANSLATION_MINOR_VERSION(PNG_TRANSLATOR_VERSION)), + int(B_TRANSLATION_REVISION_VERSION(PNG_TRANSLATOR_VERSION)), + __DATE__); + stringView = new BStringView(rect, "version", version); + stringView->ResizeToPreferred(); + AddChild(stringView); + + if (stringView->Bounds().Width() > maxWidth) + maxWidth = stringView->Bounds().Width(); + + GetFontHeight(&fontHeight); + height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; + + rect.OffsetBy(0, height + 5); + stringView = new BStringView(rect, "Copyright", B_UTF8_COPYRIGHT "2003-2006 Haiku Inc."); + stringView->ResizeToPreferred(); + AddChild(stringView); + + // setup PNG interlace options + + fInterlaceMenu = new BPopUpMenu("Interlace Option"); + BMenuItem* item = new BMenuItem("None", _InterlaceMessage(PNG_INTERLACE_NONE)); if (fSettings->SetGetInt32(PNG_SETTING_INTERLACE) == PNG_INTERLACE_NONE) - pitmNone->SetMarked(true); - else - pitmAdam7->SetMarked(true); + item->SetMarked(true); + fInterlaceMenu->AddItem(item); + + item = new BMenuItem("Adam7", _InterlaceMessage(PNG_INTERLACE_ADAM7)); + if (fSettings->SetGetInt32(PNG_SETTING_INTERLACE) == PNG_INTERLACE_ADAM7) + item->SetMarked(true); + fInterlaceMenu->AddItem(item); + + rect.OffsetBy(0, stringView->Frame().Height() + 20.0f); + BMenuField* menuField = new BMenuField(rect, "PNG Interlace Menu", + "Interlacing Type:", fInterlaceMenu); + menuField->SetDivider(menuField->StringWidth(menuField->Label()) + 7.0f); + menuField->ResizeToPreferred(); + AddChild(menuField); + + rect.OffsetBy(0, height + 15); + rect.right = Bounds().right; + rect.bottom = Bounds().bottom; + fCopyrightView = new BTextView(rect, "PNG copyright", rect.OffsetToCopy(B_ORIGIN), + B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS); + fCopyrightView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fCopyrightView->SetLowColor(fCopyrightView->ViewColor()); + fCopyrightView->MakeEditable(false); + fCopyrightView->SetText(png_get_copyright(NULL)); + + BFont font; + font.SetSize(font.Size() * 0.8); + fCopyrightView->SetFontAndColor(&font, B_FONT_SIZE, NULL); + AddChild(fCopyrightView); + + if (maxWidth + 20 > Bounds().Width()) + ResizeTo(maxWidth + 20, Bounds().Height()); + if (Bounds().Height() < rect.top + stringView->Bounds().Height() * 3.0f + 8.0f) + ResizeTo(Bounds().Width(), rect.top + height * 3.0f + 8.0f); + + fCopyrightView->SetTextRect(fCopyrightView->Bounds()); } -// --------------------------------------------------------------- -// Destructor -// -// Releases the PNGTranslator settings -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- + PNGView::~PNGView() { fSettings->Release(); } -void -PNGView::AllAttached() + +BMessage * +PNGView::_InterlaceMessage(int32 kind) { - // Tell all controls that this view is the target for - // messages from controls on this view - BView::AllAttached(); - BMessenger msgr(this); - + BMessage* message = new BMessage(M_PNG_SET_INTERLACE); + message->AddInt32(PNG_SETTING_INTERLACE, kind); + + return message; +} + + +void +PNGView::AttachedToWindow() +{ + BView::AttachedToWindow(); + // set target for interlace options menu items - for (int32 i = 0; i < fpmnuInterlace->CountItems(); i++) { - BMenuItem *pitm = fpmnuInterlace->ItemAt(i); - if (pitm) - pitm->SetTarget(msgr); - } + fInterlaceMenu->SetTargetForItems(this); } -// --------------------------------------------------------------- -// Draw -// -// Draws information about the PNGTranslator to this view. -// -// Preconditions: -// -// Parameters: area, not used -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -void -PNGView::Draw(BRect area) -{ - SetFont(be_bold_font); - font_height fh; - GetFontHeight(&fh); - float xbold, ybold; - xbold = fh.descent + 1; - ybold = fh.ascent + fh.descent * 2 + fh.leading; - - char title[] = "OpenBeOS PNG Image Translator"; - DrawString(title, BPoint(xbold, ybold)); - - SetFont(be_plain_font); - font_height plainh; - GetFontHeight(&plainh); - float yplain; - yplain = plainh.ascent + plainh.descent * 2 + plainh.leading; - - char detail[100]; - sprintf(detail, "Version %d.%d.%d %s", - static_cast(B_TRANSLATION_MAJOR_VERSION(PNG_TRANSLATOR_VERSION)), - static_cast(B_TRANSLATION_MINOR_VERSION(PNG_TRANSLATOR_VERSION)), - static_cast(B_TRANSLATION_REVISION_VERSION(PNG_TRANSLATOR_VERSION)), - __DATE__); - DrawString(detail, BPoint(xbold, yplain + ybold)); - - int32 lineno = 6; - DrawString("PNG Library:", BPoint(xbold, yplain * lineno + ybold)); - lineno += 1; - - const int32 kinfolen = 512; - char libinfo[kinfolen] = { 0 }; - strncpy(libinfo, png_get_copyright(NULL), kinfolen - 1); - char *tok = strtok(libinfo, "\n"); - while (tok) { - DrawString(tok, BPoint(xbold, yplain * lineno + ybold)); - lineno++; - tok = strtok(NULL, "\n"); - } -} void -PNGView::MessageReceived(BMessage *pmsg) +PNGView::FrameResized(float width, float height) { - if (pmsg->what == M_PNG_SET_INTERLACE) { + // This works around a flaw of BTextView + fCopyrightView->SetTextRect(fCopyrightView->Bounds()); +} + + +void +PNGView::MessageReceived(BMessage *message) +{ + if (message->what == M_PNG_SET_INTERLACE) { // change setting for interlace option int32 option; - if (pmsg->FindInt32(PNG_SETTING_INTERLACE, &option) == B_OK) { + if (message->FindInt32(PNG_SETTING_INTERLACE, &option) == B_OK) { fSettings->SetGetInt32(PNG_SETTING_INTERLACE, &option); fSettings->SaveSettings(); } } else - BView::MessageReceived(pmsg); + BView::MessageReceived(message); } diff --git a/src/add-ons/translators/png/PNGView.h b/src/add-ons/translators/png/PNGView.h index 2326ec7440..3eecec53f1 100644 --- a/src/add-ons/translators/png/PNGView.h +++ b/src/add-ons/translators/png/PNGView.h @@ -1,70 +1,50 @@ -/*****************************************************************************/ -// PNGView -// Written by Michael Wilber, OBOS Translation Kit Team -// -// PNGView.h -// -// This BView based object displays information about the PNGTranslator. -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ +/* + * Copyright 2003-2006, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Michael Wilber + * Axel Dörfler, axeld@pinc-software.de + */ +#ifndef PNG_VIEW_H +#define PNG_VIEW_H -#ifndef PNGVIEW_H -#define PNGVIEW_H -#include -#include -#include -#include #include "TranslatorSettings.h" -#define PNG_VIEW_WIDTH 300 -#define PNG_VIEW_HEIGHT 250 +#include + +class BPopUpMenu; +class BTextView; + // Config panel messages -#define M_PNG_SET_INTERLACE 'pnsi' +#define M_PNG_SET_INTERLACE 'pnsi' + +// default view size +#define PNG_VIEW_WIDTH 300 +#define PNG_VIEW_HEIGHT 270 class PNGView : public BView { -public: - PNGView(const BRect &frame, const char *name, uint32 resize, - uint32 flags, TranslatorSettings *settings); - // sets up the view - - ~PNGView(); - // releases the PNGTranslator settings + public: + PNGView(const BRect &frame, const char *name, uint32 resizeMode, + uint32 flags, TranslatorSettings *settings); + ~PNGView(); - virtual void AllAttached(); - virtual void Draw(BRect area); - // draws information about the PNGTranslator - virtual void MessageReceived(BMessage *pmsg); - -private: - BPopUpMenu *fpmnuInterlace; - BMenuField *fpfldInterlace; - - TranslatorSettings *fSettings; - // the actual settings for the translator, - // shared with the translator + virtual void AttachedToWindow(); + virtual void FrameResized(float width, float height); + virtual void MessageReceived(BMessage *message); + + private: + BMessage* _InterlaceMessage(int32 kind); + + private: + BPopUpMenu* fInterlaceMenu; + BTextView* fCopyrightView; + TranslatorSettings* fSettings; + // the actual settings for the translator, + // shared with the translator }; -#endif // #ifndef PNGVIEW_H +#endif // PNG_VIEW_H diff --git a/src/add-ons/translators/rtf/ConfigView.cpp b/src/add-ons/translators/rtf/ConfigView.cpp index fbc1103f06..63df515f2f 100644 --- a/src/add-ons/translators/rtf/ConfigView.cpp +++ b/src/add-ons/translators/rtf/ConfigView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -10,7 +10,6 @@ #include #include -#include ConfigView::ConfigView(const BRect &frame, uint32 resize, uint32 flags) @@ -28,9 +27,11 @@ ConfigView::ConfigView(const BRect &frame, uint32 resize, uint32 flags) stringView->ResizeToPreferred(); AddChild(stringView); + float maxWidth = stringView->Bounds().Width(); + rect.OffsetBy(0, height + 10); char version[256]; - sprintf(version, "Version %d.%d.%d, %s", + snprintf(version, sizeof(version), "Version %d.%d.%d, %s", int(B_TRANSLATION_MAJOR_VERSION(RTF_TRANSLATOR_VERSION)), int(B_TRANSLATION_MINOR_VERSION(RTF_TRANSLATOR_VERSION)), int(B_TRANSLATION_REVISION_VERSION(RTF_TRANSLATOR_VERSION)), @@ -39,13 +40,19 @@ ConfigView::ConfigView(const BRect &frame, uint32 resize, uint32 flags) stringView->ResizeToPreferred(); AddChild(stringView); + if (stringView->Bounds().Width() > maxWidth) + maxWidth = stringView->Bounds().Width(); + GetFontHeight(&fontHeight); height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; rect.OffsetBy(0, height + 5); - stringView = new BStringView(rect, "copyright", B_UTF8_COPYRIGHT "2004-2005 Haiku Inc."); + stringView = new BStringView(rect, "Copyright", B_UTF8_COPYRIGHT "2004-2006 Haiku Inc."); stringView->ResizeToPreferred(); AddChild(stringView); + + if (maxWidth + 20 > Bounds().Width()) + ResizeTo(maxWidth + 20, Bounds().Height()); } diff --git a/src/add-ons/translators/stxt/STXTView.cpp b/src/add-ons/translators/stxt/STXTView.cpp index 143faa26f0..b897d527d9 100644 --- a/src/add-ons/translators/stxt/STXTView.cpp +++ b/src/add-ons/translators/stxt/STXTView.cpp @@ -1,120 +1,70 @@ -/*****************************************************************************/ -// STXTView -// Written by Michael Wilber, OBOS Translation Kit Team -// -// STXTView.cpp -// -// This BView based object displays information about the STXTTranslator. -// -// -// Copyright (c) 2002 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ +/* + * Copyright 2002-2006, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Michael Wilber + * Axel Dörfler, axeld@pinc-software.de + */ + +/*! A view with information about the STXTTranslator. */ + -#include -#include #include "STXTView.h" #include "STXTTranslator.h" -// --------------------------------------------------------------- -// Constructor -// -// Sets up the view settings -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -STXTView::STXTView(const BRect &frame, const char *name, - uint32 resize, uint32 flags, TranslatorSettings *settings) - : BView(frame, name, resize, flags) +#include + +#include + + +STXTView::STXTView(const BRect &frame, const char *name, uint32 resizeMode, + uint32 flags, TranslatorSettings *settings) + : BView(frame, name, resizeMode, flags) { fSettings = settings; - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + font_height fontHeight; + be_bold_font->GetHeight(&fontHeight); + float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; + + BRect rect(10, 10, 200, 10 + height); + BStringView *stringView = new BStringView(rect, "title", "StyledEdit Files Translator"); + stringView->SetFont(be_bold_font); + stringView->ResizeToPreferred(); + AddChild(stringView); + + float maxWidth = stringView->Bounds().Width(); + + rect.OffsetBy(0, height + 10); + char version[256]; + snprintf(version, sizeof(version), "Version %d.%d.%d, %s", + int(B_TRANSLATION_MAJOR_VERSION(STXT_TRANSLATOR_VERSION)), + int(B_TRANSLATION_MINOR_VERSION(STXT_TRANSLATOR_VERSION)), + int(B_TRANSLATION_REVISION_VERSION(STXT_TRANSLATOR_VERSION)), + __DATE__); + stringView = new BStringView(rect, "version", version); + stringView->ResizeToPreferred(); + AddChild(stringView); + + if (stringView->Bounds().Width() > maxWidth) + maxWidth = stringView->Bounds().Width(); + + GetFontHeight(&fontHeight); + height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; + + rect.OffsetBy(0, height + 5); + stringView = new BStringView(rect, "Copyright", B_UTF8_COPYRIGHT "2002-2006 Haiku Inc."); + stringView->ResizeToPreferred(); + AddChild(stringView); + + if (maxWidth + 20 > Bounds().Width()) + ResizeTo(maxWidth + 20, Bounds().Height()); } -// --------------------------------------------------------------- -// Destructor -// -// Does nothing -// -// Preconditions: -// -// Parameters: -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- + STXTView::~STXTView() { fSettings->Release(); } - -// --------------------------------------------------------------- -// Draw -// -// Draws information about the STXTTranslator to this view. -// -// Preconditions: -// -// Parameters: area, not used -// -// Postconditions: -// -// Returns: -// --------------------------------------------------------------- -void -STXTView::Draw(BRect area) -{ - SetFont(be_bold_font); - font_height fh; - GetFontHeight(&fh); - float xbold, ybold; - xbold = fh.descent + 1; - ybold = fh.ascent + fh.descent * 2 + fh.leading; - - char title[] = "OpenBeOS StyledEdit Files Translator"; - DrawString(title, BPoint(xbold, ybold)); - - SetFont(be_plain_font); - font_height plainh; - GetFontHeight(&plainh); - float yplain; - yplain = plainh.ascent + plainh.descent * 2 + plainh.leading; - - char detail[100]; - sprintf(detail, "Version %d.%d.%d %s", - static_cast(B_TRANSLATION_MAJOR_VERSION(STXT_TRANSLATOR_VERSION)), - static_cast(B_TRANSLATION_MINOR_VERSION(STXT_TRANSLATOR_VERSION)), - static_cast(B_TRANSLATION_REVISION_VERSION(STXT_TRANSLATOR_VERSION)), - __DATE__); - DrawString(detail, BPoint(xbold, yplain + ybold)); -/* char copyright[] = "© 2002 OpenBeOS Project"; - DrawString(copyright, BPoint(xbold, yplain * 2 + ybold)); -*/ - char writtenby[] = "Written by the OBOS Translation Kit Team"; - DrawString(writtenby, BPoint(xbold, yplain * 7 + ybold)); -} diff --git a/src/add-ons/translators/stxt/STXTView.h b/src/add-ons/translators/stxt/STXTView.h index 35d64c5282..42ced7b8a1 100644 --- a/src/add-ons/translators/stxt/STXTView.h +++ b/src/add-ons/translators/stxt/STXTView.h @@ -1,54 +1,28 @@ -/*****************************************************************************/ -// STXTView -// Written by Michael Wilber, OBOS Translation Kit Team -// -// STXTView.h -// -// This BView based object displays information about the STXTTranslator. -// -// -// Copyright (c) 2002 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ +/* + * Copyright 2002-2006, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Authors: + * Michael Wilber + * Axel Dörfler, axeld@pinc-software.de + */ +#ifndef STXT_VIEW_H +#define STXT_VIEW_H -#ifndef STXTVIEW_H -#define STXTVIEW_H -#include -#include -#include #include "TranslatorSettings.h" -class STXTView : public BView { -public: - STXTView(const BRect &frame, const char *name, uint32 resize, - uint32 flags, TranslatorSettings *settings); - // sets up the view - - ~STXTView(); - // releases settings +#include - virtual void Draw(BRect area); - // draws information about the STXTTranslator -private: - TranslatorSettings *fSettings; + +class STXTView : public BView { + public: + STXTView(const BRect &frame, const char *name, uint32 resizeMode, + uint32 flags, TranslatorSettings *settings); + virtual ~STXTView(); + + private: + TranslatorSettings *fSettings; }; -#endif // #ifndef STXTVIEW_H +#endif // STXT_VIEW_H