xref: /haiku/src/apps/launchbox/PadView.cpp (revision 9368e58be42cdd06d03817d3815a12fbb69e7cfa)
125648ff0SStephan Aßmus /*
2*9368e58bSStephan Aßmus  * Copyright 2006-2009, Stephan Aßmus <superstippi@gmx.de>.
3*9368e58bSStephan 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 
1025648ff0SStephan Aßmus #include <Application.h>
1125648ff0SStephan Aßmus #include <GroupLayout.h>
1225648ff0SStephan Aßmus #include <MenuItem.h>
1325648ff0SStephan Aßmus #include <Message.h>
1425648ff0SStephan Aßmus #include <PopUpMenu.h>
1525648ff0SStephan Aßmus #include <Region.h>
1625648ff0SStephan Aßmus #include <Screen.h>
1725648ff0SStephan Aßmus #include <SpaceLayoutItem.h>
1825648ff0SStephan Aßmus 
1925648ff0SStephan Aßmus #include "LaunchButton.h"
2025648ff0SStephan Aßmus #include "MainWindow.h"
2125648ff0SStephan Aßmus 
228d186370SStephan Aßmus 
23a6099ca9SStephan Aßmus static bigtime_t sActivationDelay = 40000;
24a6099ca9SStephan Aßmus static const uint32 kIconSizes[] = { 16, 20, 24, 32, 40, 48, 64 };
2525648ff0SStephan Aßmus 
268d186370SStephan Aßmus 
27f32e3a29SStephan Aßmus enum {
28a6099ca9SStephan Aßmus 	MSG_TOGGLE_LAYOUT			= 'tgll',
298d186370SStephan Aßmus 	MSG_SET_ICON_SIZE			= 'stis',
308d186370SStephan Aßmus 	MSG_SET_IGNORE_DOUBLECLICK	= 'strd'
31f32e3a29SStephan Aßmus };
32f32e3a29SStephan Aßmus 
338d186370SStephan Aßmus 
3425648ff0SStephan Aßmus PadView::PadView(const char* name)
35f32e3a29SStephan Aßmus 	: BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE, NULL),
3625648ff0SStephan Aßmus 	  fDragging(false),
37f32e3a29SStephan Aßmus 	  fClickTime(0),
38a6099ca9SStephan Aßmus 	  fButtonLayout(new BGroupLayout(B_VERTICAL, 4)),
39a6099ca9SStephan Aßmus 	  fIconSize(DEFAULT_ICON_SIZE)
4025648ff0SStephan Aßmus {
4125648ff0SStephan Aßmus 	SetViewColor(B_TRANSPARENT_32_BIT);
4225648ff0SStephan Aßmus 	SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
43a6099ca9SStephan Aßmus 	get_click_speed(&sActivationDelay);
4425648ff0SStephan Aßmus 
45f32e3a29SStephan Aßmus 	fButtonLayout->SetInsets(2, 7, 2, 2);
46f32e3a29SStephan Aßmus 	SetLayout(fButtonLayout);
4725648ff0SStephan Aßmus }
4825648ff0SStephan Aßmus 
498d186370SStephan Aßmus 
5025648ff0SStephan Aßmus PadView::~PadView()
5125648ff0SStephan Aßmus {
5225648ff0SStephan Aßmus }
5325648ff0SStephan Aßmus 
548d186370SStephan Aßmus 
5525648ff0SStephan Aßmus void
5625648ff0SStephan Aßmus PadView::Draw(BRect updateRect)
5725648ff0SStephan Aßmus {
5825648ff0SStephan Aßmus 	rgb_color background = LowColor();
5925648ff0SStephan Aßmus 	rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT);
6025648ff0SStephan Aßmus 	rgb_color shadow = tint_color(background, B_DARKEN_2_TINT);
6125648ff0SStephan Aßmus 	BRect r(Bounds());
6225648ff0SStephan Aßmus 	BeginLineArray(4);
6325648ff0SStephan Aßmus 		AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), light);
6425648ff0SStephan Aßmus 		AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), light);
6525648ff0SStephan Aßmus 		AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), shadow);
6625648ff0SStephan Aßmus 		AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), shadow);
6725648ff0SStephan Aßmus 	EndLineArray();
6825648ff0SStephan Aßmus 	r.InsetBy(1.0, 1.0);
6925648ff0SStephan Aßmus 	StrokeRect(r, B_SOLID_LOW);
7025648ff0SStephan Aßmus 	r.InsetBy(1.0, 1.0);
7125648ff0SStephan Aßmus 	// dots along top
7225648ff0SStephan Aßmus 	BPoint dot = r.LeftTop();
73f32e3a29SStephan Aßmus 	int32 current;
74f32e3a29SStephan Aßmus 	int32 stop;
75f32e3a29SStephan Aßmus 	BPoint offset;
76f32e3a29SStephan Aßmus 	BPoint next;
77f32e3a29SStephan Aßmus 	if (Orientation() == B_VERTICAL) {
78f32e3a29SStephan Aßmus 		current = (int32)dot.x;
79f32e3a29SStephan Aßmus 		stop = (int32)r.right;
80f32e3a29SStephan Aßmus 		offset = BPoint(0, 1);
81f32e3a29SStephan Aßmus 		next = BPoint(1, -4);
82f32e3a29SStephan Aßmus 		r.top += 5.0;
83f32e3a29SStephan Aßmus 	} else {
84f32e3a29SStephan Aßmus 		current = (int32)dot.y;
85f32e3a29SStephan Aßmus 		stop = (int32)r.bottom;
86f32e3a29SStephan Aßmus 		offset = BPoint(1, 0);
87f32e3a29SStephan Aßmus 		next = BPoint(-4, 1);
88f32e3a29SStephan Aßmus 		r.left += 5.0;
89f32e3a29SStephan Aßmus 	}
9025648ff0SStephan Aßmus 	int32 num = 1;
91f32e3a29SStephan Aßmus 	while (current <= stop) {
9225648ff0SStephan Aßmus 		rgb_color col1;
9325648ff0SStephan Aßmus 		rgb_color col2;
9425648ff0SStephan Aßmus 		switch (num) {
9525648ff0SStephan Aßmus 			case 1:
9625648ff0SStephan Aßmus 				col1 = shadow;
9725648ff0SStephan Aßmus 				col2 = background;
9825648ff0SStephan Aßmus 				break;
9925648ff0SStephan Aßmus 			case 2:
10025648ff0SStephan Aßmus 				col1 = background;
10125648ff0SStephan Aßmus 				col2 = light;
10225648ff0SStephan Aßmus 				break;
10325648ff0SStephan Aßmus 			case 3:
10425648ff0SStephan Aßmus 				col1 = background;
10525648ff0SStephan Aßmus 				col2 = background;
10625648ff0SStephan Aßmus 				num = 0;
10725648ff0SStephan Aßmus 				break;
10825648ff0SStephan Aßmus 		}
10925648ff0SStephan Aßmus 		SetHighColor(col1);
11025648ff0SStephan Aßmus 		StrokeLine(dot, dot, B_SOLID_HIGH);
11125648ff0SStephan Aßmus 		SetHighColor(col2);
112f32e3a29SStephan Aßmus 		dot += offset;
11325648ff0SStephan Aßmus 		StrokeLine(dot, dot, B_SOLID_HIGH);
114f32e3a29SStephan Aßmus 		dot += offset;
11525648ff0SStephan Aßmus 		StrokeLine(dot, dot, B_SOLID_LOW);
116f32e3a29SStephan Aßmus 		dot += offset;
11725648ff0SStephan Aßmus 		SetHighColor(col1);
11825648ff0SStephan Aßmus 		StrokeLine(dot, dot, B_SOLID_HIGH);
119f32e3a29SStephan Aßmus 		dot += offset;
12025648ff0SStephan Aßmus 		SetHighColor(col2);
12125648ff0SStephan Aßmus 		StrokeLine(dot, dot, B_SOLID_HIGH);
12225648ff0SStephan Aßmus 		// next pixel
12325648ff0SStephan Aßmus 		num++;
124f32e3a29SStephan Aßmus 		dot += next;
125f32e3a29SStephan Aßmus 		current++;
12625648ff0SStephan Aßmus 	}
12725648ff0SStephan Aßmus 	FillRect(r, B_SOLID_LOW);
12825648ff0SStephan Aßmus }
12925648ff0SStephan Aßmus 
1308d186370SStephan Aßmus 
13125648ff0SStephan Aßmus void
13225648ff0SStephan Aßmus PadView::MessageReceived(BMessage* message)
13325648ff0SStephan Aßmus {
13425648ff0SStephan Aßmus 	switch (message->what) {
135f32e3a29SStephan Aßmus 		case MSG_TOGGLE_LAYOUT:
136f32e3a29SStephan Aßmus 			if (fButtonLayout->Orientation() == B_HORIZONTAL) {
137f32e3a29SStephan Aßmus 				fButtonLayout->SetInsets(2, 7, 2, 2);
138f32e3a29SStephan Aßmus 				fButtonLayout->SetOrientation(B_VERTICAL);
139f32e3a29SStephan Aßmus 			} else {
140f32e3a29SStephan Aßmus 				fButtonLayout->SetInsets(7, 2, 2, 2);
141f32e3a29SStephan Aßmus 				fButtonLayout->SetOrientation(B_HORIZONTAL);
142f32e3a29SStephan Aßmus 			}
143f32e3a29SStephan Aßmus 			break;
1448d186370SStephan Aßmus 
145a6099ca9SStephan Aßmus 		case MSG_SET_ICON_SIZE:
146a6099ca9SStephan Aßmus 			uint32 size;
147a6099ca9SStephan Aßmus 			if (message->FindInt32("size", (int32*)&size) == B_OK)
148a6099ca9SStephan Aßmus 				SetIconSize(size);
149a6099ca9SStephan Aßmus 			break;
1508d186370SStephan Aßmus 
1518d186370SStephan Aßmus 		case MSG_SET_IGNORE_DOUBLECLICK:
1528d186370SStephan Aßmus 			SetIgnoreDoubleClick(!IgnoreDoubleClick());
1538d186370SStephan Aßmus 			break;
1548d186370SStephan Aßmus 
15525648ff0SStephan Aßmus 		default:
15625648ff0SStephan Aßmus 			BView::MessageReceived(message);
15725648ff0SStephan Aßmus 			break;
15825648ff0SStephan Aßmus 	}
15925648ff0SStephan Aßmus }
16025648ff0SStephan Aßmus 
1618d186370SStephan Aßmus 
16225648ff0SStephan Aßmus void
16325648ff0SStephan Aßmus PadView::MouseDown(BPoint where)
16425648ff0SStephan Aßmus {
16580e19252SStephan Aßmus 	BWindow* window = Window();
16680e19252SStephan Aßmus 	if (window == NULL)
16780e19252SStephan Aßmus 		return;
16880e19252SStephan Aßmus 
16925648ff0SStephan Aßmus 	BRegion region;
17025648ff0SStephan Aßmus 	GetClippingRegion(&region);
17180e19252SStephan Aßmus 	if (!region.Contains(where))
17280e19252SStephan Aßmus 		return;
17380e19252SStephan Aßmus 
17425648ff0SStephan Aßmus 	bool handle = true;
17525648ff0SStephan Aßmus 	for (int32 i = 0; BView* child = ChildAt(i); i++) {
17625648ff0SStephan Aßmus 		if (child->Frame().Contains(where)) {
17725648ff0SStephan Aßmus 			handle = false;
17825648ff0SStephan Aßmus 			break;
17925648ff0SStephan Aßmus 		}
18025648ff0SStephan Aßmus 	}
18180e19252SStephan Aßmus 	if (!handle)
18280e19252SStephan Aßmus 		return;
18380e19252SStephan Aßmus 
18480e19252SStephan Aßmus 	BMessage* message = window->CurrentMessage();
18580e19252SStephan Aßmus 	if (message == NULL)
18680e19252SStephan Aßmus 		return;
18780e19252SStephan Aßmus 
18825648ff0SStephan Aßmus 	uint32 buttons;
18925648ff0SStephan Aßmus 	message->FindInt32("buttons", (int32*)&buttons);
19025648ff0SStephan Aßmus 	if (buttons & B_SECONDARY_MOUSE_BUTTON) {
19125648ff0SStephan Aßmus 		BRect r = Bounds();
19225648ff0SStephan Aßmus 		r.InsetBy(2.0, 2.0);
19325648ff0SStephan Aßmus 		r.top += 6.0;
19425648ff0SStephan Aßmus 		if (r.Contains(where)) {
19525648ff0SStephan Aßmus 			DisplayMenu(where);
19625648ff0SStephan Aßmus 		} else {
19725648ff0SStephan Aßmus 			// sends the window to the back
19825648ff0SStephan Aßmus 			window->Activate(false);
19925648ff0SStephan Aßmus 		}
20025648ff0SStephan Aßmus 	} else {
201a6099ca9SStephan Aßmus 		if (system_time() - fClickTime < sActivationDelay) {
20225648ff0SStephan Aßmus 			window->Minimize(true);
20325648ff0SStephan Aßmus 			fClickTime = 0;
20425648ff0SStephan Aßmus 		} else {
20525648ff0SStephan Aßmus 			window->Activate();
20625648ff0SStephan Aßmus 			fDragOffset = ConvertToScreen(where) - window->Frame().LeftTop();
20725648ff0SStephan Aßmus 			fDragging = true;
20825648ff0SStephan Aßmus 			SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
20925648ff0SStephan Aßmus 			fClickTime = system_time();
21025648ff0SStephan Aßmus 		}
21125648ff0SStephan Aßmus 	}
21225648ff0SStephan Aßmus }
21325648ff0SStephan Aßmus 
2148d186370SStephan Aßmus 
21525648ff0SStephan Aßmus void
21625648ff0SStephan Aßmus PadView::MouseUp(BPoint where)
21725648ff0SStephan Aßmus {
21825648ff0SStephan Aßmus 	if (BWindow* window = Window()) {
21925648ff0SStephan Aßmus 		uint32 buttons;
22025648ff0SStephan Aßmus 		window->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
22125648ff0SStephan Aßmus 		if (buttons & B_PRIMARY_MOUSE_BUTTON
222a6099ca9SStephan Aßmus 			&& system_time() - fClickTime < sActivationDelay
22325648ff0SStephan Aßmus 			&& window->IsActive())
22425648ff0SStephan Aßmus 			window->Activate();
22525648ff0SStephan Aßmus 	}
22625648ff0SStephan Aßmus 	fDragging = false;
22725648ff0SStephan Aßmus }
22825648ff0SStephan Aßmus 
2298d186370SStephan Aßmus 
23025648ff0SStephan Aßmus void
23125648ff0SStephan Aßmus PadView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
23225648ff0SStephan Aßmus {
2338eeb005fSStephan Aßmus 	MainWindow* window = dynamic_cast<MainWindow*>(Window());
2348eeb005fSStephan Aßmus 	if (window == NULL)
2358eeb005fSStephan Aßmus 		return;
2368eeb005fSStephan Aßmus 
23725648ff0SStephan Aßmus 	if (fDragging) {
23825648ff0SStephan Aßmus 		window->MoveTo(ConvertToScreen(where) - fDragOffset);
23925648ff0SStephan Aßmus 	} else if (window->AutoRaise()) {
24025648ff0SStephan Aßmus 		where = ConvertToScreen(where);
24125648ff0SStephan Aßmus 		BScreen screen(window);
24225648ff0SStephan Aßmus 		BRect frame = screen.Frame();
24325648ff0SStephan Aßmus 		BRect windowFrame = window->Frame();
24425648ff0SStephan Aßmus 		if (where.x == frame.left || where.x == frame.right
24525648ff0SStephan Aßmus 			|| where.y == frame.top || where.y == frame.bottom) {
24625648ff0SStephan Aßmus 			BPoint position = window->ScreenPosition();
24725648ff0SStephan Aßmus 			bool raise = false;
24825648ff0SStephan Aßmus 			if (fabs(0.5 - position.x) > fabs(0.5 - position.y)) {
24925648ff0SStephan Aßmus 				// left or right border
2508d186370SStephan Aßmus 				if (where.y >= windowFrame.top
2518d186370SStephan Aßmus 					&& where.y <= windowFrame.bottom) {
25225648ff0SStephan Aßmus 					if (position.x < 0.5 && where.x == frame.left)
25325648ff0SStephan Aßmus 						raise = true;
25425648ff0SStephan Aßmus 					else if (position.x > 0.5 && where.x == frame.right)
25525648ff0SStephan Aßmus 						raise = true;
25625648ff0SStephan Aßmus 				}
25725648ff0SStephan Aßmus 			} else {
25825648ff0SStephan Aßmus 				// top or bottom border
25925648ff0SStephan Aßmus 				if (where.x >= windowFrame.left && where.x <= windowFrame.right) {
26025648ff0SStephan Aßmus 					if (position.y < 0.5 && where.y == frame.top)
26125648ff0SStephan Aßmus 						raise = true;
262a6099ca9SStephan Aßmus 					else if (position.y > 0.5 && where.y == frame.bottom)
26325648ff0SStephan Aßmus 						raise = true;
26425648ff0SStephan Aßmus 				}
26525648ff0SStephan Aßmus 			}
26625648ff0SStephan Aßmus 			if (raise)
26725648ff0SStephan Aßmus 				window->Activate();
26825648ff0SStephan Aßmus 		}
26925648ff0SStephan Aßmus 	}
27025648ff0SStephan Aßmus }
27125648ff0SStephan Aßmus 
2728d186370SStephan Aßmus 
27325648ff0SStephan Aßmus void
27425648ff0SStephan Aßmus PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton)
27525648ff0SStephan Aßmus {
276a6099ca9SStephan Aßmus 	button->SetIconSize(fIconSize);
277a6099ca9SStephan Aßmus 
27825648ff0SStephan Aßmus 	if (beforeButton)
279f32e3a29SStephan Aßmus 		fButtonLayout->AddView(fButtonLayout->IndexOfView(beforeButton), button);
28025648ff0SStephan Aßmus 	else
281f32e3a29SStephan Aßmus 		fButtonLayout->AddView(button);
282*9368e58bSStephan Aßmus 
283*9368e58bSStephan Aßmus 	_NotifySettingsChanged();
28425648ff0SStephan Aßmus }
28525648ff0SStephan Aßmus 
2868d186370SStephan Aßmus 
28725648ff0SStephan Aßmus bool
28825648ff0SStephan Aßmus PadView::RemoveButton(LaunchButton* button)
28925648ff0SStephan Aßmus {
290*9368e58bSStephan Aßmus 	bool result = fButtonLayout->RemoveView(button);
291*9368e58bSStephan Aßmus 	if (result)
292*9368e58bSStephan Aßmus 		_NotifySettingsChanged();
293*9368e58bSStephan Aßmus 	return result;
29425648ff0SStephan Aßmus }
29525648ff0SStephan Aßmus 
2968d186370SStephan Aßmus 
29725648ff0SStephan Aßmus LaunchButton*
29825648ff0SStephan Aßmus PadView::ButtonAt(int32 index) const
29925648ff0SStephan Aßmus {
30025648ff0SStephan Aßmus 	return dynamic_cast<LaunchButton*>(ChildAt(index));
30125648ff0SStephan Aßmus }
30225648ff0SStephan Aßmus 
3038d186370SStephan Aßmus 
30425648ff0SStephan Aßmus void
30525648ff0SStephan Aßmus PadView::DisplayMenu(BPoint where, LaunchButton* button) const
30625648ff0SStephan Aßmus {
3078eeb005fSStephan Aßmus 	MainWindow* window = dynamic_cast<MainWindow*>(Window());
3088eeb005fSStephan Aßmus 	if (window == NULL)
3098eeb005fSStephan Aßmus 		return;
3108eeb005fSStephan Aßmus 
31125648ff0SStephan Aßmus 	LaunchButton* nearestButton = button;
31225648ff0SStephan Aßmus 	if (!nearestButton) {
31325648ff0SStephan Aßmus 		// find the nearest button
31425648ff0SStephan Aßmus 		for (int32 i = 0; (nearestButton = ButtonAt(i)); i++) {
31525648ff0SStephan Aßmus 			if (nearestButton->Frame().top > where.y)
31625648ff0SStephan Aßmus 				break;
31725648ff0SStephan Aßmus 		}
31825648ff0SStephan Aßmus 	}
31925648ff0SStephan Aßmus 	BPopUpMenu* menu = new BPopUpMenu("launch popup", false, false);
32025648ff0SStephan Aßmus 	// add button
32125648ff0SStephan Aßmus 	BMessage* message = new BMessage(MSG_ADD_SLOT);
32225648ff0SStephan Aßmus 	message->AddPointer("be:source", (void*)nearestButton);
32325648ff0SStephan Aßmus 	BMenuItem* item = new BMenuItem("Add Button Here", message);
32425648ff0SStephan Aßmus 	item->SetTarget(window);
32525648ff0SStephan Aßmus 	menu->AddItem(item);
32625648ff0SStephan Aßmus 	// button options
32725648ff0SStephan Aßmus 	if (button) {
328*9368e58bSStephan Aßmus 		// clear button
32925648ff0SStephan Aßmus 		message = new BMessage(MSG_CLEAR_SLOT);
33025648ff0SStephan Aßmus 		message->AddPointer("be:source", (void*)button);
33125648ff0SStephan Aßmus 		item = new BMenuItem("Clear Button", message);
33225648ff0SStephan Aßmus 		item->SetTarget(window);
33325648ff0SStephan Aßmus 		menu->AddItem(item);
33425648ff0SStephan Aßmus 		// remove button
33525648ff0SStephan Aßmus 		message = new BMessage(MSG_REMOVE_SLOT);
33625648ff0SStephan Aßmus 		message->AddPointer("be:source", (void*)button);
33725648ff0SStephan Aßmus 		item = new BMenuItem("Remove Button", message);
33825648ff0SStephan Aßmus 		item->SetTarget(window);
33925648ff0SStephan Aßmus 		menu->AddItem(item);
340*9368e58bSStephan Aßmus 		// set button description
341*9368e58bSStephan Aßmus 		if (button->Ref()) {
342*9368e58bSStephan Aßmus 			message = new BMessage(MSG_SET_DESCRIPTION);
343*9368e58bSStephan Aßmus 			message->AddPointer("be:source", (void*)button);
344*9368e58bSStephan Aßmus 			item = new BMenuItem("Set Description"B_UTF8_ELLIPSIS, message);
345*9368e58bSStephan Aßmus 			item->SetTarget(window);
346*9368e58bSStephan Aßmus 			menu->AddItem(item);
347*9368e58bSStephan Aßmus 		}
34825648ff0SStephan Aßmus 	}
34925648ff0SStephan Aßmus 	menu->AddSeparatorItem();
35025648ff0SStephan Aßmus 	// window settings
35125648ff0SStephan Aßmus 	BMenu* settingsM = new BMenu("Settings");
35225648ff0SStephan Aßmus 	settingsM->SetFont(be_plain_font);
35325648ff0SStephan Aßmus 
354f32e3a29SStephan Aßmus 	const char* toggleLayoutLabel;
355f32e3a29SStephan Aßmus 	if (fButtonLayout->Orientation() == B_HORIZONTAL)
356f32e3a29SStephan Aßmus 		toggleLayoutLabel = "Vertical Layout";
357f32e3a29SStephan Aßmus 	else
358f32e3a29SStephan Aßmus 		toggleLayoutLabel = "Horizontal Layout";
359f32e3a29SStephan Aßmus 	item = new BMenuItem(toggleLayoutLabel, new BMessage(MSG_TOGGLE_LAYOUT));
360f32e3a29SStephan Aßmus 	item->SetTarget(this);
361f32e3a29SStephan Aßmus 	settingsM->AddItem(item);
362f32e3a29SStephan Aßmus 
363a6099ca9SStephan Aßmus 	BMenu* iconSizeM = new BMenu("Icon size");
364a6099ca9SStephan Aßmus 	for (uint32 i = 0; i < sizeof(kIconSizes) / sizeof(uint32); i++) {
365a6099ca9SStephan Aßmus 		uint32 iconSize = kIconSizes[i];
366a6099ca9SStephan Aßmus 		message = new BMessage(MSG_SET_ICON_SIZE);
367a6099ca9SStephan Aßmus 		message->AddInt32("size", iconSize);
368a6099ca9SStephan Aßmus 		BString label;
369a6099ca9SStephan Aßmus 		label << iconSize << " x " << iconSize;
370a6099ca9SStephan Aßmus 		item = new BMenuItem(label.String(), message);
371a6099ca9SStephan Aßmus 		item->SetTarget(this);
372a6099ca9SStephan Aßmus 		item->SetMarked(IconSize() == iconSize);
373a6099ca9SStephan Aßmus 		iconSizeM->AddItem(item);
374a6099ca9SStephan Aßmus 	}
375a6099ca9SStephan Aßmus 	settingsM->AddItem(iconSizeM);
376a6099ca9SStephan Aßmus 
3778d186370SStephan Aßmus 	item = new BMenuItem("Ignore Double-click",
3788d186370SStephan Aßmus 		new BMessage(MSG_SET_IGNORE_DOUBLECLICK));
3798d186370SStephan Aßmus 	item->SetTarget(this);
3808d186370SStephan Aßmus 	item->SetMarked(IgnoreDoubleClick());
3818d186370SStephan Aßmus 	settingsM->AddItem(item);
3828d186370SStephan Aßmus 
38325648ff0SStephan Aßmus 	uint32 what = window->Look() == B_BORDERED_WINDOW_LOOK ? MSG_SHOW_BORDER : MSG_HIDE_BORDER;
38425648ff0SStephan Aßmus 	item = new BMenuItem("Show Window Border", new BMessage(what));
38525648ff0SStephan Aßmus 	item->SetTarget(window);
38625648ff0SStephan Aßmus 	item->SetMarked(what == MSG_HIDE_BORDER);
38725648ff0SStephan Aßmus 	settingsM->AddItem(item);
38825648ff0SStephan Aßmus 
38925648ff0SStephan Aßmus 	item = new BMenuItem("Auto Raise", new BMessage(MSG_TOGGLE_AUTORAISE));
39025648ff0SStephan Aßmus 	item->SetTarget(window);
39125648ff0SStephan Aßmus 	item->SetMarked(window->AutoRaise());
39225648ff0SStephan Aßmus 	settingsM->AddItem(item);
39325648ff0SStephan Aßmus 
39425648ff0SStephan Aßmus 	item = new BMenuItem("Show On All Workspaces", new BMessage(MSG_SHOW_ON_ALL_WORKSPACES));
39525648ff0SStephan Aßmus 	item->SetTarget(window);
39625648ff0SStephan Aßmus 	item->SetMarked(window->ShowOnAllWorkspaces());
39725648ff0SStephan Aßmus 	settingsM->AddItem(item);
39825648ff0SStephan Aßmus 
39925648ff0SStephan Aßmus 	menu->AddItem(settingsM);
40025648ff0SStephan Aßmus 
40125648ff0SStephan Aßmus 	menu->AddSeparatorItem();
40225648ff0SStephan Aßmus 
40325648ff0SStephan Aßmus 	// pad commands
40425648ff0SStephan Aßmus 	BMenu* padM = new BMenu("Pad");
40525648ff0SStephan Aßmus 	padM->SetFont(be_plain_font);
40625648ff0SStephan Aßmus 	// new pad
40725648ff0SStephan Aßmus 	item = new BMenuItem("New", new BMessage(MSG_ADD_WINDOW));
40825648ff0SStephan Aßmus 	item->SetTarget(be_app);
40925648ff0SStephan Aßmus 	padM->AddItem(item);
41025648ff0SStephan Aßmus 	// new pad
41125648ff0SStephan Aßmus 	item = new BMenuItem("Clone", new BMessage(MSG_ADD_WINDOW));
41225648ff0SStephan Aßmus 	item->SetTarget(window);
41325648ff0SStephan Aßmus 	padM->AddItem(item);
41425648ff0SStephan Aßmus 	padM->AddSeparatorItem();
41525648ff0SStephan Aßmus 	// close
41625648ff0SStephan Aßmus 	item = new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED));
41725648ff0SStephan Aßmus 	item->SetTarget(window);
41825648ff0SStephan Aßmus 	padM->AddItem(item);
41925648ff0SStephan Aßmus 	menu->AddItem(padM);
42025648ff0SStephan Aßmus 	// app commands
42125648ff0SStephan Aßmus 	BMenu* appM = new BMenu("LaunchBox");
42225648ff0SStephan Aßmus 	appM->SetFont(be_plain_font);
42325648ff0SStephan Aßmus 	// about
42425648ff0SStephan Aßmus 	item = new BMenuItem("About", new BMessage(B_ABOUT_REQUESTED));
42525648ff0SStephan Aßmus 	item->SetTarget(be_app);
42625648ff0SStephan Aßmus 	appM->AddItem(item);
42725648ff0SStephan Aßmus 	// quit
42825648ff0SStephan Aßmus 	item = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED));
42925648ff0SStephan Aßmus 	item->SetTarget(be_app);
43025648ff0SStephan Aßmus 	appM->AddItem(item);
43125648ff0SStephan Aßmus 	menu->AddItem(appM);
43225648ff0SStephan Aßmus 	// finish popup
43325648ff0SStephan Aßmus 	menu->SetAsyncAutoDestruct(true);
43425648ff0SStephan Aßmus 	menu->SetFont(be_plain_font);
43525648ff0SStephan Aßmus 	where = ConvertToScreen(where);
43625648ff0SStephan Aßmus 	BRect mouseRect(where, where);
43725648ff0SStephan Aßmus 	mouseRect.InsetBy(-4.0, -4.0);
43825648ff0SStephan Aßmus 	menu->Go(where, true, false, mouseRect, true);
43925648ff0SStephan Aßmus }
44025648ff0SStephan Aßmus 
4418d186370SStephan Aßmus 
442f32e3a29SStephan Aßmus void
443f32e3a29SStephan Aßmus PadView::SetOrientation(enum orientation orientation)
444f32e3a29SStephan Aßmus {
445f32e3a29SStephan Aßmus 	if (orientation == B_VERTICAL) {
446f32e3a29SStephan Aßmus 		fButtonLayout->SetInsets(2, 7, 2, 2);
447f32e3a29SStephan Aßmus 		fButtonLayout->SetOrientation(B_VERTICAL);
448f32e3a29SStephan Aßmus 	} else {
449f32e3a29SStephan Aßmus 		fButtonLayout->SetInsets(7, 2, 2, 2);
450f32e3a29SStephan Aßmus 		fButtonLayout->SetOrientation(B_HORIZONTAL);
451f32e3a29SStephan Aßmus 	}
452*9368e58bSStephan Aßmus 	_NotifySettingsChanged();
453f32e3a29SStephan Aßmus }
454f32e3a29SStephan Aßmus 
4558d186370SStephan Aßmus 
456f32e3a29SStephan Aßmus enum orientation
457f32e3a29SStephan Aßmus PadView::Orientation() const
458f32e3a29SStephan Aßmus {
459f32e3a29SStephan Aßmus 	return fButtonLayout->Orientation();
460f32e3a29SStephan Aßmus }
461f32e3a29SStephan Aßmus 
4628d186370SStephan Aßmus 
463a6099ca9SStephan Aßmus void
464a6099ca9SStephan Aßmus PadView::SetIconSize(uint32 size)
465a6099ca9SStephan Aßmus {
466a6099ca9SStephan Aßmus 	if (size == fIconSize)
467a6099ca9SStephan Aßmus 		return;
468a6099ca9SStephan Aßmus 
469a6099ca9SStephan Aßmus 	fIconSize = size;
470a6099ca9SStephan Aßmus 
471a6099ca9SStephan Aßmus 	for (int32 i = 0; LaunchButton* button = ButtonAt(i); i++)
472a6099ca9SStephan Aßmus 		button->SetIconSize(fIconSize);
473*9368e58bSStephan Aßmus 
474*9368e58bSStephan Aßmus 	_NotifySettingsChanged();
475a6099ca9SStephan Aßmus }
476a6099ca9SStephan Aßmus 
4778d186370SStephan Aßmus 
478a6099ca9SStephan Aßmus uint32
479a6099ca9SStephan Aßmus PadView::IconSize() const
480a6099ca9SStephan Aßmus {
481a6099ca9SStephan Aßmus 	return fIconSize;
482a6099ca9SStephan Aßmus }
483a6099ca9SStephan Aßmus 
484f32e3a29SStephan Aßmus 
4858d186370SStephan Aßmus void
4868d186370SStephan Aßmus PadView::SetIgnoreDoubleClick(bool refuse)
4878d186370SStephan Aßmus {
4888d186370SStephan Aßmus 	LaunchButton::SetIgnoreDoubleClick(refuse);
489*9368e58bSStephan Aßmus 
490*9368e58bSStephan Aßmus 	_NotifySettingsChanged();
4918d186370SStephan Aßmus }
4928d186370SStephan Aßmus 
4938d186370SStephan Aßmus 
4948d186370SStephan Aßmus bool
4958d186370SStephan Aßmus PadView::IgnoreDoubleClick() const
4968d186370SStephan Aßmus {
4978d186370SStephan Aßmus 	return LaunchButton::IgnoreDoubleClick();
4988d186370SStephan Aßmus }
4998d186370SStephan Aßmus 
5008d186370SStephan Aßmus 
501*9368e58bSStephan Aßmus void
502*9368e58bSStephan Aßmus PadView::_NotifySettingsChanged()
503*9368e58bSStephan Aßmus {
504*9368e58bSStephan Aßmus 	be_app->PostMessage(MSG_SETTINGS_CHANGED);
505*9368e58bSStephan Aßmus }
506*9368e58bSStephan Aßmus 
507