Ticket #2412: time_pref_net.patch
File time_pref_net.patch, 81.5 KB (added by , 13 years ago) |
---|
-
src/preferences/time/NetworkTimeView.cpp
1 /* 2 * Copyright 2011, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Hamish Morrison <hamish@lavabit.com> 7 * Axel Dörfler <axeld@pinc-software.de> 8 */ 9 10 #include "NetworkTimeView.h" 11 12 #include <Alert.h> 13 #include <Application.h> 14 #include <Button.h> 15 #include <CheckBox.h> 16 #include <File.h> 17 #include <FindDirectory.h> 18 #include <MenuField.h> 19 #include <MenuItem.h> 20 #include <Path.h> 21 #include <PopUpMenu.h> 22 #include <View.h> 23 24 #include <stdio.h> 25 #include <string.h> 26 27 #include "ntp.h" 28 29 30 class MessengerMonitor : public Monitor { 31 public: 32 MessengerMonitor(BLooper& looper) 33 : 34 fLooper(looper) 35 { 36 } 37 38 virtual void 39 Done(status_t status) 40 { 41 BMessage message(kMsgStatusUpdate); 42 message.AddInt32("status", status); 43 44 fLooper.PostMessage(&message); 45 fLooper.PostMessage(kMsgStopSynchronization); 46 } 47 48 private: 49 virtual void 50 update(float progress, const char *text, va_list args) 51 { 52 BMessage message(kMsgStatusUpdate); 53 if (progress != -1.f) 54 message.AddFloat("progress", progress); 55 56 if (text != NULL) { 57 char buffer[2048]; 58 vsnprintf(buffer, sizeof(buffer), text, args); 59 message.AddString("message", buffer); 60 } 61 62 fLooper.PostMessage(&message); 63 } 64 65 BLooper& fLooper; 66 }; 67 68 69 class UpdateLooper : public BLooper { 70 public: 71 UpdateLooper(const BMessage &settings, Monitor *monitor); 72 73 void MessageReceived(BMessage *message); 74 75 private: 76 const BMessage &fSettings; 77 Monitor *fMonitor; 78 }; 79 80 81 UpdateLooper::UpdateLooper(const BMessage &settings, Monitor *monitor) 82 : BLooper("update looper"), 83 fSettings(settings), 84 fMonitor(monitor) 85 { 86 PostMessage(kMsgSynchronize); 87 } 88 89 90 void 91 UpdateLooper::MessageReceived(BMessage *message) 92 { 93 if (message->what != kMsgSynchronize) 94 return; 95 96 update_time(fSettings, fMonitor); 97 } 98 99 100 status_t 101 adopt_int32(const BMessage &from, BMessage &to, 102 const char *name, bool &updated) 103 { 104 int32 value; 105 if (from.FindInt32(name, &value) != B_OK) 106 return B_ENTRY_NOT_FOUND; 107 108 int32 original; 109 if (to.FindInt32(name, &original) == B_OK) { 110 if (value == original) 111 return B_OK; 112 113 updated = true; 114 return to.ReplaceInt32(name, value); 115 } 116 117 updated = true; 118 return to.AddInt32(name, value); 119 } 120 121 122 status_t 123 adopt_bool(const BMessage &from, BMessage &to, 124 const char *name, bool &updated) 125 { 126 bool value; 127 if (from.FindBool(name, &value) != B_OK) 128 return B_ENTRY_NOT_FOUND; 129 130 bool original; 131 if (to.FindBool(name, &original) == B_OK) { 132 if (value == original) 133 return B_OK; 134 135 updated = true; 136 return to.ReplaceBool(name, value); 137 } 138 139 updated = true; 140 return to.AddBool(name, value); 141 } 142 143 144 status_t 145 adopt_rect(const BMessage &from, BMessage &to, 146 const char *name, bool &updated) 147 { 148 BRect rect; 149 if (from.FindRect(name, &rect) != B_OK) 150 return B_ENTRY_NOT_FOUND; 151 152 BRect original; 153 if (to.FindRect(name, &original) == B_OK) { 154 if (rect == original) 155 return B_OK; 156 157 updated = true; 158 return to.ReplaceRect(name, rect); 159 } 160 161 updated = true; 162 return to.AddRect(name, rect); 163 } 164 165 166 Settings::Settings() 167 : 168 fMessage(kMsgNetworkTimeSettings), 169 fWasUpdated(false) 170 { 171 ResetToDefaults(); 172 Load(); 173 } 174 175 176 Settings::~Settings() 177 { 178 if (fWasUpdated) 179 Save(); 180 } 181 182 183 void 184 Settings::CopyMessage(BMessage &message) const 185 { 186 message = fMessage; 187 } 188 189 190 const BMessage & 191 Settings::Message() const 192 { 193 return fMessage; 194 } 195 196 197 void 198 Settings::UpdateFrom(BMessage &message) 199 { 200 if (message.HasBool("reset servers")) { 201 fMessage.RemoveName("server"); 202 fWasUpdated = true; 203 } 204 205 if (message.HasString("server")) { 206 // remove old servers 207 fMessage.RemoveName("server"); 208 209 const char *server; 210 int32 index = 0; 211 while (message.FindString("server", index++, &server) == B_OK) { 212 fMessage.AddString("server", server); 213 } 214 215 fWasUpdated = true; 216 } 217 218 adopt_int32(message, fMessage, "default server", fWasUpdated); 219 220 adopt_bool(message, fMessage, "synchronize at boot", fWasUpdated); 221 adopt_bool(message, fMessage, "try all servers", fWasUpdated); 222 adopt_bool(message, fMessage, "choose default server", fWasUpdated); 223 224 adopt_rect(message, fMessage, "edit servers frame", fWasUpdated); 225 } 226 227 228 void 229 Settings::ResetServersToDefaults() 230 { 231 fMessage.RemoveName("server"); 232 233 fMessage.AddString("server", "pool.ntp.org"); 234 fMessage.AddString("server", "de.pool.ntp.org"); 235 fMessage.AddString("server", "time.nist.gov"); 236 237 if (fMessage.ReplaceInt32("default server", 0) != B_OK) 238 fMessage.AddInt32("default server", 0); 239 } 240 241 242 void 243 Settings::ResetToDefaults() 244 { 245 fMessage.MakeEmpty(); 246 ResetServersToDefaults(); 247 248 fMessage.AddBool("synchronize at boot", true); 249 fMessage.AddBool("try all servers", true); 250 251 fMessage.AddRect("status frame", BRect(0, 0, 300, 150)); 252 fMessage.AddRect("edit servers frame", BRect(0, 0, 250, 250)); 253 } 254 255 256 status_t 257 Settings::Load() 258 { 259 status_t status; 260 261 BPath path; 262 if ((status = GetPath(path)) != B_OK) 263 return status; 264 265 BFile file(path.Path(), B_READ_ONLY); 266 if ((status = file.InitCheck()) != B_OK) 267 return status; 268 269 BMessage load; 270 if ((status = load.Unflatten(&file)) != B_OK) 271 return status; 272 273 if (load.what != kMsgNetworkTimeSettings) 274 return B_BAD_TYPE; 275 276 fMessage = load; 277 return B_OK; 278 } 279 280 281 status_t 282 Settings::Save() 283 { 284 status_t status; 285 286 BPath path; 287 if ((status = GetPath(path)) != B_OK) 288 return status; 289 290 BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); 291 if ((status = file.InitCheck()) != B_OK) 292 return status; 293 294 file.SetSize(0); 295 296 return fMessage.Flatten(&file); 297 } 298 299 300 status_t 301 Settings::GetPath(BPath &path) 302 { 303 status_t status; 304 if ((status = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) 305 return status; 306 path.Append("pinc.networktime settings"); 307 return B_OK; 308 } 309 310 311 NetworkTimeView::NetworkTimeView(const char* name) 312 : 313 BGroupView(name, B_VERTICAL, B_USE_DEFAULT_SPACING), 314 fEditServerListWindow(NULL), 315 fUpdateThread(-1), 316 fStatusString(""), 317 fSettings() 318 { 319 fSettings.Load(); 320 _InitView(); 321 } 322 323 324 void 325 NetworkTimeView::_InitView() 326 { 327 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 328 329 BPopUpMenu* menu = new BPopUpMenu("serverMenu"); 330 fServerListMenuField = new BMenuField("serverList", "Use server:", menu); 331 _UpdateServerListMenu(); 332 fEditServerListButton = new BButton("editServerList", "Edit Server List", 333 new BMessage(kMsgEditServerList)); 334 335 fTryAllServersCheckBox = new BCheckBox("tryAllServers", "Try all servers", 336 new BMessage(kMsgTryAllServers)); 337 bool boolean; 338 if (fSettings.Message().FindBool("try all servers", &boolean) == B_OK) 339 fTryAllServersCheckBox->SetValue(boolean); 340 341 fSynchronizeAtBootCheckBox = new BCheckBox("autoUpdate", 342 "Synchronize at boot", new BMessage(kMsgSynchronizeAtBoot)); 343 if (fSettings.Message().FindBool("synchronize at boot", &boolean) == B_OK) 344 fSynchronizeAtBootCheckBox->SetValue(boolean); 345 fSynchronizeButton = new BButton("update", "Synchronize now", 346 new BMessage(kMsgSynchronize)); 347 348 BLayoutBuilder::Group<>(this) 349 .AddGroup(B_HORIZONTAL) 350 .Add(fServerListMenuField) 351 .Add(fEditServerListButton) 352 .End() 353 .Add(fTryAllServersCheckBox) 354 .Add(fSynchronizeAtBootCheckBox) 355 .AddGroup(B_HORIZONTAL) 356 .AddGlue() 357 .Add(fSynchronizeButton) 358 .End() 359 .SetInsets(5, 5, 5, 5); 360 } 361 362 363 void 364 NetworkTimeView::_UpdateServerListMenu() 365 { 366 while (fServerListMenuField->Menu()->RemoveItem(0L) != NULL); 367 368 const char* server; 369 int32 index = 0; 370 while (fSettings.Message().FindString("server", index++, &server) 371 == B_OK) 372 fServerListMenuField->Menu()->AddItem( 373 new BMenuItem(server, new BMessage(kMsgDefaultServer))); 374 375 int32 defaultServer; 376 if (fSettings.Message().FindInt32("default server", &defaultServer) 377 != B_OK) 378 defaultServer = 0; 379 fServerListMenuField->Menu()->ItemAt(defaultServer)->SetMarked(true); 380 } 381 382 383 void 384 NetworkTimeView::MessageReceived(BMessage* message) 385 { 386 switch (message->what) { 387 case kMsgTryAllServers: 388 { 389 BMessage update(kMsgUpdateSettings); 390 update.AddBool("try all servers", 391 fTryAllServersCheckBox->Value()); 392 Looper()->PostMessage(&update); 393 break; 394 } 395 396 case kMsgSynchronizeAtBoot: 397 { 398 BMessage update(kMsgUpdateSettings); 399 update.AddBool("synchronize at boot", 400 fSynchronizeAtBootCheckBox->Value()); 401 Looper()->PostMessage(&update); 402 break; 403 } 404 405 case kMsgSettingsUpdated: 406 { 407 if (message->HasString("server")) 408 _UpdateServerListMenu(); 409 else { 410 int32 defaultServer; 411 if (fSettings.Message() 412 .FindInt32("default server", &defaultServer) != B_OK) 413 defaultServer = 0; 414 fServerListMenuField->Menu()->ItemAt(defaultServer) 415 ->SetMarked(true); 416 } 417 bool boolean; 418 if (message->FindBool("synchronize at boot", &boolean) == B_OK) 419 fSynchronizeAtBootCheckBox->SetValue(boolean); 420 if (message->FindBool("try all servers", &boolean) == B_OK) 421 fTryAllServersCheckBox->SetValue(boolean); 422 break; 423 } 424 425 case kMsgUpdateSettings: 426 { 427 fSettings.UpdateFrom(*message); 428 message->what = kMsgSettingsUpdated; 429 BWindow *window; 430 int32 index = 0; 431 432 while ((window = be_app->WindowAt(index++)) != NULL) 433 window->PostMessage(message); 434 break; 435 } 436 437 case kMsgResetServerList: 438 { 439 fSettings.ResetServersToDefaults(); 440 441 BMessage updated = fSettings.Message(); 442 updated.what = kMsgSettingsUpdated; 443 444 BWindow *window; 445 int32 index = 0; 446 while ((window = be_app->WindowAt(index++)) != NULL) 447 window->PostMessage(message); 448 449 break; 450 } 451 452 case kMsgEditServerList: 453 if (fEditServerListWindow == NULL) { 454 BRect rect(0, 0, 250, 250); 455 fEditServerListWindow = new EditServerListWindow(rect, 456 fSettings.Message(), Looper()); 457 } 458 fEditServerListWindow->Show(); 459 break; 460 461 case kMsgEditServerListWindowClosed: 462 fEditServerListWindow = NULL; 463 break; 464 465 case kMsgDefaultServer: 466 { 467 int32 index; 468 if (message->FindInt32("index", &index) != B_OK) 469 break; 470 BMessage update(kMsgUpdateSettings); 471 update.AddInt32("default server", index); 472 Looper()->PostMessage(&update); 473 break; 474 } 475 476 case kMsgStopSynchronization: 477 if (fUpdateThread >= B_OK) 478 kill_thread(fUpdateThread); 479 fUpdateThread = -1; 480 481 fSynchronizeButton->SetLabel("Synchronize"); 482 fSynchronizeButton->Message()->what = kMsgSynchronize; 483 break; 484 485 case kMsgSynchronize: 486 { 487 if (fUpdateThread >= B_OK) 488 break; 489 490 MessengerMonitor* monitor = new MessengerMonitor(*Looper()); 491 update_time(fSettings.Message(), monitor, &fUpdateThread); 492 fSynchronizeButton->SetLabel("Stop"); 493 fSynchronizeButton->Message()->what = kMsgStopSynchronization; 494 break; 495 } 496 497 case kMsgStatusUpdate: 498 { 499 message->FindString("message", &fStatusString); 500 status_t status; 501 if (message->FindInt32("status", (int32 *)&status) == B_OK) { 502 if (status != B_OK) { 503 (new BAlert("Time", "Error synchronizing!", "OK"))->Go(); 504 } 505 } 506 break; 507 } 508 } 509 } 510 511 512 status_t 513 update_time(const BMessage &settings, Monitor *monitor) 514 { 515 int32 defaultServer; 516 if (settings.FindInt32("default server", &defaultServer) != B_OK) 517 defaultServer = 0; 518 519 status_t status = B_ENTRY_NOT_FOUND; 520 const char *server; 521 if (settings.FindString("server", defaultServer, &server) == B_OK) 522 status = ntp_update_time(server, monitor); 523 524 // try other servers if we should 525 if (status != B_OK && settings.FindBool("try all servers")) { 526 for (int32 index = 0; ; index++) { 527 if (index == defaultServer) 528 index++; 529 if (settings.FindString("server", index, &server) != B_OK) 530 break; 531 532 status = ntp_update_time(server, monitor); 533 if (status == B_OK) { 534 if (be_app != NULL && settings.FindBool("choose default server")) { 535 BMessage update(kMsgUpdateSettings); 536 update.AddInt32("default server", index); 537 be_app->PostMessage(&update); 538 } 539 break; 540 } 541 } 542 } 543 544 if (monitor != NULL) 545 monitor->Done(status); 546 547 delete monitor; 548 return status; 549 } 550 551 552 status_t 553 update_time(const BMessage &settings, Monitor *monitor, thread_id *_asyncThread) 554 { 555 if (_asyncThread != NULL) { 556 BLooper *looper = new UpdateLooper(settings, monitor); 557 *_asyncThread = looper->Run(); 558 return B_OK; 559 } 560 561 return update_time(settings, monitor); 562 } -
src/preferences/time/EditServerListWindow.h
1 /* 2 * Copyright 2004, pinc Software. All Rights Reserved. 3 * Distributed under the terms of the MIT license. 4 */ 5 #ifndef EDIT_SERVER_LIST_WINDOW_H 6 #define EDIT_SERVER_LIST_WINDOW_H 7 8 9 #include <Window.h> 10 11 class BTextView; 12 13 14 class EditServerListWindow : public BWindow { 15 public: 16 EditServerListWindow(BRect position, const BMessage &settings, BLooper* looper); 17 virtual ~EditServerListWindow(); 18 19 virtual bool QuitRequested(); 20 virtual void MessageReceived(BMessage *message); 21 22 private: 23 void UpdateDefaultServerView(const BMessage &message); 24 void UpdateServerView(const BMessage &message); 25 26 void UpdateServerList(); 27 28 const BMessage &fSettings; 29 BTextView *fServerView; 30 31 BLooper *fLooper; 32 }; 33 34 #endif /* EDIT_SERVER_LIST_WINDOW_H */ -
src/preferences/time/TimeZoneListItem.cpp
1 1 /* 2 * Copyright 201 0, Haiku Inc. All rights reserved.2 * Copyright 2011, Haiku Inc. All rights reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 9 9 * Oliver Tappe <zooey@hirschkaefer.de> 10 10 */ 11 11 12 13 12 #include "TimeZoneListItem.h" 14 13 15 14 #include <new> -
src/preferences/time/BaseView.cpp
8 8 */ 9 9 10 10 #include "BaseView.h" 11 #include "TimeMessages.h"12 11 13 14 12 #include <DateTime.h> 15 13 #include <OS.h> 16 14 15 #include "TimeMessages.h" 17 16 18 TTimeBaseView::TTimeBaseView(BRect frame, const char* name) 19 : BView(frame, name, B_FOLLOW_NONE, B_PULSE_NEEDED), 20 fMessage(H_TIME_UPDATE) 17 18 TTimeBaseView::TTimeBaseView(const char* name) 19 : 20 BGroupView(name, B_VERTICAL, 0), 21 fMessage(H_TIME_UPDATE) 21 22 { 23 SetFlags(Flags() | B_PULSE_NEEDED); 22 24 } 23 25 24 26 -
src/preferences/time/ZoneView.cpp
8 8 * Philippe Saint-Pierre <stpere@gmail.com> 9 9 * Adrien Destugues <pulkomandy@pulkomandy.ath.cx> 10 10 * Oliver Tappe <zooey@hirschkaefer.de> 11 * Hamish Morrison <hamish@lavabit.com> 11 12 */ 12 13 13 14 14 #include "ZoneView.h" 15 15 16 16 #include <stdlib.h> … … 77 77 78 78 79 79 80 TimeZoneView::TimeZoneView( BRect frame)80 TimeZoneView::TimeZoneView(const char* name) 81 81 : 82 B View(frame, "timeZoneView", B_FOLLOW_NONE, B_WILL_DRAW | B_NAVIGABLE_JUMP),82 BGroupView(name, B_HORIZONTAL, B_USE_DEFAULT_SPACING), 83 83 fToolTip(NULL), 84 84 fCurrentZoneItem(NULL), 85 85 fOldZoneItem(NULL), … … 173 173 break; 174 174 175 175 default: 176 B View::MessageReceived(message);176 BGroupView::MessageReceived(message); 177 177 break; 178 178 } 179 179 } … … 233 233 void 234 234 TimeZoneView::_InitView() 235 235 { 236 // left side 237 BRect frameLeft(Bounds()); 238 frameLeft.right = frameLeft.Width() / 2.0; 239 frameLeft.InsetBy(10.0f, 10.0f); 240 241 // City Listing 242 fZoneList = new BOutlineListView(frameLeft, "cityList", 243 B_SINGLE_SELECTION_LIST); 236 fZoneList = new BOutlineListView("cityList", B_SINGLE_SELECTION_LIST); 244 237 fZoneList->SetSelectionMessage(new BMessage(H_CITY_CHANGED)); 245 238 fZoneList->SetInvocationMessage(new BMessage(H_SET_TIME_ZONE)); 246 247 239 _BuildZoneMenu(); 248 249 240 BScrollView* scrollList = new BScrollView("scrollList", fZoneList, 250 B_FOLLOW_ALL, 0, false, true); 251 AddChild(scrollList); 241 B_FRAME_EVENTS | B_WILL_DRAW, false, true); 252 242 253 // right side 254 BRect frameRight(Bounds()); 255 frameRight.left = frameRight.Width() / 2.0; 256 frameRight.InsetBy(10.0f, 10.0f); 257 frameRight.top = frameLeft.top; 243 fCurrent = new TTZDisplay("currentTime", B_TRANSLATE("Current time:")); 244 fPreview = new TTZDisplay("previewTime", B_TRANSLATE("Preview time:")); 258 245 259 // Time Displays 260 fCurrent = new TTZDisplay(frameRight, "currentTime", 261 B_TRANSLATE("Current time:")); 262 AddChild(fCurrent); 263 fCurrent->ResizeToPreferred(); 264 265 frameRight.top = fCurrent->Frame().bottom + 10.0; 266 fPreview = new TTZDisplay(frameRight, "previewTime", 267 B_TRANSLATE("Preview time:")); 268 AddChild(fPreview); 269 fPreview->ResizeToPreferred(); 270 271 // set button 272 fSetZone = new BButton(frameRight, "setTimeZone", 273 B_TRANSLATE("Set time zone"), 246 fSetZone = new BButton("setTimeZone", B_TRANSLATE("Set time zone"), 274 247 new BMessage(H_SET_TIME_ZONE)); 275 AddChild(fSetZone);276 248 fSetZone->SetEnabled(false); 277 fSetZone->ResizeToPreferred(); 278 279 fSetZone->MoveTo(frameRight.right - fSetZone->Bounds().Width(), 280 scrollList->Frame().bottom - fSetZone->Bounds().Height()); 249 250 BLayoutBuilder::Group<>(this) 251 .Add(scrollList) 252 .AddGroup(B_VERTICAL, 5) 253 .Add(fCurrent) 254 .Add(fPreview) 255 .AddGlue() 256 .AddGroup(B_HORIZONTAL, 5) 257 .AddGlue() 258 .Add(fSetZone) 259 .End() 260 .End() 261 .SetInsets(5, 5, 5, 5); 281 262 } 282 263 283 264 -
src/preferences/time/DateTimeEdit.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * McCall <mccall@@digitalparadise.co.uk> 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 * 9 * Hamish Morrison <hamish@lavabit.com> 10 10 */ 11 11 #ifndef _DATE_TIME_EDIT_H 12 12 #define _DATE_TIME_EDIT_H … … 21 21 22 22 class TTimeEdit : public TSectionEdit { 23 23 public: 24 TTimeEdit(BRect frame, const char* name, 25 uint32 sections); 24 TTimeEdit(const char* name, uint32 sections); 26 25 virtual ~TTimeEdit(); 27 26 28 27 virtual void KeyDown(const char* bytes, int32 numBytes); 29 28 30 29 virtual void InitView(); 31 virtual void DrawSection(uint32 index, bool isfocus); 32 virtual void DrawSeparator(uint32 index); 30 virtual void DrawSection(uint32 index, BRect bounds, 31 bool isfocus); 32 virtual void DrawSeparator(uint32 index, BRect bounds); 33 33 34 virtual void SetSections(BRect area);35 34 virtual void SectionFocus(uint32 index); 36 virtual float SeparatorWidth() const; 35 virtual float MinSectionWidth(); 36 virtual float SeparatorWidth(); 37 37 38 virtual float PreferredHeight(); 38 39 virtual void DoUpPress(); 39 40 virtual void DoDownPress(); 40 41 … … 65 66 66 67 class TDateEdit : public TSectionEdit { 67 68 public: 68 TDateEdit(BRect frame, const char* name, 69 uint32 sections); 69 TDateEdit(const char* name, uint32 sections); 70 70 virtual ~TDateEdit(); 71 71 virtual void KeyDown(const char* bytes, int32 numBytes); 72 72 73 73 virtual void InitView(); 74 virtual void DrawSection(uint32 index, bool isfocus); 75 virtual void DrawSeparator(uint32 index); 74 virtual void DrawSection(uint32 index, BRect bounds, 75 bool isfocus); 76 virtual void DrawSeparator(uint32 index, BRect bounds); 76 77 77 virtual void SetSections(BRect area);78 78 virtual void SectionFocus(uint32 index); 79 virtual float SeparatorWidth() const; 79 virtual float MinSectionWidth(); 80 virtual float SeparatorWidth(); 80 81 82 virtual float PreferredHeight(); 81 83 virtual void DoUpPress(); 82 84 virtual void DoDownPress(); 83 85 84 86 virtual void BuildDispatch(BMessage* message); 87 85 88 86 89 void SetDate(int32 year, int32 month, int32 day); 87 90 … … 90 93 void _CheckRange(); 91 94 bool _IsValidDoubleDigit(int32 value); 92 95 int32 _SectionValue(int32 index) const; 93 94 96 private: 95 97 BDate fDate; 96 98 bigtime_t fLastKeyDownTime; -
src/preferences/time/SectionEdit.cpp
1 1 /* 2 * Copyright 2004-20 07, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Mike Berg <mike@berg-net.us> 7 7 * Julun <host.haiku@gmx.de> 8 * 8 * Hamish Morrison <hamish@lavabit.com> 9 9 */ 10 10 11 11 #include "SectionEdit.h" 12 12 13 13 #include <Bitmap.h> 14 14 #include <ControlLook.h> 15 #include <LayoutUtils.h> 15 16 #include <List.h> 16 17 #include <Window.h> 17 18 18 19 #include "TimeMessages.h" 19 20 20 21 21 TSection::TSection(BRect frame)22 :23 fFrame(frame)24 {25 }26 27 28 BRect29 TSection::Bounds() const30 {31 BRect frame(fFrame);32 return frame.OffsetByCopy(B_ORIGIN);33 }34 35 36 void37 TSection::SetFrame(BRect frame)38 {39 fFrame = frame;40 }41 42 43 BRect44 TSection::Frame() const45 {46 return fFrame;47 }48 49 50 22 const uint32 kArrowAreaWidth = 16; 51 23 52 24 53 TSectionEdit::TSectionEdit( BRect frame,const char* name, uint32 sections)25 TSectionEdit::TSectionEdit(const char* name, uint32 sections) 54 26 : 55 BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE | B_WILL_DRAW), 56 fSectionList(NULL), 27 BControl(name, NULL, NULL, B_WILL_DRAW | B_NAVIGABLE), 57 28 fFocus(-1), 58 29 fSectionCount(sections), 59 30 fHoldValue(0) 60 31 { 61 InitView();62 32 } 63 33 64 34 65 35 TSectionEdit::~TSectionEdit() 66 36 { 67 int32 count = fSectionList->CountItems();68 if (count > 0) {69 for (int32 index = 0; index < count; index++)70 delete (TSection*)fSectionList->ItemAt(index);71 }72 delete fSectionList;73 37 } 74 38 75 39 … … 87 51 DrawBorder(updateRect); 88 52 89 53 for (uint32 idx = 0; idx < fSectionCount; idx++) { 90 DrawSection(idx, ((uint32)fFocus == idx) && IsFocus()); 91 if (idx < fSectionCount -1) 92 DrawSeparator(idx); 54 DrawSection(idx, FrameForSection(idx), 55 ((uint32)fFocus == idx) && IsFocus()); 56 if (idx < fSectionCount - 1) 57 DrawSeparator(idx, FrameForSeparator(idx)); 93 58 } 94 59 } 95 60 … … 103 68 DoUpPress(); 104 69 else if (fDownRect.Contains(where)) 105 70 DoDownPress(); 106 else if (fSectionList->CountItems()> 0) { 107 TSection* section; 71 else if (fSectionCount > 0) { 108 72 for (uint32 idx = 0; idx < fSectionCount; idx++) { 109 section = (TSection*)fSectionList->ItemAt(idx); 110 if (section->Frame().Contains(where)) { 73 if (FrameForSection(idx).Contains(where)) { 111 74 SectionFocus(idx); 112 75 return; 113 76 } … … 116 79 } 117 80 118 81 82 BSize 83 TSectionEdit::MaxSize() 84 { 85 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), 86 BSize(B_SIZE_UNLIMITED, PreferredHeight())); 87 } 88 89 90 BSize 91 TSectionEdit::MinSize() 92 { 93 BSize minSize; 94 minSize.height = PreferredHeight(); 95 minSize.width = (SeparatorWidth() + MinSectionWidth()) 96 * fSectionCount; 97 return BLayoutUtils::ComposeSize(ExplicitMinSize(), 98 minSize); 99 } 100 101 102 BSize 103 TSectionEdit::PreferredSize() 104 { 105 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), 106 MinSize()); 107 } 108 109 110 BRect 111 TSectionEdit::FrameForSection(uint32 index) 112 { 113 BRect area = SectionArea(); 114 float sepWidth = SeparatorWidth(); 115 116 float width = (area.Width() - 117 sepWidth * (fSectionCount - 1)) 118 / fSectionCount; 119 area.left += index * (width + sepWidth); 120 area.right = area.left + width; 121 122 return area; 123 } 124 125 126 BRect 127 TSectionEdit::FrameForSeparator(uint32 index) 128 { 129 BRect area = SectionArea(); 130 float sepWidth = SeparatorWidth(); 131 132 float width = (area.Width() - 133 sepWidth * (fSectionCount - 1)) 134 / fSectionCount; 135 area.left += (index + 1) * width + index * sepWidth; 136 area.right = area.left + sepWidth; 137 138 return area; 139 } 140 141 119 142 void 120 143 TSectionEdit::MakeFocus(bool focused) 121 144 { … … 141 164 case B_LEFT_ARROW: 142 165 fFocus -= 1; 143 166 if (fFocus < 0) 144 fFocus = fSectionCount - 1;167 fFocus = fSectionCount - 1; 145 168 SectionFocus(fFocus); 146 169 break; 147 170 … … 180 203 uint32 181 204 TSectionEdit::CountSections() const 182 205 { 183 return fSection List->CountItems();206 return fSectionCount; 184 207 } 185 208 186 209 … … 191 214 } 192 215 193 216 194 void 195 TSectionEdit:: InitView()217 BRect 218 TSectionEdit::SectionArea() const 196 219 { 197 // setup sections 198 fSectionList = new BList(fSectionCount); 199 fSectionArea = Bounds().InsetByCopy(2, 2); 200 fSectionArea.right -= kArrowAreaWidth; 220 BRect sectionArea = Bounds().InsetByCopy(2, 2); 221 sectionArea.right -= kArrowAreaWidth; 222 return sectionArea; 201 223 } 202 224 203 225 … … 222 244 BPoint left(fUpRect.left + 3, fUpRect.bottom - 1); 223 245 BPoint right(left.x + 2 * (middle.x - left.x), fUpRect.bottom - 1); 224 246 225 SetPenSize(2); 247 SetPenSize(1); 248 SetLowColor(ViewColor()); 226 249 227 250 if (updateRect.Intersects(fUpRect)) { 228 251 FillRect(fUpRect, B_SOLID_LOW); … … 244 267 245 268 SetPenSize(1); 246 269 } 247 248 249 float250 TSectionEdit::SeparatorWidth() const251 {252 return 0.0f;253 }254 -
src/preferences/time/AnalogClock.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Mike Berg <mike@berg-net.us> 7 7 * Julun <host.haiku@gmx.de> 8 * Hamish Morrison <hamish@lavabit.com> 8 9 */ 9 10 #ifndef _ANALOG_CLOCK_H 10 11 #define _ANALOG_CLOCK_H … … 13 14 #include <View.h> 14 15 15 16 16 class BBitmap;17 class OffscreenClock;18 19 20 17 class TAnalogClock : public BView { 21 18 public: 22 TAnalogClock(BRect frame, const char* name, 23 bool drawSecondHand = true, bool interactive = true); 24 virtual ~TAnalogClock(); 19 TAnalogClock(const char* name, 20 bool drawSecondHand = true, 21 bool interactive = true); 22 virtual ~TAnalogClock(); 25 23 26 virtual void AttachedToWindow(); 27 virtual void Draw(BRect updateRect); 28 virtual void MessageReceived(BMessage* message); 29 virtual void MouseDown(BPoint point); 30 virtual void MouseUp(BPoint point); 31 virtual void MouseMoved(BPoint point, uint32 transit, 32 const BMessage* message); 24 virtual void Draw(BRect updateRect); 25 virtual void MessageReceived(BMessage* message); 26 virtual void MouseDown(BPoint point); 27 virtual void MouseUp(BPoint point); 28 virtual void MouseMoved(BPoint point, uint32 transit, 29 const BMessage* message); 30 virtual void FrameResized(float, float); 31 32 virtual BSize MaxSize(); 33 virtual BSize MinSize(); 34 virtual BSize PreferredSize(); 33 35 34 void SetTime(int32 hour, int32 minute, int32 second); 36 void SetTime(int32 hour, int32 minute, int32 second); 37 bool IsChangingTime(); 38 void ChangeTimeFinished(); 35 39 36 bool IsChangingTime() 37 { return fTimeChangeIsOngoing; } 38 void ChangeTimeFinished(); 40 void GetTime(int32* hour, int32* minute, int32* second); 41 void DrawClock(); 42 43 bool InHourHand(BPoint point); 44 bool InMinuteHand(BPoint point); 45 46 void SetHourHand(BPoint point); 47 void SetMinuteHand(BPoint point); 48 49 void SetHourDragging(bool dragging); 50 void SetMinuteDragging(bool dragging); 39 51 private: 40 void _InitView(BRect frame);41 52 42 BBitmap* fBitmap; 43 OffscreenClock* fClock; 53 float _GetPhi(BPoint point); 54 bool _InHand(BPoint point, int32 ticks, float radius); 55 void _DrawHands(float x, float y, float radius, 56 rgb_color hourHourColor, 57 rgb_color hourMinuteColor, 58 rgb_color secondsColor, rgb_color knobColor); 44 59 45 bool fDrawSecondHand; 46 bool fInteractive; 47 bool fDraggingHourHand; 48 bool fDraggingMinuteHand; 60 int32 fHours; 61 int32 fMinutes; 62 int32 fSeconds; 63 bool fDirty; 64 65 float fCenterX; 66 float fCenterY; 67 float fRadius; 49 68 50 bool fTimeChangeIsOngoing; 69 bool fHourDragging; 70 bool fMinuteDragging; 71 bool fDrawSecondHand; 72 bool fInteractive; 73 74 bool fTimeChangeIsOngoing; 75 51 76 }; 52 77 53 78 -
src/preferences/time/TimeWindow.cpp
1 1 /* 2 * Copyright 2004-20 07, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Andrew McCall <mccall@@digitalparadise.co.uk> 7 7 * Julun <host.haiku@gmx.de> 8 * 8 * Hamish Morrison <hamish@lavabit.com> 9 9 */ 10 10 11 11 #include "TimeWindow.h" 12 12 #include "BaseView.h" 13 13 #include "DateTimeView.h" 14 #include "NetworkTimeView.h" 14 15 #include "TimeMessages.h" 15 16 #include "TimeSettings.h" 16 17 #include "ZoneView.h" 17 18 18 19 19 #include <Application.h> 20 20 #include <Catalog.h> 21 #include <LayoutBuilder.h> 21 22 #include <Message.h> 22 23 #include <Screen.h> 23 24 #include <TabView.h> … … 27 28 #define B_TRANSLATE_CONTEXT "Time" 28 29 29 30 TTimeWindow::TTimeWindow(BRect rect) 30 : BWindow(rect, B_TRANSLATE("Time"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) 31 : 32 BWindow(rect, B_TRANSLATE("Time"), B_TITLED_WINDOW, 33 B_NOT_RESIZABLE | B_NOT_ZOOMABLE) 31 34 { 32 35 _InitWindow(); 33 36 _AlignWindow(); … … 76 79 SetRevertStatus(); 77 80 break; 78 81 82 case kMsgTryAllServers: 83 fNetworkTimeView->MessageReceived(message); 84 break; 85 86 case kMsgSynchronizeAtBoot: 87 fNetworkTimeView->MessageReceived(message); 88 break; 89 90 case kMsgEditServerList: 91 fNetworkTimeView->MessageReceived(message); 92 break; 93 94 case kMsgEditServerListWindowClosed: 95 fNetworkTimeView->MessageReceived(message); 96 break; 97 98 case kMsgResetServerList: 99 fNetworkTimeView->MessageReceived(message); 100 break; 101 102 case kMsgUpdateSettings: 103 fNetworkTimeView->MessageReceived(message); 104 break; 105 106 case kMsgSettingsUpdated: 107 fNetworkTimeView->MessageReceived(message); 108 break; 109 110 case kMsgDefaultServer: 111 fNetworkTimeView->MessageReceived(message); 112 break; 113 114 case kMsgSynchronize: 115 fNetworkTimeView->MessageReceived(message); 116 break; 117 118 case kMsgStopSynchronization: 119 fNetworkTimeView->MessageReceived(message); 120 break; 121 122 case kMsgStatusUpdate: 123 fNetworkTimeView->MessageReceived(message); 124 break; 125 79 126 default: 80 127 BWindow::MessageReceived(message); 81 128 break; … … 102 149 { 103 150 SetPulseRate(500000); 104 151 105 fDateTimeView = new DateTimeView(Bounds()); 152 fDateTimeView = new DateTimeView(B_TRANSLATE("Date and time")); 153 fTimeZoneView = new TimeZoneView(B_TRANSLATE("Time zone")); 154 fNetworkTimeView = new NetworkTimeView(B_TRANSLATE("Network time")); 106 155 107 BRect bounds = fDateTimeView->Bounds(); 108 fTimeZoneView = new TimeZoneView(bounds); 109 110 fBaseView = new TTimeBaseView(bounds, "baseView"); 111 AddChild(fBaseView); 112 156 fBaseView = new TTimeBaseView("baseView"); 113 157 fBaseView->StartWatchingAll(fDateTimeView); 114 158 fBaseView->StartWatchingAll(fTimeZoneView); 115 159 116 bounds.OffsetBy(10.0, 10.0); 117 BTabView* tabView = new BTabView(bounds.InsetByCopy(-5.0, -5.0), 118 "tabView" , B_WIDTH_AS_USUAL, B_FOLLOW_NONE); 119 120 BTab* tab = new BTab(); 121 tabView->AddTab(fDateTimeView, tab); 122 tab->SetLabel(B_TRANSLATE("Date & Time")); 123 124 tab = new BTab(); 125 tabView->AddTab(fTimeZoneView, tab); 126 tab->SetLabel(B_TRANSLATE("Time zone")); 127 160 BTabView* tabView = new BTabView("tabView"); 161 tabView->AddTab(fDateTimeView); 162 tabView->AddTab(fTimeZoneView); 163 tabView->AddTab(fNetworkTimeView); 164 128 165 fBaseView->AddChild(tabView); 129 tabView->ResizeBy(0.0, tabView->TabHeight());130 166 131 BRect rect = Bounds(); 132 133 rect.left = 10; 134 rect.top = rect.bottom - 10; 135 136 fRevertButton = new BButton(rect, "revert", "Revert", 137 new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); 138 139 fRevertButton->ResizeToPreferred(); 167 fRevertButton = new BButton("revert", "Revert", new BMessage(kMsgRevert)); 140 168 fRevertButton->SetEnabled(false); 141 float buttonHeight = fRevertButton->Bounds().Height();142 fRevertButton->MoveBy(0, -buttonHeight);143 fBaseView->AddChild(fRevertButton);144 169 fRevertButton->SetTarget(this); 145 146 fBaseView->ResizeTo(tabView->Bounds().Width() + 10.0, 147 tabView->Bounds().Height() + buttonHeight + 30.0); 148 149 ResizeTo(fBaseView->Bounds().Width(), fBaseView->Bounds().Height()); 170 171 BLayoutBuilder::Group<>(this, B_VERTICAL, 5) 172 .Add(fBaseView) 173 .AddGroup(B_HORIZONTAL, 5) 174 .Add(fRevertButton) 175 .AddGlue() 176 .End() 177 .SetInsets(5, 5, 5, 5); 150 178 } 151 179 152 180 -
src/preferences/time/Jamfile
10 10 BaseView.cpp 11 11 Bitmaps.cpp 12 12 DateTimeEdit.cpp 13 EditServerListWindow.cpp 13 14 SectionEdit.cpp 14 15 DateTimeView.cpp 16 NetworkTimeView.cpp 17 ntp.cpp 15 18 Time.cpp 16 19 TimeSettings.cpp 17 20 TimeWindow.cpp … … 28 31 29 32 Preference Time 30 33 : $(sources) 31 : be libshared.a $(TARGET_LIBSTDC++) $(HAIKU_LOCALE_LIBS) 34 : be libshared.a $(TARGET_LIBSTDC++) $(HAIKU_LOCALE_LIBS) $(HAIKU_NETWORK_LIBS) 32 35 : Time.rdef 33 36 ; 34 37 -
src/preferences/time/DateTimeView.cpp
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 9 * Philippe Saint-Pierre <stpere@gmail.com> 10 * Hamish Morrison <hamish@lavabit.com> 10 11 */ 11 12 12 13 #include "DateTimeView.h" … … 15 16 #include "TimeMessages.h" 16 17 #include "TimeWindow.h" 17 18 19 #include <Box.h> 18 20 #include <CalendarView.h> 21 #include <Catalog.h> 19 22 #include <CheckBox.h> 20 23 #include <DateTime.h> 21 24 #include <Entry.h> … … 32 35 33 36 #include <syscalls.h> 34 37 38 #undef B_TRANSLATE_CONTEXT 39 #define B_TRANSLATE_CONTEXT "Time" 35 40 41 36 42 using BPrivate::BCalendarView; 37 43 using BPrivate::BDateTime; 38 44 using BPrivate::B_LOCAL_TIME; 39 45 40 46 41 DateTimeView::DateTimeView( BRect frame)42 : BView(frame, "dateTimeView", B_FOLLOW_NONE, B_WILL_DRAW43 | B_NAVIGABLE_JUMP),47 DateTimeView::DateTimeView(const char* name) 48 : 49 BGroupView(name, B_HORIZONTAL, 5), 44 50 fGmtTime(NULL), 45 51 fUseGmtTime(false), 46 52 fInitialized(false), … … 204 210 void 205 211 DateTimeView::_InitView() 206 212 { 207 font_height fontHeight; 208 be_plain_font->GetHeight(&fontHeight); 209 float textHeight = fontHeight.descent + fontHeight.ascent 210 + fontHeight.leading + 6.0; // 6px border 211 212 // left side 213 BRect bounds = Bounds(); 214 bounds.InsetBy(10.0, 10.0); 215 bounds.top += textHeight + 10.0; 216 217 fCalendarView = new BCalendarView(bounds, "calendar"); 213 fCalendarView = new BCalendarView("calendar"); 218 214 fCalendarView->SetWeekNumberHeaderVisible(false); 219 fCalendarView->ResizeToPreferred();220 215 fCalendarView->SetSelectionMessage(new BMessage(kDayChanged)); 221 216 fCalendarView->SetInvocationMessage(new BMessage(kDayChanged)); 222 217 223 bounds.top -= textHeight + 10.0; 224 bounds.bottom = bounds.top + textHeight; 225 bounds.right = fCalendarView->Frame().right; 226 227 fDateEdit = new TDateEdit(bounds, "dateEdit", 3); 228 AddChild(fDateEdit); 229 AddChild(fCalendarView); 230 231 // right side, 2px extra for separator 232 bounds.OffsetBy(bounds.Width() + 22.0, 0.0); 233 fTimeEdit = new TTimeEdit(bounds, "timeEdit", 4); 234 AddChild(fTimeEdit); 235 236 bounds = fCalendarView->Frame(); 237 bounds.OffsetBy(bounds.Width() + 22.0, 0.0); 238 239 fClock = new TAnalogClock(bounds, "analogClock"); 240 AddChild(fClock); 218 fDateEdit = new TDateEdit("dateEdit", 3); 219 fTimeEdit = new TTimeEdit("timeEdit", 4); 220 fClock = new TAnalogClock("analogClock"); 221 241 222 BTime time(BTime::CurrentTime(B_LOCAL_TIME)); 242 223 fClock->SetTime(time.Hour(), time.Minute(), time.Second()); 243 224 244 // clock radio buttons 245 bounds.top = fClock->Frame().bottom + 10.0; 246 BStringView* text = new BStringView(bounds, "clockSetTo", "Clock set to:"); 247 AddChild(text); 248 text->ResizeToPreferred(); 225 BStringView* text = new BStringView("clockSetTo", 226 B_TRANSLATE("Clock set to:")); 227 fLocalTime = new BRadioButton("localTime", 228 B_TRANSLATE("Local time"), new BMessage(kRTCUpdate)); 229 fGmtTime = new BRadioButton("greenwichMeanTime", 230 B_TRANSLATE("GMT"), new BMessage(kRTCUpdate)); 249 231 250 bounds.left += 10.0f;251 bounds.top = text->Frame().bottom;252 fLocalTime = new BRadioButton(bounds, "localTime", "Local time",253 new BMessage(kRTCUpdate));254 AddChild(fLocalTime);255 fLocalTime->ResizeToPreferred();256 257 bounds.left = fLocalTime->Frame().right + 10.0;258 fGmtTime = new BRadioButton(bounds, "greenwichMeanTime", "GMT",259 new BMessage(kRTCUpdate));260 AddChild(fGmtTime);261 fGmtTime->ResizeToPreferred();262 263 232 if (fUseGmtTime) 264 233 fGmtTime->SetValue(B_CONTROL_ON); 265 234 else 266 235 fLocalTime->SetValue(B_CONTROL_ON); 267 268 236 fOldUseGmtTime = fUseGmtTime; 269 237 270 ResizeTo(fClock->Frame().right + 10.0, fGmtTime->Frame().bottom + 10.0); 238 BBox* divider = new BBox(BRect(0, 0, 1, 1), 239 B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, 240 B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); 241 divider->SetExplicitMaxSize(BSize(1, B_SIZE_UNLIMITED)); 242 243 BLayoutBuilder::Group<>(this) 244 .AddGroup(B_VERTICAL, 5) 245 .Add(fDateEdit) 246 .Add(fCalendarView) 247 .End() 248 .Add(divider) 249 .AddGroup(B_VERTICAL, 5) 250 .Add(fTimeEdit) 251 .Add(fClock) 252 .Add(text) 253 .AddGroup(B_HORIZONTAL, 5) 254 .Add(fLocalTime) 255 .Add(fGmtTime) 256 .End() 257 .End() 258 .SetInsets(5, 5, 5, 5); 271 259 } 272 260 273 261 -
src/preferences/time/TZDisplay.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Andrew McCall <mccall@@digitalparadise.co.uk> 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 * 9 * Hamish Morrison <hamish@lavabit.com> 10 10 */ 11 11 #ifndef _TZ_DISPLAY_H 12 12 #define _TZ_DISPLAY_H … … 18 18 19 19 class TTZDisplay : public BView { 20 20 public: 21 TTZDisplay( BRect frame,const char* name,21 TTZDisplay(const char* name, 22 22 const char* label); 23 23 virtual ~TTZDisplay(); 24 24 25 25 virtual void AttachedToWindow(); 26 26 virtual void ResizeToPreferred(); 27 27 virtual void Draw(BRect updateRect); 28 29 virtual BSize MaxSize(); 30 virtual BSize MinSize(); 31 virtual BSize PreferredSize(); 28 32 29 33 const char* Label() const; 30 34 void SetLabel(const char* label); … … 36 40 void SetTime(const char* time); 37 41 38 42 private: 43 BSize _CalcPrefSize(); 44 39 45 BString fLabel; 40 46 BString fText; 41 47 BString fTime; -
src/preferences/time/Time.cpp
1 1 /* 2 * Copyright 2002-20 07, Haiku. All rights reserved.2 * Copyright 2002-2011, Haiku. All rights reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Andrew McCall <mccall@digitalparadise.co.uk> 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 * Hamish Morrison <hamish@lavabit.com> 9 10 */ 10 11 11 12 #include "Time.h" 12 #include "TimeWindow.h"13 13 14 15 14 #include <Alert.h> 16 15 #include <Catalog.h> 17 16 18 17 #include <unistd.h> 19 18 19 #include "NetworkTimeView.h" 20 #include "TimeWindow.h" 21 20 22 #undef B_TRANSLATE_CONTEXT 21 23 #define B_TRANSLATE_CONTEXT "Time" 22 24 … … 24 26 25 27 26 28 TimeApplication::TimeApplication() 27 : BApplication(kAppSignature), 28 fWindow(NULL) 29 : 30 BApplication(kAppSignature), 31 fWindow(NULL) 29 32 { 30 fWindow = new TTimeWindow(BRect(100, 100, 5 70, 327));33 fWindow = new TTimeWindow(BRect(100, 100, 530, 360)); 31 34 } 32 35 33 36 … … 47 50 TimeApplication::AboutRequested() 48 51 { 49 52 BAlert* alert = new BAlert(B_TRANSLATE("about"), 50 B_TRANSLATE("Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t" 51 "Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2008, Haiku."), 53 B_TRANSLATE( 54 "Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t" 55 "Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2008, Haiku."), 52 56 B_TRANSLATE("OK")); 53 57 alert->Go(); 54 58 } … … 60 64 int 61 65 main(int argc, char** argv) 62 66 { 63 TimeApplication app; 64 setuid(0); 65 app.Run(); 67 if (argc > 1) { 68 if (!strcmp(argv[1], "--silent-update")) { 69 Settings settings; 70 bool boolean; 71 if (settings.Message().FindBool("synchronize at boot", &boolean) 72 == B_OK) { 73 if (!boolean) return 0; 74 update_time(settings.Message(), NULL); 75 } 76 } 77 } 78 else { 79 TimeApplication app; 80 setuid(0); 81 app.Run(); 82 } 66 83 67 84 return 0; 68 85 } -
src/preferences/time/EditServerListWindow.cpp
1 /* 2 * Copyright 2004, pinc Software. All Rights Reserved. 3 * Distributed under the terms of the MIT license. 4 */ 5 6 #include "EditServerListWindow.h" 7 #include "NetworkTimeView.h" 8 9 #include <Application.h> 10 #include <TextView.h> 11 #include <ScrollView.h> 12 #include <Button.h> 13 #include <Screen.h> 14 15 #include <string.h> 16 #include <stdlib.h> 17 18 19 static const char *kServerDelimiters = ", \n\t"; 20 21 22 struct tokens { 23 char *buffer; 24 char *next; 25 const char *delimiters; 26 }; 27 28 29 static void 30 put_tokens(tokens &tokens) 31 { 32 free(tokens.buffer); 33 tokens.buffer = NULL; 34 } 35 36 37 static status_t 38 prepare_tokens(tokens &tokens, const char *text, const char *delimiters) 39 { 40 tokens.buffer = strdup(text); 41 if (tokens.buffer == NULL) 42 return B_NO_MEMORY; 43 44 tokens.delimiters = delimiters; 45 tokens.next = tokens.buffer; 46 return B_OK; 47 } 48 49 50 static const char * 51 next_token(tokens &tokens) 52 { 53 char *token = strtok(tokens.next, tokens.delimiters); 54 if (tokens.next != NULL) 55 tokens.next = NULL; 56 if (token == NULL) 57 put_tokens(tokens); 58 59 return token; 60 } 61 62 63 // #pragma mark - 64 65 66 EditServerListWindow::EditServerListWindow(BRect position, const BMessage& settings, BLooper* looper) 67 : 68 BWindow(position, "Edit Server List", B_TITLED_WINDOW, 69 B_ASYNCHRONOUS_CONTROLS), 70 fSettings(settings), 71 fLooper(looper) 72 { 73 BRect rect = Bounds(); 74 BView *view = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); 75 view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 76 AddChild(view); 77 78 rect = view->Bounds().InsetByCopy(5, 5); 79 80 BButton *button = new BButton(rect, "defaults", "Reset To Defaults", 81 new BMessage(kMsgResetServerList), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM); 82 float width, height; 83 button->GetPreferredSize(&width, &height); 84 button->ResizeTo(rect.Width(), height); 85 button->MoveBy(0, rect.Height() - height); 86 button->SetTarget(be_app); 87 view->AddChild(button); 88 89 rect.bottom -= 5 + height; 90 rect.InsetBy(2, 2); 91 rect.right -= B_V_SCROLL_BAR_WIDTH; 92 93 fServerView = new BTextView(rect, "list", 94 rect.OffsetToCopy(B_ORIGIN).InsetByCopy(3, 3), B_FOLLOW_ALL); 95 fServerView->SetStylable(true); 96 97 BScrollView *scrollView = new BScrollView("scroller", fServerView, B_FOLLOW_ALL, B_WILL_DRAW, false, true); 98 view->AddChild(scrollView); 99 100 UpdateServerView(settings); 101 102 SetSizeLimits(200, 16384, 200, 16384); 103 104 if (Frame().LeftTop() == B_ORIGIN) { 105 // center on screen 106 BScreen screen; 107 MoveTo((screen.Frame().Width() - Bounds().Width()) / 2, 108 (screen.Frame().Height() - Bounds().Height()) / 2); 109 } 110 } 111 112 113 EditServerListWindow::~EditServerListWindow() 114 { 115 } 116 117 118 void 119 EditServerListWindow::UpdateDefaultServerView(const BMessage &message) 120 { 121 int32 defaultServer; 122 if (message.FindInt32("default server", &defaultServer) != B_OK) 123 return; 124 125 BFont font(be_plain_font); 126 fServerView->SetFontAndColor(0, fServerView->TextLength(), 127 &font, B_FONT_FAMILY_AND_STYLE); 128 129 struct tokens tokens; 130 const char *server; 131 if (fSettings.FindString("server", defaultServer, &server) == B_OK 132 && prepare_tokens(tokens, fServerView->Text(), kServerDelimiters) == B_OK) { 133 const char *token; 134 while ((token = next_token(tokens)) != NULL) { 135 if (strcasecmp(token, server)) 136 continue; 137 138 int32 start = int32(token - tokens.buffer); 139 140 BFont font; 141 font.SetFace(B_BOLD_FACE); 142 fServerView->SetFontAndColor(start, start + strlen(server), 143 &font, B_FONT_FAMILY_AND_STYLE); 144 145 break; 146 } 147 put_tokens(tokens); 148 } 149 } 150 151 152 void 153 EditServerListWindow::UpdateServerView(const BMessage &message) 154 { 155 if (message.HasString("server") || message.HasBool("reset servers")) 156 fServerView->SetText(""); 157 158 int32 defaultServer; 159 if (message.FindInt32("default server", &defaultServer) != B_OK) 160 defaultServer = 0; 161 162 const char *server; 163 int32 index = 0; 164 for (; message.FindString("server", index, &server) == B_OK; index++) { 165 int32 start, end; 166 fServerView->GetSelection(&start, &end); 167 168 fServerView->Insert(server); 169 fServerView->Insert("\n"); 170 } 171 172 UpdateDefaultServerView(message); 173 } 174 175 176 void 177 EditServerListWindow::UpdateServerList() 178 { 179 // get old default server 180 181 int32 defaultServer; 182 if (fSettings.FindInt32("default server", &defaultServer) != B_OK) 183 defaultServer = 0; 184 const char *server; 185 if (fSettings.FindString("server", defaultServer, &server) != B_OK) 186 server = NULL; 187 188 // take over server list 189 190 struct tokens tokens; 191 if (prepare_tokens(tokens, fServerView->Text(), kServerDelimiters) == B_OK) { 192 BMessage servers(kMsgUpdateSettings); 193 194 int32 count = 0, newDefaultServer = -1; 195 196 const char *token; 197 while ((token = next_token(tokens)) != NULL) { 198 servers.AddString("server", token); 199 if (!strcasecmp(token, server)) 200 newDefaultServer = count; 201 202 count++; 203 } 204 205 if (count != 0) { 206 if (newDefaultServer == -1) 207 newDefaultServer = 0; 208 209 servers.AddInt32("default server", newDefaultServer); 210 fLooper->PostMessage(&servers); 211 } else 212 fLooper->PostMessage(kMsgResetServerList); 213 } 214 } 215 216 217 bool 218 EditServerListWindow::QuitRequested() 219 { 220 fLooper->PostMessage(kMsgEditServerListWindowClosed); 221 222 BMessage update(kMsgUpdateSettings); 223 update.AddRect("edit servers frame", Frame()); 224 fLooper->PostMessage(&update); 225 226 UpdateServerList(); 227 return true; 228 } 229 230 231 void 232 EditServerListWindow::MessageReceived(BMessage *message) 233 { 234 switch (message->what) { 235 case kMsgServersEdited: 236 UpdateServerList(); 237 break; 238 239 case kMsgSettingsUpdated: 240 if (message->HasString("server")) 241 UpdateServerView(*message); 242 else 243 UpdateDefaultServerView(*message); 244 break; 245 } 246 } 247 -
src/preferences/time/DateTimeEdit.cpp
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 8 8 * Julun <host.haiku@gmx.de> 9 9 * Clemens <mail@Clemens-Zeidler.de> 10 10 * Adrien Destugues <pulkomandy@pulkomandy.cx> 11 * Hamish Morrison <hamish@lavabit.com> 11 12 */ 12 13 13 14 14 #include "DateTimeEdit.h" 15 15 16 16 #include <stdlib.h> … … 24 24 using BPrivate::B_LOCAL_TIME; 25 25 26 26 27 TTimeEdit::TTimeEdit( BRect frame,const char* name, uint32 sections)27 TTimeEdit::TTimeEdit(const char* name, uint32 sections) 28 28 : 29 TSectionEdit( frame,name, sections),29 TSectionEdit(name, sections), 30 30 fLastKeyDownTime(0), 31 31 fFields(NULL), 32 32 fFieldCount(0), … … 57 57 int32 section = FocusIndex(); 58 58 if (section < 0 || section > 2) 59 59 return; 60 61 60 bigtime_t currentTime = system_time(); 62 61 if (currentTime - fLastKeyDownTime < 1000000) { 63 62 int32 doubleDigit = number + fLastKeyDownInt * 10; … … 84 83 { 85 84 // make sure we call the base class method, as it 86 85 // will create the arrow bitmaps and the section list 87 TSectionEdit::InitView();88 89 86 fTime = BDateTime::CurrentDateTime(B_LOCAL_TIME); 90 87 _UpdateFields(); 91 92 SetSections(fSectionArea);93 88 } 94 89 95 90 96 91 void 97 TTimeEdit::DrawSection(uint32 index, bool hasFocus)92 TTimeEdit::DrawSection(uint32 index, BRect bounds, bool hasFocus) 98 93 { 99 TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index)); 100 if (!section) 94 if (fFieldPositions == NULL || index * 2 + 1 >= (uint32)fFieldPosCount) 101 95 return; 102 103 if (fFieldPositions == NULL || index * 2 + 1 > (uint32)fFieldPosCount)104 return;105 106 BRect bounds = section->Frame();107 108 96 SetLowColor(ViewColor()); 109 97 if (hasFocus) 110 98 SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); … … 113 101 fText.CopyCharsInto(field, fFieldPositions[index * 2], 114 102 fFieldPositions[index * 2 + 1] - fFieldPositions[index * 2]); 115 103 116 // calc and center text in section rect 117 float width = be_plain_font->StringWidth(field); 118 119 BPoint offset(-((bounds.Width()- width) / 2.0) - 1.0, 120 bounds.Height() / 2.0 - 6.0); 121 104 BPoint point(bounds.LeftBottom()); 105 point.y -= bounds.Height() / 2.0 - 6.0; 106 point.x += (bounds.Width() - StringWidth(field)) / 2; 122 107 SetHighColor(0, 0, 0, 255); 123 108 FillRect(bounds, B_SOLID_LOW); 124 DrawString(field, bounds.LeftBottom() - offset);109 DrawString(field, point); 125 110 } 126 111 127 112 128 113 void 129 TTimeEdit::DrawSeparator(uint32 index )114 TTimeEdit::DrawSeparator(uint32 index, BRect bounds) 130 115 { 131 TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index)); 132 if (!section) 116 if (fFieldPositions == NULL || index * 2 + 2 >= (uint32)fFieldPosCount) 133 117 return; 134 118 135 if (fFieldPositions == NULL || index * 2 + 2 > (uint32)fFieldPosCount)136 return;137 138 119 BString field; 139 120 fText.CopyCharsInto(field, fFieldPositions[index * 2 + 1], 140 121 fFieldPositions[index * 2 + 2] - fFieldPositions[index * 2 + 1]); 141 122 142 float sepWidth = SeparatorWidth(); 143 BRect bounds = section->Frame(); 144 float width = be_plain_font->StringWidth(field); 145 BPoint offset(-((sepWidth - width) / 2.0) - 1.0, 146 bounds.Height() / 2.0 - 6.0); 147 DrawString(field, bounds.RightBottom() - offset); 123 BPoint point(bounds.LeftBottom()); 124 point.y -= bounds.Height() / 2.0 - 6.0; 125 point.x += (bounds.Width() - StringWidth(field)) / 2; 126 SetHighColor(0, 0, 0, 255); 127 DrawString(field, point); 148 128 } 149 129 150 130 151 void 152 TTimeEdit::Se tSections(BRect area)131 float 132 TTimeEdit::SeparatorWidth() 153 133 { 154 // by default divide up the sections evenly 155 BRect bounds(area); 156 157 float sepWidth = SeparatorWidth(); 158 159 float sep_2 = ceil(sepWidth / fSectionCount + 1); 160 float width = bounds.Width() / fSectionCount - sep_2; 161 bounds.right = bounds.left + (width - sepWidth / fSectionCount); 162 163 for (uint32 idx = 0; idx < fSectionCount; idx++) { 164 fSectionList->AddItem(new TSection(bounds)); 165 166 bounds.left = bounds.right + sepWidth; 167 if (idx == fSectionCount - 2) 168 bounds.right = area.right - 1; 169 else 170 bounds.right = bounds.left + (width - sep_2); 171 } 134 return 10.0f; 172 135 } 173 136 174 137 175 138 float 176 TTimeEdit:: SeparatorWidth() const139 TTimeEdit::MinSectionWidth() 177 140 { 178 return 10.0f;141 return be_plain_font->StringWidth("00"); 179 142 } 180 143 181 144 … … 236 199 237 200 // send message to change time 238 201 DispatchMessage(); 202 239 203 } 240 204 241 205 … … 247 211 248 212 message->AddBool("time", true); 249 213 250 for (int32 index = 0; index < fSectionList->CountItems() - 1; ++index) {214 for (int32 index = 0; index < (int)fSectionCount; ++index) { 251 215 uint32 data = _SectionValue(index); 252 216 253 217 if (fFocus == index) … … 277 241 TTimeEdit::_UpdateFields() 278 242 { 279 243 time_t time = fTime.Time_t(); 280 BLocale::Default()->FormatTime(&fText, fFieldPositions, fFieldPosCount, 281 time, B_MEDIUM_TIME_FORMAT); 244 245 if (fFieldPositions != NULL) { 246 free(fFieldPositions); 247 fFieldPositions = NULL; 248 } 249 BLocale::Default()->FormatTime(&fText, fFieldPositions, 250 fFieldPosCount, time, B_MEDIUM_TIME_FORMAT); 251 252 if (fFields != NULL) { 253 free(fFields); 254 fFields = NULL; 255 } 282 256 BLocale::Default()->GetTimeFields(fFields, fFieldCount, 283 257 B_MEDIUM_TIME_FORMAT); 284 258 } … … 405 379 } 406 380 407 381 382 float 383 TTimeEdit::PreferredHeight() 384 { 385 font_height fontHeight; 386 GetFontHeight(&fontHeight); 387 return ceilf((fontHeight.ascent + fontHeight.descent) * 1.4); 388 } 389 390 408 391 // #pragma mark - 409 392 410 393 411 TDateEdit::TDateEdit( BRect frame,const char* name, uint32 sections)394 TDateEdit::TDateEdit(const char* name, uint32 sections) 412 395 : 413 TSectionEdit( frame,name, sections),396 TSectionEdit(name, sections), 414 397 fFields(NULL), 415 398 fFieldCount(0), 416 399 fFieldPositions(NULL), … … 476 459 { 477 460 // make sure we call the base class method, as it 478 461 // will create the arrow bitmaps and the section list 479 TSectionEdit::InitView();480 481 462 fDate = BDate::CurrentDate(B_LOCAL_TIME); 482 463 _UpdateFields(); 483 484 SetSections(fSectionArea);485 464 } 486 465 487 466 488 467 void 489 TDateEdit::DrawSection(uint32 index, bool hasFocus)468 TDateEdit::DrawSection(uint32 index, BRect bounds, bool hasFocus) 490 469 { 491 TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index)); 492 if (!section) 470 if (fFieldPositions == NULL || index * 2 + 1 >= (uint32)fFieldPosCount) 493 471 return; 494 472 495 if (fFieldPositions == NULL || index * 2 + 1 > (uint32)fFieldPosCount)496 return;497 498 473 SetLowColor(ViewColor()); 499 474 if (hasFocus) 500 475 SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); … … 503 478 fText.CopyCharsInto(field, fFieldPositions[index * 2], 504 479 fFieldPositions[index * 2 + 1] - fFieldPositions[index * 2]); 505 480 506 // calc and center text in section rect 507 BRect bounds = section->Frame(); 508 float width = StringWidth(field); 509 BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0, 510 (bounds.Height() / 2.0 - 6.0)); 511 481 BPoint point(bounds.LeftBottom()); 482 point.y -= bounds.Height() / 2.0 - 6.0; 483 point.x += (bounds.Width() - StringWidth(field)) / 2; 512 484 SetHighColor(0, 0, 0, 255); 513 485 FillRect(bounds, B_SOLID_LOW); 514 DrawString(field, bounds.LeftBottom() - offset);486 DrawString(field, point); 515 487 } 516 488 517 489 518 490 void 519 TDateEdit::DrawSeparator(uint32 index )491 TDateEdit::DrawSeparator(uint32 index, BRect bounds) 520 492 { 521 493 if (index >= 2) 522 494 return; 523 495 524 TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index)); 525 if (!section) 496 if (fFieldPositions == NULL || index * 2 + 2 >= (uint32)fFieldPosCount) 526 497 return; 527 498 528 if (fFieldPositions == NULL || index * 2 + 2 > (uint32)fFieldPosCount)529 return;530 531 499 BString field; 532 500 fText.CopyCharsInto(field, fFieldPositions[index * 2 + 1], 533 501 fFieldPositions[index * 2 + 2] - fFieldPositions[index * 2 + 1]); 534 502 535 BRect bounds = section->Frame(); 536 float width = be_plain_font->StringWidth(field); 537 float sepWidth = SeparatorWidth(); 538 BPoint offset(-((sepWidth - width) / 2.0) - 1.0, 539 bounds.Height() / 2.0 - 6.0); 540 503 BPoint point(bounds.LeftBottom()); 504 point.y -= bounds.Height() / 2.0 - 6.0; 505 point.x += (bounds.Width() - StringWidth(field)) / 2; 541 506 SetHighColor(0, 0, 0, 255); 542 DrawString(field, bounds.RightBottom() - offset);507 DrawString(field, point); 543 508 } 544 509 545 510 546 511 void 547 TDateEdit::Se tSections(BRect area)512 TDateEdit::SectionFocus(uint32 index) 548 513 { 549 // TODO : we have to be more clever here, as the fields can move and have 550 // different sizes depending on the locale 551 552 // create sections 553 for (uint32 idx = 0; idx < fSectionCount; idx++) 554 fSectionList->AddItem(new TSection(area)); 555 556 BRect bounds(area); 557 float sepWidth = SeparatorWidth(); 558 559 TSection* section = static_cast<TSection*>(fSectionList->ItemAt(0)); 560 float width = be_plain_font->StringWidth("0000") + 10; 561 bounds.left = area.left; 562 bounds.right = bounds.left + width; 563 section->SetFrame(bounds); 564 565 section = static_cast<TSection*>(fSectionList->ItemAt(1)); 566 width = be_plain_font->StringWidth("0000") + 10; 567 bounds.left = bounds.right + sepWidth; 568 bounds.right = bounds.left + width; 569 section->SetFrame(bounds); 570 571 section = static_cast<TSection*>(fSectionList->ItemAt(2)); 572 width = be_plain_font->StringWidth("0000") + 10; 573 bounds.left = bounds.right + sepWidth; 574 bounds.right = bounds.left + width; 575 section->SetFrame(bounds); 514 fLastKeyDownTime = 0; 515 fFocus = index; 516 fHoldValue = _SectionValue(index); 517 Draw(Bounds()); 576 518 } 577 519 578 520 579 521 float 580 TDateEdit:: SeparatorWidth() const522 TDateEdit::MinSectionWidth() 581 523 { 582 return 10.0f;524 return be_plain_font->StringWidth("00"); 583 525 } 584 526 585 527 586 void 587 TDateEdit::Se ctionFocus(uint32 index)528 float 529 TDateEdit::SeparatorWidth() 588 530 { 589 fLastKeyDownTime = 0; 590 fFocus = index; 591 fHoldValue = _SectionValue(index); 592 Draw(Bounds()); 531 return 10.0f; 593 532 } 594 533 595 534 … … 647 586 648 587 message->AddBool("time", false); 649 588 650 for (int32 index = 0; index < fSectionList->CountItems(); ++index) {589 for (int32 index = 0; index < (int)fSectionCount; ++index) { 651 590 uint32 data = _SectionValue(index); 652 591 653 592 if (fFocus == index) … … 677 616 TDateEdit::_UpdateFields() 678 617 { 679 618 time_t time = BDateTime(fDate, BTime()).Time_t(); 619 620 if (fFieldPositions != NULL) { 621 free(fFieldPositions); 622 fFieldPositions = NULL; 623 } 680 624 BLocale::Default()->FormatDate(&fText, fFieldPositions, fFieldPosCount, 681 625 time, B_SHORT_DATE_FORMAT); 626 627 if (fFields != NULL) { 628 free(fFields); 629 fFields = NULL; 630 } 682 631 BLocale::Default()->GetDateFields(fFields, fFieldCount, 683 632 B_SHORT_DATE_FORMAT); 684 633 } … … 797 746 798 747 return value; 799 748 } 749 750 751 float 752 TDateEdit::PreferredHeight() 753 { 754 font_height fontHeight; 755 GetFontHeight(&fontHeight); 756 return ceilf((fontHeight.ascent + fontHeight.descent) * 1.4); 757 } -
src/preferences/time/NetworkTimeView.h
1 /* 2 * Copyright 2011, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Hamish Morrison <hamish@lavabit.com> 7 * Axel Dörfler <axeld@pinc-software.de> 8 */ 9 #ifndef NETWORK_TIME_VIEW_H 10 #define NETWORK_TIME_VIEW_H 11 12 #include <LayoutBuilder.h> 13 #include <Message.h> 14 #include <Path.h> 15 16 #include "EditServerListWindow.h" 17 #include "TimeMessages.h" 18 19 class BMenuField; 20 class BButton; 21 class BCheckBox; 22 class Monitor; 23 class Settings; 24 25 26 status_t 27 update_time(const BMessage &settings, Monitor *monitor, 28 thread_id *_asyncThread); 29 status_t 30 update_time(const BMessage &settings, Monitor *monitor); 31 32 33 class Settings { 34 public: 35 Settings(); 36 ~Settings(); 37 38 void CopyMessage(BMessage &message) const; 39 const BMessage &Message() const; 40 void UpdateFrom(BMessage &message); 41 42 void ResetServersToDefaults(); 43 void ResetToDefaults(); 44 status_t Load(); 45 status_t Save(); 46 47 private: 48 status_t GetPath(BPath &path); 49 50 BMessage fMessage; 51 bool fWasUpdated; 52 }; 53 54 55 class NetworkTimeView : public BGroupView { 56 public: 57 NetworkTimeView(const char* name); 58 59 virtual void MessageReceived(BMessage* message); 60 private: 61 void _InitView(); 62 void _UpdateServerListMenu(); 63 private: 64 65 BMenuField* fServerListMenuField; 66 BButton* fEditServerListButton; 67 BButton* fSynchronizeButton; 68 BCheckBox* fTryAllServersCheckBox; 69 BCheckBox* fSynchronizeAtBootCheckBox; 70 71 BWindow* fEditServerListWindow; 72 73 thread_id fUpdateThread; 74 const char* fStatusString; 75 Settings fSettings; 76 }; 77 78 #endif -
src/preferences/time/BaseView.h
10 10 #define _BASE_VIEW_H 11 11 12 12 13 #include <LayoutBuilder.h> 13 14 #include <Message.h> 14 #include <View.h>15 15 16 16 17 class TTimeBaseView: public B View {17 class TTimeBaseView: public BGroupView { 18 18 public: 19 TTimeBaseView( BRect frame,const char* name);19 TTimeBaseView(const char* name); 20 20 virtual ~TTimeBaseView(); 21 21 22 22 virtual void Pulse(); -
src/preferences/time/ZoneView.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Mike Berg <mike@berg-net.us> 7 7 * Julun <host.haiku@gmx.de> 8 * Hamish Morrison <hamish@lavabit.com> 8 9 */ 9 10 #ifndef ZONE_VIEW_H 10 11 #define ZONE_VIEW_H 11 12 12 13 14 #include <LayoutBuilder.h> 13 15 #include <TimeZone.h> 14 #include <View.h>15 16 16 17 17 18 class BButton; … … 24 25 class TTZDisplay; 25 26 26 27 27 class TimeZoneView : public B View {28 class TimeZoneView : public BGroupView { 28 29 public: 29 TimeZoneView( BRect frame);30 TimeZoneView(const char* name); 30 31 virtual ~TimeZoneView(); 31 32 32 33 virtual void AttachedToWindow(); -
src/preferences/time/AnalogClock.cpp
1 1 /* 2 * Copyright 2004-20 09, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 7 7 * Julun <host.haiku@gmx.de> 8 8 * Stephan Aßmus <superstippi@gmx.de> 9 9 * Clemens <mail@Clemens-Zeidler.de> 10 * Hamish Morrison <hamish@lavabit.com> 10 11 */ 11 12 12 13 #include "AnalogClock.h" … … 14 15 #include <math.h> 15 16 #include <stdio.h> 16 17 17 #include < Bitmap.h>18 #include <LayoutUtils.h> 18 19 #include <Message.h> 19 20 #include <Window.h> 20 21 … … 24 25 #define DRAG_DELTA_PHI 0.2 25 26 26 27 27 class OffscreenClock : public BView {28 public:29 OffscreenClock(BRect frame, const char* name,30 bool drawSecondHand = true);31 virtual ~OffscreenClock();32 33 void SetTime(int32 hour, int32 minute, int32 second);34 void GetTime(int32* hour, int32* minute, int32* second);35 bool IsDirty() const { return fDirty; }36 void DrawClock();37 38 bool InHourHand(BPoint point);39 bool InMinuteHand(BPoint point);40 41 void SetHourHand(BPoint point);42 void SetMinuteHand(BPoint point);43 44 void SetHourDragging(bool dragging);45 void SetMinuteDragging(bool dragging);46 47 private:48 float _GetPhi(BPoint point);49 bool _InHand(BPoint point, int32 ticks, float radius);50 void _DrawHands(float x, float y, float radius,51 rgb_color hourHourColor,52 rgb_color hourMinuteColor,53 rgb_color secondsColor, rgb_color knobColor);54 55 int32 fHours;56 int32 fMinutes;57 int32 fSeconds;58 bool fDirty;59 60 float fCenterX;61 float fCenterY;62 float fRadius;63 64 bool fHourDragging;65 bool fMinuteDragging;66 67 bool fDrawSecondHand;68 };69 70 71 OffscreenClock::OffscreenClock(BRect frame, const char* name,72 bool drawSecondHand)73 :74 BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),75 fHours(0),76 fMinutes(0),77 fSeconds(0),78 fDirty(true),79 fHourDragging(false),80 fMinuteDragging(false),81 fDrawSecondHand(drawSecondHand)82 {83 SetFlags(Flags() | B_SUBPIXEL_PRECISE);84 85 BRect bounds = Bounds();86 fCenterX = floorf((bounds.left + bounds.right) / 2 + 0.5) + 0.5;87 fCenterY = floorf((bounds.top + bounds.bottom) / 2 + 0.5) + 0.5;88 // + 0.5 is for the offset to pixel centers89 // (important when drawing with B_SUBPIXEL_PRECISE)90 91 fRadius = floorf((MIN(bounds.Width(), bounds.Height()) / 2.0)) - 2.5;92 fRadius -= 3;93 }94 95 96 OffscreenClock::~OffscreenClock()97 {98 }99 100 101 28 void 102 OffscreenClock::SetTime(int32 hour, int32 minute, int32second)29 TAnalogClock::GetTime(int32* hour, int32* minute, int32* second) 103 30 { 104 if (fHours == hour && fMinutes == minute && fSeconds == second)105 return;106 107 fHours = hour;108 fMinutes = minute;109 fSeconds = second;110 111 fDirty = true;112 }113 114 115 void116 OffscreenClock::GetTime(int32* hour, int32* minute, int32* second)117 {118 31 *hour = fHours; 119 32 *minute = fMinutes; 120 33 *second = fSeconds; … … 122 35 123 36 124 37 void 125 OffscreenClock::DrawClock()38 TAnalogClock::DrawClock() 126 39 { 127 40 if (!LockLooper()) 128 41 return; … … 132 45 rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR); 133 46 SetHighColor(background); 134 47 FillRect(bounds); 135 136 48 137 49 bounds.Set(fCenterX - fRadius, fCenterY - fRadius, 138 50 fCenterX + fRadius, fCenterY + fRadius); 139 51 … … 207 119 } 208 120 209 121 122 void 123 TAnalogClock::FrameResized(float, float) 124 { 125 BRect bounds = Bounds(); 126 127 // + 0.5 is for the offset to pixel centers 128 // (important when drawing with B_SUBPIXEL_PRECISE) 129 fCenterX = floorf((bounds.left + bounds.right) / 2 + 0.5) + 0.5; 130 fCenterY = floorf((bounds.top + bounds.bottom) / 2 + 0.5) + 0.5; 131 fRadius = floorf((MIN(bounds.Width(), bounds.Height()) / 2.0)) - 2.5; 132 fRadius -= 3; 133 } 134 135 136 BSize 137 TAnalogClock::MaxSize() 138 { 139 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), 140 BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); 141 } 142 143 144 BSize 145 TAnalogClock::MinSize() 146 { 147 return BSize(0, 0); 148 } 149 150 151 BSize 152 TAnalogClock::PreferredSize() 153 { 154 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), 155 BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); 156 } 157 158 210 159 bool 211 OffscreenClock::InHourHand(BPoint point)160 TAnalogClock::InHourHand(BPoint point) 212 161 { 213 162 int32 ticks = fHours; 214 163 if (ticks > 12) … … 222 171 223 172 224 173 bool 225 OffscreenClock::InMinuteHand(BPoint point)174 TAnalogClock::InMinuteHand(BPoint point) 226 175 { 227 176 return _InHand(point, fMinutes, fRadius * 0.9); 228 177 } 229 178 230 179 231 180 void 232 OffscreenClock::SetHourHand(BPoint point)181 TAnalogClock::SetHourHand(BPoint point) 233 182 { 234 183 point.x -= fCenterX; 235 184 point.y -= fCenterY; … … 247 196 248 197 249 198 void 250 OffscreenClock::SetMinuteHand(BPoint point)199 TAnalogClock::SetMinuteHand(BPoint point) 251 200 { 252 201 point.x -= fCenterX; 253 202 point.y -= fCenterY; … … 260 209 } 261 210 262 211 263 void264 OffscreenClock::SetHourDragging(bool dragging)265 {266 fHourDragging = dragging;267 fDirty = true;268 }269 270 271 void272 OffscreenClock::SetMinuteDragging(bool dragging)273 {274 fMinuteDragging = dragging;275 fDirty = true;276 }277 278 279 212 float 280 OffscreenClock::_GetPhi(BPoint point)213 TAnalogClock::_GetPhi(BPoint point) 281 214 { 282 215 if (point.x == 0 && point.y < 0) 283 216 return 2 * M_PI; … … 302 235 303 236 304 237 bool 305 OffscreenClock::_InHand(BPoint point, int32 ticks, float radius)238 TAnalogClock::_InHand(BPoint point, int32 ticks, float radius) 306 239 { 307 240 point.x -= fCenterX; 308 241 point.y -= fCenterY; … … 323 256 324 257 325 258 void 326 OffscreenClock::_DrawHands(float x, float y, float radius, 327 rgb_color hourColor, 328 rgb_color minuteColor, 329 rgb_color secondsColor, 330 rgb_color knobColor) 259 TAnalogClock::_DrawHands(float x, float y, float radius, 260 rgb_color hourColor, rgb_color minuteColor, 261 rgb_color secondsColor, rgb_color knobColor) 331 262 { 332 263 float offsetX; 333 264 float offsetY; … … 366 297 // #pragma mark - 367 298 368 299 369 TAnalogClock::TAnalogClock( BRect frame,const char* name,300 TAnalogClock::TAnalogClock(const char* name, 370 301 bool drawSecondHand, bool interactive) 371 302 : 372 BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW | B_DRAW_ON_CHILDREN), 373 fBitmap(NULL), 374 fClock(NULL), 303 BView(name, B_WILL_DRAW | B_DRAW_ON_CHILDREN | B_FRAME_EVENTS), 304 fHours(0), 305 fMinutes(0), 306 fSeconds(0), 307 fDirty(true), 308 fHourDragging(false), 309 fMinuteDragging(false), 375 310 fDrawSecondHand(drawSecondHand), 376 311 fInteractive(interactive), 377 fDraggingHourHand(false),378 fDraggingMinuteHand(false),379 312 fTimeChangeIsOngoing(false) 380 313 { 381 _InitView(frame);314 SetFlags(Flags() | B_SUBPIXEL_PRECISE); 382 315 } 383 316 384 317 385 318 TAnalogClock::~TAnalogClock() 386 319 { 387 delete fBitmap;388 320 } 389 321 390 322 391 323 void 392 TAnalogClock::_InitView(BRect rect)393 {394 fClock = new OffscreenClock(Bounds(), "offscreen", fDrawSecondHand);395 fBitmap = new BBitmap(Bounds(), B_RGB32, true);396 fBitmap->Lock();397 fBitmap->AddChild(fClock);398 fBitmap->Unlock();399 }400 401 402 void403 TAnalogClock::AttachedToWindow()404 {405 SetViewColor(B_TRANSPARENT_COLOR);406 }407 408 409 void410 324 TAnalogClock::MessageReceived(BMessage* message) 411 325 { 412 326 int32 change; … … 445 359 return; 446 360 } 447 361 448 fDraggingMinuteHand = fClock->InMinuteHand(point);449 if (fDraggingMinuteHand) {450 f Clock->SetMinuteDragging(true);362 if (InMinuteHand(point)) { 363 fMinuteDragging = true; 364 fDirty = true; 451 365 SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); 452 366 Invalidate(); 453 367 return; 454 368 } 455 fDraggingHourHand = fClock->InHourHand(point);456 if (fDraggingHourHand) {457 f Clock->SetHourDragging(true);369 if (InHourHand(point)) { 370 fHourDragging = true; 371 fDirty = true; 458 372 SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); 459 373 Invalidate(); 460 374 return; … … 470 384 return; 471 385 } 472 386 473 if (f DraggingHourHand || fDraggingMinuteHand) {387 if (fHourDragging || fMinuteDragging) { 474 388 int32 hour, minute, second; 475 fClock->GetTime(&hour, &minute, &second);389 GetTime(&hour, &minute, &second); 476 390 BMessage message(H_USER_CHANGE); 477 391 message.AddBool("time", true); 478 392 message.AddInt32("hour", hour); … … 480 394 Window()->PostMessage(&message); 481 395 fTimeChangeIsOngoing = true; 482 396 } 483 f DraggingHourHand= false;484 fD raggingMinuteHand = false;485 f Clock->SetMinuteDragging(false);486 f Clock->SetHourDragging(false);397 fHourDragging = false; 398 fDirty = true; 399 fMinuteDragging = false; 400 fDirty = true; 487 401 } 488 402 489 403 … … 495 409 return; 496 410 } 497 411 498 if (f DraggingMinuteHand)499 fClock->SetMinuteHand(point);500 if (f DraggingHourHand)501 fClock->SetHourHand(point);412 if (fMinuteDragging) 413 SetMinuteHand(point); 414 if (fHourDragging) 415 SetHourHand(point); 502 416 503 417 Invalidate(); 504 418 } … … 507 421 void 508 422 TAnalogClock::Draw(BRect /*updateRect*/) 509 423 { 510 if (fBitmap) { 511 if (fClock->IsDirty()) 512 fClock->DrawClock(); 513 DrawBitmap(fBitmap, BPoint(0, 0)); 514 } 424 if (fDirty) 425 DrawClock(); 515 426 } 516 427 517 428 … … 519 430 TAnalogClock::SetTime(int32 hour, int32 minute, int32 second) 520 431 { 521 432 // don't set the time if the hands are in a drag action 522 if (f DraggingHourHand || fDraggingMinuteHand|| fTimeChangeIsOngoing)433 if (fHourDragging || fMinuteDragging || fTimeChangeIsOngoing) 523 434 return; 435 436 if (fHours == hour && fMinutes == minute && fSeconds == second) 437 return; 524 438 525 if (fClock) 526 fClock->SetTime(hour, minute, second); 439 fHours = hour; 440 fMinutes = minute; 441 fSeconds = second; 527 442 443 fDirty = true; 444 528 445 BWindow* window = Window(); 529 446 if (window && window->Lock()) { 530 447 Invalidate(); … … 533 450 } 534 451 535 452 453 bool 454 TAnalogClock::IsChangingTime() 455 { 456 return fTimeChangeIsOngoing; 457 } 458 459 536 460 void 537 461 TAnalogClock::ChangeTimeFinished() 538 462 { -
src/preferences/time/SectionEdit.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Mike Berg <mike@berg-net.us> 7 7 * Julun <host.haiku@gmx.de> 8 * 8 * Hamish Morrison <hamish@lavabit.com> 9 9 */ 10 10 #ifndef _SECTION_EDIT_H 11 11 #define _SECTION_EDIT_H … … 18 18 class BList; 19 19 20 20 21 class TSection {22 public:23 TSection(BRect frame);24 25 BRect Bounds() const;26 void SetFrame(BRect frame);27 BRect Frame() const;28 29 private:30 BRect fFrame;31 };32 33 34 21 class TSectionEdit: public BControl { 35 22 public: 36 TSectionEdit( BRect frame,const char* name,23 TSectionEdit(const char* name, 37 24 uint32 sections); 38 25 virtual ~TSectionEdit(); 39 26 … … 43 30 virtual void MakeFocus(bool focused = true); 44 31 virtual void KeyDown(const char* bytes, int32 numBytes); 45 32 33 BSize MaxSize(); 34 BSize MinSize(); 35 BSize PreferredSize(); 36 46 37 uint32 CountSections() const; 47 38 int32 FocusIndex() const; 48 39 BRect SectionArea() const; 49 40 50 41 protected: 51 virtual void InitView();52 53 // hooks54 42 virtual void DrawBorder(const BRect& updateRect); 55 virtual void DrawSection(uint32 index, bool isFocus) {} 56 virtual void DrawSeparator(uint32 index) {} 43 virtual void DrawSection(uint32 index, BRect bounds, 44 bool isFocus) {} 45 virtual void DrawSeparator(uint32 index, BRect bounds) {} 57 46 47 BRect FrameForSection(uint32 index); 48 BRect FrameForSeparator(uint32 index); 49 58 50 virtual void SectionFocus(uint32 index) {} 59 51 virtual void SectionChange(uint32 index, uint32 value) {} 60 52 virtual void SetSections(BRect area) {} 61 virtual float SeparatorWidth() const; 62 53 54 virtual float SeparatorWidth() = 0; 55 virtual float MinSectionWidth() = 0; 56 virtual float PreferredHeight() = 0; 57 63 58 virtual void DoUpPress() {} 64 59 virtual void DoDownPress() {} 65 60 66 61 virtual void DispatchMessage(); 67 62 virtual void BuildDispatch(BMessage* message) = 0; 68 63 69 protected: 70 BList* fSectionList; 71 64 protected: 72 65 BRect fUpRect; 73 66 BRect fDownRect; 74 BRect fSectionArea;75 67 76 68 int32 fFocus; 77 69 uint32 fSectionCount; -
src/preferences/time/TZDisplay.cpp
1 1 /* 2 * Copyright 2004-20 07, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Andrew McCall <mccall@@digitalparadise.co.uk> 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 * 9 * Hamish Morrison <hamish@lavabit.com> 10 10 */ 11 11 12 #include "TZDisplay.h" 13 12 14 #include <stdio.h> 13 15 14 #include "TZDisplay.h"16 #include <LayoutUtils.h> 15 17 16 18 17 19 namespace { … … 26 28 } 27 29 28 30 29 TTZDisplay::TTZDisplay( BRect frame,const char* name, const char* label)30 : BView( frame, name, B_FOLLOW_NONE, B_WILL_DRAW),31 TTZDisplay::TTZDisplay(const char* name, const char* label) 32 : BView(name, B_WILL_DRAW), 31 33 fLabel(label), 32 34 fText(""), 33 35 fTime("") … … 121 123 Invalidate(); 122 124 } 123 125 126 127 BSize 128 TTZDisplay::MaxSize() 129 { 130 BSize size = _CalcPrefSize(); 131 size.width = B_SIZE_UNLIMITED; 132 133 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), 134 size); 135 } 136 137 138 BSize 139 TTZDisplay::MinSize() 140 { 141 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), 142 _CalcPrefSize()); 143 } 144 145 146 BSize 147 TTZDisplay::PreferredSize() 148 { 149 return MinSize(); 150 } 151 152 153 BSize 154 TTZDisplay::_CalcPrefSize() 155 { 156 font_height fontHeight; 157 GetFontHeight(&fontHeight); 158 159 BSize size; 160 size.height = 2 * ceilf(fontHeight.ascent + fontHeight.descent); 161 size.width =StringWidth( 162 " "); 163 return size; 164 } 165 -
src/preferences/time/TimeMessages.h
46 46 // change time finished 47 47 const uint32 kChangeTimeFinished = 'tcfi'; 48 48 49 // network time messages 50 const uint32 kMsgNetworkTimeSettings = 'ntst'; 51 const uint32 kMsgDefaultServer = 'dfsr'; 52 const uint32 kMsgEditServerList = 'esrv'; 53 const uint32 kMsgTryAllServers = 'tras'; 54 const uint32 kMsgSynchronizeAtBoot = 'synb'; 55 const uint32 kMsgSynchronize = 'sync'; 56 const uint32 kMsgStopSynchronization = 'stps'; 57 const uint32 kMsgStatusUpdate = 'stup'; 49 58 59 // network time edit window messages 60 const uint32 kMsgUpdateSettings = 'upse'; 61 const uint32 kMsgSettingsUpdated = 'seUp'; 62 const uint32 kMsgServersEdited = 'sedt'; 63 const uint32 kMsgResetServerList = 'rtsl'; 64 const uint32 kMsgEditServerListWindowClosed = 'eswc'; 65 66 50 67 #endif // _TIME_MESSAGES_H 51 68 -
src/preferences/time/TimeWindow.h
5 5 * Authors: 6 6 * Andrew McCall <mccall@@digitalparadise.co.uk> 7 7 * Julun <host.haiku@gmx.de> 8 *9 8 */ 10 9 #ifndef _TIME_WINDOW_H 11 10 #define _TIME_WINDOW_H … … 18 17 class DateTimeView; 19 18 class TTimeBaseView; 20 19 class TimeZoneView; 20 class NetworkTimeView; 21 21 22 22 23 23 class TTimeWindow : public BWindow { … … 39 39 TTimeBaseView* fBaseView; 40 40 DateTimeView* fDateTimeView; 41 41 TimeZoneView* fTimeZoneView; 42 NetworkTimeView* fNetworkTimeView; 42 43 BButton* fRevertButton; 43 44 }; 44 45 -
src/preferences/time/DateTimeView.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 9 * Philippe Saint-Pierre <stpere@gmail.com> 10 * Hamish Morrison <hamish@lavabit.com> 10 11 */ 11 12 #ifndef _DATE_TIME_VIEW_H 12 13 #define _DATE_TIME_VIEW_H 13 14 14 15 15 #include < View.h>16 #include <LayoutBuilder.h> 16 17 17 18 18 19 class TDateEdit; … … 27 28 using BPrivate::BCalendarView; 28 29 29 30 30 class DateTimeView : public B View {31 class DateTimeView : public BGroupView { 31 32 public: 32 DateTimeView( BRect frame);33 DateTimeView(const char* name); 33 34 virtual ~DateTimeView(); 34 35 35 36 virtual void AttachedToWindow(); -
src/kits/shared/CalendarView.cpp
11 11 12 12 #include <stdlib.h> 13 13 14 #include <LayoutUtils.h> 14 15 #include <Window.h> 15 16 16 17 … … 72 73 } 73 74 74 75 76 BCalendarView::BCalendarView(const char* name, uint32 flags) 77 : 78 BView(name, flags), 79 BInvoker(), 80 fSelectionMessage(NULL), 81 fDay(0), 82 fYear(0), 83 fMonth(0), 84 fFocusChanged(false), 85 fSelectionChanged(false), 86 fWeekStart(B_WEEK_START_SUNDAY), 87 fDayNameHeaderVisible(true), 88 fWeekNumberHeaderVisible(true) 89 { 90 _InitObject(); 91 } 92 93 75 94 BCalendarView::~BCalendarView() 76 95 { 77 96 SetSelectionMessage(NULL); … … 559 578 } 560 579 561 580 581 BSize 582 BCalendarView::MaxSize() 583 { 584 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), 585 BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); 586 } 587 588 589 BSize 590 BCalendarView::MinSize() 591 { 592 float width, height; 593 _GetPreferredSize(&width, &height); 594 return BLayoutUtils::ComposeSize(ExplicitMinSize(), 595 BSize(width, height)); 596 } 597 598 599 BSize 600 BCalendarView::PreferredSize() 601 { 602 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), 603 MinSize()); 604 } 605 606 562 607 int32 563 608 BCalendarView::Day() const 564 609 { -
headers/private/shared/CalendarView.h
36 36 BCalendarView(BRect frame, const char *name, week_start start, 37 37 uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP, 38 38 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); 39 40 BCalendarView(const char* name, 41 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); 39 42 40 43 virtual ~BCalendarView(); 41 44 … … 88 91 89 92 virtual void ResizeToPreferred(); 90 93 virtual void GetPreferredSize(float *width, float *height); 94 95 virtual BSize MaxSize(); 96 virtual BSize MinSize(); 97 virtual BSize PreferredSize(); 91 98 92 99 int32 Day() const; 93 100 int32 Year() const;