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 230ad926b25SHumdinger BLayoutBuilder::Group<>(this, B_VERTICAL) 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 .End() 23825fd5c7bSAlex Wilson .AddGlue(); 239fb816644SAdrien Destugues } 240fb816644SAdrien Destugues 241fb816644SAdrien Destugues 2426fd2f4a0SOliver Tappe FormatSettingsView::~FormatSettingsView() 243fb816644SAdrien Destugues { 244fb816644SAdrien Destugues } 245fb816644SAdrien Destugues 246fb816644SAdrien Destugues 247fb816644SAdrien Destugues void 2486fd2f4a0SOliver Tappe FormatSettingsView::AttachedToWindow() 249fb816644SAdrien Destugues { 2506fd2f4a0SOliver Tappe fUseLanguageStringsCheckBox->SetTarget(this); 2516fd2f4a0SOliver Tappe f24HourRadioButton->SetTarget(this); 2526fd2f4a0SOliver Tappe f12HourRadioButton->SetTarget(this); 253fb816644SAdrien Destugues } 254fb816644SAdrien Destugues 255fb816644SAdrien Destugues 256fb816644SAdrien Destugues void 2576fd2f4a0SOliver Tappe FormatSettingsView::MessageReceived(BMessage* message) 258fb816644SAdrien Destugues { 259fb816644SAdrien Destugues switch (message->what) { 26031c0024dSJohn Scipione case B_LOCALE_CHANGED: 26131c0024dSJohn Scipione { 26231c0024dSJohn Scipione // Time updated 12/24 hour clock 26331c0024dSJohn Scipione BFormattingConventions conventions; 26431c0024dSJohn Scipione BLocale::Default()->GetFormattingConventions(&conventions); 26531c0024dSJohn Scipione if (conventions.Use24HourClock()) 26631c0024dSJohn Scipione f24HourRadioButton->SetValue(B_CONTROL_ON); 26731c0024dSJohn Scipione else 26831c0024dSJohn Scipione f12HourRadioButton->SetValue(B_CONTROL_ON); 26931c0024dSJohn Scipione 27031c0024dSJohn Scipione _UpdateExamples(); 27131c0024dSJohn Scipione Window()->PostMessage(kMsgSettingsChanged); 27231c0024dSJohn Scipione break; 27331c0024dSJohn Scipione } 27431c0024dSJohn Scipione 275fb816644SAdrien Destugues case kClockFormatChange: 276fb816644SAdrien Destugues { 2776fd2f4a0SOliver Tappe BFormattingConventions conventions; 27825dc253dSIngo Weinhold BLocale::Default()->GetFormattingConventions(&conventions); 2796fd2f4a0SOliver Tappe conventions.SetExplicitUse24HourClock( 28031c0024dSJohn Scipione f24HourRadioButton->Value() == B_CONTROL_ON); 28125dc253dSIngo Weinhold MutableLocaleRoster::Default()->SetDefaultFormattingConventions( 28225dc253dSIngo Weinhold conventions); 283fb816644SAdrien Destugues 284fb816644SAdrien Destugues _UpdateExamples(); 2856fd2f4a0SOliver Tappe Window()->PostMessage(kMsgSettingsChanged); 2866fd2f4a0SOliver Tappe break; 2876fd2f4a0SOliver Tappe } 2886fd2f4a0SOliver Tappe 2896fd2f4a0SOliver Tappe case kStringsLanguageChange: 2906fd2f4a0SOliver Tappe { 2916fd2f4a0SOliver Tappe BFormattingConventions conventions; 29225dc253dSIngo Weinhold BLocale::Default()->GetFormattingConventions(&conventions); 2936fd2f4a0SOliver Tappe conventions.SetUseStringsFromPreferredLanguage( 2946fd2f4a0SOliver Tappe fUseLanguageStringsCheckBox->Value() ? true : false); 29525dc253dSIngo Weinhold MutableLocaleRoster::Default()->SetDefaultFormattingConventions( 29625dc253dSIngo Weinhold conventions); 2976fd2f4a0SOliver Tappe 2986fd2f4a0SOliver Tappe _UpdateExamples(); 2996fd2f4a0SOliver Tappe 3006fd2f4a0SOliver Tappe Window()->PostMessage(kMsgSettingsChanged); 301fb816644SAdrien Destugues break; 302fb816644SAdrien Destugues } 303fb816644SAdrien Destugues 304fb816644SAdrien Destugues default: 305fb816644SAdrien Destugues BView::MessageReceived(message); 306fb816644SAdrien Destugues } 307fb816644SAdrien Destugues } 308fb816644SAdrien Destugues 309fb816644SAdrien Destugues 310fb816644SAdrien Destugues void 3116fd2f4a0SOliver Tappe FormatSettingsView::Revert() 312fb816644SAdrien Destugues { 31325dc253dSIngo Weinhold MutableLocaleRoster::Default()->SetDefaultFormattingConventions( 31425dc253dSIngo Weinhold fInitialConventions); 315bca1690bSAdrien Destugues 316fb816644SAdrien Destugues _UpdateExamples(); 317fb816644SAdrien Destugues } 318fb816644SAdrien Destugues 319fb816644SAdrien Destugues 320fb816644SAdrien Destugues void 3216fd2f4a0SOliver Tappe FormatSettingsView::Refresh(bool setInitial) 322fb816644SAdrien Destugues { 3236fd2f4a0SOliver Tappe BFormattingConventions conventions; 32425dc253dSIngo Weinhold BLocale::Default()->GetFormattingConventions(&conventions); 3256fd2f4a0SOliver Tappe if (setInitial) 3266fd2f4a0SOliver Tappe fInitialConventions = conventions; 3276fd2f4a0SOliver Tappe 3286fd2f4a0SOliver Tappe if (!conventions.Use24HourClock()) { 3296fd2f4a0SOliver Tappe f12HourRadioButton->SetValue(B_CONTROL_ON); 3306fd2f4a0SOliver Tappe fLocaleIs24Hour = false; 3316fd2f4a0SOliver Tappe } else { 3326fd2f4a0SOliver Tappe f24HourRadioButton->SetValue(B_CONTROL_ON); 3336fd2f4a0SOliver Tappe fLocaleIs24Hour = true; 3346fd2f4a0SOliver Tappe } 3356fd2f4a0SOliver Tappe 3366fd2f4a0SOliver Tappe fUseLanguageStringsCheckBox->SetValue( 3376fd2f4a0SOliver Tappe conventions.UseStringsFromPreferredLanguage() 3386fd2f4a0SOliver Tappe ? B_CONTROL_ON : B_CONTROL_OFF); 3396fd2f4a0SOliver Tappe 3406fd2f4a0SOliver Tappe _UpdateExamples(); 341fb816644SAdrien Destugues } 342fb816644SAdrien Destugues 343fb816644SAdrien Destugues 3446fd2f4a0SOliver Tappe // Return true if the Revert button should be enabled (i.e. something has been 345fb816644SAdrien Destugues // changed) 346fb816644SAdrien Destugues bool 3476fd2f4a0SOliver Tappe FormatSettingsView::IsReversible() const 348fb816644SAdrien Destugues { 3496fd2f4a0SOliver Tappe BFormattingConventions conventions; 35025dc253dSIngo Weinhold BLocale::Default()->GetFormattingConventions(&conventions); 351fb816644SAdrien Destugues 3526fd2f4a0SOliver Tappe return conventions != fInitialConventions; 353fb816644SAdrien Destugues } 354fb816644SAdrien Destugues 355fb816644SAdrien Destugues 356fb816644SAdrien Destugues void 3576fd2f4a0SOliver Tappe FormatSettingsView::_UpdateExamples() 358fb816644SAdrien Destugues { 359fb816644SAdrien Destugues time_t timeValue = (time_t)time(NULL); 3606fd2f4a0SOliver Tappe BString result; 361fb816644SAdrien Destugues 36203b2550eSAdrien Destugues // Do NOT make these class members. We do want to recreate it everytime, as 3630a925409SAdrien Destugues // to get the updated settings from the locale roster. 3640a925409SAdrien Destugues BDateFormat dateFormat; 36503b2550eSAdrien Destugues BTimeFormat timeFormat; 366*e3857211SAdrien Destugues BNumberFormat numberFormat; 3670a925409SAdrien Destugues 3680a925409SAdrien Destugues dateFormat.Format(result, timeValue, B_FULL_DATE_FORMAT); 3696fd2f4a0SOliver Tappe fFullDateExampleView->SetText(result); 370fb816644SAdrien Destugues 3710a925409SAdrien Destugues dateFormat.Format(result, timeValue, B_LONG_DATE_FORMAT); 3726fd2f4a0SOliver Tappe fLongDateExampleView->SetText(result); 373fb816644SAdrien Destugues 3740a925409SAdrien Destugues dateFormat.Format(result, timeValue, B_MEDIUM_DATE_FORMAT); 3756fd2f4a0SOliver Tappe fMediumDateExampleView->SetText(result); 376fb816644SAdrien Destugues 3770a925409SAdrien Destugues dateFormat.Format(result, timeValue, B_SHORT_DATE_FORMAT); 3786fd2f4a0SOliver Tappe fShortDateExampleView->SetText(result); 379fb816644SAdrien Destugues 38003b2550eSAdrien Destugues timeFormat.Format(result, timeValue, B_FULL_TIME_FORMAT); 3816fd2f4a0SOliver Tappe fFullTimeExampleView->SetText(result); 3826fd2f4a0SOliver Tappe 38303b2550eSAdrien Destugues timeFormat.Format(result, timeValue, B_LONG_TIME_FORMAT); 3846fd2f4a0SOliver Tappe fLongTimeExampleView->SetText(result); 3856fd2f4a0SOliver Tappe 38603b2550eSAdrien Destugues timeFormat.Format(result, timeValue, B_MEDIUM_TIME_FORMAT); 3876fd2f4a0SOliver Tappe fMediumTimeExampleView->SetText(result); 3886fd2f4a0SOliver Tappe 38903b2550eSAdrien Destugues timeFormat.Format(result, timeValue, B_SHORT_TIME_FORMAT); 3906fd2f4a0SOliver Tappe fShortTimeExampleView->SetText(result); 3916fd2f4a0SOliver Tappe 392*e3857211SAdrien Destugues status_t status = numberFormat.Format(result, 1234.5678); 3936fd2f4a0SOliver Tappe if (status == B_OK) 3946fd2f4a0SOliver Tappe fPositiveNumberExampleView->SetText(result); 395fb816644SAdrien Destugues else 3966fd2f4a0SOliver Tappe fPositiveNumberExampleView->SetText("ERROR"); 397fb816644SAdrien Destugues 398*e3857211SAdrien Destugues status = numberFormat.Format(result, -1234.5678); 3996fd2f4a0SOliver Tappe if (status == B_OK) 4006fd2f4a0SOliver Tappe fNegativeNumberExampleView->SetText(result); 4019e773899SAdrien Destugues else 4026fd2f4a0SOliver Tappe fNegativeNumberExampleView->SetText("ERROR"); 403bca1690bSAdrien Destugues 404*e3857211SAdrien Destugues status = numberFormat.FormatMonetary(result, 1234.56); 4056fd2f4a0SOliver Tappe if (status == B_OK) 4066fd2f4a0SOliver Tappe fPositiveMonetaryExampleView->SetText(result); 4076fd2f4a0SOliver Tappe else 4086fd2f4a0SOliver Tappe fPositiveMonetaryExampleView->SetText("ERROR"); 409bca1690bSAdrien Destugues 410*e3857211SAdrien Destugues status = numberFormat.FormatMonetary(result, -1234.56); 4116fd2f4a0SOliver Tappe if (status == B_OK) 4126fd2f4a0SOliver Tappe fNegativeMonetaryExampleView->SetText(result); 4136fd2f4a0SOliver Tappe else 4146fd2f4a0SOliver Tappe fNegativeMonetaryExampleView->SetText("ERROR"); 415fb816644SAdrien Destugues } 416