[haiku-commits] haiku: hrev45590 - src/kits/interface src/kits/tracker headers/os/interface src/apps/stylededit

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 1 May 2013 02:17:52 +0200 (CEST)

hrev45590 adds 4 changesets to branch 'master'
old head: fd19c7366df2134106131c370c99c3ed7f38757f
new head: f3decd20605e769ce37ef3dd2bfa71bb9c196a81
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=f3decd2+%5Efd19c73

----------------------------------------------------------------------------

f74ff8d: Remove this bit of code from StyledEdit
  
  ....as we're gonna do the work in BFilePanel instead.

6723d9f: Create a BWindow::AlertPosition() method and use it
  
  ...to position alert's and open/save dialogs nicely inside of the parent 
window,
  or if that is unavailable, the screen frame.
  
  AlertPosition() is private (for now) but BAlert and BFilePanel are BWindow's 
friends so
  BWindow allows those classes to touch it's privates.

d4d842b: Style fix in BAlert, some sort of strange spaces got in there

f3decd2: Fix #9726 Revert CenterIn() and CenterOnScreen()
  
  ... back to their previous void returning roles. AlertPosition() is used 
instead to
  check that an alert fits within the sides of the screen and all that.
  
  Also add another CenterOnScreen() method that takes a Screen ID
  so you can center a window on another monitor that the one it is currently on
  (theoretically someday anyway).

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

5 files changed, 89 insertions(+), 54 deletions(-)
headers/os/interface/Window.h            |   7 +-
src/apps/stylededit/StyledEditWindow.cpp |   4 -
src/kits/interface/Alert.cpp             |  15 ++--
src/kits/interface/Window.cpp            | 107 +++++++++++++++++----------
src/kits/tracker/FilePanel.cpp           |  10 +++

############################################################################

Commit:      f74ff8d324ac79b64713d7b52e6ec7c26dc1896a
URL:         http://cgit.haiku-os.org/haiku/commit/?id=f74ff8d
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Apr 30 23:58:50 2013 UTC

Remove this bit of code from StyledEdit

....as we're gonna do the work in BFilePanel instead.

----------------------------------------------------------------------------

diff --git a/src/apps/stylededit/StyledEditWindow.cpp 
b/src/apps/stylededit/StyledEditWindow.cpp
index a16fff5..4469d1d 100644
--- a/src/apps/stylededit/StyledEditWindow.cpp
+++ b/src/apps/stylededit/StyledEditWindow.cpp
@@ -850,10 +850,6 @@ StyledEditWindow::SaveAs(BMessage* message)
        if (message != NULL)
                fSavePanel->SetMessage(message);
 
-       // Position the save panel so that it is centered vertically but offset
-       // a bit horizontally in the parent window's frame.
-       fSavePanel->Window()->CenterIn(Frame().InsetByCopy(0, Frame().Height() 
/ 2)
-               .OffsetBySelf(0, -Frame().Height() / 3));
        fSavePanel->Show();
        return B_OK;
 }

############################################################################

Commit:      6723d9fc948b0abd71cb55b46f8c73586d8494f1
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6723d9f
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Wed May  1 00:06:29 2013 UTC

Create a BWindow::AlertPosition() method and use it

...to position alert's and open/save dialogs nicely inside of the parent window,
or if that is unavailable, the screen frame.

AlertPosition() is private (for now) but BAlert and BFilePanel are BWindow's 
friends so
BWindow allows those classes to touch it's privates.

----------------------------------------------------------------------------

diff --git a/headers/os/interface/Window.h b/headers/os/interface/Window.h
index 5b1d689..02b2cde 100644
--- a/headers/os/interface/Window.h
+++ b/headers/os/interface/Window.h
@@ -283,6 +283,7 @@ private:
        struct unpack_cookie;
        class Shortcut;
 
+       friend class BAlert;
        friend class BApplication;
        friend class BBitmap;
        friend class BView;
@@ -303,6 +304,7 @@ private:
 
        virtual void                            task_looper();
 
+                       BPoint                          AlertPosition(const 
BRect& frame);
        virtual BMessage*                       ConvertToMessage(void* raw, 
int32 code);
 
                        void                            AddShortcut(uint32 key, 
uint32 modifiers,
diff --git a/src/kits/interface/Alert.cpp b/src/kits/interface/Alert.cpp
index ce513cf..476f353 100644
--- a/src/kits/interface/Alert.cpp
+++ b/src/kits/interface/Alert.cpp
@@ -576,13 +576,10 @@ BAlert::_InitObject(const char* text, const char* 
button0, const char* button1,
        // Position the alert so that it is centered vertically but offset a bit
        // horizontally in the parent window's frame or, if unavailable, the
        // screen frame.
-       BWindow* window =
+       BWindow* parent =
                
dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL)));
-       const BRect frame = window != NULL ? window->Frame()
-               : (BScreen(this)).Frame();
-
-       CenterIn(frame.InsetByCopy(0, frame.Height() / 2)
-               .OffsetBySelf(0, -frame.Height() / 4));
+       const BRect frame = parent != NULL ? parent->Frame() : 
BScreen(this).Frame();
+       MoveTo(dynamic_cast<BWindow*>(this)->AlertPosition(frame));
 }
 
 
diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp
index a7ef4a8..fd77d14 100644
--- a/src/kits/interface/Window.cpp
+++ b/src/kits/interface/Window.cpp
@@ -3891,6 +3891,58 @@ BWindow::_KeyboardNavigation()
 }
 
 
+/*!
+       \brief Return the position of the window centered horizontally to the 
passed
+           in \a frame and vertically 3/4 from the top of \a frame.
+
+       If the window is on the borders
+
+       \param width The width of the window.
+       \param height The height of the window.
+       \param frame The \a frame to center the window in.
+
+       \return The new window position.
+*/
+BPoint
+BWindow::AlertPosition(const BRect& frame)
+{
+       float width = Bounds().Width();
+       float height = Bounds().Height();
+
+       BPoint point(frame.left + (frame.Width() / 2.0f) - (width / 2.0f),
+               frame.top + (frame.Height() / 4.0f) - ceil(height / 3.0f));
+
+       BRect screenFrame = BScreen(this).Frame();
+       if (frame == screenFrame) {
+               // reference frame is screen frame, skip the below adjustments
+               return point;
+       }
+
+       float borderWidth;
+       float tabHeight;
+       _GetDecoratorSize(&borderWidth, &tabHeight);
+
+       // clip the x position within the horizontal edges of the screen
+       if (point.x < screenFrame.left + borderWidth)
+               point.x = screenFrame.left + borderWidth;
+       else if (point.x + width > screenFrame.right - borderWidth)
+               point.x = screenFrame.right - borderWidth - width;
+
+       // lower the window down if it is covering the window tab
+       float tabPosition = frame.LeftTop().y + tabHeight + borderWidth;
+       if (point.y < tabPosition)
+               point.y = tabPosition;
+
+       // clip the y position within the vertical edges of the screen
+       if (point.y < screenFrame.top + borderWidth)
+               point.y = screenFrame.top + borderWidth;
+       else if (point.y + height > screenFrame.bottom - borderWidth)
+               point.y = screenFrame.bottom - borderWidth - height;
+
+       return point;
+}
+
+
 BMessage*
 BWindow::ConvertToMessage(void* raw, int32 code)
 {
diff --git a/src/kits/tracker/FilePanel.cpp b/src/kits/tracker/FilePanel.cpp
index ae89580..806c48f 100644
--- a/src/kits/tracker/FilePanel.cpp
+++ b/src/kits/tracker/FilePanel.cpp
@@ -40,6 +40,9 @@ All rights reserved.
 #include <BeBuild.h>
 #include <Debug.h>
 #include <FilePanel.h>
+#include <Looper.h>
+#include <Screen.h>
+#include <Window.h>
 
 #include "AutoLock.h"
 #include "Commands.h"
@@ -122,6 +125,13 @@ BFilePanel::Show()
                // window in a different workspace, reopen in current
                fWindow->SetWorkspaces(workspace);
 
+       // Position the file panel like an alert
+       BWindow* parent =
+               
dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL)));
+       const BRect frame = parent != NULL ? parent->Frame()
+               : BScreen(fWindow).Frame();
+       fWindow->MoveTo(dynamic_cast<BWindow*>(fWindow)->AlertPosition(frame));
+
        if (!IsShowing())
                fWindow->Show();
 

############################################################################

Commit:      d4d842b4ed4556f5c9b2ea98681ba8f27f087ea6
URL:         http://cgit.haiku-os.org/haiku/commit/?id=d4d842b
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Wed May  1 00:07:08 2013 UTC

Style fix in BAlert, some sort of strange spaces got in there

----------------------------------------------------------------------------

diff --git a/src/kits/interface/Alert.cpp b/src/kits/interface/Alert.cpp
index 476f353..16231f5 100644
--- a/src/kits/interface/Alert.cpp
+++ b/src/kits/interface/Alert.cpp
@@ -406,9 +406,9 @@ BAlert::AlertPosition(float width, float height)
                
dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL)));
 
        BScreen screen(window);
-       BRect screenFrame(0, 0, 640, 480);
-       if (screen.IsValid())
-               screenFrame = screen.Frame();
+       BRect screenFrame(0, 0, 640, 480);
+       if (screen.IsValid())
+               screenFrame = screen.Frame();
 
        // Horizontally, we're smack in the middle
        result.x = screenFrame.left + (screenFrame.Width() / 2.0) - (width / 
2.0);

############################################################################

Revision:    hrev45590
Commit:      f3decd20605e769ce37ef3dd2bfa71bb9c196a81
URL:         http://cgit.haiku-os.org/haiku/commit/?id=f3decd2
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Wed May  1 00:14:33 2013 UTC

Ticket:      https://dev.haiku-os.org/ticket/9726

Fix #9726 Revert CenterIn() and CenterOnScreen()

... back to their previous void returning roles. AlertPosition() is used 
instead to
check that an alert fits within the sides of the screen and all that.

Also add another CenterOnScreen() method that takes a Screen ID
so you can center a window on another monitor that the one it is currently on
(theoretically someday anyway).

----------------------------------------------------------------------------

diff --git a/headers/os/interface/Window.h b/headers/os/interface/Window.h
index 02b2cde..3be13e9 100644
--- a/headers/os/interface/Window.h
+++ b/headers/os/interface/Window.h
@@ -166,8 +166,9 @@ public:
                        void                            ResizeBy(float dx, 
float dy);
                        void                            ResizeTo(float width, 
float height);
 
-                       BPoint                          CenterIn(const BRect& 
rect);
-                       BPoint                          CenterOnScreen();
+                       void                            CenterIn(const BRect& 
rect);
+                       void                            CenterOnScreen();
+                       void                            
CenterOnScreen(screen_id id);
 
        virtual void                            Show();
        virtual void                            Hide();
diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp
index fd77d14..06d3c20 100644
--- a/src/kits/interface/Window.cpp
+++ b/src/kits/interface/Window.cpp
@@ -2585,61 +2585,38 @@ BWindow::ResizeTo(float width, float height)
 
 
 /*!
-       \brief Center the window in the passed in rectangular area.
+       \brief Center the window in the passed in \a rect.
        \param rect The rectangle to center the window in.
-       \return The new window position.
 */
-BPoint
+void
 BWindow::CenterIn(const BRect& rect)
 {
        // Set size limits now if needed
        UpdateSizeLimits();
 
-       BPoint point = BLayoutUtils::AlignInFrame(rect, Size(),
+       MoveTo(BLayoutUtils::AlignInFrame(rect, Size(),
                BAlignment(B_ALIGN_HORIZONTAL_CENTER,
-                       B_ALIGN_VERTICAL_CENTER)).LeftTop();
-
-       BRect screenFrame = (BScreen(this)).Frame();
-       if (screenFrame == rect) {
-               // if rect is the screen frame we can skip the ajustments below
-               MoveTo(point);
-               return point;
-       }
-
-       float borderWidth;
-       float tabHeight;
-       _GetDecoratorSize(&borderWidth, &tabHeight);
-
-       // clip the x position within the horizontal edges of the screen
-       if (point.x < screenFrame.left + borderWidth)
-               point.x = screenFrame.left + borderWidth;
-       else if (point.x + Frame().Width() > screenFrame.right - borderWidth)
-               point.x = screenFrame.right - borderWidth - Frame().Width();
-
-       // If the window is covering the window tab lower it down
-       if (point.y < rect.LeftTop().y + borderWidth)
-               point.y = rect.LeftTop().y + borderWidth;
-
-       // clip the y position within the vertical edges of the screen
-       if (point.y < screenFrame.top + borderWidth)
-               point.y = screenFrame.top + borderWidth;
-       else if (point.y + Frame().Height() > screenFrame.bottom - borderWidth)
-               point.y = screenFrame.bottom - borderWidth - Frame().Height();
-
-       MoveTo(point);
-       return point;
+                       B_ALIGN_VERTICAL_CENTER)).LeftTop());
 }
 
 
 /*!
        \brief Centers the window on the screen the window is currently on.
-       \return The new window position.
 */
-BPoint
+void
 BWindow::CenterOnScreen()
 {
-       BScreen screen(this);
-       return CenterIn(screen.Frame());
+       CenterIn(BScreen(this).Frame());
+}
+
+
+/*!
+       \brief Centers the window on the screen with the passed in \a id.
+*/
+void
+BWindow::CenterOnScreen(screen_id id)
+{
+       CenterIn(BScreen(id).Frame());
 }
 
 


Other related posts:

  • » [haiku-commits] haiku: hrev45590 - src/kits/interface src/kits/tracker headers/os/interface src/apps/stylededit - jscipione