diff --git a/src/apps/launchbox/App.cpp b/src/apps/launchbox/App.cpp index f9c0f54620..3481ff0634 100644 --- a/src/apps/launchbox/App.cpp +++ b/src/apps/launchbox/App.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006-2009, Stephan Aßmus . + * Copyright 2006-2011, Stephan Aßmus . * 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 @@ App::ReadyToRun() 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 @@ App::ReadyToRun() 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(); @@ -110,6 +114,28 @@ App::Pulse() } +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() { @@ -127,6 +153,8 @@ App::_StoreSettingsIfNeeded() } } } + settings.AddSize("name panel size", fNamePanelSize); + save_settings(&settings, "main_settings", "LaunchBox"); fSettingsChanged = false; diff --git a/src/apps/launchbox/App.h b/src/apps/launchbox/App.h index 9d2465ad94..12366d19d4 100644 --- a/src/apps/launchbox/App.h +++ b/src/apps/launchbox/App.h @@ -1,15 +1,19 @@ /* - * Copyright 2006-2009, Stephan Aßmus . + * Copyright 2006-2011, Stephan Aßmus . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef APP_H #define APP_H + #include #include +#include + class MainWindow; + class App : public BApplication { public: App(); @@ -20,10 +24,16 @@ public: 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 diff --git a/src/apps/launchbox/MainWindow.cpp b/src/apps/launchbox/MainWindow.cpp index 8499f5abe6..8e6f907c90 100644 --- a/src/apps/launchbox/MainWindow.cpp +++ b/src/apps/launchbox/MainWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006 - 2009, Stephan Aßmus . + * Copyright 2006 - 2011, Stephan Aßmus . * 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 @@ MainWindow::MainWindow(const char* name, BRect frame, bool addDefaultButtons) 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 @@ MainWindow::MainWindow(const char* name, BRect frame, BMessage* settings) 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 @@ MainWindow::MessageReceived(BMessage* message) 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 @@ MainWindow::LoadSettings(const BMessage* message) } } - // 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 @@ MainWindow::SaveSettings(BMessage* message) 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()); diff --git a/src/apps/launchbox/MainWindow.h b/src/apps/launchbox/MainWindow.h index 31a184ad07..50de629b54 100644 --- a/src/apps/launchbox/MainWindow.h +++ b/src/apps/launchbox/MainWindow.h @@ -1,5 +1,5 @@ /* - * Copyright 2006-2009, Stephan Aßmus . + * Copyright 2006-2011, Stephan Aßmus . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef MAIN_WINDOW_H @@ -73,8 +73,6 @@ private: BPoint fScreenPosition; // not really the position, 0...1 = left...right - BRect fNamePanelFrame; - bool fAutoRaise; bool fShowOnAllWorkspaces; }; diff --git a/src/apps/launchbox/NamePanel.cpp b/src/apps/launchbox/NamePanel.cpp index b820dcb0be..db931e7973 100644 --- a/src/apps/launchbox/NamePanel.cpp +++ b/src/apps/launchbox/NamePanel.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006-2009, Stephan Aßmus . + * Copyright 2006-2011, Stephan Aßmus . * 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 @@ NamePanel::NamePanel(const char* label, const char* text, BWindow* window, 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 @@ NamePanel::NamePanel(const char* label, const char* text, BWindow* window, // text control .Add(fNameTC->CreateLabelLayoutItem()) - .Add(fNameTC->CreateTextViewLayoutItem()) + .Add(inputItem) .AddStrut(5) .End() @@ -74,11 +80,6 @@ NamePanel::NamePanel(const char* label, const char* text, BWindow* window, } AddToSubset(fWindow); - - if (!frame.IsValid()) - CenterOnScreen(); - - Show(); } diff --git a/src/apps/launchbox/NamePanel.h b/src/apps/launchbox/NamePanel.h index 2a8d0011e9..386283aaf2 100644 --- a/src/apps/launchbox/NamePanel.h +++ b/src/apps/launchbox/NamePanel.h @@ -1,5 +1,5 @@ /* - * Copyright 2006-2009, Stephan Aßmus . + * Copyright 2006-2011, Stephan Aßmus . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef NAME_PANEL_H @@ -11,12 +11,9 @@ class BTextControl; 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);