125648ff0SStephan Aßmus /*
29368e58bSStephan Aßmus * Copyright 2006-2009, Stephan Aßmus <superstippi@gmx.de>.
39368e58bSStephan Aßmus * All rights reserved. Distributed under the terms of the MIT License.
425648ff0SStephan Aßmus */
525648ff0SStephan Aßmus
625648ff0SStephan Aßmus #include "PadView.h"
725648ff0SStephan Aßmus
825648ff0SStephan Aßmus #include <stdio.h>
925648ff0SStephan Aßmus
10e680a439SYatendra Singh #include <Directory.h>
11e680a439SYatendra Singh #include <File.h>
1225648ff0SStephan Aßmus #include <Application.h>
130e07d4c0SAdrien Destugues #include <Catalog.h>
1425648ff0SStephan Aßmus #include <GroupLayout.h>
1525648ff0SStephan Aßmus #include <MenuItem.h>
1625648ff0SStephan Aßmus #include <Message.h>
1725648ff0SStephan Aßmus #include <PopUpMenu.h>
1825648ff0SStephan Aßmus #include <Region.h>
1925648ff0SStephan Aßmus #include <Screen.h>
2025648ff0SStephan Aßmus #include <SpaceLayoutItem.h>
2125648ff0SStephan Aßmus
2225648ff0SStephan Aßmus #include "LaunchButton.h"
2325648ff0SStephan Aßmus #include "MainWindow.h"
24e680a439SYatendra Singh #include "App.h"
2525648ff0SStephan Aßmus
268d186370SStephan Aßmus
27546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
28546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "LaunchBox"
290e07d4c0SAdrien Destugues
300e07d4c0SAdrien Destugues
31a6099ca9SStephan Aßmus static bigtime_t sActivationDelay = 40000;
323b11f603SJaniceTr static const uint32 kIconSizes[] = { 16, 20, 24, 32, 40, 48, 64, 96, 128 };
3325648ff0SStephan Aßmus
348d186370SStephan Aßmus
35f32e3a29SStephan Aßmus enum {
36a6099ca9SStephan Aßmus MSG_TOGGLE_LAYOUT = 'tgll',
378d186370SStephan Aßmus MSG_SET_ICON_SIZE = 'stis',
388d186370SStephan Aßmus MSG_SET_IGNORE_DOUBLECLICK = 'strd'
39f32e3a29SStephan Aßmus };
40f32e3a29SStephan Aßmus
418d186370SStephan Aßmus
PadView(const char * name)4225648ff0SStephan Aßmus PadView::PadView(const char* name)
43f32e3a29SStephan Aßmus : BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE, NULL),
4425648ff0SStephan Aßmus fDragging(false),
45f32e3a29SStephan Aßmus fClickTime(0),
46a6099ca9SStephan Aßmus fButtonLayout(new BGroupLayout(B_VERTICAL, 4)),
47a6099ca9SStephan Aßmus fIconSize(DEFAULT_ICON_SIZE)
4825648ff0SStephan Aßmus {
4925648ff0SStephan Aßmus SetViewColor(B_TRANSPARENT_32_BIT);
5025648ff0SStephan Aßmus SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
51a6099ca9SStephan Aßmus get_click_speed(&sActivationDelay);
5225648ff0SStephan Aßmus
53f32e3a29SStephan Aßmus fButtonLayout->SetInsets(2, 7, 2, 2);
54f32e3a29SStephan Aßmus SetLayout(fButtonLayout);
5525648ff0SStephan Aßmus }
5625648ff0SStephan Aßmus
578d186370SStephan Aßmus
~PadView()5825648ff0SStephan Aßmus PadView::~PadView()
5925648ff0SStephan Aßmus {
6025648ff0SStephan Aßmus }
6125648ff0SStephan Aßmus
628d186370SStephan Aßmus
6325648ff0SStephan Aßmus void
Draw(BRect updateRect)6425648ff0SStephan Aßmus PadView::Draw(BRect updateRect)
6525648ff0SStephan Aßmus {
6625648ff0SStephan Aßmus rgb_color background = LowColor();
6725648ff0SStephan Aßmus rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT);
6825648ff0SStephan Aßmus rgb_color shadow = tint_color(background, B_DARKEN_2_TINT);
6925648ff0SStephan Aßmus BRect r(Bounds());
7025648ff0SStephan Aßmus BeginLineArray(4);
7125648ff0SStephan Aßmus AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), light);
7225648ff0SStephan Aßmus AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), light);
7325648ff0SStephan Aßmus AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), shadow);
7425648ff0SStephan Aßmus AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), shadow);
7525648ff0SStephan Aßmus EndLineArray();
7625648ff0SStephan Aßmus r.InsetBy(1.0, 1.0);
7725648ff0SStephan Aßmus StrokeRect(r, B_SOLID_LOW);
7825648ff0SStephan Aßmus r.InsetBy(1.0, 1.0);
7925648ff0SStephan Aßmus // dots along top
8025648ff0SStephan Aßmus BPoint dot = r.LeftTop();
81f32e3a29SStephan Aßmus int32 current;
82f32e3a29SStephan Aßmus int32 stop;
83f32e3a29SStephan Aßmus BPoint offset;
84f32e3a29SStephan Aßmus BPoint next;
85f32e3a29SStephan Aßmus if (Orientation() == B_VERTICAL) {
86f32e3a29SStephan Aßmus current = (int32)dot.x;
87f32e3a29SStephan Aßmus stop = (int32)r.right;
88f32e3a29SStephan Aßmus offset = BPoint(0, 1);
89f32e3a29SStephan Aßmus next = BPoint(1, -4);
90f32e3a29SStephan Aßmus r.top += 5.0;
91f32e3a29SStephan Aßmus } else {
92f32e3a29SStephan Aßmus current = (int32)dot.y;
93f32e3a29SStephan Aßmus stop = (int32)r.bottom;
94f32e3a29SStephan Aßmus offset = BPoint(1, 0);
95f32e3a29SStephan Aßmus next = BPoint(-4, 1);
96f32e3a29SStephan Aßmus r.left += 5.0;
97f32e3a29SStephan Aßmus }
9825648ff0SStephan Aßmus int32 num = 1;
99f32e3a29SStephan Aßmus while (current <= stop) {
10025648ff0SStephan Aßmus rgb_color col1;
10125648ff0SStephan Aßmus rgb_color col2;
10298dc6a20SOliver Tappe if (num == 1) {
10325648ff0SStephan Aßmus col1 = shadow;
10425648ff0SStephan Aßmus col2 = background;
10598dc6a20SOliver Tappe } else if (num == 2) {
10625648ff0SStephan Aßmus col1 = background;
10725648ff0SStephan Aßmus col2 = light;
10898dc6a20SOliver Tappe } else {
10925648ff0SStephan Aßmus col1 = background;
11025648ff0SStephan Aßmus col2 = background;
11125648ff0SStephan Aßmus num = 0;
11225648ff0SStephan Aßmus }
11325648ff0SStephan Aßmus SetHighColor(col1);
11425648ff0SStephan Aßmus StrokeLine(dot, dot, B_SOLID_HIGH);
11525648ff0SStephan Aßmus SetHighColor(col2);
116f32e3a29SStephan Aßmus dot += offset;
11725648ff0SStephan Aßmus StrokeLine(dot, dot, B_SOLID_HIGH);
118f32e3a29SStephan Aßmus dot += offset;
11925648ff0SStephan Aßmus StrokeLine(dot, dot, B_SOLID_LOW);
120f32e3a29SStephan Aßmus dot += offset;
12125648ff0SStephan Aßmus SetHighColor(col1);
12225648ff0SStephan Aßmus StrokeLine(dot, dot, B_SOLID_HIGH);
123f32e3a29SStephan Aßmus dot += offset;
12425648ff0SStephan Aßmus SetHighColor(col2);
12525648ff0SStephan Aßmus StrokeLine(dot, dot, B_SOLID_HIGH);
12625648ff0SStephan Aßmus // next pixel
12725648ff0SStephan Aßmus num++;
128f32e3a29SStephan Aßmus dot += next;
129f32e3a29SStephan Aßmus current++;
13025648ff0SStephan Aßmus }
13125648ff0SStephan Aßmus FillRect(r, B_SOLID_LOW);
13225648ff0SStephan Aßmus }
13325648ff0SStephan Aßmus
1348d186370SStephan Aßmus
13525648ff0SStephan Aßmus void
MessageReceived(BMessage * message)13625648ff0SStephan Aßmus PadView::MessageReceived(BMessage* message)
13725648ff0SStephan Aßmus {
13825648ff0SStephan Aßmus switch (message->what) {
139f32e3a29SStephan Aßmus case MSG_TOGGLE_LAYOUT:
140f32e3a29SStephan Aßmus if (fButtonLayout->Orientation() == B_HORIZONTAL) {
141f32e3a29SStephan Aßmus fButtonLayout->SetInsets(2, 7, 2, 2);
142f32e3a29SStephan Aßmus fButtonLayout->SetOrientation(B_VERTICAL);
143f32e3a29SStephan Aßmus } else {
144f32e3a29SStephan Aßmus fButtonLayout->SetInsets(7, 2, 2, 2);
145f32e3a29SStephan Aßmus fButtonLayout->SetOrientation(B_HORIZONTAL);
146f32e3a29SStephan Aßmus }
147f32e3a29SStephan Aßmus break;
1488d186370SStephan Aßmus
149a6099ca9SStephan Aßmus case MSG_SET_ICON_SIZE:
150a6099ca9SStephan Aßmus uint32 size;
151a6099ca9SStephan Aßmus if (message->FindInt32("size", (int32*)&size) == B_OK)
152a6099ca9SStephan Aßmus SetIconSize(size);
153a6099ca9SStephan Aßmus break;
1548d186370SStephan Aßmus
1558d186370SStephan Aßmus case MSG_SET_IGNORE_DOUBLECLICK:
1568d186370SStephan Aßmus SetIgnoreDoubleClick(!IgnoreDoubleClick());
1578d186370SStephan Aßmus break;
1588d186370SStephan Aßmus
15925648ff0SStephan Aßmus default:
16025648ff0SStephan Aßmus BView::MessageReceived(message);
16125648ff0SStephan Aßmus break;
16225648ff0SStephan Aßmus }
16325648ff0SStephan Aßmus }
16425648ff0SStephan Aßmus
1658d186370SStephan Aßmus
16625648ff0SStephan Aßmus void
MouseDown(BPoint where)16725648ff0SStephan Aßmus PadView::MouseDown(BPoint where)
16825648ff0SStephan Aßmus {
16980e19252SStephan Aßmus BWindow* window = Window();
17080e19252SStephan Aßmus if (window == NULL)
17180e19252SStephan Aßmus return;
17280e19252SStephan Aßmus
17325648ff0SStephan Aßmus BRegion region;
17425648ff0SStephan Aßmus GetClippingRegion(®ion);
17580e19252SStephan Aßmus if (!region.Contains(where))
17680e19252SStephan Aßmus return;
17780e19252SStephan Aßmus
17825648ff0SStephan Aßmus bool handle = true;
17925648ff0SStephan Aßmus for (int32 i = 0; BView* child = ChildAt(i); i++) {
18025648ff0SStephan Aßmus if (child->Frame().Contains(where)) {
18125648ff0SStephan Aßmus handle = false;
18225648ff0SStephan Aßmus break;
18325648ff0SStephan Aßmus }
18425648ff0SStephan Aßmus }
18580e19252SStephan Aßmus if (!handle)
18680e19252SStephan Aßmus return;
18780e19252SStephan Aßmus
18880e19252SStephan Aßmus BMessage* message = window->CurrentMessage();
18980e19252SStephan Aßmus if (message == NULL)
19080e19252SStephan Aßmus return;
19180e19252SStephan Aßmus
19225648ff0SStephan Aßmus uint32 buttons;
19325648ff0SStephan Aßmus message->FindInt32("buttons", (int32*)&buttons);
19425648ff0SStephan Aßmus if (buttons & B_SECONDARY_MOUSE_BUTTON) {
19525648ff0SStephan Aßmus BRect r = Bounds();
19625648ff0SStephan Aßmus r.InsetBy(2.0, 2.0);
19725648ff0SStephan Aßmus r.top += 6.0;
19825648ff0SStephan Aßmus if (r.Contains(where)) {
19925648ff0SStephan Aßmus DisplayMenu(where);
20025648ff0SStephan Aßmus } else {
20125648ff0SStephan Aßmus // sends the window to the back
20225648ff0SStephan Aßmus window->Activate(false);
20325648ff0SStephan Aßmus }
20425648ff0SStephan Aßmus } else {
205a6099ca9SStephan Aßmus if (system_time() - fClickTime < sActivationDelay) {
20625648ff0SStephan Aßmus window->Minimize(true);
20725648ff0SStephan Aßmus fClickTime = 0;
20825648ff0SStephan Aßmus } else {
20925648ff0SStephan Aßmus window->Activate();
21025648ff0SStephan Aßmus fDragOffset = ConvertToScreen(where) - window->Frame().LeftTop();
21125648ff0SStephan Aßmus fDragging = true;
21225648ff0SStephan Aßmus SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
21325648ff0SStephan Aßmus fClickTime = system_time();
21425648ff0SStephan Aßmus }
21525648ff0SStephan Aßmus }
21625648ff0SStephan Aßmus }
21725648ff0SStephan Aßmus
2188d186370SStephan Aßmus
21925648ff0SStephan Aßmus void
MouseUp(BPoint where)22025648ff0SStephan Aßmus PadView::MouseUp(BPoint where)
22125648ff0SStephan Aßmus {
22225648ff0SStephan Aßmus if (BWindow* window = Window()) {
22325648ff0SStephan Aßmus uint32 buttons;
22425648ff0SStephan Aßmus window->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
22525648ff0SStephan Aßmus if (buttons & B_PRIMARY_MOUSE_BUTTON
226a6099ca9SStephan Aßmus && system_time() - fClickTime < sActivationDelay
22725648ff0SStephan Aßmus && window->IsActive())
22825648ff0SStephan Aßmus window->Activate();
22925648ff0SStephan Aßmus }
23025648ff0SStephan Aßmus fDragging = false;
23125648ff0SStephan Aßmus }
23225648ff0SStephan Aßmus
2338d186370SStephan Aßmus
23425648ff0SStephan Aßmus void
MouseMoved(BPoint where,uint32 transit,const BMessage * dragMessage)23525648ff0SStephan Aßmus PadView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
23625648ff0SStephan Aßmus {
2378eeb005fSStephan Aßmus MainWindow* window = dynamic_cast<MainWindow*>(Window());
2388eeb005fSStephan Aßmus if (window == NULL)
2398eeb005fSStephan Aßmus return;
2408eeb005fSStephan Aßmus
24125648ff0SStephan Aßmus if (fDragging) {
24225648ff0SStephan Aßmus window->MoveTo(ConvertToScreen(where) - fDragOffset);
24325648ff0SStephan Aßmus } else if (window->AutoRaise()) {
24425648ff0SStephan Aßmus where = ConvertToScreen(where);
24525648ff0SStephan Aßmus BScreen screen(window);
24625648ff0SStephan Aßmus BRect frame = screen.Frame();
24725648ff0SStephan Aßmus BRect windowFrame = window->Frame();
24825648ff0SStephan Aßmus if (where.x == frame.left || where.x == frame.right
24925648ff0SStephan Aßmus || where.y == frame.top || where.y == frame.bottom) {
25025648ff0SStephan Aßmus BPoint position = window->ScreenPosition();
25125648ff0SStephan Aßmus bool raise = false;
25225648ff0SStephan Aßmus if (fabs(0.5 - position.x) > fabs(0.5 - position.y)) {
25325648ff0SStephan Aßmus // left or right border
2548d186370SStephan Aßmus if (where.y >= windowFrame.top
2558d186370SStephan Aßmus && where.y <= windowFrame.bottom) {
25625648ff0SStephan Aßmus if (position.x < 0.5 && where.x == frame.left)
25725648ff0SStephan Aßmus raise = true;
25825648ff0SStephan Aßmus else if (position.x > 0.5 && where.x == frame.right)
25925648ff0SStephan Aßmus raise = true;
26025648ff0SStephan Aßmus }
26125648ff0SStephan Aßmus } else {
26225648ff0SStephan Aßmus // top or bottom border
26325648ff0SStephan Aßmus if (where.x >= windowFrame.left && where.x <= windowFrame.right) {
26425648ff0SStephan Aßmus if (position.y < 0.5 && where.y == frame.top)
26525648ff0SStephan Aßmus raise = true;
266a6099ca9SStephan Aßmus else if (position.y > 0.5 && where.y == frame.bottom)
26725648ff0SStephan Aßmus raise = true;
26825648ff0SStephan Aßmus }
26925648ff0SStephan Aßmus }
27025648ff0SStephan Aßmus if (raise)
27125648ff0SStephan Aßmus window->Activate();
27225648ff0SStephan Aßmus }
27325648ff0SStephan Aßmus }
27425648ff0SStephan Aßmus }
27525648ff0SStephan Aßmus
2768d186370SStephan Aßmus
27725648ff0SStephan Aßmus void
AddButton(LaunchButton * button,LaunchButton * beforeButton)27825648ff0SStephan Aßmus PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton)
27925648ff0SStephan Aßmus {
280a6099ca9SStephan Aßmus button->SetIconSize(fIconSize);
281a6099ca9SStephan Aßmus
28225648ff0SStephan Aßmus if (beforeButton)
283f32e3a29SStephan Aßmus fButtonLayout->AddView(fButtonLayout->IndexOfView(beforeButton), button);
28425648ff0SStephan Aßmus else
285f32e3a29SStephan Aßmus fButtonLayout->AddView(button);
2869368e58bSStephan Aßmus
2879368e58bSStephan Aßmus _NotifySettingsChanged();
28825648ff0SStephan Aßmus }
28925648ff0SStephan Aßmus
2908d186370SStephan Aßmus
29125648ff0SStephan Aßmus bool
RemoveButton(LaunchButton * button)29225648ff0SStephan Aßmus PadView::RemoveButton(LaunchButton* button)
29325648ff0SStephan Aßmus {
2949368e58bSStephan Aßmus bool result = fButtonLayout->RemoveView(button);
2959368e58bSStephan Aßmus if (result)
2969368e58bSStephan Aßmus _NotifySettingsChanged();
2979368e58bSStephan Aßmus return result;
29825648ff0SStephan Aßmus }
29925648ff0SStephan Aßmus
3008d186370SStephan Aßmus
30125648ff0SStephan Aßmus LaunchButton*
ButtonAt(int32 index) const30225648ff0SStephan Aßmus PadView::ButtonAt(int32 index) const
30325648ff0SStephan Aßmus {
30470e39d09SStephan Aßmus BLayoutItem* item = fButtonLayout->ItemAt(index);
30570e39d09SStephan Aßmus if (item == NULL)
30670e39d09SStephan Aßmus return NULL;
30770e39d09SStephan Aßmus return dynamic_cast<LaunchButton*>(item->View());
30825648ff0SStephan Aßmus }
30925648ff0SStephan Aßmus
3108d186370SStephan Aßmus
31125648ff0SStephan Aßmus void
DisplayMenu(BPoint where,LaunchButton * button) const31225648ff0SStephan Aßmus PadView::DisplayMenu(BPoint where, LaunchButton* button) const
31325648ff0SStephan Aßmus {
3148eeb005fSStephan Aßmus MainWindow* window = dynamic_cast<MainWindow*>(Window());
3158eeb005fSStephan Aßmus if (window == NULL)
3168eeb005fSStephan Aßmus return;
3178eeb005fSStephan Aßmus
31825648ff0SStephan Aßmus LaunchButton* nearestButton = button;
31925648ff0SStephan Aßmus if (!nearestButton) {
32025648ff0SStephan Aßmus // find the nearest button
32125648ff0SStephan Aßmus for (int32 i = 0; (nearestButton = ButtonAt(i)); i++) {
32225648ff0SStephan Aßmus if (nearestButton->Frame().top > where.y)
32325648ff0SStephan Aßmus break;
32425648ff0SStephan Aßmus }
32525648ff0SStephan Aßmus }
3260e07d4c0SAdrien Destugues BPopUpMenu* menu = new BPopUpMenu(B_TRANSLATE("launch popup"), false, false);
32725648ff0SStephan Aßmus // add button
32825648ff0SStephan Aßmus BMessage* message = new BMessage(MSG_ADD_SLOT);
32925648ff0SStephan Aßmus message->AddPointer("be:source", (void*)nearestButton);
3300e07d4c0SAdrien Destugues BMenuItem* item = new BMenuItem(B_TRANSLATE("Add button here"), message);
33125648ff0SStephan Aßmus item->SetTarget(window);
33225648ff0SStephan Aßmus menu->AddItem(item);
33325648ff0SStephan Aßmus // button options
33425648ff0SStephan Aßmus if (button) {
3359368e58bSStephan Aßmus // clear button
33625648ff0SStephan Aßmus message = new BMessage(MSG_CLEAR_SLOT);
33725648ff0SStephan Aßmus message->AddPointer("be:source", (void*)button);
3380e07d4c0SAdrien Destugues item = new BMenuItem(B_TRANSLATE("Clear button"), message);
33925648ff0SStephan Aßmus item->SetTarget(window);
34025648ff0SStephan Aßmus menu->AddItem(item);
34125648ff0SStephan Aßmus // remove button
34225648ff0SStephan Aßmus message = new BMessage(MSG_REMOVE_SLOT);
34325648ff0SStephan Aßmus message->AddPointer("be:source", (void*)button);
3440e07d4c0SAdrien Destugues item = new BMenuItem(B_TRANSLATE("Remove button"), message);
34525648ff0SStephan Aßmus item->SetTarget(window);
34625648ff0SStephan Aßmus menu->AddItem(item);
347ac966d59SMatt Madia // Open containing folder button
348ac966d59SMatt Madia if (button->Ref() != NULL) {
349ac966d59SMatt Madia message = new BMessage(MSG_OPEN_CONTAINING_FOLDER);
350ac966d59SMatt Madia message->AddPointer("be:source", (void*)button);
351ac966d59SMatt Madia item = new BMenuItem(B_TRANSLATE("Open containing folder"), message);
352ac966d59SMatt Madia item->SetTarget(window);
353ac966d59SMatt Madia menu->AddItem(item);
354ac966d59SMatt Madia }
3559368e58bSStephan Aßmus // set button description
3569368e58bSStephan Aßmus if (button->Ref()) {
3579368e58bSStephan Aßmus message = new BMessage(MSG_SET_DESCRIPTION);
3589368e58bSStephan Aßmus message->AddPointer("be:source", (void*)button);
3590e07d4c0SAdrien Destugues item = new BMenuItem(B_TRANSLATE("Set description" B_UTF8_ELLIPSIS),
3600e07d4c0SAdrien Destugues message);
3619368e58bSStephan Aßmus item->SetTarget(window);
3629368e58bSStephan Aßmus menu->AddItem(item);
3639368e58bSStephan Aßmus }
36425648ff0SStephan Aßmus }
36525648ff0SStephan Aßmus menu->AddSeparatorItem();
36625648ff0SStephan Aßmus // window settings
367c16bcdfcSJoachim Seemer BMenu* settingsM = new BMenu(B_TRANSLATE("Settings"));
36825648ff0SStephan Aßmus settingsM->SetFont(be_plain_font);
36925648ff0SStephan Aßmus
370f32e3a29SStephan Aßmus const char* toggleLayoutLabel;
371f32e3a29SStephan Aßmus if (fButtonLayout->Orientation() == B_HORIZONTAL)
3720e07d4c0SAdrien Destugues toggleLayoutLabel = B_TRANSLATE("Vertical layout");
373f32e3a29SStephan Aßmus else
3740e07d4c0SAdrien Destugues toggleLayoutLabel = B_TRANSLATE("Horizontal layout");
375f32e3a29SStephan Aßmus item = new BMenuItem(toggleLayoutLabel, new BMessage(MSG_TOGGLE_LAYOUT));
376f32e3a29SStephan Aßmus item->SetTarget(this);
377f32e3a29SStephan Aßmus settingsM->AddItem(item);
378f32e3a29SStephan Aßmus
3790e07d4c0SAdrien Destugues BMenu* iconSizeM = new BMenu(B_TRANSLATE("Icon size"));
380a6099ca9SStephan Aßmus for (uint32 i = 0; i < sizeof(kIconSizes) / sizeof(uint32); i++) {
381a6099ca9SStephan Aßmus uint32 iconSize = kIconSizes[i];
382a6099ca9SStephan Aßmus message = new BMessage(MSG_SET_ICON_SIZE);
383a6099ca9SStephan Aßmus message->AddInt32("size", iconSize);
384a6099ca9SStephan Aßmus BString label;
385*3961af9fSHumdinger label.SetToFormat(B_TRANSLATE_COMMENT("%" B_PRId32" × %" B_PRId32,
386*3961af9fSHumdinger "The '×' is the Unicode multiplication sign U+00D7"),
387*3961af9fSHumdinger iconSize, iconSize);
388*3961af9fSHumdinger item = new BMenuItem(label, message);
389a6099ca9SStephan Aßmus item->SetTarget(this);
390a6099ca9SStephan Aßmus item->SetMarked(IconSize() == iconSize);
391a6099ca9SStephan Aßmus iconSizeM->AddItem(item);
392a6099ca9SStephan Aßmus }
393a6099ca9SStephan Aßmus settingsM->AddItem(iconSizeM);
394a6099ca9SStephan Aßmus
3950e07d4c0SAdrien Destugues item = new BMenuItem(B_TRANSLATE("Ignore double-click"),
3968d186370SStephan Aßmus new BMessage(MSG_SET_IGNORE_DOUBLECLICK));
3978d186370SStephan Aßmus item->SetTarget(this);
3988d186370SStephan Aßmus item->SetMarked(IgnoreDoubleClick());
3998d186370SStephan Aßmus settingsM->AddItem(item);
4008d186370SStephan Aßmus
40125648ff0SStephan Aßmus uint32 what = window->Look() == B_BORDERED_WINDOW_LOOK ? MSG_SHOW_BORDER : MSG_HIDE_BORDER;
4020e07d4c0SAdrien Destugues item = new BMenuItem(B_TRANSLATE("Show window border"), new BMessage(what));
40325648ff0SStephan Aßmus item->SetTarget(window);
40425648ff0SStephan Aßmus item->SetMarked(what == MSG_HIDE_BORDER);
40525648ff0SStephan Aßmus settingsM->AddItem(item);
40625648ff0SStephan Aßmus
407e680a439SYatendra Singh item = new BMenuItem(B_TRANSLATE("Autostart"), new BMessage(MSG_TOGGLE_AUTOSTART));
408e680a439SYatendra Singh item->SetTarget(be_app);
409e680a439SYatendra Singh item->SetMarked(((App*)be_app)->AutoStart());
410e680a439SYatendra Singh settingsM->AddItem(item);
411e680a439SYatendra Singh
4120e07d4c0SAdrien Destugues item = new BMenuItem(B_TRANSLATE("Auto-raise"), new BMessage(MSG_TOGGLE_AUTORAISE));
41325648ff0SStephan Aßmus item->SetTarget(window);
41425648ff0SStephan Aßmus item->SetMarked(window->AutoRaise());
41525648ff0SStephan Aßmus settingsM->AddItem(item);
41625648ff0SStephan Aßmus
4170e07d4c0SAdrien Destugues item = new BMenuItem(B_TRANSLATE("Show on all workspaces"), new BMessage(MSG_SHOW_ON_ALL_WORKSPACES));
41825648ff0SStephan Aßmus item->SetTarget(window);
41925648ff0SStephan Aßmus item->SetMarked(window->ShowOnAllWorkspaces());
42025648ff0SStephan Aßmus settingsM->AddItem(item);
42125648ff0SStephan Aßmus
42225648ff0SStephan Aßmus menu->AddItem(settingsM);
42325648ff0SStephan Aßmus
42425648ff0SStephan Aßmus menu->AddSeparatorItem();
42525648ff0SStephan Aßmus
42625648ff0SStephan Aßmus // pad commands
4270e07d4c0SAdrien Destugues BMenu* padM = new BMenu(B_TRANSLATE("Pad"));
42825648ff0SStephan Aßmus padM->SetFont(be_plain_font);
42925648ff0SStephan Aßmus // new pad
4300e07d4c0SAdrien Destugues item = new BMenuItem(B_TRANSLATE("New"), new BMessage(MSG_ADD_WINDOW));
43125648ff0SStephan Aßmus item->SetTarget(be_app);
43225648ff0SStephan Aßmus padM->AddItem(item);
43325648ff0SStephan Aßmus // new pad
4340e07d4c0SAdrien Destugues item = new BMenuItem(B_TRANSLATE("Clone"), new BMessage(MSG_ADD_WINDOW));
43525648ff0SStephan Aßmus item->SetTarget(window);
43625648ff0SStephan Aßmus padM->AddItem(item);
43725648ff0SStephan Aßmus padM->AddSeparatorItem();
43825648ff0SStephan Aßmus // close
4390e07d4c0SAdrien Destugues item = new BMenuItem(B_TRANSLATE("Close"), new BMessage(B_QUIT_REQUESTED));
44025648ff0SStephan Aßmus item->SetTarget(window);
44125648ff0SStephan Aßmus padM->AddItem(item);
44225648ff0SStephan Aßmus menu->AddItem(padM);
44325648ff0SStephan Aßmus // app commands
444560ff447SJonas Sundström BMenu* appM = new BMenu(B_TRANSLATE_SYSTEM_NAME("LaunchBox"));
44525648ff0SStephan Aßmus appM->SetFont(be_plain_font);
44625648ff0SStephan Aßmus // quit
4470e07d4c0SAdrien Destugues item = new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED));
44825648ff0SStephan Aßmus item->SetTarget(be_app);
44925648ff0SStephan Aßmus appM->AddItem(item);
45025648ff0SStephan Aßmus menu->AddItem(appM);
45125648ff0SStephan Aßmus // finish popup
45225648ff0SStephan Aßmus menu->SetAsyncAutoDestruct(true);
45325648ff0SStephan Aßmus menu->SetFont(be_plain_font);
45425648ff0SStephan Aßmus where = ConvertToScreen(where);
45525648ff0SStephan Aßmus BRect mouseRect(where, where);
45625648ff0SStephan Aßmus mouseRect.InsetBy(-4.0, -4.0);
45725648ff0SStephan Aßmus menu->Go(where, true, false, mouseRect, true);
45825648ff0SStephan Aßmus }
45925648ff0SStephan Aßmus
4608d186370SStephan Aßmus
461f32e3a29SStephan Aßmus void
SetOrientation(enum orientation orientation)462f32e3a29SStephan Aßmus PadView::SetOrientation(enum orientation orientation)
463f32e3a29SStephan Aßmus {
464f32e3a29SStephan Aßmus if (orientation == B_VERTICAL) {
465f32e3a29SStephan Aßmus fButtonLayout->SetInsets(2, 7, 2, 2);
466f32e3a29SStephan Aßmus fButtonLayout->SetOrientation(B_VERTICAL);
467f32e3a29SStephan Aßmus } else {
468f32e3a29SStephan Aßmus fButtonLayout->SetInsets(7, 2, 2, 2);
469f32e3a29SStephan Aßmus fButtonLayout->SetOrientation(B_HORIZONTAL);
470f32e3a29SStephan Aßmus }
4719368e58bSStephan Aßmus _NotifySettingsChanged();
472f32e3a29SStephan Aßmus }
473f32e3a29SStephan Aßmus
4748d186370SStephan Aßmus
475f32e3a29SStephan Aßmus enum orientation
Orientation() const476f32e3a29SStephan Aßmus PadView::Orientation() const
477f32e3a29SStephan Aßmus {
478f32e3a29SStephan Aßmus return fButtonLayout->Orientation();
479f32e3a29SStephan Aßmus }
480f32e3a29SStephan Aßmus
4818d186370SStephan Aßmus
482a6099ca9SStephan Aßmus void
SetIconSize(uint32 size)483a6099ca9SStephan Aßmus PadView::SetIconSize(uint32 size)
484a6099ca9SStephan Aßmus {
485a6099ca9SStephan Aßmus if (size == fIconSize)
486a6099ca9SStephan Aßmus return;
487a6099ca9SStephan Aßmus
488a6099ca9SStephan Aßmus fIconSize = size;
489a6099ca9SStephan Aßmus
490a6099ca9SStephan Aßmus for (int32 i = 0; LaunchButton* button = ButtonAt(i); i++)
491a6099ca9SStephan Aßmus button->SetIconSize(fIconSize);
4929368e58bSStephan Aßmus
4939368e58bSStephan Aßmus _NotifySettingsChanged();
494a6099ca9SStephan Aßmus }
495a6099ca9SStephan Aßmus
4968d186370SStephan Aßmus
497a6099ca9SStephan Aßmus uint32
IconSize() const498a6099ca9SStephan Aßmus PadView::IconSize() const
499a6099ca9SStephan Aßmus {
500a6099ca9SStephan Aßmus return fIconSize;
501a6099ca9SStephan Aßmus }
502a6099ca9SStephan Aßmus
503f32e3a29SStephan Aßmus
5048d186370SStephan Aßmus void
SetIgnoreDoubleClick(bool refuse)5058d186370SStephan Aßmus PadView::SetIgnoreDoubleClick(bool refuse)
5068d186370SStephan Aßmus {
5078d186370SStephan Aßmus LaunchButton::SetIgnoreDoubleClick(refuse);
5089368e58bSStephan Aßmus
5099368e58bSStephan Aßmus _NotifySettingsChanged();
5108d186370SStephan Aßmus }
5118d186370SStephan Aßmus
5128d186370SStephan Aßmus
5138d186370SStephan Aßmus bool
IgnoreDoubleClick() const5148d186370SStephan Aßmus PadView::IgnoreDoubleClick() const
5158d186370SStephan Aßmus {
5168d186370SStephan Aßmus return LaunchButton::IgnoreDoubleClick();
5178d186370SStephan Aßmus }
5188d186370SStephan Aßmus
5198d186370SStephan Aßmus
5209368e58bSStephan Aßmus void
_NotifySettingsChanged()5219368e58bSStephan Aßmus PadView::_NotifySettingsChanged()
5229368e58bSStephan Aßmus {
5239368e58bSStephan Aßmus be_app->PostMessage(MSG_SETTINGS_CHANGED);
5249368e58bSStephan Aßmus }
525