From 941098a211584bfa09f746d32e2d9a267b07e638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sundstr=C3=B6m?= Date: Thu, 1 Oct 2009 00:03:00 +0000 Subject: [PATCH] Standardizing on BWindow::CenterOnScreen() git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33378 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bootman/BootManagerWindow.cpp | 24 +------------------ src/apps/bootman/BootManagerWindow.h | 2 -- src/apps/magnify/Magnify.cpp | 17 ++----------- src/apps/tv/MainWin.cpp | 23 +----------------- src/apps/tv/MainWin.h | 1 - src/kits/tracker/FavoritesConfig.cpp | 12 +++------- .../devices/ConfigurationWindow.cpp | 2 +- src/preferences/devices/DevicesWindow.cpp | 16 +------------ src/preferences/devices/DevicesWindows.h | 2 -- src/preferences/devices/ModemWindow.cpp | 2 +- .../devices/ResourceUsageWindow.cpp | 2 +- src/preferences/dun/ModemWindow.cpp | 15 +----------- src/preferences/dun/NewConnectionWindow.cpp | 16 +------------ 13 files changed, 13 insertions(+), 121 deletions(-) diff --git a/src/apps/bootman/BootManagerWindow.cpp b/src/apps/bootman/BootManagerWindow.cpp index 08dcb0ed74..bafd4b3306 100644 --- a/src/apps/bootman/BootManagerWindow.cpp +++ b/src/apps/bootman/BootManagerWindow.cpp @@ -35,7 +35,7 @@ BootManagerWindow::BootManagerWindow() AddShortcut('A', B_COMMAND_KEY, new BMessage(B_ABOUT_REQUESTED)); - _CenterWindow(); + CenterOnScreen(); } @@ -73,25 +73,3 @@ BootManagerWindow::QuitRequested() return true; } - -void -BootManagerWindow::_CenterWindow() -{ - BScreen screen(this); - if (!screen.IsValid()) - return; - - BRect frame = screen.Frame(); - BRect windowFrame = Frame(); - - float left = floor((frame.Width() - windowFrame.Width()) / 2); - float top = floor((frame.Height() - windowFrame.Height()) / 2); - - if (left < 20) - left = 20; - if (top < 20) - top = 20; - - MoveTo(left, top); -} - diff --git a/src/apps/bootman/BootManagerWindow.h b/src/apps/bootman/BootManagerWindow.h index ea137c9806..c09885bcc4 100644 --- a/src/apps/bootman/BootManagerWindow.h +++ b/src/apps/bootman/BootManagerWindow.h @@ -26,8 +26,6 @@ public: private: - void _CenterWindow(); - BootManagerController fController; WizardView* fWizardView; }; diff --git a/src/apps/magnify/Magnify.cpp b/src/apps/magnify/Magnify.cpp index f54eccc5b1..a428fa6e9b 100644 --- a/src/apps/magnify/Magnify.cpp +++ b/src/apps/magnify/Magnify.cpp @@ -102,19 +102,6 @@ FontHeight(BView* target, bool full) } -static void -CenterWindowOnScreen(BWindow* w) -{ - BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame()); - BPoint pt; - pt.x = screenFrame.Width()/2 - w->Bounds().Width()/2; - pt.y = screenFrame.Height()/2 - w->Bounds().Height()/2; - - if (screenFrame.Contains(pt)) - w->MoveTo(pt); -} - - static void BoundsSelection(int32 incX, int32 incY, float* x, float* y, int32 xCount, int32 yCount) @@ -473,7 +460,7 @@ ALMOST_DONE: // clean up and try to position the window } // if prefs dont yet exist or the window is not onscreen, center the window - CenterWindowOnScreen(this); + CenterOnScreen(); // set all the settings to defaults if we get here DONE: @@ -839,7 +826,7 @@ TWindow::ShowHelp() text->Insert(" option-arrow key - moves the mouse location 1 pixel at a time\n"); text->Insert(" x marks the selection - the current selection has an 'x' in it\n"); - CenterWindowOnScreen(w); + w->CenterOnScreen(); w->Show(); } diff --git a/src/apps/tv/MainWin.cpp b/src/apps/tv/MainWin.cpp index 6ae2d5eb0e..4b5bf73e54 100644 --- a/src/apps/tv/MainWin.cpp +++ b/src/apps/tv/MainWin.cpp @@ -133,7 +133,7 @@ MainWin::MainWin(BRect frame_rect) VideoFormatChange(fSourceWidth, fSourceHeight, fWidthScale, fHeightScale); - CenterWindow(); + CenterOnScreen(); } @@ -1178,24 +1178,3 @@ MainWin::MessageReceived(BMessage *msg) } } - -void -MainWin::CenterWindow() -{ - BScreen screen(this); - if (!screen.IsValid()) - return; - - BRect frame = screen.Frame(); - BRect windowFrame = Frame(); - - float left = floor((frame.Width() - windowFrame.Width()) / 2); - float top = floor((frame.Height() - windowFrame.Height()) / 2); - - if (left < 20) - left = 20; - if (top < 20) - top = 20; - - MoveTo(left, top); -} diff --git a/src/apps/tv/MainWin.h b/src/apps/tv/MainWin.h index d9ea486784..d63f70c73d 100644 --- a/src/apps/tv/MainWin.h +++ b/src/apps/tv/MainWin.h @@ -75,7 +75,6 @@ public: void ToggleNoBorder(); void ToggleNoMenu(); void ToggleNoBorderNoMenu(); - void CenterWindow(); void ShowContextMenu(const BPoint &screen_point); diff --git a/src/kits/tracker/FavoritesConfig.cpp b/src/kits/tracker/FavoritesConfig.cpp index bf474e520b..88c491c9c1 100644 --- a/src/kits/tracker/FavoritesConfig.cpp +++ b/src/kits/tracker/FavoritesConfig.cpp @@ -219,13 +219,7 @@ const unsigned char kSmallNewGroupIcon [] = { void CenterWindowOnScreen(BWindow *window) { - BRect screenFrame = BScreen(B_MAIN_SCREEN_ID).Frame(); - BPoint point; - point.x = screenFrame.Width() / 2 - window->Bounds().Width() / 2; - point.y = screenFrame.Height() / 2 - window->Bounds().Height() / 2; - - if (screenFrame.Contains(point)) - window->MoveTo(point); + window->CenterOnScreen(); } @@ -264,7 +258,7 @@ TFavoritesConfigWindow::TFavoritesConfigWindow(BRect frame, const char *title, MoveTo(-1024, -1024); Show(); AddParts(maxApps, maxDocs, maxFolders); - CenterWindowOnScreen(this); + CenterOnScreen(); Unlock(); AddShortcut('R', B_COMMAND_KEY, new BMessage(kRemove)); @@ -2219,7 +2213,7 @@ NameItemPanel::NameItemPanel(BWindow *parent, const char *initialtext) AddParts(initialtext); ResizeTo(Bounds().Width(), fCancelBtn->Frame().bottom + 10); Unlock(); - CenterWindowOnScreen(this); + CenterOnScreen(); } diff --git a/src/preferences/devices/ConfigurationWindow.cpp b/src/preferences/devices/ConfigurationWindow.cpp index 0fd98ea276..db4de7fd67 100644 --- a/src/preferences/devices/ConfigurationWindow.cpp +++ b/src/preferences/devices/ConfigurationWindow.cpp @@ -142,7 +142,7 @@ ConfigurationWindow::ConfigurationWindow(BRect frame, DeviceItem *item) B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE|B_NOT_RESIZABLE), fItem(item) { - CenterWindowOnScreen(this); + CenterOnScreen(); fItem->SetWindow(this); InitWindow(); diff --git a/src/preferences/devices/DevicesWindow.cpp b/src/preferences/devices/DevicesWindow.cpp index a4c5e68882..1a74b7953f 100644 --- a/src/preferences/devices/DevicesWindow.cpp +++ b/src/preferences/devices/DevicesWindow.cpp @@ -48,25 +48,11 @@ const uint32 BTN_CONFIGURE = 'bcfg'; const uint32 SELECTION_CHANGED = 'slch'; -// CenterWindowOnScreen -- Centers the BWindow to the Current Screen -void CenterWindowOnScreen(BWindow* w) -{ - BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame()); - BPoint pt; - pt.x = screenFrame.Width()/2 - w->Bounds().Width()/2; - pt.y = screenFrame.Height()/2 - w->Bounds().Height()/2; - - if (screenFrame.Contains(pt)) - w->MoveTo(pt); -} -// ---------------------------------------------------------------------------------------------------------- // - - // DevicesWindow - Constructor DevicesWindow::DevicesWindow(BRect frame) : BWindow (frame, "Devices", B_TITLED_WINDOW, B_NORMAL_WINDOW_FEEL , 0) { InitWindow(); - CenterWindowOnScreen(this); + CenterOnScreen(); // Load User Settings BPath path; diff --git a/src/preferences/devices/DevicesWindows.h b/src/preferences/devices/DevicesWindows.h index 6249fbee83..8615ca7b21 100644 --- a/src/preferences/devices/DevicesWindows.h +++ b/src/preferences/devices/DevicesWindows.h @@ -31,8 +31,6 @@ class BStringView; #define MODEM_ADDED 'moad' -void CenterWindowOnScreen(BWindow* w); - class ResourceUsageWindow : public BWindow { public: ResourceUsageWindow(BRect frame, BList &); diff --git a/src/preferences/devices/ModemWindow.cpp b/src/preferences/devices/ModemWindow.cpp index 0be273360a..2c35c74a3c 100644 --- a/src/preferences/devices/ModemWindow.cpp +++ b/src/preferences/devices/ModemWindow.cpp @@ -44,7 +44,7 @@ ModemWindow::ModemWindow(BRect frame, BMessenger messenger) fMessenger(messenger) { InitWindow(); - CenterWindowOnScreen(this); + CenterOnScreen(); Show(); } // -------------------------------------------------------------------------------------------------- // diff --git a/src/preferences/devices/ResourceUsageWindow.cpp b/src/preferences/devices/ResourceUsageWindow.cpp index 486dbc21e7..97522feb4c 100644 --- a/src/preferences/devices/ResourceUsageWindow.cpp +++ b/src/preferences/devices/ResourceUsageWindow.cpp @@ -188,7 +188,7 @@ ResourceUsageWindow::ResourceUsageWindow(BRect frame, BList &list) : BWindow (frame, "Resource Usage", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL , B_NOT_ZOOMABLE|B_NOT_RESIZABLE) { InitWindow(list); - CenterWindowOnScreen(this); + CenterOnScreen(); Show(); } // -------------------------------------------------------------------------------------------------- // diff --git a/src/preferences/dun/ModemWindow.cpp b/src/preferences/dun/ModemWindow.cpp index df02637f06..b3a8097f4e 100644 --- a/src/preferences/dun/ModemWindow.cpp +++ b/src/preferences/dun/ModemWindow.cpp @@ -13,24 +13,11 @@ Author: Sikosis (beos@gravity24hr.com) #include "ModemWindow.h" -// CenterWindowOnScreen -- Centers the BWindow to the Current Screen -static void CenterWindowOnScreen(BWindow* w) -{ - BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame()); - BPoint pt; - pt.x = screenFrame.Width()/2 - w->Bounds().Width()/2; - pt.y = screenFrame.Height()/2 - w->Bounds().Height()/2; - - if (screenFrame.Contains(pt)) - w->MoveTo(pt); -} -// ------------------------------------------------------------------------------------------ // - // ModemWindow -- constructor for ModemWindow Class ModemWindow::ModemWindow(BRect frame) : BWindow (frame, "", B_MODAL_WINDOW, B_NOT_RESIZABLE , 0) { InitWindow(); - CenterWindowOnScreen(this); + CenterOnScreen(); Show(); } // ------------------------------------------------------------------------------- // diff --git a/src/preferences/dun/NewConnectionWindow.cpp b/src/preferences/dun/NewConnectionWindow.cpp index e88d6cf17a..aead640dc4 100644 --- a/src/preferences/dun/NewConnectionWindow.cpp +++ b/src/preferences/dun/NewConnectionWindow.cpp @@ -33,25 +33,11 @@ const uint32 TXT_NEW_CONNECTION = 'TxCx'; // ---------------------------------------------------------------------------------------------------------- // -// CenterWindowOnScreen -- Centers the BWindow to the Current Screen -static void CenterWindowOnScreen(BWindow* w) -{ - BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame()); - BPoint pt; - pt.x = screenFrame.Width()/2 - w->Bounds().Width()/2; - pt.y = screenFrame.Height()/2 - w->Bounds().Height()/2; - - if (screenFrame.Contains(pt)) - w->MoveTo(pt); -} -// ---------------------------------------------------------------------------------------------------------- // - - // NewConnectionWindow - Constructor NewConnectionWindow::NewConnectionWindow(BRect frame) : BWindow (frame, "NewConnectionWindow", B_MODAL_WINDOW , B_NOT_RESIZABLE , 0) { InitWindow(); - CenterWindowOnScreen(this); + CenterOnScreen(); Show(); }