xref: /haiku/src/preferences/locale/FormatSettingsView.cpp (revision 9e7738992b3acb3d7675b20a41f02f2d99a90f1b)
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"
8fb816644SAdrien Destugues #include "Locale.h"
9fb816644SAdrien Destugues 
10fb816644SAdrien Destugues #include <Alert.h>
11fb816644SAdrien Destugues #include <Application.h>
12fb816644SAdrien Destugues #include <Catalog.h>
13fb816644SAdrien Destugues #include <CheckBox.h>
14fb816644SAdrien Destugues #include <ControlLook.h>
15fb816644SAdrien Destugues #include <Country.h>
16fb816644SAdrien Destugues #include <GroupLayout.h>
17fb816644SAdrien Destugues #include <GroupLayoutBuilder.h>
18fb816644SAdrien Destugues #include <LayoutBuilder.h>
19fb816644SAdrien Destugues #include <Locale.h>
20fb816644SAdrien Destugues #include <MutableLocaleRoster.h>
21fb816644SAdrien Destugues #include <Message.h>
22fb816644SAdrien Destugues #include <Menu.h>
23fb816644SAdrien Destugues #include <MenuField.h>
24fb816644SAdrien Destugues #include <MenuItem.h>
25fb816644SAdrien Destugues #include <PopUpMenu.h>
26fb816644SAdrien Destugues #include <RadioButton.h>
27fb816644SAdrien Destugues #include <ScrollView.h>
28fb816644SAdrien Destugues #include <ScrollBar.h>
29fb816644SAdrien Destugues #include <SeparatorView.h>
30fb816644SAdrien Destugues #include <String.h>
31fb816644SAdrien Destugues #include <StringView.h>
32fb816644SAdrien Destugues #include <TextControl.h>
33fb816644SAdrien Destugues #include <Window.h>
34fb816644SAdrien Destugues 
35bca1690bSAdrien Destugues #include <stdio.h>
36bca1690bSAdrien Destugues #include <stdlib.h>
37bca1690bSAdrien Destugues 
38fb816644SAdrien Destugues 
3934a79bffSOliver Tappe using BPrivate::gMutableLocaleRoster;
40fb816644SAdrien Destugues 
41fb816644SAdrien Destugues 
42fb816644SAdrien Destugues #undef B_TRANSLATE_CONTEXT
43fb816644SAdrien Destugues #define B_TRANSLATE_CONTEXT "TimeFormatSettings"
44fb816644SAdrien Destugues 
45fb816644SAdrien Destugues 
46fb816644SAdrien Destugues class DateMenuItem: public BMenuItem {
47fb816644SAdrien Destugues public:
48fb816644SAdrien Destugues 	DateMenuItem(const char* label, const char* code, BMenuField* field)
49fb816644SAdrien Destugues 		:
50fb816644SAdrien Destugues 		BMenuItem(label, _MenuMessage(code, field))
51fb816644SAdrien Destugues 	{
52fb816644SAdrien Destugues 		fIcuCode = code;
53fb816644SAdrien Destugues 	}
54fb816644SAdrien Destugues 
55fb816644SAdrien Destugues 	const BString& ICUCode() const
56fb816644SAdrien Destugues 	{
57fb816644SAdrien Destugues 		return fIcuCode;
58fb816644SAdrien Destugues 	}
59fb816644SAdrien Destugues 
60fb816644SAdrien Destugues private:
61fb816644SAdrien Destugues 	static BMessage* _MenuMessage(const char* format, BMenuField* field)
62fb816644SAdrien Destugues 	{
63fb816644SAdrien Destugues 		BMessage* msg = new BMessage(kMenuMessage);
64fb816644SAdrien Destugues 		msg->AddPointer("dest", field);
65fb816644SAdrien Destugues 		msg->AddString("format", format);
66fb816644SAdrien Destugues 
67fb816644SAdrien Destugues 		return msg;
68fb816644SAdrien Destugues 	}
69fb816644SAdrien Destugues 
70fb816644SAdrien Destugues private:
71fb816644SAdrien Destugues 	BString			fIcuCode;
72fb816644SAdrien Destugues };
73fb816644SAdrien Destugues 
74fb816644SAdrien Destugues 
75fb816644SAdrien Destugues void
76fb816644SAdrien Destugues CreateDateMenu(BMenuField** field, bool longFormat = true)
77fb816644SAdrien Destugues {
78fb816644SAdrien Destugues 	BMenu* menu = new BMenu("");
79fb816644SAdrien Destugues 	*field = new BMenuField("", menu);
80fb816644SAdrien Destugues 
81fb816644SAdrien Destugues 	BPopUpMenu* dayMenu = new BPopUpMenu(B_TRANSLATE("Day"));
82fb816644SAdrien Destugues 	// Not all available ICU settings are listed here. It's possible to add some
83fb816644SAdrien Destugues 	// other things if you ever need.
84fb816644SAdrien Destugues 	menu->AddItem(dayMenu);
85fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
86fb816644SAdrien Destugues 			B_TRANSLATE("Day in month"), "d", *field));
87fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
88fb816644SAdrien Destugues 			B_TRANSLATE("Day in month (2 digits)"), "dd", *field));
89fb816644SAdrien Destugues 		/*
90fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(B_TRANSLATE("Day in year"),
91fb816644SAdrien Destugues 			"D", *field));
92fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(B_TRANSLATE("Day in year (2 digits)"),
93fb816644SAdrien Destugues 			"DD", *field));
94fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(B_TRANSLATE("Day in year (3 digits)"),
95fb816644SAdrien Destugues 			"DDD", *field));
96fb816644SAdrien Destugues 		*/
97fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
98fb816644SAdrien Destugues 			B_TRANSLATE("Day of week"), "e", *field));
99fb816644SAdrien Destugues 		// dayMenu->AddItem(new DateMenuItem("Day of week (short text)", "eee",
100fb816644SAdrien Destugues 		//	*field));
101fb816644SAdrien Destugues 		// dayMenu->AddItem(new DateMenuItem("Day of week (full text)", "eeee",
102fb816644SAdrien Destugues 		//	*field));
103fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
104fb816644SAdrien Destugues 			B_TRANSLATE("Day of week (short name)"), "E", *field));
105fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
106fb816644SAdrien Destugues 			B_TRANSLATE("Day of week (name)"), "EEEE", *field));
107fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
108fb816644SAdrien Destugues 			B_TRANSLATE("Day of week in month"), "F", *field));
109fb816644SAdrien Destugues 		// dayMenu->AddItem(new DateMenuItem(
110fb816644SAdrien Destugues 		//	B_TRANSLATE("julian day"), "g", *field));
111fb816644SAdrien Destugues 		// dayMenu->AddItem(new BMenuItem("c", msg));
112fb816644SAdrien Destugues 	BPopUpMenu* monthMenu = new BPopUpMenu(B_TRANSLATE("Month"));
113fb816644SAdrien Destugues 	menu->AddItem(monthMenu);
114fb816644SAdrien Destugues 		monthMenu->AddItem(new DateMenuItem(
115fb816644SAdrien Destugues 			B_TRANSLATE("Month number"), "M", *field));
116fb816644SAdrien Destugues 		monthMenu->AddItem(new DateMenuItem(
117fb816644SAdrien Destugues 			B_TRANSLATE("Month number (2 digits)"), "MM", *field));
118fb816644SAdrien Destugues 		monthMenu->AddItem(new DateMenuItem(
119fb816644SAdrien Destugues 			B_TRANSLATE("Month name"), "MMMM", *field));
120fb816644SAdrien Destugues 		// monthMenu->AddItem(new DateMenuItem("L", "L", *field));
121fb816644SAdrien Destugues 	BPopUpMenu* yearMenu = new BPopUpMenu(B_TRANSLATE("Year"));
122fb816644SAdrien Destugues 	menu->AddItem(yearMenu);
123fb816644SAdrien Destugues 		// And here is some ICU kludge... sorry about that.
124fb816644SAdrien Destugues 		if (longFormat)
125fb816644SAdrien Destugues 			yearMenu->AddItem(new DateMenuItem(
126fb816644SAdrien Destugues 				B_TRANSLATE("Year"), "y", *field));
127fb816644SAdrien Destugues 		else {
128fb816644SAdrien Destugues 			yearMenu->AddItem(new DateMenuItem(
129fb816644SAdrien Destugues 				B_TRANSLATE("Year (4 digits)"), "yyyy", *field));
130fb816644SAdrien Destugues 		}
131fb816644SAdrien Destugues 		yearMenu->AddItem(new DateMenuItem(
132fb816644SAdrien Destugues 			B_TRANSLATE("Year (2 digits)"), "yy", *field));
133fb816644SAdrien Destugues 		// yearMenu->AddItem(new DateMenuItem("Y", "Y", *field));
134fb816644SAdrien Destugues 		// yearMenu->AddItem(new DateMenuItem("u", "u", *field));
135fb816644SAdrien Destugues }
136fb816644SAdrien Destugues 
137fb816644SAdrien Destugues 
138fb816644SAdrien Destugues bool
139fb816644SAdrien Destugues IsSpecialDateChar(char charToTest)
140fb816644SAdrien Destugues {
141fb816644SAdrien Destugues 	static const char* specials = "dDeEFgMLyYu";
142fb816644SAdrien Destugues 	for (int i = 0; i < 11; i++)
143fb816644SAdrien Destugues 		if (charToTest == specials[i])
144fb816644SAdrien Destugues 			return true;
145fb816644SAdrien Destugues 	return false;
146fb816644SAdrien Destugues }
147fb816644SAdrien Destugues 
148fb816644SAdrien Destugues // #pragma mark -
149fb816644SAdrien Destugues 
150fb816644SAdrien Destugues 
1515c3a3034SAdrien Destugues FormatView::FormatView(const BLocale& locale)
152fb816644SAdrien Destugues 	:
153fb816644SAdrien Destugues 	BView("WindowsSettingsView", B_FRAME_EVENTS),
1545c3a3034SAdrien Destugues 	fLocale(locale)
155fb816644SAdrien Destugues {
156fb816644SAdrien Destugues 	fLongDateExampleView = new BStringView("", "");
157fb816644SAdrien Destugues 
158fb816644SAdrien Destugues 	for (int i = 0; i < 4; i++) {
159fb816644SAdrien Destugues 		CreateDateMenu(&fLongDateMenu[i]);
160fb816644SAdrien Destugues 		fLongDateSeparator[i] = new BTextControl("", "", "",
161fb816644SAdrien Destugues 			new BMessage(kSettingsContentsModified));
162fb816644SAdrien Destugues 		fLongDateSeparator[i]->SetModificationMessage(
163fb816644SAdrien Destugues 			new BMessage(kSettingsContentsModified));
164fb816644SAdrien Destugues 	}
165fb816644SAdrien Destugues 
166fb816644SAdrien Destugues 	fShortDateExampleView = new BStringView("", "");
167fb816644SAdrien Destugues 
168fb816644SAdrien Destugues 	for (int i = 0; i < 3; i++) {
169fb816644SAdrien Destugues 		CreateDateMenu(&fDateMenu[i], false);
170fb816644SAdrien Destugues 	}
171fb816644SAdrien Destugues 
172fb816644SAdrien Destugues 	BPopUpMenu* menu = new BPopUpMenu(B_TRANSLATE("Separator"));
173fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem(B_TRANSLATE("None"),
174fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified)));
175fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem(B_TRANSLATE("Space"),
176fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified)));
177fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem("-", new BMessage(kSettingsContentsModified)));
178fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem("/", new BMessage(kSettingsContentsModified)));
179fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem("\\", new BMessage(kSettingsContentsModified)));
180fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem(".", new BMessage(kSettingsContentsModified)));
181fb816644SAdrien Destugues 
182fb816644SAdrien Destugues 	fSeparatorMenuField = new BMenuField(B_TRANSLATE("Separator:"), menu);
183fb816644SAdrien Destugues 
184fb816644SAdrien Destugues 	f24HrRadioButton = new BRadioButton("", B_TRANSLATE("24 hour"),
185fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
186fb816644SAdrien Destugues 
187fb816644SAdrien Destugues 	f12HrRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"),
188fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
189fb816644SAdrien Destugues 
1905c3a3034SAdrien Destugues 	fLocale.GetTimeFormat(fOriginalTimeFormat, false);
1915c3a3034SAdrien Destugues 	fLocale.GetTimeFormat(fOriginalLongTimeFormat, true);
192fb816644SAdrien Destugues 	if (fOriginalTimeFormat.FindFirst("a") != B_ERROR) {
193fb816644SAdrien Destugues 		f12HrRadioButton->SetValue(B_CONTROL_ON);
1945c3a3034SAdrien Destugues 		fLocaleIs24Hr = false;
195fb816644SAdrien Destugues 	} else {
196fb816644SAdrien Destugues 		f24HrRadioButton->SetValue(B_CONTROL_ON);
1975c3a3034SAdrien Destugues 		fLocaleIs24Hr = true;
198fb816644SAdrien Destugues 	}
199fb816644SAdrien Destugues 
200fb816644SAdrien Destugues 	float spacing = be_control_look->DefaultItemSpacing();
201fb816644SAdrien Destugues 
202fb816644SAdrien Destugues 	fLongTimeExampleView = new BStringView("", "");
203fb816644SAdrien Destugues 	fShortTimeExampleView = new BStringView("", "");
204fb816644SAdrien Destugues 
205fb816644SAdrien Destugues 	fNumberFormatExampleView = new BStringView("", "");
206fb816644SAdrien Destugues 
207fb816644SAdrien Destugues 	BTextControl* numberThousand = new BTextControl("",
208fb816644SAdrien Destugues 		B_TRANSLATE("Thousand separator: "), "",
209fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
210fb816644SAdrien Destugues 	BTextControl* numberDecimal = new BTextControl("",
211fb816644SAdrien Destugues 		B_TRANSLATE("Decimal separator: "),	"",
212fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
213fb816644SAdrien Destugues 	// TODO number of decimal digits (spinbox ?)
214fb816644SAdrien Destugues 	BCheckBox* numberLeadingZero = new BCheckBox("", B_TRANSLATE("Leading 0"),
215fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
216fb816644SAdrien Destugues 	BTextControl* numberList = new BTextControl("",
217fb816644SAdrien Destugues 		B_TRANSLATE("List separator: "), "",
218fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
219fb816644SAdrien Destugues 	// Unit system (US/Metric) (radio)
220fb816644SAdrien Destugues 
221bca1690bSAdrien Destugues 	fCurrencySymbolView = new BTextControl("",
222fb816644SAdrien Destugues 		B_TRANSLATE("Currency symbol:"), "",
223fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
224fb816644SAdrien Destugues 	menu = new BPopUpMenu(B_TRANSLATE("Negative marker"));
225fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem("-", new BMessage(kSettingsContentsModified)));
226fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem("()", new BMessage(kSettingsContentsModified)));
227fb816644SAdrien Destugues 
228fb816644SAdrien Destugues 	BMenuField* currencyNegative = new BMenuField(
229fb816644SAdrien Destugues 		B_TRANSLATE("Negative marker:"), menu);
230fb816644SAdrien Destugues 
231fb816644SAdrien Destugues 	BTextControl* currencyDecimal = new BTextControl("",
232fb816644SAdrien Destugues 		B_TRANSLATE("Decimal separator: "), "",
233fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
234fb816644SAdrien Destugues 	BCheckBox* currencyLeadingZero = new BCheckBox("",
235fb816644SAdrien Destugues 		B_TRANSLATE("Leading 0"), new BMessage(kSettingsContentsModified));
236fb816644SAdrien Destugues 
237*9e773899SAdrien Destugues 	fCurrencySymbolBefore = new BRadioButton("CurrencySymbolPosition",
238fb816644SAdrien Destugues 		B_TRANSLATE("Before"), new BMessage(kSettingsContentsModified));
239fb816644SAdrien Destugues 
240*9e773899SAdrien Destugues 	fCurrencySymbolAfter = new BRadioButton("CurrencySymbolPosition",
241fb816644SAdrien Destugues 		B_TRANSLATE("After"), new BMessage(kSettingsContentsModified));
242fb816644SAdrien Destugues 
243bca1690bSAdrien Destugues 	fMonetaryView = new BStringView("", "");
244bca1690bSAdrien Destugues 
245fb816644SAdrien Destugues 	_UpdateExamples();
246fb816644SAdrien Destugues 	_ParseDateFormat();
247bca1690bSAdrien Destugues 	_ParseCurrencyFormat();
248fb816644SAdrien Destugues 
249fb816644SAdrien Destugues 	fDateBox = new BBox(B_TRANSLATE("Date"));
250fb816644SAdrien Destugues 	fTimeBox = new BBox(B_TRANSLATE("Time"));
251fb816644SAdrien Destugues 	fNumbersBox = new BBox(B_TRANSLATE("Numbers"));
252fb816644SAdrien Destugues 	fCurrencyBox = new BBox(B_TRANSLATE("Currency"));
253fb816644SAdrien Destugues 
254fb816644SAdrien Destugues 	fDateBox->SetLabel(B_TRANSLATE("Date"));
255fb816644SAdrien Destugues 	fTimeBox->SetLabel(B_TRANSLATE("Time"));
256fb816644SAdrien Destugues 	fNumbersBox->SetLabel(B_TRANSLATE("Numbers"));
257fb816644SAdrien Destugues 	fCurrencyBox->SetLabel(B_TRANSLATE("Currency"));
258fb816644SAdrien Destugues 
25925fd5c7bSAlex Wilson 	fDateBox->AddChild(BLayoutBuilder::Group<>(B_VERTICAL, spacing / 2)
26025fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
261fb816644SAdrien Destugues 		.AddGroup(B_HORIZONTAL, spacing)
262fb816644SAdrien Destugues 			.Add(new BStringView("", B_TRANSLATE("Long format:")))
263fb816644SAdrien Destugues 			.Add(fLongDateExampleView)
264fb816644SAdrien Destugues 			.AddGlue()
265fb816644SAdrien Destugues 			.End()
266fb816644SAdrien Destugues 		.AddGroup(B_HORIZONTAL, spacing)
267fb816644SAdrien Destugues 			.Add(fLongDateMenu[0])
268fb816644SAdrien Destugues 			.Add(fLongDateSeparator[0])
269fb816644SAdrien Destugues 			.End()
270fb816644SAdrien Destugues 		.AddGroup(B_HORIZONTAL, spacing)
271fb816644SAdrien Destugues 			.Add(fLongDateMenu[1])
272fb816644SAdrien Destugues 			.Add(fLongDateSeparator[1])
273fb816644SAdrien Destugues 			.End()
274fb816644SAdrien Destugues 		.AddGroup(B_HORIZONTAL, spacing)
275fb816644SAdrien Destugues 			.Add(fLongDateMenu[2])
276fb816644SAdrien Destugues 			.Add(fLongDateSeparator[2])
277fb816644SAdrien Destugues 			.End()
278fb816644SAdrien Destugues 		.AddGroup(B_HORIZONTAL, spacing)
279fb816644SAdrien Destugues 			.Add(fLongDateMenu[3])
280fb816644SAdrien Destugues 			.Add(fLongDateSeparator[3])
281fb816644SAdrien Destugues 			.End()
282fb816644SAdrien Destugues 		.AddGroup(B_HORIZONTAL, spacing)
283fb816644SAdrien Destugues 			.Add(new BStringView("", B_TRANSLATE("Short format:")))
284fb816644SAdrien Destugues 			.Add(fShortDateExampleView)
285fb816644SAdrien Destugues 			.AddGlue()
286fb816644SAdrien Destugues 			.End()
287fb816644SAdrien Destugues 		.Add(fDateMenu[0])
288fb816644SAdrien Destugues 		.Add(fDateMenu[1])
289fb816644SAdrien Destugues 		.Add(fDateMenu[2])
29025fd5c7bSAlex Wilson 		.View());
291fb816644SAdrien Destugues 
29225fd5c7bSAlex Wilson 	fTimeBox->AddChild(BLayoutBuilder::Group<>(B_VERTICAL, spacing / 2)
29325fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
294fb816644SAdrien Destugues 		.AddGroup(B_HORIZONTAL, spacing)
295fb816644SAdrien Destugues 			.Add(new BStringView("", B_TRANSLATE("Long format:")))
296fb816644SAdrien Destugues 			.Add(fLongTimeExampleView)
297fb816644SAdrien Destugues 			.AddGlue()
298fb816644SAdrien Destugues 			.End()
299fb816644SAdrien Destugues 		.AddGroup(B_HORIZONTAL, spacing)
300fb816644SAdrien Destugues 			.Add(new BStringView("", B_TRANSLATE("Short format:")))
301fb816644SAdrien Destugues 			.Add(fShortTimeExampleView)
302fb816644SAdrien Destugues 			.AddGlue()
303fb816644SAdrien Destugues 			.End()
304fb816644SAdrien Destugues 		.AddGroup(B_HORIZONTAL, spacing)
305fb816644SAdrien Destugues 			.Add(f24HrRadioButton)
306fb816644SAdrien Destugues 			.Add(f12HrRadioButton)
307fb816644SAdrien Destugues 			.AddGlue()
308fb816644SAdrien Destugues 			.End()
30925fd5c7bSAlex Wilson 		.View());
310fb816644SAdrien Destugues 
31125fd5c7bSAlex Wilson 	fNumbersBox->AddChild(BLayoutBuilder::Group<>(B_VERTICAL, spacing / 2)
31225fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
313fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
314fb816644SAdrien Destugues 				.Add(new BStringView("", B_TRANSLATE("Example:")))
315fb816644SAdrien Destugues 				.Add(fNumberFormatExampleView)
316fb816644SAdrien Destugues 				.AddGlue()
317fb816644SAdrien Destugues 				.End()
318fb816644SAdrien Destugues 			.Add(numberThousand)
319fb816644SAdrien Destugues 			.Add(numberDecimal)
320fb816644SAdrien Destugues 			.Add(numberLeadingZero)
321fb816644SAdrien Destugues 			.Add(numberList)
32225fd5c7bSAlex Wilson 			.View());
323fb816644SAdrien Destugues 
32425fd5c7bSAlex Wilson 	fCurrencyBox->AddChild(BLayoutBuilder::Group<>(B_VERTICAL, spacing / 2)
32525fd5c7bSAlex Wilson 		.SetInsets(spacing, spacing, spacing, spacing)
326bca1690bSAdrien Destugues 		.Add(fMonetaryView)
327bca1690bSAdrien Destugues 		.Add(fCurrencySymbolView)
32800c81cb9SAdrien Destugues 		.AddGroup(B_HORIZONTAL, spacing)
32900c81cb9SAdrien Destugues 			.AddGlue()
330*9e773899SAdrien Destugues 			.Add(fCurrencySymbolBefore)
331*9e773899SAdrien Destugues 			.Add(fCurrencySymbolAfter)
33200c81cb9SAdrien Destugues 			.End()
333fb816644SAdrien Destugues 		.Add(currencyNegative)
334fb816644SAdrien Destugues 		.Add(currencyDecimal)
335fb816644SAdrien Destugues 		.Add(currencyLeadingZero)
33625fd5c7bSAlex Wilson 		.View());
337fb816644SAdrien Destugues 
33825fd5c7bSAlex Wilson 
33925fd5c7bSAlex Wilson 	BGroupLayout* rootLayout = new BGroupLayout(B_HORIZONTAL, spacing);
34025fd5c7bSAlex Wilson 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
34125fd5c7bSAlex Wilson 	SetLayout(rootLayout);
34225fd5c7bSAlex Wilson 	BLayoutBuilder::Group<>(rootLayout)
343fb816644SAdrien Destugues 		.AddGroup(B_VERTICAL, spacing)
344fb816644SAdrien Destugues 			.Add(fDateBox)
345fb816644SAdrien Destugues 			.Add(fTimeBox)
346fb816644SAdrien Destugues 			.AddGlue()
347fb816644SAdrien Destugues 			.End()
348fb816644SAdrien Destugues 		.AddGroup(B_VERTICAL, spacing)
349fb816644SAdrien Destugues 			.Add(fNumbersBox)
350fb816644SAdrien Destugues 			.Add(fCurrencyBox)
35125fd5c7bSAlex Wilson 			.AddGlue();
352fb816644SAdrien Destugues }
353fb816644SAdrien Destugues 
354fb816644SAdrien Destugues 
355fb816644SAdrien Destugues FormatView::~FormatView()
356fb816644SAdrien Destugues {
35734a79bffSOliver Tappe 	gMutableLocaleRoster->SetDefaultLocale(fLocale);
358fb816644SAdrien Destugues }
359fb816644SAdrien Destugues 
360fb816644SAdrien Destugues 
361fb816644SAdrien Destugues void
362fb816644SAdrien Destugues FormatView::AttachedToWindow()
363fb816644SAdrien Destugues {
364fb816644SAdrien Destugues 	f24HrRadioButton->SetTarget(this);
365fb816644SAdrien Destugues 	f12HrRadioButton->SetTarget(this);
366fb816644SAdrien Destugues 
367fb816644SAdrien Destugues 	for (int j = 0; j < 4; j++) {
368fb816644SAdrien Destugues 		for (int i = 0; i < fLongDateMenu[j]->Menu()->CountItems(); i++)
369fb816644SAdrien Destugues 			fLongDateMenu[j]->Menu()->SubmenuAt(i)->SetTargetForItems(this);
370fb816644SAdrien Destugues 		fLongDateSeparator[j]->SetTarget(this);
371fb816644SAdrien Destugues 	}
372fb816644SAdrien Destugues 
373fb816644SAdrien Destugues 	for (int j = 0; j < 3; j++) {
374fb816644SAdrien Destugues 		for (int i = 0; i < fDateMenu[j]->Menu()->CountItems(); i++)
375fb816644SAdrien Destugues 			fDateMenu[j]->Menu()->SubmenuAt(i)->SetTargetForItems(this);
376fb816644SAdrien Destugues 	}
377fb816644SAdrien Destugues 
378fb816644SAdrien Destugues 	fSeparatorMenuField->Menu()->SetTargetForItems(this);
379fb816644SAdrien Destugues }
380fb816644SAdrien Destugues 
381fb816644SAdrien Destugues 
382fb816644SAdrien Destugues void
383fb816644SAdrien Destugues FormatView::MessageReceived(BMessage* message)
384fb816644SAdrien Destugues {
385fb816644SAdrien Destugues 	switch (message->what) {
386fb816644SAdrien Destugues 		case kMenuMessage:
387fb816644SAdrien Destugues 		{
388fb816644SAdrien Destugues 			// Update one of the dropdown menus
389fb816644SAdrien Destugues 			void* pointerFromMessage;
390fb816644SAdrien Destugues 			message->FindPointer("dest", &pointerFromMessage);
391fb816644SAdrien Destugues 			BMenuField* menuField
392fb816644SAdrien Destugues 			= static_cast<BMenuField*>(pointerFromMessage);
393fb816644SAdrien Destugues 			BString format;
394fb816644SAdrien Destugues 			message->FindString("format", &format);
395fb816644SAdrien Destugues 
396fb816644SAdrien Destugues 			for (int i = 0; i < 4; i++) {
397fb816644SAdrien Destugues 				if (fLongDateMenu[i]==menuField) {
398fb816644SAdrien Destugues 					fLongDateString[i] = format;
399fb816644SAdrien Destugues 					break;
400fb816644SAdrien Destugues 				}
401fb816644SAdrien Destugues 			}
402fb816644SAdrien Destugues 
403fb816644SAdrien Destugues 			for (int i = 0; i < 3; i++) {
404fb816644SAdrien Destugues 				if (fDateMenu[i]==menuField) {
405fb816644SAdrien Destugues 					fDateString[i] = format;
406fb816644SAdrien Destugues 					break;
407fb816644SAdrien Destugues 				}
408fb816644SAdrien Destugues 			}
409fb816644SAdrien Destugues 
410fb816644SAdrien Destugues 			message->FindPointer("source", &pointerFromMessage);
411fb816644SAdrien Destugues 			BMenuItem* menuItem = static_cast<BMenuItem*>(pointerFromMessage);
412fb816644SAdrien Destugues 
413fb816644SAdrien Destugues 			menuField->MenuItem()->SetLabel(menuItem->Label());
414fb816644SAdrien Destugues 
415fb816644SAdrien Destugues 			_UpdateLongDateFormatString();
416fb816644SAdrien Destugues 		}
417fb816644SAdrien Destugues 		// pass trough
418fb816644SAdrien Destugues 		case kSettingsContentsModified:
419fb816644SAdrien Destugues 			{
420fb816644SAdrien Destugues 				int32 separator = 0;
421fb816644SAdrien Destugues 				BMenuItem* item = fSeparatorMenuField->Menu()->FindMarked();
422fb816644SAdrien Destugues 				if (item) {
423fb816644SAdrien Destugues 					separator = fSeparatorMenuField->Menu()->IndexOf(item);
424fb816644SAdrien Destugues 					if (separator >= 0)
425fb816644SAdrien Destugues 						// settings.SetTimeFormatSeparator(
426fb816644SAdrien Destugues 						//	(FormatSeparator)separator);
427fb816644SAdrien Destugues 						;
428fb816644SAdrien Destugues 				}
429fb816644SAdrien Destugues 
430fb816644SAdrien Destugues 				// Make the notification message and send it to the tracker:
431fb816644SAdrien Destugues 				BMessage notificationMessage;
432fb816644SAdrien Destugues 				notificationMessage.AddInt32("TimeFormatSeparator", separator);
433fb816644SAdrien Destugues 				notificationMessage.AddBool("24HrClock",
434fb816644SAdrien Destugues 					f24HrRadioButton->Value() == 1);
435fb816644SAdrien Destugues 
436fb816644SAdrien Destugues 				_UpdateExamples();
437fb816644SAdrien Destugues 
438fb816644SAdrien Destugues 				Window()->PostMessage(kSettingsContentsModified);
439fb816644SAdrien Destugues 				break;
440fb816644SAdrien Destugues 			}
441fb816644SAdrien Destugues 
442fb816644SAdrien Destugues 		case kClockFormatChange:
443fb816644SAdrien Destugues 		{
444fb816644SAdrien Destugues 			BMessage newMessage(kMsgSettingsChanged);
445fb816644SAdrien Destugues 
446fb816644SAdrien Destugues 			BString timeFormat;
447fb816644SAdrien Destugues 			timeFormat = fOriginalTimeFormat;
448fb816644SAdrien Destugues 			if (f24HrRadioButton->Value() == 1) {
4495c3a3034SAdrien Destugues 				if (!fLocaleIs24Hr) {
450fb816644SAdrien Destugues 					timeFormat.ReplaceAll("h", "H");
451fb816644SAdrien Destugues 					timeFormat.ReplaceAll("k", "K");
452fb816644SAdrien Destugues 					timeFormat.RemoveAll(" a");
453fb816644SAdrien Destugues 					timeFormat.RemoveAll("a");
454fb816644SAdrien Destugues 				}
455fb816644SAdrien Destugues 			} else {
4565c3a3034SAdrien Destugues 				if (fLocaleIs24Hr && timeFormat.FindFirst("a") == B_ERROR) {
457fb816644SAdrien Destugues 					timeFormat.ReplaceAll("K", "k");
458fb816644SAdrien Destugues 					timeFormat.ReplaceAll("H", "h");
459fb816644SAdrien Destugues 					timeFormat.Append(" a");
460fb816644SAdrien Destugues 				}
461fb816644SAdrien Destugues 			}
4625c3a3034SAdrien Destugues 			fLocale.SetTimeFormat(timeFormat.String(), false);
463fb816644SAdrien Destugues 			newMessage.AddString("shortTimeFormat", timeFormat);
464fb816644SAdrien Destugues 
465fb816644SAdrien Destugues 			timeFormat = fOriginalLongTimeFormat;
466fb816644SAdrien Destugues 			if (f24HrRadioButton->Value() == 1) {
4675c3a3034SAdrien Destugues 				if (!fLocaleIs24Hr) {
468fb816644SAdrien Destugues 					timeFormat.ReplaceAll("h", "H");
469fb816644SAdrien Destugues 					timeFormat.ReplaceAll("k", "K");
470fb816644SAdrien Destugues 					timeFormat.RemoveAll(" a");
471fb816644SAdrien Destugues 					timeFormat.RemoveAll("a");
472fb816644SAdrien Destugues 				}
473fb816644SAdrien Destugues 			} else {
4745c3a3034SAdrien Destugues 				if (fLocaleIs24Hr && timeFormat.FindFirst("a") == B_ERROR) {
475fb816644SAdrien Destugues 					timeFormat.ReplaceAll("K", "k");
476fb816644SAdrien Destugues 					timeFormat.ReplaceAll("H", "h");
477fb816644SAdrien Destugues 					timeFormat.Append(" a");
478fb816644SAdrien Destugues 				}
479fb816644SAdrien Destugues 			}
4805c3a3034SAdrien Destugues 			fLocale.SetTimeFormat(timeFormat.String(), true);
481fb816644SAdrien Destugues 			newMessage.AddString("longTimeFormat", timeFormat);
482fb816644SAdrien Destugues 			_UpdateExamples();
483fb816644SAdrien Destugues 			Window()->PostMessage(kSettingsContentsModified);
484fb816644SAdrien Destugues 			be_app_messenger.SendMessage(&newMessage);
485fb816644SAdrien Destugues 			break;
486fb816644SAdrien Destugues 		}
487fb816644SAdrien Destugues 
488fb816644SAdrien Destugues 		default:
489fb816644SAdrien Destugues 			BView::MessageReceived(message);
490fb816644SAdrien Destugues 	}
491fb816644SAdrien Destugues }
492fb816644SAdrien Destugues 
493fb816644SAdrien Destugues 
494fb816644SAdrien Destugues void
495fb816644SAdrien Destugues FormatView::SetDefaults()
496fb816644SAdrien Destugues {
497fb816644SAdrien Destugues 	/*
498fb816644SAdrien Destugues 	TrackerSettings settings;
499fb816644SAdrien Destugues 
500fb816644SAdrien Destugues 	settings.SetTimeFormatSeparator(kSlashSeparator);
501fb816644SAdrien Destugues 	settings.SetDateOrderFormat(kMDYFormat);
502fb816644SAdrien Destugues 	settings.SetClockTo24Hr(false);
503fb816644SAdrien Destugues 	*/
504fb816644SAdrien Destugues 
5055c3a3034SAdrien Destugues 	BLocale defaultLocale;
5065c3a3034SAdrien Destugues 	be_locale_roster->GetDefaultLocale(&defaultLocale);
5075c3a3034SAdrien Destugues 	fLocale = defaultLocale;
508fb816644SAdrien Destugues 		// We work on a copy of the default country and set the changes when
509fb816644SAdrien Destugues 		// closing the preflet
510fb816644SAdrien Destugues 	_UpdateExamples();
511fb816644SAdrien Destugues 	_SendNotices();
512fb816644SAdrien Destugues }
513fb816644SAdrien Destugues 
514fb816644SAdrien Destugues 
515fb816644SAdrien Destugues bool
516fb816644SAdrien Destugues FormatView::IsDefaultable() const
517fb816644SAdrien Destugues {
518fb816644SAdrien Destugues 	/*
519fb816644SAdrien Destugues 	TrackerSettings settings;
520fb816644SAdrien Destugues 
521fb816644SAdrien Destugues 	return settings.TimeFormatSeparator() != kSlashSeparator
522fb816644SAdrien Destugues 		|| settings.DateOrderFormat() != kMDYFormat
523fb816644SAdrien Destugues 		|| settings.ClockIs24Hr() != false;
524fb816644SAdrien Destugues 	*/
525fb816644SAdrien Destugues 	return true;
526fb816644SAdrien Destugues }
527fb816644SAdrien Destugues 
528fb816644SAdrien Destugues 
529fb816644SAdrien Destugues void
530fb816644SAdrien Destugues FormatView::Revert()
531fb816644SAdrien Destugues {
532fb816644SAdrien Destugues 	/*
533fb816644SAdrien Destugues 	TrackerSettings settings;
534fb816644SAdrien Destugues 
535fb816644SAdrien Destugues 	settings.SetTimeFormatSeparator(fSeparator);
536fb816644SAdrien Destugues 	settings.SetDateOrderFormat(fFormat);
537fb816644SAdrien Destugues 	settings.SetClockTo24Hr(f24HrClock);
538fb816644SAdrien Destugues 	*/
539fb816644SAdrien Destugues 
540fb816644SAdrien Destugues 	// ShowCurrentSettings();
541fb816644SAdrien Destugues 	_SendNotices();
542fb816644SAdrien Destugues }
543fb816644SAdrien Destugues 
544fb816644SAdrien Destugues 
545fb816644SAdrien Destugues void
5465c3a3034SAdrien Destugues FormatView::SetLocale(const BLocale& locale)
547fb816644SAdrien Destugues {
5485c3a3034SAdrien Destugues 	fLocale = locale;
549fb816644SAdrien Destugues 
5505c3a3034SAdrien Destugues 	fLocale.GetTimeFormat(fOriginalTimeFormat, false);
5515c3a3034SAdrien Destugues 	fLocale.GetTimeFormat(fOriginalLongTimeFormat, true);
552fb816644SAdrien Destugues 
553fb816644SAdrien Destugues 	if (fOriginalTimeFormat.FindFirst("a") != B_ERROR) {
554fb816644SAdrien Destugues 		f12HrRadioButton->SetValue(B_CONTROL_ON);
5555c3a3034SAdrien Destugues 		fLocaleIs24Hr = false;
556fb816644SAdrien Destugues 	} else {
557fb816644SAdrien Destugues 		f24HrRadioButton->SetValue(B_CONTROL_ON);
5585c3a3034SAdrien Destugues 		fLocaleIs24Hr = true;
559fb816644SAdrien Destugues 	}
560fb816644SAdrien Destugues 
561fb816644SAdrien Destugues 	/*
562fb816644SAdrien Destugues 	FormatSeparator separator = settings.TimeFormatSeparator();
563fb816644SAdrien Destugues 
564fb816644SAdrien Destugues 	if (separator >= kNoSeparator && separator < kSeparatorsEnd)
565fb816644SAdrien Destugues 		fSeparatorMenuField->Menu()->ItemAt((int32)separator)->SetMarked(true);
566fb816644SAdrien Destugues 	*/
567bca1690bSAdrien Destugues 
568fb816644SAdrien Destugues 	_UpdateExamples();
569fb816644SAdrien Destugues 	_ParseDateFormat();
570bca1690bSAdrien Destugues 	_ParseCurrencyFormat();
571fb816644SAdrien Destugues }
572fb816644SAdrien Destugues 
573fb816644SAdrien Destugues 
574fb816644SAdrien Destugues void
575fb816644SAdrien Destugues FormatView::RecordRevertSettings()
576fb816644SAdrien Destugues {
577fb816644SAdrien Destugues 	/*
578fb816644SAdrien Destugues 	f24HrClock = settings.ClockIs24Hr();
579fb816644SAdrien Destugues 	fSeparator = settings.TimeFormatSeparator();
580fb816644SAdrien Destugues 	fFormat = settings.DateOrderFormat();
581fb816644SAdrien Destugues 	*/
582fb816644SAdrien Destugues }
583fb816644SAdrien Destugues 
584fb816644SAdrien Destugues 
585fb816644SAdrien Destugues // Return true if the Revert button should be enabled (ie some setting was
586fb816644SAdrien Destugues // changed)
587fb816644SAdrien Destugues bool
588fb816644SAdrien Destugues FormatView::IsRevertable() const
589fb816644SAdrien Destugues {
590fb816644SAdrien Destugues 	FormatSeparator separator;
591fb816644SAdrien Destugues 
592fb816644SAdrien Destugues 	BMenuItem* item = fSeparatorMenuField->Menu()->FindMarked();
593fb816644SAdrien Destugues 	if (item) {
594fb816644SAdrien Destugues 		int32 index = fSeparatorMenuField->Menu()->IndexOf(item);
595fb816644SAdrien Destugues 		if (index >= 0)
596fb816644SAdrien Destugues 			separator = (FormatSeparator)index;
597fb816644SAdrien Destugues 		else
598fb816644SAdrien Destugues 			return true;
599fb816644SAdrien Destugues 	} else
600fb816644SAdrien Destugues 		return true;
601fb816644SAdrien Destugues 
602fb816644SAdrien Destugues 	// TODO generate ICU string and compare to the initial one
603fb816644SAdrien Destugues 	BString dateFormat ;
604fb816644SAdrien Destugues 		// fYMDRadioButton->Value() ? kYMDFormat :
605fb816644SAdrien Destugues 		//(fDMYRadioButton->Value() ? kDMYFormat : kMDYFormat);
606fb816644SAdrien Destugues 
607fb816644SAdrien Destugues 	return f24HrClock != (f24HrRadioButton->Value() > 0)
608fb816644SAdrien Destugues 		|| separator != fSeparator
609fb816644SAdrien Destugues 		|| dateFormat != fDateFormat;
610fb816644SAdrien Destugues }
611fb816644SAdrien Destugues 
612fb816644SAdrien Destugues 
613fb816644SAdrien Destugues void
614fb816644SAdrien Destugues FormatView::_UpdateExamples()
615fb816644SAdrien Destugues {
616fb816644SAdrien Destugues 	time_t timeValue = (time_t)time(NULL);
617fb816644SAdrien Destugues 	BString timeFormat;
618fb816644SAdrien Destugues 
6195c3a3034SAdrien Destugues 	fLocale.FormatDate(&timeFormat, timeValue, true);
620fb816644SAdrien Destugues 	fLongDateExampleView->SetText(timeFormat);
621fb816644SAdrien Destugues 
6225c3a3034SAdrien Destugues 	fLocale.FormatDate(&timeFormat, timeValue, false);
623fb816644SAdrien Destugues 	fShortDateExampleView->SetText(timeFormat);
624fb816644SAdrien Destugues 
6255c3a3034SAdrien Destugues 	fLocale.FormatTime(&timeFormat, timeValue, true);
626fb816644SAdrien Destugues 	fLongTimeExampleView->SetText(timeFormat);
627fb816644SAdrien Destugues 
6285c3a3034SAdrien Destugues 	fLocale.FormatTime(&timeFormat, timeValue, false);
629fb816644SAdrien Destugues 	fShortTimeExampleView->SetText(timeFormat);
630fb816644SAdrien Destugues 
6315c3a3034SAdrien Destugues 	status_t Error = fLocale.FormatNumber(&timeFormat, 1234.5678);
632fb816644SAdrien Destugues 	if (Error == B_OK)
633fb816644SAdrien Destugues 		fNumberFormatExampleView->SetText(timeFormat);
634fb816644SAdrien Destugues 	else
635fb816644SAdrien Destugues 		fNumberFormatExampleView->SetText("ERROR");
636fb816644SAdrien Destugues }
637fb816644SAdrien Destugues 
638fb816644SAdrien Destugues 
639fb816644SAdrien Destugues void
640fb816644SAdrien Destugues FormatView::_SendNotices()
641fb816644SAdrien Destugues {
642fb816644SAdrien Destugues 	// Make the notification message and send it to the tracker:
643fb816644SAdrien Destugues 	/*
644fb816644SAdrien Destugues 	BMessage notificationMessage;
645fb816644SAdrien Destugues 	notificationMessage.AddInt32("TimeFormatSeparator",
646fb816644SAdrien Destugues 		(int32)settings.TimeFormatSeparator());
647fb816644SAdrien Destugues 	notificationMessage.AddInt32("DateOrderFormat",
648fb816644SAdrien Destugues 		(int32)settings.DateOrderFormat());
649fb816644SAdrien Destugues 	notificationMessage.AddBool("24HrClock", settings.ClockIs24Hr());
650fb816644SAdrien Destugues 	tracker->SendNotices(kDateFormatChanged, &notificationMessage);
651fb816644SAdrien Destugues 	*/
652fb816644SAdrien Destugues }
653fb816644SAdrien Destugues 
654fb816644SAdrien Destugues 
655bca1690bSAdrien Destugues void
656bca1690bSAdrien Destugues FormatView::_ParseCurrencyFormat()
657bca1690bSAdrien Destugues {
658bca1690bSAdrien Destugues 	BString currencySample;
659bca1690bSAdrien Destugues 	int* fieldPos = NULL;
660bca1690bSAdrien Destugues 	int fieldCount;
661bca1690bSAdrien Destugues 	BNumberElement* fieldID = NULL;
662bca1690bSAdrien Destugues 	if (fLocale.FormatMonetary(&currencySample, fieldPos, fieldID, fieldCount,
663bca1690bSAdrien Destugues 			-1234.56) != B_OK) {
664bca1690bSAdrien Destugues 		fMonetaryView->SetText("ERROR");
665bca1690bSAdrien Destugues 		return;
666bca1690bSAdrien Destugues 	}
667bca1690bSAdrien Destugues 
668bca1690bSAdrien Destugues 	fMonetaryView->SetText(currencySample);
669bca1690bSAdrien Destugues 
670bca1690bSAdrien Destugues 	for (int i = 0; i < fieldCount; i++) {
671bca1690bSAdrien Destugues 		BString currentSymbol;
672bca1690bSAdrien Destugues 		currentSymbol.AppendChars(currencySample.CharAt(fieldPos[i]&0xFFFF),
673bca1690bSAdrien Destugues 			(fieldPos[i]>>16) - (fieldPos[i]&0xFFFF));
674bca1690bSAdrien Destugues 		switch (fieldID[i]) {
675bca1690bSAdrien Destugues 			case B_NUMBER_ELEMENT_CURRENCY:
676bca1690bSAdrien Destugues 				fCurrencySymbolView->SetText(currentSymbol);
677*9e773899SAdrien Destugues 				if (i > fieldCount / 2)
678*9e773899SAdrien Destugues 					fCurrencySymbolAfter->SetValue(1);
679*9e773899SAdrien Destugues 				else
680*9e773899SAdrien Destugues 					fCurrencySymbolBefore->SetValue(1);
681bca1690bSAdrien Destugues 				break;
682bca1690bSAdrien Destugues 			default:
683bca1690bSAdrien Destugues 				break;
684bca1690bSAdrien Destugues 		}
685bca1690bSAdrien Destugues 	}
686bca1690bSAdrien Destugues 
687bca1690bSAdrien Destugues 	free(fieldPos);
688bca1690bSAdrien Destugues 	free(fieldID);
689bca1690bSAdrien Destugues }
690bca1690bSAdrien Destugues 
691bca1690bSAdrien Destugues 
692fb816644SAdrien Destugues //! Get the date format from ICU and set the date fields accordingly
693fb816644SAdrien Destugues void
694fb816644SAdrien Destugues FormatView::_ParseDateFormat()
695fb816644SAdrien Destugues {
696fb816644SAdrien Destugues 	// TODO parse the short date too
697fb816644SAdrien Destugues 	BString dateFormatString;
6985c3a3034SAdrien Destugues 	fLocale.GetDateFormat(dateFormatString, true);
699fb816644SAdrien Destugues 	const char* dateFormat = dateFormatString.String();
700fb816644SAdrien Destugues 
701fb816644SAdrien Destugues 	// Travel through the string and parse it
702fb816644SAdrien Destugues 	const char* parsePointer = dateFormat;
703fb816644SAdrien Destugues 	const char* fieldBegin = dateFormat;
704fb816644SAdrien Destugues 
705fb816644SAdrien Destugues 	for (int i = 0; i < 4; i++)
706fb816644SAdrien Destugues 	{
707fb816644SAdrien Destugues 		fieldBegin = parsePointer;
708fb816644SAdrien Destugues 		while (*parsePointer == *(parsePointer + 1)) parsePointer++ ;
709fb816644SAdrien Destugues 		parsePointer++;
710fb816644SAdrien Destugues 		BString str;
711fb816644SAdrien Destugues 		str.Append(fieldBegin, parsePointer - fieldBegin);
712fb816644SAdrien Destugues 
713fb816644SAdrien Destugues 		fLongDateString[i] = str;
714fb816644SAdrien Destugues 
715fb816644SAdrien Destugues 		BMenu* subMenu;
716fb816644SAdrien Destugues 		bool isFound = false;
717fb816644SAdrien Destugues 		for (int subMenuIndex = 0; subMenuIndex < 3; subMenuIndex++) {
718fb816644SAdrien Destugues 			subMenu = fLongDateMenu[i]->Menu()->SubmenuAt(subMenuIndex);
719fb816644SAdrien Destugues 			BMenuItem* item;
720fb816644SAdrien Destugues 			for (int itemIndex = 0; (item = subMenu->ItemAt(itemIndex)) != NULL;
721fb816644SAdrien Destugues 					itemIndex++) {
722fb816644SAdrien Destugues 				if (static_cast<DateMenuItem*>(item)->ICUCode() == str) {
723fb816644SAdrien Destugues 					item->SetMarked(true);
724fb816644SAdrien Destugues 					fLongDateMenu[i]->MenuItem()->SetLabel(item->Label());
725fb816644SAdrien Destugues 					isFound = true;
726fb816644SAdrien Destugues 				} else
727fb816644SAdrien Destugues 					item->SetMarked(false);
728fb816644SAdrien Destugues 			}
729fb816644SAdrien Destugues 		}
730fb816644SAdrien Destugues 
731fb816644SAdrien Destugues 		if (!isFound)
732fb816644SAdrien Destugues 			fLongDateMenu[i]->MenuItem()->SetLabel(str.Append("*"));
733fb816644SAdrien Destugues 
734fb816644SAdrien Destugues 		fieldBegin = parsePointer;
735fb816644SAdrien Destugues 		while ((!IsSpecialDateChar(*parsePointer)) && *parsePointer != '\0'
736fb816644SAdrien Destugues 				&& *(parsePointer - 1) >= 0) {
737fb816644SAdrien Destugues 			if (*parsePointer == '\'') {
738fb816644SAdrien Destugues 				parsePointer++;
739fb816644SAdrien Destugues 				while (*parsePointer != '\'') parsePointer++;
740fb816644SAdrien Destugues 			}
741fb816644SAdrien Destugues 			parsePointer++;
742fb816644SAdrien Destugues 		}
743fb816644SAdrien Destugues 		str.Truncate(0);
744fb816644SAdrien Destugues 		str.Append(fieldBegin, parsePointer - fieldBegin);
745fb816644SAdrien Destugues 		fLongDateSeparator[i]->SetText(str);
746fb816644SAdrien Destugues 	}
747fb816644SAdrien Destugues 
748fb816644SAdrien Destugues 	// Short date is a bit more tricky, we want to extract the separator
7495c3a3034SAdrien Destugues 	fLocale.GetDateFormat(dateFormatString, false);
750fb816644SAdrien Destugues 	dateFormat = dateFormatString.String();
751fb816644SAdrien Destugues 
752fb816644SAdrien Destugues 	// Travel trough the string and parse it
753fb816644SAdrien Destugues 	parsePointer = dateFormat;
754fb816644SAdrien Destugues 	fieldBegin = dateFormat;
755fb816644SAdrien Destugues 
756fb816644SAdrien Destugues 	for (int i = 0; i < 3; i++) {
757fb816644SAdrien Destugues 		fieldBegin = parsePointer;
758fb816644SAdrien Destugues 		while (*parsePointer == *(parsePointer + 1)) parsePointer++ ;
759fb816644SAdrien Destugues 		parsePointer++;
760fb816644SAdrien Destugues 		BString str;
761fb816644SAdrien Destugues 		str.Append(fieldBegin, parsePointer - fieldBegin);
762fb816644SAdrien Destugues 
763fb816644SAdrien Destugues 		fLongDateString[i] = str;
764fb816644SAdrien Destugues 
765fb816644SAdrien Destugues 		BMenu* subMenu;
766fb816644SAdrien Destugues 		bool isFound = false;
767fb816644SAdrien Destugues 		for (int subMenuIndex = 0; subMenuIndex < 3; subMenuIndex++) {
768fb816644SAdrien Destugues 			subMenu = fDateMenu[i]->Menu()->SubmenuAt(subMenuIndex);
769fb816644SAdrien Destugues 			BMenuItem* item;
770fb816644SAdrien Destugues 			for (int itemIndex = 0; (item = subMenu->ItemAt(itemIndex)) != NULL;
771fb816644SAdrien Destugues 					itemIndex++) {
772fb816644SAdrien Destugues 				if (static_cast<DateMenuItem*>(item)->ICUCode() == str) {
773fb816644SAdrien Destugues 					item->SetMarked(true);
774fb816644SAdrien Destugues 					fDateMenu[i]->MenuItem()->SetLabel(item->Label());
775fb816644SAdrien Destugues 					isFound = true;
776fb816644SAdrien Destugues 				} else
777fb816644SAdrien Destugues 					item->SetMarked(false);
778fb816644SAdrien Destugues 			}
779fb816644SAdrien Destugues 		}
780fb816644SAdrien Destugues 
781fb816644SAdrien Destugues 		if (!isFound) {
782fb816644SAdrien Destugues 			fDateMenu[i]->MenuItem()->SetLabel(
783fb816644SAdrien Destugues 				str.Append(B_TRANSLATE(" (unknown format)")));
784fb816644SAdrien Destugues 		}
785fb816644SAdrien Destugues 
786fb816644SAdrien Destugues 		fieldBegin = parsePointer;
787fb816644SAdrien Destugues 		while ((!IsSpecialDateChar(*parsePointer)) && *parsePointer != '\0'
788fb816644SAdrien Destugues 				&& *(parsePointer - 1) >= 0) {
789fb816644SAdrien Destugues 			if (*parsePointer == '\'') {
790fb816644SAdrien Destugues 				parsePointer++;
791fb816644SAdrien Destugues 				while (*parsePointer != '\'') parsePointer++;
792fb816644SAdrien Destugues 			}
793fb816644SAdrien Destugues 			parsePointer++;
794fb816644SAdrien Destugues 		}
795fb816644SAdrien Destugues 		if (parsePointer - fieldBegin > 0) {
796fb816644SAdrien Destugues 			str.Truncate(0);
797fb816644SAdrien Destugues 			str.Append(fieldBegin, parsePointer - fieldBegin);
798fb816644SAdrien Destugues 			fSeparatorMenuField->MenuItem()->SetLabel(str);
799fb816644SAdrien Destugues 		}
800fb816644SAdrien Destugues 	}
801fb816644SAdrien Destugues }
802fb816644SAdrien Destugues 
803fb816644SAdrien Destugues 
804fb816644SAdrien Destugues void
805fb816644SAdrien Destugues FormatView::_UpdateLongDateFormatString()
806fb816644SAdrien Destugues {
807fb816644SAdrien Destugues 	BString newDateFormat;
808fb816644SAdrien Destugues 
809fb816644SAdrien Destugues 	for (int i = 0; i < 4; i++) {
810fb816644SAdrien Destugues 		newDateFormat.Append(fLongDateString[i]);
811fb816644SAdrien Destugues 		newDateFormat.Append(fLongDateSeparator[i]->Text());
812fb816644SAdrien Destugues 	}
813fb816644SAdrien Destugues 
814fb816644SAdrien Destugues 	// TODO save this in the settings preflet and make the roster load it back
8155c3a3034SAdrien Destugues 	fLocale.SetDateFormat(newDateFormat.String());
816fb816644SAdrien Destugues 
817fb816644SAdrien Destugues 	newDateFormat.Truncate(0);
818fb816644SAdrien Destugues 
819fb816644SAdrien Destugues 	newDateFormat.Append(fDateString[0]);
820fb816644SAdrien Destugues 	newDateFormat.Append(fSeparatorMenuField->MenuItem()->Label());
821fb816644SAdrien Destugues 	newDateFormat.Append(fDateString[1]);
822fb816644SAdrien Destugues 	newDateFormat.Append(fSeparatorMenuField->MenuItem()->Label());
823fb816644SAdrien Destugues 	newDateFormat.Append(fDateString[2]);
824fb816644SAdrien Destugues 
825fb816644SAdrien Destugues 	// TODO save this in the settings preflet and make the roster load it back
8265c3a3034SAdrien Destugues 	fLocale.SetDateFormat(newDateFormat.String(), false);
827fb816644SAdrien Destugues }
828