Laid out views to fit better on-screen. Made it use BAboutWindow and BWindow::CenterOnScreen(). Partial clean-up of code I passed by. A few obvious comments removed. Hopefully an improvement. Still needs a lot of work.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33563 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jonas Sundström 2009-10-12 23:59:35 +00:00
parent 49aa230740
commit 8637183adf
7 changed files with 281 additions and 317 deletions

View File

@ -2,13 +2,14 @@ SubDir HAIKU_TOP src preferences locale ;
UseLibraryHeaders icu ;
UsePrivateHeaders locale ;
UsePrivateHeaders shared ;
Preference Locale :
Locale.cpp
LocaleWindow.cpp
TimeFormatSettingsView.cpp
: be liblocale.so $(TARGET_LIBSTDC++) $(TARGET_LIBSUPC++) libicu-common.so
libicu-data.so
libicu-data.so libshared.a
: Locale.rdef
;
@ -22,3 +23,4 @@ DoCatalogs Locale # application name
: # translations
fi.catkeys fr.catkeys de.catkeys ru.catkeys sv.catkeys
;

View File

@ -7,6 +7,7 @@
#include "Locale.h"
#include "LocaleWindow.h"
#include <AboutWindow.h>
#include <Application.h>
#include <Alert.h>
#include <Catalog.h>
@ -29,38 +30,34 @@ static const uint32 kMsgLocaleSettings = 'LCst';
class Settings {
public:
Settings();
~Settings();
public:
Settings();
~Settings();
const BMessage &Message() const { return fMessage; }
void UpdateFrom(BMessage *message);
const BMessage& Message() const { return fMessage; }
void UpdateFrom(BMessage *message);
private:
status_t Open(BFile *file, int32 mode);
private:
status_t Open(BFile *file, int32 mode);
BMessage fMessage;
bool fUpdated;
BMessage fMessage;
bool fUpdated;
};
class LocalePreflet : public BApplication {
public:
LocalePreflet();
virtual ~LocalePreflet();
public:
LocalePreflet();
virtual ~LocalePreflet();
virtual void ReadyToRun();
virtual void MessageReceived(BMessage *message);
virtual void MessageReceived(BMessage *message);
virtual void AboutRequested();
virtual bool QuitRequested();
virtual void AboutRequested();
virtual bool QuitRequested();
private:
Settings fSettings;
BWindow *fOpenWindow;
BRect fWindowFrame;
BCatalog cat;
private:
Settings fSettings;
LocaleWindow* fLocaleWindow;
BCatalog fCatalog;
};
@ -76,7 +73,6 @@ Settings::Settings()
if (Open(&file, B_READ_ONLY) != B_OK
|| fMessage.Unflatten(&file) != B_OK) {
// set default prefs
fMessage.AddRect("window_frame", BRect(50, 50, 550, 500));
fMessage.AddString("language", "en");
fMessage.AddString("country", "en_US");
return;
@ -86,12 +82,11 @@ Settings::Settings()
Settings::~Settings()
{
// only save the settings if something has changed
if (!fUpdated)
return;
BFile file;
if (Open(&file, B_CREATE_FILE | B_WRITE_ONLY) != B_OK)
if (Open(&file, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY) != B_OK)
return;
fMessage.Flatten(&file);
@ -114,19 +109,23 @@ Settings::Open(BFile *file, int32 mode)
void
Settings::UpdateFrom(BMessage *message)
{
BRect frame;
if (message->FindRect("window_frame", &frame) == B_OK)
fMessage.ReplaceRect("window_frame", frame);
BPoint point;
if (message->FindPoint("window_location", &point) == B_OK) {
fMessage.RemoveName("window_location");
fMessage.AddPoint("window_location", point);
}
BString langName;
// We make sure there is at least one string before erasing the previous
// settings, then we add the remaining ones, if any
if (message->FindString("language",&langName) == B_OK) {
if (message->FindString("language", &langName) == B_OK) {
// Remove any old data as we know we have newer one to replace it
fMessage.RemoveName("language");
for (int i = 0; message->FindString("language", i, &langName) == B_OK;
i++)
for (int i = 0;; i++) {
if (message->FindString("language", i, &langName) != B_OK)
break;
fMessage.AddString("language", langName);
}
}
if (message->FindString("country",&langName) == B_OK)
@ -141,14 +140,19 @@ Settings::UpdateFrom(BMessage *message)
LocalePreflet::LocalePreflet()
: BApplication(kSignature)
:
BApplication(kSignature)
{
fWindowFrame = fSettings.Message().FindRect("window_frame");
be_locale->GetAppCatalog(&fCatalog);
be_locale -> GetAppCatalog(&cat);
fLocaleWindow = new LocaleWindow();
BWindow* window = new LocaleWindow(fWindowFrame);
window->Show();
if (fSettings.Message().HasPoint("window_location")) {
BPoint point = fSettings.Message().FindPoint("window_location");
fLocaleWindow->MoveTo(point);
}
fLocaleWindow->Show();
}
@ -157,18 +161,6 @@ LocalePreflet::~LocalePreflet()
}
void
LocalePreflet::ReadyToRun()
{
// are there already windows open?
if (CountWindows() != 1)
return;
// if not, ask the user to open a file
PostMessage(kMsgOpenOpenWindow);
}
void
LocalePreflet::MessageReceived(BMessage *message)
{
@ -187,20 +179,11 @@ LocalePreflet::MessageReceived(BMessage *message)
void
LocalePreflet::AboutRequested()
{
BAlert *alert = new BAlert("about", TR("Locale\n"
"\twritten by Axel Dörfler\n"
"\tCopyright 2005, Haiku.\n\n"), "Ok");
BTextView *view = alert->TextView();
BFont font;
view->SetStylable(true);
view->GetFont(&font);
font.SetSize(18);
font.SetFace(B_BOLD_FACE);
view->SetFontAndColor(0, 7, &font);
alert->Go();
const char* authors[3];
authors[0] = "Axel Dörfler";
authors[1] = "Adrien Destugues";
authors[2] = NULL;
(new BAboutWindow("Locale", 2005, authors))->Show();
}
@ -218,7 +201,7 @@ int
main(int argc, char **argv)
{
LocalePreflet app;
app.Run();
return 0;
}

View File

@ -1,6 +1,6 @@
/*
* Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Distributed under the terms of the MIT License.
* Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef LOCALE_H
#define LOCALE_H
@ -9,17 +9,11 @@
#include <SupportDefs.h>
extern const char *kSignature;
extern const char* kSignature;
static const uint32 kMsgOpenFilePanel = 'opFp';
static const uint32 kMsgOpenOpenWindow = 'opOw';
static const uint32 kMsgOpenWindowClosed = 'clOw';
static const uint32 kMsgWindowClosed = 'WiCl';
static const uint32 kMsgSettingsChanged = 'SeCh';
static const uint32 kMsgOpenFindWindow = 'OpFw';
static const uint32 kMsgFindWindowClosed = 'clFw';
static const uint32 kMsgFindTarget = 'FTgt';
static const uint32 kMsgFind = 'find';
static const uint32 kMsgSelectLanguage = 'slng';
static const uint32 kMsgDefaults = 'dflt';
static const uint32 kMsgRevert = 'revt';
#endif /* LOCALE_H */

View File

@ -1,6 +1,6 @@
/*
* Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Distributed under the terms of the MIT License.
* Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
* All rights reserved. Distributed under the terms of the MIT License.
*/
@ -13,7 +13,7 @@
#include <Button.h>
#include <Catalog.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <LayoutBuilder.h>
#include <ListView.h>
#include <Locale.h>
#include <LocaleRoster.h>
@ -35,52 +35,25 @@
#define ALPHA 170
#define TEXT_OFFSET 5.0
// Language lists management
// This is a language item. It's a BStringItem but we also want to keep the
// language code and not only the displayName
class LanguageListItem: public BStringItem
{
public:
LanguageListItem(const char* display, const char* code)
: BStringItem(display)
, LanguageCode(code)
LanguageListItem(const char* text, const char* code)
:
BStringItem(text),
fLanguageCode(code)
{}
~LanguageListItem() {};
const inline BString getLanguageCode() { return LanguageCode; }
void Draw(BView *owner, BRect frame);
const inline BString LanguageCode() { return fLanguageCode; }
private:
const BString LanguageCode;
const BString fLanguageCode;
};
void
LanguageListItem::Draw(BView *owner, BRect frame)
{
owner->SetLowColor(255, 255, 255, 255);
owner->FillRect(frame, B_SOLID_LOW);
// label
owner->SetHighColor(0, 0, 0, 255);
font_height fh;
owner->GetFontHeight(&fh);
const char* text = Text();
BString truncatedString(text);
owner->TruncateString(&truncatedString, B_TRUNCATE_MIDDLE,
frame.Width() - TEXT_OFFSET - 4.0);
float height = frame.Height();
float textHeight = fh.ascent + fh.descent;
BPoint textPoint;
textPoint.x = frame.left + TEXT_OFFSET;
textPoint.y = frame.top
+ ceilf(height / 2.0 - textHeight / 2.0 + fh.ascent);
owner->DrawString(truncatedString.String(), textPoint);
}
// This is a language list. Basically, a drag-n-drop enabled list.
class LanguageListView: public BListView
{
public:
@ -107,7 +80,6 @@ class LanguageListView: public BListView
if (fDropIndex < 0 || fDropIndex > count)
fDropIndex = count;
// gather all the items from the BMessage
BList items;
int32 index;
for (int32 i = 0; message->FindInt32("index", i, &index)
@ -115,7 +87,6 @@ class LanguageListView: public BListView
if (BListItem* item = ItemAt(index))
items.AddItem((void*)item);
// handle them
if (items.CountItems() > 0) {
MoveItems(items, fDropIndex);
}
@ -125,7 +96,6 @@ class LanguageListView: public BListView
if (fDropIndex < 0 || fDropIndex > count)
fDropIndex = count;
// gather all the items from the BMessage
int32 index;
for (int32 i = 0; message->FindInt32("index", i, &index)
== B_OK; i++)
@ -224,7 +194,7 @@ LanguageListView::InitiateDrag(BPoint point, int32 index, bool)
itemBounds.bottom = itemBounds.top + ceilf(item->Height());
if (itemBounds.bottom > dragRect.bottom)
itemBounds.bottom = dragRect.bottom;
item->Draw(v, itemBounds);
item->DrawItem(v, itemBounds);
itemBounds.top = itemBounds.bottom + 1.0;
}
// make a black frame arround the edge
@ -324,40 +294,31 @@ LanguageListView::MouseMoved(BPoint where, uint32 transit, const BMessage *msg)
}
const static uint32 kMsgSelectLanguage = 'slng';
const static uint32 kMsgDefaults = 'dflt';
const static uint32 kMsgRevert = 'revt';
LocaleWindow::LocaleWindow(BRect rect)
: BWindow(rect, "Locale", B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS
| B_AUTO_UPDATE_SIZE_LIMITS)
LocaleWindow::LocaleWindow()
:
BWindow(BRect(0, 0, 0, 0), "Locale", B_TITLED_WINDOW, B_NOT_RESIZABLE
| B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
{
BCountry* defaultCountry;
be_locale_roster->GetDefaultCountry(&defaultCountry);
SetLayout(new BGroupLayout(B_HORIZONTAL));
// Buttons at the bottom
BButton *button = new BButton(TR("Defaults"), new BMessage(kMsgDefaults));
BButton* button = new BButton(TR("Defaults"), new BMessage(kMsgDefaults));
fRevertButton = new BButton(TR("Revert"), new BMessage(kMsgRevert));
fRevertButton->SetEnabled(false);
// Tabs
BTabView *tabView = new BTabView("tabview");
// Language tab
BView *tab = new BView(TR("Language"), B_WILL_DRAW);
//tab->SetViewColor(tabView->ViewColor());
tab->SetLayout(new BGroupLayout(B_VERTICAL, 0));
tabView->AddTab(tab);
BTabView* tabView = new BTabView("tabview");
BView* languageTab = new BView(TR("Language"), B_WILL_DRAW);
languageTab->SetLayout(new BGroupLayout(B_VERTICAL, 0));
{
// first list: available languages
LanguageListView *listView = new LanguageListView("available",
B_MULTIPLE_SELECTION_LIST);
BScrollView *scrollView = new BScrollView("scroller", listView,
0, false, true, B_FANCY_BORDER);
B_WILL_DRAW | B_FRAME_EVENTS, false, true);
// Fill the language list from the LocaleRoster data
BMessage installedLanguages;
@ -395,7 +356,7 @@ LocaleWindow::LocaleWindow(BRect rect)
fPreferredListView = new LanguageListView("preferred",
B_MULTIPLE_SELECTION_LIST);
BScrollView *scrollViewEnabled = new BScrollView("scroller",
fPreferredListView, 0, false, true, B_FANCY_BORDER);
fPreferredListView, B_WILL_DRAW | B_FRAME_EVENTS, false, true);
// get the preferred languages from the Settings. Move them here from
// the other list.
@ -408,40 +369,34 @@ LocaleWindow::LocaleWindow(BRect rect)
for (int listPos = 0; LanguageListItem* lli
= static_cast<LanguageListItem*>(listView->ItemAt(listPos));
listPos++) {
if (langCode == lli->getLanguageCode()) {
if (langCode == lli->LanguageCode()) {
fPreferredListView->AddItem(lli);
listView->RemoveItem(lli);
}
}
}
tab->AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10)
.Add(BGroupLayoutBuilder(B_VERTICAL, 10)
languageTab->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 10)
.AddGroup(B_VERTICAL, 10)
.Add(new BStringView("", TR("Available languages")))
.Add(scrollView)
)
.Add(BGroupLayoutBuilder(B_VERTICAL, 10)
.End()
.AddGroup(B_VERTICAL, 10)
.Add(new BStringView("", TR("Preferred languages")))
.Add(scrollViewEnabled)
)
);
.End()
.View());
}
// Country tab
tab = new BView(TR("Country"), B_WILL_DRAW);
//tab->SetViewColor(tabView->ViewColor());
tab->SetLayout(new BGroupLayout(B_VERTICAL, 0));
tabView->AddTab(tab);
BView* countryTab = new BView(TR("Country"), B_WILL_DRAW);
countryTab->SetLayout(new BGroupLayout(B_VERTICAL, 0));
{
BListView* listView = new BListView("country", B_SINGLE_SELECTION_LIST);
BScrollView *scrollView = new BScrollView("scroller",
listView, 0, false, true, B_FANCY_BORDER);
listView, B_WILL_DRAW | B_FRAME_EVENTS, false, true);
BMessage* msg = new BMessage('csel');
listView->SetSelectionMessage(msg);
// get all available countries from ICU
// Use DateFormat::getAvailableLocale so we get only the one we can
@ -449,8 +404,6 @@ LocaleWindow::LocaleWindow(BRect rect)
int32_t localeCount;
const Locale* currentLocale
= Locale::getAvailableLocales(localeCount);
BCountry* defaultCountry;
be_locale_roster->GetDefaultCountry(&defaultCountry);
for (int index = 0; index < localeCount; index++)
{
@ -467,41 +420,37 @@ LocaleWindow::LocaleWindow(BRect rect)
listView->Select(listView->CountItems() - 1);
}
fTimeFormatSettings
= new TimeFormatSettingsView(defaultCountry);
// TODO: find a real solution intead of this hack
listView->SetExplicitMinSize(BSize(300, B_SIZE_UNSET));
tab->AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 5)
.Add(scrollView)
.Add(new BScrollView("advanced", fTimeFormatSettings, 0,
false, true, B_NO_BORDER))
fTimeFormatSettings = new TimeFormatSettingsView(defaultCountry);
countryTab->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 5)
.AddGroup(B_VERTICAL, 3)
.Add(scrollView)
.End()
.Add(fTimeFormatSettings)
.View()
);
listView->ScrollToSelection();
}
// check if the window is on screen
rect = BScreen().Frame();
rect.right -= 20;
rect.bottom -= 20;
tabView->AddTab(languageTab);
tabView->AddTab(countryTab);
BPoint position = Frame().LeftTop();
if (!rect.Contains(position)) {
// center window on screen as it doesn't fit on the saved position
position.x = (rect.Width() - Bounds().Width()) / 2;
position.y = (rect.Height() - Bounds().Height()) / 2;
}
MoveTo(position);
BLayoutBuilder::Group<>(this)
.AddGroup(B_VERTICAL, 3)
.Add(tabView)
.AddGroup(B_HORIZONTAL, 3)
.Add(button)
.Add(fRevertButton)
.AddGlue()
.End()
.SetInsets(5, 5, 5, 5)
.End();
// Layout management
AddChild(BGroupLayoutBuilder(B_VERTICAL, 3)
.Add(tabView)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(button)
.Add(fRevertButton)
.AddGlue()
)
.SetInsets(5, 5, 5, 5)
);
CenterOnScreen();
}
@ -509,11 +458,11 @@ bool
LocaleWindow::QuitRequested()
{
BMessage update(kMsgSettingsChanged);
update.AddRect("window_frame", Frame());
update.AddPoint("window_location", Frame().LeftTop());
int index = 0;
while (index < fPreferredListView->CountItems()) {
update.AddString("language", static_cast<LanguageListItem*>
(fPreferredListView->ItemAt(index))->getLanguageCode());
(fPreferredListView->ItemAt(index))->LanguageCode());
index++;
}
// TODO also save Country tab settings
@ -547,10 +496,10 @@ LocaleWindow::MessageReceived(BMessage *message)
LanguageListItem* lli = static_cast<LanguageListItem*>
(countryList->ItemAt(countryList->CurrentSelection()));
BMessage* newMessage = new BMessage(kMsgSettingsChanged);
newMessage->AddString("country",lli->getLanguageCode());
newMessage->AddString("country",lli->LanguageCode());
be_app_messenger.SendMessage(newMessage);
BCountry* country = new BCountry(lli->getLanguageCode());
BCountry* country = new BCountry(lli->LanguageCode());
fTimeFormatSettings->SetCountry(country);
break;
}

View File

@ -15,7 +15,7 @@ class TimeFormatSettingsView;
class LocaleWindow : public BWindow {
public:
LocaleWindow(BRect rect);
LocaleWindow();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);

View File

@ -7,12 +7,12 @@
#include "TimeFormatSettingsView.h"
#include <Alert.h>
#include <Box.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <Country.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <LayoutBuilder.h>
#include <Locale.h>
#include <LocaleRoster.h>
#include <Message.h>
@ -39,8 +39,8 @@ BMessage*
MenuMessage(const char* format, BMenuField* field)
{
BMessage* msg = new BMessage('FRMT');
msg->AddPointer("dest",field);
msg->AddString("format",format);
msg->AddPointer("dest", field);
msg->AddString("format", format);
return msg;
}
@ -116,26 +116,22 @@ CreateDateMenu(BMenuField** field, bool longFormat = true)
TimeFormatSettingsView::TimeFormatSettingsView(BCountry* country)
: BView("WindowsSettingsView", 0)
, fCountry(country)
:
BView("WindowsSettingsView", B_FRAME_EVENTS),
fCountry(country)
{
SetLayout(new BGroupLayout(B_HORIZONTAL));
// Date
BSeparatorView* dateHeader = new BSeparatorView(TR("Date"));
// Long format
fLongDateExampleView = new BStringView("", "");
for (int i = 0; i < 4; i++) {
CreateDateMenu(&fLongDateMenu[i]);
fLongDateSeparator[i] = new BTextControl("","","",
fLongDateSeparator[i] = new BTextControl("", "", "",
new BMessage(kSettingsContentsModified));
fLongDateSeparator[i]->SetModificationMessage(
new BMessage(kSettingsContentsModified));
}
// Short format
fShortDateExampleView = new BStringView("", "");
for (int i = 0; i < 3; i++) {
@ -154,9 +150,6 @@ TimeFormatSettingsView::TimeFormatSettingsView(BCountry* country)
fSeparatorMenuField = new BMenuField(TR("Separator:"), menu);
// Time
BSeparatorView* timeHeader = new BSeparatorView(TR("Time"));
BBox *clockBox = new BBox("Clock");
clockBox->SetLabel(TR("Clock"));
@ -177,9 +170,6 @@ TimeFormatSettingsView::TimeFormatSettingsView(BCountry* country)
fLongTimeExampleView = new BStringView("", "");
fShortTimeExampleView = new BStringView("", "");
// Numbers
BSeparatorView* numberHeader = new BSeparatorView(TR("Numbers"));
fNumberFormatExampleView = new BStringView("", "");
BTextControl* numberThousand = new BTextControl("",
@ -193,8 +183,6 @@ TimeFormatSettingsView::TimeFormatSettingsView(BCountry* country)
new BMessage(kSettingsContentsModified));
// Unit system (US/Metric) (radio)
// Currency
BSeparatorView* currencyHeader = new BSeparatorView(TR("Currency"));
BTextControl* currencySymbol = new BTextControl("", TR("Currency symbol:"),
"", new BMessage(kSettingsContentsModified));
menu = new BPopUpMenu(TR("Negative marker"));
@ -228,76 +216,120 @@ TimeFormatSettingsView::TimeFormatSettingsView(BCountry* country)
_UpdateExamples();
_ParseDateFormat();
AddChild(BGroupLayoutBuilder(B_VERTICAL, 5)
.Add(dateHeader)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(new BStringView("",TR("Long format:")))
.Add(fLongDateExampleView)
.AddGlue()
)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(fLongDateMenu[0])
.Add(fLongDateSeparator[0])
)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(fLongDateMenu[1])
.Add(fLongDateSeparator[1])
)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(fLongDateMenu[2])
.Add(fLongDateSeparator[2])
)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(fLongDateMenu[3])
.Add(fLongDateSeparator[3])
)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(new BStringView("",TR("Short format:")))
.Add(fShortDateExampleView)
.AddGlue()
)
.Add(fDateMenu[0])
.Add(fDateMenu[1])
.Add(fDateMenu[2])
.Add(fSeparatorMenuField)
fDateBox = new BBox(TR("Date"));
fTimeBox = new BBox(TR("Time"));
fNumbersBox = new BBox(TR("Numbers"));
fCurrencyBox = new BBox(TR("Currency"));
.Add(timeHeader)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(new BStringView("",TR("Long format:")))
.Add(fLongTimeExampleView)
.AddGlue()
)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(new BStringView("",TR("Short format:")))
.Add(fShortTimeExampleView)
.AddGlue()
)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(clockBox)
.AddGlue()
)
fDateBox->SetLabel(TR("Date"));
fTimeBox->SetLabel(TR("Time"));
fNumbersBox->SetLabel(TR("Numbers"));
fCurrencyBox->SetLabel(TR("Currency"));
.Add(numberHeader)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(new BStringView("",TR("Example:")))
.Add(fNumberFormatExampleView)
.AddGlue()
)
.Add(numberThousand)
.Add(numberDecimal)
.Add(numberLeadingZero)
.Add(numberList)
.Add(currencyHeader)
.Add(currencySymbol)
.Add(currencyNegative)
.Add(currencyDecimal)
.Add(currencyLeadingZero)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 3)
.Add(formatBox)
.AddGlue()
)
fDateBox->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 5)
.AddGroup(B_VERTICAL, 5)
.AddGroup(B_HORIZONTAL, 3)
.Add(new BStringView("",TR("Long format:")))
.Add(fLongDateExampleView)
.AddGlue()
.End()
.AddGroup(B_HORIZONTAL, 3)
.Add(fLongDateMenu[0])
.Add(fLongDateSeparator[0])
.End()
.AddGroup(B_HORIZONTAL, 3)
.Add(fLongDateMenu[1])
.Add(fLongDateSeparator[1])
.End()
.AddGroup(B_HORIZONTAL, 3)
.Add(fLongDateMenu[2])
.Add(fLongDateSeparator[2])
.End()
.AddGroup(B_HORIZONTAL, 3)
.Add(fLongDateMenu[3])
.Add(fLongDateSeparator[3])
.End()
.AddGroup(B_HORIZONTAL, 3)
.Add(new BStringView("",TR("Short format:")))
.Add(fShortDateExampleView)
.AddGlue()
.End()
.Add(fDateMenu[0])
.Add(fDateMenu[1])
.Add(fDateMenu[2])
.End()
.SetInsets(5, 5, 5, 5)
.View()
);
fTimeBox->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 5)
.AddGroup(B_VERTICAL, 5)
.AddGroup(B_HORIZONTAL, 3)
.Add(new BStringView("",TR("Long format:")))
.Add(fLongTimeExampleView)
.AddGlue()
.End()
.AddGroup(B_HORIZONTAL, 3)
.Add(new BStringView("",TR("Short format:")))
.Add(fShortTimeExampleView)
.AddGlue()
.End()
.AddGroup(B_HORIZONTAL, 3)
.Add(clockBox)
.AddGlue()
.End()
.AddGlue()
.End()
.SetInsets(5, 5, 5, 5)
.View()
);
fNumbersBox->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 5)
.AddGroup(B_VERTICAL, 5)
.AddGroup(B_HORIZONTAL, 3)
.Add(new BStringView("",TR("Example:")))
.Add(fNumberFormatExampleView)
.AddGlue()
.End()
.Add(numberThousand)
.Add(numberDecimal)
.Add(numberLeadingZero)
.Add(numberList)
.AddGlue()
.End()
.SetInsets(5, 5, 5, 5)
.View()
);
fCurrencyBox->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 5)
.AddGroup(B_VERTICAL, 5)
.Add(currencySymbol)
.Add(currencyNegative)
.Add(currencyDecimal)
.Add(currencyLeadingZero)
.AddGroup(B_HORIZONTAL, 3)
.Add(formatBox)
.AddGlue()
.End()
.AddGlue()
.End()
.SetInsets(5, 5, 5, 5)
.View()
);
AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, 5)
.AddGroup(B_VERTICAL, 5)
.Add(fDateBox)
.Add(fTimeBox)
.AddGlue()
.End()
.AddGroup(B_VERTICAL, 5)
.Add(fNumbersBox)
.Add(fCurrencyBox)
.AddGlue()
.End()
.SetInsets(5, 5, 5, 5)
.View()
);
}
@ -469,7 +501,7 @@ TimeFormatSettingsView::_UpdateLongDateFormatString()
newDateFormat.Append(fDateString[2]);
// TODO save this in the settings preflet and make the roster load it back
fCountry->SetDateFormat(newDateFormat.String(),false);
fCountry->SetDateFormat(newDateFormat.String(), false);
}
@ -689,4 +721,3 @@ TimeFormatSettingsView::_UpdateExamples()
fNumberFormatExampleView->SetText(u_errorName((UErrorCode)Error));
}

View File

@ -1,13 +1,12 @@
/*
** Copyright 2009, Adrien Destugues, pulkomandy@gmail.com. All rights reserved.
** Distributed under the terms of the MIT License.
*/
* Copyright 2009, Adrien Destugues, pulkomandy@gmail.com. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef __TIMEFORMATSETTINGS_H__
#define __TIMEFORMATSETTINGS_H__
#include <Box.h>
#include <String.h>
#include <View.h>
@ -34,51 +33,57 @@ const uint32 kSettingsContentsModified = 'Scmo';
class TimeFormatSettingsView : public BView {
public:
TimeFormatSettingsView(BCountry* country);
public:
TimeFormatSettingsView(BCountry* country);
virtual void MessageReceived(BMessage *message);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message);
virtual void AttachedToWindow();
virtual void SetDefaults();
virtual bool IsDefaultable() const;
virtual void Revert();
virtual void SetCountry(BCountry* country);
virtual void RecordRevertSettings();
virtual bool IsRevertable() const;
virtual void SetDefaults();
virtual bool IsDefaultable() const;
virtual void Revert();
virtual void SetCountry(BCountry* country);
virtual void RecordRevertSettings();
virtual bool IsRevertable() const;
private:
void _UpdateExamples();
void _SendNotices();
void _ParseDateFormat();
void _UpdateLongDateFormatString();
private:
void _UpdateExamples();
void _SendNotices();
void _ParseDateFormat();
void _UpdateLongDateFormatString();
BRadioButton *f24HrRadioButton;
BRadioButton *f12HrRadioButton;
BRadioButton* f24HrRadioButton;
BRadioButton* f12HrRadioButton;
BMenuField *fLongDateMenu[4];
BString fLongDateString[4];
BTextControl* fLongDateSeparator[4];
BMenuField *fDateMenu[3];
BString fDateString[3];
BMenuField* fLongDateMenu[4];
BString fLongDateString[4];
BTextControl* fLongDateSeparator[4];
BMenuField* fDateMenu[3];
BString fDateString[3];
BMenuField *fSeparatorMenuField;
BMenuField* fSeparatorMenuField;
BStringView *fLongDateExampleView;
BStringView *fShortDateExampleView;
BStringView *fLongTimeExampleView;
BStringView *fShortTimeExampleView;
BStringView* fNumberFormatExampleView;
BStringView* fLongDateExampleView;
BStringView* fShortDateExampleView;
BStringView* fLongTimeExampleView;
BStringView* fShortTimeExampleView;
BStringView* fNumberFormatExampleView;
bool f24HrClock;
bool f24HrClock;
FormatSeparator fSeparator;
BString fDateFormat;
FormatSeparator fSeparator;
BString fDateFormat;
BCountry* fCountry;
BCountry* fCountry;
typedef BView _inherited;
BBox* fDateBox;
BBox* fTimeBox;
BBox* fNumbersBox;
BBox* fCurrencyBox;
typedef BView _inherited;
};
#endif