* Style fixes. Encountered ambiguous cases, please see my following questions

in the commit ml.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33923 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexandre Deckner
2009-11-06 17:32:07 +00:00
parent f7ace4e827
commit accec9a7ae
11 changed files with 93 additions and 94 deletions
+10 -7
View File
@@ -30,8 +30,9 @@ static const float kDefaultWindowHeight = 140.0;
CalcApplication::CalcApplication() CalcApplication::CalcApplication()
: BApplication(kAppSig), :
fCalcWindow(NULL) BApplication(kAppSig),
fCalcWindow(NULL)
{ {
} }
@@ -77,7 +78,7 @@ CalcApplication::QuitRequested()
void void
CalcApplication::_LoadSettings(BMessage &archive) CalcApplication::_LoadSettings(BMessage& archive)
{ {
// locate preferences file // locate preferences file
BFile prefsFile; BFile prefsFile;
@@ -128,10 +129,11 @@ CalcApplication::_SaveSettings()
} }
} }
status_t status_t
CalcApplication::_InitSettingsFile(BFile* file, bool write) CalcApplication::_InitSettingsFile(BFile* file, bool write)
{ {
// find user settings directory // find user settings directory
BPath prefsPath; BPath prefsPath;
status_t ret = find_directory(B_USER_SETTINGS_DIRECTORY, &prefsPath); status_t ret = find_directory(B_USER_SETTINGS_DIRECTORY, &prefsPath);
if (ret < B_OK) if (ret < B_OK)
@@ -141,9 +143,10 @@ CalcApplication::_InitSettingsFile(BFile* file, bool write)
if (ret < B_OK) if (ret < B_OK)
return ret; return ret;
if (write) if (write) {
ret = file->SetTo(prefsPath.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); ret = file->SetTo(prefsPath.Path(),
else B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
} else
ret = file->SetTo(prefsPath.Path(), B_READ_ONLY); ret = file->SetTo(prefsPath.Path(), B_READ_ONLY);
return ret; return ret;
+1 -1
View File
@@ -28,7 +28,7 @@ class CalcApplication : public BApplication {
virtual bool QuitRequested(); virtual bool QuitRequested();
private: private:
void _LoadSettings(BMessage &settings); void _LoadSettings(BMessage& settings);
void _SaveSettings(); void _SaveSettings();
status_t _InitSettingsFile(BFile* file, bool write); status_t _InitSettingsFile(BFile* file, bool write);
+4 -3
View File
@@ -17,9 +17,10 @@
CalcOptions::CalcOptions() CalcOptions::CalcOptions()
: auto_num_lock(false), :
audio_feedback(false), auto_num_lock(false),
show_keypad(true) audio_feedback(false),
show_keypad(true)
{ {
} }
+34 -39
View File
@@ -80,7 +80,8 @@ struct CalcView::CalcKey {
}; };
CalcView *CalcView::Instantiate(BMessage *archive) CalcView*
CalcView::Instantiate(BMessage* archive)
{ {
if (!validate_instantiation(archive, "CalcView")) if (!validate_instantiation(archive, "CalcView"))
return NULL; return NULL;
@@ -89,7 +90,7 @@ 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, BView(frame, "DeskCalc", B_FOLLOW_ALL_SIDES,
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
@@ -241,7 +242,7 @@ CalcView::MessageReceived(BMessage* message)
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();
@@ -400,7 +401,7 @@ CalcView::Draw(BRect updateRect)
SetFontSize(min_c(sizeRow * kFontScaleY, sizeCol * kFontScaleX)); SetFontSize(min_c(sizeRow * kFontScaleY, sizeCol * kFontScaleX));
if (be_control_look != NULL) { if (be_control_look != NULL) {
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++) {
BRect frame; BRect frame;
@@ -486,7 +487,7 @@ CalcView::Draw(BRect updateRect)
float baselineOffset = ((fHeight - sizeDisp) / (float)fRows) float baselineOffset = ((fHeight - sizeDisp) / (float)fRows)
* (1.0 - kFontScaleY) * 0.5; * (1.0 - kFontScaleY) * 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; float halfSymbolWidth = StringWidth(key->label) * 0.5f;
@@ -545,8 +546,8 @@ CalcView::MouseDown(BPoint point)
int gridRow = (int)floorf((point.y - sizeDisp) / sizeRow); int gridRow = (int)floorf((point.y - sizeDisp) / sizeRow);
// check limits // check limits
if ((gridCol >= 0) && (gridCol < fColums) && if ((gridCol >= 0) && (gridCol < fColums)
(gridRow >= 0) && (gridRow < fRows)) { && (gridRow >= 0) && (gridRow < fRows)) {
// process key press // process key press
int key = gridRow * fColums + gridCol; int key = gridRow * fColums + gridCol;
@@ -576,7 +577,7 @@ CalcView::MouseUp(BPoint point)
void void
CalcView::KeyDown(const char *bytes, int32 numBytes) CalcView::KeyDown(const char* bytes, int32 numBytes)
{ {
// if single byte character... // if single byte character...
if (numBytes == 1) { if (numBytes == 1) {
@@ -702,8 +703,8 @@ CalcView::Archive(BMessage* archive, bool deep) const
const_cast<CalcView*>(this)->AddChild(fExpressionTextView); const_cast<CalcView*>(this)->AddChild(fExpressionTextView);
// save app signature for replicant add-on loading // save app signature for replicant add-on loading
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddString("add_on", kAppSig); ret = archive->AddString("add_on", kAppSig);
// save all the options // save all the options
if (ret == B_OK) if (ret == B_OK)
@@ -731,14 +732,12 @@ CalcView::Copy()
// access system clipboard // access system clipboard
if (be_clipboard->Lock()) { if (be_clipboard->Lock()) {
be_clipboard->Clear(); be_clipboard->Clear();
BMessage *clipper = be_clipboard->Data(); BMessage* clipper = be_clipboard->Data();
clipper->what = B_MIME_DATA; clipper->what = B_MIME_DATA;
// TODO: should check return for errors! // TODO: should check return for errors!
BString expression = fExpressionTextView->Text(); BString expression = fExpressionTextView->Text();
clipper->AddData("text/plain", clipper->AddData("text/plain", B_MIME_TYPE,
B_MIME_TYPE, expression.String(), expression.Length());
expression.String(),
expression.Length());
//clipper->PrintToStream(); //clipper->PrintToStream();
be_clipboard->Commit(); be_clipboard->Commit();
be_clipboard->Unlock(); be_clipboard->Unlock();
@@ -747,16 +746,14 @@ CalcView::Copy()
void void
CalcView::Paste(BMessage *message) CalcView::Paste(BMessage* message)
{ {
// handle color drops first // handle color drops first
// read incoming color // read incoming color
const rgb_color* dropColor = NULL; const rgb_color* dropColor = NULL;
ssize_t dataSize; ssize_t dataSize;
if (message->FindData("RGBColor", if (message->FindData("RGBColor", B_RGB_COLOR_TYPE,
B_RGB_COLOR_TYPE, (const void**)&dropColor, &dataSize) == B_OK
(const void**)&dropColor,
&dataSize) == B_OK
&& dataSize == sizeof(rgb_color)) { && dataSize == sizeof(rgb_color)) {
// calculate view relative drop point // calculate view relative drop point
@@ -778,10 +775,8 @@ CalcView::Paste(BMessage *message)
// look for text/plain MIME data // look for text/plain MIME data
const char* text; const char* text;
ssize_t numBytes; ssize_t numBytes;
if (message->FindData("text/plain", if (message->FindData("text/plain", B_MIME_TYPE,
B_MIME_TYPE, (const void**)&text, &numBytes) == B_OK) {
(const void**)&text,
&numBytes) == B_OK) {
BString temp; BString temp;
temp.Append(text, numBytes); temp.Append(text, numBytes);
fExpressionTextView->Insert(temp.String()); fExpressionTextView->Insert(temp.String());
@@ -815,8 +810,8 @@ CalcView::_LoadSettings(BMessage* archive)
const rgb_color* color; const rgb_color* color;
ssize_t size; ssize_t size;
if (archive->FindData("rgbBaseColor", B_RGB_COLOR_TYPE, if (archive->FindData("rgbBaseColor", B_RGB_COLOR_TYPE,
(const void**)&color, &size) < B_OK (const void**)&color, &size) < B_OK
|| size != sizeof(rgb_color)) { || size != sizeof(rgb_color)) {
fBaseColor = (rgb_color){ 128, 128, 128, 255 }; fBaseColor = (rgb_color){ 128, 128, 128, 255 };
puts("Missing rgbBaseColor from CalcView archive!\n"); puts("Missing rgbBaseColor from CalcView archive!\n");
} else { } else {
@@ -824,8 +819,8 @@ CalcView::_LoadSettings(BMessage* archive)
} }
if (archive->FindData("rgbDisplay", B_RGB_COLOR_TYPE, if (archive->FindData("rgbDisplay", B_RGB_COLOR_TYPE,
(const void**)&color, &size) < B_OK (const void**)&color, &size) < B_OK
|| size != sizeof(rgb_color)) { || size != sizeof(rgb_color)) {
fExpressionBGColor = (rgb_color){ 0, 0, 0, 255 }; fExpressionBGColor = (rgb_color){ 0, 0, 0, 255 };
puts("Missing rgbBaseColor from CalcView archive!\n"); puts("Missing rgbBaseColor from CalcView archive!\n");
} else { } else {
@@ -871,10 +866,10 @@ CalcView::SaveSettings(BMessage* archive) const
// record color scheme // record color scheme
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddData("rgbBaseColor", B_RGB_COLOR_TYPE, ret = archive->AddData("rgbBaseColor", B_RGB_COLOR_TYPE,
&fBaseColor, sizeof(rgb_color)); &fBaseColor, sizeof(rgb_color));
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddData("rgbDisplay", B_RGB_COLOR_TYPE, ret = archive->AddData("rgbDisplay", B_RGB_COLOR_TYPE,
&fExpressionBGColor, sizeof(rgb_color)); &fExpressionBGColor, sizeof(rgb_color));
// record current options // record current options
if (ret == B_OK) if (ret == B_OK)
@@ -947,12 +942,12 @@ CalcView::_ParseCalcDesc(const char* keypadDescription)
fKeypad = new CalcKey[fRows * fColums]; fKeypad = new CalcKey[fRows * fColums];
// scan through calculator description and assemble keypad // scan through calculator description and assemble keypad
CalcKey *key = fKeypad; CalcKey* key = fKeypad;
const char *p = keypadDescription; const char* p = keypadDescription;
while (*p != 0) { while (*p != 0) {
// copy label // copy label
char *l = key->label; char* l = key->label;
while (!isspace(*p)) while (!isspace(*p))
*l++ = *p++; *l++ = *p++;
*l = '\0'; *l = '\0';
@@ -1010,7 +1005,7 @@ CalcView::_PressKey(int key)
void void
CalcView::_PressKey(const char *label) CalcView::_PressKey(const char* label)
{ {
int32 key = _KeyForLabel(label); int32 key = _KeyForLabel(label);
if (key >= 0) if (key >= 0)
@@ -1019,7 +1014,7 @@ CalcView::_PressKey(const char *label)
int32 int32
CalcView::_KeyForLabel(const char *label) const CalcView::_KeyForLabel(const char* label) const
{ {
int keys = fRows * fColums; int keys = fRows * fColums;
for (int i = 0; i < keys; i++) { for (int i = 0; i < keys; i++) {
@@ -1090,8 +1085,8 @@ CalcView::_Colorize()
fButtonTextColor = (rgb_color){ 255, 255, 255, 255 }; fButtonTextColor = (rgb_color){ 255, 255, 255, 255 };
// expression text color // expression text color
lightness = (fExpressionBGColor.red + lightness = (fExpressionBGColor.red
fExpressionBGColor.green + fExpressionBGColor.blue) / 3; + fExpressionBGColor.green + fExpressionBGColor.blue) / 3;
if (lightness > 200) if (lightness > 200)
fExpressionTextColor = (rgb_color){ 0, 0, 0, 255 }; fExpressionTextColor = (rgb_color){ 0, 0, 0, 255 };
else else
@@ -1164,8 +1159,8 @@ CalcView::_ShowKeypad(bool show)
if (fShowKeypadItem && fShowKeypadItem->IsMarked() ^ fShowKeypad) if (fShowKeypadItem && fShowKeypadItem->IsMarked() ^ fShowKeypad)
fShowKeypadItem->SetMarked(fShowKeypad); fShowKeypadItem->SetMarked(fShowKeypad);
float height = fShowKeypad ? fHeight / kDisplayScaleY float height
: fHeight * kDisplayScaleY; = fShowKeypad ? fHeight / kDisplayScaleY : fHeight * kDisplayScaleY;
BWindow* window = Window(); BWindow* window = Window();
if (window) { if (window) {
+7 -7
View File
@@ -23,13 +23,13 @@ class ExpressionTextView;
_EXPORT _EXPORT
class CalcView : public BView { class CalcView : public BView {
public: public:
static CalcView* Instantiate(BMessage* archive); static CalcView* Instantiate(BMessage* archive);
CalcView(BRect frame, CalcView(BRect frame,
rgb_color rgbBaseColor, rgb_color rgbBaseColor,
BMessage *settings); BMessage* settings);
CalcView(BMessage* archive); CalcView(BMessage* archive);
@@ -57,7 +57,7 @@ class CalcView : public BView {
void Copy(); void Copy();
// Paste contents of system clipboard to view. // Paste contents of system clipboard to view.
void Paste(BMessage *message); void Paste(BMessage* message);
// Save current settings // Save current settings
status_t SaveSettings(BMessage* archive) const; status_t SaveSettings(BMessage* archive) const;
@@ -68,7 +68,7 @@ class CalcView : public BView {
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;
+3 -3
View File
@@ -24,7 +24,7 @@
static const char* kWindowTitle = "DeskCalc"; static const char* kWindowTitle = "DeskCalc";
CalcWindow::CalcWindow(BRect frame, BMessage *settings) CalcWindow::CalcWindow(BRect frame, BMessage* settings)
: BWindow(frame, kWindowTitle, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) : BWindow(frame, kWindowTitle, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
{ {
// create calculator view with calculator description and // create calculator view with calculator description and
@@ -36,14 +36,14 @@ CalcWindow::CalcWindow(BRect frame, BMessage *settings)
frame.OffsetTo(B_ORIGIN); frame.OffsetTo(B_ORIGIN);
fCalcView = new CalcView(frame, baseColor, settings); fCalcView = new CalcView(frame, baseColor, settings);
// create replicant dragger // create replicant dragger
BRect replicantFrame(frame); BRect replicantFrame(frame);
replicantFrame.top = replicantFrame.bottom - 7.0f; replicantFrame.top = replicantFrame.bottom - 7.0f;
replicantFrame.left = replicantFrame.right - 7.0f; replicantFrame.left = replicantFrame.right - 7.0f;
BDragger* dragger = new BDragger(replicantFrame, fCalcView, BDragger* dragger = new BDragger(replicantFrame, fCalcView,
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
// attach views // attach views
AddChild(fCalcView); AddChild(fCalcView);
fCalcView->AddChild(dragger); fCalcView->AddChild(dragger);
+2 -2
View File
@@ -18,7 +18,7 @@ class CalcView;
class CalcWindow : public BWindow { class CalcWindow : public BWindow {
public: public:
CalcWindow(BRect frame, BMessage *settings); CalcWindow(BRect frame, BMessage* settings);
virtual ~CalcWindow(); virtual ~CalcWindow();
virtual void Show(); virtual void Show();
@@ -27,7 +27,7 @@ class CalcWindow : public BWindow {
status_t SaveSettings(BMessage* archive) const; status_t SaveSettings(BMessage* archive) const;
void SetFrame(BRect frame, void SetFrame(BRect frame,
bool forceCenter = false); bool forceCenter = false);
private: private:
CalcView* fCalcView; CalcView* fCalcView;
+3 -3
View File
@@ -257,9 +257,9 @@ ExpressionTextView::LoadSettings(const BMessage* archive)
{ {
const char* oldExpression; const char* oldExpression;
for (int32 i = 0; for (int32 i = 0;
archive->FindString("previous expression", i, &oldExpression) == B_OK; archive->FindString("previous expression", i, &oldExpression) == B_OK;
i++) { i++) {
AddExpressionToHistory(oldExpression); AddExpressionToHistory(oldExpression);
} }
} }
+1 -1
View File
@@ -19,7 +19,7 @@ class CalcView;
class ExpressionTextView : public InputTextView { class ExpressionTextView : public InputTextView {
public: public:
ExpressionTextView(BRect frame, ExpressionTextView(BRect frame,
CalcView* calcView); CalcView* calcView);
virtual ~ExpressionTextView(); virtual ~ExpressionTextView();
// BView // BView
+19 -18
View File
@@ -13,23 +13,22 @@
#include <String.h> #include <String.h>
// constructor
InputTextView::InputTextView(BRect frame, const char* name, InputTextView::InputTextView(BRect frame, const char* name, BRect textRect,
BRect textRect, uint32 resizingMode, uint32 flags)
uint32 resizingMode, :
uint32 flags) BTextView(frame, name, textRect, resizingMode, flags),
: BTextView(frame, name, textRect, resizingMode, flags), fWasFocus(false)
fWasFocus(false)
{ {
SetWordWrap(false); SetWordWrap(false);
} }
// destructor
InputTextView::~InputTextView() InputTextView::~InputTextView()
{ {
} }
// MouseDown
void void
InputTextView::MouseDown(BPoint where) InputTextView::MouseDown(BPoint where)
{ {
@@ -47,7 +46,7 @@ InputTextView::MouseDown(BPoint where)
} }
} }
// MouseUp
void void
InputTextView::MouseUp(BPoint where) InputTextView::MouseUp(BPoint where)
{ {
@@ -58,7 +57,7 @@ InputTextView::MouseUp(BPoint where)
BTextView::MouseUp(where); BTextView::MouseUp(where);
} }
// KeyDown
void void
InputTextView::KeyDown(const char* bytes, int32 numBytes) InputTextView::KeyDown(const char* bytes, int32 numBytes)
{ {
@@ -85,7 +84,7 @@ InputTextView::KeyDown(const char* bytes, int32 numBytes)
BTextView::KeyDown(bytes, numBytes); BTextView::KeyDown(bytes, numBytes);
} }
// MakeFocus
void void
InputTextView::MakeFocus(bool focus) InputTextView::MakeFocus(bool focus)
{ {
@@ -98,7 +97,7 @@ InputTextView::MakeFocus(bool focus)
} }
} }
// Invoke
status_t status_t
InputTextView::Invoke(BMessage* message) InputTextView::Invoke(BMessage* message)
{ {
@@ -114,9 +113,10 @@ InputTextView::Invoke(BMessage* message)
return B_BAD_VALUE; return B_BAD_VALUE;
} }
// #pragma mark - // #pragma mark -
// Select
void void
InputTextView::Select(int32 start, int32 finish) InputTextView::Select(int32 start, int32 finish)
{ {
@@ -125,17 +125,17 @@ InputTextView::Select(int32 start, int32 finish)
_CheckTextRect(); _CheckTextRect();
} }
// InsertText
void void
InputTextView::InsertText(const char* inText, int32 inLength, int32 inOffset, InputTextView::InsertText(const char* inText, int32 inLength, int32 inOffset,
const text_run_array* inRuns) const text_run_array* inRuns)
{ {
BTextView::InsertText(inText, inLength, inOffset, inRuns); BTextView::InsertText(inText, inLength, inOffset, inRuns);
_CheckTextRect(); _CheckTextRect();
} }
// DeleteText
void void
InputTextView::DeleteText(int32 fromOffset, int32 toOffset) InputTextView::DeleteText(int32 fromOffset, int32 toOffset)
{ {
@@ -144,9 +144,10 @@ InputTextView::DeleteText(int32 fromOffset, int32 toOffset)
_CheckTextRect(); _CheckTextRect();
} }
// #pragma mark - // #pragma mark -
// _CheckTextRect
void void
InputTextView::_CheckTextRect() InputTextView::_CheckTextRect()
{ {
+9 -10
View File
@@ -12,14 +12,13 @@
#include <Invoker.h> #include <Invoker.h>
#include <TextView.h> #include <TextView.h>
class InputTextView : public BTextView, class InputTextView : public BTextView, public BInvoker {
public BInvoker {
public: public:
InputTextView(BRect frame, InputTextView(BRect frame,
const char* name, const char* name,
BRect textRect, BRect textRect,
uint32 resizingMode, uint32 resizingMode,
uint32 flags); uint32 flags);
virtual ~InputTextView(); virtual ~InputTextView();
// BTextView interface // BTextView interface
@@ -41,11 +40,11 @@ protected:
virtual void Select(int32 start, int32 finish); virtual void Select(int32 start, int32 finish);
virtual void InsertText(const char* inText, virtual void InsertText(const char* inText,
int32 inLength, int32 inLength,
int32 inOffset, int32 inOffset,
const text_run_array* inRuns); const text_run_array* inRuns);
virtual void DeleteText(int32 fromOffset, virtual void DeleteText(int32 fromOffset,
int32 toOffset); int32 toOffset);
void _CheckTextRect(); void _CheckTextRect();