From 31535ac63b726cbcd1933c5fa429543eca4e7509 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 1 May 2013 10:10:37 +0200 Subject: [PATCH] Make BAboutWindow modal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ã* Set its type to B_MODAL_WINDO, and also set B_NOT_MOVABLE * Since this removes the window tab, add an "Ok" button to close the window * Remove the GetWindow mess and just use it as any regular window * Adjust all callers again The AlertPosition method doesn't seem to work right, the window pops up offset to the right. I also noticed that some of our calls to BAboutWindow are actually not reacable because we removed Abutrequested from the apps. Maybe we should clean them up (locale preflet and activity monitor are examples) More annoying is the fact that opening a modal window from a deskbar replicant is modal against the whole deskbar. Not sure what to do about that. --- headers/private/shared/AboutWindow.h | 5 --- src/apps/deskcalc/CalcView.cpp | 38 +++++++--------- src/apps/networkstatus/NetworkStatusView.cpp | 25 +++++------ .../processcontroller/ProcessController.cpp | 33 ++++++-------- src/apps/workspaces/Workspaces.cpp | 43 ++++++++----------- src/kits/shared/AboutWindow.cpp | 34 +++++---------- src/preferences/locale/LocalePreflet.cpp | 28 +++++------- 7 files changed, 80 insertions(+), 126 deletions(-) diff --git a/headers/private/shared/AboutWindow.h b/headers/private/shared/AboutWindow.h index 55829c03e4..a8ec0b58fa 100644 --- a/headers/private/shared/AboutWindow.h +++ b/headers/private/shared/AboutWindow.h @@ -45,13 +45,8 @@ class BAboutWindow : public BWindow { const char* Version(); void SetVersion(const char* version); - - static BAboutWindow* GetWindow(const char* appName, - const char* signature, bool* needsInit = NULL); private: AboutView* fAboutView; - - static BAboutWindow* sAboutWindow; }; #endif // B_ABOUT_WINDOW_H diff --git a/src/apps/deskcalc/CalcView.cpp b/src/apps/deskcalc/CalcView.cpp index 8af748eaec..c9a0f9c400 100644 --- a/src/apps/deskcalc/CalcView.cpp +++ b/src/apps/deskcalc/CalcView.cpp @@ -267,32 +267,26 @@ CalcView::MessageReceived(BMessage* message) // (replicant) about box requested case B_ABOUT_REQUESTED: { - bool needsInit; - BAboutWindow* window = BAboutWindow::GetWindow(kAppName, - kSignature, &needsInit); + BAboutWindow* window = new BAboutWindow(kAppName, kSignature); - if (needsInit) { - // create the about window - const char* extraCopyrights[] = { - "1997, 1998 R3 Software Ltd.", - NULL - }; + // create the about window + const char* extraCopyrights[] = { + "1997, 1998 R3 Software Ltd.", + NULL + }; - const char* authors[] = { - "Stephan Aßmus", - "John Scipione", - "Timothy Wayper", - "Ingo Weinhold", - NULL - }; + const char* authors[] = { + "Stephan Aßmus", + "John Scipione", + "Timothy Wayper", + "Ingo Weinhold", + NULL + }; - window->AddCopyright(2006, "Haiku, Inc.", extraCopyrights); - window->AddAuthors(authors); - } + window->AddCopyright(2006, "Haiku, Inc.", extraCopyrights); + window->AddAuthors(authors); - if (window->IsHidden()) - window->Show(); - window->Activate(); + window->Show(); break; } diff --git a/src/apps/networkstatus/NetworkStatusView.cpp b/src/apps/networkstatus/NetworkStatusView.cpp index faef66b63c..cdff48eb65 100644 --- a/src/apps/networkstatus/NetworkStatusView.cpp +++ b/src/apps/networkstatus/NetworkStatusView.cpp @@ -504,24 +504,19 @@ NetworkStatusView::MouseDown(BPoint point) void NetworkStatusView::_AboutRequested() { - bool needsInit; - BAboutWindow* window = BAboutWindow::GetWindow( - B_TRANSLATE_SYSTEM_NAME("NetworkStatus"), kSignature, &needsInit); + BAboutWindow* window = new BAboutWindow( + B_TRANSLATE_SYSTEM_NAME("NetworkStatus"), kSignature); - if (needsInit) { - const char* authors[] = { - "Axel Dörfler", - "Hugo Santos", - NULL - }; + const char* authors[] = { + "Axel Dörfler", + "Hugo Santos", + NULL + }; - window->AddCopyright(2007, "Haiku, Inc."); - window->AddAuthors(authors); - } + window->AddCopyright(2007, "Haiku, Inc."); + window->AddAuthors(authors); - if (window->IsHidden()) - window->Show(); - window->Activate(); + window->Show(); } diff --git a/src/apps/processcontroller/ProcessController.cpp b/src/apps/processcontroller/ProcessController.cpp index b7fe26e24e..17aae5c4b6 100644 --- a/src/apps/processcontroller/ProcessController.cpp +++ b/src/apps/processcontroller/ProcessController.cpp @@ -433,29 +433,24 @@ ProcessController::MessageReceived(BMessage *message) void ProcessController::AboutRequested() { - bool needsInit; - BAboutWindow* window = BAboutWindow::GetWindow( - B_TRANSLATE_SYSTEM_NAME("ProcessController"), kSignature, &needsInit); + BAboutWindow* window = new BAboutWindow( + B_TRANSLATE_SYSTEM_NAME("ProcessController"), kSignature); - if (needsInit) { - const char* extraCopyrights[] = { - "2004 beunited.org", - "1997-2001 Georges-Edouard Berenger", - NULL - }; + const char* extraCopyrights[] = { + "2004 beunited.org", + "1997-2001 Georges-Edouard Berenger", + NULL + }; - const char* authors[] = { - "Georges-Edouard Berenger", - NULL - }; + const char* authors[] = { + "Georges-Edouard Berenger", + NULL + }; - window->AddCopyright(2007, "Haiku, Inc.", extraCopyrights); - window->AddAuthors(authors); - } + window->AddCopyright(2007, "Haiku, Inc.", extraCopyrights); + window->AddAuthors(authors); - if (window->IsHidden()) - window->Show(); - window->Activate(); + window->Show(); } diff --git a/src/apps/workspaces/Workspaces.cpp b/src/apps/workspaces/Workspaces.cpp index 3f87647c3c..30f8f16dc2 100644 --- a/src/apps/workspaces/Workspaces.cpp +++ b/src/apps/workspaces/Workspaces.cpp @@ -400,36 +400,31 @@ WorkspacesView::Archive(BMessage* archive, bool deep) const void WorkspacesView::_AboutRequested() { - bool needsInit; - BAboutWindow* window = BAboutWindow::GetWindow( - B_TRANSLATE_SYSTEM_NAME("Workspaces"), kSignature, &needsInit); + BAboutWindow* window = new BAboutWindow( + B_TRANSLATE_SYSTEM_NAME("Workspaces"), kSignature); - if (needsInit) { - const char* authors[] = { - "Axel Dörfler", - "Oliver \"Madison\" Kohl", - "Matt Madia", - "François Revol", - NULL - }; + const char* authors[] = { + "Axel Dörfler", + "Oliver \"Madison\" Kohl", + "Matt Madia", + "François Revol", + NULL + }; - const char* extraCopyrights[] = { - "2002 François Revol", - NULL - }; + const char* extraCopyrights[] = { + "2002 François Revol", + NULL + }; - const char* extraInfo = "Send windows behind using the Option key. " - "Move windows to front using the Control key.\n"; + const char* extraInfo = "Send windows behind using the Option key. " + "Move windows to front using the Control key.\n"; - window->AddCopyright(2002, "Haiku, Inc.", + window->AddCopyright(2002, "Haiku, Inc.", extraCopyrights); - window->AddAuthors(authors); - window->AddExtraInfo(extraInfo); - } + window->AddAuthors(authors); + window->AddExtraInfo(extraInfo); - if (window->IsHidden()) - window->Show(); - window->Activate(); + window->Show(); } diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp index f2d6d50e5c..84d17ea4c8 100644 --- a/src/kits/shared/AboutWindow.cpp +++ b/src/kits/shared/AboutWindow.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -182,6 +183,11 @@ AboutView::AboutView(const char* appName, const char* signature) fStripeView = new StripeView(_GetIconFromSignature(signature)); + const char* ok = B_TRANSLATE_MARK("Ok"); + BButton* closeButton = new BButton("ok", + gSystemCatalog.GetString(ok, "AboutWindow"), + new BMessage(B_QUIT_REQUESTED)); + GroupLayout()->SetSpacing(0); BLayoutBuilder::Group<>(this) .AddGroup(B_HORIZONTAL, 0) @@ -192,6 +198,7 @@ AboutView::AboutView(const char* appName, const char* signature) .Add(fNameView) .Add(fVersionView) .Add(infoViewScroller) + .Add(closeButton) .End() .AddGlue() .End(); @@ -352,12 +359,10 @@ AboutView::SetIcon(BBitmap* icon) BAboutWindow::BAboutWindow(const char* appName, const char* signature) - : BWindow(BRect(0.0, 0.0, 200.0, 200.0), appName, B_TITLED_WINDOW, - B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE - | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE) + : BWindow(BRect(0.0, 0.0, 200.0, 200.0), appName, B_MODAL_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_NOT_MOVABLE | B_NOT_ZOOMABLE + | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE) { - sAboutWindow = this; - SetLayout(new BGroupLayout(B_VERTICAL)); const char* about = B_TRANSLATE_MARK("About %app%"); @@ -376,8 +381,6 @@ BAboutWindow::BAboutWindow(const char* appName, const char* signature) BAboutWindow::~BAboutWindow() { - sAboutWindow = NULL; - fAboutView->RemoveSelf(); delete fAboutView; fAboutView = NULL; @@ -613,20 +616,3 @@ BAboutWindow::SetIcon(BBitmap* icon) fAboutView->SetIcon(icon); } -/* static */ BAboutWindow* -BAboutWindow::GetWindow(const char* appName, const char* signature, - bool* needsInit) -{ - if(needsInit != NULL) - *needsInit = (sAboutWindow == NULL); - - if(sAboutWindow == NULL) { - new BAboutWindow(appName, signature); - } - - return sAboutWindow; -} - - -/* static */ BAboutWindow* -BAboutWindow::sAboutWindow = NULL; diff --git a/src/preferences/locale/LocalePreflet.cpp b/src/preferences/locale/LocalePreflet.cpp index 39768898a4..594e94ddaa 100644 --- a/src/preferences/locale/LocalePreflet.cpp +++ b/src/preferences/locale/LocalePreflet.cpp @@ -74,26 +74,20 @@ LocalePreflet::MessageReceived(BMessage* message) case B_ABOUT_REQUESTED: { - bool needsInit; - BAboutWindow* window = BAboutWindow::GetWindow(kAppName, - kSignature, &needsInit); + BAboutWindow* window = new BAboutWindow(kAppName, kSignature); - if (needsInit) { - const char* authors[] = { - "Axel Dörfler", - "Adrien Destugues", - "Oliver Tappe", - NULL - }; + const char* authors[] = { + "Axel Dörfler", + "Adrien Destugues", + "Oliver Tappe", + NULL + }; - window = new BAboutWindow(kAppName, kSignature); - window->AddCopyright(2005, "Haiku, Inc."); - window->AddAuthors(authors); - } + window = new BAboutWindow(kAppName, kSignature); + window->AddCopyright(2005, "Haiku, Inc."); + window->AddAuthors(authors); - if (window->IsHidden()) - window->Show(); - window->Activate(); + window->Show(); break; }