Ticket #7726: 0001-Create-TimeZoneListView-class-and-move-GetToolTipAt-.patch

File 0001-Create-TimeZoneListView-class-and-move-GetToolTipAt-.patch, 7.4 KB (added by Ziusudra, 11 years ago)

This patch creates a TimeZoneListView and moves the tooltip code from ZoneView into it. Rebased to hrev44901

  • 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 =  
    1818    TimeSettings.cpp
    1919    TimeWindow.cpp
    2020    TimeZoneListItem.cpp
     21    TimeZoneListView.cpp
    2122    TZDisplay.cpp
    2223    ZoneView.cpp
    2324    ;
    DoCatalogs Time :  
    4243    ntp.cpp
    4344    Time.cpp
    4445    TimeWindow.cpp
     46    TimeZoneListView.cpp
    4547    ZoneView.cpp
    4648    ;
  • 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
     27TimeZoneListView::TimeZoneListView(void)
     28    :
     29    BOutlineListView("cityList", B_SINGLE_SELECTION_LIST),
     30    fToolTip(NULL)
     31{
     32}
     33
     34
     35TimeZoneListView::~TimeZoneListView()
     36{
     37    if (fToolTip != NULL)
     38        fToolTip->ReleaseReference();
     39}
     40
     41
     42bool
     43TimeZoneListView::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
     15class BTextToolTip;
     16
     17
     18class TimeZoneListView : public BOutlineListView {
     19public:
     20                                TimeZoneListView(void);
     21                                ~TimeZoneListView();
     22
     23protected:
     24    virtual bool                GetToolTipAt(BPoint point, BToolTip** _tip);
     25
     26private:
     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  
    11/*
    2  * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2012, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
     
    4242#include <String.h>
    4343#include <StringView.h>
    4444#include <TimeZone.h>
    45 #include <ToolTip.h>
    4645#include <View.h>
    4746#include <Window.h>
    4847
     
    5251
    5352#include "TimeMessages.h"
    5453#include "TimeZoneListItem.h"
     54#include "TimeZoneListView.h"
    5555#include "TZDisplay.h"
    5656
    5757
    TimeZoneView::TimeZoneView(const char* name)  
    8484    :
    8585    BGroupView(name, B_HORIZONTAL, B_USE_DEFAULT_SPACING),
    8686    fGmtTime(NULL),
    87     fToolTip(NULL),
    8887    fUseGmtTime(false),
    8988    fCurrentZoneItem(NULL),
    9089    fOldZoneItem(NULL),
    TimeZoneView::CheckCanRevert()  
    107106
    108107TimeZoneView::~TimeZoneView()
    109108{
    110     if (fToolTip != NULL)
    111         fToolTip->ReleaseReference();
    112109    _WriteRTCSettings();
    113110}
    114111
    TimeZoneView::MessageReceived(BMessage* message)  
    189186}
    190187
    191188
    192 bool
    193 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: ") << nowInTimeZone
    213             << " (" << 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 
    227189void
    228190TimeZoneView::_UpdateDateTime(BMessage* message)
    229191{
    TimeZoneView::_UpdateDateTime(BMessage* message)  
    243205void
    244206TimeZoneView::_InitView()
    245207{
    246     fZoneList = new BOutlineListView("cityList", B_SINGLE_SELECTION_LIST);
     208    fZoneList = new TimeZoneListView();
    247209    fZoneList->SetSelectionMessage(new BMessage(H_CITY_CHANGED));
    248210    fZoneList->SetInvocationMessage(new BMessage(H_SET_TIME_ZONE));
    249211    _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  
    11/*
    2  * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2004-2012, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    class BMessage;  
    2020class BOutlineListView;
    2121class BPopUpMenu;
    2222class BRadioButton;
    23 class BTextToolTip;
    2423class BTimeZone;
    2524class TimeZoneListItem;
     25class TimeZoneListView;
    2626class TTZDisplay;
    2727
    2828
    public:  
    3636            bool                CheckCanRevert();
    3737
    3838protected:
    39     virtual bool                GetToolTipAt(BPoint point, BToolTip** _tip);
    4039    virtual void                DoLayout();
    4140
    4241private:
    private:  
    5857
    5958            void                _Revert();
    6059
    61             BOutlineListView*   fZoneList;
     60            TimeZoneListView*   fZoneList;
    6261            BButton*            fSetZone;
    6362            TTZDisplay*         fCurrent;
    6463            TTZDisplay*         fPreview;
    6564            BRadioButton*       fLocalTime;
    6665            BRadioButton*       fGmtTime;
    6766
    68             BTextToolTip*       fToolTip;
    69 
    7067            int32               fLastUpdateMinute;
    7168            bool                fUseGmtTime;
    7269            bool                fOldUseGmtTime;