* 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:
Stephan Aßmus 2007-06-10 19:58:16 +00:00
parent a938e3222a
commit f32e3a29b0
4 changed files with 149 additions and 42 deletions

View File

@ -31,7 +31,8 @@ MainWindow::MainWindow(const char* name, BRect frame)
: 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_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION
| B_AUTO_UPDATE_SIZE_LIMITS),
fSettings(new BMessage('sett')),
fPadView(new PadView("pad view")),
fLastID(0),
@ -42,14 +43,8 @@ MainWindow::MainWindow(const char* name, BRect frame)
bool buttonsAdded = false;
if (load_settings(fSettings, "main_settings", "LaunchBox") >= B_OK)
buttonsAdded = LoadSettings(fSettings);
if (!buttonsAdded) {
fPadView->AddButton(new LaunchButton("launch button", fLastID++, NULL,
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)));
}
if (!buttonsAdded)
_AddDefaultButtons();
SetLayout(new BGroupLayout(B_HORIZONTAL));
AddChild(fPadView);
@ -60,7 +55,8 @@ 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_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION
| B_AUTO_UPDATE_SIZE_LIMITS),
fSettings(settings),
fPadView(new PadView("pad view")),
fLastID(0),
@ -68,14 +64,8 @@ MainWindow::MainWindow(const char* name, BRect frame, BMessage* settings)
fAutoRaise(false),
fShowOnAllWorkspaces(true)
{
if (!LoadSettings(settings)) {
fPadView->AddButton(new LaunchButton("launch button", fLastID++, NULL,
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)));
}
if (!LoadSettings(settings))
_AddDefaultButtons();
SetLayout(new BGroupLayout(B_HORIZONTAL));
AddChild(fPadView);
@ -317,6 +307,12 @@ MainWindow::LoadSettings(const BMessage* message)
window_look look;
if (message->FindInt32("window look", (int32*)&look) == B_OK)
SetLook(look);
// restore orientation
int32 orientation;
if (message->FindInt32("orientation", &orientation) == B_OK)
fPadView->SetOrientation((enum orientation)orientation);
// restore buttons
const char* path;
bool buttonAdded = false;
@ -381,6 +377,11 @@ MainWindow::SaveSettings(BMessage* message)
if (message->ReplaceInt32("window look", Look()) != B_OK)
message->AddInt32("window look", Look());
// store orientation
if (message->ReplaceInt32("orientation",
(int32)fPadView->Orientation()) != B_OK)
message->AddInt32("orientation", (int32)fPadView->Orientation());
// store buttons
message->RemoveName("path");
message->RemoveName("description");
@ -473,3 +474,44 @@ MainWindow::_AdjustLocation(BRect frame)
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);
}

View File

@ -62,6 +62,7 @@ class MainWindow : public BWindow {
private:
void _GetLocation();
void _AdjustLocation(BRect frame);
void _AddDefaultButtons();
BMessage* fSettings;
PadView* fPadView;

View File

@ -24,18 +24,23 @@
bigtime_t kActivationDelay = 40000;
enum {
MSG_TOGGLE_LAYOUT = 'tgll'
};
// constructor
PadView::PadView(const char* name)
: BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE,
new BGroupLayout(B_VERTICAL, 4)),
: BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE, NULL),
fDragging(false),
fClickTime(0)
fClickTime(0),
fButtonLayout(new BGroupLayout(B_VERTICAL, 4))
{
SetViewColor(B_TRANSPARENT_32_BIT);
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
get_click_speed(&kActivationDelay);
GetLayout()->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5));
fButtonLayout->SetInsets(2, 7, 2, 2);
SetLayout(fButtonLayout);
}
// destructor
@ -62,9 +67,25 @@ PadView::Draw(BRect updateRect)
r.InsetBy(1.0, 1.0);
// dots along top
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;
while (dot.x <= stop.x) {
while (current <= stop) {
rgb_color col1;
rgb_color col2;
switch (num) {
@ -85,22 +106,21 @@ PadView::Draw(BRect updateRect)
SetHighColor(col1);
StrokeLine(dot, dot, B_SOLID_HIGH);
SetHighColor(col2);
dot.y++;
dot += offset;
StrokeLine(dot, dot, B_SOLID_HIGH);
dot.y++;
dot += offset;
StrokeLine(dot, dot, B_SOLID_LOW);
dot.y++;
dot += offset;
SetHighColor(col1);
StrokeLine(dot, dot, B_SOLID_HIGH);
dot.y++;
dot += offset;
SetHighColor(col2);
StrokeLine(dot, dot, B_SOLID_HIGH);
dot.y -= 4.0;
// next pixel
num++;
dot.x++;
dot += next;
current++;
}
r.top += 5.0;
FillRect(r, B_SOLID_LOW);
}
@ -109,6 +129,15 @@ void
PadView::MessageReceived(BMessage* message)
{
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:
BView::MessageReceived(message);
break;
@ -221,18 +250,17 @@ PadView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
void
PadView::AddButton(LaunchButton* button, LaunchButton* beforeButton)
{
BLayout* layout = GetLayout();
if (beforeButton)
layout->AddView(layout->IndexOfView(beforeButton), button);
fButtonLayout->AddView(fButtonLayout->IndexOfView(beforeButton), button);
else
layout->AddView(button);
fButtonLayout->AddView(button);
}
// RemoveButton
bool
PadView::RemoveButton(LaunchButton* button)
{
return GetLayout()->RemoveView(button);
return fButtonLayout->RemoveView(button);
}
// ButtonAt
@ -276,19 +304,29 @@ PadView::DisplayMenu(BPoint where, LaunchButton* button) const
item = new BMenuItem("Remove Button", message);
item->SetTarget(window);
menu->AddItem(item);
if (button->Ref()) {
message = new BMessage(MSG_SET_DESCRIPTION);
message->AddPointer("be:source", (void*)button);
item = new BMenuItem("Set Description"B_UTF8_ELLIPSIS, message);
item->SetTarget(window);
menu->AddItem(item);
}
// TODO: disabled because Haiku does not yet support tool tips
// if (button->Ref()) {
// message = new BMessage(MSG_SET_DESCRIPTION);
// message->AddPointer("be:source", (void*)button);
// item = new BMenuItem("Set Description"B_UTF8_ELLIPSIS, message);
// item->SetTarget(window);
// menu->AddItem(item);
// }
}
menu->AddSeparatorItem();
// window settings
BMenu* settingsM = new BMenu("Settings");
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;
item = new BMenuItem("Show Window Border", new BMessage(what));
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();
}

View File

@ -11,6 +11,7 @@
#include <View.h>
class BGroupLayout;
class LaunchButton;
class PadView : public BView {
@ -35,10 +36,14 @@ class PadView : public BView {
void DisplayMenu(BPoint where,
LaunchButton* button = NULL) const;
void SetOrientation(enum orientation orientation);
enum orientation Orientation() const;
private:
BPoint fDragOffset;
bool fDragging;
bigtime_t fClickTime;
BGroupLayout* fButtonLayout;
};
#endif // PAD_VIEW_H