Reverse the meaning of BWindow fShowLevel to match BView.

This also matches the client_window_info.show_hide_level field used in Deskbar
and other applications.

While doing this, keep fShowLevel fully in sync between BWindow and app_server,
use one message type for both hiding and showing, and make the decision to show
and hide the window in the app_server.

Lastly make minimize behave as described in the Be Book: hidden windows cannot
be minimized, and minimized windows which get hidden become unminimized.
This commit is contained in:
Ryan Leavengood
2012-08-15 23:45:15 -04:00
parent a4bca81193
commit 59347b7f1b
6 changed files with 44 additions and 58 deletions
+1
View File
@@ -352,6 +352,7 @@ private:
void _GetDecoratorSize(float* _borderWidth,
float* _tabHeight) const;
void _SendShowOrHideMessage();
private:
char* fTitle;
+2 -2
View File
@@ -87,8 +87,8 @@ enum {
AS_GET_CURSOR_BITMAP,
// Window definitions
AS_SHOW_WINDOW,
AS_HIDE_WINDOW,
AS_SHOW_OR_HIDE_WINDOW,
AS_INTERNAL_HIDE_WINDOW,
AS_MINIMIZE_WINDOW,
AS_QUIT_WINDOW,
AS_SEND_BEHIND,
+24 -26
View File
@@ -589,7 +589,8 @@ BWindow::ChildAt(int32 index) const
void
BWindow::Minimize(bool minimize)
{
if (IsModal() || IsFloating() || fMinimized == minimize || !Lock())
if (IsModal() || IsFloating() || IsHidden() || fMinimized == minimize
|| !Lock())
return;
fMinimized = minimize;
@@ -769,10 +770,7 @@ BWindow::MessageReceived(BMessage* msg)
// connect all views to the server again
fTopView->_CreateSelf();
if (fShowLevel >= 1) {
fLink->StartMessage(AS_SHOW_WINDOW);
fLink->Flush();
}
_SendShowOrHideMessage();
}
return BLooper::MessageReceived(msg);
@@ -2094,10 +2092,6 @@ BWindow::IsMinimized() const
if (!locker.IsLocked())
return false;
// Hiding takes precendence over minimization!!!
if (IsHidden())
return false;
return fMinimized;
}
@@ -2607,13 +2601,9 @@ BWindow::Show()
{
bool runCalled = true;
if (Lock()) {
fShowLevel++;
fShowLevel--;
if (fShowLevel == 1) {
fLink->StartMessage(AS_SHOW_WINDOW);
fLink->Attach<int32>(fShowLevel);
fLink->Flush();
}
_SendShowOrHideMessage();
runCalled = fRunCalled;
@@ -2638,25 +2628,24 @@ BWindow::Show()
void
BWindow::Hide()
{
if (!Lock())
return;
if (Lock()) {
// If we are minimized and are about to be hidden, unminimize
if (IsMinimized() && fShowLevel == 0)
Minimize(false);
fShowLevel--;
fShowLevel++;
if (fShowLevel == 0) {
fLink->StartMessage(AS_HIDE_WINDOW);
fLink->Attach<int32>(fShowLevel);
fLink->Flush();
_SendShowOrHideMessage();
Unlock();
}
Unlock();
}
bool
BWindow::IsHidden() const
{
return fShowLevel <= 0;
return fShowLevel > 0;
}
@@ -2793,7 +2782,7 @@ BWindow::_InitData(BRect frame, const char* title, window_look look,
fInTransaction = bitmapToken >= 0;
fUpdateRequested = false;
fActive = false;
fShowLevel = 0;
fShowLevel = 1;
fTopView = NULL;
fFocus = NULL;
@@ -4061,6 +4050,15 @@ BWindow::_GetDecoratorSize(float* _borderWidth, float* _tabHeight) const
}
void
BWindow::_SendShowOrHideMessage()
{
fLink->StartMessage(AS_SHOW_OR_HIDE_WINDOW);
fLink->Attach<int32>(fShowLevel);
fLink->Flush();
}
// #pragma mark - C++ binary compatibility kludge
+2 -2
View File
@@ -66,8 +66,8 @@ string_for_message_code(uint32 code, BString& string)
CODE(AS_GET_CURSOR_BITMAP);
// Window definitions
CODE(AS_SHOW_WINDOW);
CODE(AS_HIDE_WINDOW);
CODE(AS_SHOW_OR_HIDE_WINDOW);
CODE(AS_INTERNAL_HIDE_WINDOW);
CODE(AS_MINIMIZE_WINDOW);
CODE(AS_QUIT_WINDOW);
CODE(AS_SEND_BEHIND);
+12 -26
View File
@@ -315,7 +315,7 @@ ServerWindow::_PrepareQuit()
_Hide();
fDesktop->UnlockSingleWindow();
} else if (fThread >= B_OK)
PostMessage(AS_HIDE_WINDOW);
PostMessage(AS_INTERNAL_HIDE_WINDOW);
}
@@ -481,9 +481,7 @@ ServerWindow::GetInfo(window_info& info)
info.window_right = (int)floor(fWindow->Frame().right);
info.window_bottom = (int)floor(fWindow->Frame().bottom);
// This is essentially opposite of the ShowLevel, meaning a window is
// hidden if it is 1 or more, and shown if it is 0 or less.
info.show_hide_level = fWindow->ShowLevel() <= 0 ? 1 : 0;
info.show_hide_level = fWindow->ShowLevel();
info.is_mini = fWindow->IsMinimized();
}
@@ -596,44 +594,32 @@ void
ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
{
switch (code) {
case AS_SHOW_WINDOW:
case AS_SHOW_OR_HIDE_WINDOW:
{
DTRACE(("ServerWindow %s: Message AS_SHOW_WINDOW\n", Title()));
_Show();
int32 showLevel;
if (link.Read<int32>(&showLevel) == B_OK) {
DTRACE(("ServerWindow %s: Message AS_SHOW_OR_HIDE_WINDOW, "
"show level: %d\n", Title(), showLevel));
fWindow->SetShowLevel(showLevel);
if (showLevel <= 0)
_Show();
else
_Hide();
}
break;
}
case AS_HIDE_WINDOW:
{
DTRACE(("ServerWindow %s: Message AS_HIDE_WINDOW\n", Title()));
// Only for internal use within this class
case AS_INTERNAL_HIDE_WINDOW:
_Hide();
int32 showLevel;
if (link.Read<int32>(&showLevel) == B_OK) {
fWindow->SetShowLevel(showLevel);
}
break;
}
case AS_MINIMIZE_WINDOW:
{
bool minimize;
if (link.Read<bool>(&minimize) == B_OK) {
DTRACE(("ServerWindow %s: Message AS_MINIMIZE_WINDOW, "
"minimize: %d\n", Title(), minimize));
if (fWindow->ShowLevel() <= 0) {
// Window is currently hidden - ignore the minimize
// request, but keep the state in sync.
fWindow->SetMinimized(minimize);
break;
}
fDesktop->UnlockSingleWindow();
fDesktop->MinimizeWindow(fWindow, minimize);
fDesktop->LockSingleWindow();
+3 -2
View File
@@ -102,9 +102,10 @@ Window::Window(const BRect& frame, const char *name,
fInUpdate(false),
fUpdatesEnabled(true),
// windows start hidden
// Windows start hidden
fHidden(true),
fShowLevel(0),
// Hidden is 1 or more
fShowLevel(1),
fMinimized(false),
fIsFocus(false),