* Beautified everything with the help of BControlLook.
* When embedded on the desktop, draw with alpha compositing. * Implemented flashing the pressed keys. * Clicking the calculator icon in compressed mode will evaluate. * Cleaned up dead code, did some refactoring. * Removed Audio Feedback option, since the feature is currently missing support in Haiku. (play_sound() unimplemented) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29763 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+326
-189
@@ -21,14 +21,17 @@
|
|||||||
#include <AppFileInfo.h>
|
#include <AppFileInfo.h>
|
||||||
#include <Beep.h>
|
#include <Beep.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
|
#include <ControlLook.h>
|
||||||
#include <Clipboard.h>
|
#include <Clipboard.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Font.h>
|
#include <Font.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
#include <MessageRunner.h>
|
||||||
#include <PlaySound.h>
|
#include <PlaySound.h>
|
||||||
#include <Point.h>
|
#include <Point.h>
|
||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
|
#include <Region.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
|
|
||||||
#include "CalcApplication.h"
|
#include "CalcApplication.h"
|
||||||
@@ -37,15 +40,20 @@
|
|||||||
#include "ExpressionTextView.h"
|
#include "ExpressionTextView.h"
|
||||||
|
|
||||||
|
|
||||||
const uint8 K_COLOR_OFFSET = 32;
|
//const uint8 K_COLOR_OFFSET = 32;
|
||||||
const float K_FONT_YPROP = 0.6f;
|
const float kFontScaleY = 0.4f;
|
||||||
const float K_FONT_XPROP = 0.6f;
|
const float kFontScaleX = 0.4f;
|
||||||
const float K_DISPLAY_YPROP = 0.2f;
|
const float kExpressionFontScaleY = 0.6f;
|
||||||
|
const float kDisplayScaleY = 0.2f;
|
||||||
|
|
||||||
|
static const bigtime_t kFlashOnOffInterval = 100000;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
K_OPTIONS_AUTO_NUM_LOCK = 'opan',
|
MSG_OPTIONS_AUTO_NUM_LOCK = 'opan',
|
||||||
K_OPTIONS_AUDIO_FEEDBACK = 'opaf',
|
MSG_OPTIONS_AUDIO_FEEDBACK = 'opaf',
|
||||||
K_OPTIONS_SHOW_KEYPAD = 'opsk'
|
MSG_OPTIONS_SHOW_KEYPAD = 'opsk',
|
||||||
|
|
||||||
|
MSG_UNFLASH_KEY = 'uflk'
|
||||||
};
|
};
|
||||||
|
|
||||||
// default calculator key pad layout
|
// default calculator key pad layout
|
||||||
@@ -56,12 +64,17 @@ const char *kDefaultKeypadDescription =
|
|||||||
"0 . BS = C \n";
|
"0 . BS = C \n";
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
FLAGS_FLASH_KEY = 1 << 0,
|
||||||
|
FLAGS_MOUSE_DOWN = 1 << 1
|
||||||
|
};
|
||||||
|
|
||||||
struct CalcView::CalcKey {
|
struct CalcView::CalcKey {
|
||||||
char label[8];
|
char label[8];
|
||||||
char code[8];
|
char code[8];
|
||||||
char keymap[4];
|
char keymap[4];
|
||||||
uint32 flags;
|
uint32 flags;
|
||||||
float width;
|
// float width;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -75,34 +88,35 @@ CalcView *CalcView::Instantiate(BMessage *archive)
|
|||||||
|
|
||||||
|
|
||||||
CalcView::CalcView(BRect frame, rgb_color rgbBaseColor, BMessage *settings)
|
CalcView::CalcView(BRect frame, rgb_color rgbBaseColor, BMessage *settings)
|
||||||
: BView(frame, "DeskCalc", B_FOLLOW_ALL_SIDES,
|
:
|
||||||
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
|
BView(frame, "DeskCalc", B_FOLLOW_ALL_SIDES,
|
||||||
fColums(5),
|
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
|
||||||
fRows(4),
|
fColums(5),
|
||||||
|
fRows(4),
|
||||||
|
|
||||||
fBaseColor(rgbBaseColor),
|
fBaseColor(rgbBaseColor),
|
||||||
fExpressionBGColor((rgb_color){ 0, 0, 0, 255 }),
|
fExpressionBGColor((rgb_color){ 0, 0, 0, 255 }),
|
||||||
|
|
||||||
fWidth(1),
|
fWidth(1),
|
||||||
fHeight(1),
|
fHeight(1),
|
||||||
|
|
||||||
fKeypadDescription(strdup(kDefaultKeypadDescription)),
|
fKeypadDescription(strdup(kDefaultKeypadDescription)),
|
||||||
fKeypad(NULL),
|
fKeypad(NULL),
|
||||||
|
|
||||||
#ifdef __HAIKU__
|
#ifdef __HAIKU__
|
||||||
fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_RGBA32)),
|
fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_RGBA32)),
|
||||||
#else
|
#else
|
||||||
fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_CMAP8)),
|
fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_CMAP8)),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fPopUpMenu(NULL),
|
fPopUpMenu(NULL),
|
||||||
fAutoNumlockItem(NULL),
|
fAutoNumlockItem(NULL),
|
||||||
fAudioFeedbackItem(NULL),
|
fAudioFeedbackItem(NULL),
|
||||||
fShowKeypadItem(NULL),
|
fShowKeypadItem(NULL),
|
||||||
fAboutItem(NULL),
|
fAboutItem(NULL),
|
||||||
|
|
||||||
fOptions(new CalcOptions()),
|
fOptions(new CalcOptions()),
|
||||||
fShowKeypad(true)
|
fShowKeypad(true)
|
||||||
{
|
{
|
||||||
// create expression text view
|
// create expression text view
|
||||||
fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
|
fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
|
||||||
@@ -127,33 +141,34 @@ CalcView::CalcView(BRect frame, rgb_color rgbBaseColor, BMessage *settings)
|
|||||||
|
|
||||||
|
|
||||||
CalcView::CalcView(BMessage* archive)
|
CalcView::CalcView(BMessage* archive)
|
||||||
: BView(archive),
|
:
|
||||||
fColums(5),
|
BView(archive),
|
||||||
fRows(4),
|
fColums(5),
|
||||||
|
fRows(4),
|
||||||
|
|
||||||
fBaseColor((rgb_color){ 128, 128, 128, 255 }),
|
fBaseColor((rgb_color){ 128, 128, 128, 255 }),
|
||||||
fExpressionBGColor((rgb_color){ 0, 0, 0, 255 }),
|
fExpressionBGColor((rgb_color){ 0, 0, 0, 255 }),
|
||||||
|
|
||||||
fWidth(1),
|
fWidth(1),
|
||||||
fHeight(1),
|
fHeight(1),
|
||||||
|
|
||||||
fKeypadDescription(strdup(kDefaultKeypadDescription)),
|
fKeypadDescription(strdup(kDefaultKeypadDescription)),
|
||||||
fKeypad(NULL),
|
fKeypad(NULL),
|
||||||
|
|
||||||
#ifdef __HAIKU__
|
#ifdef __HAIKU__
|
||||||
fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_RGBA32)),
|
fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_RGBA32)),
|
||||||
#else
|
#else
|
||||||
fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_CMAP8)),
|
fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_CMAP8)),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fPopUpMenu(NULL),
|
fPopUpMenu(NULL),
|
||||||
fAutoNumlockItem(NULL),
|
fAutoNumlockItem(NULL),
|
||||||
fAudioFeedbackItem(NULL),
|
fAudioFeedbackItem(NULL),
|
||||||
fShowKeypadItem(NULL),
|
fShowKeypadItem(NULL),
|
||||||
fAboutItem(NULL),
|
fAboutItem(NULL),
|
||||||
|
|
||||||
fOptions(new CalcOptions()),
|
fOptions(new CalcOptions()),
|
||||||
fShowKeypad(true)
|
fShowKeypad(true)
|
||||||
{
|
{
|
||||||
// create expression text view
|
// create expression text view
|
||||||
fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
|
fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
|
||||||
@@ -182,7 +197,8 @@ CalcView::~CalcView()
|
|||||||
void
|
void
|
||||||
CalcView::AttachedToWindow()
|
CalcView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
SetFont(be_bold_font);
|
if (be_control_look == NULL)
|
||||||
|
SetFont(be_bold_font);
|
||||||
|
|
||||||
BRect frame(Frame());
|
BRect frame(Frame());
|
||||||
FrameResized(frame.Width(), frame.Height());
|
FrameResized(frame.Width(), frame.Height());
|
||||||
@@ -219,12 +235,12 @@ CalcView::MessageReceived(BMessage* message)
|
|||||||
// handle paste
|
// handle paste
|
||||||
case B_PASTE:
|
case B_PASTE:
|
||||||
// access system clipboard
|
// access system clipboard
|
||||||
if (be_clipboard->Lock()){
|
if (be_clipboard->Lock()) {
|
||||||
BMessage *clipper = be_clipboard->Data();
|
BMessage *clipper = be_clipboard->Data();
|
||||||
//clipper->PrintToStream();
|
//clipper->PrintToStream();
|
||||||
Paste(clipper);
|
Paste(clipper);
|
||||||
be_clipboard->Unlock();
|
be_clipboard->Unlock();
|
||||||
} // end if
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// (replicant) about box requested
|
// (replicant) about box requested
|
||||||
@@ -232,22 +248,30 @@ CalcView::MessageReceived(BMessage* message)
|
|||||||
AboutRequested();
|
AboutRequested();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case K_OPTIONS_AUTO_NUM_LOCK:
|
case MSG_OPTIONS_AUTO_NUM_LOCK:
|
||||||
fOptions->auto_num_lock = !fOptions->auto_num_lock;
|
fOptions->auto_num_lock = !fOptions->auto_num_lock;
|
||||||
fAutoNumlockItem->SetMarked(fOptions->auto_num_lock);
|
fAutoNumlockItem->SetMarked(fOptions->auto_num_lock);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case K_OPTIONS_AUDIO_FEEDBACK:
|
case MSG_OPTIONS_AUDIO_FEEDBACK:
|
||||||
fOptions->audio_feedback = !fOptions->audio_feedback;
|
fOptions->audio_feedback = !fOptions->audio_feedback;
|
||||||
fAudioFeedbackItem->SetMarked(fOptions->audio_feedback);
|
fAudioFeedbackItem->SetMarked(fOptions->audio_feedback);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case K_OPTIONS_SHOW_KEYPAD:
|
case MSG_OPTIONS_SHOW_KEYPAD:
|
||||||
fOptions->show_keypad = !fOptions->show_keypad;
|
fOptions->show_keypad = !fOptions->show_keypad;
|
||||||
fShowKeypadItem->SetMarked(fOptions->show_keypad);
|
fShowKeypadItem->SetMarked(fOptions->show_keypad);
|
||||||
_ShowKeypad(fOptions->show_keypad);
|
_ShowKeypad(fOptions->show_keypad);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MSG_UNFLASH_KEY:
|
||||||
|
{
|
||||||
|
int32 key;
|
||||||
|
if (message->FindInt32("key", &key) == B_OK)
|
||||||
|
_FlashKey(key, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@@ -259,13 +283,24 @@ CalcView::MessageReceived(BMessage* message)
|
|||||||
void
|
void
|
||||||
CalcView::Draw(BRect updateRect)
|
CalcView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
|
bool drawBackground = true;
|
||||||
|
if (Parent() && Window()->Bounds() != Frame()) {
|
||||||
|
// CalcView is embedded somewhere, most likely the Tracker Desktop
|
||||||
|
// shelf.
|
||||||
|
drawBackground = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetHighColor(fBaseColor);
|
||||||
BRect expressionRect(_ExpressionRect());
|
BRect expressionRect(_ExpressionRect());
|
||||||
if (updateRect.Intersects(expressionRect)) {
|
if (updateRect.Intersects(expressionRect)) {
|
||||||
if (!fShowKeypad && expressionRect.Height() >= fCalcIcon->Bounds().Height()) {
|
if (!fShowKeypad
|
||||||
|
&& expressionRect.Height() >= fCalcIcon->Bounds().Height()) {
|
||||||
// render calc icon
|
// render calc icon
|
||||||
expressionRect.left = fExpressionTextView->Frame().right + 2;
|
expressionRect.left = fExpressionTextView->Frame().right + 2;
|
||||||
SetHighColor(fBaseColor);
|
if (drawBackground) {
|
||||||
FillRect(updateRect & expressionRect);
|
SetHighColor(fBaseColor);
|
||||||
|
FillRect(updateRect & expressionRect);
|
||||||
|
}
|
||||||
|
|
||||||
if (fCalcIcon->ColorSpace() == B_RGBA32) {
|
if (fCalcIcon->ColorSpace() == B_RGBA32) {
|
||||||
SetDrawingMode(B_OP_ALPHA);
|
SetDrawingMode(B_OP_ALPHA);
|
||||||
@@ -287,39 +322,55 @@ CalcView::Draw(BRect updateRect)
|
|||||||
// render border around expression text view
|
// render border around expression text view
|
||||||
expressionRect = fExpressionTextView->Frame();
|
expressionRect = fExpressionTextView->Frame();
|
||||||
expressionRect.InsetBy(-2, -2);
|
expressionRect.InsetBy(-2, -2);
|
||||||
BeginLineArray(8);
|
if (fShowKeypad && drawBackground) {
|
||||||
|
expressionRect.InsetBy(-2, -2);
|
||||||
|
StrokeRect(expressionRect);
|
||||||
|
expressionRect.InsetBy(1, 1);
|
||||||
|
StrokeRect(expressionRect);
|
||||||
|
expressionRect.InsetBy(1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
rgb_color lightShadow = tint_color(fBaseColor, B_DARKEN_1_TINT);
|
if (be_control_look != NULL) {
|
||||||
rgb_color darkShadow = tint_color(fBaseColor, B_DARKEN_3_TINT);
|
uint32 flags = 0;
|
||||||
|
if (!drawBackground)
|
||||||
|
flags |= BControlLook::B_BLEND_FRAME;
|
||||||
|
be_control_look->DrawTextControlBorder(this, expressionRect,
|
||||||
|
updateRect, fBaseColor, flags);
|
||||||
|
} else {
|
||||||
|
BeginLineArray(8);
|
||||||
|
|
||||||
AddLine(BPoint(expressionRect.left, expressionRect.bottom),
|
rgb_color lightShadow = tint_color(fBaseColor, B_DARKEN_1_TINT);
|
||||||
BPoint(expressionRect.left, expressionRect.top),
|
rgb_color darkShadow = tint_color(fBaseColor, B_DARKEN_3_TINT);
|
||||||
lightShadow);
|
|
||||||
AddLine(BPoint(expressionRect.left + 1, expressionRect.top),
|
|
||||||
BPoint(expressionRect.right, expressionRect.top),
|
|
||||||
lightShadow);
|
|
||||||
AddLine(BPoint(expressionRect.right, expressionRect.top + 1),
|
|
||||||
BPoint(expressionRect.right, expressionRect.bottom),
|
|
||||||
fLightColor);
|
|
||||||
AddLine(BPoint(expressionRect.left + 1, expressionRect.bottom),
|
|
||||||
BPoint(expressionRect.right - 1, expressionRect.bottom),
|
|
||||||
fLightColor);
|
|
||||||
|
|
||||||
expressionRect.InsetBy(1, 1);
|
AddLine(BPoint(expressionRect.left, expressionRect.bottom),
|
||||||
AddLine(BPoint(expressionRect.left, expressionRect.bottom),
|
BPoint(expressionRect.left, expressionRect.top),
|
||||||
BPoint(expressionRect.left, expressionRect.top),
|
lightShadow);
|
||||||
darkShadow);
|
AddLine(BPoint(expressionRect.left + 1, expressionRect.top),
|
||||||
AddLine(BPoint(expressionRect.left + 1, expressionRect.top),
|
BPoint(expressionRect.right, expressionRect.top),
|
||||||
BPoint(expressionRect.right, expressionRect.top),
|
lightShadow);
|
||||||
darkShadow);
|
AddLine(BPoint(expressionRect.right, expressionRect.top + 1),
|
||||||
AddLine(BPoint(expressionRect.right, expressionRect.top + 1),
|
BPoint(expressionRect.right, expressionRect.bottom),
|
||||||
BPoint(expressionRect.right, expressionRect.bottom),
|
fLightColor);
|
||||||
fBaseColor);
|
AddLine(BPoint(expressionRect.left + 1, expressionRect.bottom),
|
||||||
AddLine(BPoint(expressionRect.left + 1, expressionRect.bottom),
|
BPoint(expressionRect.right - 1, expressionRect.bottom),
|
||||||
BPoint(expressionRect.right - 1, expressionRect.bottom),
|
fLightColor);
|
||||||
fBaseColor);
|
|
||||||
|
|
||||||
EndLineArray();
|
expressionRect.InsetBy(1, 1);
|
||||||
|
AddLine(BPoint(expressionRect.left, expressionRect.bottom),
|
||||||
|
BPoint(expressionRect.left, expressionRect.top),
|
||||||
|
darkShadow);
|
||||||
|
AddLine(BPoint(expressionRect.left + 1, expressionRect.top),
|
||||||
|
BPoint(expressionRect.right, expressionRect.top),
|
||||||
|
darkShadow);
|
||||||
|
AddLine(BPoint(expressionRect.right, expressionRect.top + 1),
|
||||||
|
BPoint(expressionRect.right, expressionRect.bottom),
|
||||||
|
fBaseColor);
|
||||||
|
AddLine(BPoint(expressionRect.left + 1, expressionRect.bottom),
|
||||||
|
BPoint(expressionRect.right - 1, expressionRect.bottom),
|
||||||
|
fBaseColor);
|
||||||
|
|
||||||
|
EndLineArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fShowKeypad)
|
if (!fShowKeypad)
|
||||||
@@ -327,76 +378,118 @@ CalcView::Draw(BRect updateRect)
|
|||||||
|
|
||||||
// calculate grid sizes
|
// calculate grid sizes
|
||||||
BRect keypadRect(_KeypadRect());
|
BRect keypadRect(_KeypadRect());
|
||||||
|
|
||||||
|
if (be_control_look != NULL) {
|
||||||
|
if (drawBackground)
|
||||||
|
StrokeRect(keypadRect);
|
||||||
|
keypadRect.InsetBy(1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
float sizeDisp = keypadRect.top;
|
float sizeDisp = keypadRect.top;
|
||||||
float sizeCol = fWidth / (float)fColums;
|
float sizeCol = (keypadRect.Width() + 1) / (float)fColums;
|
||||||
float sizeRow = (fHeight - sizeDisp) / (float)fRows;
|
float sizeRow = (keypadRect.Height() + 1) / (float)fRows;
|
||||||
|
|
||||||
if (updateRect.Intersects(keypadRect)) {
|
if (!updateRect.Intersects(keypadRect))
|
||||||
// TODO: support pressed keys
|
return;
|
||||||
|
|
||||||
// paint keypad b/g
|
SetFontSize(min_c(sizeRow * kFontScaleY, sizeCol * kFontScaleX));
|
||||||
SetHighColor(fBaseColor);
|
|
||||||
FillRect(updateRect & keypadRect);
|
|
||||||
|
|
||||||
// render key main grid
|
if (be_control_look != NULL) {
|
||||||
BeginLineArray(((fColums + fRows) << 1) + 1);
|
|
||||||
|
|
||||||
// render cols
|
|
||||||
AddLine(BPoint(0.0, sizeDisp),
|
|
||||||
BPoint(0.0, fHeight),
|
|
||||||
fLightColor);
|
|
||||||
for (int col = 1; col < fColums; col++) {
|
|
||||||
AddLine(BPoint(col * sizeCol - 1.0, sizeDisp),
|
|
||||||
BPoint(col * sizeCol - 1.0, fHeight),
|
|
||||||
fDarkColor);
|
|
||||||
AddLine(BPoint(col * sizeCol, sizeDisp),
|
|
||||||
BPoint(col * sizeCol, fHeight),
|
|
||||||
fLightColor);
|
|
||||||
}
|
|
||||||
AddLine(BPoint(fColums * sizeCol, sizeDisp),
|
|
||||||
BPoint(fColums * sizeCol, fHeight),
|
|
||||||
fDarkColor);
|
|
||||||
|
|
||||||
// render rows
|
|
||||||
for (int row = 0; row < fRows; row++) {
|
|
||||||
AddLine(BPoint(0.0, sizeDisp + row * sizeRow - 1.0),
|
|
||||||
BPoint(fWidth, sizeDisp + row * sizeRow - 1.0),
|
|
||||||
fDarkColor);
|
|
||||||
AddLine(BPoint(0.0, sizeDisp + row * sizeRow),
|
|
||||||
BPoint(fWidth, sizeDisp + row * sizeRow),
|
|
||||||
fLightColor);
|
|
||||||
}
|
|
||||||
AddLine(BPoint(0.0, sizeDisp + fRows * sizeRow),
|
|
||||||
BPoint(fWidth, sizeDisp + fRows * sizeRow),
|
|
||||||
fDarkColor);
|
|
||||||
|
|
||||||
// main grid complete
|
|
||||||
EndLineArray();
|
|
||||||
|
|
||||||
// render key symbols
|
|
||||||
float halfSizeCol = sizeCol * 0.5f;
|
|
||||||
SetHighColor(fButtonTextColor);
|
|
||||||
SetLowColor(fBaseColor);
|
|
||||||
SetDrawingMode(B_OP_COPY);
|
|
||||||
|
|
||||||
float fontSize =
|
|
||||||
min_c(((fHeight - sizeDisp) / (float)fRows) * K_FONT_YPROP,
|
|
||||||
(fWidth / (float)fColums) * K_FONT_XPROP);
|
|
||||||
|
|
||||||
SetFontSize(fontSize);
|
|
||||||
|
|
||||||
float baselineOffset = ((fHeight - sizeDisp) / (float)fRows)
|
|
||||||
* (1.0 - K_FONT_YPROP) * 0.5;
|
|
||||||
CalcKey *key = fKeypad;
|
CalcKey *key = fKeypad;
|
||||||
for (int row = 0; row < fRows; row++) {
|
for (int row = 0; row < fRows; row++) {
|
||||||
for (int col = 0; col < fColums; col++) {
|
for (int col = 0; col < fColums; col++) {
|
||||||
float halfSymbolWidth = StringWidth(key->label) * 0.5f;
|
BRect frame;
|
||||||
DrawString(key->label,
|
frame.left = keypadRect.left + col * sizeCol;
|
||||||
BPoint(col * sizeCol + halfSizeCol - halfSymbolWidth,
|
frame.right = keypadRect.left + (col + 1) * sizeCol - 1;
|
||||||
sizeDisp + (row + 1) * sizeRow - baselineOffset));
|
frame.top = sizeDisp + row * sizeRow;
|
||||||
|
frame.bottom = sizeDisp + (row + 1) * sizeRow - 1;
|
||||||
|
|
||||||
|
if (drawBackground) {
|
||||||
|
SetHighColor(fBaseColor);
|
||||||
|
StrokeRect(frame);
|
||||||
|
}
|
||||||
|
frame.InsetBy(1, 1);
|
||||||
|
|
||||||
|
uint32 flags = 0;
|
||||||
|
if (!drawBackground)
|
||||||
|
flags |= BControlLook::B_BLEND_FRAME;
|
||||||
|
if (key->flags != 0)
|
||||||
|
flags |= BControlLook::B_ACTIVATED;
|
||||||
|
|
||||||
|
be_control_look->DrawButtonFrame(this, frame, updateRect,
|
||||||
|
fBaseColor, fBaseColor, flags);
|
||||||
|
|
||||||
|
be_control_look->DrawButtonBackground(this, frame, updateRect,
|
||||||
|
fBaseColor, flags);
|
||||||
|
|
||||||
|
be_control_look->DrawLabel(this, key->label, frame, updateRect,
|
||||||
|
fBaseColor, flags, BAlignment(B_ALIGN_HORIZONTAL_CENTER,
|
||||||
|
B_ALIGN_VERTICAL_CENTER));
|
||||||
|
|
||||||
key++;
|
key++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: support pressed keys
|
||||||
|
|
||||||
|
// paint keypad b/g
|
||||||
|
SetHighColor(fBaseColor);
|
||||||
|
FillRect(updateRect & keypadRect);
|
||||||
|
|
||||||
|
// render key main grid
|
||||||
|
BeginLineArray(((fColums + fRows) << 1) + 1);
|
||||||
|
|
||||||
|
// render cols
|
||||||
|
AddLine(BPoint(0.0, sizeDisp),
|
||||||
|
BPoint(0.0, fHeight),
|
||||||
|
fLightColor);
|
||||||
|
for (int col = 1; col < fColums; col++) {
|
||||||
|
AddLine(BPoint(col * sizeCol - 1.0, sizeDisp),
|
||||||
|
BPoint(col * sizeCol - 1.0, fHeight),
|
||||||
|
fDarkColor);
|
||||||
|
AddLine(BPoint(col * sizeCol, sizeDisp),
|
||||||
|
BPoint(col * sizeCol, fHeight),
|
||||||
|
fLightColor);
|
||||||
|
}
|
||||||
|
AddLine(BPoint(fColums * sizeCol, sizeDisp),
|
||||||
|
BPoint(fColums * sizeCol, fHeight),
|
||||||
|
fDarkColor);
|
||||||
|
|
||||||
|
// render rows
|
||||||
|
for (int row = 0; row < fRows; row++) {
|
||||||
|
AddLine(BPoint(0.0, sizeDisp + row * sizeRow - 1.0),
|
||||||
|
BPoint(fWidth, sizeDisp + row * sizeRow - 1.0),
|
||||||
|
fDarkColor);
|
||||||
|
AddLine(BPoint(0.0, sizeDisp + row * sizeRow),
|
||||||
|
BPoint(fWidth, sizeDisp + row * sizeRow),
|
||||||
|
fLightColor);
|
||||||
|
}
|
||||||
|
AddLine(BPoint(0.0, sizeDisp + fRows * sizeRow),
|
||||||
|
BPoint(fWidth, sizeDisp + fRows * sizeRow),
|
||||||
|
fDarkColor);
|
||||||
|
|
||||||
|
// main grid complete
|
||||||
|
EndLineArray();
|
||||||
|
|
||||||
|
// render key symbols
|
||||||
|
float halfSizeCol = sizeCol * 0.5f;
|
||||||
|
SetHighColor(fButtonTextColor);
|
||||||
|
SetLowColor(fBaseColor);
|
||||||
|
SetDrawingMode(B_OP_COPY);
|
||||||
|
|
||||||
|
float baselineOffset = ((fHeight - sizeDisp) / (float)fRows)
|
||||||
|
* (1.0 - kFontScaleY) * 0.5;
|
||||||
|
CalcKey *key = fKeypad;
|
||||||
|
for (int row = 0; row < fRows; row++) {
|
||||||
|
for (int col = 0; col < fColums; col++) {
|
||||||
|
float halfSymbolWidth = StringWidth(key->label) * 0.5f;
|
||||||
|
DrawString(key->label,
|
||||||
|
BPoint(col * sizeCol + halfSizeCol - halfSymbolWidth,
|
||||||
|
sizeDisp + (row + 1) * sizeRow - baselineOffset));
|
||||||
|
key++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,11 +514,20 @@ CalcView::MouseDown(BPoint point)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fShowKeypad)
|
if (!fShowKeypad) {
|
||||||
|
if (fCalcIcon != NULL) {
|
||||||
|
BRect bounds(Bounds());
|
||||||
|
bounds.left = bounds.right - fCalcIcon->Bounds().Width();
|
||||||
|
if (bounds.Contains(point)) {
|
||||||
|
// user clicked on calculator icon
|
||||||
|
fExpressionTextView->ApplyChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// calculate grid sizes
|
// calculate grid sizes
|
||||||
float sizeDisp = fHeight * K_DISPLAY_YPROP;
|
float sizeDisp = fHeight * kDisplayScaleY;
|
||||||
float sizeCol = fWidth / (float)fColums;
|
float sizeCol = fWidth / (float)fColums;
|
||||||
float sizeRow = (fHeight - sizeDisp) / (float)fRows;
|
float sizeRow = (fHeight - sizeDisp) / (float)fRows;
|
||||||
|
|
||||||
@@ -438,7 +540,25 @@ CalcView::MouseDown(BPoint point)
|
|||||||
(gridRow >= 0) && (gridRow < fRows)) {
|
(gridRow >= 0) && (gridRow < fRows)) {
|
||||||
|
|
||||||
// process key press
|
// process key press
|
||||||
_PressKey(gridRow * fColums + gridCol);
|
int key = gridRow * fColums + gridCol;
|
||||||
|
_FlashKey(key, FLAGS_MOUSE_DOWN);
|
||||||
|
_PressKey(key);
|
||||||
|
|
||||||
|
// make sure we receive the mouse up!
|
||||||
|
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CalcView::MouseUp(BPoint point)
|
||||||
|
{
|
||||||
|
int keys = fRows * fColums;
|
||||||
|
for (int i = 0; i < keys; i++) {
|
||||||
|
if (fKeypad[i].flags & FLAGS_MOUSE_DOWN) {
|
||||||
|
_FlashKey(i, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,7 +642,10 @@ CalcView::FrameResized(float width, float height)
|
|||||||
|
|
||||||
// layout expression text view
|
// layout expression text view
|
||||||
BRect frame = _ExpressionRect();
|
BRect frame = _ExpressionRect();
|
||||||
frame.InsetBy(2, 2);
|
if (fShowKeypad)
|
||||||
|
frame.InsetBy(4, 4);
|
||||||
|
else
|
||||||
|
frame.InsetBy(2, 2);
|
||||||
|
|
||||||
if (!fShowKeypad)
|
if (!fShowKeypad)
|
||||||
frame.right -= ceilf(fCalcIcon->Bounds().Width() * 1.5);
|
frame.right -= ceilf(fCalcIcon->Bounds().Width() * 1.5);
|
||||||
@@ -531,17 +654,15 @@ CalcView::FrameResized(float width, float height)
|
|||||||
fExpressionTextView->ResizeTo(frame.Width(), frame.Height());
|
fExpressionTextView->ResizeTo(frame.Width(), frame.Height());
|
||||||
|
|
||||||
frame.OffsetTo(B_ORIGIN);
|
frame.OffsetTo(B_ORIGIN);
|
||||||
frame.InsetBy(2, 2);
|
float inset = (frame.Height() - fExpressionTextView->LineHeight(0)) / 2;
|
||||||
|
frame.InsetBy(inset, inset);
|
||||||
fExpressionTextView->SetTextRect(frame);
|
fExpressionTextView->SetTextRect(frame);
|
||||||
|
|
||||||
// configure expression text view font size and color
|
// configure expression text view font size and color
|
||||||
float sizeDisp = fShowKeypad ? fHeight * K_DISPLAY_YPROP : fHeight;
|
float sizeDisp = fShowKeypad ? fHeight * kDisplayScaleY : fHeight;
|
||||||
BFont font(be_bold_font);
|
BFont font(be_bold_font);
|
||||||
font.SetSize(sizeDisp * K_FONT_YPROP);
|
font.SetSize(sizeDisp * kExpressionFontScaleY);
|
||||||
// fExpressionTextView->SetViewColor(fExpressionBGColor);
|
fExpressionTextView->SetFontAndColor(&font, B_FONT_ALL);
|
||||||
// fExpressionTextView->SetLowColor(fExpressionBGColor);
|
|
||||||
// fExpressionTextView->SetFontAndColor(&font, B_FONT_ALL, &fExpressionTextColor);
|
|
||||||
fExpressionTextView->SetFontAndColor(&font, B_FONT_ALL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -630,7 +751,7 @@ CalcView::Paste(BMessage *message)
|
|||||||
BPoint dropPoint = ConvertFromScreen(message->DropPoint());
|
BPoint dropPoint = ConvertFromScreen(message->DropPoint());
|
||||||
|
|
||||||
// calculate current keypad area
|
// calculate current keypad area
|
||||||
float sizeDisp = fHeight * K_DISPLAY_YPROP;
|
float sizeDisp = fHeight * kDisplayScaleY;
|
||||||
BRect keypadRect(0.0, sizeDisp, fWidth, fHeight);
|
BRect keypadRect(0.0, sizeDisp, fWidth, fHeight);
|
||||||
|
|
||||||
// check location of color drop
|
// check location of color drop
|
||||||
@@ -773,13 +894,7 @@ CalcView::Evaluate()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// audio feedback
|
_AudioFeedback(false);
|
||||||
if (fOptions->audio_feedback) {
|
|
||||||
BEntry zimp("zimp.AIFF");
|
|
||||||
entry_ref zimp_ref;
|
|
||||||
zimp.GetRef(&zimp_ref);
|
|
||||||
play_sound(&zimp_ref, true, false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// evaluate expression
|
// evaluate expression
|
||||||
BString value;
|
BString value;
|
||||||
@@ -806,7 +921,7 @@ CalcView::FlashKey(const char* bytes, int32 numBytes)
|
|||||||
temp.Append(bytes, numBytes);
|
temp.Append(bytes, numBytes);
|
||||||
int32 key = _KeyForLabel(temp.String());
|
int32 key = _KeyForLabel(temp.String());
|
||||||
if (key >= 0)
|
if (key >= 0)
|
||||||
_FlashKey(key);
|
_FlashKey(key, FLAGS_FLASH_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -837,11 +952,12 @@ CalcView::_ParseCalcDesc(const char* keypadDescription)
|
|||||||
strcpy(key->code, key->label);
|
strcpy(key->code, key->label);
|
||||||
|
|
||||||
// set keymap
|
// set keymap
|
||||||
if (strlen(key->label) == 1) {
|
if (strlen(key->label) == 1)
|
||||||
strcpy(key->keymap, key->label);
|
strcpy(key->keymap, key->label);
|
||||||
} else {
|
else
|
||||||
*key->keymap = '\0';
|
*key->keymap = '\0';
|
||||||
} // end if
|
|
||||||
|
key->flags = 0;
|
||||||
|
|
||||||
// add this to the expression text view, so that it
|
// add this to the expression text view, so that it
|
||||||
// will forward the respective KeyDown event to us
|
// will forward the respective KeyDown event to us
|
||||||
@@ -870,23 +986,14 @@ CalcView::_PressKey(int key)
|
|||||||
} else {
|
} else {
|
||||||
// check for evaluation order
|
// check for evaluation order
|
||||||
if (fKeypad[key].code[0] == '\n') {
|
if (fKeypad[key].code[0] == '\n') {
|
||||||
Evaluate();
|
fExpressionTextView->ApplyChanges();
|
||||||
} else {
|
} else {
|
||||||
// insert into expression text
|
// insert into expression text
|
||||||
fExpressionTextView->Insert(fKeypad[key].code);
|
fExpressionTextView->Insert(fKeypad[key].code);
|
||||||
|
|
||||||
// audio feedback
|
|
||||||
if (fOptions->audio_feedback) {
|
|
||||||
BEntry zimp("key.AIFF");
|
|
||||||
entry_ref zimp_ref;
|
|
||||||
zimp.GetRef(&zimp_ref);
|
|
||||||
play_sound(&zimp_ref, true, false, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// redraw display
|
_AudioFeedback(true);
|
||||||
// _InvalidateExpression();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -913,9 +1020,36 @@ CalcView::_KeyForLabel(const char *label) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CalcView::_FlashKey(int32 key)
|
CalcView::_FlashKey(int32 key, uint32 flashFlags)
|
||||||
{
|
{
|
||||||
// TODO ...
|
if (flashFlags != 0)
|
||||||
|
fKeypad[key].flags |= flashFlags;
|
||||||
|
else
|
||||||
|
fKeypad[key].flags = 0;
|
||||||
|
Invalidate();
|
||||||
|
|
||||||
|
if (fKeypad[key].flags == FLAGS_FLASH_KEY) {
|
||||||
|
BMessage message(MSG_UNFLASH_KEY);
|
||||||
|
message.AddInt32("key", key);
|
||||||
|
BMessageRunner::StartSending(BMessenger(this), &message,
|
||||||
|
kFlashOnOffInterval, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CalcView::_AudioFeedback(bool inBackGround)
|
||||||
|
{
|
||||||
|
// TODO: Use beep events... This interface is not implemented on Haiku
|
||||||
|
// anyways...
|
||||||
|
#if 0
|
||||||
|
if (fOptions->audio_feedback) {
|
||||||
|
BEntry zimp("key.AIFF");
|
||||||
|
entry_ref zimp_ref;
|
||||||
|
zimp.GetRef(&zimp_ref);
|
||||||
|
play_sound(&zimp_ref, true, false, inBackGround);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -955,11 +1089,11 @@ CalcView::_CreatePopUpMenu()
|
|||||||
{
|
{
|
||||||
// construct items
|
// construct items
|
||||||
fAutoNumlockItem = new BMenuItem("Enable Num Lock on start up",
|
fAutoNumlockItem = new BMenuItem("Enable Num Lock on start up",
|
||||||
new BMessage(K_OPTIONS_AUTO_NUM_LOCK));
|
new BMessage(MSG_OPTIONS_AUTO_NUM_LOCK));
|
||||||
fAudioFeedbackItem = new BMenuItem("Audio Feedback",
|
fAudioFeedbackItem = new BMenuItem("Audio Feedback",
|
||||||
new BMessage(K_OPTIONS_AUDIO_FEEDBACK));
|
new BMessage(MSG_OPTIONS_AUDIO_FEEDBACK));
|
||||||
fShowKeypadItem = new BMenuItem("Show Keypad",
|
fShowKeypadItem = new BMenuItem("Show Keypad",
|
||||||
new BMessage(K_OPTIONS_SHOW_KEYPAD));
|
new BMessage(MSG_OPTIONS_SHOW_KEYPAD));
|
||||||
fAboutItem = new BMenuItem("About DeskCalc",
|
fAboutItem = new BMenuItem("About DeskCalc",
|
||||||
new BMessage(B_ABOUT_REQUESTED));
|
new BMessage(B_ABOUT_REQUESTED));
|
||||||
|
|
||||||
@@ -972,7 +1106,9 @@ CalcView::_CreatePopUpMenu()
|
|||||||
fPopUpMenu = new BPopUpMenu("pop-up", false, false);
|
fPopUpMenu = new BPopUpMenu("pop-up", false, false);
|
||||||
|
|
||||||
fPopUpMenu->AddItem(fAutoNumlockItem);
|
fPopUpMenu->AddItem(fAutoNumlockItem);
|
||||||
fPopUpMenu->AddItem(fAudioFeedbackItem);
|
// TODO: Enabled when we use beep events which can be configured in the Sounds
|
||||||
|
// preflet.
|
||||||
|
// fPopUpMenu->AddItem(fAudioFeedbackItem);
|
||||||
fPopUpMenu->AddItem(fShowKeypadItem);
|
fPopUpMenu->AddItem(fShowKeypadItem);
|
||||||
fPopUpMenu->AddSeparatorItem();
|
fPopUpMenu->AddSeparatorItem();
|
||||||
fPopUpMenu->AddItem(fAboutItem);
|
fPopUpMenu->AddItem(fAboutItem);
|
||||||
@@ -984,7 +1120,7 @@ CalcView::_ExpressionRect() const
|
|||||||
{
|
{
|
||||||
BRect r(0.0, 0.0, fWidth, fHeight);
|
BRect r(0.0, 0.0, fWidth, fHeight);
|
||||||
if (fShowKeypad) {
|
if (fShowKeypad) {
|
||||||
r.bottom = floorf(fHeight * K_DISPLAY_YPROP);
|
r.bottom = floorf(fHeight * kDisplayScaleY) + 1;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -997,7 +1133,7 @@ CalcView::_KeypadRect() const
|
|||||||
if (fShowKeypad) {
|
if (fShowKeypad) {
|
||||||
r.right = fWidth;
|
r.right = fWidth;
|
||||||
r.bottom = fHeight;
|
r.bottom = fHeight;
|
||||||
r.top = floorf(fHeight * K_DISPLAY_YPROP) + 1;
|
r.top = floorf(fHeight * kDisplayScaleY);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -1011,16 +1147,17 @@ CalcView::_ShowKeypad(bool show)
|
|||||||
|
|
||||||
fShowKeypad = show;
|
fShowKeypad = show;
|
||||||
if (fShowKeypadItem && fShowKeypadItem->IsMarked() ^ fShowKeypad)
|
if (fShowKeypadItem && fShowKeypadItem->IsMarked() ^ fShowKeypad)
|
||||||
fShowKeypadItem->SetMarked(fShowKeypad);
|
fShowKeypadItem->SetMarked(fShowKeypad);
|
||||||
|
|
||||||
float height = fShowKeypad ? fHeight / K_DISPLAY_YPROP
|
float height = fShowKeypad ? fHeight / kDisplayScaleY
|
||||||
: fHeight * K_DISPLAY_YPROP;
|
: fHeight * kDisplayScaleY;
|
||||||
|
|
||||||
BWindow* window = Window();
|
BWindow* window = Window();
|
||||||
if (window) {
|
if (window) {
|
||||||
if (window->Bounds() == Frame()) {
|
if (window->Bounds() == Frame()) {
|
||||||
|
window->SetSizeLimits(100.0, 400.0,
|
||||||
|
fShowKeypad ? 100.0 : 20.0, fShowKeypad ? 400.0 : 60.0);
|
||||||
window->ResizeTo(fWidth, height);
|
window->ResizeTo(fWidth, height);
|
||||||
window->SetSizeLimits(100.0, 400.0, fShowKeypad ? 100.0 : 20.0, 400.0);
|
|
||||||
} else
|
} else
|
||||||
ResizeTo(fWidth, height);
|
ResizeTo(fWidth, height);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class CalcView : public BView {
|
|||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
virtual void MouseDown(BPoint point);
|
virtual void MouseDown(BPoint point);
|
||||||
|
virtual void MouseUp(BPoint point);
|
||||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||||
virtual void MakeFocus(bool focused = true);
|
virtual void MakeFocus(bool focused = true);
|
||||||
virtual void FrameResized(float width, float height);
|
virtual void FrameResized(float width, float height);
|
||||||
@@ -65,17 +66,14 @@ class CalcView : public BView {
|
|||||||
|
|
||||||
void FlashKey(const char* bytes, int32 numBytes);
|
void FlashKey(const char* bytes, int32 numBytes);
|
||||||
|
|
||||||
void AddExpressionToHistory(const char* expression);
|
|
||||||
void PreviousExpression();
|
|
||||||
void NextExpression();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _ParseCalcDesc(const char* keypadDescription);
|
void _ParseCalcDesc(const char* keypadDescription);
|
||||||
|
|
||||||
void _PressKey(int key);
|
void _PressKey(int key);
|
||||||
void _PressKey(const char* label);
|
void _PressKey(const char* label);
|
||||||
int32 _KeyForLabel(const char* label) const;
|
int32 _KeyForLabel(const char* label) const;
|
||||||
void _FlashKey(int32 key);
|
void _FlashKey(int32 key, uint32 flashFlags);
|
||||||
|
void _AudioFeedback(bool inBackGround);
|
||||||
|
|
||||||
void _Colorize();
|
void _Colorize();
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
/*
|
|
||||||
** /boot/home/projects/develop/ThirdParty/Haiku/src/apps/deskcalc/DeskCalc.h
|
|
||||||
**
|
|
||||||
** Automatically generated by BResourceParser on
|
|
||||||
** Tuesday, June 06, 2006 at 17:38:14.
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
@@ -22,14 +22,15 @@ static const int32 kMaxPreviousExpressions = 20;
|
|||||||
|
|
||||||
|
|
||||||
ExpressionTextView::ExpressionTextView(BRect frame, CalcView* calcView)
|
ExpressionTextView::ExpressionTextView(BRect frame, CalcView* calcView)
|
||||||
: InputTextView(frame, "expression text view",
|
:
|
||||||
(frame.OffsetToCopy(B_ORIGIN)).InsetByCopy(2, 2),
|
InputTextView(frame, "expression text view",
|
||||||
B_FOLLOW_NONE, B_WILL_DRAW),
|
(frame.OffsetToCopy(B_ORIGIN)).InsetByCopy(2, 2),
|
||||||
fCalcView(calcView),
|
B_FOLLOW_NONE, B_WILL_DRAW),
|
||||||
fKeypadLabels(""),
|
fCalcView(calcView),
|
||||||
fPreviousExpressions(20),
|
fKeypadLabels(""),
|
||||||
fHistoryPos(0),
|
fPreviousExpressions(20),
|
||||||
fCurrentExpression("")
|
fHistoryPos(0),
|
||||||
|
fCurrentExpression("")
|
||||||
{
|
{
|
||||||
SetStylable(false);
|
SetStylable(false);
|
||||||
SetDoesUndo(true);
|
SetDoesUndo(true);
|
||||||
@@ -75,12 +76,16 @@ ExpressionTextView::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
BString current = Text();
|
BString current = Text();
|
||||||
|
|
||||||
// handle in InputTextView, except B_TAB
|
// handle in InputTextView, except B_TAB
|
||||||
if (bytes[0] != B_TAB)
|
if (bytes[0] == '=')
|
||||||
|
ApplyChanges();
|
||||||
|
else if (bytes[0] != B_TAB)
|
||||||
InputTextView::KeyDown(bytes, numBytes);
|
InputTextView::KeyDown(bytes, numBytes);
|
||||||
|
|
||||||
// pass on to CalcView if this was a label on a key
|
// pass on to CalcView if this was a label on a key
|
||||||
if (fKeypadLabels.FindFirst(bytes[0]) >= 0)
|
if (fKeypadLabels.FindFirst(bytes[0]) >= 0)
|
||||||
fCalcView->FlashKey(bytes, numBytes);
|
fCalcView->FlashKey(bytes, numBytes);
|
||||||
|
else if (bytes[0] == B_BACKSPACE)
|
||||||
|
fCalcView->FlashKey("BS", 2);
|
||||||
|
|
||||||
// as soon as something is typed, we are at the
|
// as soon as something is typed, we are at the
|
||||||
// end of the expression history
|
// end of the expression history
|
||||||
@@ -126,6 +131,7 @@ void
|
|||||||
ExpressionTextView::ApplyChanges()
|
ExpressionTextView::ApplyChanges()
|
||||||
{
|
{
|
||||||
AddExpressionToHistory(Text());
|
AddExpressionToHistory(Text());
|
||||||
|
fCalcView->FlashKey("=", 1);
|
||||||
fCalcView->Evaluate();
|
fCalcView->Evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +160,8 @@ ExpressionTextView::BackSpace()
|
|||||||
{
|
{
|
||||||
const char bytes[1] = { B_BACKSPACE };
|
const char bytes[1] = { B_BACKSPACE };
|
||||||
KeyDown(bytes, 1);
|
KeyDown(bytes, 1);
|
||||||
|
|
||||||
|
fCalcView->FlashKey("BS", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -161,6 +169,8 @@ void
|
|||||||
ExpressionTextView::Clear()
|
ExpressionTextView::Clear()
|
||||||
{
|
{
|
||||||
SetText("");
|
SetText("");
|
||||||
|
|
||||||
|
fCalcView->FlashKey("C", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -267,4 +277,3 @@ ExpressionTextView::SaveSettings(BMessage* archive) const
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user