From 2388b04ab89c5cb78f6038c235b9659b90149b04 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 19 Aug 2013 14:57:32 -0400 Subject: [PATCH] Keymap mod keys: Move ConflictView to top. Also, move includes from .h to .cpp file. Make _FillSavedIcon() private, make Draw() public. --- src/preferences/keymap/ModifierKeysWindow.cpp | 270 +++++++++--------- src/preferences/keymap/ModifierKeysWindow.h | 46 ++- 2 files changed, 161 insertions(+), 155 deletions(-) diff --git a/src/preferences/keymap/ModifierKeysWindow.cpp b/src/preferences/keymap/ModifierKeysWindow.cpp index 9596359513..714bc9584b 100644 --- a/src/preferences/keymap/ModifierKeysWindow.cpp +++ b/src/preferences/keymap/ModifierKeysWindow.cpp @@ -13,19 +13,26 @@ #include #include +#include +#include #include +#include #include #include #include #include #include -#include +#include #include +#include +#include #include #include #include +#include #include #include +#include #include "KeymapApplication.h" @@ -65,6 +72,138 @@ static const uint32 kMsgRevertModifiers = 'rvmd'; #define B_TRANSLATION_CONTEXT "Modifier keys window" +// #pragma mark - ConflictView + + +ConflictView::ConflictView(const char* name) + : + BView(BRect(0, 0, 15, 15), name, B_FOLLOW_NONE, B_WILL_DRAW), + fIcon(NULL), + fSavedIcon(NULL) +{ + _FillSavedIcon(); +} + + +ConflictView::~ConflictView() +{ + delete fSavedIcon; +} + + +void +ConflictView::Draw(BRect updateRect) +{ + // Draw background + + if (Parent()) + SetLowColor(Parent()->ViewColor()); + else + SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + FillRect(updateRect, B_SOLID_LOW); + + // Draw icon + if (fIcon == NULL) + return; + + SetDrawingMode(B_OP_ALPHA); + SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); + DrawBitmapAsync(fIcon, BPoint(0, 0)); +} + + +// get the icon +BBitmap* +ConflictView::Icon() +{ + return fIcon; +} + + +// show or hide the icon +void +ConflictView::ShowIcon(bool show) +{ + if (show) + fIcon = fSavedIcon; + else + fIcon = NULL; +} + + +// #pragma mark - ConflictView Private Methods + + +// fill out the icon with the stop symbol from app_server +void +ConflictView::_FillSavedIcon() +{ + // return if the fSavedIcon has already been filled out + if (fSavedIcon != NULL && fSavedIcon->InitCheck() == B_OK) + return; + + BPath path; + status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path); + if (status < B_OK) { + FTRACE((stderr, + "_FillWarningIcon() - find_directory failed: %s\n", + strerror(status))); + delete fSavedIcon; + fSavedIcon = NULL; + return; + } + + path.Append("app_server"); + BFile file; + status = file.SetTo(path.Path(), B_READ_ONLY); + if (status < B_OK) { + FTRACE((stderr, + "_FillWarningIcon() - BFile init failed: %s\n", + strerror(status))); + delete fSavedIcon; + fSavedIcon = NULL; + return; + } + + BResources resources; + status = resources.SetTo(&file); + if (status < B_OK) { + FTRACE((stderr, + "_WarningIcon() - BResources init failed: %s\n", + strerror(status))); + delete fSavedIcon; + fSavedIcon = NULL; + return; + } + + // Allocate the fSavedIcon bitmap + fSavedIcon = new(std::nothrow) BBitmap(BRect(0, 0, 15, 15), 0, B_RGBA32); + if (fSavedIcon->InitCheck() < B_OK) { + FTRACE((stderr, "_WarningIcon() - No memory for warning bitmap\n")); + delete fSavedIcon; + fSavedIcon = NULL; + return; + } + + // Load the raw stop icon data + size_t size = 0; + const uint8* rawIcon; + rawIcon = (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE, + "stop", &size); + + // load vector warning icon into fSavedIcon + if (rawIcon == NULL + || BIconUtils::GetVectorIcon(rawIcon, size, fSavedIcon) < B_OK) { + delete fSavedIcon; + fSavedIcon = NULL; + } +} + + +// #pragma mark - ModifierKeysWindow + + ModifierKeysWindow::ModifierKeysWindow() : BWindow(BRect(0, 0, 360, 220), B_TRANSLATE("Modifier keys"), @@ -653,132 +792,3 @@ ModifierKeysWindow::_DuplicateKeys() return duplicateMask; } - - -// #pragma mark - ConflictView - - -ConflictView::ConflictView(const char* name) - : - BView(BRect(0, 0, 15, 15), name, B_FOLLOW_NONE, B_WILL_DRAW), - fIcon(NULL), - fSavedIcon(NULL) -{ - _FillSavedIcon(); -} - - -ConflictView::~ConflictView() -{ - delete fSavedIcon; -} - - -void -ConflictView::Draw(BRect updateRect) -{ - // Draw background - - if (Parent()) - SetLowColor(Parent()->ViewColor()); - else - SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - FillRect(updateRect, B_SOLID_LOW); - - // Draw icon - if (fIcon == NULL) - return; - - SetDrawingMode(B_OP_ALPHA); - SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); - DrawBitmapAsync(fIcon, BPoint(0, 0)); -} - - -// get the icon -BBitmap* -ConflictView::Icon() -{ - return fIcon; -} - - -// show or hide the icon -void -ConflictView::ShowIcon(bool show) -{ - if (show) - fIcon = fSavedIcon; - else - fIcon = NULL; -} - - -// #pragma mark - - - -// fill out the icon with the stop symbol from app_server -void -ConflictView::_FillSavedIcon() -{ - // return if the fSavedIcon has already been filled out - if (fSavedIcon != NULL && fSavedIcon->InitCheck() == B_OK) - return; - - BPath path; - status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path); - if (status < B_OK) { - FTRACE((stderr, - "_FillWarningIcon() - find_directory failed: %s\n", - strerror(status))); - delete fSavedIcon; - fSavedIcon = NULL; - return; - } - - path.Append("app_server"); - BFile file; - status = file.SetTo(path.Path(), B_READ_ONLY); - if (status < B_OK) { - FTRACE((stderr, - "_FillWarningIcon() - BFile init failed: %s\n", - strerror(status))); - delete fSavedIcon; - fSavedIcon = NULL; - return; - } - - BResources resources; - status = resources.SetTo(&file); - if (status < B_OK) { - FTRACE((stderr, - "_WarningIcon() - BResources init failed: %s\n", - strerror(status))); - delete fSavedIcon; - fSavedIcon = NULL; - return; - } - - // Allocate the fSavedIcon bitmap - fSavedIcon = new(std::nothrow) BBitmap(BRect(0, 0, 15, 15), 0, B_RGBA32); - if (fSavedIcon->InitCheck() < B_OK) { - FTRACE((stderr, "_WarningIcon() - No memory for warning bitmap\n")); - delete fSavedIcon; - fSavedIcon = NULL; - return; - } - - // Load the raw stop icon data - size_t size = 0; - const uint8* rawIcon; - rawIcon = (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE, - "stop", &size); - - // load vector warning icon into fSavedIcon - if (rawIcon == NULL - || BIconUtils::GetVectorIcon(rawIcon, size, fSavedIcon) < B_OK) { - delete fSavedIcon; - fSavedIcon = NULL; - } -} diff --git a/src/preferences/keymap/ModifierKeysWindow.h b/src/preferences/keymap/ModifierKeysWindow.h index a8200eb303..280f5e0661 100644 --- a/src/preferences/keymap/ModifierKeysWindow.h +++ b/src/preferences/keymap/ModifierKeysWindow.h @@ -9,17 +9,30 @@ #define MODIFIER_KEYS_WINDOW_H -#include -#include -#include -#include -#include -#include -#include #include -class ConflictView; +class BMenuField; +class BPopUpMenu; + + +class ConflictView : public BView { +public: + ConflictView(const char* name); + ~ConflictView(); + + virtual void Draw(BRect updateRect); + + BBitmap* Icon(); + void ShowIcon(bool show); + +private: + void _FillSavedIcon(); + + BBitmap* fIcon; + BBitmap* fSavedIcon; +}; + class ModifierKeysWindow : public BWindow { public: @@ -70,21 +83,4 @@ private: }; -class ConflictView : public BView { - public: - ConflictView(const char* name); - ~ConflictView(); - BBitmap* Icon(); - void ShowIcon(bool show); - - protected: - virtual void Draw(BRect updateRect); - void _FillSavedIcon(); - - private: - BBitmap* fIcon; - BBitmap* fSavedIcon; -}; - - #endif // MODIFIER_KEYS_WINDOW_H