Place the button description window near the mouse and to
the side of the pad window that has enough room (preferring right/bottom side of pad). The algorithm doesn't strictly prevent the window to be placed outside of the screen in any and all situations, but it should work pretty well in practice. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42975 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, Stephan Aßmus <[email protected]>.
|
* Copyright 2006-2011, Stephan Aßmus <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -22,7 +22,8 @@
|
|||||||
App::App()
|
App::App()
|
||||||
:
|
:
|
||||||
BApplication("application/x-vnd.Haiku-LaunchBox"),
|
BApplication("application/x-vnd.Haiku-LaunchBox"),
|
||||||
fSettingsChanged(false)
|
fSettingsChanged(false),
|
||||||
|
fNamePanelSize(200, 50)
|
||||||
{
|
{
|
||||||
SetPulseRate(3000000);
|
SetPulseRate(3000000);
|
||||||
}
|
}
|
||||||
@@ -47,7 +48,7 @@ App::ReadyToRun()
|
|||||||
bool windowAdded = false;
|
bool windowAdded = false;
|
||||||
BRect frame(50.0, 50.0, 65.0, 100.0);
|
BRect frame(50.0, 50.0, 65.0, 100.0);
|
||||||
|
|
||||||
BMessage settings('sett');
|
BMessage settings;
|
||||||
status_t status = load_settings(&settings, "main_settings", "LaunchBox");
|
status_t status = load_settings(&settings, "main_settings", "LaunchBox");
|
||||||
if (status >= B_OK) {
|
if (status >= B_OK) {
|
||||||
BMessage windowMessage;
|
BMessage windowMessage;
|
||||||
@@ -65,8 +66,11 @@ App::ReadyToRun()
|
|||||||
frame.OffsetBy(10.0, 10.0);
|
frame.OffsetBy(10.0, 10.0);
|
||||||
windowMessage.MakeEmpty();
|
windowMessage.MakeEmpty();
|
||||||
}
|
}
|
||||||
|
BSize size;
|
||||||
|
if (settings.FindSize("name panel size", &size) == B_OK)
|
||||||
|
fNamePanelSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!windowAdded) {
|
if (!windowAdded) {
|
||||||
MainWindow* window = new MainWindow(B_TRANSLATE("Pad 1"), frame, true);
|
MainWindow* window = new MainWindow(B_TRANSLATE("Pad 1"), frame, true);
|
||||||
window->Show();
|
window->Show();
|
||||||
@@ -110,6 +114,28 @@ App::Pulse()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
App::SetNamePanelSize(const BSize& size)
|
||||||
|
{
|
||||||
|
if (Lock()) {
|
||||||
|
fNamePanelSize = size;
|
||||||
|
Unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
App::NamePanelSize()
|
||||||
|
{
|
||||||
|
BSize size;
|
||||||
|
if (Lock()) {
|
||||||
|
size = fNamePanelSize;
|
||||||
|
Unlock();
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
App::_StoreSettingsIfNeeded()
|
App::_StoreSettingsIfNeeded()
|
||||||
{
|
{
|
||||||
@@ -127,6 +153,8 @@ App::_StoreSettingsIfNeeded()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
settings.AddSize("name panel size", fNamePanelSize);
|
||||||
|
|
||||||
save_settings(&settings, "main_settings", "LaunchBox");
|
save_settings(&settings, "main_settings", "LaunchBox");
|
||||||
|
|
||||||
fSettingsChanged = false;
|
fSettingsChanged = false;
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, Stephan Aßmus <[email protected]>.
|
* Copyright 2006-2011, Stephan Aßmus <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef APP_H
|
#ifndef APP_H
|
||||||
#define APP_H
|
#define APP_H
|
||||||
|
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
#include <Size.h>
|
||||||
|
|
||||||
|
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
|
||||||
|
|
||||||
class App : public BApplication {
|
class App : public BApplication {
|
||||||
public:
|
public:
|
||||||
App();
|
App();
|
||||||
@@ -20,10 +24,16 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual void Pulse();
|
virtual void Pulse();
|
||||||
|
|
||||||
|
void SetNamePanelSize(const BSize& size);
|
||||||
|
BSize NamePanelSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _StoreSettingsIfNeeded();
|
void _StoreSettingsIfNeeded();
|
||||||
|
|
||||||
bool fSettingsChanged;
|
bool fSettingsChanged;
|
||||||
|
|
||||||
|
BSize fNamePanelSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // APP_H
|
#endif // APP_H
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006 - 2009, Stephan Aßmus <[email protected]>.
|
* Copyright 2006 - 2011, Stephan Aßmus <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "support.h"
|
#include "support.h"
|
||||||
|
|
||||||
|
#include "App.h"
|
||||||
#include "LaunchButton.h"
|
#include "LaunchButton.h"
|
||||||
#include "NamePanel.h"
|
#include "NamePanel.h"
|
||||||
#include "PadView.h"
|
#include "PadView.h"
|
||||||
@@ -36,7 +37,6 @@ MainWindow::MainWindow(const char* name, BRect frame, bool addDefaultButtons)
|
|||||||
B_ALL_WORKSPACES),
|
B_ALL_WORKSPACES),
|
||||||
fSettings(new BMessage('sett')),
|
fSettings(new BMessage('sett')),
|
||||||
fPadView(new PadView("pad view")),
|
fPadView(new PadView("pad view")),
|
||||||
fNamePanelFrame(-1000.0, -1000.0, -800.0, -900.0),
|
|
||||||
fAutoRaise(false),
|
fAutoRaise(false),
|
||||||
fShowOnAllWorkspaces(true)
|
fShowOnAllWorkspaces(true)
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,6 @@ MainWindow::MainWindow(const char* name, BRect frame, BMessage* settings)
|
|||||||
B_ALL_WORKSPACES),
|
B_ALL_WORKSPACES),
|
||||||
fSettings(settings),
|
fSettings(settings),
|
||||||
fPadView(new PadView("pad view")),
|
fPadView(new PadView("pad view")),
|
||||||
fNamePanelFrame(-1000.0, -1000.0, -900.0, -900.0),
|
|
||||||
fAutoRaise(false),
|
fAutoRaise(false),
|
||||||
fShowOnAllWorkspaces(true)
|
fShowOnAllWorkspaces(true)
|
||||||
{
|
{
|
||||||
@@ -206,17 +205,52 @@ MainWindow::MessageReceived(BMessage* message)
|
|||||||
if (message->FindString("name", &name) >= B_OK) {
|
if (message->FindString("name", &name) >= B_OK) {
|
||||||
// message comes from a previous name panel
|
// message comes from a previous name panel
|
||||||
button->SetDescription(name);
|
button->SetDescription(name);
|
||||||
message->FindRect("frame", &fNamePanelFrame);
|
BRect namePanelFrame;
|
||||||
|
if (message->FindRect("frame", &namePanelFrame) == B_OK) {
|
||||||
|
((App*)be_app)->SetNamePanelSize(
|
||||||
|
namePanelFrame.Size());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// message comes from pad view
|
// message comes from pad view
|
||||||
entry_ref* ref = button->Ref();
|
entry_ref* ref = button->Ref();
|
||||||
if (ref) {
|
if (ref) {
|
||||||
BString helper(B_TRANSLATE("Description for '%3'"));
|
BString helper(B_TRANSLATE("Description for '%3'"));
|
||||||
helper.ReplaceFirst("%3", ref->name);
|
helper.ReplaceFirst("%3", ref->name);
|
||||||
make_sure_frame_is_on_screen(fNamePanelFrame, this);
|
// Place the name panel besides the pad, but give it
|
||||||
new NamePanel(helper.String(), button->Description(),
|
// the user configured size.
|
||||||
this, this, new BMessage(*message),
|
BPoint origin = B_ORIGIN;
|
||||||
fNamePanelFrame);
|
BSize size = ((App*)be_app)->NamePanelSize();
|
||||||
|
NamePanel* panel = new NamePanel(helper.String(),
|
||||||
|
button->Description(), this, this,
|
||||||
|
new BMessage(*message), size);
|
||||||
|
panel->Layout(true);
|
||||||
|
size = panel->Frame().Size();
|
||||||
|
BScreen screen(this);
|
||||||
|
BPoint mousePos;
|
||||||
|
uint32 buttons;
|
||||||
|
fPadView->GetMouse(&mousePos, &buttons, false);
|
||||||
|
fPadView->ConvertToScreen(&mousePos);
|
||||||
|
if (fPadView->Orientation() == B_HORIZONTAL) {
|
||||||
|
// Place above or below the pad
|
||||||
|
origin.x = mousePos.x - size.width / 2;
|
||||||
|
if (screen.Frame().bottom - Frame().bottom
|
||||||
|
> size.height + 20) {
|
||||||
|
origin.y = Frame().bottom + 10;
|
||||||
|
} else {
|
||||||
|
origin.y = Frame().top - 10 - size.height;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Place left or right of the pad
|
||||||
|
origin.y = mousePos.y - size.height / 2;
|
||||||
|
if (screen.Frame().right - Frame().right
|
||||||
|
> size.width + 20) {
|
||||||
|
origin.x = Frame().right + 10;
|
||||||
|
} else {
|
||||||
|
origin.x = Frame().left - 10 - size.width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panel->MoveTo(origin);
|
||||||
|
panel->Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,14 +378,6 @@ MainWindow::LoadSettings(const BMessage* message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore name panel frame
|
|
||||||
if (message->FindRect("name panel frame", &frame) == B_OK) {
|
|
||||||
if (frame.IsValid()) {
|
|
||||||
make_sure_frame_is_on_screen(frame, this);
|
|
||||||
fNamePanelFrame = frame;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// restore window look
|
// restore window look
|
||||||
window_look look;
|
window_look look;
|
||||||
if (message->FindInt32("window look", (int32*)&look) == B_OK)
|
if (message->FindInt32("window look", (int32*)&look) == B_OK)
|
||||||
@@ -429,14 +455,10 @@ 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 and look
|
||||||
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());
|
||||||
|
|
||||||
// store name panel frame
|
|
||||||
if (message->ReplaceRect("name panel frame", fNamePanelFrame) != B_OK)
|
|
||||||
message->AddRect("name panel frame", fNamePanelFrame);
|
|
||||||
|
|
||||||
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());
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, Stephan Aßmus <[email protected]>.
|
* Copyright 2006-2011, Stephan Aßmus <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef MAIN_WINDOW_H
|
#ifndef MAIN_WINDOW_H
|
||||||
@@ -73,8 +73,6 @@ private:
|
|||||||
BPoint fScreenPosition;
|
BPoint fScreenPosition;
|
||||||
// not really the position, 0...1 = left...right
|
// not really the position, 0...1 = left...right
|
||||||
|
|
||||||
BRect fNamePanelFrame;
|
|
||||||
|
|
||||||
bool fAutoRaise;
|
bool fAutoRaise;
|
||||||
bool fShowOnAllWorkspaces;
|
bool fShowOnAllWorkspaces;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, Stephan Aßmus <[email protected]>.
|
* Copyright 2006-2011, Stephan Aßmus <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -15,16 +15,18 @@
|
|||||||
|
|
||||||
#undef B_TRANSLATE_CONTEXT
|
#undef B_TRANSLATE_CONTEXT
|
||||||
#define B_TRANSLATE_CONTEXT "LaunchBox"
|
#define B_TRANSLATE_CONTEXT "LaunchBox"
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MSG_PANEL_OK,
|
MSG_PANEL_OK,
|
||||||
MSG_PANEL_CANCEL,
|
MSG_PANEL_CANCEL,
|
||||||
};
|
};
|
||||||
|
|
||||||
// constructor
|
|
||||||
NamePanel::NamePanel(const char* label, const char* text, BWindow* window,
|
NamePanel::NamePanel(const char* label, const char* text, BWindow* window,
|
||||||
BHandler* target, BMessage* message, BRect frame)
|
BHandler* target, BMessage* message, const BSize& size)
|
||||||
:
|
:
|
||||||
Panel(frame, B_TRANSLATE("Name Panel"),
|
Panel(BRect(B_ORIGIN, size), B_TRANSLATE("Name Panel"),
|
||||||
B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL,
|
B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL,
|
||||||
B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE
|
B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE
|
||||||
| B_AUTO_UPDATE_SIZE_LIMITS),
|
| B_AUTO_UPDATE_SIZE_LIMITS),
|
||||||
@@ -37,6 +39,10 @@ NamePanel::NamePanel(const char* label, const char* text, BWindow* window,
|
|||||||
BButton* cancelButton = new BButton(B_TRANSLATE("Cancel"),
|
BButton* cancelButton = new BButton(B_TRANSLATE("Cancel"),
|
||||||
new BMessage(MSG_PANEL_CANCEL));
|
new BMessage(MSG_PANEL_CANCEL));
|
||||||
fNameTC = new BTextControl(label, text, NULL);
|
fNameTC = new BTextControl(label, text, NULL);
|
||||||
|
BLayoutItem* inputItem = fNameTC->CreateTextViewLayoutItem();
|
||||||
|
inputItem->SetExplicitMinSize(
|
||||||
|
BSize(fNameTC->StringWidth("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"),
|
||||||
|
B_SIZE_UNSET));
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL, 10)
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 10)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
@@ -47,7 +53,7 @@ NamePanel::NamePanel(const char* label, const char* text, BWindow* window,
|
|||||||
|
|
||||||
// text control
|
// text control
|
||||||
.Add(fNameTC->CreateLabelLayoutItem())
|
.Add(fNameTC->CreateLabelLayoutItem())
|
||||||
.Add(fNameTC->CreateTextViewLayoutItem())
|
.Add(inputItem)
|
||||||
.AddStrut(5)
|
.AddStrut(5)
|
||||||
.End()
|
.End()
|
||||||
|
|
||||||
@@ -74,11 +80,6 @@ NamePanel::NamePanel(const char* label, const char* text, BWindow* window,
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddToSubset(fWindow);
|
AddToSubset(fWindow);
|
||||||
|
|
||||||
if (!frame.IsValid())
|
|
||||||
CenterOnScreen();
|
|
||||||
|
|
||||||
Show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, Stephan Aßmus <[email protected]>.
|
* Copyright 2006-2011, Stephan Aßmus <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef NAME_PANEL_H
|
#ifndef NAME_PANEL_H
|
||||||
@@ -11,12 +11,9 @@ class BTextControl;
|
|||||||
|
|
||||||
class NamePanel : public Panel {
|
class NamePanel : public Panel {
|
||||||
public:
|
public:
|
||||||
NamePanel(const char* label,
|
NamePanel(const char* label, const char* text,
|
||||||
const char* text,
|
BWindow* window, BHandler* target,
|
||||||
BWindow* window,
|
BMessage* message, const BSize& size);
|
||||||
BHandler* target,
|
|
||||||
BMessage* message,
|
|
||||||
BRect frame = BRect(-1000.0, -1000.0, -900.0, -900.0));
|
|
||||||
virtual ~NamePanel();
|
virtual ~NamePanel();
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
|||||||
Reference in New Issue
Block a user