* Minor cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31391 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2004-2008, Haiku. All rights reserved.
|
* Copyright 2004-2009, Haiku. All rights reserved.
|
||||||
* Distributed under the terms of the MIT/X11 license.
|
* Distributed under the terms of the MIT license.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Jérôme Duval
|
* Jérôme Duval
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "MethodReplicant.h"
|
#include "MethodReplicant.h"
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
@@ -33,21 +34,25 @@
|
|||||||
|
|
||||||
|
|
||||||
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),
|
||||||
fSegments->SetBits(kRemoteBits, kRemoteWidth*kRemoteHeight, 0, kRemoteColorSpace);
|
kRemoteColorSpace);
|
||||||
|
fSegments->SetBits(kRemoteBits, kRemoteWidth * kRemoteHeight, 0,
|
||||||
|
kRemoteColorSpace);
|
||||||
// Background Color
|
// Background Color
|
||||||
|
|
||||||
// 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,
|
||||||
AddChild(dragger);
|
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||||
dragger->SetViewColor(B_TRANSPARENT_32_BIT);
|
dragger->SetViewColor(B_TRANSPARENT_32_BIT);
|
||||||
|
AddChild(dragger);
|
||||||
|
|
||||||
ASSERT(signature != NULL);
|
ASSERT(signature != NULL);
|
||||||
fSignature = strdup(signature);
|
fSignature = strdup(signature);
|
||||||
@@ -58,12 +63,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),
|
||||||
fSegments->SetBits(kRemoteBits, kRemoteWidth*kRemoteHeight, 0, kRemoteColorSpace);
|
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);
|
||||||
@@ -115,22 +123,24 @@ 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");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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-2009", "OK"))->Go();
|
||||||
break;
|
break;
|
||||||
case IS_UPDATE_NAME:
|
case IS_UPDATE_NAME:
|
||||||
UpdateMethodName(message);
|
UpdateMethodName(message);
|
||||||
@@ -182,7 +192,7 @@ MethodReplicant::MouseDown(BPoint point)
|
|||||||
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 (dynamic_cast<MethodMenuItem*>(item) != NULL) {
|
||||||
BMessage msg(IS_SET_METHOD);
|
BMessage msg(IS_SET_METHOD);
|
||||||
msg.AddInt32("cookie", ((MethodMenuItem*)item)->Cookie());
|
msg.AddInt32("cookie", ((MethodMenuItem*)item)->Cookie());
|
||||||
BMessenger messenger(fSignature);
|
BMessenger messenger(fSignature);
|
||||||
@@ -215,7 +225,8 @@ MethodReplicant::UpdateMethod(BMessage *message)
|
|||||||
}
|
}
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
|
|
||||||
fSegments->SetBits(item->Icon(), kRemoteWidth*kRemoteHeight, 0, kRemoteColorSpace);
|
fSegments->SetBits(item->Icon(), kRemoteWidth * kRemoteHeight, 0,
|
||||||
|
kRemoteColorSpace);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +243,8 @@ MethodReplicant::UpdateMethodIcon(BMessage *message)
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -284,11 +296,12 @@ MethodReplicant::UpdateMethodMenu(BMessage *message)
|
|||||||
int32 index = fMenu.IndexOf(item);
|
int32 index = fMenu.IndexOf(item);
|
||||||
|
|
||||||
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());
|
||||||
|
|
||||||
item = (MethodMenuItem*)fMenu.RemoveItem(index);
|
item = (MethodMenuItem*)fMenu.RemoveItem(index);
|
||||||
fMenu.AddItem(item2, index);
|
fMenu.AddItem(item2, index);
|
||||||
item2->SetMarked(item->IsMarked());
|
item2->SetMarked(item->IsMarked());
|
||||||
@@ -354,7 +367,8 @@ MethodReplicant::AddMethod(BMessage *message)
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user