Fix Deskbar clock show/hide when Deskbar is hidden.

Bug #9469 happens because I set the showClock checkbox or not based on whether
or not the clock is currently hidden. This works most of the time, but if
Deskbar is hidden the clock is also considered to be hidden and that isn't what
I want in this case.

The solution is to override BView's Show(), Hide(), and IsHidden() methods
in TimeView to ignore whether or not the window is hidden when considering if
the clock is hidden.

The commit also deletes some no-longer-used private member variables of
TimeView.

Fixes #9469
This commit is contained in:
John Scipione
2013-02-23 14:41:54 -05:00
parent a2d1b65a85
commit ca00f398da
2 changed files with 33 additions and 6 deletions
+27 -1
View File
@@ -37,6 +37,8 @@ All rights reserved.
#include "TimeView.h" #include "TimeView.h"
#include <string.h> #include <string.h>
#include <stdint.h>
// for INT16_MIN and INT16_MAX
#include <Application.h> #include <Application.h>
#include <Catalog.h> #include <Catalog.h>
@@ -69,6 +71,7 @@ TTimeView::TTimeView(float maxWidth, float height)
fMaxWidth(maxWidth), fMaxWidth(maxWidth),
fHeight(height), fHeight(height),
fOrientation(true), fOrientation(true),
fShowLevel(0),
fShowSeconds(false), fShowSeconds(false),
fShowDayOfWeek(false), fShowDayOfWeek(false),
fShowTimeZone(false) fShowTimeZone(false)
@@ -116,10 +119,11 @@ status_t
TTimeView::Archive(BMessage* data, bool deep) const TTimeView::Archive(BMessage* data, bool deep) const
{ {
BView::Archive(data, deep); BView::Archive(data, deep);
data->AddBool("orientation", fOrientation);
data->AddInt16("showLevel", fShowLevel);
data->AddBool("showSeconds", fShowSeconds); data->AddBool("showSeconds", fShowSeconds);
data->AddBool("showDayOfWeek", fShowDayOfWeek); data->AddBool("showDayOfWeek", fShowDayOfWeek);
data->AddBool("showTimeZone", fShowTimeZone); data->AddBool("showTimeZone", fShowTimeZone);
data->AddBool("orientation", fOrientation);
data->AddInt32("deskbar:private_align", B_ALIGN_RIGHT); data->AddInt32("deskbar:private_align", B_ALIGN_RIGHT);
return B_OK; return B_OK;
@@ -183,6 +187,17 @@ TTimeView::GetPreferredSize(float* width, float* height)
} }
void
TTimeView::Hide()
{
// Prevent overflow
if (fShowLevel < INT16_MAX)
++fShowLevel;
BView::Hide();
}
void void
TTimeView::MessageReceived(BMessage* message) TTimeView::MessageReceived(BMessage* message)
{ {
@@ -292,6 +307,17 @@ TTimeView::ResizeToPreferred()
} }
void
TTimeView::Show()
{
// Prevent underflow
if (fShowLevel > INT16_MIN)
--fShowLevel;
BView::Show();
}
// # pragma mark - Public methods // # pragma mark - Public methods
+6 -5
View File
@@ -88,10 +88,13 @@ public:
void Draw(BRect update); void Draw(BRect update);
void FrameMoved(BPoint); void FrameMoved(BPoint);
void GetPreferredSize(float* width, float* height); void GetPreferredSize(float* width, float* height);
void Hide();
bool IsHidden() const { return fShowLevel > 0; };
void MessageReceived(BMessage*); void MessageReceived(BMessage*);
void MouseDown(BPoint where); void MouseDown(BPoint where);
void Pulse(); void Pulse();
void ResizeToPreferred(); void ResizeToPreferred();
void Show();
bool Orientation() const; bool Orientation() const;
void SetOrientation(bool o); void SetOrientation(bool o);
@@ -133,16 +136,14 @@ private:
float fMaxWidth; float fMaxWidth;
float fHeight; float fHeight;
bool fOrientation; // vertical = true bool fOrientation;
// vertical = true
int16 fShowLevel;
bool fOverrideLocale;
bool fUse24HourClock;
bool fShowSeconds; bool fShowSeconds;
bool fShowDayOfWeek; bool fShowDayOfWeek;
bool fShowTimeZone; bool fShowTimeZone;
BString fTimeFormat;
BPoint fTimeLocation; BPoint fTimeLocation;
BPoint fDateLocation; BPoint fDateLocation;