* Fixed various font sensitivity and other issues.

* Worked over config views, they now look much cleaner.
* This fixes bug #214.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16712 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-03-11 18:55:38 +00:00
parent a45369f00a
commit 4316cb15fa
7 changed files with 332 additions and 522 deletions
+57 -102
View File
@@ -1,116 +1,71 @@
/*****************************************************************************/ /*
// BMPView * Copyright 2002-2006, Haiku, Inc.
// BMPView.cpp * Distributed under the terms of the MIT license.
// *
// This BView based object displays information about the BMPTranslator. * Authors:
// * Michael Wilber
// * Axel Dörfler, [email protected]
// Copyright (c) 2002 OpenBeOS Project */
//
// Permission is hereby granted, free of charge, to any person obtaining a /*! A view with information about the BMPTranslator. */
// 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.
/*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include "BMPView.h" #include "BMPView.h"
#include "BMPTranslator.h" #include "BMPTranslator.h"
// --------------------------------------------------------------- #include <StringView.h>
// Constructor
// #include <stdio.h>
// Sets up the view settings
//
// Preconditions: BMPView::BMPView(const BRect &frame, const char *name, uint32 resizeMode,
// uint32 flags, TranslatorSettings *settings)
// Parameters: : BView(frame, name, resizeMode, flags)
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
BMPView::BMPView(const BRect &frame, const char *name,
uint32 resize, uint32 flags, TranslatorSettings *settings)
: BView(frame, name, resize, flags)
{ {
fSettings = settings; fSettings = settings;
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 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() BMPView::~BMPView()
{ {
fSettings->Release(); 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<int>(B_TRANSLATION_MAJOR_VERSION(BMP_TRANSLATOR_VERSION)),
static_cast<int>(B_TRANSLATION_MINOR_VERSION(BMP_TRANSLATOR_VERSION)),
static_cast<int>(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));
}
+21 -45
View File
@@ -1,52 +1,28 @@
/*****************************************************************************/ /*
// BMPView * Copyright 2002-2006, Haiku, Inc.
// BMPView.h * Distributed under the terms of the MIT license.
// *
// This BView based object displays information about the BMPTranslator. * Authors:
// * Michael Wilber
// * Axel Dörfler, [email protected]
// Copyright (c) 2002 OpenBeOS Project */
// #ifndef BMP_VIEW_H
// Permission is hereby granted, free of charge, to any person obtaining a #define BMP_VIEW_H
// 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.
/*****************************************************************************/
#ifndef BMPVIEW_H
#define BMPVIEW_H
#include <View.h>
#include <MenuField.h>
#include <MenuItem.h>
#include "TranslatorSettings.h" #include "TranslatorSettings.h"
class BMPView : public BView { #include <View.h>
public:
BMPView(const BRect &frame, const char *name, uint32 resize,
uint32 flags, TranslatorSettings *settings);
// sets up the view
~BMPView();
// releases settings
virtual void Draw(BRect area);
// draws information about the BMPTranslator class BMPView : public BView {
private: public:
TranslatorSettings *fSettings; 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
+127 -159
View File
@@ -1,189 +1,157 @@
/*****************************************************************************/ /*
// PNGView * Copyright 2003-2006, Haiku, Inc.
// Written by Michael Wilber, OBOS Translation Kit Team * Distributed under the terms of the MIT license.
// *
// PNGView.cpp * Authors:
// * Michael Wilber
// This BView based object displays information about the PNGTranslator. * Axel Dörfler, [email protected]
// */
//
// 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.
/*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <png.h>
#include <Alert.h>
#include "PNGView.h" #include "PNGView.h"
#include "PNGTranslator.h" #include "PNGTranslator.h"
BMessage * #include <Alert.h>
interlace_msg(int option) #include <MenuField.h>
{ #include <MenuItem.h>
BMessage *pmsg = new BMessage(M_PNG_SET_INTERLACE); #include <PopUpMenu.h>
pmsg->AddInt32(PNG_SETTING_INTERLACE, option); #include <StringView.h>
return pmsg; #include <TextView.h>
}
// --------------------------------------------------------------- #include <stdio.h>
// Constructor #include <png.h>
//
// Sets up the view settings
// PNGView::PNGView(const BRect &frame, const char *name, uint32 resizeMode,
// Preconditions: uint32 flags, TranslatorSettings *settings)
// : BView(frame, name, resizeMode, flags | B_FRAME_EVENTS)
// Parameters:
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
PNGView::PNGView(const BRect &frame, const char *name,
uint32 resize, uint32 flags, TranslatorSettings *settings)
: BView(frame, name, resize, flags)
{ {
fSettings = settings; fSettings = settings;
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetViewColor(220,220,220,0);
font_height fontHeight;
// setup PNG interlace options menu be_bold_font->GetHeight(&fontHeight);
fpmnuInterlace = new BPopUpMenu("Interlace Option"); float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
BMenuItem *pitmNone, *pitmAdam7;
pitmNone = new BMenuItem("None", interlace_msg(PNG_INTERLACE_NONE)); BRect rect(10, 10, 200, 10 + height);
pitmAdam7 = new BMenuItem("Adam7", interlace_msg(PNG_INTERLACE_ADAM7)); BStringView *stringView = new BStringView(rect, "title", "PNG Image Translator");
fpmnuInterlace->AddItem(pitmNone); stringView->SetFont(be_bold_font);
fpmnuInterlace->AddItem(pitmAdam7); stringView->ResizeToPreferred();
AddChild(stringView);
fpfldInterlace = new BMenuField(BRect(20, 50, 200, 70),
"PNG Interlace Menu", "Interlacing Type", fpmnuInterlace); float maxWidth = stringView->Bounds().Width();
fpfldInterlace->SetViewColor(ViewColor());
AddChild(fpfldInterlace); rect.OffsetBy(0, height + 10);
char version[256];
// set Interlace option to show the current configuration 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) if (fSettings->SetGetInt32(PNG_SETTING_INTERLACE) == PNG_INTERLACE_NONE)
pitmNone->SetMarked(true); item->SetMarked(true);
else fInterlaceMenu->AddItem(item);
pitmAdam7->SetMarked(true);
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() PNGView::~PNGView()
{ {
fSettings->Release(); fSettings->Release();
} }
void
PNGView::AllAttached() BMessage *
PNGView::_InterlaceMessage(int32 kind)
{ {
// Tell all controls that this view is the target for BMessage* message = new BMessage(M_PNG_SET_INTERLACE);
// messages from controls on this view message->AddInt32(PNG_SETTING_INTERLACE, kind);
BView::AllAttached();
BMessenger msgr(this); return message;
}
void
PNGView::AttachedToWindow()
{
BView::AttachedToWindow();
// set target for interlace options menu items // set target for interlace options menu items
for (int32 i = 0; i < fpmnuInterlace->CountItems(); i++) { fInterlaceMenu->SetTargetForItems(this);
BMenuItem *pitm = fpmnuInterlace->ItemAt(i);
if (pitm)
pitm->SetTarget(msgr);
}
} }
// ---------------------------------------------------------------
// 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<int>(B_TRANSLATION_MAJOR_VERSION(PNG_TRANSLATOR_VERSION)),
static_cast<int>(B_TRANSLATION_MINOR_VERSION(PNG_TRANSLATOR_VERSION)),
static_cast<int>(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 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 // change setting for interlace option
int32 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->SetGetInt32(PNG_SETTING_INTERLACE, &option);
fSettings->SaveSettings(); fSettings->SaveSettings();
} }
} else } else
BView::MessageReceived(pmsg); BView::MessageReceived(message);
} }
+38 -58
View File
@@ -1,70 +1,50 @@
/*****************************************************************************/ /*
// PNGView * Copyright 2003-2006, Haiku, Inc.
// Written by Michael Wilber, OBOS Translation Kit Team * Distributed under the terms of the MIT license.
// *
// PNGView.h * Authors:
// * Michael Wilber
// This BView based object displays information about the PNGTranslator. * Axel Dörfler, [email protected]
// */
// #ifndef PNG_VIEW_H
// Copyright (c) 2003 OpenBeOS Project #define PNG_VIEW_H
//
// 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.
/*****************************************************************************/
#ifndef PNGVIEW_H
#define PNGVIEW_H
#include <View.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include "TranslatorSettings.h" #include "TranslatorSettings.h"
#define PNG_VIEW_WIDTH 300 #include <View.h>
#define PNG_VIEW_HEIGHT 250
class BPopUpMenu;
class BTextView;
// Config panel messages // 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 { class PNGView : public BView {
public: public:
PNGView(const BRect &frame, const char *name, uint32 resize, PNGView(const BRect &frame, const char *name, uint32 resizeMode,
uint32 flags, TranslatorSettings *settings); uint32 flags, TranslatorSettings *settings);
// sets up the view ~PNGView();
~PNGView();
// releases the PNGTranslator settings
virtual void AllAttached(); virtual void AttachedToWindow();
virtual void Draw(BRect area); virtual void FrameResized(float width, float height);
// draws information about the PNGTranslator virtual void MessageReceived(BMessage *message);
virtual void MessageReceived(BMessage *pmsg);
private:
private: BMessage* _InterlaceMessage(int32 kind);
BPopUpMenu *fpmnuInterlace;
BMenuField *fpfldInterlace; private:
BPopUpMenu* fInterlaceMenu;
TranslatorSettings *fSettings; BTextView* fCopyrightView;
// the actual settings for the translator, TranslatorSettings* fSettings;
// shared with the translator // the actual settings for the translator,
// shared with the translator
}; };
#endif // #ifndef PNGVIEW_H #endif // PNG_VIEW_H
+11 -4
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2005, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2006, Axel Dörfler, [email protected]. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -10,7 +10,6 @@
#include <StringView.h> #include <StringView.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
ConfigView::ConfigView(const BRect &frame, uint32 resize, uint32 flags) ConfigView::ConfigView(const BRect &frame, uint32 resize, uint32 flags)
@@ -28,9 +27,11 @@ ConfigView::ConfigView(const BRect &frame, uint32 resize, uint32 flags)
stringView->ResizeToPreferred(); stringView->ResizeToPreferred();
AddChild(stringView); AddChild(stringView);
float maxWidth = stringView->Bounds().Width();
rect.OffsetBy(0, height + 10); rect.OffsetBy(0, height + 10);
char version[256]; 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_MAJOR_VERSION(RTF_TRANSLATOR_VERSION)),
int(B_TRANSLATION_MINOR_VERSION(RTF_TRANSLATOR_VERSION)), int(B_TRANSLATION_MINOR_VERSION(RTF_TRANSLATOR_VERSION)),
int(B_TRANSLATION_REVISION_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(); stringView->ResizeToPreferred();
AddChild(stringView); AddChild(stringView);
if (stringView->Bounds().Width() > maxWidth)
maxWidth = stringView->Bounds().Width();
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
rect.OffsetBy(0, height + 5); 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(); stringView->ResizeToPreferred();
AddChild(stringView); AddChild(stringView);
if (maxWidth + 20 > Bounds().Width())
ResizeTo(maxWidth + 20, Bounds().Height());
} }
+57 -107
View File
@@ -1,120 +1,70 @@
/*****************************************************************************/ /*
// STXTView * Copyright 2002-2006, Haiku, Inc.
// Written by Michael Wilber, OBOS Translation Kit Team * Distributed under the terms of the MIT license.
// *
// STXTView.cpp * Authors:
// * Michael Wilber
// This BView based object displays information about the STXTTranslator. * Axel Dörfler, [email protected]
// */
//
// Copyright (c) 2002 OpenBeOS Project /*! A view with information about the STXTTranslator. */
//
// 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.
/*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include "STXTView.h" #include "STXTView.h"
#include "STXTTranslator.h" #include "STXTTranslator.h"
// --------------------------------------------------------------- #include <StringView.h>
// Constructor
// #include <stdio.h>
// Sets up the view settings
//
// Preconditions: STXTView::STXTView(const BRect &frame, const char *name, uint32 resizeMode,
// uint32 flags, TranslatorSettings *settings)
// Parameters: : BView(frame, name, resizeMode, flags)
//
// Postconditions:
//
// Returns:
// ---------------------------------------------------------------
STXTView::STXTView(const BRect &frame, const char *name,
uint32 resize, uint32 flags, TranslatorSettings *settings)
: BView(frame, name, resize, flags)
{ {
fSettings = settings; fSettings = settings;
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 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() STXTView::~STXTView()
{ {
fSettings->Release(); 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<int>(B_TRANSLATION_MAJOR_VERSION(STXT_TRANSLATOR_VERSION)),
static_cast<int>(B_TRANSLATION_MINOR_VERSION(STXT_TRANSLATOR_VERSION)),
static_cast<int>(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));
}
+21 -47
View File
@@ -1,54 +1,28 @@
/*****************************************************************************/ /*
// STXTView * Copyright 2002-2006, Haiku, Inc.
// Written by Michael Wilber, OBOS Translation Kit Team * Distributed under the terms of the MIT license.
// *
// STXTView.h * Authors:
// * Michael Wilber
// This BView based object displays information about the STXTTranslator. * Axel Dörfler, [email protected]
// */
// #ifndef STXT_VIEW_H
// Copyright (c) 2002 OpenBeOS Project #define STXT_VIEW_H
//
// 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.
/*****************************************************************************/
#ifndef STXTVIEW_H
#define STXTVIEW_H
#include <View.h>
#include <MenuField.h>
#include <MenuItem.h>
#include "TranslatorSettings.h" #include "TranslatorSettings.h"
class STXTView : public BView { #include <View.h>
public:
STXTView(const BRect &frame, const char *name, uint32 resize,
uint32 flags, TranslatorSettings *settings);
// sets up the view
~STXTView();
// releases settings
virtual void Draw(BRect area);
// draws information about the STXTTranslator class STXTView : public BView {
private: public:
TranslatorSettings *fSettings; 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