Fixed some issues in the "keep settings" alert:

* pressing the escape key now exits the window as it should be (SetEventMask()
  was called in the constructor, but has no effect as long as the view isn't
  attached to a window).
* The window is now font sensitive (fixing bug #450).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17159 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-04-17 23:22:12 +00:00
parent 8165fa3936
commit 50f6c62f4b
3 changed files with 47 additions and 27 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2005, Haiku.
* Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -29,60 +29,81 @@ AlertView::AlertView(BRect frame, char *name)
// we will wait 8 seconds until we send a message
fSeconds(8)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fBitmap = InitIcon();
BStringView *stringView = new BStringView(BRect(60, 20, 400, 36), NULL,
BRect rect(60, 8, 400, 36);
BStringView *stringView = new BStringView(rect, NULL,
"Do you wish to keep these settings?");
stringView->SetFont(be_bold_font);
stringView->ResizeToPreferred();
AddChild(stringView);
fCountdownView = new BStringView(BRect(60, 37, 400, 50), "countdown",
B_EMPTY_STRING);
rect = stringView->Frame();
rect.OffsetBy(0, rect.Height());
fCountdownView = new BStringView(rect, "countdown", NULL);
UpdateCountdownView();
fCountdownView->ResizeToPreferred();
AddChild(fCountdownView);
BButton *button = new BButton(BRect(215, 59, 400, 190), "keep", "Keep",
new BMessage(BUTTON_KEEP_MSG));
BButton* keepButton = new BButton(rect, "keep", "Keep",
new BMessage(BUTTON_KEEP_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
keepButton->ResizeToPreferred();
AddChild(keepButton);
BButton* button = new BButton(rect, "revert", "Revert",
new BMessage(BUTTON_REVERT_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
button->ResizeToPreferred();
AddChild(button);
button = new BButton(BRect(130, 59, 400, 199), "revert", "Revert",
new BMessage(BUTTON_REVERT_MSG));
button->ResizeToPreferred();
AddChild(button);
// we're resizing ourselves to the right size
// (but we're not implementing GetPreferredSize(), bad style!)
float width = stringView->Frame().right;
if (fCountdownView->Frame().right > width)
width = fCountdownView->Frame().right;
if (width < Bounds().Width())
width = Bounds().Width();
SetEventMask(B_KEYBOARD_EVENTS);
float height = fCountdownView->Frame().bottom + 24 + button->Bounds().Height();
ResizeTo(width, height);
keepButton->MoveTo(Bounds().Width() - 8 - keepButton->Bounds().Width(),
Bounds().Height() - 8 - keepButton->Bounds().Height());
button->MoveTo(keepButton->Frame().left - button->Bounds().Width() - 8,
keepButton->Frame().top);
keepButton->MakeDefault(true);
}
void
AlertView::AttachedToWindow()
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
// the view displays a decrementing counter (until the user must take action)
Window()->SetPulseRate(1000000);
// every second
if (BButton* button = dynamic_cast<BButton *>(FindView("keep")))
Window()->SetDefaultButton(button);
SetEventMask(B_KEYBOARD_EVENTS);
}
void
AlertView::Draw(BRect updateRect)
{
{
rgb_color dark = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT);
SetHighColor(dark);
SetHighColor(dark);
FillRect(BRect(0.0, 0.0, 30.0, 100.0));
FillRect(BRect(0.0, 0.0, 30.0, Bounds().bottom));
if (fBitmap != NULL) {
SetDrawingMode(B_OP_ALPHA);
DrawBitmap(fBitmap, BPoint(18.0, 6.0));
SetDrawingMode(B_OP_COPY);
}
}
void
void
AlertView::Pulse()
{
if (--fSeconds == 0)

View File

@ -20,7 +20,7 @@ class BStringView;
class AlertView : public BView {
public:
AlertView(BRect frame, char *name);
AlertView(BRect frame, char* name);
virtual void AttachedToWindow();
virtual void Draw(BRect updateRect);
@ -29,11 +29,11 @@ class AlertView : public BView {
private:
void UpdateCountdownView();
BBitmap *InitIcon();
BBitmap* InitIcon();
BStringView *fCountdownView;
BBitmap *fBitmap;
int32 fSeconds;
BStringView* fCountdownView;
BBitmap* fBitmap;
int32 fSeconds;
};
#endif /* ALERT_VIEW_H */

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2005, Haiku.
* Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -23,10 +23,9 @@ AlertWindow::AlertWindow(BMessenger target)
fTarget(target)
{
fAlertView = new AlertView(Bounds(), "AlertView");
AddChild(fAlertView);
// the view displays a decrementing counter (until the user must take action)
SetPulseRate(1000000); // every second
ResizeTo(fAlertView->Bounds().Width(), fAlertView->Bounds().Height());
AddChild(fAlertView);
// center window on screen
BScreen screen(this);