[haiku-commits] haiku: hrev49585 - src/preferences/screen

  • From: waddlesplash@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 27 Aug 2015 03:21:53 +0200 (CEST)

hrev49585 adds 2 changesets to branch 'master'
old head: da1815146999aa993efcf62669ccfc3f552c978b
new head: 41f43d568fa1f2af68bd3209850cb0b349b49ff4
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=41f43d568fa1+%5Eda1815146999

----------------------------------------------------------------------------

1ea54e567e1d: docs/user: BAlert: Fix incorrect ::TextView() docs.

TextView() returns *the* BTextView the BAlert is using, not a new
TextView with the contents of the BAlert (which is what this seemed to
imply).

41f43d568fa1: Screen: Rework AlertView to just use BAlert.

Fixes #12330.

[ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

7 files changed, 104 insertions(+), 259 deletions(-)
docs/user/interface/Alert.dox | 4 +-
src/preferences/screen/AlertView.cpp | 176 ----------------------------
src/preferences/screen/AlertView.h | 39 ------
src/preferences/screen/AlertWindow.cpp | 105 +++++++++++++----
src/preferences/screen/AlertWindow.h | 27 +++--
src/preferences/screen/Jamfile | 4 +-
src/preferences/screen/ScreenWindow.cpp | 8 +-

############################################################################

Commit: 1ea54e567e1dcb60302e6a685c0ab99ed27bad16
URL: http://cgit.haiku-os.org/haiku/commit/?id=1ea54e567e1d
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Tue Aug 25 14:25:10 2015 UTC

docs/user: BAlert: Fix incorrect ::TextView() docs.

TextView() returns *the* BTextView the BAlert is using, not a new
TextView with the contents of the BAlert (which is what this seemed to
imply).

----------------------------------------------------------------------------

diff --git a/docs/user/interface/Alert.dox b/docs/user/interface/Alert.dox
index b92ec9a..d4be24c 100644
--- a/docs/user/interface/Alert.dox
+++ b/docs/user/interface/Alert.dox
@@ -227,7 +227,7 @@ int32 button_index = alert->Go();
See button_width for details.
\param spacing Determines how the buttons are spaced. Options are
\li \c B_EVEN_SPACING
- \li \c B_OFFSET_SPACING
+ \li \c B_OFFSET_SPACING

See button_spacing for details.
\param type Constant that determines which alert icon is displayed.
@@ -408,7 +408,7 @@ int32 button_index = alert->Go();

/*!
\fn BTextView* BAlert::TextView() const
- \brief Returns a TextView containing the text of the Alert.
+ \brief Returns the Alert's TextView.

\since BeOS R3
*/

############################################################################

Revision: hrev49585
Commit: 41f43d568fa1f2af68bd3209850cb0b349b49ff4
URL: http://cgit.haiku-os.org/haiku/commit/?id=41f43d568fa1
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Wed Aug 26 18:36:59 2015 UTC

Ticket: https://dev.haiku-os.org/ticket/12330

Screen: Rework AlertView to just use BAlert.

Fixes #12330.

----------------------------------------------------------------------------

diff --git a/src/preferences/screen/AlertView.cpp
b/src/preferences/screen/AlertView.cpp
deleted file mode 100644
index 7d50749..0000000
--- a/src/preferences/screen/AlertView.cpp
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright 2001-2008, Haiku.
- * Distributed under the terms of the MIT License.
- *
- * Authors:
- * Rafael Romo
- * Stefano Ceccherini (burton666@xxxxxxxxx)
- * Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
- */
-
-
-#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;
-}
diff --git a/src/preferences/screen/AlertView.h
b/src/preferences/screen/AlertView.h
deleted file mode 100644
index 66432b3..0000000
--- a/src/preferences/screen/AlertView.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2001-2005, Haiku.
- * Distributed under the terms of the MIT License.
- *
- * Authors:
- * Rafael Romo
- * Stefano Ceccherini (burton666@xxxxxxxxx)
- * Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
- */
-#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 */
diff --git a/src/preferences/screen/AlertWindow.cpp
b/src/preferences/screen/AlertWindow.cpp
index 51943fd..8d9ec10 100644
--- a/src/preferences/screen/AlertWindow.cpp
+++ b/src/preferences/screen/AlertWindow.cpp
@@ -1,60 +1,117 @@
/*
- * Copyright 2001-2006, Haiku.
+ * Copyright 2001-2015, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Rafael Romo
* Stefano Ceccherini (burton666@xxxxxxxxx)
* Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
+ * Augustin Cavalier <waddlesplash>
*/

+
#include "AlertWindow.h"
-#include "AlertView.h"
#include "Constants.h"

+#include <Button.h>
#include <Catalog.h>
+#include <String.h>
+#include <TextView.h>
#include <Window.h>
-#include <Screen.h>
+#include <TimeUnitFormat.h>


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Screen"


-AlertWindow::AlertWindow(BMessenger target)
- : BWindow(BRect(100.0, 100.0, 400.0, 193.0), B_TRANSLATE("Undo"),
- B_MODAL_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
- B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES),
- fTarget(target)
+AlertWindow::AlertWindow(BMessenger handler)
+ : BAlert(B_TRANSLATE("Confirm changes"),
+ "", B_TRANSLATE("Undo"), B_TRANSLATE("Keep")),
+ // we will wait 12 seconds until we send a message
+ fSeconds(12),
+ fHandler(handler)
{
- fAlertView = new AlertView(Bounds(), "AlertView");
+ SetType(B_WARNING_ALERT);
+ SetPulseRate(1000000);
+ TextView()->SetStylable(true);
+ TextView()->GetFontAndColor(0, &fOriginalFont);
+ fFont = fOriginalFont;
+ fFont.SetFace(B_BOLD_FACE);
+ UpdateCountdownView();
+}

- ResizeTo(fAlertView->Bounds().Width(), fAlertView->Bounds().Height());
- AddChild(fAlertView);

- // center window on screen
- BScreen screen(this);
- MoveTo(screen.Frame().left + (screen.Frame().Width() - Frame().Width())
/ 2,
- screen.Frame().top + (screen.Frame().Height() -
Frame().Height()) / 2);
+void
+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)
+AlertWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
- case BUTTON_KEEP_MSG:
- fTarget.SendMessage(MAKE_INITIAL_MSG);
- PostMessage(B_QUIT_REQUESTED);
+ case 'ALTB': // alert button message
+ {
+ 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;
+ }

- case BUTTON_UNDO_MSG:
- fTarget.SendMessage(BUTTON_UNDO_MSG);
- PostMessage(B_QUIT_REQUESTED);
- break;
+ case B_KEY_DOWN:
+ {
+ int8 val;
+ if (message->FindInt8("byte", &val) == B_OK && val ==
B_ESCAPE) {
+ fHandler.SendMessage(BUTTON_UNDO_MSG);
+ PostMessage(B_QUIT_REQUESTED);
+ Hide();
+ break;
+ }
+ // fall through
+ }

default:
- BWindow::MessageReceived(message);
+ BAlert::MessageReceived(message);
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);
+}
diff --git a/src/preferences/screen/AlertWindow.h
b/src/preferences/screen/AlertWindow.h
index d216757..48a4d00 100644
--- a/src/preferences/screen/AlertWindow.h
+++ b/src/preferences/screen/AlertWindow.h
@@ -1,34 +1,39 @@
/*
- * Copyright 2001-2005, Haiku.
+ * Copyright 2001-2015, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Rafael Romo
* Stefano Ceccherini (burton666@xxxxxxxxx)
* Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
+ * Augustin Cavalier <waddlesplash>
*/
#ifndef ALERT_WINDOW_H
#define ALERT_WINDOW_H


-#include <Window.h>
+#include <Alert.h>
+#include <Font.h>
#include <Messenger.h>
+#include <String.h>

+class BWindow;

-class BMessageRunner;
-class BButton;
-class AlertView;

-
-class AlertWindow : public BWindow {
+class AlertWindow : public BAlert {
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:
- BMessenger fTarget;
- AlertView* fAlertView;
+ void UpdateCountdownView();
+
+ int32 fSeconds;
+ BMessenger fHandler;
+ BFont fOriginalFont;
+ BFont fFont;
};

#endif /* ALERT_WINDOW_H */
diff --git a/src/preferences/screen/Jamfile b/src/preferences/screen/Jamfile
index d2370cd..ba8bc57 100644
--- a/src/preferences/screen/Jamfile
+++ b/src/preferences/screen/Jamfile
@@ -1,14 +1,13 @@
SubDir HAIKU_TOP src preferences screen ;

-SetSubDirSupportedPlatformsBeOSCompatible ;
AddSubDirSupportedPlatforms libbe_test ;

UsePrivateHeaders [ FDirName graphics common ] ;
UsePrivateHeaders [ FDirName graphics radeon ] ;
UsePrivateHeaders interface ;

+SubDirC++Flags -O0 -g ;
Preference Screen :
- AlertView.cpp
AlertWindow.cpp
MonitorView.cpp
multimon.cpp
@@ -31,7 +30,6 @@ if $(TARGET_PLATFORM) = libbe_test {
DoCatalogs Screen :
x-vnd.Haiku-Screen
:
- AlertView.cpp
AlertWindow.cpp
RefreshSlider.cpp
RefreshWindow.cpp
diff --git a/src/preferences/screen/ScreenWindow.cpp
b/src/preferences/screen/ScreenWindow.cpp
index 3ccc5a3..29f38dd 100644
--- a/src/preferences/screen/ScreenWindow.cpp
+++ b/src/preferences/screen/ScreenWindow.cpp
@@ -1185,7 +1185,7 @@ void
ScreenWindow::_CheckApplyEnabled()
{
bool applyEnabled = true;
-
+
if (fSelected == fActive) {
applyEnabled = false;
if (fAllWorkspacesItem->IsMarked()) {
@@ -1200,7 +1200,7 @@ ScreenWindow::_CheckApplyEnabled()
}
}
}
-
+
fApplyButton->SetEnabled(applyEnabled);

uint32 columns;
@@ -1336,8 +1336,8 @@ ScreenWindow::_Apply()
fActive = fSelected;

// TODO: only show alert when this is an unknown mode
- BWindow* window = new AlertWindow(this);
- window->Show();
+ BAlert* window = new AlertWindow(this);
+ window->Go(NULL);
} else {
char message[256];
snprintf(message, sizeof(message),


Other related posts:

  • » [haiku-commits] haiku: hrev49585 - src/preferences/screen - waddlesplash