* Now uses the B_ALL_WORKSPACES flag when it's supposed to show on all

workspaces.
* It uses the Haiku-specific B_SAME_POSITION_IN_ALL_WORKSPACES to behave
  in the same way as before (which I couldn't really test, though).
* Some cleanup, removed extraneous white space.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24633 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-03-28 19:12:50 +00:00
parent 9dbce7a4e7
commit 6c14516a18
+39 -33
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006-2008, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -28,11 +28,11 @@
// constructor // constructor
MainWindow::MainWindow(const char* name, BRect frame, bool addDefaultButtons) MainWindow::MainWindow(const char* name, BRect frame, bool addDefaultButtons)
: 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 | B_SAME_POSITION_IN_ALL_WORKSPACES,
| B_AUTO_UPDATE_SIZE_LIMITS), B_ALL_WORKSPACES),
fSettings(new BMessage('sett')), fSettings(new BMessage('sett')),
fPadView(new PadView("pad view")), fPadView(new PadView("pad view")),
fLastID(0), fLastID(0),
@@ -57,10 +57,11 @@ MainWindow::MainWindow(const char* name, BRect frame, bool addDefaultButtons)
// constructor // constructor
MainWindow::MainWindow(const char* name, BRect frame, BMessage* settings) 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), | B_AUTO_UPDATE_SIZE_LIMITS | B_SAME_POSITION_IN_ALL_WORKSPACES,
B_ALL_WORKSPACES),
fSettings(settings), fSettings(settings),
fPadView(new PadView("pad view")), fPadView(new PadView("pad view")),
fLastID(0), fLastID(0),
@@ -96,8 +97,8 @@ MainWindow::QuitRequested()
return false; return false;
} else { } else {
BAlert* alert = new BAlert("last chance", "Really close this pad?\n" BAlert* alert = new BAlert("last chance", "Really close this pad?\n"
"(The pad will not be remembered.)", "(The pad will not be remembered.)",
"Close", "Cancel", NULL); "Close", "Cancel", NULL);
if (alert->Go() == 1) if (alert->Go() == 1)
return false; return false;
} }
@@ -112,7 +113,8 @@ MainWindow::MessageReceived(BMessage* message)
case MSG_LAUNCH: { case MSG_LAUNCH: {
BView* pointer; BView* pointer;
if (message->FindPointer("be:source", (void**)&pointer) >= B_OK) { if (message->FindPointer("be:source", (void**)&pointer) >= B_OK) {
if (LaunchButton* button = dynamic_cast<LaunchButton*>(pointer)) { if (LaunchButton* button
= dynamic_cast<LaunchButton*>(pointer)) {
if (button->AppSignature()) { if (button->AppSignature()) {
be_roster->Launch(button->AppSignature()); be_roster->Launch(button->AppSignature());
} else { } else {
@@ -129,7 +131,7 @@ MainWindow::MessageReceived(BMessage* message)
status_t ret = be_roster->Launch(button->Ref()); status_t ret = be_roster->Launch(button->Ref());
if (ret < B_OK) if (ret < B_OK)
fprintf(stderr, "launching %s failed: %s\n", fprintf(stderr, "launching %s failed: %s\n",
button->Ref()->name, strerror(ret)); button->Ref()->name, strerror(ret));
} }
} }
} }
@@ -139,8 +141,8 @@ MainWindow::MessageReceived(BMessage* message)
case MSG_ADD_SLOT: { case MSG_ADD_SLOT: {
LaunchButton* button; LaunchButton* button;
if (message->FindPointer("be:source", (void**)&button) >= B_OK) { if (message->FindPointer("be:source", (void**)&button) >= B_OK) {
fPadView->AddButton(new LaunchButton("launch button", fLastID++, NULL, fPadView->AddButton(new LaunchButton("launch button", fLastID++,
new BMessage(MSG_LAUNCH)), button); NULL, new BMessage(MSG_LAUNCH)), button);
} }
break; break;
} }
@@ -173,11 +175,9 @@ MainWindow::MessageReceived(BMessage* message)
BString helper("Description for '"); BString helper("Description for '");
helper << ref->name << "'"; helper << ref->name << "'";
// BRect* frame = fNamePanelFrame.IsValid() ? &fNamePanelFrame : NULL; // BRect* frame = fNamePanelFrame.IsValid() ? &fNamePanelFrame : NULL;
new NamePanel(helper.String(), new NamePanel(helper.String(), button->Description(),
button->Description(), this, this, new BMessage(*message),
this, this, fNamePanelFrame);
new BMessage(*message),
fNamePanelFrame);
} }
} }
} }
@@ -201,6 +201,10 @@ MainWindow::MessageReceived(BMessage* message)
break; break;
case MSG_SHOW_ON_ALL_WORKSPACES: case MSG_SHOW_ON_ALL_WORKSPACES:
fShowOnAllWorkspaces = !fShowOnAllWorkspaces; fShowOnAllWorkspaces = !fShowOnAllWorkspaces;
if (fShowOnAllWorkspaces)
SetWorkspaces(B_ALL_WORKSPACES);
else
SetWorkspaces(1L << current_workspace());
break; break;
case B_SIMPLE_DATA: case B_SIMPLE_DATA:
case B_REFS_RECEIVED: case B_REFS_RECEIVED:
@@ -230,17 +234,16 @@ MainWindow::ScreenChanged(BRect frame, color_space format)
{ {
_AdjustLocation(Frame()); _AdjustLocation(Frame());
} }
// WorkspaceActivated // WorkspaceActivated
void void
MainWindow::WorkspaceActivated(int32 workspace, bool active) MainWindow::WorkspaceActivated(int32 workspace, bool active)
{ {
if (fShowOnAllWorkspaces) { if (fShowOnAllWorkspaces) {
if (!active) { if (!active)
SetWorkspaces(1 << current_workspace());
_AdjustLocation(Frame());
} else
_GetLocation(); _GetLocation();
else
_AdjustLocation(Frame());
} }
} }
@@ -321,8 +324,8 @@ MainWindow::LoadSettings(const BMessage* message)
const char* path; const char* path;
bool buttonAdded = false; bool buttonAdded = false;
for (int32 i = 0; message->FindString("path", i, &path) >= B_OK; i++) { for (int32 i = 0; message->FindString("path", i, &path) >= B_OK; i++) {
LaunchButton* button = new LaunchButton("launch button", fLastID++, NULL, LaunchButton* button = new LaunchButton("launch button", fLastID++,
new BMessage(MSG_LAUNCH)); NULL, new BMessage(MSG_LAUNCH));
fPadView->AddButton(button); fPadView->AddButton(button);
BString signature; BString signature;
if (message->FindString("signature", i, &signature) >= B_OK if (message->FindString("signature", i, &signature) >= B_OK
@@ -348,6 +351,8 @@ MainWindow::LoadSettings(const BMessage* message)
bool showOnAllWorkspaces; bool showOnAllWorkspaces;
if (message->FindBool("all workspaces", &showOnAllWorkspaces) == B_OK) if (message->FindBool("all workspaces", &showOnAllWorkspaces) == B_OK)
fShowOnAllWorkspaces = showOnAllWorkspaces; fShowOnAllWorkspaces = showOnAllWorkspaces;
SetWorkspaces(showOnAllWorkspaces
? B_ALL_WORKSPACES : 1L << current_workspace());
if (!fShowOnAllWorkspaces) { if (!fShowOnAllWorkspaces) {
uint32 workspaces; uint32 workspaces;
if (message->FindInt32("workspaces", (int32*)&workspaces) == B_OK) if (message->FindInt32("workspaces", (int32*)&workspaces) == B_OK)
@@ -369,7 +374,7 @@ MainWindow::SaveSettings(BMessage* message)
if (message->ReplaceFloat("border distance", fBorderDist) != B_OK) if (message->ReplaceFloat("border distance", fBorderDist) != B_OK)
message->AddFloat("border distance", fBorderDist); message->AddFloat("border distance", fBorderDist);
// store window frame // store window frame
if (message->ReplaceRect("window frame", Frame()) != B_OK) if (message->ReplaceRect("window frame", Frame()) != B_OK)
message->AddRect("window frame", Frame()); message->AddRect("window frame", Frame());
@@ -403,7 +408,7 @@ MainWindow::SaveSettings(BMessage* message)
else else
message->AddString("signature", ""); message->AddString("signature", "");
} }
// store auto raise setting // store auto raise setting
if (message->ReplaceBool("auto raise", fAutoRaise) != B_OK) if (message->ReplaceBool("auto raise", fAutoRaise) != B_OK)
message->AddBool("auto raise", fAutoRaise); message->AddBool("auto raise", fAutoRaise);
@@ -421,7 +426,8 @@ MainWindow::_GetLocation()
{ {
BRect frame = Frame(); BRect frame = Frame();
BPoint origin = frame.LeftTop(); BPoint origin = frame.LeftTop();
BPoint center(origin.x + frame.Width() / 2.0, origin.y + frame.Height() / 2.0); BPoint center(origin.x + frame.Width() / 2.0,
origin.y + frame.Height() / 2.0);
BScreen screen(this); BScreen screen(this);
BRect screenFrame = screen.Frame(); BRect screenFrame = screen.Frame();
fScreenPosition.x = center.x / screenFrame.Width(); fScreenPosition.x = center.x / screenFrame.Width();
@@ -448,9 +454,9 @@ MainWindow::_AdjustLocation(BRect frame)
BScreen screen(this); BScreen screen(this);
BRect screenFrame = screen.Frame(); BRect screenFrame = screen.Frame();
BPoint center(fScreenPosition.x * screenFrame.Width(), BPoint center(fScreenPosition.x * screenFrame.Width(),
fScreenPosition.y * screenFrame.Height()); fScreenPosition.y * screenFrame.Height());
BPoint frameCenter(frame.left + frame.Width() / 2.0, BPoint frameCenter(frame.left + frame.Width() / 2.0,
frame.top + frame.Height() / 2.0); frame.top + frame.Height() / 2.0);
frame.OffsetBy(center - frameCenter); frame.OffsetBy(center - frameCenter);
// ignore border dist when distance too large // ignore border dist when distance too large
if (fBorderDist < 10.0) { if (fBorderDist < 10.0) {