xref: /haiku/src/preferences/locale/FormatSettingsView.cpp (revision 31c0024d1b271b0b671c77432cce0be483b366f0)
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>
166fd2f4a0SOliver Tappe #include <GridLayout.h>
176fd2f4a0SOliver Tappe #include <GridLayoutBuilder.h>
18fb816644SAdrien Destugues #include <GroupLayout.h>
19fb816644SAdrien Destugues #include <GroupLayoutBuilder.h>
20fb816644SAdrien Destugues #include <LayoutBuilder.h>
21fb816644SAdrien Destugues #include <Locale.h>
22fb816644SAdrien Destugues #include <MutableLocaleRoster.h>
23fb816644SAdrien Destugues #include <Message.h>
24fb816644SAdrien Destugues #include <Menu.h>
25fb816644SAdrien Destugues #include <MenuField.h>
26fb816644SAdrien Destugues #include <MenuItem.h>
27fb816644SAdrien Destugues #include <PopUpMenu.h>
28fb816644SAdrien Destugues #include <RadioButton.h>
29fb816644SAdrien Destugues #include <ScrollView.h>
30fb816644SAdrien Destugues #include <ScrollBar.h>
31fb816644SAdrien Destugues #include <SeparatorView.h>
326fd2f4a0SOliver Tappe #include <SpaceLayoutItem.h>
33fb816644SAdrien Destugues #include <String.h>
34fb816644SAdrien Destugues #include <StringView.h>
35fb816644SAdrien Destugues #include <TextControl.h>
36fb816644SAdrien Destugues #include <Window.h>
37fb816644SAdrien Destugues 
386bb481c7SOliver Tappe #include "LocalePreflet.h"
39bca1690bSAdrien Destugues 
40fb816644SAdrien Destugues 
4125dc253dSIngo Weinhold using BPrivate::MutableLocaleRoster;
42fb816644SAdrien Destugues 
43fb816644SAdrien Destugues 
44546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
45546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "TimeFormatSettings"
46fb816644SAdrien Destugues 
47fb816644SAdrien Destugues 
48fb816644SAdrien Destugues // #pragma mark -
49fb816644SAdrien Destugues 
50fb816644SAdrien Destugues 
516fd2f4a0SOliver Tappe FormatSettingsView::FormatSettingsView()
52fb816644SAdrien Destugues 	:
536fd2f4a0SOliver Tappe 	BView("WindowsSettingsView", B_FRAME_EVENTS)
54fb816644SAdrien Destugues {
556fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox = new BCheckBox(
566fd2f4a0SOliver Tappe 		B_TRANSLATE("Use month/day-names from preferred language"),
576fd2f4a0SOliver Tappe 		new BMessage(kStringsLanguageChange));
586fd2f4a0SOliver Tappe 
596fd2f4a0SOliver Tappe 	BStringView* fullDateLabel
606fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Full format:"));
616fd2f4a0SOliver Tappe 	fullDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
626fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
636fd2f4a0SOliver Tappe 	BStringView* longDateLabel
646fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Long format:"));
656fd2f4a0SOliver Tappe 	longDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
666fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
676fd2f4a0SOliver Tappe 	BStringView* mediumDateLabel
686fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Medium format:"));
696fd2f4a0SOliver Tappe 	mediumDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
706fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
716fd2f4a0SOliver Tappe 	BStringView* shortDateLabel
726fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Short format:"));
736fd2f4a0SOliver Tappe 	shortDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
746fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
756fd2f4a0SOliver Tappe 
766fd2f4a0SOliver Tappe 	fFullDateExampleView = new BStringView("", "");
776fd2f4a0SOliver Tappe 	fFullDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
786fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
79fb816644SAdrien Destugues 	fLongDateExampleView = new BStringView("", "");
806fd2f4a0SOliver Tappe 	fLongDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
816fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
826fd2f4a0SOliver Tappe 	fMediumDateExampleView = new BStringView("", "");
836fd2f4a0SOliver Tappe 	fMediumDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
846fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
85fb816644SAdrien Destugues 	fShortDateExampleView = new BStringView("", "");
866fd2f4a0SOliver Tappe 	fShortDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
876fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
88fb816644SAdrien Destugues 
896fd2f4a0SOliver Tappe 	f24HourRadioButton = new BRadioButton("", B_TRANSLATE("24 hour"),
90fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
916fd2f4a0SOliver Tappe 	f12HourRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"),
92fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
93fb816644SAdrien Destugues 
94fb816644SAdrien Destugues 	float spacing = be_control_look->DefaultItemSpacing();
95fb816644SAdrien Destugues 
966fd2f4a0SOliver Tappe 	BStringView* fullTimeLabel
976fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Full format:"));
986fd2f4a0SOliver Tappe 	fullTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
996fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1006fd2f4a0SOliver Tappe 	BStringView* longTimeLabel
1016fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Long format:"));
1026fd2f4a0SOliver Tappe 	longTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1036fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1046fd2f4a0SOliver Tappe 	BStringView* mediumTimeLabel
1056fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Medium format:"));
1066fd2f4a0SOliver Tappe 	mediumTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1076fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1086fd2f4a0SOliver Tappe 	BStringView* shortTimeLabel
1096fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Short format:"));
1106fd2f4a0SOliver Tappe 	shortTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1116fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1126fd2f4a0SOliver Tappe 
1136fd2f4a0SOliver Tappe 	fFullTimeExampleView = new BStringView("", "");
1146fd2f4a0SOliver Tappe 	fFullTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1156fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
116fb816644SAdrien Destugues 	fLongTimeExampleView = new BStringView("", "");
1176fd2f4a0SOliver Tappe 	fLongTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1186fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1196fd2f4a0SOliver Tappe 	fMediumTimeExampleView = new BStringView("", "");
1206fd2f4a0SOliver Tappe 	fMediumTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1216fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
122fb816644SAdrien Destugues 	fShortTimeExampleView = new BStringView("", "");
1236fd2f4a0SOliver Tappe 	fShortTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1246fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
125fb816644SAdrien Destugues 
1266fd2f4a0SOliver Tappe 	BStringView* positiveNumberLabel
1276fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Positive:"));
1286fd2f4a0SOliver Tappe 	positiveNumberLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1296fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1306fd2f4a0SOliver Tappe 	BStringView* negativeNumberLabel
1316fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Negative:"));
1326fd2f4a0SOliver Tappe 	negativeNumberLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1336fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
134fb816644SAdrien Destugues 
1356fd2f4a0SOliver Tappe 	fPositiveNumberExampleView = new BStringView("", "");
1366fd2f4a0SOliver Tappe 	fPositiveNumberExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1376fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1386fd2f4a0SOliver Tappe 	fNegativeNumberExampleView = new BStringView("", "");
1396fd2f4a0SOliver Tappe 	fNegativeNumberExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1406fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
141fb816644SAdrien Destugues 
1426fd2f4a0SOliver Tappe 	BStringView* positiveMonetaryLabel
1436fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Positive:"));
1446fd2f4a0SOliver Tappe 	positiveMonetaryLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1456fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1466fd2f4a0SOliver Tappe 	BStringView* negativeMonetaryLabel
1476fd2f4a0SOliver Tappe 		= new BStringView("", B_TRANSLATE("Negative:"));
1486fd2f4a0SOliver Tappe 	negativeMonetaryLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1496fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
150fb816644SAdrien Destugues 
1516fd2f4a0SOliver Tappe 	fPositiveMonetaryExampleView = new BStringView("", "");
1526fd2f4a0SOliver Tappe 	fPositiveMonetaryExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1536fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
1546fd2f4a0SOliver Tappe 	fNegativeMonetaryExampleView = new BStringView("", "");
1556fd2f4a0SOliver Tappe 	fNegativeMonetaryExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1566fd2f4a0SOliver Tappe 		B_ALIGN_VERTICAL_UNSET));
157fb816644SAdrien Destugues 
1586fd2f4a0SOliver Tappe 	Refresh(true);
159fb816644SAdrien Destugues 
160fb816644SAdrien Destugues 	fDateBox = new BBox(B_TRANSLATE("Date"));
161fb816644SAdrien Destugues 	fTimeBox = new BBox(B_TRANSLATE("Time"));
1626fd2f4a0SOliver Tappe 	fNumberBox = new BBox(B_TRANSLATE("Numbers"));
1636fd2f4a0SOliver Tappe 	fMonetaryBox = new BBox(B_TRANSLATE("Currency"));
164fb816644SAdrien Destugues 
165fb816644SAdrien Destugues 	fDateBox->SetLabel(B_TRANSLATE("Date"));
166fb816644SAdrien Destugues 	fTimeBox->SetLabel(B_TRANSLATE("Time"));
1676fd2f4a0SOliver Tappe 	fNumberBox->SetLabel(B_TRANSLATE("Numbers"));
1686fd2f4a0SOliver Tappe 	fMonetaryBox->SetLabel(B_TRANSLATE("Currency"));
169fb816644SAdrien Destugues 
1706fd2f4a0SOliver Tappe 	fDateBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
17125fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
1726fd2f4a0SOliver Tappe 		.Add(fullDateLabel, 0, 0)
1736fd2f4a0SOliver Tappe 		.Add(fFullDateExampleView, 1, 0)
1746fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
1756fd2f4a0SOliver Tappe 		.Add(longDateLabel, 0, 1)
1766fd2f4a0SOliver Tappe 		.Add(fLongDateExampleView, 1, 1)
1776fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
1786fd2f4a0SOliver Tappe 		.Add(mediumDateLabel, 0, 2)
1796fd2f4a0SOliver Tappe 		.Add(fMediumDateExampleView, 1, 2)
1806fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 2)
1816fd2f4a0SOliver Tappe 		.Add(shortDateLabel, 0, 3)
1826fd2f4a0SOliver Tappe 		.Add(fShortDateExampleView, 1, 3)
1836fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 3)
18425fd5c7bSAlex Wilson 		.View());
185fb816644SAdrien Destugues 
1866fd2f4a0SOliver Tappe 	fTimeBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
18725fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
1886fd2f4a0SOliver Tappe 		.AddGroup(B_HORIZONTAL, spacing, 0, 0, 2)
1896fd2f4a0SOliver Tappe 			.Add(f24HourRadioButton, 0)
1906fd2f4a0SOliver Tappe 			.Add(f12HourRadioButton, 0)
191fb816644SAdrien Destugues 			.AddGlue()
192fb816644SAdrien Destugues 			.End()
1936fd2f4a0SOliver Tappe 		.Add(fullTimeLabel, 0, 1)
1946fd2f4a0SOliver Tappe 		.Add(fFullTimeExampleView, 1, 1)
1956fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
1966fd2f4a0SOliver Tappe 		.Add(longTimeLabel, 0, 2)
1976fd2f4a0SOliver Tappe 		.Add(fLongTimeExampleView, 1, 2)
1986fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 2)
1996fd2f4a0SOliver Tappe 		.Add(mediumTimeLabel, 0, 3)
2006fd2f4a0SOliver Tappe 		.Add(fMediumTimeExampleView, 1, 3)
2016fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 3)
2026fd2f4a0SOliver Tappe 		.Add(shortTimeLabel, 0, 4)
2036fd2f4a0SOliver Tappe 		.Add(fShortTimeExampleView, 1, 4)
2046fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 4)
20525fd5c7bSAlex Wilson 		.View());
206fb816644SAdrien Destugues 
2076fd2f4a0SOliver Tappe 	fNumberBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
20825fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
2096fd2f4a0SOliver Tappe 		.Add(positiveNumberLabel, 0, 0)
2106fd2f4a0SOliver Tappe 		.Add(fPositiveNumberExampleView, 1, 0)
2116fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
2126fd2f4a0SOliver Tappe 		.Add(negativeNumberLabel, 0, 1)
2136fd2f4a0SOliver Tappe 		.Add(fNegativeNumberExampleView, 1, 1)
2146fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
21525fd5c7bSAlex Wilson 		.View());
216fb816644SAdrien Destugues 
2176fd2f4a0SOliver Tappe 	fMonetaryBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
21825fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
2196fd2f4a0SOliver Tappe 		.Add(positiveMonetaryLabel, 0, 0)
2206fd2f4a0SOliver Tappe 		.Add(fPositiveMonetaryExampleView, 1, 0)
2216fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
2226fd2f4a0SOliver Tappe 		.Add(negativeMonetaryLabel, 0, 1)
2236fd2f4a0SOliver Tappe 		.Add(fNegativeMonetaryExampleView, 1, 1)
2246fd2f4a0SOliver Tappe 		.Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
22525fd5c7bSAlex Wilson 		.View());
226fb816644SAdrien Destugues 
2276fd2f4a0SOliver Tappe 	BGroupLayout* rootLayout = new BGroupLayout(B_VERTICAL, spacing);
22825fd5c7bSAlex Wilson 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
22925fd5c7bSAlex Wilson 	SetLayout(rootLayout);
23025fd5c7bSAlex Wilson 	BLayoutBuilder::Group<>(rootLayout)
2316fd2f4a0SOliver Tappe 		.Add(fUseLanguageStringsCheckBox)
232fb816644SAdrien Destugues 		.Add(fDateBox)
233fb816644SAdrien Destugues 		.Add(fTimeBox)
2346fd2f4a0SOliver Tappe 		.AddGroup(B_HORIZONTAL, spacing)
2356fd2f4a0SOliver Tappe 			.Add(fNumberBox)
2366fd2f4a0SOliver Tappe 			.Add(fMonetaryBox)
237fb816644SAdrien Destugues 			.AddGlue()
238fb816644SAdrien Destugues 			.End()
23925fd5c7bSAlex Wilson 		.AddGlue();
240fb816644SAdrien Destugues }
241fb816644SAdrien Destugues 
242fb816644SAdrien Destugues 
2436fd2f4a0SOliver Tappe FormatSettingsView::~FormatSettingsView()
244fb816644SAdrien Destugues {
245fb816644SAdrien Destugues }
246fb816644SAdrien Destugues 
247fb816644SAdrien Destugues 
248fb816644SAdrien Destugues void
2496fd2f4a0SOliver Tappe FormatSettingsView::AttachedToWindow()
250fb816644SAdrien Destugues {
2516fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox->SetTarget(this);
2526fd2f4a0SOliver Tappe 	f24HourRadioButton->SetTarget(this);
2536fd2f4a0SOliver Tappe 	f12HourRadioButton->SetTarget(this);
254fb816644SAdrien Destugues }
255fb816644SAdrien Destugues 
256fb816644SAdrien Destugues 
257fb816644SAdrien Destugues void
2586fd2f4a0SOliver Tappe FormatSettingsView::MessageReceived(BMessage* message)
259fb816644SAdrien Destugues {
260fb816644SAdrien Destugues 	switch (message->what) {
261*31c0024dSJohn Scipione 		case B_LOCALE_CHANGED:
262*31c0024dSJohn Scipione 		{
263*31c0024dSJohn Scipione 			// Time updated 12/24 hour clock
264*31c0024dSJohn Scipione 			BFormattingConventions conventions;
265*31c0024dSJohn Scipione 			BLocale::Default()->GetFormattingConventions(&conventions);
266*31c0024dSJohn Scipione 			if (conventions.Use24HourClock())
267*31c0024dSJohn Scipione 				f24HourRadioButton->SetValue(B_CONTROL_ON);
268*31c0024dSJohn Scipione 			else
269*31c0024dSJohn Scipione 				f12HourRadioButton->SetValue(B_CONTROL_ON);
270*31c0024dSJohn Scipione 
271*31c0024dSJohn Scipione 			_UpdateExamples();
272*31c0024dSJohn Scipione 			Window()->PostMessage(kMsgSettingsChanged);
273*31c0024dSJohn Scipione 			break;
274*31c0024dSJohn Scipione 		}
275*31c0024dSJohn Scipione 
276fb816644SAdrien Destugues 		case kClockFormatChange:
277fb816644SAdrien Destugues 		{
2786fd2f4a0SOliver Tappe 			BFormattingConventions conventions;
27925dc253dSIngo Weinhold 			BLocale::Default()->GetFormattingConventions(&conventions);
2806fd2f4a0SOliver Tappe 			conventions.SetExplicitUse24HourClock(
281*31c0024dSJohn Scipione 				f24HourRadioButton->Value() == B_CONTROL_ON);
28225dc253dSIngo Weinhold 			MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
28325dc253dSIngo Weinhold 				conventions);
284fb816644SAdrien Destugues 
285fb816644SAdrien Destugues 			_UpdateExamples();
2866fd2f4a0SOliver Tappe 			Window()->PostMessage(kMsgSettingsChanged);
2876fd2f4a0SOliver Tappe 			break;
2886fd2f4a0SOliver Tappe 		}
2896fd2f4a0SOliver Tappe 
2906fd2f4a0SOliver Tappe 		case kStringsLanguageChange:
2916fd2f4a0SOliver Tappe 		{
2926fd2f4a0SOliver Tappe 			BFormattingConventions conventions;
29325dc253dSIngo Weinhold 			BLocale::Default()->GetFormattingConventions(&conventions);
2946fd2f4a0SOliver Tappe 			conventions.SetUseStringsFromPreferredLanguage(
2956fd2f4a0SOliver Tappe 				fUseLanguageStringsCheckBox->Value() ? true : false);
29625dc253dSIngo Weinhold 			MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
29725dc253dSIngo Weinhold 				conventions);
2986fd2f4a0SOliver Tappe 
2996fd2f4a0SOliver Tappe 			_UpdateExamples();
3006fd2f4a0SOliver Tappe 
3016fd2f4a0SOliver Tappe 			Window()->PostMessage(kMsgSettingsChanged);
302fb816644SAdrien Destugues 			break;
303fb816644SAdrien Destugues 		}
304fb816644SAdrien Destugues 
305fb816644SAdrien Destugues 		default:
306fb816644SAdrien Destugues 			BView::MessageReceived(message);
307fb816644SAdrien Destugues 	}
308fb816644SAdrien Destugues }
309fb816644SAdrien Destugues 
310fb816644SAdrien Destugues 
311fb816644SAdrien Destugues void
3126fd2f4a0SOliver Tappe FormatSettingsView::Revert()
313fb816644SAdrien Destugues {
31425dc253dSIngo Weinhold 	MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
31525dc253dSIngo Weinhold 		fInitialConventions);
316bca1690bSAdrien Destugues 
317fb816644SAdrien Destugues 	_UpdateExamples();
318fb816644SAdrien Destugues }
319fb816644SAdrien Destugues 
320fb816644SAdrien Destugues 
321fb816644SAdrien Destugues void
3226fd2f4a0SOliver Tappe FormatSettingsView::Refresh(bool setInitial)
323fb816644SAdrien Destugues {
3246fd2f4a0SOliver Tappe 	BFormattingConventions conventions;
32525dc253dSIngo Weinhold 	BLocale::Default()->GetFormattingConventions(&conventions);
3266fd2f4a0SOliver Tappe 	if (setInitial)
3276fd2f4a0SOliver Tappe 		fInitialConventions = conventions;
3286fd2f4a0SOliver Tappe 
3296fd2f4a0SOliver Tappe 	if (!conventions.Use24HourClock()) {
3306fd2f4a0SOliver Tappe 		f12HourRadioButton->SetValue(B_CONTROL_ON);
3316fd2f4a0SOliver Tappe 		fLocaleIs24Hour = false;
3326fd2f4a0SOliver Tappe 	} else {
3336fd2f4a0SOliver Tappe 		f24HourRadioButton->SetValue(B_CONTROL_ON);
3346fd2f4a0SOliver Tappe 		fLocaleIs24Hour = true;
3356fd2f4a0SOliver Tappe 	}
3366fd2f4a0SOliver Tappe 
3376fd2f4a0SOliver Tappe 	fUseLanguageStringsCheckBox->SetValue(
3386fd2f4a0SOliver Tappe 		conventions.UseStringsFromPreferredLanguage()
3396fd2f4a0SOliver Tappe 			? B_CONTROL_ON : B_CONTROL_OFF);
3406fd2f4a0SOliver Tappe 
3416fd2f4a0SOliver Tappe 	_UpdateExamples();
342fb816644SAdrien Destugues }
343fb816644SAdrien Destugues 
344fb816644SAdrien Destugues 
3456fd2f4a0SOliver Tappe // Return true if the Revert button should be enabled (i.e. something has been
346fb816644SAdrien Destugues // changed)
347fb816644SAdrien Destugues bool
3486fd2f4a0SOliver Tappe FormatSettingsView::IsReversible() const
349fb816644SAdrien Destugues {
3506fd2f4a0SOliver Tappe 	BFormattingConventions conventions;
35125dc253dSIngo Weinhold 	BLocale::Default()->GetFormattingConventions(&conventions);
352fb816644SAdrien Destugues 
3536fd2f4a0SOliver Tappe 	return conventions != fInitialConventions;
354fb816644SAdrien Destugues }
355fb816644SAdrien Destugues 
356fb816644SAdrien Destugues 
357fb816644SAdrien Destugues void
3586fd2f4a0SOliver Tappe FormatSettingsView::_UpdateExamples()
359fb816644SAdrien Destugues {
360fb816644SAdrien Destugues 	time_t timeValue = (time_t)time(NULL);
3616fd2f4a0SOliver Tappe 	BString result;
362fb816644SAdrien Destugues 
36325dc253dSIngo Weinhold 	BLocale::Default()->FormatDate(&result, timeValue, B_FULL_DATE_FORMAT);
3646fd2f4a0SOliver Tappe 	fFullDateExampleView->SetText(result);
365fb816644SAdrien Destugues 
36625dc253dSIngo Weinhold 	BLocale::Default()->FormatDate(&result, timeValue, B_LONG_DATE_FORMAT);
3676fd2f4a0SOliver Tappe 	fLongDateExampleView->SetText(result);
368fb816644SAdrien Destugues 
36925dc253dSIngo Weinhold 	BLocale::Default()->FormatDate(&result, timeValue, B_MEDIUM_DATE_FORMAT);
3706fd2f4a0SOliver Tappe 	fMediumDateExampleView->SetText(result);
371fb816644SAdrien Destugues 
37225dc253dSIngo Weinhold 	BLocale::Default()->FormatDate(&result, timeValue, B_SHORT_DATE_FORMAT);
3736fd2f4a0SOliver Tappe 	fShortDateExampleView->SetText(result);
374fb816644SAdrien Destugues 
37525dc253dSIngo Weinhold 	BLocale::Default()->FormatTime(&result, timeValue, B_FULL_TIME_FORMAT);
3766fd2f4a0SOliver Tappe 	fFullTimeExampleView->SetText(result);
3776fd2f4a0SOliver Tappe 
37825dc253dSIngo Weinhold 	BLocale::Default()->FormatTime(&result, timeValue, B_LONG_TIME_FORMAT);
3796fd2f4a0SOliver Tappe 	fLongTimeExampleView->SetText(result);
3806fd2f4a0SOliver Tappe 
38125dc253dSIngo Weinhold 	BLocale::Default()->FormatTime(&result, timeValue, B_MEDIUM_TIME_FORMAT);
3826fd2f4a0SOliver Tappe 	fMediumTimeExampleView->SetText(result);
3836fd2f4a0SOliver Tappe 
38425dc253dSIngo Weinhold 	BLocale::Default()->FormatTime(&result, timeValue, B_SHORT_TIME_FORMAT);
3856fd2f4a0SOliver Tappe 	fShortTimeExampleView->SetText(result);
3866fd2f4a0SOliver Tappe 
38725dc253dSIngo Weinhold 	status_t status = BLocale::Default()->FormatNumber(&result, 1234.5678);
3886fd2f4a0SOliver Tappe 	if (status == B_OK)
3896fd2f4a0SOliver Tappe 		fPositiveNumberExampleView->SetText(result);
390fb816644SAdrien Destugues 	else
3916fd2f4a0SOliver Tappe 		fPositiveNumberExampleView->SetText("ERROR");
392fb816644SAdrien Destugues 
39325dc253dSIngo Weinhold 	status = BLocale::Default()->FormatNumber(&result, -1234.5678);
3946fd2f4a0SOliver Tappe 	if (status == B_OK)
3956fd2f4a0SOliver Tappe 		fNegativeNumberExampleView->SetText(result);
3969e773899SAdrien Destugues 	else
3976fd2f4a0SOliver Tappe 		fNegativeNumberExampleView->SetText("ERROR");
398bca1690bSAdrien Destugues 
39925dc253dSIngo Weinhold 	status = BLocale::Default()->FormatMonetary(&result, 1234.56);
4006fd2f4a0SOliver Tappe 	if (status == B_OK)
4016fd2f4a0SOliver Tappe 		fPositiveMonetaryExampleView->SetText(result);
4026fd2f4a0SOliver Tappe 	else
4036fd2f4a0SOliver Tappe 		fPositiveMonetaryExampleView->SetText("ERROR");
404bca1690bSAdrien Destugues 
40525dc253dSIngo Weinhold 	status = BLocale::Default()->FormatMonetary(&result, -1234.56);
4066fd2f4a0SOliver Tappe 	if (status == B_OK)
4076fd2f4a0SOliver Tappe 		fNegativeMonetaryExampleView->SetText(result);
4086fd2f4a0SOliver Tappe 	else
4096fd2f4a0SOliver Tappe 		fNegativeMonetaryExampleView->SetText("ERROR");
410fb816644SAdrien Destugues }
411