@@ -1,176 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2001-2008, Haiku.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Rafael Romo
|
|
||||||
* Stefano Ceccherini ([email protected])
|
|
||||||
* Axel Dörfler, [email protected]
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "AlertView.h"
|
|
||||||
#include "Constants.h"
|
|
||||||
|
|
||||||
#include <Window.h>
|
|
||||||
#include <Bitmap.h>
|
|
||||||
#include <Button.h>
|
|
||||||
#include <Catalog.h>
|
|
||||||
#include <StringView.h>
|
|
||||||
#include <String.h>
|
|
||||||
#include <TimeUnitFormat.h>
|
|
||||||
|
|
||||||
#include <IconUtils.h>
|
|
||||||
#include <FindDirectory.h>
|
|
||||||
#include <Resources.h>
|
|
||||||
#include <File.h>
|
|
||||||
#include <Path.h>
|
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
|
||||||
#define B_TRANSLATION_CONTEXT "Screen"
|
|
||||||
|
|
||||||
|
|
||||||
AlertView::AlertView(BRect frame, const char *name)
|
|
||||||
: BView(frame, name, B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED),
|
|
||||||
// we will wait 12 seconds until we send a message
|
|
||||||
fSeconds(12)
|
|
||||||
{
|
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
|
||||||
fBitmap = InitIcon();
|
|
||||||
|
|
||||||
BRect rect(60, 8, 400, 36);
|
|
||||||
BStringView *stringView = new BStringView(rect, NULL,
|
|
||||||
B_TRANSLATE("Do you wish to keep these settings?"));
|
|
||||||
stringView->SetFont(be_bold_font);
|
|
||||||
stringView->ResizeToPreferred();
|
|
||||||
AddChild(stringView);
|
|
||||||
|
|
||||||
rect = stringView->Frame();
|
|
||||||
rect.OffsetBy(0, rect.Height());
|
|
||||||
fCountdownView = new BStringView(rect, "countdown", NULL);
|
|
||||||
UpdateCountdownView();
|
|
||||||
fCountdownView->ResizeToPreferred();
|
|
||||||
AddChild(fCountdownView);
|
|
||||||
|
|
||||||
BButton* keepButton = new BButton(rect, "keep", B_TRANSLATE("Keep"),
|
|
||||||
new BMessage(BUTTON_KEEP_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
|
||||||
keepButton->ResizeToPreferred();
|
|
||||||
AddChild(keepButton);
|
|
||||||
|
|
||||||
BButton* button = new BButton(rect, "undo", B_TRANSLATE("Undo"),
|
|
||||||
new BMessage(BUTTON_UNDO_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
|
||||||
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();
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
// the view displays a decrementing counter
|
|
||||||
// (until the user must take action)
|
|
||||||
Window()->SetPulseRate(1000000);
|
|
||||||
// every second
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
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
|
|
||||||
AlertView::Pulse()
|
|
||||||
{
|
|
||||||
if (--fSeconds == 0)
|
|
||||||
Window()->PostMessage(BUTTON_UNDO_MSG);
|
|
||||||
else
|
|
||||||
UpdateCountdownView();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AlertView::KeyDown(const char* bytes, int32 numBytes)
|
|
||||||
{
|
|
||||||
if (numBytes == 1 && bytes[0] == B_ESCAPE)
|
|
||||||
Window()->PostMessage(BUTTON_UNDO_MSG);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AlertView::UpdateCountdownView()
|
|
||||||
{
|
|
||||||
BString string;
|
|
||||||
string = B_TRANSLATE("Settings will revert in %seconds.");
|
|
||||||
|
|
||||||
BTimeUnitFormat format;
|
|
||||||
BString tmp;
|
|
||||||
format.Format(tmp, fSeconds, B_TIME_UNIT_SECOND);
|
|
||||||
|
|
||||||
string.ReplaceFirst("%seconds", tmp);
|
|
||||||
fCountdownView->SetText(string.String());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BBitmap*
|
|
||||||
AlertView::InitIcon()
|
|
||||||
{
|
|
||||||
// This is how BAlert gets to its icon
|
|
||||||
BBitmap* icon = NULL;
|
|
||||||
BPath path;
|
|
||||||
if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
|
|
||||||
path.Append("app_server");
|
|
||||||
BResources resources;
|
|
||||||
BFile file;
|
|
||||||
if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK
|
|
||||||
&& resources.SetTo(&file) == B_OK) {
|
|
||||||
size_t size;
|
|
||||||
const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE,
|
|
||||||
"warn", &size);
|
|
||||||
if (data) {
|
|
||||||
icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
|
|
||||||
if (BIconUtils::GetVectorIcon((const uint8*)data, size, icon)
|
|
||||||
!= B_OK) {
|
|
||||||
delete icon;
|
|
||||||
icon = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2001-2005, Haiku.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Rafael Romo
|
|
||||||
* Stefano Ceccherini ([email protected])
|
|
||||||
* Axel Dörfler, [email protected]
|
|
||||||
*/
|
|
||||||
#ifndef ALERT_VIEW_H
|
|
||||||
#define ALERT_VIEW_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <String.h>
|
|
||||||
#include <View.h>
|
|
||||||
|
|
||||||
class BBitmap;
|
|
||||||
class BStringView;
|
|
||||||
|
|
||||||
|
|
||||||
class AlertView : public BView {
|
|
||||||
public:
|
|
||||||
AlertView(BRect frame, const char* name);
|
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
|
||||||
virtual void Draw(BRect updateRect);
|
|
||||||
virtual void Pulse();
|
|
||||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void UpdateCountdownView();
|
|
||||||
BBitmap* InitIcon();
|
|
||||||
|
|
||||||
BStringView* fCountdownView;
|
|
||||||
BBitmap* fBitmap;
|
|
||||||
int32 fSeconds;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* ALERT_VIEW_H */
|
|
||||||
@@ -1,60 +1,117 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2006, Haiku.
|
* Copyright 2001-2015, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Rafael Romo
|
* Rafael Romo
|
||||||
* Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini ([email protected])
|
||||||
* Axel Dörfler, [email protected]
|
* Axel Dörfler, [email protected]
|
||||||
|
* Augustin Cavalier <waddlesplash>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "AlertWindow.h"
|
#include "AlertWindow.h"
|
||||||
#include "AlertView.h"
|
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
|
|
||||||
|
#include <Button.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <TextView.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
#include <Screen.h>
|
#include <TimeUnitFormat.h>
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#define B_TRANSLATION_CONTEXT "Screen"
|
#define B_TRANSLATION_CONTEXT "Screen"
|
||||||
|
|
||||||
|
|
||||||
AlertWindow::AlertWindow(BMessenger target)
|
AlertWindow::AlertWindow(BMessenger handler)
|
||||||
: BWindow(BRect(100.0, 100.0, 400.0, 193.0), B_TRANSLATE("Undo"),
|
: BAlert(B_TRANSLATE("Confirm changes"),
|
||||||
B_MODAL_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
|
"", B_TRANSLATE("Undo"), B_TRANSLATE("Keep")),
|
||||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES),
|
// we will wait 12 seconds until we send a message
|
||||||
fTarget(target)
|
fSeconds(12),
|
||||||
|
fHandler(handler)
|
||||||
{
|
{
|
||||||
fAlertView = new AlertView(Bounds(), "AlertView");
|
SetType(B_WARNING_ALERT);
|
||||||
|
SetPulseRate(1000000);
|
||||||
ResizeTo(fAlertView->Bounds().Width(), fAlertView->Bounds().Height());
|
TextView()->SetStylable(true);
|
||||||
AddChild(fAlertView);
|
TextView()->GetFontAndColor(0, &fOriginalFont);
|
||||||
|
fFont = fOriginalFont;
|
||||||
// center window on screen
|
fFont.SetFace(B_BOLD_FACE);
|
||||||
BScreen screen(this);
|
UpdateCountdownView();
|
||||||
MoveTo(screen.Frame().left + (screen.Frame().Width() - Frame().Width()) / 2,
|
|
||||||
screen.Frame().top + (screen.Frame().Height() - Frame().Height()) / 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AlertWindow::MessageReceived(BMessage *message)
|
AlertWindow::DispatchMessage(BMessage* message, BHandler* handler)
|
||||||
|
{
|
||||||
|
if (message->what == B_PULSE) {
|
||||||
|
if (--fSeconds == 0) {
|
||||||
|
fHandler.SendMessage(BUTTON_UNDO_MSG);
|
||||||
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
|
Hide();
|
||||||
|
} else
|
||||||
|
UpdateCountdownView();
|
||||||
|
}
|
||||||
|
|
||||||
|
BAlert::DispatchMessage(message, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AlertWindow::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case BUTTON_KEEP_MSG:
|
case 'ALTB': // alert button message
|
||||||
fTarget.SendMessage(MAKE_INITIAL_MSG);
|
{
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
int32 which;
|
||||||
|
if (message->FindInt32("which", &which) == B_OK) {
|
||||||
|
if (which == 1)
|
||||||
|
fHandler.SendMessage(MAKE_INITIAL_MSG);
|
||||||
|
else if (which == 0)
|
||||||
|
fHandler.SendMessage(BUTTON_UNDO_MSG);
|
||||||
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
|
Hide();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case BUTTON_UNDO_MSG:
|
case B_KEY_DOWN:
|
||||||
fTarget.SendMessage(BUTTON_UNDO_MSG);
|
{
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
int8 val;
|
||||||
break;
|
if (message->FindInt8("byte", &val) == B_OK && val == B_ESCAPE) {
|
||||||
|
fHandler.SendMessage(BUTTON_UNDO_MSG);
|
||||||
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
|
Hide();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// fall through
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BAlert::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AlertWindow::UpdateCountdownView()
|
||||||
|
{
|
||||||
|
BString str1 = B_TRANSLATE("Do you wish to keep these settings?");
|
||||||
|
BString string = str1;
|
||||||
|
string += "\n";
|
||||||
|
string += B_TRANSLATE("Settings will revert in %seconds.");
|
||||||
|
|
||||||
|
BTimeUnitFormat format;
|
||||||
|
BString tmp;
|
||||||
|
format.Format(tmp, fSeconds, B_TIME_UNIT_SECOND);
|
||||||
|
|
||||||
|
string.ReplaceFirst("%seconds", tmp);
|
||||||
|
// The below is black magic, do not touch. We really need to refactor
|
||||||
|
// BTextView sometime...
|
||||||
|
TextView()->SetFontAndColor(0, str1.Length() + 1, &fOriginalFont,
|
||||||
|
B_FONT_ALL);
|
||||||
|
TextView()->SetText(string.String());
|
||||||
|
TextView()->SetFontAndColor(0, str1.Length(), &fFont, B_FONT_ALL);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,34 +1,39 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2005, Haiku.
|
* Copyright 2001-2015, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Rafael Romo
|
* Rafael Romo
|
||||||
* Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini ([email protected])
|
||||||
* Axel Dörfler, [email protected]
|
* Axel Dörfler, [email protected]
|
||||||
|
* Augustin Cavalier <waddlesplash>
|
||||||
*/
|
*/
|
||||||
#ifndef ALERT_WINDOW_H
|
#ifndef ALERT_WINDOW_H
|
||||||
#define ALERT_WINDOW_H
|
#define ALERT_WINDOW_H
|
||||||
|
|
||||||
|
|
||||||
#include <Window.h>
|
#include <Alert.h>
|
||||||
|
#include <Font.h>
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
class BWindow;
|
||||||
|
|
||||||
|
|
||||||
class BMessageRunner;
|
class AlertWindow : public BAlert {
|
||||||
class BButton;
|
|
||||||
class AlertView;
|
|
||||||
|
|
||||||
|
|
||||||
class AlertWindow : public BWindow {
|
|
||||||
public:
|
public:
|
||||||
AlertWindow(BMessenger target);
|
AlertWindow(BMessenger handler);
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
virtual void DispatchMessage(BMessage* message, BHandler* handler);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMessenger fTarget;
|
void UpdateCountdownView();
|
||||||
AlertView* fAlertView;
|
|
||||||
|
int32 fSeconds;
|
||||||
|
BMessenger fHandler;
|
||||||
|
BFont fOriginalFont;
|
||||||
|
BFont fFont;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* ALERT_WINDOW_H */
|
#endif /* ALERT_WINDOW_H */
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
SubDir HAIKU_TOP src preferences screen ;
|
SubDir HAIKU_TOP src preferences screen ;
|
||||||
|
|
||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
|
||||||
AddSubDirSupportedPlatforms libbe_test ;
|
AddSubDirSupportedPlatforms libbe_test ;
|
||||||
|
|
||||||
UsePrivateHeaders [ FDirName graphics common ] ;
|
UsePrivateHeaders [ FDirName graphics common ] ;
|
||||||
UsePrivateHeaders [ FDirName graphics radeon ] ;
|
UsePrivateHeaders [ FDirName graphics radeon ] ;
|
||||||
UsePrivateHeaders interface ;
|
UsePrivateHeaders interface ;
|
||||||
|
|
||||||
|
SubDirC++Flags -O0 -g ;
|
||||||
Preference Screen :
|
Preference Screen :
|
||||||
AlertView.cpp
|
|
||||||
AlertWindow.cpp
|
AlertWindow.cpp
|
||||||
MonitorView.cpp
|
MonitorView.cpp
|
||||||
multimon.cpp
|
multimon.cpp
|
||||||
@@ -31,7 +30,6 @@ if $(TARGET_PLATFORM) = libbe_test {
|
|||||||
DoCatalogs Screen :
|
DoCatalogs Screen :
|
||||||
x-vnd.Haiku-Screen
|
x-vnd.Haiku-Screen
|
||||||
:
|
:
|
||||||
AlertView.cpp
|
|
||||||
AlertWindow.cpp
|
AlertWindow.cpp
|
||||||
RefreshSlider.cpp
|
RefreshSlider.cpp
|
||||||
RefreshWindow.cpp
|
RefreshWindow.cpp
|
||||||
|
|||||||
@@ -1336,8 +1336,8 @@ ScreenWindow::_Apply()
|
|||||||
fActive = fSelected;
|
fActive = fSelected;
|
||||||
|
|
||||||
// TODO: only show alert when this is an unknown mode
|
// TODO: only show alert when this is an unknown mode
|
||||||
BWindow* window = new AlertWindow(this);
|
BAlert* window = new AlertWindow(this);
|
||||||
window->Show();
|
window->Go(NULL);
|
||||||
} else {
|
} else {
|
||||||
char message[256];
|
char message[256];
|
||||||
snprintf(message, sizeof(message),
|
snprintf(message, sizeof(message),
|
||||||
|
|||||||
Reference in New Issue
Block a user