* 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
This commit is contained in:
Stephan Aßmus
2009-09-18 09:53:19 +00:00
parent 92c015e696
commit 9368e58be4
10 changed files with 156 additions and 135 deletions
+46 -25
View File
@@ -1,12 +1,8 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006-2009, Stephan Aßmus <[email protected]>.
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/ */
#include "App.h" #include "App.h"
#include <stdio.h> #include <stdio.h>
@@ -21,37 +17,28 @@
#include "MainWindow.h" #include "MainWindow.h"
// constructor
App::App() App::App()
: BApplication("application/x-vnd.Haiku-LaunchBox") :
BApplication("application/x-vnd.Haiku-LaunchBox"),
fSettingsChanged(false)
{ {
SetPulseRate(3000000);
} }
// destructor
App::~App() App::~App()
{ {
} }
// QuitRequested
bool bool
App::QuitRequested() App::QuitRequested()
{ {
BMessage settings('sett'); _StoreSettingsIfNeeded();
for (int32 i = 0; BWindow* window = WindowAt(i); i++) {
if (MainWindow* padWindow = dynamic_cast<MainWindow*>(window)) {
BMessage* windowSettings = padWindow->Settings();
if (windowSettings && padWindow->Lock()) {
padWindow->SaveSettings(windowSettings);
padWindow->Unlock();
settings.AddMessage("window", windowSettings);
}
}
}
save_settings(&settings, "main_settings", "LaunchBox");
return true; return true;
} }
// ReadyToRun
void void
App::ReadyToRun() App::ReadyToRun()
{ {
@@ -80,7 +67,7 @@ App::ReadyToRun()
} }
} }
// MessageReceived
void void
App::MessageReceived(BMessage* message) App::MessageReceived(BMessage* message)
{ {
@@ -95,15 +82,19 @@ App::MessageReceived(BMessage* message)
if (wasCloned) if (wasCloned)
window->MoveBy(10, 10); window->MoveBy(10, 10);
window->Show(); window->Show();
fSettingsChanged = true;
break; break;
} }
case MSG_SETTINGS_CHANGED:
fSettingsChanged = true;
break;
default: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
break; break;
} }
} }
// AboutRequested
void void
App::AboutRequested() App::AboutRequested()
{ {
@@ -112,3 +103,33 @@ App::AboutRequested()
authors[1] = NULL; authors[1] = NULL;
(new BAboutWindow("LaunchBox", 2004, authors))->Show(); (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<MainWindow*>(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;
}
+8 -7
View File
@@ -1,9 +1,6 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006-2009, Stephan Aßmus <[email protected]>.
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/ */
#ifndef APP_H #ifndef APP_H
#define APP_H #define APP_H
@@ -14,7 +11,7 @@
class MainWindow; class MainWindow;
class App : public BApplication { class App : public BApplication {
public: public:
App(); App();
virtual ~App(); virtual ~App();
@@ -22,8 +19,12 @@ class App : public BApplication {
virtual void ReadyToRun(); virtual void ReadyToRun();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void AboutRequested(); virtual void AboutRequested();
virtual void Pulse();
private: private:
void _StoreSettingsIfNeeded();
bool fSettingsChanged;
}; };
#endif // APP_H #endif // APP_H
+25 -20
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2006 - 2009, Stephan Aßmus <[email protected]> * Copyright 2006-2009, Stephan Aßmus <[email protected]>
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
@@ -9,6 +9,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <Application.h>
#include <AppDefs.h> #include <AppDefs.h>
#include <AppFileInfo.h> #include <AppFileInfo.h>
#include <Bitmap.h> #include <Bitmap.h>
@@ -19,13 +20,13 @@
#include <Roster.h> #include <Roster.h>
#include <Window.h> #include <Window.h>
//#include "BubbleHelper.h"
#include "PadView.h" #include "PadView.h"
#include "MainWindow.h"
static const float kDragStartDist = 10.0; static const float kDragStartDist = 10.0;
static const float kDragBitmapAlphaScale = 0.6; 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 bigtime_t
@@ -37,13 +38,14 @@ LaunchButton::sIgnoreDoubleClick = true;
LaunchButton::LaunchButton(const char* name, uint32 id, const char* label, LaunchButton::LaunchButton(const char* name, uint32 id, const char* label,
BMessage* message, BHandler* target) BMessage* message, BHandler* target)
: IconButton(name, id, label, message, target), :
fRef(NULL), IconButton(name, id, label, message, target),
fAppSig(NULL), fRef(NULL),
fDescription(""), fAppSig(NULL),
fAnticipatingDrop(false), fDescription(""),
fLastClickTime(0), fAnticipatingDrop(false),
fIconSize(DEFAULT_ICON_SIZE) fLastClickTime(0),
fIconSize(DEFAULT_ICON_SIZE)
{ {
if (sClickSpeed == 0 || get_click_speed(&sClickSpeed) != B_OK) if (sClickSpeed == 0 || get_click_speed(&sClickSpeed) != B_OK)
sClickSpeed = 500000; sClickSpeed = 500000;
@@ -65,19 +67,12 @@ LaunchButton::AttachedToWindow()
} }
void
LaunchButton::DetachedFromWindow()
{
// BubbleHelper::Default()->SetHelp(this, NULL);
}
void void
LaunchButton::Draw(BRect updateRect) LaunchButton::Draw(BRect updateRect)
{ {
if (fAnticipatingDrop) { if (fAnticipatingDrop) {
rgb_color color = fRef ? ui_color(B_KEYBOARD_NAVIGATION_COLOR) rgb_color color = fRef ? ui_color(B_KEYBOARD_NAVIGATION_COLOR)
: (rgb_color){ 0, 130, 60, 255 }; : (rgb_color){ 0, 130, 60, 255 };
SetHighColor(color); SetHighColor(color);
// limit clipping region to exclude the blue rect we just drew // limit clipping region to exclude the blue rect we just drew
BRect r(Bounds()); BRect r(Bounds());
@@ -317,6 +312,7 @@ LaunchButton::SetTo(const entry_ref* ref)
ClearIcon(); ClearIcon();
} }
_UpdateToolTip(); _UpdateToolTip();
_NotifySettingsChanged();
} }
@@ -340,6 +336,7 @@ LaunchButton::SetTo(const char* appSig, bool updateIcon)
} }
} }
_UpdateToolTip(); _UpdateToolTip();
_NotifySettingsChanged();
} }
@@ -348,6 +345,7 @@ LaunchButton::SetDescription(const char* text)
{ {
fDescription.SetTo(text); fDescription.SetTo(text);
_UpdateToolTip(); _UpdateToolTip();
_NotifySettingsChanged();
} }
@@ -393,9 +391,9 @@ LaunchButton::_UpdateToolTip()
helper << "\n\n" << info.short_info; helper << "\n\n" << info.short_info;
} }
} }
// BubbleHelper::Default()->SetHelp(this, helper.String()); SetToolTip(helper.String());
} else { } else {
// BubbleHelper::Default()->SetHelp(this, kEmptyHelpString); SetToolTip(kEmptyHelpString);
} }
} }
@@ -412,3 +410,10 @@ LaunchButton::_UpdateIcon(const entry_ref* ref)
delete icon; delete icon;
} }
void
LaunchButton::_NotifySettingsChanged()
{
be_app->PostMessage(MSG_SETTINGS_CHANGED);
}
+4 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2006 - 2009, Stephan Aßmus <[email protected]> * Copyright 2006-2009, Stephan Aßmus <[email protected]>
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
#ifndef LAUNCH_BUTTON_H #ifndef LAUNCH_BUTTON_H
@@ -27,7 +27,6 @@ public:
// IconButton interface // IconButton interface
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void DetachedFromWindow();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
@@ -59,10 +58,12 @@ public:
static bool IgnoreDoubleClick() static bool IgnoreDoubleClick()
{ return sIgnoreDoubleClick; } { return sIgnoreDoubleClick; }
private: private:
void _UpdateToolTip(); void _UpdateToolTip();
void _UpdateIcon(const entry_ref* ref); void _UpdateIcon(const entry_ref* ref);
void _NotifySettingsChanged();
entry_ref* fRef; entry_ref* fRef;
char* fAppSig; char* fAppSig;
BString fDescription; BString fDescription;
+14 -3
View File
@@ -209,7 +209,6 @@ MainWindow::MessageReceived(BMessage* message)
if (ref) { if (ref) {
BString helper("Description for '"); BString helper("Description for '");
helper << ref->name << "'"; helper << ref->name << "'";
// BRect* frame = fNamePanelFrame.IsValid() ? &fNamePanelFrame : NULL;
new NamePanel(helper.String(), button->Description(), new NamePanel(helper.String(), button->Description(),
this, this, new BMessage(*message), this, this, new BMessage(*message),
fNamePanelFrame); fNamePanelFrame);
@@ -286,16 +285,20 @@ MainWindow::WorkspaceActivated(int32 workspace, bool active)
void void
MainWindow::FrameMoved(BPoint origin) MainWindow::FrameMoved(BPoint origin)
{ {
if (IsActive()) if (IsActive()) {
_GetLocation(); _GetLocation();
_NotifySettingsChanged();
}
} }
void void
MainWindow::FrameResized(float width, float height) MainWindow::FrameResized(float width, float height)
{ {
if (IsActive()) if (IsActive()) {
_GetLocation(); _GetLocation();
_NotifySettingsChanged();
}
BWindow::FrameResized(width, height); BWindow::FrameResized(width, height);
} }
@@ -308,6 +311,8 @@ MainWindow::ToggleAutoRaise()
fPadView->SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY); fPadView->SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
else else
fPadView->SetEventMask(0); fPadView->SetEventMask(0);
_NotifySettingsChanged();
} }
@@ -600,3 +605,9 @@ MainWindow::_AddEmptyButtons()
} }
void
MainWindow::_NotifySettingsChanged()
{
be_app->PostMessage(MSG_SETTINGS_CHANGED);
}
+4 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2006 - 2009, Stephan Aßmus <[email protected]>. * Copyright 2006-2009, Stephan Aßmus <[email protected]>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
#ifndef MAIN_WINDOW_H #ifndef MAIN_WINDOW_H
@@ -20,6 +20,7 @@ enum {
MSG_SET_DESCRIPTION = 'dscr', MSG_SET_DESCRIPTION = 'dscr',
MSG_ADD_WINDOW = 'addw', MSG_ADD_WINDOW = 'addw',
MSG_SETTINGS_CHANGED = 'stch',
}; };
@@ -62,6 +63,8 @@ private:
void _AddDefaultButtons(); void _AddDefaultButtons();
void _AddEmptyButtons(); void _AddEmptyButtons();
void _NotifySettingsChanged();
BMessage* fSettings; BMessage* fSettings;
PadView* fPadView; PadView* fPadView;
int32 fLastID; int32 fLastID;
+20 -50
View File
@@ -1,9 +1,6 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006-2009, Stephan Aßmus <[email protected]>.
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/ */
#include <stdio.h> #include <stdio.h>
@@ -22,21 +19,20 @@ enum {
}; };
// constructor // constructor
NamePanel::NamePanel(const char* label, NamePanel::NamePanel(const char* label, const char* text, BWindow* window,
const char* text, BHandler* target, BMessage* message, BRect frame)
BWindow *window, :
BHandler* target, Panel(frame, "Name Panel",
BMessage* message, B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL,
BRect frame) B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE
: Panel(frame, "Name Panel", | B_AUTO_UPDATE_SIZE_LIMITS),
B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL, fWindow(window),
B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE), fTarget(target),
fWindow(window), fMessage(message)
fTarget(target),
fMessage(message)
{ {
BButton* defaultButton = new BButton("Ok", new BMessage(MSG_PANEL_OK)); 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); fNameTC = new BTextControl(label, text, NULL);
BView* topView = BGroupLayoutBuilder(B_VERTICAL, 10) BView* topView = BGroupLayoutBuilder(B_VERTICAL, 10)
@@ -80,18 +76,14 @@ NamePanel::NamePanel(const char* label,
} }
AddToSubset(fWindow); AddToSubset(fWindow);
Hide();
if (!frame.IsValid())
CenterOnScreen();
Show(); Show();
if (Lock()) {
frame = _CalculateFrame(Frame());
MoveTo(frame.LeftTop());
// ResizeTo(frame.Width(), frame.Height());
Show();
Unlock();
}
} }
// destructor
NamePanel::~NamePanel() NamePanel::~NamePanel()
{ {
if (fWindow && fWindow->Lock()) { if (fWindow && fWindow->Lock()) {
@@ -101,7 +93,7 @@ NamePanel::~NamePanel()
delete fMessage; delete fMessage;
} }
// MessageReceived
void NamePanel::MessageReceived(BMessage* message) void NamePanel::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
@@ -125,25 +117,3 @@ void NamePanel::MessageReceived(BMessage* message)
Panel::MessageReceived(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;
}
+4 -10
View File
@@ -1,11 +1,7 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006-2009, Stephan Aßmus <[email protected]>.
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/ */
#ifndef NAME_PANEL_H #ifndef NAME_PANEL_H
#define NAME_PANEL_H #define NAME_PANEL_H
@@ -14,7 +10,7 @@
class BTextControl; class BTextControl;
class NamePanel : public Panel { class NamePanel : public Panel {
public: public:
NamePanel(const char* label, NamePanel(const char* label,
const char* text, const char* text,
BWindow* window, BWindow* window,
@@ -25,9 +21,7 @@ class NamePanel : public Panel {
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
private: private:
BRect _CalculateFrame(BRect frame);
BTextControl* fNameTC; BTextControl* fNameTC;
BWindow* fWindow; BWindow* fWindow;
BHandler* fTarget; BHandler* fTarget;
+28 -15
View File
@@ -1,9 +1,6 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006-2009, Stephan Aßmus <[email protected]>.
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/ */
#include "PadView.h" #include "PadView.h"
@@ -282,13 +279,18 @@ PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton)
fButtonLayout->AddView(fButtonLayout->IndexOfView(beforeButton), button); fButtonLayout->AddView(fButtonLayout->IndexOfView(beforeButton), button);
else else
fButtonLayout->AddView(button); fButtonLayout->AddView(button);
_NotifySettingsChanged();
} }
bool bool
PadView::RemoveButton(LaunchButton* button) 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); menu->AddItem(item);
// button options // button options
if (button) { if (button) {
// remove button // clear button
message = new BMessage(MSG_CLEAR_SLOT); message = new BMessage(MSG_CLEAR_SLOT);
message->AddPointer("be:source", (void*)button); message->AddPointer("be:source", (void*)button);
item = new BMenuItem("Clear Button", message); item = new BMenuItem("Clear Button", message);
@@ -335,14 +337,14 @@ PadView::DisplayMenu(BPoint where, LaunchButton* button) const
item = new BMenuItem("Remove Button", message); item = new BMenuItem("Remove Button", message);
item->SetTarget(window); item->SetTarget(window);
menu->AddItem(item); menu->AddItem(item);
// TODO: disabled because Haiku does not yet support tool tips // set button description
// if (button->Ref()) { if (button->Ref()) {
// message = new BMessage(MSG_SET_DESCRIPTION); message = new BMessage(MSG_SET_DESCRIPTION);
// message->AddPointer("be:source", (void*)button); message->AddPointer("be:source", (void*)button);
// item = new BMenuItem("Set Description"B_UTF8_ELLIPSIS, message); item = new BMenuItem("Set Description"B_UTF8_ELLIPSIS, message);
// item->SetTarget(window); item->SetTarget(window);
// menu->AddItem(item); menu->AddItem(item);
// } }
} }
menu->AddSeparatorItem(); menu->AddSeparatorItem();
// window settings // window settings
@@ -447,6 +449,7 @@ PadView::SetOrientation(enum orientation orientation)
fButtonLayout->SetInsets(7, 2, 2, 2); fButtonLayout->SetInsets(7, 2, 2, 2);
fButtonLayout->SetOrientation(B_HORIZONTAL); fButtonLayout->SetOrientation(B_HORIZONTAL);
} }
_NotifySettingsChanged();
} }
@@ -467,6 +470,8 @@ PadView::SetIconSize(uint32 size)
for (int32 i = 0; LaunchButton* button = ButtonAt(i); i++) for (int32 i = 0; LaunchButton* button = ButtonAt(i); i++)
button->SetIconSize(fIconSize); button->SetIconSize(fIconSize);
_NotifySettingsChanged();
} }
@@ -481,6 +486,8 @@ void
PadView::SetIgnoreDoubleClick(bool refuse) PadView::SetIgnoreDoubleClick(bool refuse)
{ {
LaunchButton::SetIgnoreDoubleClick(refuse); LaunchButton::SetIgnoreDoubleClick(refuse);
_NotifySettingsChanged();
} }
@@ -491,3 +498,9 @@ PadView::IgnoreDoubleClick() const
} }
void
PadView::_NotifySettingsChanged()
{
be_app->PostMessage(MSG_SETTINGS_CHANGED);
}
+3 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2006 - 2009, Stephan Aßmus <[email protected]> * Copyright 2006-2009, Stephan Aßmus <[email protected]>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
#ifndef PAD_VIEW_H #ifndef PAD_VIEW_H
@@ -44,6 +44,8 @@ public:
bool IgnoreDoubleClick() const; bool IgnoreDoubleClick() const;
private: private:
void _NotifySettingsChanged();
BPoint fDragOffset; BPoint fDragOffset;
bool fDragging; bool fDragging;
bigtime_t fClickTime; bigtime_t fClickTime;