xref: /haiku/src/preferences/locale/FormatSettingsView.cpp (revision e3857211d305a595c2d0b58768f25623d5967675)
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>
28*e3857211SAdrien Destugues #include <NumberFormat.h>
29fb816644SAdrien Destugues #include <PopUpMenu.h>
30fb816644SAdrien Destugues #include <RadioButton.h>
31fb816644SAdrien Destugues #include <ScrollView.h>
32fb816644SAdrien Destugues #include <ScrollBar.h>
33fb816644SAdrien Destugues #include <SeparatorView.h>
346fd2f4a0SOliver Tappe #include <SpaceLayoutItem.h>
35fb816644SAdrien Destugues #include <String.h>
36fb816644SAdrien Destugues #include <StringView.h>
37fb816644SAdrien Destugues #include <TextControl.h>
3803b2550eSAdrien Destugues #include <TimeFormat.h>
39fb816644SAdrien Destugues #include <Window.h>
40fb816644SAdrien Destugues 
416bb481c7SOliver Tappe #include "LocalePreflet.h"
42bca1690bSAdrien Destugues 
43fb816644SAdrien Destugues 
4425dc253dSIngo Weinhold using BPrivate::MutableLocaleRoster;
45fb816644SAdrien Destugues 
46fb816644SAdrien Destugues 
47546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
48546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "TimeFormatSettings"
49fb816644SAdrien Destugues 
50fb816644SAdrien Destugues 
51fb816644SAdrien Destugues // #pragma mark -
52fb816644SAdrien Destugues 
53fb816644SAdrien Destugues 
546fd2f4a0SOliver Tappe FormatSettingsView::FormatSettingsView()
55fb816644SAdrien Destugues 	:
566fd2f4a0SOliver Tappe 	BView("WindowsSettingsView", B_FRAME_EVENTS)
57fb816644SAdrien Destugues {
586fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox = new BCheckBox(
596fd2f4a0SOliver Tappe 		B_TRANSLATE("Use month/day-names from preferred language"),
606fd2f4a0SOliver Tappe 		new BMessage(kStringsLanguageChange));
616fd2f4a0SOliver Tappe 
626fd2f4a0SOliver Tappe 	BStringView* fullDateLabel
636fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Full format:"));
646fd2f4a0SOliver Tappe 	fullDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
656fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
666fd2f4a0SOliver Tappe 	BStringView* longDateLabel
676fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Long format:"));
686fd2f4a0SOliver Tappe 	longDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
696fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
706fd2f4a0SOliver Tappe 	BStringView* mediumDateLabel
716fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Medium format:"));
726fd2f4a0SOliver Tappe 	mediumDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
736fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
746fd2f4a0SOliver Tappe 	BStringView* shortDateLabel
756fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Short format:"));
766fd2f4a0SOliver Tappe 	shortDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
776fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
786fd2f4a0SOliver Tappe 
796fd2f4a0SOliver Tappe 	fFullDateExampleView = new BStringView("", "");
806fd2f4a0SOliver Tappe 	fFullDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
816fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
82fb816644SAdrien Destugues 	fLongDateExampleView = new BStringView("", "");
836fd2f4a0SOliver Tappe 	fLongDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
846fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
856fd2f4a0SOliver Tappe 	fMediumDateExampleView = new BStringView("", "");
866fd2f4a0SOliver Tappe 	fMediumDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
876fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
88fb816644SAdrien Destugues 	fShortDateExampleView = new BStringView("", "");
896fd2f4a0SOliver Tappe 	fShortDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
906fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
91fb816644SAdrien Destugues 
926fd2f4a0SOliver Tappe 	f24HourRadioButton = new BRadioButton("", B_TRANSLATE("24 hour"),
93fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
946fd2f4a0SOliver Tappe 	f12HourRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"),
95fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
96fb816644SAdrien Destugues 
97fb816644SAdrien Destugues 	float spacing = be_control_look->DefaultItemSpacing();
98fb816644SAdrien Destugues 
996fd2f4a0SOliver Tappe 	BStringView* fullTimeLabel
1006fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Full format:"));
1016fd2f4a0SOliver Tappe 	fullTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1026fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1036fd2f4a0SOliver Tappe 	BStringView* longTimeLabel
1046fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Long format:"));
1056fd2f4a0SOliver Tappe 	longTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1066fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1076fd2f4a0SOliver Tappe 	BStringView* mediumTimeLabel
1086fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Medium format:"));
1096fd2f4a0SOliver Tappe 	mediumTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1106fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1116fd2f4a0SOliver Tappe 	BStringView* shortTimeLabel
1126fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Short format:"));
1136fd2f4a0SOliver Tappe 	shortTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1146fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1156fd2f4a0SOliver Tappe 
1166fd2f4a0SOliver Tappe 	fFullTimeExampleView = new BStringView("", "");
1176fd2f4a0SOliver Tappe 	fFullTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1186fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
119fb816644SAdrien Destugues 	fLongTimeExampleView = new BStringView("", "");
1206fd2f4a0SOliver Tappe 	fLongTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1216fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1226fd2f4a0SOliver Tappe 	fMediumTimeExampleView = new BStringView("", "");
1236fd2f4a0SOliver Tappe 	fMediumTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1246fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
125fb816644SAdrien Destugues 	fShortTimeExampleView = new BStringView("", "");
1266fd2f4a0SOliver Tappe 	fShortTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1276fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
128fb816644SAdrien Destugues 
1296fd2f4a0SOliver Tappe 	BStringView* positiveNumberLabel
1306fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Positive:"));
1316fd2f4a0SOliver Tappe 	positiveNumberLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1326fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1336fd2f4a0SOliver Tappe 	BStringView* negativeNumberLabel
1346fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Negative:"));
1356fd2f4a0SOliver Tappe 	negativeNumberLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1366fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
137fb816644SAdrien Destugues 
1386fd2f4a0SOliver Tappe 	fPositiveNumberExampleView = new BStringView("", "");
1396fd2f4a0SOliver Tappe 	fPositiveNumberExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1406fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1416fd2f4a0SOliver Tappe 	fNegativeNumberExampleView = new BStringView("", "");
1426fd2f4a0SOliver Tappe 	fNegativeNumberExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1436fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
144fb816644SAdrien Destugues 
1456fd2f4a0SOliver Tappe 	BStringView* positiveMonetaryLabel
1466fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Positive:"));
1476fd2f4a0SOliver Tappe 	positiveMonetaryLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1486fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1496fd2f4a0SOliver Tappe 	BStringView* negativeMonetaryLabel
1506fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Negative:"));
1516fd2f4a0SOliver Tappe 	negativeMonetaryLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1526fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
153fb816644SAdrien Destugues 
1546fd2f4a0SOliver Tappe 	fPositiveMonetaryExampleView = new BStringView("", "");
1556fd2f4a0SOliver Tappe 	fPositiveMonetaryExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1566fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1576fd2f4a0SOliver Tappe 	fNegativeMonetaryExampleView = new BStringView("", "");
1586fd2f4a0SOliver Tappe 	fNegativeMonetaryExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1596fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
160fb816644SAdrien Destugues 
1616fd2f4a0SOliver Tappe 	Refresh(true);
162fb816644SAdrien Destugues 
163fb816644SAdrien Destugues 	fDateBox = new BBox(B_TRANSLATE("Date"));
164fb816644SAdrien Destugues 	fTimeBox = new BBox(B_TRANSLATE("Time"));
1656fd2f4a0SOliver Tappe 	fNumberBox = new BBox(B_TRANSLATE("Numbers"));
1666fd2f4a0SOliver Tappe 	fMonetaryBox = new BBox(B_TRANSLATE("Currency"));
167fb816644SAdrien Destugues 
168fb816644SAdrien Destugues 	fDateBox->SetLabel(B_TRANSLATE("Date"));
169fb816644SAdrien Destugues 	fTimeBox->SetLabel(B_TRANSLATE("Time"));
1706fd2f4a0SOliver Tappe 	fNumberBox->SetLabel(B_TRANSLATE("Numbers"));
1716fd2f4a0SOliver Tappe 	fMonetaryBox->SetLabel(B_TRANSLATE("Currency"));
172fb816644SAdrien Destugues 
1736fd2f4a0SOliver Tappe 	fDateBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
17425fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
1756fd2f4a0SOliver Tappe 		.Add(fullDateLabel, 0, 0)
1766fd2f4a0SOliver Tappe 		.Add(fFullDateExampleView, 1, 0)
1776fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
1786fd2f4a0SOliver Tappe 		.Add(longDateLabel, 0, 1)
1796fd2f4a0SOliver Tappe 		.Add(fLongDateExampleView, 1, 1)
1806fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
1816fd2f4a0SOliver Tappe 		.Add(mediumDateLabel, 0, 2)
1826fd2f4a0SOliver Tappe 		.Add(fMediumDateExampleView, 1, 2)
1836fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 2)
1846fd2f4a0SOliver Tappe 		.Add(shortDateLabel, 0, 3)
1856fd2f4a0SOliver Tappe 		.Add(fShortDateExampleView, 1, 3)
1866fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 3)
18725fd5c7bSAlex Wilson 		.View());
188fb816644SAdrien Destugues 
1896fd2f4a0SOliver Tappe 	fTimeBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
19025fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
1916fd2f4a0SOliver Tappe 		.AddGroup(B_HORIZONTAL, spacing, 0, 0, 2)
1926fd2f4a0SOliver Tappe 			.Add(f24HourRadioButton, 0)
1936fd2f4a0SOliver Tappe 			.Add(f12HourRadioButton, 0)
194fb816644SAdrien Destugues 			.AddGlue()
195fb816644SAdrien Destugues 			.End()
1966fd2f4a0SOliver Tappe 		.Add(fullTimeLabel, 0, 1)
1976fd2f4a0SOliver Tappe 		.Add(fFullTimeExampleView, 1, 1)
1986fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
1996fd2f4a0SOliver Tappe 		.Add(longTimeLabel, 0, 2)
2006fd2f4a0SOliver Tappe 		.Add(fLongTimeExampleView, 1, 2)
2016fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 2)
2026fd2f4a0SOliver Tappe 		.Add(mediumTimeLabel, 0, 3)
2036fd2f4a0SOliver Tappe 		.Add(fMediumTimeExampleView, 1, 3)
2046fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 3)
2056fd2f4a0SOliver Tappe 		.Add(shortTimeLabel, 0, 4)
2066fd2f4a0SOliver Tappe 		.Add(fShortTimeExampleView, 1, 4)
2076fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 4)
20825fd5c7bSAlex Wilson 		.View());
209fb816644SAdrien Destugues 
2106fd2f4a0SOliver Tappe 	fNumberBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
21125fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
2126fd2f4a0SOliver Tappe 		.Add(positiveNumberLabel, 0, 0)
2136fd2f4a0SOliver Tappe 		.Add(fPositiveNumberExampleView, 1, 0)
2146fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
2156fd2f4a0SOliver Tappe 		.Add(negativeNumberLabel, 0, 1)
2166fd2f4a0SOliver Tappe 		.Add(fNegativeNumberExampleView, 1, 1)
2176fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
21825fd5c7bSAlex Wilson 		.View());
219fb816644SAdrien Destugues 
2206fd2f4a0SOliver Tappe 	fMonetaryBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
22125fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
2226fd2f4a0SOliver Tappe 		.Add(positiveMonetaryLabel, 0, 0)
2236fd2f4a0SOliver Tappe 		.Add(fPositiveMonetaryExampleView, 1, 0)
2246fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
2256fd2f4a0SOliver Tappe 		.Add(negativeMonetaryLabel, 0, 1)
2266fd2f4a0SOliver Tappe 		.Add(fNegativeMonetaryExampleView, 1, 1)
2276fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
22825fd5c7bSAlex Wilson 		.View());
229fb816644SAdrien Destugues 
2306fd2f4a0SOliver Tappe 	BGroupLayout* rootLayout = new BGroupLayout(B_VERTICAL, spacing);
23125fd5c7bSAlex Wilson 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
23225fd5c7bSAlex Wilson 	SetLayout(rootLayout);
23325fd5c7bSAlex Wilson 	BLayoutBuilder::Group<>(rootLayout)
2346fd2f4a0SOliver Tappe 		.Add(fUseLanguageStringsCheckBox)
235fb816644SAdrien Destugues 		.Add(fDateBox)
236fb816644SAdrien Destugues 		.Add(fTimeBox)
2376fd2f4a0SOliver Tappe 		.AddGroup(B_HORIZONTAL, spacing)
2386fd2f4a0SOliver Tappe 			.Add(fNumberBox)
2396fd2f4a0SOliver Tappe 			.Add(fMonetaryBox)
240fb816644SAdrien Destugues 			.AddGlue()
241fb816644SAdrien Destugues 			.End()
24225fd5c7bSAlex Wilson 		.AddGlue();
243fb816644SAdrien Destugues }
244fb816644SAdrien Destugues 
245fb816644SAdrien Destugues 
2466fd2f4a0SOliver Tappe FormatSettingsView::~FormatSettingsView()
247fb816644SAdrien Destugues {
248fb816644SAdrien Destugues }
249fb816644SAdrien Destugues 
250fb816644SAdrien Destugues 
251fb816644SAdrien Destugues void
2526fd2f4a0SOliver Tappe FormatSettingsView::AttachedToWindow()
253fb816644SAdrien Destugues {
2546fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox->SetTarget(this);
2556fd2f4a0SOliver Tappe 	f24HourRadioButton->SetTarget(this);
2566fd2f4a0SOliver Tappe 	f12HourRadioButton->SetTarget(this);
257fb816644SAdrien Destugues }
258fb816644SAdrien Destugues 
259fb816644SAdrien Destugues 
260fb816644SAdrien Destugues void
2616fd2f4a0SOliver Tappe FormatSettingsView::MessageReceived(BMessage* message)
262fb816644SAdrien Destugues {
263fb816644SAdrien Destugues 	switch (message->what) {
26431c0024dSJohn Scipione 		case B_LOCALE_CHANGED:
26531c0024dSJohn Scipione 		{
26631c0024dSJohn Scipione 			// Time updated 12/24 hour clock
26731c0024dSJohn Scipione 			BFormattingConventions conventions;
26831c0024dSJohn Scipione 			BLocale::Default()->GetFormattingConventions(&conventions);
26931c0024dSJohn Scipione 			if (conventions.Use24HourClock())
27031c0024dSJohn Scipione 				f24HourRadioButton->SetValue(B_CONTROL_ON);
27131c0024dSJohn Scipione 			else
27231c0024dSJohn Scipione 				f12HourRadioButton->SetValue(B_CONTROL_ON);
27331c0024dSJohn Scipione 
27431c0024dSJohn Scipione 			_UpdateExamples();
27531c0024dSJohn Scipione 			Window()->PostMessage(kMsgSettingsChanged);
27631c0024dSJohn Scipione 			break;
27731c0024dSJohn Scipione 		}
27831c0024dSJohn Scipione 
279fb816644SAdrien Destugues 		case kClockFormatChange:
280fb816644SAdrien Destugues 		{
2816fd2f4a0SOliver Tappe 			BFormattingConventions conventions;
28225dc253dSIngo Weinhold 			BLocale::Default()->GetFormattingConventions(&conventions);
2836fd2f4a0SOliver Tappe 			conventions.SetExplicitUse24HourClock(
28431c0024dSJohn Scipione 				f24HourRadioButton->Value() == B_CONTROL_ON);
28525dc253dSIngo Weinhold 			MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
28625dc253dSIngo Weinhold 				conventions);
287fb816644SAdrien Destugues 
288fb816644SAdrien Destugues 			_UpdateExamples();
2896fd2f4a0SOliver Tappe 			Window()->PostMessage(kMsgSettingsChanged);
2906fd2f4a0SOliver Tappe 			break;
2916fd2f4a0SOliver Tappe 		}
2926fd2f4a0SOliver Tappe 
2936fd2f4a0SOliver Tappe 		case kStringsLanguageChange:
2946fd2f4a0SOliver Tappe 		{
2956fd2f4a0SOliver Tappe 			BFormattingConventions conventions;
29625dc253dSIngo Weinhold 			BLocale::Default()->GetFormattingConventions(&conventions);
2976fd2f4a0SOliver Tappe 			conventions.SetUseStringsFromPreferredLanguage(
2986fd2f4a0SOliver Tappe 				fUseLanguageStringsCheckBox->Value() ? true : false);
29925dc253dSIngo Weinhold 			MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
30025dc253dSIngo Weinhold 				conventions);
3016fd2f4a0SOliver Tappe 
3026fd2f4a0SOliver Tappe 			_UpdateExamples();
3036fd2f4a0SOliver Tappe 
3046fd2f4a0SOliver Tappe 			Window()->PostMessage(kMsgSettingsChanged);
305fb816644SAdrien Destugues 			break;
306fb816644SAdrien Destugues 		}
307fb816644SAdrien Destugues 
308fb816644SAdrien Destugues 		default:
309fb816644SAdrien Destugues 			BView::MessageReceived(message);
310fb816644SAdrien Destugues 	}
311fb816644SAdrien Destugues }
312fb816644SAdrien Destugues 
313fb816644SAdrien Destugues 
314fb816644SAdrien Destugues void
3156fd2f4a0SOliver Tappe FormatSettingsView::Revert()
316fb816644SAdrien Destugues {
31725dc253dSIngo Weinhold 	MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
31825dc253dSIngo Weinhold 		fInitialConventions);
319bca1690bSAdrien Destugues 
320fb816644SAdrien Destugues 	_UpdateExamples();
321fb816644SAdrien Destugues }
322fb816644SAdrien Destugues 
323fb816644SAdrien Destugues 
324fb816644SAdrien Destugues void
3256fd2f4a0SOliver Tappe FormatSettingsView::Refresh(bool setInitial)
326fb816644SAdrien Destugues {
3276fd2f4a0SOliver Tappe 	BFormattingConventions conventions;
32825dc253dSIngo Weinhold 	BLocale::Default()->GetFormattingConventions(&conventions);
3296fd2f4a0SOliver Tappe 	if (setInitial)
3306fd2f4a0SOliver Tappe 		fInitialConventions = conventions;
3316fd2f4a0SOliver Tappe 
3326fd2f4a0SOliver Tappe 	if (!conventions.Use24HourClock()) {
3336fd2f4a0SOliver Tappe 		f12HourRadioButton->SetValue(B_CONTROL_ON);
3346fd2f4a0SOliver Tappe 		fLocaleIs24Hour = false;
3356fd2f4a0SOliver Tappe 	} else {
3366fd2f4a0SOliver Tappe 		f24HourRadioButton->SetValue(B_CONTROL_ON);
3376fd2f4a0SOliver Tappe 		fLocaleIs24Hour = true;
3386fd2f4a0SOliver Tappe 	}
3396fd2f4a0SOliver Tappe 
3406fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox->SetValue(
3416fd2f4a0SOliver Tappe 		conventions.UseStringsFromPreferredLanguage()
3426fd2f4a0SOliver Tappe 			? B_CONTROL_ON : B_CONTROL_OFF);
3436fd2f4a0SOliver Tappe 
3446fd2f4a0SOliver Tappe 	_UpdateExamples();
345fb816644SAdrien Destugues }
346fb816644SAdrien Destugues 
347fb816644SAdrien Destugues 
3486fd2f4a0SOliver Tappe // Return true if the Revert button should be enabled (i.e. something has been
349fb816644SAdrien Destugues // changed)
350fb816644SAdrien Destugues bool
3516fd2f4a0SOliver Tappe FormatSettingsView::IsReversible() const
352fb816644SAdrien Destugues {
3536fd2f4a0SOliver Tappe 	BFormattingConventions conventions;
35425dc253dSIngo Weinhold 	BLocale::Default()->GetFormattingConventions(&conventions);
355fb816644SAdrien Destugues 
3566fd2f4a0SOliver Tappe 	return conventions != fInitialConventions;
357fb816644SAdrien Destugues }
358fb816644SAdrien Destugues 
359fb816644SAdrien Destugues 
360fb816644SAdrien Destugues void
3616fd2f4a0SOliver Tappe FormatSettingsView::_UpdateExamples()
362fb816644SAdrien Destugues {
363fb816644SAdrien Destugues 	time_t timeValue = (time_t)time(NULL);
3646fd2f4a0SOliver Tappe 	BString result;
365fb816644SAdrien Destugues 
36603b2550eSAdrien Destugues 	// Do NOT make these class members. We do want to recreate it everytime, as
3670a925409SAdrien Destugues 	// to get the updated settings from the locale roster.
3680a925409SAdrien Destugues 	BDateFormat dateFormat;
36903b2550eSAdrien Destugues 	BTimeFormat timeFormat;
370*e3857211SAdrien Destugues 	BNumberFormat numberFormat;
3710a925409SAdrien Destugues 
3720a925409SAdrien Destugues 	dateFormat.Format(result, timeValue, B_FULL_DATE_FORMAT);
3736fd2f4a0SOliver Tappe 	fFullDateExampleView->SetText(result);
374fb816644SAdrien Destugues 
3750a925409SAdrien Destugues 	dateFormat.Format(result, timeValue, B_LONG_DATE_FORMAT);
3766fd2f4a0SOliver Tappe 	fLongDateExampleView->SetText(result);
377fb816644SAdrien Destugues 
3780a925409SAdrien Destugues 	dateFormat.Format(result, timeValue, B_MEDIUM_DATE_FORMAT);
3796fd2f4a0SOliver Tappe 	fMediumDateExampleView->SetText(result);
380fb816644SAdrien Destugues 
3810a925409SAdrien Destugues 	dateFormat.Format(result, timeValue, B_SHORT_DATE_FORMAT);
3826fd2f4a0SOliver Tappe 	fShortDateExampleView->SetText(result);
383fb816644SAdrien Destugues 
38403b2550eSAdrien Destugues 	timeFormat.Format(result, timeValue, B_FULL_TIME_FORMAT);
3856fd2f4a0SOliver Tappe 	fFullTimeExampleView->SetText(result);
3866fd2f4a0SOliver Tappe 
38703b2550eSAdrien Destugues 	timeFormat.Format(result, timeValue, B_LONG_TIME_FORMAT);
3886fd2f4a0SOliver Tappe 	fLongTimeExampleView->SetText(result);
3896fd2f4a0SOliver Tappe 
39003b2550eSAdrien Destugues 	timeFormat.Format(result, timeValue, B_MEDIUM_TIME_FORMAT);
3916fd2f4a0SOliver Tappe 	fMediumTimeExampleView->SetText(result);
3926fd2f4a0SOliver Tappe 
39303b2550eSAdrien Destugues 	timeFormat.Format(result, timeValue, B_SHORT_TIME_FORMAT);
3946fd2f4a0SOliver Tappe 	fShortTimeExampleView->SetText(result);
3956fd2f4a0SOliver Tappe 
396*e3857211SAdrien Destugues 	status_t status = numberFormat.Format(result, 1234.5678);
3976fd2f4a0SOliver Tappe 	if (status == B_OK)
3986fd2f4a0SOliver Tappe 		fPositiveNumberExampleView->SetText(result);
399fb816644SAdrien Destugues 	else
4006fd2f4a0SOliver Tappe 		fPositiveNumberExampleView->SetText("ERROR");
401fb816644SAdrien Destugues 
402*e3857211SAdrien Destugues 	status = numberFormat.Format(result, -1234.5678);
4036fd2f4a0SOliver Tappe 	if (status == B_OK)
4046fd2f4a0SOliver Tappe 		fNegativeNumberExampleView->SetText(result);
4059e773899SAdrien Destugues 	else
4066fd2f4a0SOliver Tappe 		fNegativeNumberExampleView->SetText("ERROR");
407bca1690bSAdrien Destugues 
408*e3857211SAdrien Destugues 	status = numberFormat.FormatMonetary(result, 1234.56);
4096fd2f4a0SOliver Tappe 	if (status == B_OK)
4106fd2f4a0SOliver Tappe 		fPositiveMonetaryExampleView->SetText(result);
4116fd2f4a0SOliver Tappe 	else
4126fd2f4a0SOliver Tappe 		fPositiveMonetaryExampleView->SetText("ERROR");
413bca1690bSAdrien Destugues 
414*e3857211SAdrien Destugues 	status = numberFormat.FormatMonetary(result, -1234.56);
4156fd2f4a0SOliver Tappe 	if (status == B_OK)
4166fd2f4a0SOliver Tappe 		fNegativeMonetaryExampleView->SetText(result);
4176fd2f4a0SOliver Tappe 	else
4186fd2f4a0SOliver Tappe 		fNegativeMonetaryExampleView->SetText("ERROR");
419fb816644SAdrien Destugues }
420