xref: /haiku/src/preferences/locale/FormatSettingsView.cpp (revision 03b2550ef1fba975beb15689659a4a5f38986aa0)
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>
162a5e33a9SAdrien 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>
37*03b2550eSAdrien Destugues #include <TimeFormat.h>
38fb816644SAdrien Destugues #include <Window.h>
39fb816644SAdrien Destugues 
406bb481c7SOliver Tappe #include "LocalePreflet.h"
41bca1690bSAdrien Destugues 
42fb816644SAdrien Destugues 
4325dc253dSIngo Weinhold using BPrivate::MutableLocaleRoster;
44fb816644SAdrien Destugues 
45fb816644SAdrien Destugues 
46546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
47546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "TimeFormatSettings"
48fb816644SAdrien Destugues 
49fb816644SAdrien Destugues 
50fb816644SAdrien Destugues // #pragma mark -
51fb816644SAdrien Destugues 
52fb816644SAdrien Destugues 
536fd2f4a0SOliver Tappe FormatSettingsView::FormatSettingsView()
54fb816644SAdrien Destugues 	:
556fd2f4a0SOliver Tappe 	BView("WindowsSettingsView", B_FRAME_EVENTS)
56fb816644SAdrien Destugues {
576fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox = new BCheckBox(
586fd2f4a0SOliver Tappe 		B_TRANSLATE("Use month/day-names from preferred language"),
596fd2f4a0SOliver Tappe 		new BMessage(kStringsLanguageChange));
606fd2f4a0SOliver Tappe 
616fd2f4a0SOliver Tappe 	BStringView* fullDateLabel
626fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Full format:"));
636fd2f4a0SOliver Tappe 	fullDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
646fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
656fd2f4a0SOliver Tappe 	BStringView* longDateLabel
666fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Long format:"));
676fd2f4a0SOliver Tappe 	longDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
686fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
696fd2f4a0SOliver Tappe 	BStringView* mediumDateLabel
706fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Medium format:"));
716fd2f4a0SOliver Tappe 	mediumDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
726fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
736fd2f4a0SOliver Tappe 	BStringView* shortDateLabel
746fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Short format:"));
756fd2f4a0SOliver Tappe 	shortDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
766fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
776fd2f4a0SOliver Tappe 
786fd2f4a0SOliver Tappe 	fFullDateExampleView = new BStringView("", "");
796fd2f4a0SOliver Tappe 	fFullDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
806fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
81fb816644SAdrien Destugues 	fLongDateExampleView = new BStringView("", "");
826fd2f4a0SOliver Tappe 	fLongDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
836fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
846fd2f4a0SOliver Tappe 	fMediumDateExampleView = new BStringView("", "");
856fd2f4a0SOliver Tappe 	fMediumDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
866fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
87fb816644SAdrien Destugues 	fShortDateExampleView = new BStringView("", "");
886fd2f4a0SOliver Tappe 	fShortDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
896fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
90fb816644SAdrien Destugues 
916fd2f4a0SOliver Tappe 	f24HourRadioButton = new BRadioButton("", B_TRANSLATE("24 hour"),
92fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
936fd2f4a0SOliver Tappe 	f12HourRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"),
94fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
95fb816644SAdrien Destugues 
96fb816644SAdrien Destugues 	float spacing = be_control_look->DefaultItemSpacing();
97fb816644SAdrien Destugues 
986fd2f4a0SOliver Tappe 	BStringView* fullTimeLabel
996fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Full format:"));
1006fd2f4a0SOliver Tappe 	fullTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1016fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1026fd2f4a0SOliver Tappe 	BStringView* longTimeLabel
1036fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Long format:"));
1046fd2f4a0SOliver Tappe 	longTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1056fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1066fd2f4a0SOliver Tappe 	BStringView* mediumTimeLabel
1076fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Medium format:"));
1086fd2f4a0SOliver Tappe 	mediumTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1096fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1106fd2f4a0SOliver Tappe 	BStringView* shortTimeLabel
1116fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Short format:"));
1126fd2f4a0SOliver Tappe 	shortTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1136fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1146fd2f4a0SOliver Tappe 
1156fd2f4a0SOliver Tappe 	fFullTimeExampleView = new BStringView("", "");
1166fd2f4a0SOliver Tappe 	fFullTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1176fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
118fb816644SAdrien Destugues 	fLongTimeExampleView = new BStringView("", "");
1196fd2f4a0SOliver Tappe 	fLongTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1206fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1216fd2f4a0SOliver Tappe 	fMediumTimeExampleView = new BStringView("", "");
1226fd2f4a0SOliver Tappe 	fMediumTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1236fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
124fb816644SAdrien Destugues 	fShortTimeExampleView = new BStringView("", "");
1256fd2f4a0SOliver Tappe 	fShortTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1266fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
127fb816644SAdrien Destugues 
1286fd2f4a0SOliver Tappe 	BStringView* positiveNumberLabel
1296fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Positive:"));
1306fd2f4a0SOliver Tappe 	positiveNumberLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1316fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1326fd2f4a0SOliver Tappe 	BStringView* negativeNumberLabel
1336fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Negative:"));
1346fd2f4a0SOliver Tappe 	negativeNumberLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1356fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
136fb816644SAdrien Destugues 
1376fd2f4a0SOliver Tappe 	fPositiveNumberExampleView = new BStringView("", "");
1386fd2f4a0SOliver Tappe 	fPositiveNumberExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1396fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1406fd2f4a0SOliver Tappe 	fNegativeNumberExampleView = new BStringView("", "");
1416fd2f4a0SOliver Tappe 	fNegativeNumberExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1426fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
143fb816644SAdrien Destugues 
1446fd2f4a0SOliver Tappe 	BStringView* positiveMonetaryLabel
1456fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Positive:"));
1466fd2f4a0SOliver Tappe 	positiveMonetaryLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1476fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1486fd2f4a0SOliver Tappe 	BStringView* negativeMonetaryLabel
1496fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Negative:"));
1506fd2f4a0SOliver Tappe 	negativeMonetaryLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1516fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
152fb816644SAdrien Destugues 
1536fd2f4a0SOliver Tappe 	fPositiveMonetaryExampleView = new BStringView("", "");
1546fd2f4a0SOliver Tappe 	fPositiveMonetaryExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1556fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1566fd2f4a0SOliver Tappe 	fNegativeMonetaryExampleView = new BStringView("", "");
1576fd2f4a0SOliver Tappe 	fNegativeMonetaryExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1586fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
159fb816644SAdrien Destugues 
1606fd2f4a0SOliver Tappe 	Refresh(true);
161fb816644SAdrien Destugues 
162fb816644SAdrien Destugues 	fDateBox = new BBox(B_TRANSLATE("Date"));
163fb816644SAdrien Destugues 	fTimeBox = new BBox(B_TRANSLATE("Time"));
1646fd2f4a0SOliver Tappe 	fNumberBox = new BBox(B_TRANSLATE("Numbers"));
1656fd2f4a0SOliver Tappe 	fMonetaryBox = new BBox(B_TRANSLATE("Currency"));
166fb816644SAdrien Destugues 
167fb816644SAdrien Destugues 	fDateBox->SetLabel(B_TRANSLATE("Date"));
168fb816644SAdrien Destugues 	fTimeBox->SetLabel(B_TRANSLATE("Time"));
1696fd2f4a0SOliver Tappe 	fNumberBox->SetLabel(B_TRANSLATE("Numbers"));
1706fd2f4a0SOliver Tappe 	fMonetaryBox->SetLabel(B_TRANSLATE("Currency"));
171fb816644SAdrien Destugues 
1726fd2f4a0SOliver Tappe 	fDateBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
17325fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
1746fd2f4a0SOliver Tappe 		.Add(fullDateLabel, 0, 0)
1756fd2f4a0SOliver Tappe 		.Add(fFullDateExampleView, 1, 0)
1766fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
1776fd2f4a0SOliver Tappe 		.Add(longDateLabel, 0, 1)
1786fd2f4a0SOliver Tappe 		.Add(fLongDateExampleView, 1, 1)
1796fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
1806fd2f4a0SOliver Tappe 		.Add(mediumDateLabel, 0, 2)
1816fd2f4a0SOliver Tappe 		.Add(fMediumDateExampleView, 1, 2)
1826fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 2)
1836fd2f4a0SOliver Tappe 		.Add(shortDateLabel, 0, 3)
1846fd2f4a0SOliver Tappe 		.Add(fShortDateExampleView, 1, 3)
1856fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 3)
18625fd5c7bSAlex Wilson 		.View());
187fb816644SAdrien Destugues 
1886fd2f4a0SOliver Tappe 	fTimeBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
18925fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
1906fd2f4a0SOliver Tappe 		.AddGroup(B_HORIZONTAL, spacing, 0, 0, 2)
1916fd2f4a0SOliver Tappe 			.Add(f24HourRadioButton, 0)
1926fd2f4a0SOliver Tappe 			.Add(f12HourRadioButton, 0)
193fb816644SAdrien Destugues 			.AddGlue()
194fb816644SAdrien Destugues 			.End()
1956fd2f4a0SOliver Tappe 		.Add(fullTimeLabel, 0, 1)
1966fd2f4a0SOliver Tappe 		.Add(fFullTimeExampleView, 1, 1)
1976fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
1986fd2f4a0SOliver Tappe 		.Add(longTimeLabel, 0, 2)
1996fd2f4a0SOliver Tappe 		.Add(fLongTimeExampleView, 1, 2)
2006fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 2)
2016fd2f4a0SOliver Tappe 		.Add(mediumTimeLabel, 0, 3)
2026fd2f4a0SOliver Tappe 		.Add(fMediumTimeExampleView, 1, 3)
2036fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 3)
2046fd2f4a0SOliver Tappe 		.Add(shortTimeLabel, 0, 4)
2056fd2f4a0SOliver Tappe 		.Add(fShortTimeExampleView, 1, 4)
2066fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 4)
20725fd5c7bSAlex Wilson 		.View());
208fb816644SAdrien Destugues 
2096fd2f4a0SOliver Tappe 	fNumberBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
21025fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
2116fd2f4a0SOliver Tappe 		.Add(positiveNumberLabel, 0, 0)
2126fd2f4a0SOliver Tappe 		.Add(fPositiveNumberExampleView, 1, 0)
2136fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
2146fd2f4a0SOliver Tappe 		.Add(negativeNumberLabel, 0, 1)
2156fd2f4a0SOliver Tappe 		.Add(fNegativeNumberExampleView, 1, 1)
2166fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
21725fd5c7bSAlex Wilson 		.View());
218fb816644SAdrien Destugues 
2196fd2f4a0SOliver Tappe 	fMonetaryBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
22025fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
2216fd2f4a0SOliver Tappe 		.Add(positiveMonetaryLabel, 0, 0)
2226fd2f4a0SOliver Tappe 		.Add(fPositiveMonetaryExampleView, 1, 0)
2236fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
2246fd2f4a0SOliver Tappe 		.Add(negativeMonetaryLabel, 0, 1)
2256fd2f4a0SOliver Tappe 		.Add(fNegativeMonetaryExampleView, 1, 1)
2266fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
22725fd5c7bSAlex Wilson 		.View());
228fb816644SAdrien Destugues 
2296fd2f4a0SOliver Tappe 	BGroupLayout* rootLayout = new BGroupLayout(B_VERTICAL, spacing);
23025fd5c7bSAlex Wilson 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
23125fd5c7bSAlex Wilson 	SetLayout(rootLayout);
23225fd5c7bSAlex Wilson 	BLayoutBuilder::Group<>(rootLayout)
2336fd2f4a0SOliver Tappe 		.Add(fUseLanguageStringsCheckBox)
234fb816644SAdrien Destugues 		.Add(fDateBox)
235fb816644SAdrien Destugues 		.Add(fTimeBox)
2366fd2f4a0SOliver Tappe 		.AddGroup(B_HORIZONTAL, spacing)
2376fd2f4a0SOliver Tappe 			.Add(fNumberBox)
2386fd2f4a0SOliver Tappe 			.Add(fMonetaryBox)
239fb816644SAdrien Destugues 			.AddGlue()
240fb816644SAdrien Destugues 			.End()
24125fd5c7bSAlex Wilson 		.AddGlue();
242fb816644SAdrien Destugues }
243fb816644SAdrien Destugues 
244fb816644SAdrien Destugues 
2456fd2f4a0SOliver Tappe FormatSettingsView::~FormatSettingsView()
246fb816644SAdrien Destugues {
247fb816644SAdrien Destugues }
248fb816644SAdrien Destugues 
249fb816644SAdrien Destugues 
250fb816644SAdrien Destugues void
2516fd2f4a0SOliver Tappe FormatSettingsView::AttachedToWindow()
252fb816644SAdrien Destugues {
2536fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox->SetTarget(this);
2546fd2f4a0SOliver Tappe 	f24HourRadioButton->SetTarget(this);
2556fd2f4a0SOliver Tappe 	f12HourRadioButton->SetTarget(this);
256fb816644SAdrien Destugues }
257fb816644SAdrien Destugues 
258fb816644SAdrien Destugues 
259fb816644SAdrien Destugues void
2606fd2f4a0SOliver Tappe FormatSettingsView::MessageReceived(BMessage* message)
261fb816644SAdrien Destugues {
262fb816644SAdrien Destugues 	switch (message->what) {
26331c0024dSJohn Scipione 		case B_LOCALE_CHANGED:
26431c0024dSJohn Scipione 		{
26531c0024dSJohn Scipione 			// Time updated 12/24 hour clock
26631c0024dSJohn Scipione 			BFormattingConventions conventions;
26731c0024dSJohn Scipione 			BLocale::Default()->GetFormattingConventions(&conventions);
26831c0024dSJohn Scipione 			if (conventions.Use24HourClock())
26931c0024dSJohn Scipione 				f24HourRadioButton->SetValue(B_CONTROL_ON);
27031c0024dSJohn Scipione 			else
27131c0024dSJohn Scipione 				f12HourRadioButton->SetValue(B_CONTROL_ON);
27231c0024dSJohn Scipione 
27331c0024dSJohn Scipione 			_UpdateExamples();
27431c0024dSJohn Scipione 			Window()->PostMessage(kMsgSettingsChanged);
27531c0024dSJohn Scipione 			break;
27631c0024dSJohn Scipione 		}
27731c0024dSJohn Scipione 
278fb816644SAdrien Destugues 		case kClockFormatChange:
279fb816644SAdrien Destugues 		{
2806fd2f4a0SOliver Tappe 			BFormattingConventions conventions;
28125dc253dSIngo Weinhold 			BLocale::Default()->GetFormattingConventions(&conventions);
2826fd2f4a0SOliver Tappe 			conventions.SetExplicitUse24HourClock(
28331c0024dSJohn Scipione 				f24HourRadioButton->Value() == B_CONTROL_ON);
28425dc253dSIngo Weinhold 			MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
28525dc253dSIngo Weinhold 				conventions);
286fb816644SAdrien Destugues 
287fb816644SAdrien Destugues 			_UpdateExamples();
2886fd2f4a0SOliver Tappe 			Window()->PostMessage(kMsgSettingsChanged);
2896fd2f4a0SOliver Tappe 			break;
2906fd2f4a0SOliver Tappe 		}
2916fd2f4a0SOliver Tappe 
2926fd2f4a0SOliver Tappe 		case kStringsLanguageChange:
2936fd2f4a0SOliver Tappe 		{
2946fd2f4a0SOliver Tappe 			BFormattingConventions conventions;
29525dc253dSIngo Weinhold 			BLocale::Default()->GetFormattingConventions(&conventions);
2966fd2f4a0SOliver Tappe 			conventions.SetUseStringsFromPreferredLanguage(
2976fd2f4a0SOliver Tappe 				fUseLanguageStringsCheckBox->Value() ? true : false);
29825dc253dSIngo Weinhold 			MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
29925dc253dSIngo Weinhold 				conventions);
3006fd2f4a0SOliver Tappe 
3016fd2f4a0SOliver Tappe 			_UpdateExamples();
3026fd2f4a0SOliver Tappe 
3036fd2f4a0SOliver Tappe 			Window()->PostMessage(kMsgSettingsChanged);
304fb816644SAdrien Destugues 			break;
305fb816644SAdrien Destugues 		}
306fb816644SAdrien Destugues 
307fb816644SAdrien Destugues 		default:
308fb816644SAdrien Destugues 			BView::MessageReceived(message);
309fb816644SAdrien Destugues 	}
310fb816644SAdrien Destugues }
311fb816644SAdrien Destugues 
312fb816644SAdrien Destugues 
313fb816644SAdrien Destugues void
3146fd2f4a0SOliver Tappe FormatSettingsView::Revert()
315fb816644SAdrien Destugues {
31625dc253dSIngo Weinhold 	MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
31725dc253dSIngo Weinhold 		fInitialConventions);
318bca1690bSAdrien Destugues 
319fb816644SAdrien Destugues 	_UpdateExamples();
320fb816644SAdrien Destugues }
321fb816644SAdrien Destugues 
322fb816644SAdrien Destugues 
323fb816644SAdrien Destugues void
3246fd2f4a0SOliver Tappe FormatSettingsView::Refresh(bool setInitial)
325fb816644SAdrien Destugues {
3266fd2f4a0SOliver Tappe 	BFormattingConventions conventions;
32725dc253dSIngo Weinhold 	BLocale::Default()->GetFormattingConventions(&conventions);
3286fd2f4a0SOliver Tappe 	if (setInitial)
3296fd2f4a0SOliver Tappe 		fInitialConventions = conventions;
3306fd2f4a0SOliver Tappe 
3316fd2f4a0SOliver Tappe 	if (!conventions.Use24HourClock()) {
3326fd2f4a0SOliver Tappe 		f12HourRadioButton->SetValue(B_CONTROL_ON);
3336fd2f4a0SOliver Tappe 		fLocaleIs24Hour = false;
3346fd2f4a0SOliver Tappe 	} else {
3356fd2f4a0SOliver Tappe 		f24HourRadioButton->SetValue(B_CONTROL_ON);
3366fd2f4a0SOliver Tappe 		fLocaleIs24Hour = true;
3376fd2f4a0SOliver Tappe 	}
3386fd2f4a0SOliver Tappe 
3396fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox->SetValue(
3406fd2f4a0SOliver Tappe 		conventions.UseStringsFromPreferredLanguage()
3416fd2f4a0SOliver Tappe 			? B_CONTROL_ON : B_CONTROL_OFF);
3426fd2f4a0SOliver Tappe 
3436fd2f4a0SOliver Tappe 	_UpdateExamples();
344fb816644SAdrien Destugues }
345fb816644SAdrien Destugues 
346fb816644SAdrien Destugues 
3476fd2f4a0SOliver Tappe // Return true if the Revert button should be enabled (i.e. something has been
348fb816644SAdrien Destugues // changed)
349fb816644SAdrien Destugues bool
3506fd2f4a0SOliver Tappe FormatSettingsView::IsReversible() const
351fb816644SAdrien Destugues {
3526fd2f4a0SOliver Tappe 	BFormattingConventions conventions;
35325dc253dSIngo Weinhold 	BLocale::Default()->GetFormattingConventions(&conventions);
354fb816644SAdrien Destugues 
3556fd2f4a0SOliver Tappe 	return conventions != fInitialConventions;
356fb816644SAdrien Destugues }
357fb816644SAdrien Destugues 
358fb816644SAdrien Destugues 
359fb816644SAdrien Destugues void
3606fd2f4a0SOliver Tappe FormatSettingsView::_UpdateExamples()
361fb816644SAdrien Destugues {
362fb816644SAdrien Destugues 	time_t timeValue = (time_t)time(NULL);
3636fd2f4a0SOliver Tappe 	BString result;
364fb816644SAdrien Destugues 
365*03b2550eSAdrien Destugues 	// Do NOT make these class members. We do want to recreate it everytime, as
3660a925409SAdrien Destugues 	// to get the updated settings from the locale roster.
3670a925409SAdrien Destugues 	BDateFormat dateFormat;
368*03b2550eSAdrien Destugues 	BTimeFormat timeFormat;
3690a925409SAdrien Destugues 
3700a925409SAdrien Destugues 	dateFormat.Format(result, timeValue, B_FULL_DATE_FORMAT);
3716fd2f4a0SOliver Tappe 	fFullDateExampleView->SetText(result);
372fb816644SAdrien Destugues 
3730a925409SAdrien Destugues 	dateFormat.Format(result, timeValue, B_LONG_DATE_FORMAT);
3746fd2f4a0SOliver Tappe 	fLongDateExampleView->SetText(result);
375fb816644SAdrien Destugues 
3760a925409SAdrien Destugues 	dateFormat.Format(result, timeValue, B_MEDIUM_DATE_FORMAT);
3776fd2f4a0SOliver Tappe 	fMediumDateExampleView->SetText(result);
378fb816644SAdrien Destugues 
3790a925409SAdrien Destugues 	dateFormat.Format(result, timeValue, B_SHORT_DATE_FORMAT);
3806fd2f4a0SOliver Tappe 	fShortDateExampleView->SetText(result);
381fb816644SAdrien Destugues 
382*03b2550eSAdrien Destugues 	timeFormat.Format(result, timeValue, B_FULL_TIME_FORMAT);
3836fd2f4a0SOliver Tappe 	fFullTimeExampleView->SetText(result);
3846fd2f4a0SOliver Tappe 
385*03b2550eSAdrien Destugues 	timeFormat.Format(result, timeValue, B_LONG_TIME_FORMAT);
3866fd2f4a0SOliver Tappe 	fLongTimeExampleView->SetText(result);
3876fd2f4a0SOliver Tappe 
388*03b2550eSAdrien Destugues 	timeFormat.Format(result, timeValue, B_MEDIUM_TIME_FORMAT);
3896fd2f4a0SOliver Tappe 	fMediumTimeExampleView->SetText(result);
3906fd2f4a0SOliver Tappe 
391*03b2550eSAdrien Destugues 	timeFormat.Format(result, timeValue, B_SHORT_TIME_FORMAT);
3926fd2f4a0SOliver Tappe 	fShortTimeExampleView->SetText(result);
3936fd2f4a0SOliver Tappe 
39425dc253dSIngo Weinhold 	status_t status = BLocale::Default()->FormatNumber(&result, 1234.5678);
3956fd2f4a0SOliver Tappe 	if (status == B_OK)
3966fd2f4a0SOliver Tappe 		fPositiveNumberExampleView->SetText(result);
397fb816644SAdrien Destugues 	else
3986fd2f4a0SOliver Tappe 		fPositiveNumberExampleView->SetText("ERROR");
399fb816644SAdrien Destugues 
40025dc253dSIngo Weinhold 	status = BLocale::Default()->FormatNumber(&result, -1234.5678);
4016fd2f4a0SOliver Tappe 	if (status == B_OK)
4026fd2f4a0SOliver Tappe 		fNegativeNumberExampleView->SetText(result);
4039e773899SAdrien Destugues 	else
4046fd2f4a0SOliver Tappe 		fNegativeNumberExampleView->SetText("ERROR");
405bca1690bSAdrien Destugues 
40625dc253dSIngo Weinhold 	status = BLocale::Default()->FormatMonetary(&result, 1234.56);
4076fd2f4a0SOliver Tappe 	if (status == B_OK)
4086fd2f4a0SOliver Tappe 		fPositiveMonetaryExampleView->SetText(result);
4096fd2f4a0SOliver Tappe 	else
4106fd2f4a0SOliver Tappe 		fPositiveMonetaryExampleView->SetText("ERROR");
411bca1690bSAdrien Destugues 
41225dc253dSIngo Weinhold 	status = BLocale::Default()->FormatMonetary(&result, -1234.56);
4136fd2f4a0SOliver Tappe 	if (status == B_OK)
4146fd2f4a0SOliver Tappe 		fNegativeMonetaryExampleView->SetText(result);
4156fd2f4a0SOliver Tappe 	else
4166fd2f4a0SOliver Tappe 		fNegativeMonetaryExampleView->SetText("ERROR");
417fb816644SAdrien Destugues }
418