[haiku-commits] r42975 - haiku/trunk/src/apps/launchbox

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 29 Oct 2011 21:31:30 +0200 (CEST)

Author: stippi
Date: 2011-10-29 21:31:29 +0200 (Sat, 29 Oct 2011)
New Revision: 42975
Changeset: https://dev.haiku-os.org/changeset/42975

Modified:
   haiku/trunk/src/apps/launchbox/App.cpp
   haiku/trunk/src/apps/launchbox/App.h
   haiku/trunk/src/apps/launchbox/MainWindow.cpp
   haiku/trunk/src/apps/launchbox/MainWindow.h
   haiku/trunk/src/apps/launchbox/NamePanel.cpp
   haiku/trunk/src/apps/launchbox/NamePanel.h
Log:
Place the button description window near the mouse and to
the side of the pad window that has enough room (preferring
right/bottom side of pad). The algorithm doesn't strictly
prevent the window to be placed outside of the screen in any
and all situations, but it should work pretty well in
practice.


Modified: haiku/trunk/src/apps/launchbox/App.cpp
===================================================================
--- haiku/trunk/src/apps/launchbox/App.cpp      2011-10-29 18:47:21 UTC (rev 
42974)
+++ haiku/trunk/src/apps/launchbox/App.cpp      2011-10-29 19:31:29 UTC (rev 
42975)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2009, Stephan Aßmus <superstippi@xxxxxx>.
+ * Copyright 2006-2011, Stephan Aßmus <superstippi@xxxxxx>.
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 
@@ -22,7 +22,8 @@
 App::App()
        :
        BApplication("application/x-vnd.Haiku-LaunchBox"),
-       fSettingsChanged(false)
+       fSettingsChanged(false),
+       fNamePanelSize(200, 50)
 {
        SetPulseRate(3000000);
 }
@@ -47,7 +48,7 @@
        bool windowAdded = false;
        BRect frame(50.0, 50.0, 65.0, 100.0);
 
-       BMessage settings('sett');
+       BMessage settings;
        status_t status = load_settings(&settings, "main_settings", 
"LaunchBox");
        if (status >= B_OK) {
                BMessage windowMessage;
@@ -65,8 +66,11 @@
                        frame.OffsetBy(10.0, 10.0);
                        windowMessage.MakeEmpty();
                }
+               BSize size;
+               if (settings.FindSize("name panel size", &size) == B_OK)
+                       fNamePanelSize = size;
        }
-       
+
        if (!windowAdded) {
                MainWindow* window = new MainWindow(B_TRANSLATE("Pad 1"), 
frame, true);
                window->Show();
@@ -111,6 +115,28 @@
 
 
 void
+App::SetNamePanelSize(const BSize& size)
+{
+       if (Lock()) {
+               fNamePanelSize = size;
+               Unlock();
+       }
+}
+
+
+BSize
+App::NamePanelSize()
+{
+       BSize size;
+       if (Lock()) {
+               size = fNamePanelSize;
+               Unlock();
+       }
+       return size;
+}
+
+
+void
 App::_StoreSettingsIfNeeded()
 {
        if (!fSettingsChanged)
@@ -127,6 +153,8 @@
                        }
                }
        }
+       settings.AddSize("name panel size", fNamePanelSize);
+
        save_settings(&settings, "main_settings", "LaunchBox");
 
        fSettingsChanged = false;

Modified: haiku/trunk/src/apps/launchbox/App.h
===================================================================
--- haiku/trunk/src/apps/launchbox/App.h        2011-10-29 18:47:21 UTC (rev 
42974)
+++ haiku/trunk/src/apps/launchbox/App.h        2011-10-29 19:31:29 UTC (rev 
42975)
@@ -1,15 +1,19 @@
 /*
- * Copyright 2006-2009, Stephan Aßmus <superstippi@xxxxxx>.
+ * Copyright 2006-2011, Stephan Aßmus <superstippi@xxxxxx>.
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 #ifndef APP_H
 #define APP_H
 
+
 #include <Application.h>
 #include <List.h>
+#include <Size.h>
 
+
 class MainWindow;
 
+
 class App : public BApplication {
 public:
                                                                App();
@@ -20,10 +24,16 @@
        virtual void                            MessageReceived(BMessage* 
message);
        virtual void                            Pulse();
 
+                       void                            SetNamePanelSize(const 
BSize& size);
+                       BSize                           NamePanelSize();
+
 private:
                        void                            
_StoreSettingsIfNeeded();
 
                        bool                            fSettingsChanged;
+
+                       BSize                           fNamePanelSize;
 };
 
+
 #endif // APP_H

Modified: haiku/trunk/src/apps/launchbox/MainWindow.cpp
===================================================================
--- haiku/trunk/src/apps/launchbox/MainWindow.cpp       2011-10-29 18:47:21 UTC 
(rev 42974)
+++ haiku/trunk/src/apps/launchbox/MainWindow.cpp       2011-10-29 19:31:29 UTC 
(rev 42975)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006 - 2009, Stephan Aßmus <superstippi@xxxxxx>.
+ * Copyright 2006 - 2011, Stephan Aßmus <superstippi@xxxxxx>.
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 
@@ -20,6 +20,7 @@
 
 #include "support.h"
 
+#include "App.h"
 #include "LaunchButton.h"
 #include "NamePanel.h"
 #include "PadView.h"
@@ -36,7 +37,6 @@
                B_ALL_WORKSPACES),
        fSettings(new BMessage('sett')),
        fPadView(new PadView("pad view")),
-       fNamePanelFrame(-1000.0, -1000.0, -800.0, -900.0),
        fAutoRaise(false),
        fShowOnAllWorkspaces(true)
 {
@@ -65,7 +65,6 @@
                B_ALL_WORKSPACES),
        fSettings(settings),
        fPadView(new PadView("pad view")),
-       fNamePanelFrame(-1000.0, -1000.0, -900.0, -900.0),
        fAutoRaise(false),
        fShowOnAllWorkspaces(true)
 {
@@ -206,17 +205,52 @@
                                if (message->FindString("name", &name) >= B_OK) 
{
                                        // message comes from a previous name 
panel
                                        button->SetDescription(name);
-                                       message->FindRect("frame", 
&fNamePanelFrame);
+                                       BRect namePanelFrame;
+                                       if (message->FindRect("frame", 
&namePanelFrame) == B_OK) {
+                                               
((App*)be_app)->SetNamePanelSize(
+                                                       namePanelFrame.Size());
+                                       }
                                } else {
                                        // message comes from pad view
                                        entry_ref* ref = button->Ref();
                                        if (ref) {
                                                BString 
helper(B_TRANSLATE("Description for '%3'"));
                                                helper.ReplaceFirst("%3", 
ref->name);
-                                               
make_sure_frame_is_on_screen(fNamePanelFrame, this);
-                                               new NamePanel(helper.String(), 
button->Description(),
-                                                       this, this, new 
BMessage(*message),
-                                                       fNamePanelFrame);
+                                               // Place the name panel besides 
the pad, but give it
+                                               // the user configured size.
+                                               BPoint origin = B_ORIGIN;
+                                               BSize size = 
((App*)be_app)->NamePanelSize();
+                                               NamePanel* panel = new 
NamePanel(helper.String(),
+                                                       button->Description(), 
this, this,
+                                                       new BMessage(*message), 
size);
+                                               panel->Layout(true);
+                                               size = panel->Frame().Size();
+                                               BScreen screen(this);
+                                               BPoint mousePos;
+                                               uint32 buttons;
+                                               fPadView->GetMouse(&mousePos, 
&buttons, false);
+                                               
fPadView->ConvertToScreen(&mousePos);
+                                               if (fPadView->Orientation() == 
B_HORIZONTAL) {
+                                                       // Place above or below 
the pad
+                                                       origin.x = mousePos.x - 
size.width / 2;
+                                                       if 
(screen.Frame().bottom - Frame().bottom
+                                                                       > 
size.height + 20) {
+                                                               origin.y = 
Frame().bottom + 10;
+                                                       } else {
+                                                               origin.y = 
Frame().top - 10 - size.height;
+                                                       }
+                                               } else {
+                                                       // Place left or right 
of the pad
+                                                       origin.y = mousePos.y - 
size.height / 2;
+                                                       if 
(screen.Frame().right - Frame().right
+                                                                       > 
size.width + 20) {
+                                                               origin.x = 
Frame().right + 10;
+                                                       } else {
+                                                               origin.x = 
Frame().left - 10 - size.width;
+                                                       }
+                                               }
+                                               panel->MoveTo(origin);
+                                               panel->Show();
                                        }
                                }
                        }
@@ -344,14 +378,6 @@
                }
        }
 
-       // restore name panel frame
-       if (message->FindRect("name panel frame", &frame) == B_OK) {
-               if (frame.IsValid()) {
-                       make_sure_frame_is_on_screen(frame, this);
-                       fNamePanelFrame = frame;
-               }
-       }
-
        // restore window look
        window_look look;
        if (message->FindInt32("window look", (int32*)&look) == B_OK)
@@ -429,14 +455,10 @@
        if (message->ReplaceFloat("border distance", fBorderDist) != B_OK)
                message->AddFloat("border distance", fBorderDist);
 
-       // store window frame
+       // store window frame and look
        if (message->ReplaceRect("window frame", Frame()) != B_OK)
                message->AddRect("window frame", Frame());
 
-       // store name panel frame
-       if (message->ReplaceRect("name panel frame", fNamePanelFrame) != B_OK)
-               message->AddRect("name panel frame", fNamePanelFrame);
-
        if (message->ReplaceInt32("window look", Look()) != B_OK)
                message->AddInt32("window look", Look());
 

Modified: haiku/trunk/src/apps/launchbox/MainWindow.h
===================================================================
--- haiku/trunk/src/apps/launchbox/MainWindow.h 2011-10-29 18:47:21 UTC (rev 
42974)
+++ haiku/trunk/src/apps/launchbox/MainWindow.h 2011-10-29 19:31:29 UTC (rev 
42975)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2009, Stephan Aßmus <superstippi@xxxxxx>.
+ * Copyright 2006-2011, Stephan Aßmus <superstippi@xxxxxx>.
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 #ifndef MAIN_WINDOW_H
@@ -73,8 +73,6 @@
                        BPoint                          fScreenPosition;
                                // not really the position, 0...1 = left...right
 
-                       BRect                           fNamePanelFrame;
-
                        bool                            fAutoRaise;
                        bool                            fShowOnAllWorkspaces;
 };

Modified: haiku/trunk/src/apps/launchbox/NamePanel.cpp
===================================================================
--- haiku/trunk/src/apps/launchbox/NamePanel.cpp        2011-10-29 18:47:21 UTC 
(rev 42974)
+++ haiku/trunk/src/apps/launchbox/NamePanel.cpp        2011-10-29 19:31:29 UTC 
(rev 42975)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2009, Stephan Aßmus <superstippi@xxxxxx>.
+ * Copyright 2006-2011, Stephan Aßmus <superstippi@xxxxxx>.
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 
@@ -15,16 +15,18 @@
 
 #undef B_TRANSLATE_CONTEXT
 #define B_TRANSLATE_CONTEXT "LaunchBox"
+
+
 enum {
        MSG_PANEL_OK,
        MSG_PANEL_CANCEL,
 };
 
-// constructor
+
 NamePanel::NamePanel(const char* label, const char* text, BWindow* window,
-               BHandler* target, BMessage* message, BRect frame)
+               BHandler* target, BMessage* message, const BSize& size)
        :
-       Panel(frame, B_TRANSLATE("Name Panel"),
+       Panel(BRect(B_ORIGIN, size), B_TRANSLATE("Name Panel"),
                B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL,
                B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE
                        | B_AUTO_UPDATE_SIZE_LIMITS),
@@ -37,6 +39,10 @@
        BButton* cancelButton = new BButton(B_TRANSLATE("Cancel"),
                new BMessage(MSG_PANEL_CANCEL));
        fNameTC = new BTextControl(label, text, NULL);
+       BLayoutItem* inputItem = fNameTC->CreateTextViewLayoutItem();
+       inputItem->SetExplicitMinSize(
+               BSize(fNameTC->StringWidth("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"),
+                       B_SIZE_UNSET));
 
        BLayoutBuilder::Group<>(this, B_VERTICAL, 10)
                .AddGlue()
@@ -47,7 +53,7 @@
 
                        // text control
                        .Add(fNameTC->CreateLabelLayoutItem())
-                       .Add(fNameTC->CreateTextViewLayoutItem())
+                       .Add(inputItem)
                        .AddStrut(5)
                        .End()
 
@@ -74,11 +80,6 @@
        }       
 
        AddToSubset(fWindow);
-
-       if (!frame.IsValid())
-               CenterOnScreen();
-
-       Show();
 }
 
 

Modified: haiku/trunk/src/apps/launchbox/NamePanel.h
===================================================================
--- haiku/trunk/src/apps/launchbox/NamePanel.h  2011-10-29 18:47:21 UTC (rev 
42974)
+++ haiku/trunk/src/apps/launchbox/NamePanel.h  2011-10-29 19:31:29 UTC (rev 
42975)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2009, Stephan Aßmus <superstippi@xxxxxx>.
+ * Copyright 2006-2011, Stephan Aßmus <superstippi@xxxxxx>.
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 #ifndef NAME_PANEL_H
@@ -11,12 +11,9 @@
 
 class NamePanel : public Panel {
 public:
-                                                       NamePanel(const char* 
label,
-                                                                         const 
char* text,
-                                                                         
BWindow* window,
-                                                                         
BHandler* target,
-                                                                         
BMessage* message,
-                                                                         BRect 
frame = BRect(-1000.0, -1000.0, -900.0, -900.0));
+                                                       NamePanel(const char* 
label, const char* text,
+                                                               BWindow* 
window, BHandler* target,
+                                                               BMessage* 
message, const BSize& size);
        virtual                                 ~NamePanel();
 
        virtual void                    MessageReceived(BMessage *message);


Other related posts:

  • » [haiku-commits] r42975 - haiku/trunk/src/apps/launchbox - superstippi