xref: /haiku/src/preferences/locale/FormatSettingsView.cpp (revision 2a5e33a98056c2b92d46a6c9aae6da808c8524b1)
1fb816644SAdrien Destugues /*
2fb816644SAdrien Destugues  * Copyright 2009, Adrien Destugues, pulkomandy@gmail.com. All rights reserved.
3fb816644SAdrien Destugues  * Distributed under the terms of the MIT License.
4fb816644SAdrien Destugues  */
5fb816644SAdrien Destugues 
6fb816644SAdrien Destugues 
7fb816644SAdrien Destugues #include "FormatSettingsView.h"
86bb481c7SOliver Tappe 
96bb481c7SOliver Tappe #include <stdlib.h>
10fb816644SAdrien Destugues 
11fb816644SAdrien Destugues #include <Alert.h>
12fb816644SAdrien Destugues #include <Application.h>
13fb816644SAdrien Destugues #include <Catalog.h>
14fb816644SAdrien Destugues #include <CheckBox.h>
15fb816644SAdrien Destugues #include <ControlLook.h>
16*2a5e33a9SAdrien Destugues #include <DateFormat.h>
176fd2f4a0SOliver Tappe #include <GridLayout.h>
186fd2f4a0SOliver Tappe #include <GridLayoutBuilder.h>
19fb816644SAdrien Destugues #include <GroupLayout.h>
20fb816644SAdrien Destugues #include <GroupLayoutBuilder.h>
21fb816644SAdrien Destugues #include <LayoutBuilder.h>
22fb816644SAdrien Destugues #include <Locale.h>
23fb816644SAdrien Destugues #include <MutableLocaleRoster.h>
24fb816644SAdrien Destugues #include <Message.h>
25fb816644SAdrien Destugues #include <Menu.h>
26fb816644SAdrien Destugues #include <MenuField.h>
27fb816644SAdrien Destugues #include <MenuItem.h>
28fb816644SAdrien Destugues #include <PopUpMenu.h>
29fb816644SAdrien Destugues #include <RadioButton.h>
30fb816644SAdrien Destugues #include <ScrollView.h>
31fb816644SAdrien Destugues #include <ScrollBar.h>
32fb816644SAdrien Destugues #include <SeparatorView.h>
336fd2f4a0SOliver Tappe #include <SpaceLayoutItem.h>
34fb816644SAdrien Destugues #include <String.h>
35fb816644SAdrien Destugues #include <StringView.h>
36fb816644SAdrien Destugues #include <TextControl.h>
37fb816644SAdrien Destugues #include <Window.h>
38fb816644SAdrien Destugues 
396bb481c7SOliver Tappe #include "LocalePreflet.h"
40bca1690bSAdrien Destugues 
41fb816644SAdrien Destugues 
4225dc253dSIngo Weinhold using BPrivate::MutableLocaleRoster;
43fb816644SAdrien Destugues 
44fb816644SAdrien Destugues 
45546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
46546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "TimeFormatSettings"
47fb816644SAdrien Destugues 
48fb816644SAdrien Destugues 
49fb816644SAdrien Destugues // #pragma mark -
50fb816644SAdrien Destugues 
51fb816644SAdrien Destugues 
526fd2f4a0SOliver Tappe FormatSettingsView::FormatSettingsView()
53fb816644SAdrien Destugues 	:
546fd2f4a0SOliver Tappe 	BView("WindowsSettingsView", B_FRAME_EVENTS)
55fb816644SAdrien Destugues {
566fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox = new BCheckBox(
576fd2f4a0SOliver Tappe 		B_TRANSLATE("Use month/day-names from preferred language"),
586fd2f4a0SOliver Tappe 		new BMessage(kStringsLanguageChange));
596fd2f4a0SOliver Tappe 
606fd2f4a0SOliver Tappe 	BStringView* fullDateLabel
616fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Full format:"));
626fd2f4a0SOliver Tappe 	fullDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
636fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
646fd2f4a0SOliver Tappe 	BStringView* longDateLabel
656fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Long format:"));
666fd2f4a0SOliver Tappe 	longDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
676fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
686fd2f4a0SOliver Tappe 	BStringView* mediumDateLabel
696fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Medium format:"));
706fd2f4a0SOliver Tappe 	mediumDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
716fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
726fd2f4a0SOliver Tappe 	BStringView* shortDateLabel
736fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Short format:"));
746fd2f4a0SOliver Tappe 	shortDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
756fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
766fd2f4a0SOliver Tappe 
776fd2f4a0SOliver Tappe 	fFullDateExampleView = new BStringView("", "");
786fd2f4a0SOliver Tappe 	fFullDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
796fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
80fb816644SAdrien Destugues 	fLongDateExampleView = new BStringView("", "");
816fd2f4a0SOliver Tappe 	fLongDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
826fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
836fd2f4a0SOliver Tappe 	fMediumDateExampleView = new BStringView("", "");
846fd2f4a0SOliver Tappe 	fMediumDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
856fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
86fb816644SAdrien Destugues 	fShortDateExampleView = new BStringView("", "");
876fd2f4a0SOliver Tappe 	fShortDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
886fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
89fb816644SAdrien Destugues 
906fd2f4a0SOliver Tappe 	f24HourRadioButton = new BRadioButton("", B_TRANSLATE("24 hour"),
91fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
926fd2f4a0SOliver Tappe 	f12HourRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"),
93fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
94fb816644SAdrien Destugues 
95fb816644SAdrien Destugues 	float spacing = be_control_look->DefaultItemSpacing();
96fb816644SAdrien Destugues 
976fd2f4a0SOliver Tappe 	BStringView* fullTimeLabel
986fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Full format:"));
996fd2f4a0SOliver Tappe 	fullTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1006fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1016fd2f4a0SOliver Tappe 	BStringView* longTimeLabel
1026fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Long format:"));
1036fd2f4a0SOliver Tappe 	longTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1046fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1056fd2f4a0SOliver Tappe 	BStringView* mediumTimeLabel
1066fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Medium format:"));
1076fd2f4a0SOliver Tappe 	mediumTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1086fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1096fd2f4a0SOliver Tappe 	BStringView* shortTimeLabel
1106fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Short format:"));
1116fd2f4a0SOliver Tappe 	shortTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1126fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1136fd2f4a0SOliver Tappe 
1146fd2f4a0SOliver Tappe 	fFullTimeExampleView = new BStringView("", "");
1156fd2f4a0SOliver Tappe 	fFullTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1166fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
117fb816644SAdrien Destugues 	fLongTimeExampleView = new BStringView("", "");
1186fd2f4a0SOliver Tappe 	fLongTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1196fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1206fd2f4a0SOliver Tappe 	fMediumTimeExampleView = new BStringView("", "");
1216fd2f4a0SOliver Tappe 	fMediumTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1226fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
123fb816644SAdrien Destugues 	fShortTimeExampleView = new BStringView("", "");
1246fd2f4a0SOliver Tappe 	fShortTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1256fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
126fb816644SAdrien Destugues 
1276fd2f4a0SOliver Tappe 	BStringView* positiveNumberLabel
1286fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Positive:"));
1296fd2f4a0SOliver Tappe 	positiveNumberLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1306fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1316fd2f4a0SOliver Tappe 	BStringView* negativeNumberLabel
1326fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Negative:"));
1336fd2f4a0SOliver Tappe 	negativeNumberLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1346fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
135fb816644SAdrien Destugues 
1366fd2f4a0SOliver Tappe 	fPositiveNumberExampleView = new BStringView("", "");
1376fd2f4a0SOliver Tappe 	fPositiveNumberExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1386fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1396fd2f4a0SOliver Tappe 	fNegativeNumberExampleView = new BStringView("", "");
1406fd2f4a0SOliver Tappe 	fNegativeNumberExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1416fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
142fb816644SAdrien Destugues 
1436fd2f4a0SOliver Tappe 	BStringView* positiveMonetaryLabel
1446fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Positive:"));
1456fd2f4a0SOliver Tappe 	positiveMonetaryLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1466fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1476fd2f4a0SOliver Tappe 	BStringView* negativeMonetaryLabel
1486fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Negative:"));
1496fd2f4a0SOliver Tappe 	negativeMonetaryLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1506fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
151fb816644SAdrien Destugues 
1526fd2f4a0SOliver Tappe 	fPositiveMonetaryExampleView = new BStringView("", "");
1536fd2f4a0SOliver Tappe 	fPositiveMonetaryExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1546fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1556fd2f4a0SOliver Tappe 	fNegativeMonetaryExampleView = new BStringView("", "");
1566fd2f4a0SOliver Tappe 	fNegativeMonetaryExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1576fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
158fb816644SAdrien Destugues 
1596fd2f4a0SOliver Tappe 	Refresh(true);
160fb816644SAdrien Destugues 
161fb816644SAdrien Destugues 	fDateBox = new BBox(B_TRANSLATE("Date"));
162fb816644SAdrien Destugues 	fTimeBox = new BBox(B_TRANSLATE("Time"));
1636fd2f4a0SOliver Tappe 	fNumberBox = new BBox(B_TRANSLATE("Numbers"));
1646fd2f4a0SOliver Tappe 	fMonetaryBox = new BBox(B_TRANSLATE("Currency"));
165fb816644SAdrien Destugues 
166fb816644SAdrien Destugues 	fDateBox->SetLabel(B_TRANSLATE("Date"));
167fb816644SAdrien Destugues 	fTimeBox->SetLabel(B_TRANSLATE("Time"));
1686fd2f4a0SOliver Tappe 	fNumberBox->SetLabel(B_TRANSLATE("Numbers"));
1696fd2f4a0SOliver Tappe 	fMonetaryBox->SetLabel(B_TRANSLATE("Currency"));
170fb816644SAdrien Destugues 
1716fd2f4a0SOliver Tappe 	fDateBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
17225fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
1736fd2f4a0SOliver Tappe 		.Add(fullDateLabel, 0, 0)
1746fd2f4a0SOliver Tappe 		.Add(fFullDateExampleView, 1, 0)
1756fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
1766fd2f4a0SOliver Tappe 		.Add(longDateLabel, 0, 1)
1776fd2f4a0SOliver Tappe 		.Add(fLongDateExampleView, 1, 1)
1786fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
1796fd2f4a0SOliver Tappe 		.Add(mediumDateLabel, 0, 2)
1806fd2f4a0SOliver Tappe 		.Add(fMediumDateExampleView, 1, 2)
1816fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 2)
1826fd2f4a0SOliver Tappe 		.Add(shortDateLabel, 0, 3)
1836fd2f4a0SOliver Tappe 		.Add(fShortDateExampleView, 1, 3)
1846fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 3)
18525fd5c7bSAlex Wilson 		.View());
186fb816644SAdrien Destugues 
1876fd2f4a0SOliver Tappe 	fTimeBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
18825fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
1896fd2f4a0SOliver Tappe 		.AddGroup(B_HORIZONTAL, spacing, 0, 0, 2)
1906fd2f4a0SOliver Tappe 			.Add(f24HourRadioButton, 0)
1916fd2f4a0SOliver Tappe 			.Add(f12HourRadioButton, 0)
192fb816644SAdrien Destugues 			.AddGlue()
193fb816644SAdrien Destugues 			.End()
1946fd2f4a0SOliver Tappe 		.Add(fullTimeLabel, 0, 1)
1956fd2f4a0SOliver Tappe 		.Add(fFullTimeExampleView, 1, 1)
1966fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
1976fd2f4a0SOliver Tappe 		.Add(longTimeLabel, 0, 2)
1986fd2f4a0SOliver Tappe 		.Add(fLongTimeExampleView, 1, 2)
1996fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 2)
2006fd2f4a0SOliver Tappe 		.Add(mediumTimeLabel, 0, 3)
2016fd2f4a0SOliver Tappe 		.Add(fMediumTimeExampleView, 1, 3)
2026fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 3)
2036fd2f4a0SOliver Tappe 		.Add(shortTimeLabel, 0, 4)
2046fd2f4a0SOliver Tappe 		.Add(fShortTimeExampleView, 1, 4)
2056fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 4)
20625fd5c7bSAlex Wilson 		.View());
207fb816644SAdrien Destugues 
2086fd2f4a0SOliver Tappe 	fNumberBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
20925fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
2106fd2f4a0SOliver Tappe 		.Add(positiveNumberLabel, 0, 0)
2116fd2f4a0SOliver Tappe 		.Add(fPositiveNumberExampleView, 1, 0)
2126fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
2136fd2f4a0SOliver Tappe 		.Add(negativeNumberLabel, 0, 1)
2146fd2f4a0SOliver Tappe 		.Add(fNegativeNumberExampleView, 1, 1)
2156fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
21625fd5c7bSAlex Wilson 		.View());
217fb816644SAdrien Destugues 
2186fd2f4a0SOliver Tappe 	fMonetaryBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
21925fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
2206fd2f4a0SOliver Tappe 		.Add(positiveMonetaryLabel, 0, 0)
2216fd2f4a0SOliver Tappe 		.Add(fPositiveMonetaryExampleView, 1, 0)
2226fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
2236fd2f4a0SOliver Tappe 		.Add(negativeMonetaryLabel, 0, 1)
2246fd2f4a0SOliver Tappe 		.Add(fNegativeMonetaryExampleView, 1, 1)
2256fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
22625fd5c7bSAlex Wilson 		.View());
227fb816644SAdrien Destugues 
2286fd2f4a0SOliver Tappe 	BGroupLayout* rootLayout = new BGroupLayout(B_VERTICAL, spacing);
22925fd5c7bSAlex Wilson 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
23025fd5c7bSAlex Wilson 	SetLayout(rootLayout);
23125fd5c7bSAlex Wilson 	BLayoutBuilder::Group<>(rootLayout)
2326fd2f4a0SOliver Tappe 		.Add(fUseLanguageStringsCheckBox)
233fb816644SAdrien Destugues 		.Add(fDateBox)
234fb816644SAdrien Destugues 		.Add(fTimeBox)
2356fd2f4a0SOliver Tappe 		.AddGroup(B_HORIZONTAL, spacing)
2366fd2f4a0SOliver Tappe 			.Add(fNumberBox)
2376fd2f4a0SOliver Tappe 			.Add(fMonetaryBox)
238fb816644SAdrien Destugues 			.AddGlue()
239fb816644SAdrien Destugues 			.End()
24025fd5c7bSAlex Wilson 		.AddGlue();
241fb816644SAdrien Destugues }
242fb816644SAdrien Destugues 
243fb816644SAdrien Destugues 
2446fd2f4a0SOliver Tappe FormatSettingsView::~FormatSettingsView()
245fb816644SAdrien Destugues {
246fb816644SAdrien Destugues }
247fb816644SAdrien Destugues 
248fb816644SAdrien Destugues 
249fb816644SAdrien Destugues void
2506fd2f4a0SOliver Tappe FormatSettingsView::AttachedToWindow()
251fb816644SAdrien Destugues {
2526fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox->SetTarget(this);
2536fd2f4a0SOliver Tappe 	f24HourRadioButton->SetTarget(this);
2546fd2f4a0SOliver Tappe 	f12HourRadioButton->SetTarget(this);
255fb816644SAdrien Destugues }
256fb816644SAdrien Destugues 
257fb816644SAdrien Destugues 
258fb816644SAdrien Destugues void
2596fd2f4a0SOliver Tappe FormatSettingsView::MessageReceived(BMessage* message)
260fb816644SAdrien Destugues {
261fb816644SAdrien Destugues 	switch (message->what) {
26231c0024dSJohn Scipione 		case B_LOCALE_CHANGED:
26331c0024dSJohn Scipione 		{
26431c0024dSJohn Scipione 			// Time updated 12/24 hour clock
26531c0024dSJohn Scipione 			BFormattingConventions conventions;
26631c0024dSJohn Scipione 			BLocale::Default()->GetFormattingConventions(&conventions);
26731c0024dSJohn Scipione 			if (conventions.Use24HourClock())
26831c0024dSJohn Scipione 				f24HourRadioButton->SetValue(B_CONTROL_ON);
26931c0024dSJohn Scipione 			else
27031c0024dSJohn Scipione 				f12HourRadioButton->SetValue(B_CONTROL_ON);
27131c0024dSJohn Scipione 
27231c0024dSJohn Scipione 			_UpdateExamples();
27331c0024dSJohn Scipione 			Window()->PostMessage(kMsgSettingsChanged);
27431c0024dSJohn Scipione 			break;
27531c0024dSJohn Scipione 		}
27631c0024dSJohn Scipione 
277fb816644SAdrien Destugues 		case kClockFormatChange:
278fb816644SAdrien Destugues 		{
2796fd2f4a0SOliver Tappe 			BFormattingConventions conventions;
28025dc253dSIngo Weinhold 			BLocale::Default()->GetFormattingConventions(&conventions);
2816fd2f4a0SOliver Tappe 			conventions.SetExplicitUse24HourClock(
28231c0024dSJohn Scipione 				f24HourRadioButton->Value() == B_CONTROL_ON);
28325dc253dSIngo Weinhold 			MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
28425dc253dSIngo Weinhold 				conventions);
285fb816644SAdrien Destugues 
286fb816644SAdrien Destugues 			_UpdateExamples();
2876fd2f4a0SOliver Tappe 			Window()->PostMessage(kMsgSettingsChanged);
2886fd2f4a0SOliver Tappe 			break;
2896fd2f4a0SOliver Tappe 		}
2906fd2f4a0SOliver Tappe 
2916fd2f4a0SOliver Tappe 		case kStringsLanguageChange:
2926fd2f4a0SOliver Tappe 		{
2936fd2f4a0SOliver Tappe 			BFormattingConventions conventions;
29425dc253dSIngo Weinhold 			BLocale::Default()->GetFormattingConventions(&conventions);
2956fd2f4a0SOliver Tappe 			conventions.SetUseStringsFromPreferredLanguage(
2966fd2f4a0SOliver Tappe 				fUseLanguageStringsCheckBox->Value() ? true : false);
29725dc253dSIngo Weinhold 			MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
29825dc253dSIngo Weinhold 				conventions);
2996fd2f4a0SOliver Tappe 
3006fd2f4a0SOliver Tappe 			_UpdateExamples();
3016fd2f4a0SOliver Tappe 
3026fd2f4a0SOliver Tappe 			Window()->PostMessage(kMsgSettingsChanged);
303fb816644SAdrien Destugues 			break;
304fb816644SAdrien Destugues 		}
305fb816644SAdrien Destugues 
306fb816644SAdrien Destugues 		default:
307fb816644SAdrien Destugues 			BView::MessageReceived(message);
308fb816644SAdrien Destugues 	}
309fb816644SAdrien Destugues }
310fb816644SAdrien Destugues 
311fb816644SAdrien Destugues 
312fb816644SAdrien Destugues void
3136fd2f4a0SOliver Tappe FormatSettingsView::Revert()
314fb816644SAdrien Destugues {
31525dc253dSIngo Weinhold 	MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
31625dc253dSIngo Weinhold 		fInitialConventions);
317bca1690bSAdrien Destugues 
318fb816644SAdrien Destugues 	_UpdateExamples();
319fb816644SAdrien Destugues }
320fb816644SAdrien Destugues 
321fb816644SAdrien Destugues 
322fb816644SAdrien Destugues void
3236fd2f4a0SOliver Tappe FormatSettingsView::Refresh(bool setInitial)
324fb816644SAdrien Destugues {
3256fd2f4a0SOliver Tappe 	BFormattingConventions conventions;
32625dc253dSIngo Weinhold 	BLocale::Default()->GetFormattingConventions(&conventions);
3276fd2f4a0SOliver Tappe 	if (setInitial)
3286fd2f4a0SOliver Tappe 		fInitialConventions = conventions;
3296fd2f4a0SOliver Tappe 
3306fd2f4a0SOliver Tappe 	if (!conventions.Use24HourClock()) {
3316fd2f4a0SOliver Tappe 		f12HourRadioButton->SetValue(B_CONTROL_ON);
3326fd2f4a0SOliver Tappe 		fLocaleIs24Hour = false;
3336fd2f4a0SOliver Tappe 	} else {
3346fd2f4a0SOliver Tappe 		f24HourRadioButton->SetValue(B_CONTROL_ON);
3356fd2f4a0SOliver Tappe 		fLocaleIs24Hour = true;
3366fd2f4a0SOliver Tappe 	}
3376fd2f4a0SOliver Tappe 
3386fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox->SetValue(
3396fd2f4a0SOliver Tappe 		conventions.UseStringsFromPreferredLanguage()
3406fd2f4a0SOliver Tappe 			? B_CONTROL_ON : B_CONTROL_OFF);
3416fd2f4a0SOliver Tappe 
3426fd2f4a0SOliver Tappe 	_UpdateExamples();
343fb816644SAdrien Destugues }
344fb816644SAdrien Destugues 
345fb816644SAdrien Destugues 
3466fd2f4a0SOliver Tappe // Return true if the Revert button should be enabled (i.e. something has been
347fb816644SAdrien Destugues // changed)
348fb816644SAdrien Destugues bool
3496fd2f4a0SOliver Tappe FormatSettingsView::IsReversible() const
350fb816644SAdrien Destugues {
3516fd2f4a0SOliver Tappe 	BFormattingConventions conventions;
35225dc253dSIngo Weinhold 	BLocale::Default()->GetFormattingConventions(&conventions);
353fb816644SAdrien Destugues 
3546fd2f4a0SOliver Tappe 	return conventions != fInitialConventions;
355fb816644SAdrien Destugues }
356fb816644SAdrien Destugues 
357fb816644SAdrien Destugues 
358fb816644SAdrien Destugues void
3596fd2f4a0SOliver Tappe FormatSettingsView::_UpdateExamples()
360fb816644SAdrien Destugues {
361fb816644SAdrien Destugues 	time_t timeValue = (time_t)time(NULL);
3626fd2f4a0SOliver Tappe 	BString result;
363fb816644SAdrien Destugues 
364*2a5e33a9SAdrien Destugues 	BDateFormat::Default()->Format(&result, timeValue, B_FULL_DATE_FORMAT);
3656fd2f4a0SOliver Tappe 	fFullDateExampleView->SetText(result);
366fb816644SAdrien Destugues 
367*2a5e33a9SAdrien Destugues 	BDateFormat::Default()->Format(&result, timeValue, B_LONG_DATE_FORMAT);
3686fd2f4a0SOliver Tappe 	fLongDateExampleView->SetText(result);
369fb816644SAdrien Destugues 
370*2a5e33a9SAdrien Destugues 	BDateFormat::Default()->Format(&result, timeValue, B_MEDIUM_DATE_FORMAT);
3716fd2f4a0SOliver Tappe 	fMediumDateExampleView->SetText(result);
372fb816644SAdrien Destugues 
373*2a5e33a9SAdrien Destugues 	BDateFormat::Default()->Format(&result, timeValue, B_SHORT_DATE_FORMAT);
3746fd2f4a0SOliver Tappe 	fShortDateExampleView->SetText(result);
375fb816644SAdrien Destugues 
37625dc253dSIngo Weinhold 	BLocale::Default()->FormatTime(&result, timeValue, B_FULL_TIME_FORMAT);
3776fd2f4a0SOliver Tappe 	fFullTimeExampleView->SetText(result);
3786fd2f4a0SOliver Tappe 
37925dc253dSIngo Weinhold 	BLocale::Default()->FormatTime(&result, timeValue, B_LONG_TIME_FORMAT);
3806fd2f4a0SOliver Tappe 	fLongTimeExampleView->SetText(result);
3816fd2f4a0SOliver Tappe 
38225dc253dSIngo Weinhold 	BLocale::Default()->FormatTime(&result, timeValue, B_MEDIUM_TIME_FORMAT);
3836fd2f4a0SOliver Tappe 	fMediumTimeExampleView->SetText(result);
3846fd2f4a0SOliver Tappe 
38525dc253dSIngo Weinhold 	BLocale::Default()->FormatTime(&result, timeValue, B_SHORT_TIME_FORMAT);
3866fd2f4a0SOliver Tappe 	fShortTimeExampleView->SetText(result);
3876fd2f4a0SOliver Tappe 
38825dc253dSIngo Weinhold 	status_t status = BLocale::Default()->FormatNumber(&result, 1234.5678);
3896fd2f4a0SOliver Tappe 	if (status == B_OK)
3906fd2f4a0SOliver Tappe 		fPositiveNumberExampleView->SetText(result);
391fb816644SAdrien Destugues 	else
3926fd2f4a0SOliver Tappe 		fPositiveNumberExampleView->SetText("ERROR");
393fb816644SAdrien Destugues 
39425dc253dSIngo Weinhold 	status = BLocale::Default()->FormatNumber(&result, -1234.5678);
3956fd2f4a0SOliver Tappe 	if (status == B_OK)
3966fd2f4a0SOliver Tappe 		fNegativeNumberExampleView->SetText(result);
3979e773899SAdrien Destugues 	else
3986fd2f4a0SOliver Tappe 		fNegativeNumberExampleView->SetText("ERROR");
399bca1690bSAdrien Destugues 
40025dc253dSIngo Weinhold 	status = BLocale::Default()->FormatMonetary(&result, 1234.56);
4016fd2f4a0SOliver Tappe 	if (status == B_OK)
4026fd2f4a0SOliver Tappe 		fPositiveMonetaryExampleView->SetText(result);
4036fd2f4a0SOliver Tappe 	else
4046fd2f4a0SOliver Tappe 		fPositiveMonetaryExampleView->SetText("ERROR");
405bca1690bSAdrien Destugues 
40625dc253dSIngo Weinhold 	status = BLocale::Default()->FormatMonetary(&result, -1234.56);
4076fd2f4a0SOliver Tappe 	if (status == B_OK)
4086fd2f4a0SOliver Tappe 		fNegativeMonetaryExampleView->SetText(result);
4096fd2f4a0SOliver Tappe 	else
4106fd2f4a0SOliver Tappe 		fNegativeMonetaryExampleView->SetText("ERROR");
411fb816644SAdrien Destugues }
412