* Minor cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31391 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-07-03 12:59:56 +00:00
parent e59fc195db
commit 4d365bbed9
+35 -21
View File
@@ -1,11 +1,12 @@
/*
* Copyright (c) 2004-2008, Haiku. All rights reserved.
* Distributed under the terms of the MIT/X11 license.
* Copyright 2004-2009, Haiku. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Jérôme Duval
*/
#include "MethodReplicant.h"
#include <new>
@@ -33,21 +34,25 @@
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)
{
// Background Bitmap
fSegments = new BBitmap(BRect(0, 0, kRemoteWidth - 1, kRemoteHeight - 1), kRemoteColorSpace);
fSegments->SetBits(kRemoteBits, kRemoteWidth*kRemoteHeight, 0, kRemoteColorSpace);
fSegments = new BBitmap(BRect(0, 0, kRemoteWidth - 1, kRemoteHeight - 1),
kRemoteColorSpace);
fSegments->SetBits(kRemoteBits, kRemoteWidth * kRemoteHeight, 0,
kRemoteColorSpace);
// Background Color
// add dragger
BRect rect(Bounds());
rect.left = rect.right - 7.0;
rect.top = rect.bottom - 7.0;
BDragger *dragger = new BDragger(rect, this, B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
AddChild(dragger);
BDragger* dragger = new BDragger(rect, this,
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
dragger->SetViewColor(B_TRANSPARENT_32_BIT);
AddChild(dragger);
ASSERT(signature != NULL);
fSignature = strdup(signature);
@@ -58,12 +63,15 @@ MethodReplicant::MethodReplicant(const char* signature)
MethodReplicant::MethodReplicant(BMessage* message)
: BView(message),
:
BView(message),
fMenu("", false, false)
{
// Background Bitmap
fSegments = new BBitmap(BRect(0, 0, kRemoteWidth - 1, kRemoteHeight - 1), kRemoteColorSpace);
fSegments->SetBits(kRemoteBits, kRemoteWidth*kRemoteHeight, 0, kRemoteColorSpace);
fSegments = new BBitmap(BRect(0, 0, kRemoteWidth - 1, kRemoteHeight - 1),
kRemoteColorSpace);
fSegments->SetBits(kRemoteBits, kRemoteWidth * kRemoteHeight, 0,
kRemoteColorSpace);
const char* signature = NULL;
message->FindString("add_on", &signature);
@@ -115,22 +123,24 @@ MethodReplicant::AttachedToWindow()
msg.AddMessenger("address", messenger);
BMessenger inputMessenger(fSignature);
if (inputMessenger.SendMessage(&msg) != B_OK) {
if (inputMessenger.SendMessage(&msg) != B_OK)
printf("error when contacting input_server\n");
}
}
void
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);
switch (message->what) {
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"
"Haiku, 2004", "OK"))->Go();
"Haiku, 2004-2009", "OK"))->Go();
break;
case IS_UPDATE_NAME:
UpdateMethodName(message);
@@ -182,7 +192,7 @@ MethodReplicant::MouseDown(BPoint point)
BMenuItem* item = fMenu.Go(where, true, true,
BRect(where - BPoint(4, 4), where + BPoint(4, 4)));
if (item && dynamic_cast<MethodMenuItem *>(item)) {
if (dynamic_cast<MethodMenuItem*>(item) != NULL) {
BMessage msg(IS_SET_METHOD);
msg.AddInt32("cookie", ((MethodMenuItem*)item)->Cookie());
BMessenger messenger(fSignature);
@@ -215,7 +225,8 @@ MethodReplicant::UpdateMethod(BMessage *message)
}
item->SetMarked(true);
fSegments->SetBits(item->Icon(), kRemoteWidth*kRemoteHeight, 0, kRemoteColorSpace);
fSegments->SetBits(item->Icon(), kRemoteWidth * kRemoteHeight, 0,
kRemoteColorSpace);
Invalidate();
}
@@ -232,7 +243,8 @@ MethodReplicant::UpdateMethodIcon(BMessage *message)
const uchar* data;
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");
return;
}
@@ -284,11 +296,12 @@ MethodReplicant::UpdateMethodMenu(BMessage *message)
int32 index = fMenu.IndexOf(item);
MethodMenuItem* item2 = NULL;
if (menu)
if (menu) {
item2 = new MethodMenuItem(cookie, item->Label(), item->Icon(),
menu, messenger);
else
} else
item2 = new MethodMenuItem(cookie, item->Label(), item->Icon());
item = (MethodMenuItem*)fMenu.RemoveItem(index);
fMenu.AddItem(item2, index);
item2->SetMarked(item->IsMarked());
@@ -354,7 +367,8 @@ MethodReplicant::AddMethod(BMessage *message)
const uchar* icon;
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");
return;
}