code style

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20704 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2007-04-15 14:17:02 +00:00
parent 88ec4b1dbe
commit 1cafa90eda
4 changed files with 119 additions and 121 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ MethodMenuItem::MethodMenuItem(int32 cookie, const char* name, const uchar* icon
{ {
SetLabel(name); SetLabel(name);
fIcon.SetBits(icon, MENUITEM_ICON_SIZE * MENUITEM_ICON_SIZE, 0, B_CMAP8); fIcon.SetBits(icon, MENUITEM_ICON_SIZE * MENUITEM_ICON_SIZE, 0, B_CMAP8);
fMessenger = messenger; fMessenger = messenger;
} }
+19 -20
View File
@@ -2,13 +2,13 @@
// //
// Copyright (c) 2004, Haiku // Copyright (c) 2004, Haiku
// //
// This software is part of the Haiku distribution and is covered // This software is part of the Haiku distribution and is covered
// by the Haiku license. // by the Haiku license.
// //
// //
// File: MethodMenuItem.h // File: MethodMenuItem.h
// Authors: Jérôme Duval, // Authors: Jérôme Duval,
// //
// Description: Input Server // Description: Input Server
// Created: October 19, 2004 // Created: October 19, 2004
// //
@@ -23,27 +23,26 @@
#define MENUITEM_ICON_SIZE 16 #define MENUITEM_ICON_SIZE 16
class MethodMenuItem : public BMenuItem { class MethodMenuItem : public BMenuItem {
public: public:
MethodMenuItem(int32 cookie, const char *label, const uchar *icon, BMenu *subMenu, BMessenger &messenger); MethodMenuItem(int32 cookie, const char *label, const uchar *icon, BMenu *subMenu, BMessenger &messenger);
MethodMenuItem(int32 cookie, const char *label, const uchar *icon); MethodMenuItem(int32 cookie, const char *label, const uchar *icon);
virtual ~MethodMenuItem();
virtual void DrawContent(); virtual ~MethodMenuItem();
virtual void GetContentSize(float *width, float *height);
void SetName(const char *name); virtual void DrawContent();
const char *Name() { return Label(); }; virtual void GetContentSize(float *width, float *height);
void SetIcon(const uchar *icon); void SetName(const char *name);
const uchar *Icon() { return (uchar *)fIcon.Bits(); }; const char *Name() { return Label(); };
const int32 Cookie() { return fCookie; }; void SetIcon(const uchar *icon);
private: const uchar *Icon() { return(uchar *)fIcon.Bits(); };
BBitmap fIcon;
int32 fCookie; const int32 Cookie() { return fCookie; };
BMessenger fMessenger; private:
BBitmap fIcon;
int32 fCookie;
BMessenger fMessenger;
}; };
#endif #endif
+70 -70
View File
@@ -2,13 +2,13 @@
// //
// Copyright (c) 2004, Haiku // Copyright (c) 2004, Haiku
// //
// This software is part of the Haiku distribution and is covered // This software is part of the Haiku distribution and is covered
// by the Haiku license. // by the Haiku license.
// //
// //
// File: MethodReplicant.cpp // File: MethodReplicant.cpp
// Authors: Jérôme Duval, // Authors: Jérôme Duval,
// //
// Description: Input Server // Description: Input Server
// Created: October 13, 2004 // Created: October 13, 2004
// //
@@ -33,29 +33,29 @@
#ifdef DEBUG #ifdef DEBUG
#define CALLED() PRINT(("CALLED %s \n", __PRETTY_FUNCTION__)); #define CALLED() PRINT(("CALLED %s \n", __PRETTY_FUNCTION__));
#else #else
#define CALLED() #define CALLED()
#endif #endif
MethodReplicant::MethodReplicant(const char* signature) MethodReplicant::MethodReplicant(const char* signature)
: BView(BRect(0, 0, 15, 15), REPLICANT_CTL_NAME, B_FOLLOW_ALL, B_WILL_DRAW), : BView(BRect(0, 0, 15, 15), REPLICANT_CTL_NAME, B_FOLLOW_ALL, B_WILL_DRAW),
fMenu("", false, false) fMenu("", false, false)
{ {
// Background Bitmap // Background Bitmap
fSegments = new BBitmap(BRect(0, 0, kRemoteWidth - 1, kRemoteHeight - 1), kRemoteColorSpace); fSegments = new BBitmap(BRect(0, 0, kRemoteWidth - 1, kRemoteHeight - 1), kRemoteColorSpace);
fSegments->SetBits(kRemoteBits, kRemoteWidth*kRemoteHeight, 0, kRemoteColorSpace); fSegments->SetBits(kRemoteBits, kRemoteWidth*kRemoteHeight, 0, kRemoteColorSpace);
// Background Color // Background Color
SetViewColor(184,184,184); SetViewColor(184, 184, 184);
//add dragger //add dragger
BRect rect(Bounds()); BRect rect(Bounds());
rect.left = rect.right-7.0; rect.left = rect.right - 7.0;
rect.top = rect.bottom-7.0; rect.top = rect.bottom - 7.0;
BDragger *dragger = new BDragger(rect, this, B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); BDragger *dragger = new BDragger(rect, this, B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
AddChild(dragger); AddChild(dragger);
dragger->SetViewColor(B_TRANSPARENT_32_BIT); dragger->SetViewColor(B_TRANSPARENT_32_BIT);
ASSERT(signature!=NULL); ASSERT(signature != NULL);
fSignature = strdup(signature); fSignature = strdup(signature);
fMenu.SetFont(be_plain_font); fMenu.SetFont(be_plain_font);
@@ -65,15 +65,15 @@ MethodReplicant::MethodReplicant(const char* signature)
MethodReplicant::MethodReplicant(BMessage *message) MethodReplicant::MethodReplicant(BMessage *message)
: BView(message), : BView(message),
fMenu("", false, false) fMenu("", false, false)
{ {
// Background Bitmap // Background Bitmap
fSegments = new BBitmap(BRect(0, 0, kRemoteWidth - 1, kRemoteHeight - 1), kRemoteColorSpace); fSegments = new BBitmap(BRect(0, 0, kRemoteWidth - 1, kRemoteHeight - 1), kRemoteColorSpace);
fSegments->SetBits(kRemoteBits, kRemoteWidth*kRemoteHeight, 0, kRemoteColorSpace); fSegments->SetBits(kRemoteBits, kRemoteWidth*kRemoteHeight, 0, kRemoteColorSpace);
const char *signature = NULL; const char *signature = NULL;
message->FindString("add_on", &signature); message->FindString("add_on", &signature);
ASSERT(signature!=NULL); ASSERT(signature != NULL);
fSignature = strdup(signature); fSignature = strdup(signature);
fMenu.SetFont(be_plain_font); fMenu.SetFont(be_plain_font);
@@ -99,7 +99,7 @@ MethodReplicant::Instantiate(BMessage *data)
} }
status_t status_t
MethodReplicant::Archive(BMessage *data, bool deep) const MethodReplicant::Archive(BMessage *data, bool deep) const
{ {
BView::Archive(data, deep); BView::Archive(data, deep);
@@ -118,7 +118,7 @@ MethodReplicant::AttachedToWindow()
msg.AddMessenger("address", messenger); msg.AddMessenger("address", messenger);
BMessenger inputMessenger(fSignature); BMessenger inputMessenger(fSignature);
if (inputMessenger.SendMessage(&msg)!=B_OK) { if (inputMessenger.SendMessage(&msg) != B_OK) {
printf("error when contacting input_server\n"); printf("error when contacting input_server\n");
} }
} }
@@ -127,45 +127,45 @@ MethodReplicant::AttachedToWindow()
void void
MethodReplicant::MessageReceived(BMessage *message) MethodReplicant::MessageReceived(BMessage *message)
{ {
PRINT(("%s what:%c%c%c%c\n", __PRETTY_FUNCTION__, message->what>>24, message->what>>16, message->what>>8, message->what)); PRINT(("%s what:%c%c%c%c\n", __PRETTY_FUNCTION__, message->what >> 24, message->what >> 16, message->what >> 8, message->what));
PRINT_OBJECT(*message); PRINT_OBJECT(*message);
switch (message->what) { switch (message->what) {
case B_ABOUT_REQUESTED: case B_ABOUT_REQUESTED:
(new BAlert("About Method Replicant", "Method Replicant (Replicant)\n" (new BAlert("About Method Replicant", "Method Replicant (Replicant)\n"
" Brought to you by Jérôme DUVAL.\n\n" " Brought to you by Jérôme DUVAL.\n\n"
"Haiku, 2004","OK"))->Go(); "Haiku, 2004", "OK"))->Go();
break; break;
case IS_UPDATE_NAME: case IS_UPDATE_NAME:
UpdateMethodName(message); UpdateMethodName(message);
break; break;
case IS_UPDATE_ICON: case IS_UPDATE_ICON:
UpdateMethodIcon(message); UpdateMethodIcon(message);
break; break;
case IS_UPDATE_MENU: case IS_UPDATE_MENU:
UpdateMethodMenu(message); UpdateMethodMenu(message);
break; break;
case IS_UPDATE_METHOD: case IS_UPDATE_METHOD:
UpdateMethod(message); UpdateMethod(message);
break; break;
case IS_ADD_METHOD: case IS_ADD_METHOD:
AddMethod(message); AddMethod(message);
break; break;
case IS_REMOVE_METHOD: case IS_REMOVE_METHOD:
RemoveMethod(message); RemoveMethod(message);
break; break;
default: default:
BView::MessageReceived(message); BView::MessageReceived(message);
break; break;
} }
} }
void void
MethodReplicant::Draw(BRect rect) MethodReplicant::Draw(BRect rect)
{ {
BView::Draw(rect); BView::Draw(rect);
SetDrawingMode(B_OP_OVER); SetDrawingMode(B_OP_OVER);
DrawBitmap(fSegments); DrawBitmap(fSegments);
} }
@@ -178,13 +178,13 @@ MethodReplicant::MouseDown(BPoint point)
uint32 mouseButtons; uint32 mouseButtons;
BPoint where; BPoint where;
GetMouse(&where, &mouseButtons, true); GetMouse(&where, &mouseButtons, true);
where = ConvertToScreen(point); where = ConvertToScreen(point);
fMenu.SetTargetForItems(this); fMenu.SetTargetForItems(this);
BMenuItem *item = fMenu.Go(where, true, true, BMenuItem *item = fMenu.Go(where, true, true,
BRect(where - BPoint(4, 4), where + BPoint(4, 4))); BRect(where - BPoint(4, 4), where + BPoint(4, 4)));
if (item && dynamic_cast<MethodMenuItem *>(item)) { if (item && dynamic_cast<MethodMenuItem *>(item)) {
BMessage msg(IS_SET_METHOD); BMessage msg(IS_SET_METHOD);
msg.AddInt32("cookie", ((MethodMenuItem*)item)->Cookie()); msg.AddInt32("cookie", ((MethodMenuItem*)item)->Cookie());
@@ -201,12 +201,12 @@ MethodReplicant::MouseUp(BPoint point)
} }
void void
MethodReplicant::UpdateMethod(BMessage *message) MethodReplicant::UpdateMethod(BMessage *message)
{ {
CALLED(); CALLED();
int32 cookie; int32 cookie;
if (message->FindInt32("cookie", &cookie)!=B_OK) { if (message->FindInt32("cookie", &cookie) != B_OK) {
fprintf(stderr, "can't find cookie in message\n"); fprintf(stderr, "can't find cookie in message\n");
return; return;
} }
@@ -223,19 +223,19 @@ MethodReplicant::UpdateMethod(BMessage *message)
} }
void void
MethodReplicant::UpdateMethodIcon(BMessage *message) MethodReplicant::UpdateMethodIcon(BMessage *message)
{ {
CALLED(); CALLED();
int32 cookie; int32 cookie;
if (message->FindInt32("cookie", &cookie)!=B_OK) { if (message->FindInt32("cookie", &cookie) != B_OK) {
fprintf(stderr, "can't find cookie in message\n"); fprintf(stderr, "can't find cookie in message\n");
return; return;
} }
const uchar *data; const uchar *data;
ssize_t numBytes; ssize_t numBytes;
if (message->FindData("icon", B_ANY_TYPE, (const void**)&data, &numBytes)!=B_OK) { if (message->FindData("icon", B_ANY_TYPE, (const void**)&data, &numBytes) != B_OK) {
fprintf(stderr, "can't find icon in message\n"); fprintf(stderr, "can't find icon in message\n");
return; return;
} }
@@ -250,25 +250,25 @@ MethodReplicant::UpdateMethodIcon(BMessage *message)
} }
void void
MethodReplicant::UpdateMethodMenu(BMessage *message) MethodReplicant::UpdateMethodMenu(BMessage *message)
{ {
CALLED(); CALLED();
int32 cookie; int32 cookie;
if (message->FindInt32("cookie", &cookie)!=B_OK) { if (message->FindInt32("cookie", &cookie) != B_OK) {
fprintf(stderr, "can't find cookie in message\n"); fprintf(stderr, "can't find cookie in message\n");
return; return;
} }
BMessage msg; BMessage msg;
if (message->FindMessage("menu", &msg)!=B_OK) { if (message->FindMessage("menu", &msg) != B_OK) {
fprintf(stderr, "can't find menu in message\n"); fprintf(stderr, "can't find menu in message\n");
return; return;
} }
PRINT_OBJECT(msg); PRINT_OBJECT(msg);
BMessenger messenger; BMessenger messenger;
if (message->FindMessenger("target", &messenger)!=B_OK) { if (message->FindMessenger("target", &messenger) != B_OK) {
fprintf(stderr, "can't find target in message\n"); fprintf(stderr, "can't find target in message\n");
return; return;
} }
@@ -288,7 +288,7 @@ MethodReplicant::UpdateMethodMenu(BMessage *message)
MethodMenuItem *item2 = NULL; MethodMenuItem *item2 = NULL;
if (menu) if (menu)
item2 = new MethodMenuItem(cookie, item->Label(), item->Icon(), item2 = new MethodMenuItem(cookie, item->Label(), item->Icon(),
menu, messenger); menu, messenger);
else else
item2 = new MethodMenuItem(cookie, item->Label(), item->Icon()); item2 = new MethodMenuItem(cookie, item->Label(), item->Icon());
@@ -299,18 +299,18 @@ MethodReplicant::UpdateMethodMenu(BMessage *message)
} }
void void
MethodReplicant::UpdateMethodName(BMessage *message) MethodReplicant::UpdateMethodName(BMessage *message)
{ {
CALLED(); CALLED();
int32 cookie; int32 cookie;
if (message->FindInt32("cookie", &cookie)!=B_OK) { if (message->FindInt32("cookie", &cookie) != B_OK) {
fprintf(stderr, "can't find cookie in message\n"); fprintf(stderr, "can't find cookie in message\n");
return; return;
} }
const char *name; const char *name;
if (message->FindString("name", &name)!=B_OK) { if (message->FindString("name", &name) != B_OK) {
fprintf(stderr, "can't find name in message\n"); fprintf(stderr, "can't find name in message\n");
return; return;
} }
@@ -328,36 +328,36 @@ MethodReplicant::UpdateMethodName(BMessage *message)
MethodMenuItem * MethodMenuItem *
MethodReplicant::FindItemByCookie(int32 cookie) MethodReplicant::FindItemByCookie(int32 cookie)
{ {
for (int32 i=0; i<fMenu.CountItems(); i++) { for (int32 i = 0; i < fMenu.CountItems(); i++) {
MethodMenuItem *item = (MethodMenuItem *)fMenu.ItemAt(i); MethodMenuItem *item = (MethodMenuItem *)fMenu.ItemAt(i);
PRINT(("cookie : 0x%lx\n", item->Cookie())); PRINT(("cookie : 0x%lx\n", item->Cookie()));
if (item->Cookie()==cookie) if (item->Cookie() == cookie)
return item; return item;
} }
return NULL; return NULL;
} }
void void
MethodReplicant::AddMethod(BMessage *message) MethodReplicant::AddMethod(BMessage *message)
{ {
CALLED(); CALLED();
int32 cookie; int32 cookie;
if (message->FindInt32("cookie", &cookie)!=B_OK) { if (message->FindInt32("cookie", &cookie) != B_OK) {
fprintf(stderr, "can't find cookie in message\n"); fprintf(stderr, "can't find cookie in message\n");
return; return;
} }
const char *name; const char *name;
if (message->FindString("name", &name)!=B_OK) { if (message->FindString("name", &name) != B_OK) {
fprintf(stderr, "can't find name in message\n"); fprintf(stderr, "can't find name in message\n");
return; return;
} }
const uchar *icon; const uchar *icon;
ssize_t numBytes; ssize_t numBytes;
if (message->FindData("icon", B_ANY_TYPE, (const void**)&icon, &numBytes)!=B_OK) { if (message->FindData("icon", B_ANY_TYPE, (const void**)&icon, &numBytes) != B_OK) {
fprintf(stderr, "can't find icon in message\n"); fprintf(stderr, "can't find icon in message\n");
return; return;
} }
@@ -377,12 +377,12 @@ MethodReplicant::AddMethod(BMessage *message)
} }
void void
MethodReplicant::RemoveMethod(BMessage *message) MethodReplicant::RemoveMethod(BMessage *message)
{ {
CALLED(); CALLED();
int32 cookie; int32 cookie;
if (message->FindInt32("cookie", &cookie)!=B_OK) { if (message->FindInt32("cookie", &cookie) != B_OK) {
fprintf(stderr, "can't find cookie in message\n"); fprintf(stderr, "can't find cookie in message\n");
return; return;
} }
+29 -30
View File
@@ -2,13 +2,13 @@
// //
// Copyright (c) 2004, Haiku // Copyright (c) 2004, Haiku
// //
// This software is part of the Haiku distribution and is covered // This software is part of the Haiku distribution and is covered
// by the Haiku license. // by the Haiku license.
// //
// //
// File: MethodReplicant.h // File: MethodReplicant.h
// Authors: Jérôme Duval, // Authors: Jérôme Duval,
// //
// Description: Input Server // Description: Input Server
// Created: October 13, 2004 // Created: October 13, 2004
// //
@@ -26,39 +26,38 @@
class _EXPORT MethodReplicant; class _EXPORT MethodReplicant;
class MethodReplicant : public BView { class MethodReplicant : public BView {
public: public:
MethodReplicant(const char* signature); MethodReplicant(const char* signature);
MethodReplicant(BMessage *); MethodReplicant(BMessage *);
// BMessage * based constructor needed to support archiving // BMessage * based constructor needed to support archiving
virtual ~MethodReplicant(); virtual ~MethodReplicant();
// archiving overrides // archiving overrides
static MethodReplicant *Instantiate(BMessage *data); static MethodReplicant *Instantiate(BMessage *data);
virtual status_t Archive(BMessage *data, bool deep = true) const; virtual status_t Archive(BMessage *data, bool deep = true) const;
virtual void AttachedToWindow(); virtual void AttachedToWindow();
// misc BView overrides // misc BView overrides
virtual void MouseDown(BPoint); virtual void MouseDown(BPoint);
virtual void MouseUp(BPoint); virtual void MouseUp(BPoint);
virtual void Draw(BRect );
virtual void MessageReceived(BMessage *); virtual void Draw(BRect);
private:
BBitmap *fSegments;
char *fSignature;
BPopUpMenu fMenu;
void UpdateMethod(BMessage *); virtual void MessageReceived(BMessage *);
void UpdateMethodIcon(BMessage *); private:
void UpdateMethodMenu(BMessage *); BBitmap *fSegments;
void UpdateMethodName(BMessage *); char *fSignature;
void AddMethod(BMessage *message); BPopUpMenu fMenu;
void RemoveMethod(BMessage *message);
MethodMenuItem *FindItemByCookie(int32 cookie); void UpdateMethod(BMessage *);
void UpdateMethodIcon(BMessage *);
void UpdateMethodMenu(BMessage *);
void UpdateMethodName(BMessage *);
void AddMethod(BMessage *message);
void RemoveMethod(BMessage *message);
MethodMenuItem *FindItemByCookie(int32 cookie);
}; };
#endif #endif