Create TimeZoneListView class and move GetToolTipAt into it, fixes #7726

Signed-off-by: Matt Madia <mattmadia@gmail.com>
This commit is contained in:
Ziusudra 2012-11-25 21:05:16 -07:00 committed by Matt Madia
parent be7b42ea99
commit f0e995c8d4
5 changed files with 113 additions and 47 deletions

View File

@ -19,6 +19,7 @@ local sources =
TimeSettings.cpp
TimeWindow.cpp
TimeZoneListItem.cpp
TimeZoneListView.cpp
TZDisplay.cpp
ZoneView.cpp
;
@ -44,5 +45,6 @@ DoCatalogs Time :
ntp.cpp
Time.cpp
TimeWindow.cpp
TimeZoneListView.cpp
ZoneView.cpp
;

View File

@ -0,0 +1,74 @@
/*
* Copyright 2012, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Sean Bailey <ziusudra@gmail.com>
*/
#include "TimeZoneListView.h"
#include <new>
#include <Catalog.h>
#include <Locale.h>
#include <String.h>
#include <TimeZone.h>
#include <ToolTip.h>
#include "TimeZoneListItem.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Time"
TimeZoneListView::TimeZoneListView(void)
:
BOutlineListView("cityList", B_SINGLE_SELECTION_LIST),
fToolTip(NULL)
{
}
TimeZoneListView::~TimeZoneListView()
{
if (fToolTip != NULL)
fToolTip->ReleaseReference();
}
bool
TimeZoneListView::GetToolTipAt(BPoint point, BToolTip** _tip)
{
TimeZoneListItem* item = static_cast<TimeZoneListItem*>(
this->ItemAt(this->IndexOf(point)));
if (item == NULL || !item->HasTimeZone())
return false;
BString nowInTimeZone;
time_t now = time(NULL);
BLocale::Default()->FormatTime(&nowInTimeZone, now, B_SHORT_TIME_FORMAT,
&item->TimeZone());
BString dateInTimeZone;
BLocale::Default()->FormatDate(&dateInTimeZone, now, B_SHORT_DATE_FORMAT,
&item->TimeZone());
BString toolTip = item->Text();
toolTip << '\n' << item->TimeZone().ShortName() << " / "
<< item->TimeZone().ShortDaylightSavingName()
<< B_TRANSLATE("\nNow: ") << nowInTimeZone
<< " (" << dateInTimeZone << ')';
if (fToolTip != NULL)
fToolTip->ReleaseReference();
fToolTip = new (std::nothrow) BTextToolTip(toolTip.String());
if (fToolTip == NULL)
return false;
*_tip = fToolTip;
return true;
}

View File

@ -0,0 +1,31 @@
/*
* Copyright 2012, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Sean Bailey <ziusudra@gmail.com>
*/
#ifndef _TIME_ZONE_LIST_VIEW_H
#define _TIME_ZONE_LIST_VIEW_H
#include <OutlineListView.h>
class BTextToolTip;
class TimeZoneListView : public BOutlineListView {
public:
TimeZoneListView(void);
~TimeZoneListView();
protected:
virtual bool GetToolTipAt(BPoint point, BToolTip** _tip);
private:
BTextToolTip* fToolTip;
};
#endif // _TIME_ZONE_LIST_VIEW_H

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
* Copyright 2004-2012, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -42,7 +42,6 @@
#include <String.h>
#include <StringView.h>
#include <TimeZone.h>
#include <ToolTip.h>
#include <View.h>
#include <Window.h>
@ -52,6 +51,7 @@
#include "TimeMessages.h"
#include "TimeZoneListItem.h"
#include "TimeZoneListView.h"
#include "TZDisplay.h"
@ -84,7 +84,6 @@ TimeZoneView::TimeZoneView(const char* name)
:
BGroupView(name, B_HORIZONTAL, B_USE_DEFAULT_SPACING),
fGmtTime(NULL),
fToolTip(NULL),
fUseGmtTime(false),
fCurrentZoneItem(NULL),
fOldZoneItem(NULL),
@ -107,8 +106,6 @@ TimeZoneView::CheckCanRevert()
TimeZoneView::~TimeZoneView()
{
if (fToolTip != NULL)
fToolTip->ReleaseReference();
_WriteRTCSettings();
}
@ -189,41 +186,6 @@ TimeZoneView::MessageReceived(BMessage* message)
}
bool
TimeZoneView::GetToolTipAt(BPoint point, BToolTip** _tip)
{
TimeZoneListItem* item = static_cast<TimeZoneListItem*>(
fZoneList->ItemAt(fZoneList->IndexOf(point)));
if (item == NULL || !item->HasTimeZone())
return false;
BString nowInTimeZone;
time_t now = time(NULL);
BLocale::Default()->FormatTime(&nowInTimeZone, now, B_SHORT_TIME_FORMAT,
&item->TimeZone());
BString dateInTimeZone;
BLocale::Default()->FormatDate(&dateInTimeZone, now, B_SHORT_DATE_FORMAT,
&item->TimeZone());
BString toolTip = item->Text();
toolTip << '\n' << item->TimeZone().ShortName() << " / "
<< item->TimeZone().ShortDaylightSavingName()
<< B_TRANSLATE("\nNow: ") << nowInTimeZone
<< " (" << dateInTimeZone << ')';
if (fToolTip != NULL)
fToolTip->ReleaseReference();
fToolTip = new (std::nothrow) BTextToolTip(toolTip.String());
if (fToolTip == NULL)
return false;
*_tip = fToolTip;
return true;
}
void
TimeZoneView::_UpdateDateTime(BMessage* message)
{
@ -243,7 +205,7 @@ TimeZoneView::_UpdateDateTime(BMessage* message)
void
TimeZoneView::_InitView()
{
fZoneList = new BOutlineListView("cityList", B_SINGLE_SELECTION_LIST);
fZoneList = new TimeZoneListView();
fZoneList->SetSelectionMessage(new BMessage(H_CITY_CHANGED));
fZoneList->SetInvocationMessage(new BMessage(H_SET_TIME_ZONE));
_BuildZoneMenu();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
* Copyright 2004-2012, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -20,9 +20,9 @@ class BMessage;
class BOutlineListView;
class BPopUpMenu;
class BRadioButton;
class BTextToolTip;
class BTimeZone;
class TimeZoneListItem;
class TimeZoneListView;
class TTZDisplay;
@ -36,7 +36,6 @@ public:
bool CheckCanRevert();
protected:
virtual bool GetToolTipAt(BPoint point, BToolTip** _tip);
virtual void DoLayout();
private:
@ -58,15 +57,13 @@ private:
void _Revert();
BOutlineListView* fZoneList;
TimeZoneListView* fZoneList;
BButton* fSetZone;
TTZDisplay* fCurrent;
TTZDisplay* fPreview;
BRadioButton* fLocalTime;
BRadioButton* fGmtTime;
BTextToolTip* fToolTip;
int32 fLastUpdateMinute;
bool fUseGmtTime;
bool fOldUseGmtTime;