* implemented default buttons
* window size limits are correctly set * one can now chose between horizontal and vertical layout (brilliantly simple with the new layout system :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21385 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
a938e3222a
commit
f32e3a29b0
@ -31,7 +31,8 @@ MainWindow::MainWindow(const char* name, BRect frame)
|
|||||||
: BWindow(frame, name,
|
: BWindow(frame, name,
|
||||||
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||||
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE
|
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE
|
||||||
| B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION),
|
| B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION
|
||||||
|
| B_AUTO_UPDATE_SIZE_LIMITS),
|
||||||
fSettings(new BMessage('sett')),
|
fSettings(new BMessage('sett')),
|
||||||
fPadView(new PadView("pad view")),
|
fPadView(new PadView("pad view")),
|
||||||
fLastID(0),
|
fLastID(0),
|
||||||
@ -42,14 +43,8 @@ MainWindow::MainWindow(const char* name, BRect frame)
|
|||||||
bool buttonsAdded = false;
|
bool buttonsAdded = false;
|
||||||
if (load_settings(fSettings, "main_settings", "LaunchBox") >= B_OK)
|
if (load_settings(fSettings, "main_settings", "LaunchBox") >= B_OK)
|
||||||
buttonsAdded = LoadSettings(fSettings);
|
buttonsAdded = LoadSettings(fSettings);
|
||||||
if (!buttonsAdded) {
|
if (!buttonsAdded)
|
||||||
fPadView->AddButton(new LaunchButton("launch button", fLastID++, NULL,
|
_AddDefaultButtons();
|
||||||
new BMessage(MSG_LAUNCH)));
|
|
||||||
fPadView->AddButton(new LaunchButton("launch button", fLastID++, NULL,
|
|
||||||
new BMessage(MSG_LAUNCH)));
|
|
||||||
fPadView->AddButton(new LaunchButton("launch button", fLastID++, NULL,
|
|
||||||
new BMessage(MSG_LAUNCH)));
|
|
||||||
}
|
|
||||||
|
|
||||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
AddChild(fPadView);
|
AddChild(fPadView);
|
||||||
@ -60,7 +55,8 @@ MainWindow::MainWindow(const char* name, BRect frame, BMessage* settings)
|
|||||||
: BWindow(frame, name,
|
: BWindow(frame, name,
|
||||||
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||||
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE
|
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE
|
||||||
| B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION),
|
| B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION
|
||||||
|
| B_AUTO_UPDATE_SIZE_LIMITS),
|
||||||
fSettings(settings),
|
fSettings(settings),
|
||||||
fPadView(new PadView("pad view")),
|
fPadView(new PadView("pad view")),
|
||||||
fLastID(0),
|
fLastID(0),
|
||||||
@ -68,14 +64,8 @@ MainWindow::MainWindow(const char* name, BRect frame, BMessage* settings)
|
|||||||
fAutoRaise(false),
|
fAutoRaise(false),
|
||||||
fShowOnAllWorkspaces(true)
|
fShowOnAllWorkspaces(true)
|
||||||
{
|
{
|
||||||
if (!LoadSettings(settings)) {
|
if (!LoadSettings(settings))
|
||||||
fPadView->AddButton(new LaunchButton("launch button", fLastID++, NULL,
|
_AddDefaultButtons();
|
||||||
new BMessage(MSG_LAUNCH)));
|
|
||||||
fPadView->AddButton(new LaunchButton("launch button", fLastID++, NULL,
|
|
||||||
new BMessage(MSG_LAUNCH)));
|
|
||||||
fPadView->AddButton(new LaunchButton("launch button", fLastID++, NULL,
|
|
||||||
new BMessage(MSG_LAUNCH)));
|
|
||||||
}
|
|
||||||
|
|
||||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
AddChild(fPadView);
|
AddChild(fPadView);
|
||||||
@ -317,6 +307,12 @@ MainWindow::LoadSettings(const BMessage* message)
|
|||||||
window_look look;
|
window_look look;
|
||||||
if (message->FindInt32("window look", (int32*)&look) == B_OK)
|
if (message->FindInt32("window look", (int32*)&look) == B_OK)
|
||||||
SetLook(look);
|
SetLook(look);
|
||||||
|
|
||||||
|
// restore orientation
|
||||||
|
int32 orientation;
|
||||||
|
if (message->FindInt32("orientation", &orientation) == B_OK)
|
||||||
|
fPadView->SetOrientation((enum orientation)orientation);
|
||||||
|
|
||||||
// restore buttons
|
// restore buttons
|
||||||
const char* path;
|
const char* path;
|
||||||
bool buttonAdded = false;
|
bool buttonAdded = false;
|
||||||
@ -381,6 +377,11 @@ MainWindow::SaveSettings(BMessage* message)
|
|||||||
if (message->ReplaceInt32("window look", Look()) != B_OK)
|
if (message->ReplaceInt32("window look", Look()) != B_OK)
|
||||||
message->AddInt32("window look", Look());
|
message->AddInt32("window look", Look());
|
||||||
|
|
||||||
|
// store orientation
|
||||||
|
if (message->ReplaceInt32("orientation",
|
||||||
|
(int32)fPadView->Orientation()) != B_OK)
|
||||||
|
message->AddInt32("orientation", (int32)fPadView->Orientation());
|
||||||
|
|
||||||
// store buttons
|
// store buttons
|
||||||
message->RemoveName("path");
|
message->RemoveName("path");
|
||||||
message->RemoveName("description");
|
message->RemoveName("description");
|
||||||
@ -473,3 +474,44 @@ MainWindow::_AdjustLocation(BRect frame)
|
|||||||
ResizeTo(frame.Width(), frame.Height());
|
ResizeTo(frame.Width(), frame.Height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::_AddDefaultButtons()
|
||||||
|
{
|
||||||
|
// Mail
|
||||||
|
LaunchButton* button = new LaunchButton("launch button", fLastID++, NULL,
|
||||||
|
new BMessage(MSG_LAUNCH));
|
||||||
|
fPadView->AddButton(button);
|
||||||
|
button->SetTo("application/x-vnd.Be-MAIL", true);
|
||||||
|
|
||||||
|
// StyledEdit
|
||||||
|
button = new LaunchButton("launch button", fLastID++, NULL,
|
||||||
|
new BMessage(MSG_LAUNCH));
|
||||||
|
fPadView->AddButton(button);
|
||||||
|
button->SetTo("application/x-vnd.Haiku-StyledEdit", true);
|
||||||
|
|
||||||
|
// ShowImage
|
||||||
|
button = new LaunchButton("launch button", fLastID++, NULL,
|
||||||
|
new BMessage(MSG_LAUNCH));
|
||||||
|
fPadView->AddButton(button);
|
||||||
|
button->SetTo("application/x-vnd.Haiku-ShowImage", true);
|
||||||
|
|
||||||
|
// MediaPlayer
|
||||||
|
button = new LaunchButton("launch button", fLastID++, NULL,
|
||||||
|
new BMessage(MSG_LAUNCH));
|
||||||
|
fPadView->AddButton(button);
|
||||||
|
button->SetTo("application/x-vnd.Haiku-MediaPlayer", true);
|
||||||
|
|
||||||
|
// DeskCalc
|
||||||
|
button = new LaunchButton("launch button", fLastID++, NULL,
|
||||||
|
new BMessage(MSG_LAUNCH));
|
||||||
|
fPadView->AddButton(button);
|
||||||
|
button->SetTo("application/x-vnd.Haiku-DeskCalc", true);
|
||||||
|
|
||||||
|
// Terminal
|
||||||
|
button = new LaunchButton("launch button", fLastID++, NULL,
|
||||||
|
new BMessage(MSG_LAUNCH));
|
||||||
|
fPadView->AddButton(button);
|
||||||
|
button->SetTo("application/x-vnd.Haiku-Terminal", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ class MainWindow : public BWindow {
|
|||||||
private:
|
private:
|
||||||
void _GetLocation();
|
void _GetLocation();
|
||||||
void _AdjustLocation(BRect frame);
|
void _AdjustLocation(BRect frame);
|
||||||
|
void _AddDefaultButtons();
|
||||||
|
|
||||||
BMessage* fSettings;
|
BMessage* fSettings;
|
||||||
PadView* fPadView;
|
PadView* fPadView;
|
||||||
|
@ -24,18 +24,23 @@
|
|||||||
|
|
||||||
bigtime_t kActivationDelay = 40000;
|
bigtime_t kActivationDelay = 40000;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MSG_TOGGLE_LAYOUT = 'tgll'
|
||||||
|
};
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
PadView::PadView(const char* name)
|
PadView::PadView(const char* name)
|
||||||
: BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE,
|
: BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE, NULL),
|
||||||
new BGroupLayout(B_VERTICAL, 4)),
|
|
||||||
fDragging(false),
|
fDragging(false),
|
||||||
fClickTime(0)
|
fClickTime(0),
|
||||||
|
fButtonLayout(new BGroupLayout(B_VERTICAL, 4))
|
||||||
{
|
{
|
||||||
SetViewColor(B_TRANSPARENT_32_BIT);
|
SetViewColor(B_TRANSPARENT_32_BIT);
|
||||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
get_click_speed(&kActivationDelay);
|
get_click_speed(&kActivationDelay);
|
||||||
|
|
||||||
GetLayout()->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5));
|
fButtonLayout->SetInsets(2, 7, 2, 2);
|
||||||
|
SetLayout(fButtonLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
@ -62,9 +67,25 @@ PadView::Draw(BRect updateRect)
|
|||||||
r.InsetBy(1.0, 1.0);
|
r.InsetBy(1.0, 1.0);
|
||||||
// dots along top
|
// dots along top
|
||||||
BPoint dot = r.LeftTop();
|
BPoint dot = r.LeftTop();
|
||||||
BPoint stop = r.RightTop();
|
int32 current;
|
||||||
|
int32 stop;
|
||||||
|
BPoint offset;
|
||||||
|
BPoint next;
|
||||||
|
if (Orientation() == B_VERTICAL) {
|
||||||
|
current = (int32)dot.x;
|
||||||
|
stop = (int32)r.right;
|
||||||
|
offset = BPoint(0, 1);
|
||||||
|
next = BPoint(1, -4);
|
||||||
|
r.top += 5.0;
|
||||||
|
} else {
|
||||||
|
current = (int32)dot.y;
|
||||||
|
stop = (int32)r.bottom;
|
||||||
|
offset = BPoint(1, 0);
|
||||||
|
next = BPoint(-4, 1);
|
||||||
|
r.left += 5.0;
|
||||||
|
}
|
||||||
int32 num = 1;
|
int32 num = 1;
|
||||||
while (dot.x <= stop.x) {
|
while (current <= stop) {
|
||||||
rgb_color col1;
|
rgb_color col1;
|
||||||
rgb_color col2;
|
rgb_color col2;
|
||||||
switch (num) {
|
switch (num) {
|
||||||
@ -85,22 +106,21 @@ PadView::Draw(BRect updateRect)
|
|||||||
SetHighColor(col1);
|
SetHighColor(col1);
|
||||||
StrokeLine(dot, dot, B_SOLID_HIGH);
|
StrokeLine(dot, dot, B_SOLID_HIGH);
|
||||||
SetHighColor(col2);
|
SetHighColor(col2);
|
||||||
dot.y++;
|
dot += offset;
|
||||||
StrokeLine(dot, dot, B_SOLID_HIGH);
|
StrokeLine(dot, dot, B_SOLID_HIGH);
|
||||||
dot.y++;
|
dot += offset;
|
||||||
StrokeLine(dot, dot, B_SOLID_LOW);
|
StrokeLine(dot, dot, B_SOLID_LOW);
|
||||||
dot.y++;
|
dot += offset;
|
||||||
SetHighColor(col1);
|
SetHighColor(col1);
|
||||||
StrokeLine(dot, dot, B_SOLID_HIGH);
|
StrokeLine(dot, dot, B_SOLID_HIGH);
|
||||||
dot.y++;
|
dot += offset;
|
||||||
SetHighColor(col2);
|
SetHighColor(col2);
|
||||||
StrokeLine(dot, dot, B_SOLID_HIGH);
|
StrokeLine(dot, dot, B_SOLID_HIGH);
|
||||||
dot.y -= 4.0;
|
|
||||||
// next pixel
|
// next pixel
|
||||||
num++;
|
num++;
|
||||||
dot.x++;
|
dot += next;
|
||||||
|
current++;
|
||||||
}
|
}
|
||||||
r.top += 5.0;
|
|
||||||
FillRect(r, B_SOLID_LOW);
|
FillRect(r, B_SOLID_LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +129,15 @@ void
|
|||||||
PadView::MessageReceived(BMessage* message)
|
PadView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
|
case MSG_TOGGLE_LAYOUT:
|
||||||
|
if (fButtonLayout->Orientation() == B_HORIZONTAL) {
|
||||||
|
fButtonLayout->SetInsets(2, 7, 2, 2);
|
||||||
|
fButtonLayout->SetOrientation(B_VERTICAL);
|
||||||
|
} else {
|
||||||
|
fButtonLayout->SetInsets(7, 2, 2, 2);
|
||||||
|
fButtonLayout->SetOrientation(B_HORIZONTAL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@ -221,18 +250,17 @@ PadView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
|
|||||||
void
|
void
|
||||||
PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton)
|
PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton)
|
||||||
{
|
{
|
||||||
BLayout* layout = GetLayout();
|
|
||||||
if (beforeButton)
|
if (beforeButton)
|
||||||
layout->AddView(layout->IndexOfView(beforeButton), button);
|
fButtonLayout->AddView(fButtonLayout->IndexOfView(beforeButton), button);
|
||||||
else
|
else
|
||||||
layout->AddView(button);
|
fButtonLayout->AddView(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveButton
|
// RemoveButton
|
||||||
bool
|
bool
|
||||||
PadView::RemoveButton(LaunchButton* button)
|
PadView::RemoveButton(LaunchButton* button)
|
||||||
{
|
{
|
||||||
return GetLayout()->RemoveView(button);
|
return fButtonLayout->RemoveView(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ButtonAt
|
// ButtonAt
|
||||||
@ -276,19 +304,29 @@ 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);
|
||||||
if (button->Ref()) {
|
// TODO: disabled because Haiku does not yet support tool tips
|
||||||
message = new BMessage(MSG_SET_DESCRIPTION);
|
// if (button->Ref()) {
|
||||||
message->AddPointer("be:source", (void*)button);
|
// message = new BMessage(MSG_SET_DESCRIPTION);
|
||||||
item = new BMenuItem("Set Description"B_UTF8_ELLIPSIS, message);
|
// message->AddPointer("be:source", (void*)button);
|
||||||
item->SetTarget(window);
|
// item = new BMenuItem("Set Description"B_UTF8_ELLIPSIS, message);
|
||||||
menu->AddItem(item);
|
// item->SetTarget(window);
|
||||||
}
|
// menu->AddItem(item);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
// window settings
|
// window settings
|
||||||
BMenu* settingsM = new BMenu("Settings");
|
BMenu* settingsM = new BMenu("Settings");
|
||||||
settingsM->SetFont(be_plain_font);
|
settingsM->SetFont(be_plain_font);
|
||||||
|
|
||||||
|
const char* toggleLayoutLabel;
|
||||||
|
if (fButtonLayout->Orientation() == B_HORIZONTAL)
|
||||||
|
toggleLayoutLabel = "Vertical Layout";
|
||||||
|
else
|
||||||
|
toggleLayoutLabel = "Horizontal Layout";
|
||||||
|
item = new BMenuItem(toggleLayoutLabel, new BMessage(MSG_TOGGLE_LAYOUT));
|
||||||
|
item->SetTarget(this);
|
||||||
|
settingsM->AddItem(item);
|
||||||
|
|
||||||
uint32 what = window->Look() == B_BORDERED_WINDOW_LOOK ? MSG_SHOW_BORDER : MSG_HIDE_BORDER;
|
uint32 what = window->Look() == B_BORDERED_WINDOW_LOOK ? MSG_SHOW_BORDER : MSG_HIDE_BORDER;
|
||||||
item = new BMenuItem("Show Window Border", new BMessage(what));
|
item = new BMenuItem("Show Window Border", new BMessage(what));
|
||||||
item->SetTarget(window);
|
item->SetTarget(window);
|
||||||
@ -348,3 +386,24 @@ PadView::DisplayMenu(BPoint where, LaunchButton* button) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetOrientation
|
||||||
|
void
|
||||||
|
PadView::SetOrientation(enum orientation orientation)
|
||||||
|
{
|
||||||
|
if (orientation == B_VERTICAL) {
|
||||||
|
fButtonLayout->SetInsets(2, 7, 2, 2);
|
||||||
|
fButtonLayout->SetOrientation(B_VERTICAL);
|
||||||
|
} else {
|
||||||
|
fButtonLayout->SetInsets(7, 2, 2, 2);
|
||||||
|
fButtonLayout->SetOrientation(B_HORIZONTAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orientation
|
||||||
|
enum orientation
|
||||||
|
PadView::Orientation() const
|
||||||
|
{
|
||||||
|
return fButtonLayout->Orientation();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
class BGroupLayout;
|
||||||
class LaunchButton;
|
class LaunchButton;
|
||||||
|
|
||||||
class PadView : public BView {
|
class PadView : public BView {
|
||||||
@ -35,10 +36,14 @@ class PadView : public BView {
|
|||||||
void DisplayMenu(BPoint where,
|
void DisplayMenu(BPoint where,
|
||||||
LaunchButton* button = NULL) const;
|
LaunchButton* button = NULL) const;
|
||||||
|
|
||||||
|
void SetOrientation(enum orientation orientation);
|
||||||
|
enum orientation Orientation() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BPoint fDragOffset;
|
BPoint fDragOffset;
|
||||||
bool fDragging;
|
bool fDragging;
|
||||||
bigtime_t fClickTime;
|
bigtime_t fClickTime;
|
||||||
|
BGroupLayout* fButtonLayout;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PAD_VIEW_H
|
#endif // PAD_VIEW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user