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

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 29 Apr 2013 02:42:34 +0200 (CEST)

hrev45582 adds 4 changesets to branch 'master'
old head: 292b0d784c8a6326f070fdf877a3a7bcbabd62b6
new head: 72fb3d3984850bbc56838a6fde14f096285201b2
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=72fb3d3+%5E292b0d7

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

65e6ce6: Style changes in Alert and StyledEdit Find Window

54153cc: Update CenterIn() and CenterOnScreen() methods in BWindow
  
  * These methods now return the new point after centering.
  * But more importantly CenterIn() does some new adjustments to keep the window
    position inside the screen edge. If you pass the screen frame into 
CenterIn()
    it skips these adjustments.

e894fbc: Adjust BAlert to position the alert using the revamped 
BWindow::CenterIn() method.
  
  BAlert::AlertPosition() has been superceded by the new BWindow method and 
should
  be considered deprecated. Note that the alert position is not in the direct 
center of the
  screen, it is offset vertically like before.

72fb3d3: Remove the alert dialog adjustements, they are now done in BAlert 
directly
  
  The save panel adjustment has been kept and modified a bit to position the
  window nicely. It too uses the BWindow::CenterIn() method that adjusts based
  on the screen edges.

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

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

5 files changed, 68 insertions(+), 28 deletions(-)
headers/os/interface/Window.h            |  4 +--
src/apps/stylededit/FindWindow.cpp       |  3 +-
src/apps/stylededit/StyledEditWindow.cpp | 17 +++-------
src/kits/interface/Alert.cpp             | 23 +++++++++----
src/kits/interface/Window.cpp            | 49 +++++++++++++++++++++++++---

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

Commit:      65e6ce6d53a03130be27c0d3d9650fe42a3bfc01
URL:         http://cgit.haiku-os.org/haiku/commit/?id=65e6ce6
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Mon Apr 29 00:08:46 2013 UTC

Style changes in Alert and StyledEdit Find Window

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

diff --git a/src/apps/stylededit/FindWindow.cpp 
b/src/apps/stylededit/FindWindow.cpp
index 2f4eb61..20187d7 100644
--- a/src/apps/stylededit/FindWindow.cpp
+++ b/src/apps/stylededit/FindWindow.cpp
@@ -25,6 +25,7 @@
 #undef B_TRANSLATION_CONTEXT
 #define B_TRANSLATION_CONTEXT "FindandReplaceWindow"
 
+
 FindWindow::FindWindow(BRect frame, BHandler* _handler, BString* searchString,
        bool caseState, bool wrapState, bool backState)
        : BWindow(frame, "FindWindow", B_MODAL_WINDOW,
@@ -125,5 +126,3 @@ FindWindow::_SendMessage()
 
        PostMessage(B_QUIT_REQUESTED);
 }
-
-
diff --git a/src/kits/interface/Alert.cpp b/src/kits/interface/Alert.cpp
index ed53bb1..fcd39f9 100644
--- a/src/kits/interface/Alert.cpp
+++ b/src/kits/interface/Alert.cpp
@@ -499,9 +499,11 @@ BAlert::_InitObject(const char* text, const char* button0, 
const char* button1,
                }
        }
 
-       float defaultButtonFrameWidth = -fButtons[buttonCount - 
1]->Bounds().Width() / 2.0f;
+       float defaultButtonFrameWidth
+               = -fButtons[buttonCount - 1]->Bounds().Width() / 2.0f;
        SetDefaultButton(fButtons[buttonCount - 1]);
-       defaultButtonFrameWidth += fButtons[buttonCount - 1]->Bounds().Width() 
/ 2.0f;
+       defaultButtonFrameWidth
+               += fButtons[buttonCount - 1]->Bounds().Width() / 2.0f;
 
        // Layout buttons
 
@@ -525,9 +527,9 @@ BAlert::_InitObject(const char* text, const char* button0, 
const char* button1,
        int32 iconLayoutScale = icon_layout_scale();
        float totalWidth = kRightOffset + fButtons[buttonCount - 
1]->Frame().right
                - defaultButtonFrameWidth - fButtons[0]->Frame().left;
-       if (view->Bitmap()) {
+       if (view->Bitmap())
                totalWidth += (kIconStripeWidth + kWindowIconOffset) * 
iconLayoutScale;
-       } else
+       else
                totalWidth += kWindowMinOffset;
 
        float width = (spacing == B_OFFSET_SPACING
@@ -815,4 +817,3 @@ _BAlertFilter_::Filter(BMessage* msg, BHandler** target)
 
        return B_DISPATCH_MESSAGE;
 }
-

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

Commit:      54153cc8b27318d70d05601ac0024ecbea295b1f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=54153cc
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Mon Apr 29 00:23:23 2013 UTC

Update CenterIn() and CenterOnScreen() methods in BWindow

* These methods now return the new point after centering.
* But more importantly CenterIn() does some new adjustments to keep the window
  position inside the screen edge. If you pass the screen frame into CenterIn()
  it skips these adjustments.

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

diff --git a/headers/os/interface/Window.h b/headers/os/interface/Window.h
index 59f6c5e..5b1d689 100644
--- a/headers/os/interface/Window.h
+++ b/headers/os/interface/Window.h
@@ -166,8 +166,8 @@ public:
                        void                            ResizeBy(float dx, 
float dy);
                        void                            ResizeTo(float width, 
float height);
 
-                       void                            CenterIn(const BRect& 
rect);
-                       void                            CenterOnScreen();
+                       BPoint                          CenterIn(const BRect& 
rect);
+                       BPoint                          CenterOnScreen();
 
        virtual void                            Show();
        virtual void                            Hide();
diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp
index 10cd771..a7ef4a8 100644
--- a/src/kits/interface/Window.cpp
+++ b/src/kits/interface/Window.cpp
@@ -2584,23 +2584,62 @@ BWindow::ResizeTo(float width, float height)
 }
 
 
-void
+/*!
+       \brief Center the window in the passed in rectangular area.
+       \param rect The rectangle to center the window in.
+       \return The new window position.
+*/
+BPoint
 BWindow::CenterIn(const BRect& rect)
 {
        // Set size limits now if needed
        UpdateSizeLimits();
 
-       MoveTo(BLayoutUtils::AlignInFrame(rect, Size(),
+       BPoint point = BLayoutUtils::AlignInFrame(rect, Size(),
                BAlignment(B_ALIGN_HORIZONTAL_CENTER,
-                       B_ALIGN_VERTICAL_CENTER)).LeftTop());
+                       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;
 }
 
 
-void
+/*!
+       \brief Centers the window on the screen the window is currently on.
+       \return The new window position.
+*/
+BPoint
 BWindow::CenterOnScreen()
 {
        BScreen screen(this);
-       CenterIn(screen.Frame());
+       return CenterIn(screen.Frame());
 }
 
 

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

Commit:      e894fbc0ac91379ca471b86399f4d7930a70e8d3
URL:         http://cgit.haiku-os.org/haiku/commit/?id=e894fbc
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Mon Apr 29 00:27:44 2013 UTC

Adjust BAlert to position the alert using the revamped BWindow::CenterIn() 
method.

BAlert::AlertPosition() has been superceded by the new BWindow method and should
be considered deprecated. Note that the alert position is not in the direct 
center of the
screen, it is offset vertically like before.

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

diff --git a/src/kits/interface/Alert.cpp b/src/kits/interface/Alert.cpp
index fcd39f9..ce513cf 100644
--- a/src/kits/interface/Alert.cpp
+++ b/src/kits/interface/Alert.cpp
@@ -396,6 +396,7 @@ BAlert::QuitRequested()
 }
 
 
+// This method is deprecated, do not use
 BPoint
 BAlert::AlertPosition(float width, float height)
 {
@@ -572,7 +573,16 @@ BAlert::_InitObject(const char* text, const char* button0, 
const char* button1,
 
        AddCommonFilter(new(std::nothrow) _BAlertFilter_(this));
 
-       MoveTo(AlertPosition(Frame().Width(), Frame().Height()));
+       // 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 =
+               
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));
 }
 
 

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

Revision:    hrev45582
Commit:      72fb3d3984850bbc56838a6fde14f096285201b2
URL:         http://cgit.haiku-os.org/haiku/commit/?id=72fb3d3
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Mon Apr 29 00:30:01 2013 UTC

Remove the alert dialog adjustements, they are now done in BAlert directly

The save panel adjustment has been kept and modified a bit to position the
window nicely. It too uses the BWindow::CenterIn() method that adjusts based
on the screen edges.

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

diff --git a/src/apps/stylededit/StyledEditWindow.cpp 
b/src/apps/stylededit/StyledEditWindow.cpp
index cf0e856..a16fff5 100644
--- a/src/apps/stylededit/StyledEditWindow.cpp
+++ b/src/apps/stylededit/StyledEditWindow.cpp
@@ -850,11 +850,10 @@ StyledEditWindow::SaveAs(BMessage* message)
        if (message != NULL)
                fSavePanel->SetMessage(message);
 
-       // Move the save panel to the middle of the window
-       fSavePanel->Window()->MoveTo(Frame().LeftTop().x + Frame().Width() / 2
-                       - fSavePanel->Window()->Frame().Width() / 2,
-               Frame().LeftTop().y + Frame().Height() / 4);
-
+       // 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;
 }
@@ -1847,10 +1846,6 @@ StyledEditWindow::_ShowStatistics()
        BAlert* alert = new BAlert("Statistics", result, B_TRANSLATE("OK"), 
NULL,
                NULL, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_INFO_ALERT);
        alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
-       // Move the alert to the middle of the window
-       alert->MoveTo(Frame().LeftTop().x + Frame().Width() / 2
-                       - alert->Frame().Width() / 2,
-               Frame().LeftTop().y + Frame().Height() / 4);
 
        return alert->Go();
 }
@@ -1906,10 +1901,6 @@ StyledEditWindow::_ShowAlert(const BString& text, const 
BString& label,
        BAlert* alert = new BAlert("Alert", text.String(), label.String(), 
button2,
                button3, B_WIDTH_AS_USUAL, spacing, type);
        alert->SetShortcut(0, B_ESCAPE);
-       // Move the alert to the middle of the window
-       alert->MoveTo(Frame().LeftTop().x + Frame().Width() / 2
-                       - alert->Frame().Width() / 2,
-               Frame().LeftTop().y + Frame().Height() / 4);
 
        return alert->Go();
 }


Other related posts: