2 * Copyright 2001-2015, Haiku.
3 * Distributed under the terms of the MIT License.
7 * Stefano Ceccherini (burton666@libero.it)
8 * Axel Dörfler, axeld@pinc-software.de
9 * Augustin Cavalier <waddlesplash>
13 #include "AlertWindow.h"
14 #include "Constants.h"
21 #include <TimeUnitFormat.h>
24 #undef B_TRANSLATION_CONTEXT
25 #define B_TRANSLATION_CONTEXT "Screen"
28 AlertWindow::AlertWindow(BMessenger handler
)
29 : BAlert(B_TRANSLATE("Confirm changes"),
30 "", B_TRANSLATE("Undo"), B_TRANSLATE("Keep")),
31 // we will wait 12 seconds until we send a message
35 SetType(B_WARNING_ALERT
);
36 SetPulseRate(1000000);
37 TextView()->SetStylable(true);
38 TextView()->GetFontAndColor(0, &fOriginalFont
);
39 fFont
= fOriginalFont
;
40 fFont
.SetFace(B_BOLD_FACE
);
41 UpdateCountdownView();
46 AlertWindow::DispatchMessage(BMessage
* message
, BHandler
* handler
)
48 if (message
->what
== B_PULSE
) {
49 if (--fSeconds
== 0) {
50 fHandler
.SendMessage(BUTTON_UNDO_MSG
);
51 PostMessage(B_QUIT_REQUESTED
);
54 UpdateCountdownView();
57 BAlert::DispatchMessage(message
, handler
);
62 AlertWindow::MessageReceived(BMessage
* message
)
64 switch (message
->what
) {
65 case 'ALTB': // alert button message
68 if (message
->FindInt32("which", &which
) == B_OK
) {
70 fHandler
.SendMessage(MAKE_INITIAL_MSG
);
72 fHandler
.SendMessage(BUTTON_UNDO_MSG
);
73 PostMessage(B_QUIT_REQUESTED
);
82 if (message
->FindInt8("byte", &val
) == B_OK
&& val
== B_ESCAPE
) {
83 fHandler
.SendMessage(BUTTON_UNDO_MSG
);
84 PostMessage(B_QUIT_REQUESTED
);
92 BAlert::MessageReceived(message
);
99 AlertWindow::UpdateCountdownView()
101 BString str1
= B_TRANSLATE("Do you wish to keep these settings?");
102 BString string
= str1
;
104 string
+= B_TRANSLATE("Settings will revert in %seconds.");
106 BTimeUnitFormat format
;
108 format
.Format(tmp
, fSeconds
, B_TIME_UNIT_SECOND
);
110 string
.ReplaceFirst("%seconds", tmp
);
111 // The below is black magic, do not touch. We really need to refactor
112 // BTextView sometime...
113 TextView()->SetFontAndColor(0, str1
.Length() + 1, &fOriginalFont
,
115 TextView()->SetText(string
.String());
116 TextView()->SetFontAndColor(0, str1
.Length(), &fFont
, B_FONT_ALL
);