BDeskbar & Deskbar: export window bool settings to BDeskbar

Add methods to get and set "Always on top", "Auto raise", and "auto hide"
which are all booleans which control aspects of the Deskbar window to
BDeskbar.

Set the bool to the default value initially. Check if sending the
message succeeds, if so check the reply which also fills out the bool.
Don't check to see if reply succeeded because the bool will only be
overwritten if it did.

Follow the BDeskbar convention Is...() for getter, Set...() for setter
e.g IsAlwaysOnTop() is the getter, SetAlwaysOnTop() is the setter.

Define new message constants to call the newly created methods.
Follow BDeskbar convention: 'gtla' is used for getter, 'stla' for setter.
g/s for getter/setter, tla is an all-lowercase code unique to each
getter/setter pair.

Copy/paste these message constants into BarApp.h unchanged. Replace four
letter codes with imported message constants in BarApp.cpp and
BarWindow.cpp. Much nicer than using bare codes.

The new BDeskbar methods are all handled by TBarApp. The getters send
back a reply message containing the bool while the setters fall through
to existing setter cases.
This commit is contained in:
John Scipione 2017-11-26 21:59:44 -08:00
parent f8811591e1
commit fc23c09758
5 changed files with 159 additions and 27 deletions

View File

@ -41,6 +41,15 @@ public:
bool IsExpanded() const;
status_t Expand(bool expand);
bool IsAlwaysOnTop() const;
status_t SetAlwaysOnTop(bool alwaysOnTop);
bool IsAutoRaise() const;
status_t SetAutoRaise(bool autoRaise);
bool IsAutoHide() const;
status_t SetAutoHide(bool autoHide);
// Item querying methods
status_t GetItemInfo(int32 id, const char** _name) const;
status_t GetItemInfo(const char* name, int32* _id) const;

View File

@ -366,17 +366,41 @@ void
TBarApp::MessageReceived(BMessage* message)
{
switch (message->what) {
case 'gloc':
case 'sloc':
case 'gexp':
case 'sexp':
case 'info':
case 'exst':
case 'cwnt':
case 'icon':
case 'remv':
case 'adon':
// pass any BDeskbar originating messages on to the window
// BDeskbar originating messages we can handle
case kMsgIsAlwaysOnTop:
{
BMessage reply('rply');
reply.AddBool("always on top", fSettings.alwaysOnTop);
message->SendReply(&reply);
break;
}
case kMsgIsAutoRaise:
{
BMessage reply('rply');
reply.AddBool("auto raise", fSettings.autoRaise);
message->SendReply(&reply);
break;
}
case kMsgIsAutoHide:
{
BMessage reply('rply');
reply.AddBool("auto hide", fSettings.autoHide);
message->SendReply(&reply);
break;
}
// pass rest of BDeskbar originating messages onto the window
// (except for setters handled below)
case kMsgLocation:
case kMsgSetLocation:
case kMsgIsExpanded:
case kMsgExpand:
case kMsgGetItemInfo:
case kMsgHasItem:
case kMsgCountItems:
case kMsgAddView:
case kMsgRemoveItem:
case kMsgAddAddOn:
fBarWindow->PostMessage(message);
break;
@ -469,6 +493,7 @@ TBarApp::MessageReceived(BMessage* message)
BDragger::ShowAllDraggers();
break;
case kMsgAlwaysOnTop: // from BDeskbar
case kAlwaysTop:
fSettings.alwaysOnTop = !fSettings.alwaysOnTop;
@ -480,6 +505,7 @@ TBarApp::MessageReceived(BMessage* message)
: B_NORMAL_WINDOW_FEEL);
break;
case kMsgAutoRaise: // from BDeskbar
case kAutoRaise:
fSettings.autoRaise = fSettings.alwaysOnTop ? false
: !fSettings.autoRaise;
@ -488,6 +514,7 @@ TBarApp::MessageReceived(BMessage* message)
fPreferencesWindow->PostMessage(kUpdatePreferences);
break;
case kMsgAutoHide: // from BDeskbar
case kAutoHide:
fSettings.autoHide = !fSettings.autoHide;

View File

@ -79,6 +79,25 @@ const uint32 kUpdatePreferences = 'Pref';
// realign replicants message constant
const uint32 kRealignReplicants = 'Algn';
// BDeskbar message constants
static const uint32 kMsgIsAlwaysOnTop = 'gtop';
static const uint32 kMsgAlwaysOnTop = 'stop';
static const uint32 kMsgIsAutoRaise = 'grse';
static const uint32 kMsgAutoRaise = 'srse';
static const uint32 kMsgIsAutoHide = 'ghid';
static const uint32 kMsgAutoHide = 'shid';
static const uint32 kMsgAddView = 'icon';
static const uint32 kMsgAddAddOn = 'adon';
static const uint32 kMsgHasItem = 'exst';
static const uint32 kMsgGetItemInfo = 'info';
static const uint32 kMsgCountItems = 'cwnt';
static const uint32 kMsgRemoveItem = 'remv';
static const uint32 kMsgLocation = 'gloc';
static const uint32 kMsgIsExpanded = 'gexp';
static const uint32 kMsgSetLocation = 'sloc';
static const uint32 kMsgExpand = 'sexp';
/* --------------------------------------------- */
class BBitmap;

View File

@ -168,40 +168,40 @@ TBarWindow::MessageReceived(BMessage* message)
break;
}
case 'gloc':
case kMsgLocation:
GetLocation(message);
break;
case 'sloc':
case kMsgSetLocation:
SetLocation(message);
break;
case 'gexp':
case kMsgIsExpanded:
IsExpanded(message);
break;
case 'sexp':
case kMsgExpand:
Expand(message);
break;
case 'info':
case kMsgGetItemInfo:
ItemInfo(message);
break;
case 'exst':
case kMsgHasItem:
ItemExists(message);
break;
case 'cwnt':
case kMsgCountItems:
CountItems(message);
break;
case 'adon':
case 'icon':
case kMsgAddAddOn:
case kMsgAddView:
AddItem(message);
break;
case 'remv':
case kMsgRemoveItem:
RemoveItem(message);
break;

View File

@ -33,6 +33,13 @@
static const char* kDeskbarSignature = "application/x-vnd.Be-TSKB";
static const uint32 kMsgIsAlwaysOnTop = 'gtop';
static const uint32 kMsgAlwaysOnTop = 'stop';
static const uint32 kMsgIsAutoRaise = 'grse';
static const uint32 kMsgAutoRaise = 'srse';
static const uint32 kMsgIsAutoHide = 'ghid';
static const uint32 kMsgAutoHide = 'shid';
static const uint32 kMsgAddView = 'icon';
static const uint32 kMsgAddAddOn = 'adon';
static const uint32 kMsgHasItem = 'exst';
@ -149,12 +156,10 @@ BDeskbar::IsExpanded() const
{
BMessage request(kMsgIsExpanded);
BMessage reply;
bool isExpanded;
bool isExpanded = true;
if (fMessenger->SendMessage(&request, &reply) != B_OK
|| reply.FindBool("expanded", &isExpanded) != B_OK) {
isExpanded = true;
}
if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindBool("expanded", &isExpanded);
return isExpanded;
}
@ -170,6 +175,78 @@ BDeskbar::Expand(bool expand)
}
bool
BDeskbar::IsAlwaysOnTop() const
{
BMessage request(kMsgIsAlwaysOnTop);
BMessage reply;
bool isAlwaysOnTop = false;
if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindBool("always on top", &isAlwaysOnTop);
return isAlwaysOnTop;
}
status_t
BDeskbar::SetAlwaysOnTop(bool alwaysOnTop)
{
BMessage request(kMsgAlwaysOnTop);
request.AddBool("always on top", alwaysOnTop);
return fMessenger->SendMessage(&request);
}
bool
BDeskbar::IsAutoRaise() const
{
BMessage request(kMsgIsAutoRaise);
BMessage reply;
bool isAutoRaise = false;
if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindBool("auto raise", &isAutoRaise);
return isAutoRaise;
}
status_t
BDeskbar::SetAutoRaise(bool autoRaise)
{
BMessage request(kMsgAutoRaise);
request.AddBool("auto raise", autoRaise);
return fMessenger->SendMessage(&request);
}
bool
BDeskbar::IsAutoHide() const
{
BMessage request(kMsgIsAutoHide);
BMessage reply;
bool isAutoHidden;
if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindBool("auto hide", &isAutoHidden);
return isAutoHidden;
}
status_t
BDeskbar::SetAutoHide(bool autoHide)
{
BMessage request(kMsgAutoHide);
request.AddBool("auto hide", autoHide);
return fMessenger->SendMessage(&request);
}
// #pragma mark - Item querying methods
@ -249,7 +326,7 @@ BDeskbar::HasItem(const char* name) const
uint32
BDeskbar::CountItems(void) const
BDeskbar::CountItems() const
{
BMessage request(kMsgCountItems);
BMessage reply;