Ticket #7726: 0001-Create-TimeZoneListView-class-and-move-GetToolTipAt-.patch
File 0001-Create-TimeZoneListView-class-and-move-GetToolTipAt-.patch, 7.4 KB (added by , 11 years ago) |
---|
-
src/preferences/time/Jamfile
From 85b404a74715a9c358c32839466e3891b5d57e76 Mon Sep 17 00:00:00 2001 From: Ziusudra <ziusudra@gmail.com> Date: Sun, 25 Nov 2012 21:05:16 -0700 Subject: [PATCH] Create TimeZoneListView class and move GetToolTipAt into it, fixes #7726 --- src/preferences/time/Jamfile | 2 + src/preferences/time/TimeZoneListView.cpp | 74 +++++++++++++++++++++++++++++ src/preferences/time/TimeZoneListView.h | 31 ++++++++++++ src/preferences/time/ZoneView.cpp | 44 ++--------------- src/preferences/time/ZoneView.h | 9 ++-- 5 files changed, 113 insertions(+), 47 deletions(-) create mode 100644 src/preferences/time/TimeZoneListView.cpp create mode 100644 src/preferences/time/TimeZoneListView.h diff --git a/src/preferences/time/Jamfile b/src/preferences/time/Jamfile index 43e27b0..3ed6e20 100644
a b local sources = 18 18 TimeSettings.cpp 19 19 TimeWindow.cpp 20 20 TimeZoneListItem.cpp 21 TimeZoneListView.cpp 21 22 TZDisplay.cpp 22 23 ZoneView.cpp 23 24 ; … … DoCatalogs Time : 42 43 ntp.cpp 43 44 Time.cpp 44 45 TimeWindow.cpp 46 TimeZoneListView.cpp 45 47 ZoneView.cpp 46 48 ; -
new file src/preferences/time/TimeZoneListView.cpp
diff --git a/src/preferences/time/TimeZoneListView.cpp b/src/preferences/time/TimeZoneListView.cpp new file mode 100644 index 0000000..87a8519
- + 1 /* 2 * Copyright 2012, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Sean Bailey <ziusudra@gmail.com> 7 */ 8 9 10 #include "TimeZoneListView.h" 11 12 #include <new> 13 14 #include <Catalog.h> 15 #include <Locale.h> 16 #include <String.h> 17 #include <TimeZone.h> 18 #include <ToolTip.h> 19 20 #include "TimeZoneListItem.h" 21 22 23 #undef B_TRANSLATION_CONTEXT 24 #define B_TRANSLATION_CONTEXT "Time" 25 26 27 TimeZoneListView::TimeZoneListView(void) 28 : 29 BOutlineListView("cityList", B_SINGLE_SELECTION_LIST), 30 fToolTip(NULL) 31 { 32 } 33 34 35 TimeZoneListView::~TimeZoneListView() 36 { 37 if (fToolTip != NULL) 38 fToolTip->ReleaseReference(); 39 } 40 41 42 bool 43 TimeZoneListView::GetToolTipAt(BPoint point, BToolTip** _tip) 44 { 45 TimeZoneListItem* item = static_cast<TimeZoneListItem*>( 46 this->ItemAt(this->IndexOf(point))); 47 if (item == NULL || !item->HasTimeZone()) 48 return false; 49 50 BString nowInTimeZone; 51 time_t now = time(NULL); 52 BLocale::Default()->FormatTime(&nowInTimeZone, now, B_SHORT_TIME_FORMAT, 53 &item->TimeZone()); 54 55 BString dateInTimeZone; 56 BLocale::Default()->FormatDate(&dateInTimeZone, now, B_SHORT_DATE_FORMAT, 57 &item->TimeZone()); 58 59 BString toolTip = item->Text(); 60 toolTip << '\n' << item->TimeZone().ShortName() << " / " 61 << item->TimeZone().ShortDaylightSavingName() 62 << B_TRANSLATE("\nNow: ") << nowInTimeZone 63 << " (" << dateInTimeZone << ')'; 64 65 if (fToolTip != NULL) 66 fToolTip->ReleaseReference(); 67 fToolTip = new (std::nothrow) BTextToolTip(toolTip.String()); 68 if (fToolTip == NULL) 69 return false; 70 71 *_tip = fToolTip; 72 73 return true; 74 } -
new file src/preferences/time/TimeZoneListView.h
diff --git a/src/preferences/time/TimeZoneListView.h b/src/preferences/time/TimeZoneListView.h new file mode 100644 index 0000000..0b9fd48
- + 1 /* 2 * Copyright 2012, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Sean Bailey <ziusudra@gmail.com> 7 */ 8 #ifndef _TIME_ZONE_LIST_VIEW_H 9 #define _TIME_ZONE_LIST_VIEW_H 10 11 12 #include <OutlineListView.h> 13 14 15 class BTextToolTip; 16 17 18 class TimeZoneListView : public BOutlineListView { 19 public: 20 TimeZoneListView(void); 21 ~TimeZoneListView(); 22 23 protected: 24 virtual bool GetToolTipAt(BPoint point, BToolTip** _tip); 25 26 private: 27 BTextToolTip* fToolTip; 28 }; 29 30 31 #endif // _TIME_ZONE_LIST_VIEW_H -
src/preferences/time/ZoneView.cpp
diff --git a/src/preferences/time/ZoneView.cpp b/src/preferences/time/ZoneView.cpp index c773de5..08f5332 100644
a b 1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2012, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 42 42 #include <String.h> 43 43 #include <StringView.h> 44 44 #include <TimeZone.h> 45 #include <ToolTip.h>46 45 #include <View.h> 47 46 #include <Window.h> 48 47 … … 52 51 53 52 #include "TimeMessages.h" 54 53 #include "TimeZoneListItem.h" 54 #include "TimeZoneListView.h" 55 55 #include "TZDisplay.h" 56 56 57 57 … … TimeZoneView::TimeZoneView(const char* name) 84 84 : 85 85 BGroupView(name, B_HORIZONTAL, B_USE_DEFAULT_SPACING), 86 86 fGmtTime(NULL), 87 fToolTip(NULL),88 87 fUseGmtTime(false), 89 88 fCurrentZoneItem(NULL), 90 89 fOldZoneItem(NULL), … … TimeZoneView::CheckCanRevert() 107 106 108 107 TimeZoneView::~TimeZoneView() 109 108 { 110 if (fToolTip != NULL)111 fToolTip->ReleaseReference();112 109 _WriteRTCSettings(); 113 110 } 114 111 … … TimeZoneView::MessageReceived(BMessage* message) 189 186 } 190 187 191 188 192 bool193 TimeZoneView::GetToolTipAt(BPoint point, BToolTip** _tip)194 {195 TimeZoneListItem* item = static_cast<TimeZoneListItem*>(196 fZoneList->ItemAt(fZoneList->IndexOf(point)));197 if (item == NULL || !item->HasTimeZone())198 return false;199 200 BString nowInTimeZone;201 time_t now = time(NULL);202 BLocale::Default()->FormatTime(&nowInTimeZone, now, B_SHORT_TIME_FORMAT,203 &item->TimeZone());204 205 BString dateInTimeZone;206 BLocale::Default()->FormatDate(&dateInTimeZone, now, B_SHORT_DATE_FORMAT,207 &item->TimeZone());208 209 BString toolTip = item->Text();210 toolTip << '\n' << item->TimeZone().ShortName() << " / "211 << item->TimeZone().ShortDaylightSavingName()212 << B_TRANSLATE("\nNow: ") << nowInTimeZone213 << " (" << dateInTimeZone << ')';214 215 if (fToolTip != NULL)216 fToolTip->ReleaseReference();217 fToolTip = new (std::nothrow) BTextToolTip(toolTip.String());218 if (fToolTip == NULL)219 return false;220 221 *_tip = fToolTip;222 223 return true;224 }225 226 227 189 void 228 190 TimeZoneView::_UpdateDateTime(BMessage* message) 229 191 { … … TimeZoneView::_UpdateDateTime(BMessage* message) 243 205 void 244 206 TimeZoneView::_InitView() 245 207 { 246 fZoneList = new BOutlineListView("cityList", B_SINGLE_SELECTION_LIST);208 fZoneList = new TimeZoneListView(); 247 209 fZoneList->SetSelectionMessage(new BMessage(H_CITY_CHANGED)); 248 210 fZoneList->SetInvocationMessage(new BMessage(H_SET_TIME_ZONE)); 249 211 _BuildZoneMenu(); -
src/preferences/time/ZoneView.h
diff --git a/src/preferences/time/ZoneView.h b/src/preferences/time/ZoneView.h index b0ac9b4..9766263 100644
a b 1 1 /* 2 * Copyright 2004-201 1, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2012, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … class BMessage; 20 20 class BOutlineListView; 21 21 class BPopUpMenu; 22 22 class BRadioButton; 23 class BTextToolTip;24 23 class BTimeZone; 25 24 class TimeZoneListItem; 25 class TimeZoneListView; 26 26 class TTZDisplay; 27 27 28 28 … … public: 36 36 bool CheckCanRevert(); 37 37 38 38 protected: 39 virtual bool GetToolTipAt(BPoint point, BToolTip** _tip);40 39 virtual void DoLayout(); 41 40 42 41 private: … … private: 58 57 59 58 void _Revert(); 60 59 61 BOutlineListView* fZoneList;60 TimeZoneListView* fZoneList; 62 61 BButton* fSetZone; 63 62 TTZDisplay* fCurrent; 64 63 TTZDisplay* fPreview; 65 64 BRadioButton* fLocalTime; 66 65 BRadioButton* fGmtTime; 67 66 68 BTextToolTip* fToolTip;69 70 67 int32 fLastUpdateMinute; 71 68 bool fUseGmtTime; 72 69 bool fOldUseGmtTime;