From 9368e58be42cdd06d03817d3815a12fbb69e7cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 18 Sep 2009 09:53:19 +0000 Subject: [PATCH] * Re-enabled tool tips as those are now supported in Haiku. * Make sure settings are saved rightaway whenever they change. (Solves a ticket which I cannot seem to find right now.) * Some improvements to the NamePanel layout/size (when setting descriptions). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33167 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/launchbox/App.cpp | 71 +++++++++++++++++++---------- src/apps/launchbox/App.h | 15 +++--- src/apps/launchbox/LaunchButton.cpp | 45 ++++++++++-------- src/apps/launchbox/LaunchButton.h | 7 +-- src/apps/launchbox/MainWindow.cpp | 17 +++++-- src/apps/launchbox/MainWindow.h | 5 +- src/apps/launchbox/NamePanel.cpp | 70 ++++++++-------------------- src/apps/launchbox/NamePanel.h | 14 ++---- src/apps/launchbox/PadView.cpp | 43 +++++++++++------ src/apps/launchbox/PadView.h | 4 +- 10 files changed, 156 insertions(+), 135 deletions(-) diff --git a/src/apps/launchbox/App.cpp b/src/apps/launchbox/App.cpp index 101fbffb03..55832ef46d 100644 --- a/src/apps/launchbox/App.cpp +++ b/src/apps/launchbox/App.cpp @@ -1,12 +1,8 @@ /* - * Copyright 2006, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan Aßmus + * Copyright 2006-2009, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. */ - #include "App.h" #include @@ -21,37 +17,28 @@ #include "MainWindow.h" -// constructor App::App() - : BApplication("application/x-vnd.Haiku-LaunchBox") + : + BApplication("application/x-vnd.Haiku-LaunchBox"), + fSettingsChanged(false) { + SetPulseRate(3000000); } -// destructor + App::~App() { } -// QuitRequested + bool App::QuitRequested() { - BMessage settings('sett'); - for (int32 i = 0; BWindow* window = WindowAt(i); i++) { - if (MainWindow* padWindow = dynamic_cast(window)) { - BMessage* windowSettings = padWindow->Settings(); - if (windowSettings && padWindow->Lock()) { - padWindow->SaveSettings(windowSettings); - padWindow->Unlock(); - settings.AddMessage("window", windowSettings); - } - } - } - save_settings(&settings, "main_settings", "LaunchBox"); + _StoreSettingsIfNeeded(); return true; } -// ReadyToRun + void App::ReadyToRun() { @@ -80,7 +67,7 @@ App::ReadyToRun() } } -// MessageReceived + void App::MessageReceived(BMessage* message) { @@ -95,15 +82,19 @@ App::MessageReceived(BMessage* message) if (wasCloned) window->MoveBy(10, 10); window->Show(); + fSettingsChanged = true; break; } + case MSG_SETTINGS_CHANGED: + fSettingsChanged = true; + break; default: BApplication::MessageReceived(message); break; } } -// AboutRequested + void App::AboutRequested() { @@ -112,3 +103,33 @@ App::AboutRequested() authors[1] = NULL; (new BAboutWindow("LaunchBox", 2004, authors))->Show(); } + + +void +App::Pulse() +{ + _StoreSettingsIfNeeded(); +} + + +void +App::_StoreSettingsIfNeeded() +{ + if (!fSettingsChanged) + return; + + BMessage settings('sett'); + for (int32 i = 0; BWindow* window = WindowAt(i); i++) { + if (MainWindow* padWindow = dynamic_cast(window)) { + BMessage* windowSettings = padWindow->Settings(); + if (windowSettings && padWindow->Lock()) { + padWindow->SaveSettings(windowSettings); + padWindow->Unlock(); + settings.AddMessage("window", windowSettings); + } + } + } + save_settings(&settings, "main_settings", "LaunchBox"); + + fSettingsChanged = false; +} diff --git a/src/apps/launchbox/App.h b/src/apps/launchbox/App.h index 7b59f0dfcf..00a3f75945 100644 --- a/src/apps/launchbox/App.h +++ b/src/apps/launchbox/App.h @@ -1,9 +1,6 @@ /* - * Copyright 2006, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan Aßmus + * Copyright 2006-2009, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef APP_H #define APP_H @@ -14,7 +11,7 @@ class MainWindow; class App : public BApplication { - public: +public: App(); virtual ~App(); @@ -22,8 +19,12 @@ class App : public BApplication { virtual void ReadyToRun(); virtual void MessageReceived(BMessage* message); virtual void AboutRequested(); + virtual void Pulse(); - private: +private: + void _StoreSettingsIfNeeded(); + + bool fSettingsChanged; }; #endif // APP_H diff --git a/src/apps/launchbox/LaunchButton.cpp b/src/apps/launchbox/LaunchButton.cpp index 081692629f..86107930a1 100644 --- a/src/apps/launchbox/LaunchButton.cpp +++ b/src/apps/launchbox/LaunchButton.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006 - 2009, Stephan Aßmus + * Copyright 2006-2009, Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT License. */ @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -19,13 +20,13 @@ #include #include -//#include "BubbleHelper.h" #include "PadView.h" +#include "MainWindow.h" static const float kDragStartDist = 10.0; static const float kDragBitmapAlphaScale = 0.6; -//static const char* kEmptyHelpString = "You can drag an icon here."; +static const char* kEmptyHelpString = "You can drag an icon here."; bigtime_t @@ -37,13 +38,14 @@ LaunchButton::sIgnoreDoubleClick = true; LaunchButton::LaunchButton(const char* name, uint32 id, const char* label, BMessage* message, BHandler* target) - : IconButton(name, id, label, message, target), - fRef(NULL), - fAppSig(NULL), - fDescription(""), - fAnticipatingDrop(false), - fLastClickTime(0), - fIconSize(DEFAULT_ICON_SIZE) + : + IconButton(name, id, label, message, target), + fRef(NULL), + fAppSig(NULL), + fDescription(""), + fAnticipatingDrop(false), + fLastClickTime(0), + fIconSize(DEFAULT_ICON_SIZE) { if (sClickSpeed == 0 || get_click_speed(&sClickSpeed) != B_OK) sClickSpeed = 500000; @@ -65,19 +67,12 @@ LaunchButton::AttachedToWindow() } -void -LaunchButton::DetachedFromWindow() -{ -// BubbleHelper::Default()->SetHelp(this, NULL); -} - - void LaunchButton::Draw(BRect updateRect) { if (fAnticipatingDrop) { rgb_color color = fRef ? ui_color(B_KEYBOARD_NAVIGATION_COLOR) - : (rgb_color){ 0, 130, 60, 255 }; + : (rgb_color){ 0, 130, 60, 255 }; SetHighColor(color); // limit clipping region to exclude the blue rect we just drew BRect r(Bounds()); @@ -317,6 +312,7 @@ LaunchButton::SetTo(const entry_ref* ref) ClearIcon(); } _UpdateToolTip(); + _NotifySettingsChanged(); } @@ -340,6 +336,7 @@ LaunchButton::SetTo(const char* appSig, bool updateIcon) } } _UpdateToolTip(); + _NotifySettingsChanged(); } @@ -348,6 +345,7 @@ LaunchButton::SetDescription(const char* text) { fDescription.SetTo(text); _UpdateToolTip(); + _NotifySettingsChanged(); } @@ -393,9 +391,9 @@ LaunchButton::_UpdateToolTip() helper << "\n\n" << info.short_info; } } -// BubbleHelper::Default()->SetHelp(this, helper.String()); + SetToolTip(helper.String()); } else { -// BubbleHelper::Default()->SetHelp(this, kEmptyHelpString); + SetToolTip(kEmptyHelpString); } } @@ -412,3 +410,10 @@ LaunchButton::_UpdateIcon(const entry_ref* ref) delete icon; } + + +void +LaunchButton::_NotifySettingsChanged() +{ + be_app->PostMessage(MSG_SETTINGS_CHANGED); +} diff --git a/src/apps/launchbox/LaunchButton.h b/src/apps/launchbox/LaunchButton.h index 3697b78042..4d06c0f19a 100644 --- a/src/apps/launchbox/LaunchButton.h +++ b/src/apps/launchbox/LaunchButton.h @@ -1,5 +1,5 @@ /* - * Copyright 2006 - 2009, Stephan Aßmus + * Copyright 2006-2009, Stephan Aßmus * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef LAUNCH_BUTTON_H @@ -27,7 +27,6 @@ public: // IconButton interface virtual void AttachedToWindow(); - virtual void DetachedFromWindow(); virtual void Draw(BRect updateRect); virtual void MessageReceived(BMessage* message); virtual void MouseDown(BPoint where); @@ -59,10 +58,12 @@ public: static bool IgnoreDoubleClick() { return sIgnoreDoubleClick; } - private: +private: void _UpdateToolTip(); void _UpdateIcon(const entry_ref* ref); + void _NotifySettingsChanged(); + entry_ref* fRef; char* fAppSig; BString fDescription; diff --git a/src/apps/launchbox/MainWindow.cpp b/src/apps/launchbox/MainWindow.cpp index 250520a183..d657652241 100644 --- a/src/apps/launchbox/MainWindow.cpp +++ b/src/apps/launchbox/MainWindow.cpp @@ -209,7 +209,6 @@ MainWindow::MessageReceived(BMessage* message) if (ref) { BString helper("Description for '"); helper << ref->name << "'"; -// BRect* frame = fNamePanelFrame.IsValid() ? &fNamePanelFrame : NULL; new NamePanel(helper.String(), button->Description(), this, this, new BMessage(*message), fNamePanelFrame); @@ -286,16 +285,20 @@ MainWindow::WorkspaceActivated(int32 workspace, bool active) void MainWindow::FrameMoved(BPoint origin) { - if (IsActive()) + if (IsActive()) { _GetLocation(); + _NotifySettingsChanged(); + } } void MainWindow::FrameResized(float width, float height) { - if (IsActive()) + if (IsActive()) { _GetLocation(); + _NotifySettingsChanged(); + } BWindow::FrameResized(width, height); } @@ -308,6 +311,8 @@ MainWindow::ToggleAutoRaise() fPadView->SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY); else fPadView->SetEventMask(0); + + _NotifySettingsChanged(); } @@ -600,3 +605,9 @@ MainWindow::_AddEmptyButtons() } +void +MainWindow::_NotifySettingsChanged() +{ + be_app->PostMessage(MSG_SETTINGS_CHANGED); +} + diff --git a/src/apps/launchbox/MainWindow.h b/src/apps/launchbox/MainWindow.h index 0c32f7741c..e85b8d5536 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-2009, Stephan Aßmus . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef MAIN_WINDOW_H @@ -20,6 +20,7 @@ enum { MSG_SET_DESCRIPTION = 'dscr', MSG_ADD_WINDOW = 'addw', + MSG_SETTINGS_CHANGED = 'stch', }; @@ -62,6 +63,8 @@ private: void _AddDefaultButtons(); void _AddEmptyButtons(); + void _NotifySettingsChanged(); + BMessage* fSettings; PadView* fPadView; int32 fLastID; diff --git a/src/apps/launchbox/NamePanel.cpp b/src/apps/launchbox/NamePanel.cpp index 46248b57b2..1777908621 100644 --- a/src/apps/launchbox/NamePanel.cpp +++ b/src/apps/launchbox/NamePanel.cpp @@ -1,9 +1,6 @@ /* - * Copyright 2006, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan Aßmus + * Copyright 2006-2009, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. */ #include @@ -22,21 +19,20 @@ enum { }; // constructor -NamePanel::NamePanel(const char* label, - const char* text, - BWindow *window, - BHandler* target, - BMessage* message, - BRect frame) - : Panel(frame, "Name Panel", - B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL, - B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE), - fWindow(window), - fTarget(target), - fMessage(message) +NamePanel::NamePanel(const char* label, const char* text, BWindow* window, + BHandler* target, BMessage* message, BRect frame) + : + Panel(frame, "Name Panel", + B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL, + B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE + | B_AUTO_UPDATE_SIZE_LIMITS), + fWindow(window), + fTarget(target), + fMessage(message) { BButton* defaultButton = new BButton("Ok", new BMessage(MSG_PANEL_OK)); - BButton* cancelButton = new BButton("Cancel", new BMessage(MSG_PANEL_CANCEL)); + BButton* cancelButton = new BButton("Cancel", + new BMessage(MSG_PANEL_CANCEL)); fNameTC = new BTextControl(label, text, NULL); BView* topView = BGroupLayoutBuilder(B_VERTICAL, 10) @@ -80,18 +76,14 @@ NamePanel::NamePanel(const char* label, } AddToSubset(fWindow); - Hide(); + + if (!frame.IsValid()) + CenterOnScreen(); + Show(); - if (Lock()) { - frame = _CalculateFrame(Frame()); - MoveTo(frame.LeftTop()); -// ResizeTo(frame.Width(), frame.Height()); - Show(); - Unlock(); - } } -// destructor + NamePanel::~NamePanel() { if (fWindow && fWindow->Lock()) { @@ -101,7 +93,7 @@ NamePanel::~NamePanel() delete fMessage; } -// MessageReceived + void NamePanel::MessageReceived(BMessage* message) { switch (message->what) { @@ -125,25 +117,3 @@ void NamePanel::MessageReceived(BMessage* message) Panel::MessageReceived(message); } } - -// _CalculateFrame -BRect -NamePanel::_CalculateFrame(BRect frame) -{ - BScreen screen(this); - BRect screenFrame = screen.Frame(); - if (!frame.IsValid()) - frame.Set(-1000.0, -1000.0, -900.0, -900.0); - if (!screenFrame.Contains(frame)) { - float width = frame.Width(); - float height = frame.Height(); - BPoint center; - center.x = screenFrame.left + screenFrame.Width() / 2.0; - center.y = screenFrame.top + screenFrame.Height() / 4.0; - frame.left = center.x - width / 2.0; - frame.right = frame.left + width; - frame.top = center.y - height / 2.0; - frame.bottom = frame.top + height; - } - return frame; -} diff --git a/src/apps/launchbox/NamePanel.h b/src/apps/launchbox/NamePanel.h index 7ab2f416c1..2a8d0011e9 100644 --- a/src/apps/launchbox/NamePanel.h +++ b/src/apps/launchbox/NamePanel.h @@ -1,11 +1,7 @@ /* - * Copyright 2006, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan Aßmus + * Copyright 2006-2009, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. */ - #ifndef NAME_PANEL_H #define NAME_PANEL_H @@ -14,7 +10,7 @@ class BTextControl; class NamePanel : public Panel { - public: +public: NamePanel(const char* label, const char* text, BWindow* window, @@ -25,9 +21,7 @@ class NamePanel : public Panel { virtual void MessageReceived(BMessage *message); - private: - BRect _CalculateFrame(BRect frame); - +private: BTextControl* fNameTC; BWindow* fWindow; BHandler* fTarget; diff --git a/src/apps/launchbox/PadView.cpp b/src/apps/launchbox/PadView.cpp index 85f05fbdfd..2e90585866 100644 --- a/src/apps/launchbox/PadView.cpp +++ b/src/apps/launchbox/PadView.cpp @@ -1,9 +1,6 @@ /* - * Copyright 2006, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan Aßmus + * Copyright 2006-2009, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. */ #include "PadView.h" @@ -282,13 +279,18 @@ PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton) fButtonLayout->AddView(fButtonLayout->IndexOfView(beforeButton), button); else fButtonLayout->AddView(button); + + _NotifySettingsChanged(); } bool PadView::RemoveButton(LaunchButton* button) { - return fButtonLayout->RemoveView(button); + bool result = fButtonLayout->RemoveView(button); + if (result) + _NotifySettingsChanged(); + return result; } @@ -323,7 +325,7 @@ PadView::DisplayMenu(BPoint where, LaunchButton* button) const menu->AddItem(item); // button options if (button) { - // remove button + // clear button message = new BMessage(MSG_CLEAR_SLOT); message->AddPointer("be:source", (void*)button); item = new BMenuItem("Clear Button", message); @@ -335,14 +337,14 @@ PadView::DisplayMenu(BPoint where, LaunchButton* button) const item = new BMenuItem("Remove Button", message); item->SetTarget(window); menu->AddItem(item); -// TODO: disabled because Haiku does not yet support tool tips -// if (button->Ref()) { -// message = new BMessage(MSG_SET_DESCRIPTION); -// message->AddPointer("be:source", (void*)button); -// item = new BMenuItem("Set Description"B_UTF8_ELLIPSIS, message); -// item->SetTarget(window); -// menu->AddItem(item); -// } + // set button description + if (button->Ref()) { + message = new BMessage(MSG_SET_DESCRIPTION); + message->AddPointer("be:source", (void*)button); + item = new BMenuItem("Set Description"B_UTF8_ELLIPSIS, message); + item->SetTarget(window); + menu->AddItem(item); + } } menu->AddSeparatorItem(); // window settings @@ -447,6 +449,7 @@ PadView::SetOrientation(enum orientation orientation) fButtonLayout->SetInsets(7, 2, 2, 2); fButtonLayout->SetOrientation(B_HORIZONTAL); } + _NotifySettingsChanged(); } @@ -467,6 +470,8 @@ PadView::SetIconSize(uint32 size) for (int32 i = 0; LaunchButton* button = ButtonAt(i); i++) button->SetIconSize(fIconSize); + + _NotifySettingsChanged(); } @@ -481,6 +486,8 @@ void PadView::SetIgnoreDoubleClick(bool refuse) { LaunchButton::SetIgnoreDoubleClick(refuse); + + _NotifySettingsChanged(); } @@ -491,3 +498,9 @@ PadView::IgnoreDoubleClick() const } +void +PadView::_NotifySettingsChanged() +{ + be_app->PostMessage(MSG_SETTINGS_CHANGED); +} + diff --git a/src/apps/launchbox/PadView.h b/src/apps/launchbox/PadView.h index 140e828405..f19a1c3239 100644 --- a/src/apps/launchbox/PadView.h +++ b/src/apps/launchbox/PadView.h @@ -1,5 +1,5 @@ /* - * Copyright 2006 - 2009, Stephan Aßmus + * Copyright 2006-2009, Stephan Aßmus . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef PAD_VIEW_H @@ -44,6 +44,8 @@ public: bool IgnoreDoubleClick() const; private: + void _NotifySettingsChanged(); + BPoint fDragOffset; bool fDragging; bigtime_t fClickTime;