From 3a613432c9f06b372e5f8d3a456b97e0ad071f4a Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Sat, 15 Aug 2009 03:20:07 +0000 Subject: [PATCH] Center the OpenWindow. The problem is that we cannot get the real size of the window before it's actually shown on screen.. the trick I did was to show it offscreen, get the real size and move the window. Fixes ticket #4236 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32410 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/diskprobe/OpenWindow.cpp | 20 +++++++++++++++----- src/apps/diskprobe/OpenWindow.h | 3 +++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/apps/diskprobe/OpenWindow.cpp b/src/apps/diskprobe/OpenWindow.cpp index a88d687066..4ededce048 100644 --- a/src/apps/diskprobe/OpenWindow.cpp +++ b/src/apps/diskprobe/OpenWindow.cpp @@ -57,12 +57,22 @@ OpenWindow::OpenWindow() .Add(probeDeviceButton, 2, 1) .SetInsets(8, 8, 8, 8) ); - - // TODO: This does not center the window, since with layout management, - // the window will still have an invalid size at this point. BScreen screen(this); - MoveTo(screen.Frame().left + (screen.Frame().Width() - Frame().Width()) / 2, - screen.Frame().top + (screen.Frame().Height() - Frame().Height()) / 2); + // move the window offscreen.. + MoveTo(screen.Frame().right+20, screen.Frame().top); + fCentered = true; +} + + +void +OpenWindow::FrameResized(float width, float height) +{ + if (fCentered) { + BScreen screen(this); + MoveTo(screen.Frame().left + (screen.Frame().Width() - width) / 2, + screen.Frame().top + (screen.Frame().Height() - height) / 2); + } + fCentered = false; } diff --git a/src/apps/diskprobe/OpenWindow.h b/src/apps/diskprobe/OpenWindow.h index 4df1c635ce..b7269751f6 100644 --- a/src/apps/diskprobe/OpenWindow.h +++ b/src/apps/diskprobe/OpenWindow.h @@ -20,11 +20,14 @@ public: virtual void MessageReceived(BMessage* message); virtual bool QuitRequested(); + virtual void FrameResized(float width, float height); + static void CollectDevices(BMenu* menu, BEntry* startEntry = NULL); private: BMenu* fDevicesMenu; + bool fCentered; }; #endif /* OPEN_WINDOW_H */