From 8d1863708046e19583d17c048b0ca3c7058d98fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 21 Apr 2009 21:39:14 +0000 Subject: [PATCH] * Added setting for "Ignore Double Click". I assumed it to be the desired behavior to ignore double clicks in case someone did it out of habbit, but wouldn't expect an app to launch twice because of that. However, some people may want the plain/straight button behavior, as testified in #3800. :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30307 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/launchbox/LaunchButton.cpp | 18 ++++-- src/apps/launchbox/LaunchButton.h | 7 +- src/apps/launchbox/MainWindow.cpp | 99 ++++++++++++++++------------- src/apps/launchbox/MainWindow.h | 34 +++++----- src/apps/launchbox/PadView.cpp | 64 ++++++++++++++----- src/apps/launchbox/PadView.h | 3 + 6 files changed, 140 insertions(+), 85 deletions(-) diff --git a/src/apps/launchbox/LaunchButton.cpp b/src/apps/launchbox/LaunchButton.cpp index 461e18e8bb..081692629f 100644 --- a/src/apps/launchbox/LaunchButton.cpp +++ b/src/apps/launchbox/LaunchButton.cpp @@ -29,7 +29,10 @@ static const float kDragBitmapAlphaScale = 0.6; bigtime_t -LaunchButton::fClickSpeed = 0; +LaunchButton::sClickSpeed = 0; + +bool +LaunchButton::sIgnoreDoubleClick = true; LaunchButton::LaunchButton(const char* name, uint32 id, const char* label, @@ -42,8 +45,8 @@ LaunchButton::LaunchButton(const char* name, uint32 id, const char* label, fLastClickTime(0), fIconSize(DEFAULT_ICON_SIZE) { - if (fClickSpeed == 0 || get_click_speed(&fClickSpeed) != B_OK) - fClickSpeed = 500000; + if (sClickSpeed == 0 || get_click_speed(&sClickSpeed) != B_OK) + sClickSpeed = 500000; } @@ -159,7 +162,7 @@ LaunchButton::MouseDown(BPoint where) { bigtime_t now = system_time(); bool callInherited = true; - if (now - fLastClickTime < fClickSpeed) + if (sIgnoreDoubleClick && now - fLastClickTime < sClickSpeed) callInherited = false; fLastClickTime = now; if (BMessage* message = Window()->CurrentMessage()) { @@ -362,6 +365,13 @@ LaunchButton::SetIconSize(uint32 size) } +void +LaunchButton::SetIgnoreDoubleClick(bool refuse) +{ + sIgnoreDoubleClick = refuse; +} + + // #pragma mark - diff --git a/src/apps/launchbox/LaunchButton.h b/src/apps/launchbox/LaunchButton.h index 4433191431..3697b78042 100644 --- a/src/apps/launchbox/LaunchButton.h +++ b/src/apps/launchbox/LaunchButton.h @@ -55,6 +55,10 @@ public: uint32 IconSize() const { return fIconSize; } + static void SetIgnoreDoubleClick(bool refuse); + static bool IgnoreDoubleClick() + { return sIgnoreDoubleClick; } + private: void _UpdateToolTip(); void _UpdateIcon(const entry_ref* ref); @@ -69,7 +73,8 @@ public: uint32 fIconSize; - static bigtime_t fClickSpeed; + static bigtime_t sClickSpeed; + static bool sIgnoreDoubleClick; }; #endif // LAUNCH_BUTTON_H diff --git a/src/apps/launchbox/MainWindow.cpp b/src/apps/launchbox/MainWindow.cpp index 6e0bab03cf..250520a183 100644 --- a/src/apps/launchbox/MainWindow.cpp +++ b/src/apps/launchbox/MainWindow.cpp @@ -1,9 +1,6 @@ /* - * Copyright 2006-2008, Haiku Inc. All rights reserved. - * 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 "MainWindow.h" @@ -26,19 +23,20 @@ #include "NamePanel.h" #include "PadView.h" -// constructor + MainWindow::MainWindow(const char* name, BRect frame, bool addDefaultButtons) - : BWindow(frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, - B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE - | B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION - | B_AUTO_UPDATE_SIZE_LIMITS | B_SAME_POSITION_IN_ALL_WORKSPACES, - B_ALL_WORKSPACES), - fSettings(new BMessage('sett')), - fPadView(new PadView("pad view")), - fLastID(0), - fNamePanelFrame(-1000.0, -1000.0, -800.0, -900.0), - fAutoRaise(false), - fShowOnAllWorkspaces(true) + : + BWindow(frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, + B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE + | B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION + | B_AUTO_UPDATE_SIZE_LIMITS | B_SAME_POSITION_IN_ALL_WORKSPACES, + B_ALL_WORKSPACES), + fSettings(new BMessage('sett')), + fPadView(new PadView("pad view")), + fLastID(0), + fNamePanelFrame(-1000.0, -1000.0, -800.0, -900.0), + fAutoRaise(false), + fShowOnAllWorkspaces(true) { bool buttonsAdded = false; if (load_settings(fSettings, "main_settings", "LaunchBox") >= B_OK) @@ -54,20 +52,21 @@ MainWindow::MainWindow(const char* name, BRect frame, bool addDefaultButtons) AddChild(fPadView); } -// constructor + MainWindow::MainWindow(const char* name, BRect frame, BMessage* settings) - : BWindow(frame, name, - B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, - B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE - | B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION - | B_AUTO_UPDATE_SIZE_LIMITS | B_SAME_POSITION_IN_ALL_WORKSPACES, - B_ALL_WORKSPACES), - fSettings(settings), - fPadView(new PadView("pad view")), - fLastID(0), - fNamePanelFrame(-1000.0, -1000.0, -900.0, -900.0), - fAutoRaise(false), - fShowOnAllWorkspaces(true) + : + BWindow(frame, name, + B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, + B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE + | B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION + | B_AUTO_UPDATE_SIZE_LIMITS | B_SAME_POSITION_IN_ALL_WORKSPACES, + B_ALL_WORKSPACES), + fSettings(settings), + fPadView(new PadView("pad view")), + fLastID(0), + fNamePanelFrame(-1000.0, -1000.0, -900.0, -900.0), + fAutoRaise(false), + fShowOnAllWorkspaces(true) { if (!LoadSettings(settings)) _AddEmptyButtons(); @@ -77,13 +76,12 @@ MainWindow::MainWindow(const char* name, BRect frame, BMessage* settings) } -// destructor MainWindow::~MainWindow() { delete fSettings; } -// QuitRequested + bool MainWindow::QuitRequested() { @@ -105,7 +103,7 @@ MainWindow::QuitRequested() return true; } -// MessageReceived + void MainWindow::MessageReceived(BMessage* message) { @@ -257,7 +255,7 @@ MainWindow::MessageReceived(BMessage* message) } } -// Show + void MainWindow::Show() { @@ -265,14 +263,14 @@ MainWindow::Show() _GetLocation(); } -// ScreenChanged + void MainWindow::ScreenChanged(BRect frame, color_space format) { _AdjustLocation(Frame()); } -// WorkspaceActivated + void MainWindow::WorkspaceActivated(int32 workspace, bool active) { @@ -284,7 +282,7 @@ MainWindow::WorkspaceActivated(int32 workspace, bool active) } } -// FrameMoved + void MainWindow::FrameMoved(BPoint origin) { @@ -292,7 +290,7 @@ MainWindow::FrameMoved(BPoint origin) _GetLocation(); } -// FrameResized + void MainWindow::FrameResized(float width, float height) { @@ -301,7 +299,7 @@ MainWindow::FrameResized(float width, float height) BWindow::FrameResized(width, height); } -// ToggleAutoRaise + void MainWindow::ToggleAutoRaise() { @@ -312,7 +310,7 @@ MainWindow::ToggleAutoRaise() fPadView->SetEventMask(0); } -// LoadSettings + bool MainWindow::LoadSettings(const BMessage* message) { @@ -362,6 +360,11 @@ MainWindow::LoadSettings(const BMessage* message) if (message->FindInt32("icon size", &iconSize) == B_OK) fPadView->SetIconSize(iconSize); + // restore ignore double click + bool ignoreDoubleClick; + if (message->FindBool("ignore double click", &ignoreDoubleClick) == B_OK) + fPadView->SetIgnoreDoubleClick(ignoreDoubleClick); + // restore buttons const char* path; bool buttonAdded = false; @@ -406,7 +409,7 @@ MainWindow::LoadSettings(const BMessage* message) return buttonAdded; } -// SaveSettings + void MainWindow::SaveSettings(BMessage* message) { @@ -439,6 +442,12 @@ MainWindow::SaveSettings(BMessage* message) if (message->ReplaceInt32("icon size", fPadView->IconSize()) != B_OK) message->AddInt32("icon size", fPadView->IconSize()); + // store ignore double click + if (message->ReplaceBool("ignore double click", + fPadView->IgnoreDoubleClick()) != B_OK) { + message->AddBool("ignore double click", fPadView->IgnoreDoubleClick()); + } + // store buttons message->RemoveName("path"); message->RemoveName("description"); @@ -468,7 +477,7 @@ MainWindow::SaveSettings(BMessage* message) message->AddInt32("workspaces", Workspaces()); } -// _GetLocation + void MainWindow::_GetLocation() { @@ -495,7 +504,7 @@ MainWindow::_GetLocation() } } -// _AdjustLocation + void MainWindow::_AdjustLocation(BRect frame) { @@ -532,7 +541,7 @@ MainWindow::_AdjustLocation(BRect frame) ResizeTo(frame.Width(), frame.Height()); } -// _AddDefaultButtons + void MainWindow::_AddDefaultButtons() { @@ -573,7 +582,7 @@ MainWindow::_AddDefaultButtons() button->SetTo("application/x-vnd.Haiku-Terminal", true); } -// _AddEmptyButtons + void MainWindow::_AddEmptyButtons() { diff --git a/src/apps/launchbox/MainWindow.h b/src/apps/launchbox/MainWindow.h index dcda3fa6b8..0c32f7741c 100644 --- a/src/apps/launchbox/MainWindow.h +++ b/src/apps/launchbox/MainWindow.h @@ -1,16 +1,13 @@ /* - * 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 MAIN_WINDOW_H #define MAIN_WINDOW_H #include + class PadView; enum { @@ -25,8 +22,9 @@ enum { MSG_ADD_WINDOW = 'addw', }; + class MainWindow : public BWindow { - public: +public: MainWindow(const char* name, BRect frame, bool addDefaultButtons = false); MainWindow(const char* name, BRect frame, @@ -41,8 +39,7 @@ class MainWindow : public BWindow { virtual void ScreenChanged(BRect frame, color_space format); virtual void WorkspaceActivated(int32 workspace, bool active); virtual void FrameMoved(BPoint origin); - virtual void FrameResized(float width, - float height); + virtual void FrameResized(float width, float height); // MainWindow void ToggleAutoRaise(); @@ -59,23 +56,24 @@ class MainWindow : public BWindow { BMessage* Settings() const { return fSettings; } - private: +private: void _GetLocation(); void _AdjustLocation(BRect frame); void _AddDefaultButtons(); void _AddEmptyButtons(); - BMessage* fSettings; - PadView* fPadView; - int32 fLastID; + BMessage* fSettings; + PadView* fPadView; + int32 fLastID; - float fBorderDist; - BPoint fScreenPosition; // not really the position, 0...1 = left...right + float fBorderDist; + BPoint fScreenPosition; + // not really the position, 0...1 = left...right - BRect fNamePanelFrame; + BRect fNamePanelFrame; - bool fAutoRaise; - bool fShowOnAllWorkspaces; + bool fAutoRaise; + bool fShowOnAllWorkspaces; }; #endif // MAIN_WINDOW_H diff --git a/src/apps/launchbox/PadView.cpp b/src/apps/launchbox/PadView.cpp index b80a26157f..85f05fbdfd 100644 --- a/src/apps/launchbox/PadView.cpp +++ b/src/apps/launchbox/PadView.cpp @@ -22,15 +22,18 @@ #include "LaunchButton.h" #include "MainWindow.h" + static bigtime_t sActivationDelay = 40000; static const uint32 kIconSizes[] = { 16, 20, 24, 32, 40, 48, 64 }; + enum { MSG_TOGGLE_LAYOUT = 'tgll', - MSG_SET_ICON_SIZE = 'stis' + MSG_SET_ICON_SIZE = 'stis', + MSG_SET_IGNORE_DOUBLECLICK = 'strd' }; -// constructor + PadView::PadView(const char* name) : BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE, NULL), fDragging(false), @@ -46,12 +49,12 @@ PadView::PadView(const char* name) SetLayout(fButtonLayout); } -// destructor + PadView::~PadView() { } -// Draw + void PadView::Draw(BRect updateRect) { @@ -127,7 +130,7 @@ PadView::Draw(BRect updateRect) FillRect(r, B_SOLID_LOW); } -// MessageReceived + void PadView::MessageReceived(BMessage* message) { @@ -141,18 +144,24 @@ PadView::MessageReceived(BMessage* message) fButtonLayout->SetOrientation(B_HORIZONTAL); } break; + case MSG_SET_ICON_SIZE: uint32 size; if (message->FindInt32("size", (int32*)&size) == B_OK) SetIconSize(size); break; + + case MSG_SET_IGNORE_DOUBLECLICK: + SetIgnoreDoubleClick(!IgnoreDoubleClick()); + break; + default: BView::MessageReceived(message); break; } } -// MouseDown + void PadView::MouseDown(BPoint where) { @@ -205,7 +214,7 @@ PadView::MouseDown(BPoint where) } } -// MouseUp + void PadView::MouseUp(BPoint where) { @@ -220,7 +229,7 @@ PadView::MouseUp(BPoint where) fDragging = false; } -// MouseMoved + void PadView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) { @@ -241,7 +250,8 @@ PadView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) bool raise = false; if (fabs(0.5 - position.x) > fabs(0.5 - position.y)) { // left or right border - if (where.y >= windowFrame.top && where.y <= windowFrame.bottom) { + if (where.y >= windowFrame.top + && where.y <= windowFrame.bottom) { if (position.x < 0.5 && where.x == frame.left) raise = true; else if (position.x > 0.5 && where.x == frame.right) @@ -262,7 +272,7 @@ PadView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) } } -// AddButton + void PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton) { @@ -274,21 +284,21 @@ PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton) fButtonLayout->AddView(button); } -// RemoveButton + bool PadView::RemoveButton(LaunchButton* button) { return fButtonLayout->RemoveView(button); } -// ButtonAt + LaunchButton* PadView::ButtonAt(int32 index) const { return dynamic_cast(ChildAt(index)); } -// DisplayMenu + void PadView::DisplayMenu(BPoint where, LaunchButton* button) const { @@ -362,6 +372,12 @@ PadView::DisplayMenu(BPoint where, LaunchButton* button) const } settingsM->AddItem(iconSizeM); + item = new BMenuItem("Ignore Double-click", + new BMessage(MSG_SET_IGNORE_DOUBLECLICK)); + item->SetTarget(this); + item->SetMarked(IgnoreDoubleClick()); + settingsM->AddItem(item); + uint32 what = window->Look() == B_BORDERED_WINDOW_LOOK ? MSG_SHOW_BORDER : MSG_HIDE_BORDER; item = new BMenuItem("Show Window Border", new BMessage(what)); item->SetTarget(window); @@ -420,7 +436,7 @@ PadView::DisplayMenu(BPoint where, LaunchButton* button) const menu->Go(where, true, false, mouseRect, true); } -// SetOrientation + void PadView::SetOrientation(enum orientation orientation) { @@ -433,14 +449,14 @@ PadView::SetOrientation(enum orientation orientation) } } -// Orientation + enum orientation PadView::Orientation() const { return fButtonLayout->Orientation(); } -// SetIconSize + void PadView::SetIconSize(uint32 size) { @@ -453,7 +469,7 @@ PadView::SetIconSize(uint32 size) button->SetIconSize(fIconSize); } -// IconSize + uint32 PadView::IconSize() const { @@ -461,3 +477,17 @@ PadView::IconSize() const } +void +PadView::SetIgnoreDoubleClick(bool refuse) +{ + LaunchButton::SetIgnoreDoubleClick(refuse); +} + + +bool +PadView::IgnoreDoubleClick() const +{ + return LaunchButton::IgnoreDoubleClick(); +} + + diff --git a/src/apps/launchbox/PadView.h b/src/apps/launchbox/PadView.h index d62f3a172f..140e828405 100644 --- a/src/apps/launchbox/PadView.h +++ b/src/apps/launchbox/PadView.h @@ -40,6 +40,9 @@ public: void SetIconSize(uint32 size); uint32 IconSize() const; + void SetIgnoreDoubleClick(bool refuse); + bool IgnoreDoubleClick() const; + private: BPoint fDragOffset; bool fDragging;