*modified ReadRawFromPort() and ConvertToMessage() methods to use BSession class.

*modified/added B_VIEW_(MOVED/RESIZED) handlers in ConvertToMessage()/DispatchMessage()


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4802 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adi Oanca
2003-09-25 12:15:49 +00:00
parent 6e62790567
commit da024ab387
+184 -265
View File
@@ -53,11 +53,12 @@
// Standard Includes ----------------------------------------------------------- // Standard Includes -----------------------------------------------------------
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <posix/math.h>
// Local Includes -------------------------------------------------------------- // Local Includes --------------------------------------------------------------
// Local Defines --------------------------------------------------------------- // Local Defines ---------------------------------------------------------------
#define DEBUG_WIN //#define DEBUG_WIN
#ifdef DEBUG_WIN #ifdef DEBUG_WIN
# include <stdio.h> # include <stdio.h>
# define STRACE(x) printf x # define STRACE(x) printf x
@@ -780,7 +781,7 @@ void BWindow::DispatchMessage(BMessage *msg, BHandler *target)
msg->FindInt32( "modifiers", (int32*)&modifiers ); msg->FindInt32( "modifiers", (int32*)&modifiers );
msg->FindInt32( "raw_char", &raw_char ); msg->FindInt32( "raw_char", &raw_char );
msg->FindString( "bytes", &string ); msg->FindString( "bytes", &string );
// TODO: it is NOT "bytes" field you should pass to KeyDown(), it is "byte" field.
if ( !handleKeyDown( raw_char, (uint32)modifiers) ) if ( !handleKeyDown( raw_char, (uint32)modifiers) )
fFocus->KeyDown( string, strlen(string)-1 ); fFocus->KeyDown( string, strlen(string)-1 );
break;} break;}
@@ -857,22 +858,59 @@ void BWindow::DispatchMessage(BMessage *msg, BHandler *target)
break;} break;}
case _UPDATE_:{ case _UPDATE_:{
BView *view; BRect updateRect;
int32 token; msg->FindRect("_rect", &updateRect);
BRect frame;
msg->FindInt32("token", &token); // TODO: ADD this method:
msg->FindRect("frame", &frame); //DrawViews( updateRect );
view = findView( top_view, token );
drawView( view, frame );
break;} break;}
case B_VIEW_MOVED:{
BPoint where;
int32 token = B_NULL_TOKEN;
BView *view;
msg->FindPoint("where", &where);
msg->FindInt32("_token", &token);
msg->RemoveName("_token");
view = findView(top_view, token);
if (view){
STRACE(("Calling BView(%s)::FrameMoved( %f, %f )\n", view->Name(), where.x, where.y));
view->FrameMoved( where );
}
else
printf("***PANIC: BW: Can't find view with ID: %ld !***\n", token);
break;}
case B_VIEW_RESIZED:{
float newWidth,
newHeight;
BPoint where;
int32 token = B_NULL_TOKEN;
BView *view;
msg->FindFloat("width", &newWidth);
msg->FindFloat("height", &newHeight);
msg->FindPoint("where", &where);
msg->FindInt32("_token", &token);
msg->RemoveName("_token");
view = findView(top_view, token);
if (view){
STRACE(("Calling BView(%s)::FrameResized( %f, %f )\n", view->Name(), newWidth, newHeight));
view->FrameResized( newWidth, newHeight );
}
else
printf("***PANIC: BW: Can't find view with ID: %ld !***\n", token);
break;}
default:{ default:{
BLooper::DispatchMessage(msg, target); BLooper::DispatchMessage(msg, target);
break;} break;}
} }
Sync();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -1728,30 +1766,24 @@ void BWindow::ResizeTo(float width, float height){
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BWindow::Show(){ void BWindow::Show(){
bool isLocked = IsLocked(); bool isLocked = this->IsLocked();
fShowLevel--; fShowLevel--;
if (fShowLevel == 0){ if (fShowLevel == 0){
#ifdef DEBUG_WIN STRACE(("BWindow(%s): sending AS_SHOW_WINDOW message...\n", Name() ));
printf(">BWindow: sending AS_SHOW_WINDOW message...\n");
#endif
if ( !isLocked ) Lock(); if ( !isLocked ) Lock();
session->WriteInt32( AS_SHOW_WINDOW ); session->WriteInt32( AS_SHOW_WINDOW );
session->Sync( ); session->Sync( );
if ( !isLocked) Unlock(); if ( !isLocked) Unlock();
} }
// if it's the fist time Show() is called... start the Looper thread.
if ( Thread() == B_ERROR ) if ( Thread() == B_ERROR )
{ {
#ifdef DEBUG_WIN // normaly this won't happen, but I want to be sure!
printf(">BWindow: calling Run()...\n"); if ( !isLocked ) Lock();
#endif
Lock();
Run(); Run();
#ifdef DEBUG_WIN
printf(">BWindow: Run() called.\n");
#endif
} }
} }
@@ -1871,13 +1903,11 @@ void BWindow::InitData( BRect frame,
uint32 flags, uint32 flags,
uint32 workspace){ uint32 workspace){
#ifdef DEBUG_WIN STRACE(("BWindow::InitData(...)\n"));
printf("BWindow::InitData(...)\n");
#endif
fTitle=NULL; fTitle=NULL;
if ( be_app == NULL ){ if ( be_app == NULL ){
//debugger("You need a valid BApplication object before interacting with the app_server"); debugger("You need a valid BApplication object before interacting with the app_server");
return; return;
} }
@@ -1940,26 +1970,25 @@ void BWindow::InitData( BRect frame,
// TODO: other initializations! // TODO: other initializations!
/* /*
Here, we will contact app_server and let him that a window has been created Here, we will contact app_server and let him know that a window has
been created
*/ */
receive_port = create_port( B_LOOPER_PORT_DEFAULT_CAPACITY , receive_port = create_port( B_LOOPER_PORT_DEFAULT_CAPACITY ,
"w_rcv_port"); "w_rcv_port");
if (receive_port==B_BAD_VALUE || receive_port==B_NO_MORE_PORTS){ if (receive_port==B_BAD_VALUE || receive_port==B_NO_MORE_PORTS){
debugger("Could not create BWindow's receive port, used for interacting with the app_server!"); debugger("Could not create BWindow's receive port, used for interacting with the app_server!");
return; delete this;
} }
#ifdef DEBUG_WIN STRACE(("BWindow::InitData(): contacting app_server...\n"));
printf("BWindow::InitData(): contacting app_server\n");
#endif
// let app_server to know that a window has been created. // let app_server to know that a window has been created.
session = new BSession( receive_port, be_app->fServerFrom ); session = new BSession( receive_port, be_app->fServerFrom );
// HERE we are in BApplication's thread, so for locking we use be_app variable // HERE we are in BApplication's thread, so for locking we use be_app variable
// we'll lock the be_app to be sure we're the only one writing at BApplication's server port // we'll lock the be_app to be sure we're the only one writing at BApplication's server port
bool locked = false; bool locked = false;
if ( !(be_app->IsLocked()) && !locked) if ( !(be_app->IsLocked()) )
{ be_app->Lock(); locked = true; } { be_app->Lock(); locked = true; }
session->WriteInt32( AS_CREATE_WINDOW ); session->WriteInt32( AS_CREATE_WINDOW );
@@ -1970,6 +1999,7 @@ void BWindow::InitData( BRect frame,
session->WriteUInt32( workspace ); session->WriteUInt32( workspace );
session->WriteInt32( _get_object_token_(this) ); session->WriteInt32( _get_object_token_(this) );
session->WriteData( &receive_port, sizeof(port_id) ); session->WriteData( &receive_port, sizeof(port_id) );
session->WriteData( &fMsgPort, sizeof(port_id) );
session->WriteString( title ); session->WriteString( title );
session->Sync(); session->Sync();
// The port on witch app_server will listen for us // The port on witch app_server will listen for us
@@ -1980,10 +2010,9 @@ void BWindow::InitData( BRect frame,
be_app->Unlock(); be_app->Unlock();
session->SetSendPort(send_port); session->SetSendPort(send_port);
#ifdef DEBUG_WIN
printf("BWindow::InitData(): app_server link established - port_id received\n"); STRACE(("\tapp_server link established.\n"));
PrintToStream(); STRACE(("Window locked?: %s\n", IsLocked()?"True":"False"));
#endif
// build and register top_view with app_server // build and register top_view with app_server
BuildTopView(); BuildTopView();
@@ -2006,9 +2035,8 @@ void BWindow::task_looper(){
// loop: As long as we are not terminating. // loop: As long as we are not terminating.
while (!fTerminating) while (!fTerminating)
{ {
// get BMessages from app_server // get BMessages from app_server
while ( (msg = ReadMessageFromPort(0)) ){ while ( (msg = ReadMessageFromPort(10)) ){
fQueue->Lock(); fQueue->Lock();
fQueue->AddMessage(msg); fQueue->AddMessage(msg);
fQueue->Unlock(); fQueue->Unlock();
@@ -2022,7 +2050,7 @@ void BWindow::task_looper(){
fQueue->Unlock(); fQueue->Unlock();
dispatchNextMessage = true; dispatchNextMessage = true;
} }
// loop: As long as there are messages in the queue and // loop: As long as there are messages in the queue and
// and we are not terminating. // and we are not terminating.
while (!fTerminating && dispatchNextMessage) while (!fTerminating && dispatchNextMessage)
@@ -2032,6 +2060,7 @@ void BWindow::task_looper(){
fQueue->Unlock(); fQueue->Unlock();
Lock(); Lock();
// TODO: add code for drag & drop
if (!fLastMessage) if (!fLastMessage)
{ {
// No more messages: Unlock the looper and terminate the // No more messages: Unlock the looper and terminate the
@@ -2065,11 +2094,12 @@ void BWindow::task_looper(){
{ {
// Do filtering // Do filtering
handler = top_level_filter(fLastMessage, handler); handler = top_level_filter(fLastMessage, handler);
if (handler && handler->Looper() == this) if (handler && handler->Looper() == this)
DispatchMessage(fLastMessage, handler); DispatchMessage(fLastMessage, handler);
} }
} }
// empty our message buffer
session->Sync();
Unlock(); Unlock();
@@ -2087,49 +2117,41 @@ void BWindow::task_looper(){
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BMessage* BWindow::ReadMessageFromPort(bigtime_t tout){ BMessage* BWindow::ReadMessageFromPort(bigtime_t tout){
int32 msgcode; int32 msgCode;
BMessage* msg = NULL; BMessage* msg = NULL;
uint8* msgbuffer;
msgbuffer = ReadRawFromPort(&msgcode, tout); ssize_t bufferSize;
if (msgcode != B_ERROR)
msg = ConvertToMessage(msgbuffer, msgcode);
if (msgbuffer)
delete msgbuffer;
return msg;
}
//------------------------------------------------------------------------------
uint8* BWindow::ReadRawFromPort(int32* code, bigtime_t tout){
uint8* msgbuffer = NULL;
ssize_t buffersize;
// we NEVER have to use B_INFINITE_TIMEOUT // we NEVER have to use B_INFINITE_TIMEOUT
if (tout == B_INFINITE_TIMEOUT) if (tout == B_INFINITE_TIMEOUT)
tout = 0; tout = 0;
buffersize = port_buffer_size_etc(receive_port, B_TIMEOUT, tout); /* because BSession does not have support for timeout operations
if (buffersize == B_TIMED_OUT || buffersize == B_BAD_PORT_ID || We'll use this trick! :-) */
buffersize == B_WOULD_BLOCK) bufferSize = port_buffer_size_etc(receive_port, B_TIMEOUT, tout);
if (bufferSize == B_TIMED_OUT || bufferSize == B_BAD_PORT_ID ||
bufferSize == B_WOULD_BLOCK || bufferSize == B_INTERRUPTED )
{ {
*code = B_ERROR; msgCode = B_ERROR;
return NULL;
} }
// we have something in our port's queue
if (bufferSize > 0){
/* A rudimentary synchronize mechanism between BWindow and app_server.
* Just in case some we do something foolish :-)
* It ensures a clean "restart" if I can call it that way.
*/
if ( session->DropInputBuffer() )
printf("***PANIC: BWindow(%s): BSession's input buffer dropped! The buffer WASN'T empty!***\n", Name());
if (buffersize > 0){ // read message code
msgbuffer = new uint8[buffersize]; session->ReadInt32( &msgCode );
read_port_etc( receive_port, code, msgbuffer,
buffersize, B_TIMEOUT, tout);
} }
return msgbuffer; if ( msgCode != B_ERROR )
msg = ConvertToMessage( NULL, msgCode );
return msg;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -2543,27 +2565,16 @@ void BWindow::sendMessageUsingEventMask( int32 message, BPoint where ){
BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
BMessage *msg; BMessage *msg;
msg = new BMessage();
// This is in case we receive a BMessage from another thread or application
msg = BLooper::ConvertToMessage( raw1, code );
if (msg)
return msg;
// (ALL)This is in case we receive a message from app_server
uint8 *raw;
raw = (uint8*)raw1;
// time since 01/01/70 // time since 01/01/70
int64 when; int64 when;
msg = new BMessage();
switch(code){ switch(code){
case B_WINDOW_ACTIVATED:{ case B_WINDOW_ACTIVATED:{
bool active; bool active;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
active = *((bool*)raw); session->ReadBool( &active );
msg->what = B_WINDOW_ACTIVATED; msg->what = B_WINDOW_ACTIVATED;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2571,35 +2582,33 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
break;} break;}
// TODO: this might be sent by app_server as a BMessage! Anyway, this won't be a problem.
case B_QUIT_REQUESTED:{ case B_QUIT_REQUESTED:{
msg->what = B_QUIT_REQUESTED; msg->what = B_QUIT_REQUESTED;
msg->AddBool("shortcut", false); msg->AddBool("shortcut", false);
break;} break;}
case B_KEY_DOWN:{ case B_KEY_DOWN:{
int32 physicalKeyCode, int32 physicalKeyCode,
repeat, repeat,
modifiers, modifiers,
ASCIIcode; ASCIIcode;
char *bytes; char *bytes = NULL;
uint8 states; uint8 states;
int8 UTF8_1, UTF8_2, UTF8_3; int8 UTF8_1, UTF8_2, UTF8_3;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
physicalKeyCode = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &physicalKeyCode );
repeat = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &repeat );
modifiers = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &modifiers );
states = *((uint8*)raw); raw += sizeof(uint8); session->ReadUInt8( &states );
UTF8_1 = *((int8*)raw); raw += sizeof(int8); session->ReadInt8( &UTF8_1 );
UTF8_2 = *((int8*)raw); raw += sizeof(int8); session->ReadInt8( &UTF8_2 );
UTF8_3 = *((int8*)raw); raw += sizeof(int8); session->ReadInt8( &UTF8_3 );
ASCIIcode = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &ASCIIcode );
bytes = session->ReadString();
bytes = strdup( (char*)raw );
msg->what = B_KEY_DOWN; msg->what = B_KEY_DOWN;
msg->AddInt64("when", when); msg->AddInt64("when", when);
msg->AddInt32("key", physicalKeyCode); msg->AddInt32("key", physicalKeyCode);
@@ -2611,6 +2620,9 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
msg->AddInt8("byte", UTF8_3); msg->AddInt8("byte", UTF8_3);
msg->AddInt32("raw_char", ASCIIcode); msg->AddInt32("raw_char", ASCIIcode);
msg->AddString("bytes", bytes); msg->AddString("bytes", bytes);
if (bytes)
delete bytes;
break;} break;}
@@ -2622,16 +2634,15 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
uint8 states; uint8 states;
int8 UTF8_1, UTF8_2, UTF8_3; int8 UTF8_1, UTF8_2, UTF8_3;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
physicalKeyCode = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &physicalKeyCode );
modifiers = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &modifiers );
states = *((uint8*)raw); raw += sizeof(uint8); session->ReadUInt8( &states );
UTF8_1 = *((int8*)raw); raw += sizeof(int8); session->ReadInt8( &UTF8_1 );
UTF8_2 = *((int8*)raw); raw += sizeof(int8); session->ReadInt8( &UTF8_2 );
UTF8_3 = *((int8*)raw); raw += sizeof(int8); session->ReadInt8( &UTF8_3 );
ASCIIcode = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &ASCIIcode );
bytes = session->ReadString();
bytes = strdup( (char*)raw );
msg->what = B_KEY_UP; msg->what = B_KEY_UP;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2644,6 +2655,9 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
msg->AddInt32("raw_char", ASCIIcode); msg->AddInt32("raw_char", ASCIIcode);
msg->AddString("bytes", bytes); msg->AddString("bytes", bytes);
if (bytes)
delete bytes;
break;} break;}
case B_UNMAPPED_KEY_DOWN:{ case B_UNMAPPED_KEY_DOWN:{
@@ -2651,10 +2665,10 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
modifiers; modifiers;
uint8 states; uint8 states;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
physicalKeyCode = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &physicalKeyCode );
modifiers = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &modifiers );
states = *((uint8*)raw); session->ReadUInt8( &states );
msg->what = B_UNMAPPED_KEY_DOWN; msg->what = B_UNMAPPED_KEY_DOWN;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2669,10 +2683,10 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
modifiers; modifiers;
uint8 states; uint8 states;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
physicalKeyCode = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &physicalKeyCode );
modifiers = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &modifiers );
states = *((uint8*)raw); session->ReadUInt8( &states );
msg->what = B_UNMAPPED_KEY_UP; msg->what = B_UNMAPPED_KEY_UP;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2687,10 +2701,10 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
modifiersOld; modifiersOld;
uint8 states; uint8 states;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
modifiers = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &modifiers );
modifiersOld = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &modifiersOld );
states = *((uint8*)raw); session->ReadUInt8( &states );
msg->what = B_MODIFIERS_CHANGED; msg->what = B_MODIFIERS_CHANGED;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2703,8 +2717,8 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
case B_MINIMIZE:{ case B_MINIMIZE:{
bool minimize; bool minimize;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
minimize = *((bool*)raw); session->ReadBool( &minimize );
msg->what = B_MINIMIZE; msg->what = B_MINIMIZE;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2713,21 +2727,16 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
break;} break;}
case B_MOUSE_DOWN:{ case B_MOUSE_DOWN:{
float mouseLocationX,
mouseLocationY;
int32 modifiers, int32 modifiers,
buttons, buttons,
noOfClicks; noOfClicks;
BPoint where; BPoint where;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
mouseLocationX = *((float*)raw); raw += sizeof(float); // view's coordinate system session->ReadPoint( &where );
mouseLocationY = *((float*)raw); raw += sizeof(float); // view's coordinate system session->ReadInt32( &modifiers );
modifiers = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &buttons );
buttons = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &noOfClicks );
noOfClicks = *((int32*)raw);
where.Set( mouseLocationX, mouseLocationY );
msg->what = B_MOUSE_DOWN; msg->what = B_MOUSE_DOWN;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2739,43 +2748,32 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
break;} break;}
case B_MOUSE_MOVED:{ case B_MOUSE_MOVED:{
float mouseLocationX,
mouseLocationY;
int32 buttons; int32 buttons;
int32 modifiers; // added by OBOS Team int32 modifiers; // added by OBOS Team
BPoint where; BPoint where;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
mouseLocationX = *((float*)raw); raw += sizeof(float); // windows's coordinate system session->ReadPoint( &where );
mouseLocationY = *((float*)raw); raw += sizeof(float); // windows's coordinate system session->ReadInt32( &buttons );
modifiers = *((int32*)raw); raw += sizeof(int32); // added by OBOS Team session->ReadInt32( &modifiers );
buttons = *((int32*)raw);
where.Set( mouseLocationX, mouseLocationY );
msg->what = B_MOUSE_MOVED; msg->what = B_MOUSE_MOVED;
msg->AddInt64("when", when); msg->AddInt64("when", when);
msg->AddPoint("where", where); msg->AddPoint("where", where);
msg->AddInt32("buttons", buttons); msg->AddInt32("buttons", buttons);
// TODO Add "modifiers" field ! msg->AddInt32("modifiers", modifiers);
break;} break;}
case B_MOUSE_UP:{ case B_MOUSE_UP:{
float mouseLocationX,
mouseLocationY;
int32 modifiers, int32 modifiers,
buttons; buttons;
BPoint where; BPoint where;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
mouseLocationX = *((float*)raw); raw += sizeof(float); // view's coordinate system session->ReadPoint( &where );
mouseLocationY = *((float*)raw); raw += sizeof(float); // view's coordinate system session->ReadInt32( &buttons );
buttons = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &modifiers );
modifiers = *((int32*)raw);
where.Set( mouseLocationX, mouseLocationY );
msg->what = B_MOUSE_UP; msg->what = B_MOUSE_UP;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2789,9 +2787,9 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
float whellChangeX, float whellChangeX,
whellChangeY; whellChangeY;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
whellChangeX = *((float*)raw); raw += sizeof(float); session->ReadFloat( &whellChangeX );
whellChangeY = *((float*)raw); session->ReadFloat( &whellChangeY );
msg->what = B_MOUSE_WHEEL_CHANGED; msg->what = B_MOUSE_WHEEL_CHANGED;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2801,21 +2799,12 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
break;} break;}
case B_SCREEN_CHANGED:{ case B_SCREEN_CHANGED:{
float top,
left,
right,
bottom;
int32 colorSpace; int32 colorSpace;
BRect frame; BRect frame;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
left = *((float*)raw); raw += sizeof(float); session->ReadRect( &frame );
top = *((float*)raw); raw += sizeof(float); session->ReadInt32( &colorSpace );
right = *((float*)raw); raw += sizeof(float);
bottom = *((float*)raw); raw += sizeof(float);
colorSpace = *((int32*)raw);
frame.Set( left, top, right, bottom );
msg->what = B_SCREEN_CHANGED; msg->what = B_SCREEN_CHANGED;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2824,84 +2813,11 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
break;} break;}
case B_VIEW_MOVED:{
float xAxisNewOrigin,
yAxisNewOrigin;
BPoint where;
int32 token;
when = *((int64*)raw); raw += sizeof(int64);
token = *((int32*)raw); raw += sizeof(int32);
xAxisNewOrigin = *((float*)raw); raw += sizeof(float);
yAxisNewOrigin = *((float*)raw);
where.Set( xAxisNewOrigin, yAxisNewOrigin );
msg->what = B_VIEW_MOVED;
msg->AddInt64("when", when);
msg->AddPoint("where", where);
_set_message_target_( msg, token, false);
break;}
case B_VIEW_RESIZED:{
int32 newWidth,
newHeight;
float xAxisNewOrigin,
yAxisNewOrigin;
BPoint where;
int32 token;
when = *((int64*)raw); raw += sizeof(int64);
token = *((int32*)raw); raw += sizeof(int32);
newWidth = *((int32*)raw); raw += sizeof(int32);
newHeight = *((int32*)raw); raw += sizeof(int32);
xAxisNewOrigin = *((float*)raw); raw += sizeof(float);
yAxisNewOrigin = *((float*)raw);
where.Set( xAxisNewOrigin, yAxisNewOrigin );
msg->what = B_VIEW_RESIZED;
msg->AddInt64("when", when);
msg->AddInt32("width", newWidth);
msg->AddInt32("height", newHeight);
msg->AddPoint("where", where);
_set_message_target_( msg, token, false);
break;}
case _UPDATE_:{
int32 token;
float left, top,
right, bottom;
BRect frame;
token = *((int32*)raw); raw += sizeof(int32);
left = *((float*)raw); raw += sizeof(float);
top = *((float*)raw); raw += sizeof(float);
right = *((float*)raw); raw += sizeof(float);
bottom = *((float*)raw);
frame.Set( left, top, right, bottom );
msg->what = _UPDATE_;
msg->AddInt32("token", token);
msg->AddRect("frame", frame);
break;}
case B_WINDOW_MOVED:{ case B_WINDOW_MOVED:{
float xAxisNewOrigin,
yAxisNewOrigin;
BPoint where; BPoint where;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
xAxisNewOrigin = *((float*)raw); raw += sizeof(float); session->ReadPoint( &where );
yAxisNewOrigin = *((float*)raw);
where.Set( xAxisNewOrigin, yAxisNewOrigin );
msg->what = B_WINDOW_MOVED; msg->what = B_WINDOW_MOVED;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2913,10 +2829,10 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
int32 newWidth, int32 newWidth,
newHeight; newHeight;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
newWidth = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &newWidth );
newHeight = *((int32*)raw); session->ReadInt32( &newHeight );
msg->what = B_WINDOW_RESIZED; msg->what = B_WINDOW_RESIZED;
msg->AddInt64("when", when); msg->AddInt64("when", when);
msg->AddInt32("width", newWidth); msg->AddInt32("width", newWidth);
@@ -2928,9 +2844,9 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
int32 newWorkSpace, int32 newWorkSpace,
oldWorkSpace; oldWorkSpace;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
oldWorkSpace = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &newWorkSpace );
newWorkSpace = *((int32*)raw); session->ReadInt32( &oldWorkSpace );
msg->what = B_WORKSPACES_CHANGED; msg->what = B_WORKSPACES_CHANGED;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2943,9 +2859,9 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
int32 workSpace; int32 workSpace;
bool active; bool active;
when = *((int64*)raw); raw += sizeof(int64); session->ReadInt64( &when );
workSpace = *((int32*)raw); raw += sizeof(int32); session->ReadInt32( &workSpace );
active = *((bool*)raw); session->ReadBool( &active );
msg->what = B_WORKSPACE_ACTIVATED; msg->what = B_WORKSPACE_ACTIVATED;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2956,7 +2872,7 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
case B_ZOOM:{ case B_ZOOM:{
when = *((int64*)raw); session->ReadInt64( &when );
msg->what = B_ZOOM; msg->what = B_ZOOM;
msg->AddInt64("when", when); msg->AddInt64("when", when);
@@ -2964,10 +2880,13 @@ BMessage* BWindow::ConvertToMessage(void* raw1, int32 code){
break;} break;}
default:{ default:{
// there is no need for default, but, just in case... delete msg;
printf("There is a message from app_server that I don't undersand: '%c%c%c%c'\n",
(char)((code & 0xFF000000) >> 24), (char)((code & 0x00FF0000) >> 16), msg = BLooper::ConvertToMessage( raw1, code );
(char)((code & 0x0000FF00) >> 8), (char)(code & 0x000000FF) ); if (!msg)
printf("***PANIC: app_server message NOT understood: '%c%c%c%c'***\n",
(char)((code & 0xFF000000) >> 24), (char)((code & 0x00FF0000) >> 16),
(char)((code & 0x0000FF00) >> 8), (char)(code & 0x000000FF) );
} }
} }
@@ -3368,15 +3287,15 @@ TODO list:
*) take care of temporarely events mask!!! *) take care of temporarely events mask!!!
*) what's with this flag B_ASYNCHRONOUS_CONTROLS ? *) what's with this flag B_ASYNCHRONOUS_CONTROLS ?
*) what should I do if frame rect is invalid?
*) AddInt32("ccc", (uint32));
*) test arguments for SetWindowAligment *) test arguments for SetWindowAligment
*) call hook functions: MenusBeginning, MenusEnded. Add menu activation code. *) call hook functions: MenusBeginning, MenusEnded. Add menu activation code.
* add handlers for B_VIEW_MOVED/RESIZED in DispatchMessage()
* modify _UPDATE_ handler in DispatchMessage()
*/ */
/* /*
@log @log
* made fLastViewToken member equal with top_view's token. This avoids an unnecessary message to be sent to app_server. *modified ReadRawFromPort() and ConvertToMessage() methods to use BSession class.
* added some debugging code? *modified/added B_VIEW_(MOVED/RESIZED) handlers in ConvertToMessage()/DispatchMessage()
*/ */