Skip to content

Commit

Permalink
Keymap mod keys: Move ConflictView to top.
Browse files Browse the repository at this point in the history
Also, move includes from .h to .cpp file.

Make _FillSavedIcon() private, make Draw() public.
  • Loading branch information
jscipione committed Aug 19, 2013
1 parent 222b10c commit 2388b04
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 155 deletions.
270 changes: 140 additions & 130 deletions src/preferences/keymap/ModifierKeysWindow.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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;
}
}
46 changes: 21 additions & 25 deletions src/preferences/keymap/ModifierKeysWindow.h
Expand Up @@ -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:
Expand Down Expand Up @@ -70,21 +83,4 @@ class ModifierKeysWindow : public BWindow {
};


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

0 comments on commit 2388b04

Please sign in to comment.