Keymap mod keys: Move ConflictView to top.

Also, move includes from .h to .cpp file.

Make _FillSavedIcon() private, make Draw() public.
This commit is contained in:
John Scipione 2013-08-19 14:57:32 -04:00
parent 222b10cbc0
commit 2388b04ab8
2 changed files with 161 additions and 155 deletions

View File

@ -13,19 +13,26 @@
#include <stdlib.h>
#include <string.h>
#include <Bitmap.h>
#include <Button.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <FindDirectory.h>
#include <GroupLayout.h>
#include <GridLayoutBuilder.h>
#include <GroupLayoutBuilder.h>
#include <IconUtils.h>
#include <Locale.h>
#include <InterfaceDefs.h>
#include <LayoutBuilder.h>
#include <Locale.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <Message.h>
#include <Path.h>
#include <PopUpMenu.h>
#include <Resources.h>
#include <Size.h>
#include <StringView.h>
#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;
}
}

View File

@ -9,17 +9,30 @@
#define MODIFIER_KEYS_WINDOW_H
#include <Bitmap.h>
#include <Button.h>
#include <CheckBox.h>
#include <InterfaceDefs.h>
#include <MenuField.h>
#include <PopUpMenu.h>
#include <StringView.h>
#include <Window.h>
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