From 3ceb31b96aefa3601ccc51e415da557b00155d4f Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Fri, 30 Jul 2004 15:15:27 +0000 Subject: [PATCH] Pahtz's changes from PortLink/BSession/PortMessage/PortQueue to BPortLink git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8519 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/app/AppServerLink.cpp | 31 +- src/kits/app/Application.cpp | 92 +- src/kits/app/Cursor.cpp | 13 +- src/kits/app/Message.cpp | 8 +- src/kits/app/PortLink.cpp | 757 ++++++- src/kits/app/app.src | 3 - src/kits/interface/Alert.cpp | 17 +- src/kits/interface/Bitmap.cpp | 41 +- src/kits/interface/Button.cpp | 22 +- src/kits/interface/ClientFontList.cpp | 111 +- src/kits/interface/Control.cpp | 23 +- src/kits/interface/Font.cpp | 23 +- src/kits/interface/InterfaceDefs.cpp | 86 +- src/kits/interface/Picture.cpp | 61 +- src/kits/interface/View.cpp | 2888 ++++++++++++++----------- src/kits/interface/Window.cpp | 1987 +++++++++-------- 16 files changed, 3683 insertions(+), 2480 deletions(-) diff --git a/src/kits/app/AppServerLink.cpp b/src/kits/app/AppServerLink.cpp index 6346147603..a1f220e301 100644 --- a/src/kits/app/AppServerLink.cpp +++ b/src/kits/app/AppServerLink.cpp @@ -44,11 +44,16 @@ namespace BPrivate { BAppServerLink::BAppServerLink(void) - : PortLink(0L) + : BPortLink() { - be_app->Lock(); + if (be_app) + { + be_app->Lock(); + SetSendPort(be_app->fServerTo); + } receiver=create_port(100,"AppServerLink reply port"); - SetPort(be_app->fServerFrom); + SetReplyPort(receiver); + } //------------------------------------------------------------------------------ @@ -56,7 +61,25 @@ BAppServerLink::BAppServerLink(void) BAppServerLink::~BAppServerLink() { delete_port(receiver); - be_app->Unlock(); + if (be_app) + be_app->Unlock(); +} + +//------------------------------------------------------------------------------ + +status_t BAppServerLink::FlushWithReply(int32 *code) +{ + status_t err; + + err = Attach(receiver); + if (err < B_OK) + return err; + + err = Flush(); + if (err < B_OK) + return err; + + return GetNextReply(code); } } // namespace BPrivate diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp index f53f723f89..3eb92cd24c 100644 --- a/src/kits/app/Application.cpp +++ b/src/kits/app/Application.cpp @@ -56,9 +56,7 @@ #include #include #include -#include - -#include "PrivateScreen.h" +#include // Local Includes -------------------------------------------------------------- @@ -172,9 +170,6 @@ property_info gApplicationPropInfo[] = extern const int __libc_argc; extern const char * const *__libc_argv; -// TODO: We have a more or less complete BMenuWindow class in Menu.cpp. -// If this file needs to include its interface, we'd better move it to -// some private header. class BMenuWindow : public BWindow { }; @@ -186,7 +181,7 @@ class BMenuWindow : public BWindow #define OUT printf enum { - NOT_IMPLEMENTED = B_ERROR, + NOT_IMPLEMENTED = B_ERROR }; // prototypes of helper functions @@ -228,7 +223,8 @@ BApplication::BApplication(const char* signature, status_t* error) //------------------------------------------------------------------------------ BApplication::~BApplication() { - // tell all loopers(usualy windows) to quit. Also, wait for them. + // tell all loopers(usually windows) to quit. Also, wait for them. + // TODO: As Axel suggested, this functionality should probably be moved // to quit_all_windows(), and that function should be called from both // here and QuitRequested(). @@ -255,13 +251,14 @@ BApplication::~BApplication() // unregister from the roster BRoster::Private().RemoveApp(Team()); - // tell app_server we're quiting... - PortLink link(fServerFrom); - link.SetOpCode(B_QUIT_REQUESTED); + // tell app_server we're quitting... + BPortLink link(fServerFrom); + link.StartMessage(B_QUIT_REQUESTED); link.Flush(); // uninitialize be_app and be_app_messenger be_app = NULL; + // R5 doesn't uninitialize be_app_messenger. //be_app_messenger = BMessenger(); } @@ -422,38 +419,37 @@ BHandler* BApplication::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier, int32 form, const char* property) { - return NULL; // TODO: implement + return NULL; // TODO: implement? not implemented? } //------------------------------------------------------------------------------ void BApplication::ShowCursor() { - // Because we're just sending an opcode, we can skip the BSession and fake the protocol - int32 foo=AS_SHOW_CURSOR; - write_port(fServerTo,AS_SHOW_CURSOR,&foo,sizeof(int32)); + BPrivate::BAppServerLink link; + link.StartMessage(AS_SHOW_CURSOR); + link.Flush(); } //------------------------------------------------------------------------------ void BApplication::HideCursor() { - // Because we're just sending an opcode, we can skip the BSession and fake the protocol - int32 foo=AS_HIDE_CURSOR; - write_port(fServerTo,AS_HIDE_CURSOR,&foo,sizeof(int32)); + BPrivate::BAppServerLink link; + link.StartMessage(AS_HIDE_CURSOR); + link.Flush(); } //------------------------------------------------------------------------------ void BApplication::ObscureCursor() { - // Because we're just sending an opcode, we can skip the BSession and fake the protocol - int32 foo=AS_OBSCURE_CURSOR; - write_port(fServerTo,AS_OBSCURE_CURSOR,&foo,sizeof(int32)); + BPrivate::BAppServerLink link; + link.StartMessage(AS_OBSCURE_CURSOR); + link.Flush(); } //------------------------------------------------------------------------------ bool BApplication::IsCursorHidden() const { - PortMessage msg; - BPrivate::BAppServerLink link; - link.SetOpCode(AS_QUERY_CURSOR_HIDDEN); - link.FlushWithReply(&msg); - return (msg.Code()==SERVER_TRUE)?true:false; + int32 code = SERVER_FALSE; + link.StartMessage(AS_QUERY_CURSOR_HIDDEN); + link.FlushWithReply(&code); + return (code==SERVER_TRUE)?true:false; } //------------------------------------------------------------------------------ void BApplication::SetCursor(const void* cursor) @@ -468,13 +464,13 @@ void BApplication::SetCursor(const void* cursor) void BApplication::SetCursor(const BCursor* cursor, bool sync) { BPrivate::BAppServerLink link; - PortMessage msg; + int32 code=SERVER_FALSE; - link.SetOpCode(AS_SET_CURSOR_BCURSOR); + link.StartMessage(AS_SET_CURSOR_BCURSOR); link.Attach(sync); link.Attach(cursor->m_serverToken); if(sync) - link.FlushWithReply(&msg); + link.FlushWithReply(&code); else link.Flush(); } @@ -728,7 +724,7 @@ void BApplication::_ReservedApplication8() //------------------------------------------------------------------------------ bool BApplication::ScriptReceived(BMessage* msg, int32 index, BMessage* specifier, int32 form, const char* property) { - return false; // TODO: Implement + return false; // TODO: Implement? Not implemented? } //------------------------------------------------------------------------------ void BApplication::run_task() @@ -835,6 +831,9 @@ void BApplication::InitData(const char* signature, status_t* error) // Do that even, if we are B_ARGV_ONLY. // TODO: When BLooper::AddMessage() is done, use that instead of // PostMessage(). + + DBG(OUT("info: BApplication sucessfully registered.\n")); + if (__libc_argc > 1) { BMessage argvMessage(B_ARGV_RECEIVED); do_argv(&argvMessage); @@ -896,7 +895,7 @@ void BApplication::InitData(const char* signature, status_t* error) void BApplication::BeginRectTracking(BRect r, bool trackWhole) { BPrivate::BAppServerLink link; - link.Attach(AS_BEGIN_RECT_TRACKING); + link.StartMessage(AS_BEGIN_RECT_TRACKING); link.Attach(r); link.Attach(trackWhole); link.Flush(); @@ -904,8 +903,9 @@ void BApplication::BeginRectTracking(BRect r, bool trackWhole) //------------------------------------------------------------------------------ void BApplication::EndRectTracking() { - int32 foo=AS_END_RECT_TRACKING; - write_port(fServerTo,AS_END_RECT_TRACKING,&foo,sizeof(int32)); + BPrivate::BAppServerLink link; + link.StartMessage(AS_END_RECT_TRACKING); + link.Flush(); } //------------------------------------------------------------------------------ void BApplication::get_scs() @@ -915,7 +915,12 @@ void BApplication::get_scs() //------------------------------------------------------------------------------ void BApplication::setup_server_heaps() { - // TODO: implement + // TODO: implement? + + // We may not need to implement this function or the XX_offs_to_ptr functions. + // R5 sets up a couple of areas for various tasks having to do with the + // app_server. Currently (7/29/04), the R1 app_server does not do this and + // may never do this unless a significant need is found for it. --DW } //------------------------------------------------------------------------------ void* BApplication::rw_offs_to_ptr(uint32 offset) @@ -940,6 +945,9 @@ void BApplication::connect_to_app_server() // Create the port so that the app_server knows where to send messages fServerTo = create_port(100, "a= 0) { + + //We can't use BAppServerLink because be_app == NULL + // AS_CREATE_APP: // Attach data: @@ -948,21 +956,23 @@ void BApplication::connect_to_app_server() // 3) team_id - team identification field // 4) int32 - handler ID token of the app // 5) char * - signature of the regular app - PortLink link(fServerFrom); - PortMessage pmsg; + BPortLink link(fServerFrom); + int32 code=SERVER_FALSE; - link.SetOpCode(AS_CREATE_APP); + link.StartMessage(AS_CREATE_APP); link.Attach(fServerTo); link.Attach(_get_looper_port_(this)); link.Attach(Team()); link.Attach(_get_object_token_(this)); link.AttachString(fAppName); - link.FlushWithReply(&pmsg); + link.Flush(); + link.GetNextReply(&code); // Reply code: AS_CREATE_APP // Reply data: // 1) port_id server-side application port (fServerFrom value) - pmsg.Read(&fServerFrom); + if(code==AS_CREATE_APP) + link.Read(&fServerFrom); } else fInitError = fServerTo; @@ -987,7 +997,7 @@ void BApplication::write_drag(_BSession_* session, BMessage* a_message) //------------------------------------------------------------------------------ bool BApplication::quit_all_windows(bool force) { - return false; // TODO: implement + return false; // TODO: implement? } //------------------------------------------------------------------------------ bool BApplication::window_quit_loop(bool, bool) @@ -1087,7 +1097,7 @@ status_t BApplication::get_window_list(BList* list, bool incl_menus) const //------------------------------------------------------------------------------ int32 BApplication::async_quit_entry(void* data) { - return 0; // TODO: implement ? + return 0; // TODO: implement? not implemented? } //------------------------------------------------------------------------------ diff --git a/src/kits/app/Cursor.cpp b/src/kits/app/Cursor.cpp index 1d87d6501f..18b31d0cd1 100644 --- a/src/kits/app/Cursor.cpp +++ b/src/kits/app/Cursor.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include // Project Includes ------------------------------------------------------------ @@ -60,13 +59,13 @@ BCursor::BCursor(const void *cursorData) // Send data directly to server BPrivate::BAppServerLink serverlink; - PortMessage msg; + int32 code=SERVER_FALSE; - serverlink.SetOpCode(AS_CREATE_BCURSOR); + serverlink.StartMessage(AS_CREATE_BCURSOR); serverlink.Attach(cursorData, 68); - serverlink.FlushWithReply(&msg); - - msg.Read(&m_serverToken); + serverlink.FlushWithReply(&code); + if(code==SERVER_TRUE) + serverlink.Read(&m_serverToken); } @@ -82,7 +81,7 @@ BCursor::~BCursor() { // Notify server to deallocate server-side objects for this cursor BPrivate::BAppServerLink serverlink; - serverlink.SetOpCode(AS_DELETE_BCURSOR); + serverlink.StartMessage(AS_DELETE_BCURSOR); serverlink.Attach(m_serverToken); serverlink.Flush(); } diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp index ab7ac29225..c60d3f54a9 100644 --- a/src/kits/app/Message.cpp +++ b/src/kits/app/Message.cpp @@ -118,11 +118,11 @@ int _init_message_() int _delete_message_() { delete_port(BMessage::sReplyPorts[0]); - BMessage::sReplyPorts[0] = NULL; + BMessage::sReplyPorts[0] = -1; delete_port(BMessage::sReplyPorts[1]); - BMessage::sReplyPorts[1] = NULL; + BMessage::sReplyPorts[1] = -1; delete_port(BMessage::sReplyPorts[2]); - BMessage::sReplyPorts[2] = NULL; + BMessage::sReplyPorts[2] = -1; return 0; } } // extern "C" @@ -698,7 +698,7 @@ status_t BMessage::Unflatten(BDataIO* stream) } // Add each data field to the message - uint32 itemSize; + uint32 itemSize=0; if (flags & MSG_FLAG_FIXED_SIZE) { itemSize = dataLen / count; diff --git a/src/kits/app/PortLink.cpp b/src/kits/app/PortLink.cpp index 854f5caae6..f8610e4dbf 100644 --- a/src/kits/app/PortLink.cpp +++ b/src/kits/app/PortLink.cpp @@ -20,146 +20,709 @@ // DEALINGS IN THE SOFTWARE. // // File Name: PortLink.cpp -// Author: DarkWyrm -// Description: Class for low-overhead packet-style port-based messaging +// Author: Pahtz +// Description: Class for low-overhead port-based messaging // //------------------------------------------------------------------------------ #include +#include +#include #include #include "PortLink.h" -#include "PortMessage.h" -PortLink::PortLink(port_id port) +#define DEBUG_BPORTLINK +#ifdef DEBUG_BPORTLINK +# include +# define STRACE(x) printf x + const char *strcode(int32 code); +#else +# define STRACE(x) ; +#endif + +//set Initial==Max for a fixed buffer size +static const int32 kInitialSendBufferSize = 2048; +static const int32 kMaxSendBufferSize = 2048; +static const int32 kInitialReceiveBufferSize = 2048; +static const int32 kMaxReceiveBufferSize = 2048; +//make the max receive buffer at least as large as max send + +static const int32 kHeaderSize = sizeof(int32) * 3; //size + code + flags + +BPortLink::BPortLink(port_id send, port_id receive) : + fSendPort(send), fReceivePort(receive), fSendBuffer(NULL), fRecvBuffer(NULL), + fSendPosition(0), fRecvPosition(0), fSendStart(0), fRecvStart(0), + fSendBufferSize(0), fRecvBufferSize(0), fSendCount(0), fDataSize(0), + fReplySize(0), fWriteError(B_OK), fReadError(B_OK) { - port_info pi; - fPortValid = (get_port_info(port, &pi)==B_OK)? true: false; - - fSendPort = port; - fReceivePort = create_port(30,"PortLink reply port"); - - fSendCode = 0; - fSendBuffer = new char[SESSION_BUFFER_SIZE * 4]; - fSendPosition = 8; - fDataSize = (int32*)(fSendBuffer+sizeof(int32)); - *fDataSize = 0; + /* */ } -PortLink::PortLink( const PortLink &link ) +BPortLink::~BPortLink() { - fPortValid = link.fPortValid; + if (fSendBuffer) + free(fSendBuffer); + if (fRecvBuffer) + free(fRecvBuffer); +} - fSendPort = link.fSendPort; - fReceivePort = create_port(30,"PortLink reply port"); +status_t BPortLink::StartMessage(int32 code) +{ + if (EndMessage() < B_OK) //end previous message + CancelMessage(); //abandon previous message + + if (fSendBufferSize == 0) + { + fSendBuffer = (char *)malloc(kInitialSendBufferSize); + if (fSendBuffer == NULL) + { + fWriteError = B_NO_MEMORY; + return B_NO_MEMORY; + } + fSendBufferSize = kInitialSendBufferSize; + } + + status_t err; + //must have space for at least size + code + flags + if (fSendBufferSize - fSendPosition < kHeaderSize) + { + err = Flush(); //will set fSendPosition and fSendStart to 0 + if (err < B_OK) + return err; + } + + int32 *p = (int32 *)(fSendBuffer + fSendStart); //start of current message + *p = 0; //size + *(++p) = code; //code + *(++p) = 0; //flags + fSendPosition += kHeaderSize; //size + code + flags - fSendCode = 0; - fSendBuffer = new char[SESSION_BUFFER_SIZE * 4]; - fSendPosition = 8; - fDataSize = (int32*)(fSendBuffer+sizeof(int32)); - *fDataSize = 0; + STRACE(("info: BPortLink buffered header %s [%ld %ld %ld].\n", strcode(code), (int32)0, *(p-1), *p)); + + return B_OK; } -PortLink::~PortLink(void) +status_t BPortLink::EndMessage() { - delete [] fSendBuffer; -} + if (fSendPosition == fSendStart || fWriteError < B_OK) + return fWriteError; -void PortLink::SetOpCode( int32 code ) -{ - fSendCode=code; - int32 *cast=(int32*)fSendBuffer; - *cast=code; -} + int32 *p = (int32 *)(fSendBuffer + fSendStart); //start of the message + *p = fSendPosition - fSendStart; //record the size of the message + fSendCount++; //increase the number of completed messages -void PortLink::SetPort( port_id port ) -{ - port_info pi; + fSendStart = fSendPosition; //start of next new message + return B_OK; + STRACE(("info: BPortLink EndMessage() of size %ld.\n", *p)); +} + +void BPortLink::CancelMessage() +{ + fSendPosition = fSendStart; + fWriteError = B_OK; +} + +status_t BPortLink::Attach(const void *data, ssize_t size) +{ + if (fWriteError < B_OK) + return fWriteError; + + if (size <= 0) + { + fWriteError = B_BAD_VALUE; + return B_BAD_VALUE; + } + + if (fSendPosition == fSendStart) + return B_NO_INIT; //need to call StartMessage() first + + int32 remaining = fSendBufferSize - fSendPosition; + if (remaining < size) //we have to make space for the data + { + int32 total = size + (fSendPosition - fSendStart); + //resulting size of current message + + int32 newbuffersize; + if (total <= fSendBufferSize) + newbuffersize = fSendBufferSize; //no change + else if (total > kMaxSendBufferSize) + { + fWriteError = B_BAD_VALUE; + return B_BAD_VALUE; + } + else if (total <= kInitialSendBufferSize) + newbuffersize = kInitialSendBufferSize; + else + newbuffersize = (total + B_PAGE_SIZE) - (total % B_PAGE_SIZE); + + //FlushCompleted() to make space + status_t err; + err = FlushCompleted(newbuffersize); + if (err < B_OK) + { + fWriteError = err; + return err; + } + } + + memcpy(fSendBuffer + fSendPosition, data, size); + fSendPosition += size; + return fWriteError; +} + +status_t BPortLink::FlushCompleted(ssize_t newbuffersize) +{ + char *buffer = NULL; + if (newbuffersize == fSendBufferSize) + buffer = fSendBuffer; //keep existing buffer + else + { + //create new larger buffer + buffer = (char *)malloc(newbuffersize); + if (buffer == NULL) + return B_NO_MEMORY; + } + + int32 position = fSendPosition; + int32 start = fSendStart; + fSendPosition = fSendStart; //trick to hide the incomplete message + + status_t err; + err = Flush(); + if (err < B_OK) + { + fSendPosition = position; + if (buffer != fSendBuffer) + free(buffer); + return err; + } + + //move the incomplete message to the start of the buffer + fSendPosition = min_c(position - start, newbuffersize); + memcpy(buffer, fSendBuffer + start, fSendPosition); + + if (fSendBuffer != buffer) + { + free(fSendBuffer); + fSendBuffer = buffer; + fSendBufferSize = newbuffersize; + } + + return B_OK; +} + + +void BPortLink::SetSendPort( port_id port ) +{ fSendPort=port; - fPortValid=(get_port_info(port, &pi) == B_OK)? true: false; } -port_id PortLink::GetPort() +port_id BPortLink::GetSendPort() { return fSendPort; } -status_t PortLink::Flush(bigtime_t timeout) +void BPortLink::SetReplyPort( port_id port ) { - status_t write_stat; - - if(!fPortValid) - return B_BAD_VALUE; - - if(timeout!=B_INFINITE_TIMEOUT) - write_stat=write_port_etc(fSendPort, AS_SERVER_PORTLINK, fSendBuffer, - fSendPosition, B_TIMEOUT, timeout); - else - write_stat=write_port(fSendPort, AS_SERVER_PORTLINK, fSendBuffer, fSendPosition); - - fSendPosition=8; - *fDataSize=0; - - return write_stat; + fReceivePort=port; } -status_t PortLink::FlushWithReply( PortMessage *msg,bigtime_t timeout ) +port_id BPortLink::GetReplyPort() { - if(!fPortValid || !msg) - return B_BAD_VALUE; - - // attach our reply port_id at the end - Attach(fReceivePort); - - // Flush the thing....FOOSH! :P - write_port(fSendPort, AS_SERVER_PORTLINK, fSendBuffer, fSendPosition); - fSendPosition = 8; - *fDataSize=0; - - // Now we wait for the reply - msg->ReadFromPort(fReceivePort,timeout); - - return B_OK; + return fReceivePort; } -// Deprecated compatibility hack added to allow PortLink to send messages in a fashion -// like BSession. This was because originally there were differences in how they sent -// messages across ports. This is no longer the case, so this call should never need to be -// made. It remains only until current calls to it can be removed. -status_t PortLink::FlushToSession() +status_t BPortLink::Flush(bigtime_t timeout) { - BSession ses(0, fSendPort); - ses.CopyToSendBuffer(fSendBuffer, fSendPosition - 8); - ses.Sync(); - return B_OK; -} + if (fWriteError < B_OK) + return fWriteError; -status_t PortLink::Attach(const void *data, size_t size) -{ - if (!data || size <= 0) - return B_ERROR; - - if (SESSION_BUFFER_SIZE - fSendPosition > (int32)size) + EndMessage(); + if (fSendCount == 0) + return B_OK; + + STRACE(("info: BPortLink Flush() waiting to send %ld messages of %ld bytes on port %ld.\n", fSendCount, fSendPosition, fSendPort)); + + //TODO: we only need AS_SERVER_PORTLINK when all OBOS uses BPortLink + int32 protocol = (fSendCount > 1 ? AS_SERVER_SESSION : AS_SERVER_PORTLINK); + + status_t err; + if(timeout != B_INFINITE_TIMEOUT) { - memcpy(fSendBuffer + fSendPosition, data, size); - fSendPosition += size; - *fDataSize+=size; + do { + err = write_port_etc(fSendPort, protocol, fSendBuffer, + fSendPosition, B_RELATIVE_TIMEOUT, timeout); + } while(err == B_INTERRUPTED); + } + else + { + do { + err = write_port(fSendPort, protocol, fSendBuffer, fSendPosition); + } while(err == B_INTERRUPTED); + } + + if (err == B_OK) + { + STRACE(("info: BPortLink Flush() %ld messages total of %ld bytes on port %ld.\n", fSendCount, fSendPosition, fSendPort)); + fSendPosition = 0; + fSendStart = 0; + fSendCount = 0; return B_OK; } - return B_NO_MEMORY; + + STRACE(("error info: BPortLink Flush() failed for %ld bytes (%s) on port %ld.\n", fSendPosition, strerror(err), fSendPort)); + return err; } -status_t PortLink::AttachString(const char *string) +status_t BPortLink::GetNextReply(int32 *code, bigtime_t timeout) { - int16 len = (int16)strlen(string)+1; + int32 remaining; - Attach(len); - return Attach(string, len); + fReadError = B_OK; + + remaining = fDataSize - (fRecvStart + fReplySize); + STRACE(("info: BPortLink GetNextReply() reports %ld bytes remaining in buffer.\n", remaining)); + + //find the position of the next message header in the buffer + int32 *header; + if (remaining <= 0) + { + status_t err = ReadFromPort(timeout); + if (err < B_OK) + return err; + remaining = fDataSize; + header = (int32 *)fRecvBuffer; + } + else + { + fRecvStart += fReplySize; //start of the next message + fRecvPosition = fRecvStart; + header = (int32 *)(fRecvBuffer + fRecvStart); + } + + //check we have a well-formed message + if (remaining < kHeaderSize) + //we don't have enough data for a complete header + { + STRACE(("error info: BPortLink remaining %ld bytes is less than header size.\n", remaining)); + ResetReplyBuffer(); + return B_ERROR; + } + + fReplySize = *header; //size of the first message + if (fReplySize > remaining || fReplySize < kHeaderSize) + //the header info declares more data than we have OR + //the header info declares less data than kHeaderSize + { + STRACE(("error info: BPortLink message size of %ld bytes smaller than header size.\n", fReplySize)); + ResetReplyBuffer(); + return B_ERROR; + } + + *code = *(++header); + fRecvPosition += kHeaderSize; //size + code + flags + + STRACE(("info: BPortLink got header %s [%ld %ld %ld] from port %ld.\n", strcode(*code), fReplySize, *code, *(header + 1), fReceivePort)); + + return B_OK; } -void PortLink::MakeEmpty() +void BPortLink::ResetReplyBuffer() { - fSendPosition=8; - *fDataSize=0; + fRecvPosition = 0; + fRecvStart = 0; + fDataSize = 0; + fReplySize = 0; } +status_t BPortLink::AdjustReplyBuffer(bigtime_t timeout) +{ + //Here we take advantage of the compiler's dead-code elimination + if (kInitialReceiveBufferSize == kMaxReceiveBufferSize) //fixed buffer size + { + if (fRecvBuffer != NULL) + return B_OK; + + fRecvBuffer = (char *)malloc(kInitialReceiveBufferSize); + if (fRecvBuffer == NULL) + return B_NO_MEMORY; + fRecvBufferSize = kInitialReceiveBufferSize; + } + else //if (kInitialReceiveBufferSize < kMaxReceiveBufferSize) + { + STRACE(("info: BPortLink getting port_buffer_size().\n")); + ssize_t buffersize; + if (timeout == B_INFINITE_TIMEOUT) + buffersize = port_buffer_size(fReceivePort); + else + buffersize = port_buffer_size_etc(fReceivePort, B_TIMEOUT, timeout); + STRACE(("info: BPortLink got port_buffer_size() = %ld.\n", buffersize)); + + if (buffersize < 0) + return (status_t)buffersize; + + //make sure our receive buffer is large enough + if (buffersize > fRecvBufferSize) + { + if (buffersize <= kInitialReceiveBufferSize) + buffersize = kInitialReceiveBufferSize; + else + buffersize = (buffersize + B_PAGE_SIZE) - (buffersize % B_PAGE_SIZE); + if (buffersize > kMaxReceiveBufferSize) + return B_ERROR; //we can't continue + + STRACE(("info: BPortLink setting receive buffersize to %ld.\n", buffersize)); + char *buffer = (char *)malloc(buffersize); + if (buffer == NULL) + return B_NO_MEMORY; + if (fRecvBuffer) + free(fRecvBuffer); + fRecvBuffer = buffer; + fRecvBufferSize = buffersize; + } + } + + return B_OK; +} + +status_t BPortLink::ReadFromPort(bigtime_t timeout) +{ + //we are here so it means we finished reading the buffer contents + ResetReplyBuffer(); + + status_t err = AdjustReplyBuffer(timeout); + if (err < B_OK) + return err; + + int32 protocol; + ssize_t bytesread; + STRACE(("info: BPortLink reading port %ld.\n", fReceivePort)); + if (timeout != B_INFINITE_TIMEOUT) + { + do { + bytesread = read_port_etc(fReceivePort, &protocol, fRecvBuffer, + fRecvBufferSize, B_TIMEOUT, timeout); + } while(bytesread == B_INTERRUPTED); + } + else + { + do { + bytesread = read_port(fReceivePort, &protocol, fRecvBuffer, + fRecvBufferSize); + } while(bytesread == B_INTERRUPTED); + } + + STRACE(("info: BPortLink read %ld bytes.\n", bytesread)); + if (bytesread < B_OK) + return bytesread; + + //TODO: we only need AS_SERVER_PORTLINK when all OBOS uses BPortLink + if (protocol != AS_SERVER_PORTLINK && protocol != AS_SERVER_SESSION) + return B_ERROR; + if (protocol == AS_SERVER_PORTLINK && bytesread != *((int32 *)fRecvBuffer)) + //should only be one message for PORTLINK so the size declared in the header + //(the first int32 in the header) should be the same as bytesread + return B_ERROR; + + fDataSize = bytesread; + return B_OK; +} + +status_t BPortLink::Read(void *data, ssize_t size) +{ +// STRACE(("info: BPortLink Read()ing %ld bytes...\n", size)); + if (fReadError < B_OK) + return fReadError; + + if (size < 1) + { + fReadError = B_BAD_VALUE; + return B_BAD_VALUE; + } + + if (fDataSize == 0 || fReplySize == 0) + return B_NO_INIT; //need to call GetNextReply() first + + if (fRecvPosition + size > fRecvStart + fReplySize) + { + //reading past the end of current message + fReadError = B_BAD_VALUE; + return B_BAD_VALUE; + } + + memcpy(data, fRecvBuffer + fRecvPosition, size); + fRecvPosition += size; + return fReadError; +} + +status_t BPortLink::ReadString(char **string) +{ + status_t err; + int32 len = 0; + + err = Read(&len); + if (err < B_OK) + return err; + + if (len) + { + *string = (char *)malloc(len); + if (*string == NULL) + { + fRecvPosition -= sizeof(int32); //rewind the transaction + return B_NO_MEMORY; + } + + err = Read(*string, len); + if (err < B_OK) + { + free(*string); + *string = NULL; + fRecvPosition -= sizeof(int32); //rewind the transaction + return err; + } + (*string)[len-1] = '\0'; + return B_OK; + } + else + { + fRecvPosition -= sizeof(int32); //rewind the transaction + return B_ERROR; + } +} + +status_t BPortLink::AttachString(const char *string) +{ + status_t err; + if (string == NULL) + return B_BAD_VALUE; + + int32 len = strlen(string)+1; + err = Attach(len); + if (err < B_OK) + return err; + + err = Attach(string, len); + if (err < B_OK) + fSendPosition -= sizeof(int32); //rewind the transaction + + return err; +} + +#ifdef DEBUG_BPORTLINK +#include + +static const char *kASCodeNames[] = +{ +"SERVER_TRUE", +"SERVER_FALSE", +"AS_SERVER_BMESSAGE", +"AS_SERVER_AREALINK", +"AS_SERVER_SESSION", +"AS_SERVER_PORTLINK", +"AS_CLIENT_DEAD", +"AS_CREATE_APP", +"AS_DELETE_APP", +"AS_QUIT_APP", +"AS_SET_SERVER_PORT", +"AS_CREATE_WINDOW", +"AS_DELETE_WINDOW", +"AS_CREATE_BITMAP", +"AS_DELETE_BITMAP", +"AS_SET_CURSOR_DATA", +"AS_SET_CURSOR_BCURSOR", +"AS_SET_CURSOR_BBITMAP", +"AS_SET_CURSOR_SYSTEM", +"AS_SET_SYSCURSOR_DATA", +"AS_SET_SYSCURSOR_BCURSOR", +"AS_SET_SYSCURSOR_BBITMAP", +"AS_SET_SYSCURSOR_DEFAULTS", +"AS_GET_SYSCURSOR", +"AS_SHOW_CURSOR", +"AS_HIDE_CURSOR", +"AS_OBSCURE_CURSOR", +"AS_QUERY_CURSOR_HIDDEN", +"AS_CREATE_BCURSOR", +"AS_DELETE_BCURSOR", +"AS_BEGIN_RECT_TRACKING", +"AS_END_RECT_TRACKING", +"AS_SHOW_WINDOW", +"AS_HIDE_WINDOW", +"AS_QUIT_WINDOW", +"AS_SEND_BEHIND", +"AS_SET_LOOK", +"AS_SET_FEEL", +"AS_SET_FLAGS", +"AS_DISABLE_UPDATES", +"AS_ENABLE_UPDATES", +"AS_BEGIN_UPDATE", +"AS_END_UPDATE", +"AS_NEEDS_UPDATE", +"AS_WINDOW_TITLE", +"AS_ADD_TO_SUBSET", +"AS_REM_FROM_SUBSET", +"AS_SET_ALIGNMENT", +"AS_GET_ALIGNMENT", +"AS_GET_WORKSPACES", +"AS_SET_WORKSPACES", +"AS_WINDOW_RESIZE", +"AS_WINDOW_MOVE", +"AS_SET_SIZE_LIMITS", +"AS_ACTIVATE_WINDOW", +"AS_WINDOW_MINIMIZE", +"AS_UPDATE_IF_NEEDED", +"_ALL_UPDATED_", +"AS_CREATE_PICTURE", +"AS_DELETE_PICTURE", +"AS_CLONE_PICTURE", +"AS_DOWNLOAD_PICTURE", +"AS_QUERY_FONTS_CHANGED", +"AS_UPDATED_CLIENT_FONTLIST", +"AS_GET_FAMILY_ID", +"AS_GET_STYLE_ID", +"AS_GET_STYLE_FOR_FACE", +"AS_GET_SCREEN_MODE", +"AS_SET_UI_COLORS", +"AS_GET_UI_COLORS", +"AS_GET_UI_COLOR", +"AS_SET_DECORATOR", +"AS_GET_DECORATOR", +"AS_R5_SET_DECORATOR", +"AS_COUNT_WORKSPACES", +"AS_SET_WORKSPACE_COUNT", +"AS_CURRENT_WORKSPACE", +"AS_ACTIVATE_WORKSPACE", +"AS_SET_SCREEN_MODE", +"AS_GET_SCROLLBAR_INFO", +"AS_SET_SCROLLBAR_INFO", +"AS_IDLE_TIME", +"AS_SELECT_PRINTER_PANEL", +"AS_ADD_PRINTER_PANEL", +"AS_RUN_BE_ABOUT", +"AS_SET_FOCUS_FOLLOWS_MOUSE", +"AS_FOCUS_FOLLOWS_MOUSE", +"AS_SET_MOUSE_MODE", +"AS_GET_MOUSE_MODE", +"AS_WORKSPACE_ACTIVATED", +"AS_WORKSPACES_CHANGED", +"AS_WINDOW_ACTIVATED", +"AS_SCREENMODE_CHANGED", +"AS_BEGIN_TRANSACTION", +"AS_END_TRANSACTION", +"AS_SET_HIGH_COLOR", +"AS_SET_LOW_COLOR", +"AS_SET_VIEW_COLOR", +"AS_STROKE_ARC", +"AS_STROKE_BEZIER", +"AS_STROKE_ELLIPSE", +"AS_STROKE_LINE", +"AS_STROKE_LINEARRAY", +"AS_STROKE_POLYGON", +"AS_STROKE_RECT", +"AS_STROKE_ROUNDRECT", +"AS_STROKE_SHAPE", +"AS_STROKE_TRIANGLE", +"AS_FILL_ARC", +"AS_FILL_BEZIER", +"AS_FILL_ELLIPSE", +"AS_FILL_POLYGON", +"AS_FILL_RECT", +"AS_FILL_REGION", +"AS_FILL_ROUNDRECT", +"AS_FILL_SHAPE", +"AS_FILL_TRIANGLE", +"AS_MOVEPENBY", +"AS_MOVEPENTO", +"AS_SETPENSIZE", +"AS_DRAW_STRING", +"AS_SET_FONT", +"AS_SET_FONT_SIZE", +"AS_FLUSH", +"AS_SYNC", +"AS_LAYER_CREATE", +"AS_LAYER_DELETE", +"AS_LAYER_CREATE_ROOT", +"AS_LAYER_DELETE_ROOT", +"AS_LAYER_ADD_CHILD", +"AS_LAYER_REMOVE_CHILD", +"AS_LAYER_REMOVE_SELF", +"AS_LAYER_SHOW", +"AS_LAYER_HIDE", +"AS_LAYER_MOVE", +"AS_LAYER_RESIZE", +"AS_LAYER_INVALIDATE", +"AS_LAYER_DRAW", +"AS_LAYER_GET_TOKEN", +"AS_LAYER_ADD", +"AS_LAYER_REMOVE", +"AS_LAYER_GET_COORD", +"AS_LAYER_SET_FLAGS", +"AS_LAYER_SET_ORIGIN", +"AS_LAYER_GET_ORIGIN", +"AS_LAYER_RESIZE_MODE", +"AS_LAYER_CURSOR", +"AS_LAYER_BEGIN_RECT_TRACK", +"AS_LAYER_END_RECT_TRACK", +"AS_LAYER_DRAG_RECT", +"AS_LAYER_DRAG_IMAGE", +"AS_LAYER_GET_MOUSE_COORDS", +"AS_LAYER_SCROLL", +"AS_LAYER_SET_LINE_MODE", +"AS_LAYER_GET_LINE_MODE", +"AS_LAYER_PUSH_STATE", +"AS_LAYER_POP_STATE", +"AS_LAYER_SET_SCALE", +"AS_LAYER_GET_SCALE", +"AS_LAYER_SET_DRAW_MODE", +"AS_LAYER_GET_DRAW_MODE", +"AS_LAYER_SET_BLEND_MODE", +"AS_LAYER_GET_BLEND_MODE", +"AS_LAYER_SET_PEN_LOC", +"AS_LAYER_GET_PEN_LOC", +"AS_LAYER_SET_PEN_SIZE", +"AS_LAYER_GET_PEN_SIZE", +"AS_LAYER_SET_HIGH_COLOR", +"AS_LAYER_SET_LOW_COLOR", +"AS_LAYER_SET_VIEW_COLOR", +"AS_LAYER_GET_COLORS", +"AS_LAYER_PRINT_ALIASING", +"AS_LAYER_CLIP_TO_PICTURE", +"AS_LAYER_CLIP_TO_INVERSE_PICTURE", +"AS_LAYER_GET_CLIP_REGION", +"AS_LAYER_DRAW_BITMAP_ASYNC_IN_RECT", +"AS_LAYER_DRAW_BITMAP_ASYNC_AT_POINT", +"AS_LAYER_DRAW_BITMAP_SYNC_IN_RECT", +"AS_LAYER_DRAW_BITMAP_SYNC_AT_POINT", +"AS_LAYER_DRAW_STRING", +"AS_LAYER_SET_CLIP_REGION", +"AS_LAYER_LINE_ARRAY", +"AS_LAYER_BEGIN_PICTURE", +"AS_LAYER_APPEND_TO_PICTURE", +"AS_LAYER_END_PICTURE", +"AS_LAYER_COPY_BITS", +"AS_LAYER_DRAW_PICTURE", +"AS_LAYER_INVAL_RECT", +"AS_LAYER_INVAL_REGION", +"AS_LAYER_INVERT_RECT", +"AS_LAYER_MOVETO", +"AS_LAYER_RESIZETO", +"AS_LAYER_SET_STATE", +"AS_LAYER_SET_FONT_STATE", +"AS_LAYER_GET_STATE", +"AS_LAYER_SET_VIEW_IMAGE", +"AS_LAYER_SET_PATTERN", +"AS_SET_CURRENT_LAYER", +}; + +const char *strcode(int32 code) +{ + code = code - SERVER_TRUE; + if (code >= 0 && code <= AS_SET_CURRENT_LAYER - SERVER_TRUE) + return kASCodeNames[code]; + else + return "Unknown"; +} +#endif //DEBUG_BPORTLINK + + diff --git a/src/kits/app/app.src b/src/kits/app/app.src index 685af9e3a3..69f7b54db2 100644 --- a/src/kits/app/app.src +++ b/src/kits/app/app.src @@ -22,13 +22,10 @@ APP_KIT_SOURCE = MessageUtils.cpp PropertyInfo.cpp PortLink.cpp - PortMessage.cpp - PortQueue.cpp RegistrarDefs.cpp RegistrarThread.cpp RegistrarThreadManager.cpp Roster.cpp RosterPrivate.cpp - Session.cpp TokenSpace.cpp ; diff --git a/src/kits/interface/Alert.cpp b/src/kits/interface/Alert.cpp index e7633555c2..62ad9d2bec 100644 --- a/src/kits/interface/Alert.cpp +++ b/src/kits/interface/Alert.cpp @@ -416,14 +416,9 @@ BPoint BAlert::AlertPosition(float width, float height) dynamic_cast(BLooper::LooperForThread(find_thread(NULL))); BScreen Screen(Window); - if (!Screen.IsValid()) - { - // We should never be here because a BScreen object will return - // a valid screen. - debugger("Couldn't find the screen!"); - } - - BRect screenRect = Screen.Frame(); + BRect screenRect(0, 0, 640, 480); + if (Screen.IsValid()) + screenRect = Screen.Frame(); // Horizontally, we're smack in the middle result.x = (screenRect.Width() / 2.0) - (width / 2.0); @@ -474,7 +469,6 @@ void BAlert::InitObject(const char* text, const char* button0, // Set up the "_master_" view TAlertView* MasterView = new TAlertView(Bounds()); MasterView->SetBitmap(InitIcon()); - AddChild(MasterView); // Set up the buttons int buttonCount = 0; @@ -621,6 +615,9 @@ void BAlert::InitObject(const char* text, const char* button0, fTextView = new BTextView(TextViewRect, "_tv_", TextViewRect, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); + AddChild(MasterView); + MasterView->AddChild(fTextView); + fTextView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fTextView->SetText(text, strlen(text)); fTextView->MakeEditable(false); @@ -636,8 +633,6 @@ void BAlert::InitObject(const char* text, const char* button0, TextViewRect.bottom += textHeight; fTextView->SetTextRect(TextViewRect); - MasterView->AddChild(fTextView); - AddCommonFilter(new _BAlertFilter_(this)); MoveTo(AlertPosition(Frame().Width(), Frame().Height())); diff --git a/src/kits/interface/Bitmap.cpp b/src/kits/interface/Bitmap.cpp index 2d14e048d9..a8f182ca7f 100644 --- a/src/kits/interface/Bitmap.cpp +++ b/src/kits/interface/Bitmap.cpp @@ -39,11 +39,10 @@ // Includes to be able to talk to the app_server #include #include -#include #include enum { - NOT_IMPLEMENTED = B_ERROR, + NOT_IMPLEMENTED = B_ERROR }; // TODO: system palette -- hard-coded for now, when the app server is ready @@ -2140,7 +2139,7 @@ BBitmap::get_shared_pointer() const int32 BBitmap::get_server_token() const { - return -1; // not implemented + return fServerToken; } // InitObject @@ -2159,8 +2158,7 @@ BBitmap::InitObject(BRect bounds, color_space colorSpace, uint32 flags, { status_t error = B_OK; - PortMessage pmsg; - BPrivate::BAppServerLink *link=new BPrivate::BAppServerLink(); + BPrivate::BAppServerLink link; // clean up if (fBasePtr) { @@ -2176,10 +2174,11 @@ BBitmap::InitObject(BRect bounds, color_space colorSpace, uint32 flags, // Reply Data: // none // status_t freestat; - link->SetOpCode(AS_DELETE_BITMAP); - link->Attach(fServerToken); - error=link->FlushWithReply(&pmsg); - if(pmsg.Code()==SERVER_FALSE) + int32 code = SERVER_FALSE; + link.StartMessage(AS_DELETE_BITMAP); + link.Attach(fServerToken); + error=link.FlushWithReply(&code); + if(code==SERVER_FALSE) error=B_NO_MEMORY; fBasePtr=NULL; fArea=-1; @@ -2208,12 +2207,12 @@ BBitmap::InitObject(BRect bounds, color_space colorSpace, uint32 flags, // 3) int32 bitmap_flags // 4) int32 bytes_per_row // 5) int32 screen_id::id - link->SetOpCode(AS_CREATE_BITMAP); - link->Attach(bounds); - link->Attach(&colorSpace, sizeof(color_space)); - link->Attach((int32)flags); - link->Attach(bytesPerRow); - link->Attach(screenID.id); + link.StartMessage(AS_CREATE_BITMAP); + link.Attach(bounds); + link.Attach(colorSpace); + link.Attach((int32)flags); + link.Attach(bytesPerRow); + link.Attach(screenID.id); // Reply Code: SERVER_TRUE // Reply Data: @@ -2225,21 +2224,22 @@ BBitmap::InitObject(BRect bounds, color_space colorSpace, uint32 flags, // Reply Code: SERVER_FALSE // Reply Data: // None - error=link->FlushWithReply(&pmsg); + int32 code = SERVER_FALSE; + error=link.FlushWithReply(&code); // We shouldn't ever have to execute this block, but just in case... if(error!=B_OK) fBasePtr=NULL; - if(pmsg.Code()==SERVER_TRUE) + if(code==SERVER_TRUE) { // Get token area_id bmparea; int32 areaoffset; - pmsg.Read(&fServerToken); - pmsg.Read(&bmparea); - pmsg.Read(&areaoffset); + link.Read(&fServerToken); + link.Read(&bmparea); + link.Read(&areaoffset); // Get the area in which the data resides fArea=clone_area("shared bitmap area",(void**)&fBasePtr,B_ANY_ADDRESS, @@ -2266,7 +2266,6 @@ BBitmap::InitObject(BRect bounds, color_space colorSpace, uint32 flags, fToken = -1; fOrigArea = -1; } - delete link; fInitError = error; } diff --git a/src/kits/interface/Button.cpp b/src/kits/interface/Button.cpp index 809c083849..a86b4c0cf4 100644 --- a/src/kits/interface/Button.cpp +++ b/src/kits/interface/Button.cpp @@ -42,7 +42,7 @@ //------------------------------------------------------------------------------ BButton::BButton(BRect frame, const char *name, const char *label, BMessage *message, uint32 resizingMode, uint32 flags) - : BControl(frame, name, label, message, resizingMode, flags), + : BControl(frame, name, label, message, resizingMode, flags |= B_WILL_DRAW), fDrawAsDefault(false) { // Resize to minimum height if needed @@ -95,7 +95,7 @@ void BButton::Draw(BRect updateRect) // If the focus is changing, just redraw the focus indicator if (IsFocusChanging()) { - float x = bounds.right / 2 - StringWidth(Label()) / 2.0f; + float x = (bounds.right - StringWidth(Label())) / 2.0f; float y = bounds.bottom - fh.descent - (IsDefault() ? 6.0f : 3.0f); if (IsFocus()) @@ -185,7 +185,7 @@ void BButton::Draw(BRect updateRect) } // Label - float x = bounds.right / 2 - StringWidth(Label()) / 2.0f; + float x = (bounds.right - StringWidth(Label())) / 2.0f; float y = bounds.bottom - fh.descent - (IsDefault() ? 8.0f : 5.0f); if (Value()) @@ -260,7 +260,7 @@ void BButton::Draw(BRect updateRect) FillRect(rect); // Label - float x = bounds.right / 2 - StringWidth(Label()) / 2.0f; + float x = (bounds.right - StringWidth(Label())) / 2.0f; float y = bounds.bottom - fh.descent - 5.0f; SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT)); @@ -278,16 +278,23 @@ void BButton::MouseDown(BPoint point) if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) { + SetTracking(true); + SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); + } + else + { BRect bounds = Bounds(); uint32 buttons; do { + Window()->UpdateIfNeeded(); + snooze(40000); GetMouse(&point, &buttons, true); - bool inside = bounds.Contains(point); + bool inside = bounds.Contains(ConvertFromScreen(point)); if ((Value() == B_CONTROL_ON) != inside) SetValue(inside ? B_CONTROL_ON : B_CONTROL_OFF); @@ -296,11 +303,6 @@ void BButton::MouseDown(BPoint point) if (Value() == B_CONTROL_ON) Invoke(); } - else - { - SetTracking(true); - SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); - } } //------------------------------------------------------------------------------ void BButton::AttachedToWindow() diff --git a/src/kits/interface/ClientFontList.cpp b/src/kits/interface/ClientFontList.cpp index fc827e13e2..f38f4435fd 100644 --- a/src/kits/interface/ClientFontList.cpp +++ b/src/kits/interface/ClientFontList.cpp @@ -34,11 +34,15 @@ #include #include -#include #include #include //#define DEBUG_CLIENT_FONT_LIST +#ifdef DEBUG_CLIENT_FONT_LIST +# define STRACE(x) printf x +#else +# define STRACE(x) ; +#endif class FontListFamily { @@ -70,18 +74,15 @@ FontListFamily::~FontListFamily(void) ClientFontList::ClientFontList(void) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("ClientFontList()\n"); -#endif + STRACE(("ClientFontList()\n")); familylist=new BList(0); fontlock=create_sem(1,"fontlist_sem"); } ClientFontList::~ClientFontList(void) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("~ClientFontList()\n"); -#endif + STRACE(("~ClientFontList()\n")); + acquire_sem(fontlock); font_family *fam; @@ -97,9 +98,8 @@ printf("~ClientFontList()\n"); bool ClientFontList::Update(bool check_only) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("ClientFontList::Update(%s) - %s\n", (check_only)?"true":"false",SERVER_FONT_LIST); -#endif + STRACE(("ClientFontList::Update(%s) - %s\n", (check_only)?"true":"false",SERVER_FONT_LIST)); + // Open the font list kept in font list acquire_sem(fontlock); @@ -108,29 +108,27 @@ printf("ClientFontList::Update(%s) - %s\n", (check_only)?"true":"false",SERVER_F serverport=find_port(SERVER_PORT_NAME); bool needs_update=true; - PortLink *serverlink=new PortLink(serverport); + BPortLink serverlink(serverport); if(serverport!=B_NAME_NOT_FOUND) { - PortMessage pmsg; - serverlink->SetOpCode(AS_QUERY_FONTS_CHANGED); - serverlink->FlushWithReply(&pmsg); + int32 code=SERVER_FALSE; + serverlink.StartMessage(AS_QUERY_FONTS_CHANGED); + serverlink.Flush(); + serverlink.GetNextReply(&code); // Attached Data: none // Reply: SERVER_TRUE if fonts have changed, SERVER_FALSE if not - needs_update=(pmsg.Code()==SERVER_TRUE)?true:false; + needs_update=(code==SERVER_TRUE)?true:false; } -#ifdef DEBUG_CLIENT_FONT_LIST else { - printf("ClientFontList::Update(): Couldn't find app_server port\n"); + STRACE(("ClientFontList::Update(): Couldn't find app_server port\n")); } -#endif if(check_only) { - delete serverlink; release_sem(fontlock); return needs_update; } @@ -145,10 +143,11 @@ printf("ClientFontList::Update(%s) - %s\n", (check_only)?"true":"false",SERVER_F { if(fontmsg.Unflatten(&file)==B_OK) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("Font message contents:\n"); -fontmsg.PrintToStream(); -#endif + #ifdef DEBUG_CLIENT_FONT_LIST + printf("Font message contents:\n"); + fontmsg.PrintToStream(); + #endif + // Empty the font list FontListFamily *flf=(FontListFamily*)familylist->RemoveItem(0L); BString sty, extra; @@ -157,15 +156,11 @@ fontmsg.PrintToStream(); while(flf) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("Removing %s from list\n",flf->name.String()); -#endif + STRACE(("Removing %s from list\n",flf->name.String())); delete flf; flf=(FontListFamily*)familylist->RemoveItem(0L); } -#ifdef DEBUG_CLIENT_FONT_LIST -printf("\n"); -#endif + STRACE(("\n")); famindex=0; @@ -178,44 +173,35 @@ printf("\n"); familylist->AddItem(flf); familymsg.FindString("name",&(flf->name)); -#ifdef DEBUG_CLIENT_FONT_LIST -printf("Adding %s to list\n",flf->name.String()); -#endif + STRACE(("Adding %s to list\n",flf->name.String())); styindex=0; // populate family with styles while(familymsg.FindString("styles",styindex,&sty)==B_OK) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("\tAdding %s\n",sty.String()); -#endif + STRACE(("\tAdding %s\n",sty.String())); styindex++; flf->styles->AddItem(new BString(sty)); } if(familymsg.FindBool("tuned",&tempbool)==B_OK) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("Family %s has tuned fonts\n", flf->name.String()); -#endif + STRACE(("Family %s has tuned fonts\n", flf->name.String())); flf->flags|=B_HAS_TUNED_FONT; } if(familymsg.FindBool("fixed",&tempbool)==B_OK) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("Family %s is fixed-width\n", flf->name.String()); -#endif + STRACE(("Family %s is fixed-width\n", flf->name.String())); flf->flags|=B_IS_FIXED; } familymsg.MakeEmpty(); } - serverlink->SetOpCode(AS_UPDATED_CLIENT_FONTLIST); - serverlink->Flush(); + serverlink.StartMessage(AS_UPDATED_CLIENT_FONTLIST); + serverlink.Flush(); - delete serverlink; release_sem(fontlock); return false; @@ -223,16 +209,13 @@ printf("Family %s is fixed-width\n", flf->name.String()); } // end if InitCheck==B_OK } // end if needs_update - delete serverlink; release_sem(fontlock); return false; } int32 ClientFontList::CountFamilies(void) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("ClientFontList::CountFamilies\n"); -#endif +STRACE(("ClientFontList::CountFamilies\n")); acquire_sem(fontlock); int32 count=familylist->CountItems(); release_sem(fontlock); @@ -241,14 +224,10 @@ printf("ClientFontList::CountFamilies\n"); status_t ClientFontList::GetFamily(int32 index, font_family *name, uint32 *flags) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("ClientFontList::GetFamily(%ld)\n",index); -#endif + STRACE(("ClientFontList::GetFamily(%ld)\n",index)); if(!name) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("ClientFontList::GetFamily: NULL font_family parameter\n"); -#endif + STRACE(("ClientFontList::GetFamily: NULL font_family parameter\n")); return B_ERROR; } @@ -256,9 +235,7 @@ printf("ClientFontList::GetFamily: NULL font_family parameter\n"); FontListFamily *flf=(FontListFamily*)familylist->ItemAt(index); if(!flf) { -#ifdef DEBUG_CLIENT_FONT_LIST -printf("ClientFontList::GetFamily: index not found\n"); -#endif + STRACE(("ClientFontList::GetFamily: index not found\n")); return B_ERROR; } strcpy(*name,flf->name.String()); @@ -347,39 +324,29 @@ status_t ClientFontList::GetStyle(font_family family, int32 index, font_style *n style->ICompare("Plain")==0) { *face|=B_REGULAR_FACE; -#ifdef DEBUG_FONTSERVER -printf("GetStyle: %s Roman face\n", style->String()); -#endif + STRACE(("GetStyle: %s Roman face\n", style->String())); } else if(style->ICompare("Bold")==0) { *face|=B_BOLD_FACE; -#ifdef DEBUG_FONTSERVER -printf("GetStyle: %s Bold face\n"); -#endif + STRACE(("GetStyle: %s Bold face\n")); } else if(style->ICompare("Italic")==0) { *face|=B_ITALIC_FACE; -#ifdef DEBUG_FONTSERVER -printf("GetStyle: %s Italic face\n"); -#endif + STRACE(("GetStyle: %s Italic face\n")); } else if(style->ICompare("Bold Italic")==0) { *face|=B_ITALIC_FACE | B_BOLD_FACE; -#ifdef DEBUG_FONTSERVER -printf("GetStyle: %s Bold Italic face\n"); -#endif + STRACE(("GetStyle: %s Bold Italic face\n")); } else { -#ifdef DEBUG_FONTSERVER -printf("GetStyle: %s Unknown face %s\n", style->String()); -#endif + STRACE(("GetStyle: %s Unknown face %s\n", style->String())); } } diff --git a/src/kits/interface/Control.cpp b/src/kits/interface/Control.cpp index 3410d7d55a..08ff59f221 100644 --- a/src/kits/interface/Control.cpp +++ b/src/kits/interface/Control.cpp @@ -33,6 +33,7 @@ #include #include #include +#include // Project Includes ------------------------------------------------------------ @@ -180,7 +181,7 @@ void BControl::WindowActivated(bool active) BView::WindowActivated(active); if (IsFocus()) - Draw(Bounds()); + Invalidate(Bounds()); } //------------------------------------------------------------------------------ void BControl::AttachedToWindow() @@ -290,7 +291,7 @@ void BControl::MakeFocus(bool focused) if(Window()) { fFocusChanging = true; - Draw(Bounds()); + Invalidate(Bounds()); Flush(); fFocusChanging = false; } @@ -345,7 +346,7 @@ void BControl::SetLabel(const char *string) if (string) fLabel = strdup(string); else - fLabel = NULL; + fLabel = strdup(B_EMPTY_STRING); Invalidate(); } @@ -364,7 +365,7 @@ void BControl::SetValue(int32 value) if (Window()) { - Draw(Bounds()); + Invalidate(Bounds()); Flush(); } } @@ -388,7 +389,7 @@ void BControl::SetEnabled(bool enabled) if (Window()) { - Draw(Bounds()); + Invalidate(Bounds()); Flush(); } } @@ -435,8 +436,8 @@ status_t BControl::Invoke(BMessage *message) if (message) err = BInvoker::Invoke(&clone); -// TODO: assynchronous messaging -// SendNotices(kind, &clone); + // TODO: asynchronous messaging + SendNotices(kind, &clone); return err; } @@ -513,6 +514,7 @@ BControl &BControl::operator=(const BControl &) void BControl::InitData(BMessage *data) { fLabel = NULL; + SetLabel(B_EMPTY_STRING); fValue = B_CONTROL_OFF; fEnabled = true; fFocusChanging = false; @@ -523,10 +525,3 @@ void BControl::InitData(BMessage *data) SetFont(be_plain_font, B_FONT_FAMILY_AND_STYLE); } //------------------------------------------------------------------------------ - -/* - * $Log $ - * - * $Id $ - * - */ diff --git a/src/kits/interface/Font.cpp b/src/kits/interface/Font.cpp index 1efbd1c136..9dcb596525 100644 --- a/src/kits/interface/Font.cpp +++ b/src/kits/interface/Font.cpp @@ -158,17 +158,18 @@ status_t set_font_cache_info(uint32 id, void *set) // BFont Class Definition //---------------------------------------------------------------------------------------- -BFont::BFont(void) +BFont::BFont(void) + //initialise for be_plain_font (avoid circular definition) + : fFamilyID(0), fStyleID(0), fSize(10.0), fShear(0.0), fRotation(0.0), + fSpacing(0), fEncoding(0), fFace(0), fFlags(0) { + fHeight.ascent = 7.0; + fHeight.descent = 2.0; + fHeight.leading = 13.0; + fFamilyID=be_plain_font->fFamilyID; fStyleID=be_plain_font->fStyleID; fSize=be_plain_font->fSize; - fShear=be_plain_font->fShear; - fRotation=be_plain_font->fRotation; - fSpacing=be_plain_font->fSpacing; - fEncoding=be_plain_font->fEncoding; - fFace=be_plain_font->fFace; - fHeight=be_plain_font->fHeight; } BFont::BFont(const BFont &font) @@ -422,13 +423,17 @@ void BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, float BFont::StringWidth(const char *string) const { // TODO: implement - return 0.0; + + // an estimate + return (fHeight.ascent - fHeight.descent) * strlen(string); } float BFont::StringWidth(const char *string, int32 length) const { // TODO: implement - return 0.0; + + // an estimate + return (fHeight.ascent - fHeight.descent) * length; } void BFont::GetStringWidths(const char *stringArray[], const int32 lengthArray[], diff --git a/src/kits/interface/InterfaceDefs.cpp b/src/kits/interface/InterfaceDefs.cpp index ca55a9a6f8..7a7544a2e0 100644 --- a/src/kits/interface/InterfaceDefs.cpp +++ b/src/kits/interface/InterfaceDefs.cpp @@ -41,10 +41,9 @@ #include // Private definitions not placed in public headers -#include - extern "C" void _init_global_fonts(); extern "C" status_t _fini_interface_kit_(); +extern status_t _control_input_server_(BMessage *command, BMessage *reply); using namespace BPrivate; @@ -61,14 +60,15 @@ _IMPEXP_BE status_t set_screen_space(int32 index, uint32 res, bool stick) { BAppServerLink link; - link.SetOpCode(AS_SET_SCREEN_MODE); + int32 code = SERVER_FALSE; + + link.StartMessage(AS_SET_SCREEN_MODE); link.Attach(index); link.Attach((int32)res); link.Attach(stick); - link.Flush(); + link.FlushWithReply(&code); - //TODO: Read back the status from the app_server's reply - return B_OK; + return ((code==SERVER_TRUE)?B_OK:B_ERROR); } @@ -79,15 +79,14 @@ get_scroll_bar_info(scroll_bar_info *info) return B_BAD_VALUE; BAppServerLink link; - PortMessage msg; - link.SetOpCode(AS_GET_SCROLLBAR_INFO); - link.FlushWithReply(&msg); - msg.Read(info); + int32 code; + link.StartMessage(AS_GET_SCROLLBAR_INFO); + link.FlushWithReply(&code); + link.Read(info); return B_OK; } - _IMPEXP_BE status_t set_scroll_bar_info(scroll_bar_info *info) { @@ -95,11 +94,11 @@ set_scroll_bar_info(scroll_bar_info *info) return B_BAD_VALUE; BAppServerLink link; - PortMessage msg; + int32 code; - link.SetOpCode(AS_SET_SCROLLBAR_INFO); + link.StartMessage(AS_SET_SCROLLBAR_INFO); link.Attach(*info); - link.FlushWithReply(&msg); + link.FlushWithReply(&code); return B_OK; } @@ -406,10 +405,10 @@ count_workspaces() int32 count; BAppServerLink link; - PortMessage msg; - link.SetOpCode(AS_COUNT_WORKSPACES); - link.FlushWithReply(&msg); - msg.Read(&count); + int32 code; + link.StartMessage(AS_COUNT_WORKSPACES); + link.FlushWithReply(&code); + link.Read(&count); return count; } @@ -418,7 +417,7 @@ _IMPEXP_BE void set_workspace_count(int32 count) { BAppServerLink link; - link.SetOpCode(AS_SET_WORKSPACE_COUNT); + link.StartMessage(AS_SET_WORKSPACE_COUNT); link.Attach(count); link.Flush(); } @@ -430,10 +429,10 @@ current_workspace() int32 index; BAppServerLink link; - PortMessage msg; - link.SetOpCode(AS_CURRENT_WORKSPACE); - link.FlushWithReply(&msg); - msg.Read(&index); + int32 code; + link.StartMessage(AS_CURRENT_WORKSPACE); + link.FlushWithReply(&code); + link.Read(&index); return index; } @@ -443,7 +442,7 @@ _IMPEXP_BE void activate_workspace(int32 workspace) { BAppServerLink link; - link.SetOpCode(AS_ACTIVATE_WORKSPACE); + link.StartMessage(AS_ACTIVATE_WORKSPACE); link.Attach(workspace); link.Flush(); } @@ -455,10 +454,10 @@ idle_time() bigtime_t idletime; BAppServerLink link; - PortMessage msg; - link.SetOpCode(AS_IDLE_TIME); - link.FlushWithReply(&msg); - msg.Read(&idletime); + int32 code; + link.StartMessage(AS_IDLE_TIME); + link.FlushWithReply(&code); + link.Read(&idletime); return idletime; } @@ -493,7 +492,7 @@ _IMPEXP_BE void set_focus_follows_mouse(bool follow) { BAppServerLink link; - link.SetOpCode(AS_SET_FOCUS_FOLLOWS_MOUSE); + link.StartMessage(AS_SET_FOCUS_FOLLOWS_MOUSE); link.Attach(follow); link.Flush(); } @@ -505,10 +504,10 @@ focus_follows_mouse() bool ffm; BAppServerLink link; - PortMessage msg; - link.SetOpCode(AS_FOCUS_FOLLOWS_MOUSE); - link.FlushWithReply(&msg); - msg.Read(&ffm); + int32 code; + link.StartMessage(AS_FOCUS_FOLLOWS_MOUSE); + link.FlushWithReply(&code); + link.Read(&ffm); return ffm; } @@ -517,7 +516,7 @@ _IMPEXP_BE void set_mouse_mode(mode_mouse mode) { BAppServerLink link; - link.SetOpCode(AS_SET_MOUSE_MODE); + link.StartMessage(AS_SET_MOUSE_MODE); link.Attach(mode); link.Flush(); } @@ -529,10 +528,10 @@ mouse_mode() mode_mouse mode; BAppServerLink link; - PortMessage msg; - link.SetOpCode(AS_GET_MOUSE_MODE); - link.FlushWithReply(&msg); - msg.Read(&mode); + int32 code; + link.StartMessage(AS_GET_MOUSE_MODE); + link.FlushWithReply(&code); + link.Read(&mode); return mode; } @@ -543,11 +542,12 @@ ui_color(color_which which) rgb_color color; BAppServerLink link; - PortMessage msg; - link.SetOpCode(AS_GET_UI_COLOR); + int32 code; + link.StartMessage(AS_GET_UI_COLOR); link.Attach(which); - link.FlushWithReply(&msg); - msg.Read(&color); + link.FlushWithReply(&code); + if(code==SERVER_TRUE) + link.Read(&color); return color; } @@ -630,7 +630,7 @@ _init_global_fonts() void __set_window_decor(int32 theme) { BAppServerLink link; - link.SetOpCode(AS_R5_SET_DECORATOR); + link.StartMessage(AS_R5_SET_DECORATOR); link.Attach(theme); link.Flush(); } diff --git a/src/kits/interface/Picture.cpp b/src/kits/interface/Picture.cpp index 5f217f083b..f7a0180cc1 100644 --- a/src/kits/interface/Picture.cpp +++ b/src/kits/interface/Picture.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include // Project Includes ------------------------------------------------------------ @@ -83,15 +82,14 @@ BPicture::BPicture(const BPicture &picture) if (picture.token != -1) { - BPrivate::BAppServerLink link; - PortMessage msg; + int32 code=SERVER_FALSE; - link.Attach(AS_CLONE_PICTURE); + link.StartMessage(AS_CLONE_PICTURE); link.Attach(picture.token); - link.FlushWithReply(&msg); - msg.Read(&token); - + link.FlushWithReply(&code); + if(code==SERVER_TRUE) + link.Read(&token); } if (picture.extent->fNewData != NULL) { @@ -160,10 +158,10 @@ BPicture::BPicture(BMessage *archive) if (extent->fNewSize != 0 && extent->fNewData != 0) { BPrivate::BAppServerLink link; - PortMessage msg; + int32 code=SERVER_FALSE; BPicture *pic; - link.Attach(AS_CREATE_PICTURE); + link.StartMessage(AS_CREATE_PICTURE); link.Attach(extent->fPictures.CountItems()); for (int32 i = 0; i < extent->fPictures.CountItems(); i++) { @@ -173,8 +171,9 @@ BPicture::BPicture(BMessage *archive) } link.Attach(extent->fNewSize); link.Attach(extent->fNewData,extent->fNewSize); - link.FlushWithReply(&msg); - msg.Read(&token); + link.FlushWithReply(&code); + if(code==SERVER_TRUE) + link.Read(&token); } } @@ -205,7 +204,7 @@ BPicture::~BPicture() { BPrivate::BAppServerLink link; - link.Attach(AS_DELETE_PICTURE); + link.StartMessage(AS_DELETE_PICTURE); link.Attach(token); link.Flush(); } @@ -341,10 +340,10 @@ status_t BPicture::Unflatten(BDataIO *stream) // swap_data(extent->fNewData, extent->fNewSize); BPrivate::BAppServerLink link; - PortMessage msg; + int32 code=SERVER_FALSE; BPicture *pic; - link.Attach(AS_CREATE_PICTURE); + link.StartMessage(AS_CREATE_PICTURE); link.Attach(extent->fPictures.CountItems()); for (int32 i = 0; i < extent->fPictures.CountItems(); i++) { @@ -354,8 +353,9 @@ status_t BPicture::Unflatten(BDataIO *stream) } link.Attach(extent->fNewSize); link.Attach(extent->fNewData, extent->fNewSize); - link.FlushWithReply(&msg); - msg.Read(&token); + link.FlushWithReply(&code); + if(code==SERVER_TRUE) + link.Read(&token); if (extent->fNewData) { @@ -395,9 +395,9 @@ void BPicture::import_data(const void *data, int32 size, BPicture **subs, return; BPrivate::BAppServerLink link; - PortMessage msg; + int32 code=SERVER_FALSE; - link.Attach(AS_CREATE_PICTURE); + link.StartMessage(AS_CREATE_PICTURE); link.Attach(subCount); for (int32 i = 0; i < subCount; i++) @@ -405,8 +405,9 @@ void BPicture::import_data(const void *data, int32 size, BPicture **subs, link.Attach(size); link.Attach(data, size); - link.FlushWithReply(&msg); - msg.Read(&token); + link.FlushWithReply(&code); + if(code==SERVER_TRUE) + link.Read(&token); } //------------------------------------------------------------------------------ void BPicture::import_old_data(const void *data, int32 size) @@ -421,12 +422,13 @@ void BPicture::import_old_data(const void *data, int32 size) convert_old_to_new(data, size, &extent->fNewData, &extent->fNewSize); BPrivate::BAppServerLink link; - link.Attach(AS_CREATE_PICTURE); + link.StartMessage(AS_CREATE_PICTURE); link.Attach(0L); link.Attach(extent->fNewSize); link.Attach(extent->fNewData,extent->fNewSize); - link.FlushWithReply(&msg); - msg.Read(&token) + link.FlushWithReply(&code); + if(code==SERVER_TRUE) + link.Read(&token) // Do we free all data now? free(extent->fNewData); @@ -453,9 +455,9 @@ bool BPicture::assert_local_copy() /* BPrivate::BAppServerLink link; int32 count; - link.Attach(AS_DOWNLOAD_PICTURE); + link.StartMessage(AS_DOWNLOAD_PICTURE); link.Attach(token); - link.FlushWithReply(&msg); + link.FlushWithReply(&code); count=*((int32*)replydata.buffer); // Read sub picture tokens @@ -501,14 +503,15 @@ bool BPicture::assert_server_copy() extent->fPictures.ItemAt(i)->assert_server_copy(); BPrivate::BAppServerLink link; - link.Attach(AS_CREATE_PICTURE); + link.StartMessage(AS_CREATE_PICTURE); link.Attach(extent->fPictures.CountItems()); for (int32 i = 0; i < extent->fPictures.CountItems(); i++) link.Attach(extent->fPictures.ItemAt(i)->token); link.Attach(extent->fNewSize); link.Attach(extent->fNewData,extent->fNewSize); - link.FlushWithReply(&msg); - msg.Read(&token); + link.FlushWithReply(&code); + if(code==SERVER_TRUE) + link.Read(&token); return token != -1;*/ return true; @@ -548,7 +551,7 @@ void BPicture::usurp(BPicture *lameDuck) { BPrivate::BAppServerLink link; - link.Attach(AS_DELETE_PICTURE); + link.StartMessage(AS_DELETE_PICTURE); link.Attach(token); link.Flush(); } diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 9c23d86bde..05ad0cc8b7 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -50,16 +50,18 @@ #include #include #include +#include +#include +#include // Project Includes ------------------------------------------------------------ #include #include #include #include -#include #include #include -#include +#include #include // Local Includes -------------------------------------------------------------- @@ -245,7 +247,8 @@ BView::BView(BMessage *archive) //--------------------------------------------------------------------------- -BArchivable* BView::Instantiate(BMessage* data){ +BArchivable* BView::Instantiate(BMessage* data) +{ if ( !validate_instantiation( data , "BView" ) ) return NULL; return new BView(data); @@ -253,7 +256,8 @@ BArchivable* BView::Instantiate(BMessage* data){ //--------------------------------------------------------------------------- -status_t BView::Archive(BMessage* data, bool deep) const{ +status_t BView::Archive(BMessage* data, bool deep) const +{ status_t retval; retval = BHandler::Archive( data, deep ); @@ -295,12 +299,12 @@ status_t BView::Archive(BMessage* data, bool deep) const{ data->AddInt32("_color", _get_uint32_color(LowColor()) ); data->AddInt32("_color", _get_uint32_color(ViewColor()) ); } -/* -NOTE: we do not use this flag any more - if ( 1 ){ - data->AddInt32("_dbuf", 1); - } -*/ + +// NOTE: we do not use this flag any more +// if ( 1 ){ +// data->AddInt32("_dbuf", 1); +// } + if ( fState->archivingFlags & B_VIEW_ORIGIN_BIT ) data->AddPoint("_origin", Origin()); @@ -310,13 +314,15 @@ NOTE: we do not use this flag any more if ( fState->archivingFlags & B_VIEW_PEN_LOC_BIT ) data->AddPoint("_ploc", PenLocation()); - if ( fState->archivingFlags & B_VIEW_LINE_MODES_BIT ){ + if ( fState->archivingFlags & B_VIEW_LINE_MODES_BIT ) + { data->AddInt16("_lmcapjoin", (int16)LineCapMode()); data->AddInt16("_lmcapjoin", (int16)LineJoinMode()); data->AddFloat("_lmmiter", LineMiterLimit()); } - if ( fState->archivingFlags & B_VIEW_BLENDING_BIT ){ + if ( fState->archivingFlags & B_VIEW_BLENDING_BIT ) + { source_alpha alphaSrcMode; alpha_function alphaFncMode; GetBlendingMode( &alphaSrcMode, &alphaFncMode); @@ -328,49 +334,52 @@ NOTE: we do not use this flag any more if ( fState->archivingFlags & B_VIEW_DRAW_MODE_BIT ) data->AddInt32("_dmod", DrawingMode()); - if (deep){ + if (deep) + { int i = 0; BView *child = NULL; - while ( (child = ChildAt(i++)) != NULL){ + while ( (child = ChildAt(i++)) != NULL) + { BMessage childArchive; - + retval = child->Archive( &childArchive, deep ); if (retval == B_OK) data->AddMessage( "_views", &childArchive ); } } - + return retval; } //--------------------------------------------------------------------------- -BView::~BView(){ +BView::~BView() +{ STRACE(("BView(%s)::~BView()\n", this->Name())); if (owner) debugger("Trying to delete a view that belongs to a window. Call RemoveSelf first."); removeSelf(); -// TODO: see about BShelf! must I delete it here? is it deleted by the window? - - // we also delete all its childern + // TODO: see about BShelf! must I delete it here? is it deleted by the window? + + // we also delete all its childern BView *child, *_child; child = first_child; - while(child){ + while(child) + { _child = child; child = child->next_sibling; deleteView( _child ); } - - if (fVerScroller){ + + if (fVerScroller) fVerScroller->SetTarget( (const char*)NULL ); - } - if (fHorScroller){ + + if (fHorScroller) fHorScroller->SetTarget( (const char*)NULL ); - } SetName( NULL ); @@ -379,26 +388,33 @@ STRACE(("BView(%s)::~BView()\n", this->Name())); if (fState) delete fState; - free( pr_state ); + if(pr_state) + free( pr_state ); pr_state = NULL; } //--------------------------------------------------------------------------- -BRect BView::Bounds() const{ - // if we have the actual coordiantes +BRect BView::Bounds() const +{ + // if we have the actual coordiantes if (fState->flags & B_VIEW_COORD_BIT) - if (owner){ + if (owner) + { check_lock(); - - owner->session->WriteInt32( AS_LAYER_GET_COORD ); - owner->session->Sync(); - owner->session->ReadFloat( const_cast(&originX) ); - owner->session->ReadFloat( const_cast(&originY) ); - owner->session->ReadRect( const_cast(&fBounds) ); - - fState->flags &= ~B_VIEW_COORD_BIT; + owner->fLink->StartMessage( AS_LAYER_GET_COORD ); + owner->fLink->Flush(); + + int32 rCode=SERVER_FALSE; + owner->fLink->GetNextReply(&rCode); + if(rCode==SERVER_TRUE) + { + owner->fLink->Read( const_cast(&originX) ); + owner->fLink->Read( const_cast(&originY) ); + owner->fLink->Read( const_cast(&fBounds) ); + fState->flags &= ~B_VIEW_COORD_BIT; + } } return fBounds; @@ -406,7 +422,8 @@ BRect BView::Bounds() const{ //--------------------------------------------------------------------------- -void BView::ConvertToParent(BPoint* pt) const{ +void BView::ConvertToParent(BPoint* pt) const +{ if (!parent) return; @@ -418,7 +435,8 @@ void BView::ConvertToParent(BPoint* pt) const{ //--------------------------------------------------------------------------- -BPoint BView::ConvertToParent(BPoint pt) const{ +BPoint BView::ConvertToParent(BPoint pt) const +{ if (!parent) return pt; @@ -433,7 +451,8 @@ BPoint BView::ConvertToParent(BPoint pt) const{ //--------------------------------------------------------------------------- -void BView::ConvertFromParent(BPoint* pt) const{ +void BView::ConvertFromParent(BPoint* pt) const +{ if (!parent) return; @@ -445,7 +464,8 @@ void BView::ConvertFromParent(BPoint* pt) const{ //--------------------------------------------------------------------------- -BPoint BView::ConvertFromParent(BPoint pt) const{ +BPoint BView::ConvertFromParent(BPoint pt) const +{ if (!parent) return pt; @@ -460,7 +480,8 @@ BPoint BView::ConvertFromParent(BPoint pt) const{ //--------------------------------------------------------------------------- -void BView::ConvertToParent(BRect* r) const{ +void BView::ConvertToParent(BRect* r) const +{ if (!parent) return; @@ -471,7 +492,8 @@ void BView::ConvertToParent(BRect* r) const{ //--------------------------------------------------------------------------- -BRect BView::ConvertToParent(BRect r) const{ +BRect BView::ConvertToParent(BRect r) const +{ if (!parent) return r; @@ -482,7 +504,8 @@ BRect BView::ConvertToParent(BRect r) const{ //--------------------------------------------------------------------------- -void BView::ConvertFromParent(BRect* r) const{ +void BView::ConvertFromParent(BRect* r) const +{ if (!parent) return; @@ -493,7 +516,8 @@ void BView::ConvertFromParent(BRect* r) const{ //--------------------------------------------------------------------------- -BRect BView::ConvertFromParent(BRect r) const{ +BRect BView::ConvertFromParent(BRect r) const +{ if (!parent) return r; @@ -506,7 +530,8 @@ BRect BView::ConvertFromParent(BRect r) const{ -void BView::ConvertToScreen(BPoint* pt) const{ +void BView::ConvertToScreen(BPoint* pt) const +{ if (!parent) return; @@ -518,7 +543,8 @@ void BView::ConvertToScreen(BPoint* pt) const{ //--------------------------------------------------------------------------- -BPoint BView::ConvertToScreen(BPoint pt) const{ +BPoint BView::ConvertToScreen(BPoint pt) const +{ if (!parent) return pt; @@ -534,9 +560,15 @@ BPoint BView::ConvertToScreen(BPoint pt) const{ //--------------------------------------------------------------------------- -void BView::ConvertFromScreen(BPoint* pt) const{ +void BView::ConvertFromScreen(BPoint* pt) const +{ if (!parent) + { + if(owner) + return owner->ConvertFromScreen(pt); + return; + } do_owner_check_no_pick(); @@ -546,10 +578,16 @@ void BView::ConvertFromScreen(BPoint* pt) const{ //--------------------------------------------------------------------------- -BPoint BView::ConvertFromScreen(BPoint pt) const{ +BPoint BView::ConvertFromScreen(BPoint pt) const +{ if (!parent) + { + if(owner) + return owner->ConvertFromScreen(pt); + return pt; - + } + do_owner_check_no_pick(); BPoint p; @@ -563,7 +601,8 @@ BPoint BView::ConvertFromScreen(BPoint pt) const{ //--------------------------------------------------------------------------- -void BView::ConvertToScreen(BRect* r) const{ +void BView::ConvertToScreen(BRect* r) const +{ if (!parent) return; @@ -575,7 +614,8 @@ void BView::ConvertToScreen(BRect* r) const{ //--------------------------------------------------------------------------- -BRect BView::ConvertToScreen(BRect r) const{ +BRect BView::ConvertToScreen(BRect r) const +{ if (!parent) return r; @@ -591,7 +631,8 @@ BRect BView::ConvertToScreen(BRect r) const{ //--------------------------------------------------------------------------- -void BView::ConvertFromScreen(BRect* r) const{ +void BView::ConvertFromScreen(BRect* r) const +{ if (!parent) return; @@ -603,7 +644,8 @@ void BView::ConvertFromScreen(BRect* r) const{ //--------------------------------------------------------------------------- -BRect BView::ConvertFromScreen(BRect r) const{ +BRect BView::ConvertFromScreen(BRect r) const +{ if (!parent) return r; @@ -619,19 +661,23 @@ BRect BView::ConvertFromScreen(BRect r) const{ //--------------------------------------------------------------------------- -uint32 BView::Flags() const { +uint32 BView::Flags() const +{ check_lock_no_pick(); return ( fFlags & ~_RESIZE_MASK_ ); } //--------------------------------------------------------------------------- -void BView::SetFlags( uint32 flags ){ +void BView::SetFlags( uint32 flags ) +{ if (Flags() == flags) return; - if (owner){ - if ( flags & B_PULSE_NEEDED ){ + if (owner) + { + if ( flags & B_PULSE_NEEDED ) + { check_lock_no_pick(); if ( !owner->fPulseEnabled ) owner->SetPulseRate( 500000 ); @@ -642,8 +688,8 @@ void BView::SetFlags( uint32 flags ){ { check_lock(); - owner->session->WriteInt32( AS_LAYER_SET_FLAGS ); - owner->session->WriteUInt32( flags ); + owner->fLink->StartMessage( AS_LAYER_SET_FLAGS ); + owner->fLink->Attach( flags ); } } @@ -661,7 +707,8 @@ void BView::SetFlags( uint32 flags ){ //--------------------------------------------------------------------------- -BRect BView::Frame() const { +BRect BView::Frame() const +{ check_lock_no_pick(); if ( fState->flags & B_VIEW_COORD_BIT ){ @@ -673,28 +720,34 @@ BRect BView::Frame() const { //--------------------------------------------------------------------------- -void BView::Hide(){ - if ( owner && fShowLevel == 0){ +void BView::Hide() +{ + if ( owner && fShowLevel == 0) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_HIDE ); + owner->fLink->StartMessage( AS_LAYER_HIDE ); } fShowLevel++; } //--------------------------------------------------------------------------- -void BView::Show(){ +void BView::Show() +{ fShowLevel--; - if (owner && fShowLevel == 0){ + if (owner && fShowLevel == 0) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_SHOW ); + owner->fLink->StartMessage( AS_LAYER_SHOW ); } } //--------------------------------------------------------------------------- -bool BView::IsFocus() const { - if (owner){ +bool BView::IsFocus() const +{ + if (owner) + { check_lock_no_pick(); return owner->CurrentFocus() == this; } @@ -717,7 +770,7 @@ BView::IsHidden(const BView *lookingFrom) const // we have the same visibility state as our // parent, if there is one if (parent) - return parent->IsHidden(); + return parent->IsHidden(lookingFrom); // if we're the top view, and we're interested // in the "global" view, we're inheriting the @@ -738,69 +791,82 @@ BView::IsHidden() const //--------------------------------------------------------------------------- -bool BView::IsPrinting() const { +bool BView::IsPrinting() const +{ return f_is_printing; } //--------------------------------------------------------------------------- -BPoint BView::LeftTop() const { +BPoint BView::LeftTop() const +{ return Bounds().LeftTop(); } //--------------------------------------------------------------------------- -void BView::SetOrigin(BPoint pt) { +void BView::SetOrigin(BPoint pt) +{ SetOrigin( pt.x, pt.y ); } //--------------------------------------------------------------------------- -void BView::SetOrigin(float x, float y) { -// TODO: maybe app_server should do a redraw? - WRITE down into specs +void BView::SetOrigin(float x, float y) +{ + // TODO: maybe app_server should do a redraw? - WRITE down into specs if ( x==originX && y==originY ) return; - if (do_owner_check()){ - owner->session->WriteInt32( AS_LAYER_SET_ORIGIN ); - owner->session->WriteFloat( x ); - owner->session->WriteFloat( y ); + if (do_owner_check()) + { + owner->fLink->StartMessage( AS_LAYER_SET_ORIGIN ); + owner->fLink->Attach( x ); + owner->fLink->Attach( y ); } - // invalidate this flag, to stay in sync with app_server + // invalidate this flag, to stay in sync with app_server fState->flags |= B_VIEW_ORIGIN_BIT; - // our local coord system origin has changed, so when archiving we'll add this too + // our local coord system origin has changed, so when archiving we'll add this too fState->archivingFlags |= B_VIEW_ORIGIN_BIT; } //--------------------------------------------------------------------------- -BPoint BView::Origin(void) const { - - if ( fState->flags & B_VIEW_ORIGIN_BIT ) { - do_owner_check(); - - owner->session->WriteInt32( AS_LAYER_GET_ORIGIN ); - owner->session->Sync(); - - owner->session->ReadPoint( &fState->coordSysOrigin ); +BPoint BView::Origin(void) const +{ + if ( fState->flags & B_VIEW_ORIGIN_BIT ) + { + do_owner_check(); + + owner->fLink->StartMessage( AS_LAYER_GET_ORIGIN ); + owner->fLink->Flush(); + + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply(&rCode); + if(rCode==SERVER_TRUE) + { + owner->fLink->Read( &fState->coordSysOrigin ); fState->flags &= ~B_VIEW_ORIGIN_BIT; + } } - + return fState->coordSysOrigin; } //--------------------------------------------------------------------------- -void BView::SetResizingMode(uint32 mode) { - if (owner){ +void BView::SetResizingMode(uint32 mode) +{ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_RESIZE_MODE ); - owner->session->WriteInt32( mode ); + owner->fLink->StartMessage( AS_LAYER_RESIZE_MODE ); + owner->fLink->Attach( mode ); } // look at SetFlags() for more info on the below line @@ -818,7 +884,8 @@ uint32 BView::ResizingMode() const { //--------------------------------------------------------------------------- -void BView::SetViewCursor(const BCursor *cursor, bool sync) { +void BView::SetViewCursor(const BCursor *cursor, bool sync) +{ if (!cursor) return; @@ -828,34 +895,39 @@ void BView::SetViewCursor(const BCursor *cursor, bool sync) { check_lock(); - if (sync){ - owner->session->WriteInt32( AS_LAYER_CURSOR ); - owner->session->WriteInt32( cursor->m_serverToken ); - owner->session->Sync(); + if (sync) + { + owner->fLink->StartMessage( AS_LAYER_CURSOR ); + owner->fLink->Attach( cursor->m_serverToken ); + owner->fLink->Flush(); } - else{ - owner->session->WriteInt32( AS_LAYER_CURSOR ); - owner->session->WriteInt32( cursor->m_serverToken ); + else + { + owner->fLink->StartMessage( AS_LAYER_CURSOR ); + owner->fLink->Attach( cursor->m_serverToken ); } } //--------------------------------------------------------------------------- -void BView::Flush(void) const { +void BView::Flush(void) const +{ if (owner) owner->Flush(); } //--------------------------------------------------------------------------- -void BView::Sync(void) const { +void BView::Sync(void) const +{ do_owner_check_no_pick(); owner->Sync(); } //--------------------------------------------------------------------------- -BWindow* BView::Window() const { +BWindow* BView::Window() const +{ return owner; } @@ -864,104 +936,122 @@ BWindow* BView::Window() const { // Hook Functions //--------------------------------------------------------------------------- -void BView::AttachedToWindow(){ +void BView::AttachedToWindow() +{ // HOOK function STRACE(("\tHOOK: BView(%s)::AttachedToWindow()\n", Name())); } //--------------------------------------------------------------------------- -void BView::AllAttached(){ +void BView::AllAttached() +{ // HOOK function STRACE(("\tHOOK: BView(%s)::AllAttached()\n", Name())); } //--------------------------------------------------------------------------- -void BView::DetachedFromWindow(){ +void BView::DetachedFromWindow() +{ // HOOK function STRACE(("\tHOOK: BView(%s)::DetachedFromWindow()\n", Name())); } //--------------------------------------------------------------------------- -void BView::AllDetached(){ +void BView::AllDetached() +{ // HOOK function STRACE(("\tHOOK: BView(%s)::AllDetached()\n", Name())); } //--------------------------------------------------------------------------- -void BView::Draw(BRect updateRect){ +void BView::Draw(BRect updateRect) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::Draw()\n", Name())); } -void BView::DrawAfterChildren(BRect r){ +void BView::DrawAfterChildren(BRect r) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::DrawAfterChildren()\n", Name())); } -void BView::FrameMoved(BPoint new_position){ +void BView::FrameMoved(BPoint new_position) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::FrameMoved()\n", Name())); } -void BView::FrameResized(float new_width, float new_height){ +void BView::FrameResized(float new_width, float new_height) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::FrameResized()\n", Name())); } -void BView::GetPreferredSize(float* width, float* height){ +void BView::GetPreferredSize(float* width, float* height) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::GetPreferredSize()\n", Name())); *width = fBounds.Width(); *height = fBounds.Height(); } -void BView::ResizeToPreferred(){ +void BView::ResizeToPreferred() +{ // HOOK function STRACE(("\tHOOK: BView(%s)::ResizeToPreferred()\n", Name())); ResizeTo(fBounds.Width(), fBounds.Height()); } -void BView::KeyDown(const char* bytes, int32 numBytes){ +void BView::KeyDown(const char* bytes, int32 numBytes) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::KeyDown()\n", Name())); } -void BView::KeyUp(const char* bytes, int32 numBytes){ +void BView::KeyUp(const char* bytes, int32 numBytes) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::KeyUp()\n", Name())); } -void BView::MouseDown(BPoint where){ +void BView::MouseDown(BPoint where) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::MouseDown()\n", Name())); } -void BView::MouseUp(BPoint where){ +void BView::MouseUp(BPoint where) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::MouseUp()\n", Name())); } -void BView::MouseMoved(BPoint where, uint32 code, const BMessage* a_message){ +void BView::MouseMoved(BPoint where, uint32 code, const BMessage* a_message) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::MouseMoved()\n", Name())); } -void BView::Pulse(){ +void BView::Pulse() +{ // HOOK function STRACE(("\tHOOK: BView(%s)::Pulse()\n", Name())); } -void BView::TargetedByScrollView(BScrollView* scroll_view){ +void BView::TargetedByScrollView(BScrollView* scroll_view) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::TargetedByScrollView()\n", Name())); } -void BView::WindowActivated(bool state){ +void BView::WindowActivated(bool state) +{ // HOOK function STRACE(("\tHOOK: BView(%s)::WindowActivated()\n", Name())); } @@ -969,28 +1059,27 @@ void BView::WindowActivated(bool state){ // Input Functions //--------------------------------------------------------------------------- -void BView::BeginRectTracking(BRect startRect, - uint32 style) +void BView::BeginRectTracking(BRect startRect, uint32 style) { - if (do_owner_check()) { - owner->session->WriteInt32( AS_LAYER_BEGIN_RECT_TRACK ); - owner->session->WriteRect( startRect ); - owner->session->WriteInt32( style ); + if (do_owner_check()) + { + owner->fLink->StartMessage( AS_LAYER_BEGIN_RECT_TRACK ); + owner->fLink->Attach( startRect ); + owner->fLink->Attach( style ); } } //--------------------------------------------------------------------------- -void BView::EndRectTracking(){ - if (do_owner_check()) { - owner->session->WriteInt32( AS_LAYER_END_RECT_TRACK ); - } +void BView::EndRectTracking() +{ + if (do_owner_check()) + owner->fLink->StartMessage( AS_LAYER_END_RECT_TRACK ); } //--------------------------------------------------------------------------- -void BView::DragMessage(BMessage* aMessage, BRect dragRect, - BHandler* reply_to) +void BView::DragMessage(BMessage* aMessage, BRect dragRect, BHandler* reply_to) { if ( !aMessage || !dragRect.IsValid()) return; @@ -1005,14 +1094,18 @@ void BView::DragMessage(BMessage* aMessage, BRect dragRect, BPoint offset; - if ( !aMessage->HasInt32("buttons") ){ + if ( !aMessage->HasInt32("buttons") ) + { BMessage *msg = owner->CurrentMessage(); uint32 buttons; - if ( msg ){ - if ( msg->FindInt32("buttons", (int32*)&buttons) == B_OK ){ + if ( msg ) + { + if ( msg->FindInt32("buttons", (int32*)&buttons) == B_OK ) + { } - else{ + else + { BPoint point; GetMouse(&point, &buttons, false); } @@ -1022,10 +1115,12 @@ void BView::DragMessage(BMessage* aMessage, BRect dragRect, offset = point - dragRect.LeftTop(); } - else{ + else + { BPoint point; GetMouse(&point, &buttons, false); } + aMessage->AddInt32("buttons", buttons); } @@ -1035,20 +1130,20 @@ void BView::DragMessage(BMessage* aMessage, BRect dragRect, char *buffer = new char[ bufSize ]; aMessage->Flatten( buffer, bufSize ); - owner->session->WriteInt32( AS_LAYER_DRAG_RECT ); - owner->session->WriteRect( dragRect ); - owner->session->WritePoint( offset ); - owner->session->WriteInt32( bufSize ); - owner->session->WriteData( buffer, bufSize ); - owner->session->Sync(); + owner->fLink->StartMessage( AS_LAYER_DRAG_RECT ); + owner->fLink->Attach( dragRect ); + owner->fLink->Attach( offset ); + owner->fLink->Attach( bufSize ); + owner->fLink->Attach( buffer, bufSize ); + owner->fLink->Flush(); - delete buffer; + delete [] buffer; } //--------------------------------------------------------------------------- void BView::DragMessage(BMessage* aMessage, BBitmap* anImage, BPoint offset, - BHandler* reply_to) + BHandler* reply_to) { DragMessage( aMessage, anImage, B_OP_COPY, offset, reply_to ); } @@ -1056,8 +1151,7 @@ void BView::DragMessage(BMessage* aMessage, BBitmap* anImage, BPoint offset, //--------------------------------------------------------------------------- void BView::DragMessage(BMessage* aMessage, BBitmap* anImage, - drawing_mode dragMode, BPoint offset, - BHandler* reply_to) + drawing_mode dragMode, BPoint offset,BHandler* reply_to) { if ( !aMessage || !anImage ) return; @@ -1070,19 +1164,24 @@ void BView::DragMessage(BMessage* aMessage, BBitmap* anImage, do_owner_check_no_pick(); - if ( !aMessage->HasInt32("buttons") ){ + if ( !aMessage->HasInt32("buttons") ) + { BMessage *msg = owner->CurrentMessage(); uint32 buttons; - if ( msg ){ - if ( msg->FindInt32("buttons", (int32*)&buttons) == B_OK ){ + if ( msg ) + { + if ( msg->FindInt32("buttons", (int32*)&buttons) == B_OK ) + { } - else{ + else + { BPoint point; GetMouse(&point, &buttons, false); } } - else{ + else + { BPoint point; GetMouse(&point, &buttons, false); } @@ -1095,28 +1194,29 @@ void BView::DragMessage(BMessage* aMessage, BBitmap* anImage, char *buffer = new char[ bufSize ]; aMessage->Flatten( buffer, bufSize ); - owner->session->WriteInt32( AS_LAYER_DRAG_IMAGE ); - owner->session->WriteInt32( anImage->get_server_token() ); - owner->session->WriteInt32( (int32)dragMode ); - owner->session->WritePoint( offset ); - owner->session->WriteInt32( bufSize ); - owner->session->WriteData( buffer, bufSize ); + owner->fLink->StartMessage( AS_LAYER_DRAG_IMAGE ); + owner->fLink->Attach( anImage->get_server_token() ); + owner->fLink->Attach( (int32)dragMode ); + owner->fLink->Attach( offset ); + owner->fLink->Attach( bufSize ); + owner->fLink->Attach( buffer, bufSize ); + + delete [] buffer; + + // TODO: in app_server the bitmap refCount must be incremented + // WRITE this into specs!!!! - delete buffer; -/* TODO: in app_server the bitmap refCount must be incremented - * WRITE this into specs!!!! - */ delete anImage; } //--------------------------------------------------------------------------- -void BView::GetMouse(BPoint* location, uint32* buttons, - bool checkMessageQueue) +void BView::GetMouse(BPoint* location, uint32* buttons, bool checkMessageQueue) { do_owner_check(); - if (checkMessageQueue) { + if (checkMessageQueue) + { BMessageQueue *mq; BMessage *msg; int32 i = 0; @@ -1124,33 +1224,38 @@ void BView::GetMouse(BPoint* location, uint32* buttons, mq = Window()->MessageQueue(); mq->Lock(); - while( (msg = mq->FindMessage(i++)) != NULL ) { - switch (msg->what) { + while( (msg = mq->FindMessage(i++)) != NULL ) + { + switch (msg->what) + { case B_MOUSE_UP: - msg->FindPoint("where", location); - msg->FindInt32("buttons", (int32*)buttons); - Window()->DispatchMessage( msg, Window() ); - mq->RemoveMessage( msg ); - delete msg; - return; + { + msg->FindPoint("where", location); + msg->FindInt32("buttons", (int32*)buttons); + Window()->DispatchMessage( msg, Window() ); + mq->RemoveMessage( msg ); + delete msg; + return; break; - + } case B_MOUSE_MOVED: - msg->FindPoint("where", location); - msg->FindInt32("buttons", (int32*)buttons); - Window()->DispatchMessage( msg, Window() ); - mq->RemoveMessage( msg ); - delete msg; - return; + { + msg->FindPoint("where", location); + msg->FindInt32("buttons", (int32*)buttons); + Window()->DispatchMessage( msg, Window() ); + mq->RemoveMessage( msg ); + delete msg; + return; break; - + } case _UPDATE_: - Window()->DispatchMessage( msg, Window() ); - mq->RemoveMessage( msg ); - delete msg; - return; + { + Window()->DispatchMessage( msg, Window() ); + mq->RemoveMessage( msg ); + delete msg; + return; break; - + } default: break; } @@ -1158,28 +1263,38 @@ void BView::GetMouse(BPoint* location, uint32* buttons, mq->Unlock(); } - // If B_MOUSE_UP or B_MOUSE_MOVED has not been found in the message queue, - // tell app_server to send us the current mouse coords and buttons. - owner->session->WriteInt32( AS_LAYER_GET_MOUSE_COORDS ); - owner->session->Sync(); + // If B_MOUSE_UP or B_MOUSE_MOVED has not been found in the message queue, + // tell app_server to send us the current mouse coords and buttons. + owner->fLink->StartMessage( AS_LAYER_GET_MOUSE_COORDS ); + owner->fLink->Flush(); - owner->session->ReadPoint( location ); - owner->session->ReadInt32( (int32*)buttons ); + int32 rCode=SERVER_FALSE; + owner->fLink->GetNextReply(&rCode); + if(rCode==SERVER_TRUE) + { + owner->fLink->Read( location ); + owner->fLink->Read( (int32*)buttons ); + } } //--------------------------------------------------------------------------- -void BView::MakeFocus(bool focusState){ - if (owner){ - // if a view is in focus +void BView::MakeFocus(bool focusState) +{ + if (owner) + { + // if a view is in focus BView *focus = owner->CurrentFocus(); - if (focus) { + if (focus) + { owner->fFocus = NULL; focus->MakeFocus(false); owner->SetPreferredHandler(NULL); } - // if we want to make this view the current focus view - if (focusState){ + + // if we want to make this view the current focus view + if (focusState) + { owner->fFocus = this; owner->SetPreferredHandler(this); } @@ -1188,14 +1303,20 @@ void BView::MakeFocus(bool focusState){ //--------------------------------------------------------------------------- -BScrollBar* BView::ScrollBar(orientation posture) const{ - switch (posture) { +BScrollBar* BView::ScrollBar(orientation posture) const +{ + switch (posture) + { case B_VERTICAL: - return fVerScroller; + { + return fVerScroller; break; + } case B_HORIZONTAL: - return fHorScroller; + { + return fHorScroller; break; + } default: return NULL; break; @@ -1204,25 +1325,28 @@ BScrollBar* BView::ScrollBar(orientation posture) const{ //--------------------------------------------------------------------------- -void BView::ScrollBy(float dh, float dv){ - // no reason to process this further if no scroll is intended. - if ( dh == 0 && dv == 0){ +void BView::ScrollBy(float dh, float dv) +{ + // no reason to process this further if no scroll is intended. + if ( dh == 0 && dv == 0) return; - } check_lock(); - // if we're attached to a window tell app_server about this change - if (owner) { - owner->session->WriteInt32( AS_LAYER_SCROLL ); - owner->session->WriteFloat( dh ); - owner->session->WriteFloat( dv ); - + + // if we're attached to a window tell app_server about this change + if (owner) + { + owner->fLink->StartMessage( AS_LAYER_SCROLL ); + owner->fLink->Attach( dh ); + owner->fLink->Attach( dv ); + fState->flags |= B_VIEW_COORD_BIT; } - - // we modify our bounds rectangle by dh/dv coord units hor/ver. + + // we modify our bounds rectangle by dh/dv coord units hor/ver. fBounds.OffsetBy(dh, dv); - // then set the new values of the scrollbars + + // then set the new values of the scrollbars if (fHorScroller) fHorScroller->SetValue( fBounds.top ); if (fVerScroller) @@ -1231,69 +1355,63 @@ void BView::ScrollBy(float dh, float dv){ //--------------------------------------------------------------------------- -void BView::ScrollTo(BPoint where){ +void BView::ScrollTo(BPoint where) +{ ScrollBy( where.x - fBounds.left, where.y - fBounds.top ); } //--------------------------------------------------------------------------- -status_t BView::SetEventMask(uint32 mask, uint32 options){ +status_t BView::SetEventMask(uint32 mask, uint32 options) +{ if (fEventMask == mask && fEventOptions == options) return B_ERROR; - fEventMask = mask; + fEventMask = mask | (fEventMask & 0xFFFF0000); fEventOptions = options; fState->archivingFlags |= B_VIEW_EVMASK_BIT; -// TODO: modify! contact app_server! - + + // TODO: modify! contact app_server! + return B_OK; } //--------------------------------------------------------------------------- -uint32 BView::EventMask(){ +uint32 BView::EventMask() +{ return fEventMask; } //--------------------------------------------------------------------------- -status_t BView::SetMouseEventMask(uint32 mask, uint32 options){ - if (fEventMask == mask && fEventOptions == options) { - return B_ERROR; - } +status_t BView::SetMouseEventMask(uint32 mask, uint32 options) +{ + fEventMask = (mask << 16) | (fEventMask & 0x0000FFFF); + fEventOptions = (options << 16) | (options & 0x0000FFFF); - if (owner && owner->CurrentMessage()->what == B_MOUSE_DOWN ) { - // we'll store the current mask and options in the upper bits of our: - fEventMask |= ( ((fEventMask << 16) & 0xFFFF0000) | mask ); - fEventOptions |= ( ((fEventOptions << 16) & 0xFFFF0000) | options ); - } - -/* TODO: write this in ... where B_MOUSE_UP is handled... :) - fEventMask = ((fEventMask >> 16) & 0x0000FFFF); - fEventOptions = ((fEventOptions >> 16) & 0x0000FFFF); -*/ -// TODO: modify! contact app_server! + // TODO: Contact app_server return B_OK; } // Graphic State Functions //--------------------------------------------------------------------------- -void BView::SetLineMode(cap_mode lineCap, join_mode lineJoin, - float miterLimit) +void BView::SetLineMode(cap_mode lineCap, join_mode lineJoin,float miterLimit) { if (lineCap == fState->lineCap && lineJoin == fState->lineJoin && miterLimit == fState->miterLimit) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_SET_LINE_MODE ); - owner->session->WriteInt8( (int8)lineCap ); - owner->session->WriteInt8( (int8)lineJoin ); - owner->session->WriteFloat( miterLimit ); + owner->fLink->StartMessage( AS_LAYER_SET_LINE_MODE ); + owner->fLink->Attach( (int8)lineCap ); + owner->fLink->Attach( (int8)lineJoin ); + owner->fLink->Attach( miterLimit ); fState->flags |= B_VIEW_LINE_MODES_BIT; } @@ -1307,7 +1425,8 @@ void BView::SetLineMode(cap_mode lineCap, join_mode lineJoin, //--------------------------------------------------------------------------- -join_mode BView::LineJoinMode() const{ +join_mode BView::LineJoinMode() const +{ if (fState->flags & B_VIEW_LINE_MODES_BIT) LineMiterLimit(); @@ -1316,7 +1435,8 @@ join_mode BView::LineJoinMode() const{ //--------------------------------------------------------------------------- -cap_mode BView::LineCapMode() const{ +cap_mode BView::LineCapMode() const +{ if (fState->flags & B_VIEW_LINE_MODES_BIT) LineMiterLimit(); @@ -1325,18 +1445,23 @@ cap_mode BView::LineCapMode() const{ //--------------------------------------------------------------------------- -float BView::LineMiterLimit() const{ - if (fState->flags & B_VIEW_LINE_MODES_BIT) - if (owner) +float BView::LineMiterLimit() const +{ + if ( (fState->flags & B_VIEW_LINE_MODES_BIT) && owner) { check_lock(); - owner->session->WriteInt32( AS_LAYER_GET_LINE_MODE ); - owner->session->Sync(); + owner->fLink->StartMessage( AS_LAYER_GET_LINE_MODE ); + owner->fLink->Flush(); - owner->session->ReadInt8( (int8*)&(fState->lineCap) ); - owner->session->ReadInt8( (int8*)&(fState->lineJoin) ); - owner->session->ReadFloat( &(fState->miterLimit) ); + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + { + owner->fLink->Read( (int8*)&(fState->lineCap) ); + owner->fLink->Read( (int8*)&(fState->lineJoin) ); + owner->fLink->Read( &(fState->miterLimit) ); + } fState->flags &= ~B_VIEW_LINE_MODES_BIT; } @@ -1346,40 +1471,45 @@ float BView::LineMiterLimit() const{ //--------------------------------------------------------------------------- -void BView::PushState(){ +void BView::PushState() +{ do_owner_check(); - owner->session->WriteInt32( AS_LAYER_PUSH_STATE ); + owner->fLink->StartMessage( AS_LAYER_PUSH_STATE ); initCachedState(); } //--------------------------------------------------------------------------- -void BView::PopState(){ +void BView::PopState() +{ do_owner_check(); - owner->session->WriteInt32( AS_LAYER_POP_STATE ); + owner->fLink->StartMessage( AS_LAYER_POP_STATE ); - // this avoids a compiler warning + // this avoids a compiler warning uint32 dummy = 0xffffffffUL; - // invalidate all flags + + // invalidate all flags fState->flags = dummy; } //--------------------------------------------------------------------------- -void BView::SetScale(float scale) const{ +void BView::SetScale(float scale) const +{ if (scale == fState->scale) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_SET_SCALE ); - owner->session->WriteFloat( scale ); + owner->fLink->StartMessage( AS_LAYER_SET_SCALE ); + owner->fLink->Attach( scale ); - // I think that this flag won't be used after all... in 'flags' of course. + // I think that this flag won't be used after all... in 'flags' of course. fState->flags |= B_VIEW_SCALE_BIT; } @@ -1389,17 +1519,22 @@ void BView::SetScale(float scale) const{ } //--------------------------------------------------------------------------- -float BView::Scale() const{ - if (fState->flags & B_VIEW_SCALE_BIT) - if (owner) +float BView::Scale() const +{ + if ( (fState->flags & B_VIEW_SCALE_BIT) && owner) { check_lock(); - owner->session->WriteInt32( AS_LAYER_GET_SCALE ); - owner->session->Sync(); + owner->fLink->StartMessage( AS_LAYER_GET_SCALE ); + owner->fLink->Flush(); + + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + { + owner->fLink->Read( &(fState->scale) ); + } - owner->session->ReadFloat( &(fState->scale) ); - fState->flags &= ~B_VIEW_SCALE_BIT; } @@ -1408,15 +1543,17 @@ float BView::Scale() const{ //--------------------------------------------------------------------------- -void BView::SetDrawingMode(drawing_mode mode){ +void BView::SetDrawingMode(drawing_mode mode) +{ if (mode == fState->drawingMode) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_SET_DRAW_MODE ); - owner->session->WriteInt8( (int8)mode ); + owner->fLink->StartMessage( AS_LAYER_SET_DRAW_MODE ); + owner->fLink->Attach( (int8)mode ); fState->flags |= B_VIEW_DRAW_MODE_BIT; } @@ -1428,17 +1565,20 @@ void BView::SetDrawingMode(drawing_mode mode){ //--------------------------------------------------------------------------- -drawing_mode BView::DrawingMode() const{ - if (fState->flags & B_VIEW_DRAW_MODE_BIT) - if (owner) +drawing_mode BView::DrawingMode() const +{ + if ( (fState->flags & B_VIEW_DRAW_MODE_BIT) && owner) { check_lock(); int8 drawingMode; - owner->session->WriteInt32( AS_LAYER_GET_DRAW_MODE ); - owner->session->Sync(); + owner->fLink->StartMessage( AS_LAYER_GET_DRAW_MODE ); + owner->fLink->Flush(); - owner->session->ReadInt8( &drawingMode ); + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + owner->fLink->Read( &drawingMode ); fState->drawingMode = (drawing_mode)drawingMode; @@ -1450,17 +1590,18 @@ drawing_mode BView::DrawingMode() const{ //--------------------------------------------------------------------------- -void BView::SetBlendingMode(source_alpha srcAlpha, alpha_function alphaFunc){ - if (srcAlpha == fState->alphaSrcMode && - alphaFunc == fState->alphaFncMode) +void BView::SetBlendingMode(source_alpha srcAlpha, alpha_function alphaFunc) +{ + if (srcAlpha == fState->alphaSrcMode && alphaFunc == fState->alphaFncMode) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_SET_BLEND_MODE ); - owner->session->WriteInt8( (int8)srcAlpha ); - owner->session->WriteInt8( (int8)alphaFunc ); + owner->fLink->StartMessage( AS_LAYER_SET_BLEND_MODE ); + owner->fLink->Attach( (int8)srcAlpha ); + owner->fLink->Attach( (int8)alphaFunc ); fState->flags |= B_VIEW_BLENDING_BIT; } @@ -1473,18 +1614,23 @@ void BView::SetBlendingMode(source_alpha srcAlpha, alpha_function alphaFunc){ //--------------------------------------------------------------------------- -void BView::GetBlendingMode(source_alpha* srcAlpha, alpha_function* alphaFunc) const{ - if (fState->flags & B_VIEW_BLENDING_BIT) - if (owner) +void BView::GetBlendingMode(source_alpha* srcAlpha, alpha_function* alphaFunc) const +{ + if ( (fState->flags & B_VIEW_BLENDING_BIT) && owner) { check_lock(); int8 alphaSrcMode, alphaFncMode; - owner->session->WriteInt32( AS_LAYER_GET_BLEND_MODE ); - owner->session->Sync(); + owner->fLink->StartMessage( AS_LAYER_GET_BLEND_MODE ); + owner->fLink->Flush(); - owner->session->ReadInt8( &alphaSrcMode ); - owner->session->ReadInt8( &alphaFncMode ); + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + { + owner->fLink->Read( &alphaSrcMode ); + owner->fLink->Read( &alphaFncMode ); + } fState->alphaSrcMode = (source_alpha)alphaSrcMode; fState->alphaFncMode = (alpha_function)alphaFncMode; @@ -1501,23 +1647,25 @@ void BView::GetBlendingMode(source_alpha* srcAlpha, alpha_function* alphaFunc) c //--------------------------------------------------------------------------- -void BView::MovePenTo(BPoint pt){ +void BView::MovePenTo(BPoint pt) +{ MovePenTo( pt.x, pt.y ); } //--------------------------------------------------------------------------- -void BView::MovePenTo(float x, float y){ - if (x == fState->penPosition.x && - y == fState->penPosition.y) +void BView::MovePenTo(float x, float y) +{ + if (x == fState->penPosition.x && y == fState->penPosition.y) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_SET_PEN_LOC ); - owner->session->WriteFloat( x ); - owner->session->WriteFloat( y ); + owner->fLink->StartMessage( AS_LAYER_SET_PEN_LOC ); + owner->fLink->Attach( x ); + owner->fLink->Attach( y ); fState->flags |= B_VIEW_PEN_LOC_BIT; } @@ -1530,22 +1678,26 @@ void BView::MovePenTo(float x, float y){ //--------------------------------------------------------------------------- -void BView::MovePenBy(float x, float y){ +void BView::MovePenBy(float x, float y) +{ MovePenTo(fState->penPosition.x + x, fState->penPosition.y + y); } //--------------------------------------------------------------------------- -BPoint BView::PenLocation() const{ - if (fState->flags & B_VIEW_PEN_LOC_BIT) - if (owner) +BPoint BView::PenLocation() const +{ + if ( (fState->flags & B_VIEW_PEN_LOC_BIT) && owner) { check_lock(); - owner->session->WriteInt32( AS_LAYER_GET_PEN_LOC ); - owner->session->Sync(); + owner->fLink->StartMessage( AS_LAYER_GET_PEN_LOC ); + owner->fLink->Flush(); - owner->session->ReadPoint( &(fState->penPosition) ); + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + owner->fLink->Read( &(fState->penPosition) ); fState->flags &= ~B_VIEW_PEN_LOC_BIT; } @@ -1562,8 +1714,8 @@ void BView::SetPenSize(float size){ if (owner){ check_lock(); - owner->session->WriteInt32( AS_LAYER_SET_PEN_SIZE ); - owner->session->WriteFloat( size ); + owner->fLink->StartMessage( AS_LAYER_SET_PEN_SIZE ); + owner->fLink->Attach( size ); fState->flags |= B_VIEW_PEN_SIZE_BIT; } @@ -1575,34 +1727,41 @@ void BView::SetPenSize(float size){ //--------------------------------------------------------------------------- -float BView::PenSize() const{ +float BView::PenSize() const +{ if (fState->flags & B_VIEW_PEN_SIZE_BIT) - if (owner) { - check_lock(); - - owner->session->WriteInt32( AS_LAYER_GET_PEN_SIZE ); - owner->session->Sync(); - - owner->session->ReadFloat( &(fState->penSize) ); - - fState->flags &= ~B_VIEW_PEN_SIZE_BIT; + if (owner) + { + check_lock(); + + owner->fLink->StartMessage( AS_LAYER_GET_PEN_SIZE ); + owner->fLink->Flush(); + + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + owner->fLink->Read( &(fState->penSize) ); + + fState->flags &= ~B_VIEW_PEN_SIZE_BIT; + } } - return fState->penSize; } //--------------------------------------------------------------------------- -void BView::SetHighColor(rgb_color a_color){ +void BView::SetHighColor(rgb_color a_color) +{ if (_rgb_color_are_equal( fState->highColor, a_color )) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_SET_HIGH_COLOR ); - owner->session->WriteData( &a_color, sizeof(rgb_color) ); + owner->fLink->StartMessage( AS_LAYER_SET_HIGH_COLOR ); + owner->fLink->Attach( a_color ); fState->flags |= B_VIEW_COLORS_BIT; } @@ -1615,36 +1774,46 @@ void BView::SetHighColor(rgb_color a_color){ //--------------------------------------------------------------------------- -rgb_color BView::HighColor() const{ +rgb_color BView::HighColor() const +{ if (fState->flags & B_VIEW_COLORS_BIT) - if (owner) { - check_lock(); - - owner->session->WriteInt32( AS_LAYER_GET_COLORS ); - owner->session->Sync(); - - owner->session->ReadData( &(fState->highColor), sizeof(rgb_color) ); - owner->session->ReadData( &(fState->lowColor), sizeof(rgb_color) ); - owner->session->ReadData( &(fState->viewColor), sizeof(rgb_color) ); - - fState->flags &= ~B_VIEW_COLORS_BIT; + if (owner) + { + check_lock(); + + owner->fLink->StartMessage( AS_LAYER_GET_COLORS ); + owner->fLink->Flush(); + + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + { + owner->fLink->Read( &(fState->highColor) ); + owner->fLink->Read( &(fState->lowColor) ); + owner->fLink->Read( &(fState->viewColor) ); + } + + fState->flags &= ~B_VIEW_COLORS_BIT; + } } - + return fState->highColor; } //--------------------------------------------------------------------------- -void BView::SetLowColor(rgb_color a_color){ +void BView::SetLowColor(rgb_color a_color) +{ if (_rgb_color_are_equal( fState->lowColor, a_color )) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_SET_LOW_COLOR ); - owner->session->WriteData( &a_color, sizeof(rgb_color) ); + owner->fLink->StartMessage( AS_LAYER_SET_LOW_COLOR ); + owner->fLink->Attach( a_color ); fState->flags |= B_VIEW_COLORS_BIT; } @@ -1657,27 +1826,32 @@ void BView::SetLowColor(rgb_color a_color){ //--------------------------------------------------------------------------- -rgb_color BView::LowColor() const{ +rgb_color BView::LowColor() const +{ if (fState->flags & B_VIEW_COLORS_BIT) - if (owner){ + { + if (owner) + { // HighColor() contacts app_server and gets the high, low and view colors - HighColor(); + HighColor(); + } } - return fState->lowColor; } //--------------------------------------------------------------------------- -void BView::SetViewColor(rgb_color c){ +void BView::SetViewColor(rgb_color c) +{ if (_rgb_color_are_equal( fState->viewColor, c )) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_SET_VIEW_COLOR ); - owner->session->WriteData( &c, sizeof(rgb_color) ); + owner->fLink->StartMessage( AS_LAYER_SET_VIEW_COLOR ); + owner->fLink->Attach( c ); fState->flags |= B_VIEW_COLORS_BIT; } @@ -1690,48 +1864,56 @@ void BView::SetViewColor(rgb_color c){ //--------------------------------------------------------------------------- -rgb_color BView::ViewColor() const{ +rgb_color BView::ViewColor() const +{ if (fState->flags & B_VIEW_COLORS_BIT) - if (owner){ + { + if (owner) + { // HighColor() contacts app_server and gets the high, low and view colors - HighColor(); + HighColor(); + } } - return fState->viewColor; } //--------------------------------------------------------------------------- -void BView::ForceFontAliasing(bool enable){ +void BView::ForceFontAliasing(bool enable) +{ if ( enable == fState->fontAliasing) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_PRINT_ALIASING ); - owner->session->WriteBool( enable ); - - // I think this flag won't be used... + owner->fLink->StartMessage( AS_LAYER_PRINT_ALIASING ); + owner->fLink->Attach( enable ); + + // I think this flag won't be used... fState->flags |= B_VIEW_FONT_ALIASING_BIT; } fState->fontAliasing = enable; - + fState->archivingFlags |= B_VIEW_FONT_ALIASING_BIT; } //--------------------------------------------------------------------------- -void BView::SetFont(const BFont* font, uint32 mask){ +void BView::SetFont(const BFont* font, uint32 mask) +{ if (!font || mask == 0) return; - if ( mask == B_FONT_ALL ){ + if ( mask == B_FONT_ALL ) + { fState->font = *font; } - else{ + else + { if ( mask & B_FONT_FAMILY_AND_STYLE ) fState->font.SetFamilyAndStyle( font->FamilyAndStyle() ); @@ -1759,7 +1941,8 @@ void BView::SetFont(const BFont* font, uint32 mask){ fState->fontFlags = mask; - if (owner){ + if (owner) + { check_lock(); setFontState( &(fState->font), fState->fontFlags ); @@ -1769,77 +1952,80 @@ void BView::SetFont(const BFont* font, uint32 mask){ //--------------------------------------------------------------------------- #if !_PR3_COMPATIBLE_ -void BView::GetFont(BFont* font) const{ +void BView::GetFont(BFont* font) const +{ *font = fState->font; } //--------------------------------------------------------------------------- #else -void BView:GetFont(BFont* font){ +void BView:GetFont(BFont* font) +{ *font = fState->font; } #endif //--------------------------------------------------------------------------- -void BView::GetFontHeight(font_height* height) const{ +void BView::GetFontHeight(font_height* height) const +{ fState->font.GetHeight( height ); } //--------------------------------------------------------------------------- -void BView::SetFontSize(float size){ +void BView::SetFontSize(float size) +{ fState->font.SetSize( size ); } //--------------------------------------------------------------------------- -float BView::StringWidth(const char* string) const{ +float BView::StringWidth(const char* string) const +{ return fState->font.StringWidth( string ); } //--------------------------------------------------------------------------- -float BView::StringWidth(const char* string, int32 length) const{ +float BView::StringWidth(const char* string, int32 length) const +{ return fState->font.StringWidth( string, length ); } //--------------------------------------------------------------------------- void BView::GetStringWidths(char* stringArray[],int32 lengthArray[], - int32 numStrings, float widthArray[]) const + int32 numStrings, float widthArray[]) const { + // ARE these const_cast good????? fState->font.GetStringWidths( const_cast(stringArray), - const_cast(lengthArray), - numStrings, &*widthArray ); - // ARE these const_cast good????? + const_cast(lengthArray),numStrings, &*widthArray ); } //--------------------------------------------------------------------------- -void BView::TruncateString(BString* in_out, uint32 mode, float width) const{ +void BView::TruncateString(BString* in_out, uint32 mode, float width) const +{ fState->font.TruncateString( in_out, mode, width); } //--------------------------------------------------------------------------- -void BView::ClipToPicture(BPicture* picture, - BPoint where, - bool sync) +void BView::ClipToPicture(BPicture* picture,BPoint where,bool sync) { - if ( picture == NULL ) + if (!picture) return; - if (do_owner_check()){ + if (do_owner_check()) + { + owner->fLink->StartMessage( AS_LAYER_CLIP_TO_PICTURE ); + owner->fLink->Attach( picture->token ); + owner->fLink->Attach( where ); - owner->session->WriteInt32( AS_LAYER_CLIP_TO_PICTURE ); - owner->session->WriteInt32( picture->token ); - owner->session->WritePoint( where ); - - if (sync){ - owner->session->Sync(); - } + if (sync) + owner->fLink->Flush(); fState->flags |= B_VIEW_CLIP_REGION_BIT; } @@ -1853,17 +2039,18 @@ void BView::ClipToInversePicture(BPicture* picture, BPoint where, bool sync) { - if ( picture == NULL ) + if (!picture) return; - if (do_owner_check()){ + if (do_owner_check()) + { + owner->fLink->StartMessage( AS_LAYER_CLIP_TO_INVERSE_PICTURE ); + owner->fLink->Attach( picture->token ); + owner->fLink->Attach( where ); - owner->session->WriteInt32( AS_LAYER_CLIP_TO_INVERSE_PICTURE ); - owner->session->WriteInt32( picture->token ); - owner->session->WritePoint( where ); - - if (sync){ - owner->session->Sync(); + if (sync) + { + owner->fLink->Flush(); } fState->flags |= B_VIEW_CLIP_REGION_BIT; @@ -1874,55 +2061,66 @@ void BView::ClipToInversePicture(BPicture* picture, //--------------------------------------------------------------------------- -void BView::GetClippingRegion(BRegion* region) const{ - if ( region == NULL ) +void BView::GetClippingRegion(BRegion* region) const +{ + if (!region) return; if (fState->flags & B_VIEW_CLIP_REGION_BIT) - if (do_owner_check()) { - int32 noOfRects; - - owner->session->WriteInt32( AS_LAYER_GET_CLIP_REGION ); - owner->session->Sync(); - owner->session->ReadInt32( &noOfRects ); - - fState->clippingRegion.MakeEmpty(); - for (int32 i = 0; i < noOfRects; i++){ - BRect rect; - - owner->session->ReadRect( &rect ); - - fState->clippingRegion.Include( rect ); - } - - fState->flags &= ~B_VIEW_CLIP_REGION_BIT; - } + if (do_owner_check()) + { + int32 noOfRects; + owner->fLink->StartMessage( AS_LAYER_GET_CLIP_REGION ); + owner->fLink->Flush(); + + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + { + owner->fLink->Read( &noOfRects ); + + fState->clippingRegion.MakeEmpty(); + for (int32 i = 0; i < noOfRects; i++) + { + BRect rect; + + owner->fLink->Read( &rect ); + + fState->clippingRegion.Include( rect ); + } + fState->flags &= ~B_VIEW_CLIP_REGION_BIT; + } + } + } *region = fState->clippingRegion; } //--------------------------------------------------------------------------- -void BView::ConstrainClippingRegion(BRegion* region){ - if (do_owner_check()){ +void BView::ConstrainClippingRegion(BRegion* region) +{ + if (do_owner_check()) + { int32 noOfRects = 0; if (region) noOfRects = region->CountRects(); - owner->session->WriteInt32( AS_LAYER_SET_CLIP_REGION ); - /* '0' means that in the app_server, there won't be any 'local' - * clipping region (it will be = NULL) - */ -// TODO: note this in the specs!!!!!! - owner->session->WriteInt32( noOfRects ); + owner->fLink->StartMessage( AS_LAYER_SET_CLIP_REGION ); + + // '0' means that in the app_server, there won't be any 'local' + // clipping region (it will be = NULL) - for (int32 i = 0; isession->WriteRect( region->RectAt(i) ); - } - // we flush here because app_server waits for all the rects - owner->session->Sync(); + // TODO: note this in the specs + owner->fLink->Attach( noOfRects ); + + for (int32 i = 0; ifLink->Attach( region->RectAt(i) ); + + // we flush here because app_server waits for all the rects + owner->fLink->Flush(); fState->flags |= B_VIEW_CLIP_REGION_BIT; fState->archivingFlags |= B_VIEW_CLIP_REGION_BIT; @@ -1935,23 +2133,26 @@ void BView::ConstrainClippingRegion(BRegion* region){ // Drawing Functions //--------------------------------------------------------------------------- -void BView::DrawBitmapAsync(const BBitmap* aBitmap, BRect srcRect, BRect dstRect){ +void BView::DrawBitmapAsync(const BBitmap* aBitmap, BRect srcRect, BRect dstRect) +{ if ( !aBitmap || !srcRect.IsValid() || !dstRect.IsValid()) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_DRAW_BITMAP_ASYNC_IN_RECT ); - owner->session->WriteInt32( aBitmap->get_server_token() ); - owner->session->WriteRect( dstRect ); - owner->session->WriteRect( srcRect ); + owner->fLink->StartMessage( AS_LAYER_DRAW_BITMAP_ASYNC_IN_RECT ); + owner->fLink->Attach( aBitmap->get_server_token() ); + owner->fLink->Attach( srcRect ); + owner->fLink->Attach( dstRect ); } } //--------------------------------------------------------------------------- -void BView::DrawBitmapAsync(const BBitmap* aBitmap, BRect dstRect){ +void BView::DrawBitmapAsync(const BBitmap* aBitmap, BRect dstRect) +{ if ( !aBitmap || !dstRect.IsValid()) return; @@ -1960,50 +2161,57 @@ void BView::DrawBitmapAsync(const BBitmap* aBitmap, BRect dstRect){ //--------------------------------------------------------------------------- -void BView::DrawBitmapAsync(const BBitmap* aBitmap){ +void BView::DrawBitmapAsync(const BBitmap* aBitmap) +{ DrawBitmapAsync( aBitmap, PenLocation() ); } //--------------------------------------------------------------------------- -void BView::DrawBitmapAsync(const BBitmap* aBitmap, BPoint where){ +void BView::DrawBitmapAsync(const BBitmap* aBitmap, BPoint where) +{ if ( !aBitmap ) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_DRAW_BITMAP_ASYNC_AT_POINT ); - owner->session->WriteInt32( aBitmap->get_server_token() ); - owner->session->WritePoint( where ); + owner->fLink->StartMessage( AS_LAYER_DRAW_BITMAP_ASYNC_AT_POINT ); + owner->fLink->Attach( aBitmap->get_server_token() ); + owner->fLink->Attach( where ); } } //--------------------------------------------------------------------------- -void BView::DrawBitmap(const BBitmap* aBitmap){ +void BView::DrawBitmap(const BBitmap* aBitmap) +{ DrawBitmap( aBitmap, PenLocation() ); } //--------------------------------------------------------------------------- -void BView::DrawBitmap(const BBitmap* aBitmap, BPoint where){ +void BView::DrawBitmap(const BBitmap* aBitmap, BPoint where) +{ if ( !aBitmap ) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_DRAW_BITMAP_SYNC_AT_POINT ); - owner->session->WriteInt32( aBitmap->get_server_token() ); - owner->session->WritePoint( where ); - owner->session->Sync(); + owner->fLink->StartMessage( AS_LAYER_DRAW_BITMAP_SYNC_AT_POINT ); + owner->fLink->Attach( aBitmap->get_server_token() ); + owner->fLink->Attach( where ); + owner->fLink->Flush(); } } //--------------------------------------------------------------------------- -void BView::DrawBitmap(const BBitmap* aBitmap, BRect dstRect){ +void BView::DrawBitmap(const BBitmap* aBitmap, BRect dstRect) +{ if ( !aBitmap || !dstRect.IsValid()) return; @@ -2012,30 +2220,34 @@ void BView::DrawBitmap(const BBitmap* aBitmap, BRect dstRect){ //--------------------------------------------------------------------------- -void BView::DrawBitmap(const BBitmap* aBitmap, BRect srcRect, BRect dstRect){ +void BView::DrawBitmap(const BBitmap* aBitmap, BRect srcRect, BRect dstRect) +{ if ( !aBitmap || !srcRect.IsValid() || !dstRect.IsValid()) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_DRAW_BITMAP_SYNC_IN_RECT ); - owner->session->WriteInt32( aBitmap->get_server_token() ); - owner->session->WriteRect( dstRect ); - owner->session->WriteRect( srcRect ); - owner->session->Sync(); + owner->fLink->StartMessage( AS_LAYER_DRAW_BITMAP_SYNC_IN_RECT ); + owner->fLink->Attach( aBitmap->get_server_token() ); + owner->fLink->Attach( dstRect ); + owner->fLink->Attach( srcRect ); + owner->fLink->Flush(); } } //--------------------------------------------------------------------------- -void BView::DrawChar(char aChar){ +void BView::DrawChar(char aChar) +{ DrawChar( aChar, PenLocation() ); } //--------------------------------------------------------------------------- -void BView::DrawChar(char aChar, BPoint location){ +void BView::DrawChar(char aChar, BPoint location) +{ char ch[2]; ch[0] = aChar; ch[1] = '\0'; @@ -2045,8 +2257,7 @@ void BView::DrawChar(char aChar, BPoint location){ //--------------------------------------------------------------------------- -void BView::DrawString(const char* aString, - escapement_delta* delta) +void BView::DrawString(const char* aString, escapement_delta* delta) { if ( !aString ) return; @@ -2056,8 +2267,7 @@ void BView::DrawString(const char* aString, //--------------------------------------------------------------------------- -void BView::DrawString(const char* aString, BPoint location, - escapement_delta* delta) +void BView::DrawString(const char* aString, BPoint location, escapement_delta* delta) { if ( !aString ) return; @@ -2067,8 +2277,7 @@ void BView::DrawString(const char* aString, BPoint location, //--------------------------------------------------------------------------- -void BView::DrawString(const char* aString, int32 length, - escapement_delta* delta) +void BView::DrawString(const char* aString, int32 length, escapement_delta* delta) { if ( !aString ) return; @@ -2079,210 +2288,227 @@ void BView::DrawString(const char* aString, int32 length, //--------------------------------------------------------------------------- void BView::DrawString(const char* aString, int32 length, BPoint location, - escapement_delta* delta) + escapement_delta* delta) { if ( !aString ) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_DRAW_STRING ); - owner->session->WritePoint( location ); - owner->session->WriteData( delta, sizeof(escapement_delta) ); - owner->session->WriteString( aString ); + owner->fLink->StartMessage( AS_DRAW_STRING ); + owner->fLink->Attach( location ); + + // Quite often delta will be NULL, so we have to accomodate this. + if(delta) + owner->fLink->Attach( *delta ); + else + { + escapement_delta tdelta; + tdelta.space=0; + tdelta.nonspace=0; + + owner->fLink->Attach( tdelta ); + } + owner->fLink->AttachString( aString ); - // this modifies our pen location, so we invalidate the flag. + // this modifies our pen location, so we invalidate the flag. fState->flags |= B_VIEW_PEN_LOC_BIT; } } //--------------------------------------------------------------------------- -void BView::StrokeEllipse(BPoint center, - float xRadius, float yRadius, - pattern p) +void BView::StrokeEllipse(BPoint center, float xRadius, float yRadius, + pattern p) { - if (owner){ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_STROKE_ELLIPSE ); - owner->session->WritePoint( center ); - owner->session->WriteFloat( xRadius ); - owner->session->WriteFloat( yRadius ); + owner->fLink->StartMessage( AS_STROKE_ELLIPSE ); + owner->fLink->Attach( center ); + owner->fLink->Attach( xRadius ); + owner->fLink->Attach( yRadius ); } } //--------------------------------------------------------------------------- -void BView::StrokeEllipse(BRect r, pattern p) { +void BView::StrokeEllipse(BRect r, pattern p) +{ if (owner) - StrokeEllipse( r.LeftTop() + BPoint(r.Width()/2, r.Height()/2), + { + StrokeEllipse( r.LeftTop() + BPoint(r.Width()/2, r.Height()/2), r.Width()/2, r.Height()/2, p ); -} - -//--------------------------------------------------------------------------- - -void BView::FillEllipse(BPoint center, - float xRadius, float yRadius, - pattern p) -{ - if (owner){ - check_lock(); - - if ( _is_new_pattern( fState->patt, p ) ) - SetPattern( p ); - - owner->session->WriteInt32( AS_FILL_ELLIPSE ); - owner->session->WritePoint( center ); - owner->session->WriteFloat( xRadius ); - owner->session->WriteFloat( yRadius ); } } //--------------------------------------------------------------------------- -void BView::FillEllipse(BRect r, pattern p) { - if (owner) - FillEllipse( r.LeftTop() + BPoint(r.Width()/2, r.Height()/2), - r.Width()/2, r.Height()/2, p ); - -} - -//--------------------------------------------------------------------------- - -void BView::StrokeArc(BPoint center, - float xRadius, float yRadius, - float start_angle, float arc_angle, - pattern p) +void BView::FillEllipse(BPoint center, float xRadius, float yRadius, + pattern p) { - if (owner){ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_STROKE_ARC ); - owner->session->WritePoint( center ); - owner->session->WriteFloat( xRadius ); - owner->session->WriteFloat( yRadius ); - owner->session->WriteFloat( start_angle ); - owner->session->WriteFloat( arc_angle ); + owner->fLink->StartMessage( AS_FILL_ELLIPSE ); + owner->fLink->Attach( center ); + owner->fLink->Attach( xRadius ); + owner->fLink->Attach( yRadius ); } } //--------------------------------------------------------------------------- -void BView::StrokeArc(BRect r, - float start_angle, float arc_angle, - pattern p) +void BView::FillEllipse(BRect r, pattern p) { if (owner) - StrokeArc( r.LeftTop() + BPoint(r.Width()/2, r.Height()/2), - r.Width()/2, r.Height()/2, - start_angle, arc_angle, p ); + { + FillEllipse(r.LeftTop() + BPoint(r.Width()/2, r.Height()/2), + r.Width()/2, r.Height()/2, p ); + } +} + +//--------------------------------------------------------------------------- + +void BView::StrokeArc(BPoint center, float xRadius, float yRadius, + float start_angle, float arc_angle, pattern p) +{ + if (owner) + { + check_lock(); + + if ( _is_new_pattern( fState->patt, p ) ) + SetPattern( p ); + + owner->fLink->StartMessage( AS_STROKE_ARC ); + owner->fLink->Attach( center ); + owner->fLink->Attach( xRadius ); + owner->fLink->Attach( yRadius ); + owner->fLink->Attach( start_angle ); + owner->fLink->Attach( arc_angle ); + } +} + +//--------------------------------------------------------------------------- + +void BView::StrokeArc(BRect r, float start_angle, float arc_angle, + pattern p) +{ + if (owner) + { + StrokeArc( r.LeftTop() + BPoint(r.Width()/2, r.Height()/2), + r.Width()/2, r.Height()/2, start_angle, arc_angle, p ); + } } //--------------------------------------------------------------------------- -void BView::FillArc(BPoint center, - float xRadius, float yRadius, - float start_angle, float arc_angle, - pattern p) -{ - if (owner){ - check_lock(); - - if ( _is_new_pattern( fState->patt, p ) ) - SetPattern( p ); - - owner->session->WriteInt32( AS_FILL_ARC ); - owner->session->WritePoint( center ); - owner->session->WriteFloat( xRadius ); - owner->session->WriteFloat( yRadius ); - owner->session->WriteFloat( start_angle ); - owner->session->WriteFloat( arc_angle ); - } -} - -//--------------------------------------------------------------------------- - -void BView::FillArc(BRect r, - float start_angle, float arc_angle, - pattern p) +void BView::FillArc(BPoint center,float xRadius, float yRadius, + float start_angle, float arc_angle, pattern p) { if (owner) - FillArc( r.LeftTop() + BPoint(r.Width()/2, r.Height()/2), - r.Width()/2, r.Height()/2, - start_angle, arc_angle, p ); -} - -//--------------------------------------------------------------------------- - -void BView::StrokeBezier(BPoint* controlPoints, pattern p){ - if (owner){ + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_STROKE_BEZIER ); - owner->session->WritePoint( controlPoints[0] ); - owner->session->WritePoint( controlPoints[1] ); - owner->session->WritePoint( controlPoints[2] ); - owner->session->WritePoint( controlPoints[3] ); + owner->fLink->StartMessage( AS_FILL_ARC ); + owner->fLink->Attach( center ); + owner->fLink->Attach( xRadius ); + owner->fLink->Attach( yRadius ); + owner->fLink->Attach( start_angle ); + owner->fLink->Attach( arc_angle ); } } //--------------------------------------------------------------------------- -void BView::FillBezier(BPoint* controlPoints, pattern p){ - if (owner){ +void BView::FillArc(BRect r, float start_angle, float arc_angle, + pattern p) +{ + if (owner) + { + FillArc(r.LeftTop() + BPoint(r.Width()/2, r.Height()/2), + r.Width()/2, r.Height()/2,start_angle, arc_angle, p ); + } +} + +//--------------------------------------------------------------------------- + +void BView::StrokeBezier(BPoint* controlPoints, pattern p) +{ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_FILL_BEZIER ); - owner->session->WritePoint( controlPoints[0] ); - owner->session->WritePoint( controlPoints[1] ); - owner->session->WritePoint( controlPoints[2] ); - owner->session->WritePoint( controlPoints[3] ); + owner->fLink->StartMessage( AS_STROKE_BEZIER ); + owner->fLink->Attach( controlPoints[0] ); + owner->fLink->Attach( controlPoints[1] ); + owner->fLink->Attach( controlPoints[2] ); + owner->fLink->Attach( controlPoints[3] ); } } //--------------------------------------------------------------------------- -void BView::StrokePolygon(const BPolygon* aPolygon, - bool closed, pattern p) +void BView::FillBezier(BPoint* controlPoints, pattern p) +{ + if (owner) + { + check_lock(); + + if ( _is_new_pattern( fState->patt, p ) ) + SetPattern( p ); + + owner->fLink->StartMessage( AS_FILL_BEZIER ); + owner->fLink->Attach( controlPoints[0] ); + owner->fLink->Attach( controlPoints[1] ); + owner->fLink->Attach( controlPoints[2] ); + owner->fLink->Attach( controlPoints[3] ); + } +} + +//--------------------------------------------------------------------------- + +void BView::StrokePolygon(const BPolygon* aPolygon,bool closed, pattern p) { if ( !aPolygon ) return; if ( aPolygon->fCount <= 2 ) return; - - if (owner){ + + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_STROKE_POLYGON ); - owner->session->WriteInt8( closed ); - owner->session->WriteInt32( aPolygon->fCount ); - owner->session->WriteData( aPolygon->fPts, - aPolygon->fCount * sizeof(BPoint) ); + owner->fLink->StartMessage( AS_STROKE_POLYGON ); + owner->fLink->Attach( closed ); + owner->fLink->Attach( aPolygon->fCount ); + owner->fLink->Attach(aPolygon->fPts,aPolygon->fCount * sizeof(BPoint) ); } } //--------------------------------------------------------------------------- -void BView::StrokePolygon(const BPoint* ptArray, int32 numPts, - bool closed, pattern p) +void BView::StrokePolygon(const BPoint* ptArray, int32 numPts,bool closed, pattern p) { if ( !ptArray ) return; @@ -2294,7 +2520,7 @@ void BView::StrokePolygon(const BPoint* ptArray, int32 numPts, //--------------------------------------------------------------------------- void BView::StrokePolygon(const BPoint* ptArray, int32 numPts, BRect bounds, - bool closed, pattern p) + bool closed, pattern p) { if ( !ptArray ) return; @@ -2306,8 +2532,7 @@ void BView::StrokePolygon(const BPoint* ptArray, int32 numPts, BRect bounds, //--------------------------------------------------------------------------- -void BView::FillPolygon(const BPolygon* aPolygon, - pattern p) +void BView::FillPolygon(const BPolygon* aPolygon,pattern p) { if ( !aPolygon ) return; @@ -2315,23 +2540,22 @@ void BView::FillPolygon(const BPolygon* aPolygon, if ( aPolygon->fCount <= 2 ) return; - if (owner){ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_FILL_POLYGON ); - owner->session->WriteInt32( aPolygon->fCount ); - owner->session->WriteData( aPolygon->fPts, - aPolygon->fCount * sizeof(BPoint) ); + owner->fLink->StartMessage( AS_FILL_POLYGON ); + owner->fLink->Attach( aPolygon->fCount ); + owner->fLink->Attach(aPolygon->fPts,aPolygon->fCount * sizeof(BPoint) ); } } //--------------------------------------------------------------------------- -void BView::FillPolygon(const BPoint* ptArray, int32 numPts, - pattern p) +void BView::FillPolygon(const BPoint* ptArray, int32 numPts, pattern p) { if ( !ptArray ) return; @@ -2343,7 +2567,7 @@ void BView::FillPolygon(const BPoint* ptArray, int32 numPts, //--------------------------------------------------------------------------- void BView::FillPolygon(const BPoint* ptArray, int32 numPts, BRect bounds, - pattern p) + pattern p) { if ( !ptArray ) return; @@ -2355,54 +2579,59 @@ void BView::FillPolygon(const BPoint* ptArray, int32 numPts, BRect bounds, //--------------------------------------------------------------------------- -void BView::StrokeRect(BRect r, pattern p){ - if (owner){ +void BView::StrokeRect(BRect r, pattern p) +{ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_STROKE_RECT ); - owner->session->WriteRect( r ); + owner->fLink->StartMessage( AS_STROKE_RECT ); + owner->fLink->Attach( r ); } } //--------------------------------------------------------------------------- -void BView::FillRect(BRect r, pattern p){ - if (owner){ +void BView::FillRect(BRect r, pattern p) +{ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_FILL_RECT ); - owner->session->WriteRect( r ); + owner->fLink->StartMessage( AS_FILL_RECT ); + owner->fLink->Attach( r ); } } //--------------------------------------------------------------------------- void BView::StrokeRoundRect(BRect r, float xRadius, float yRadius, - pattern p) + pattern p) { - if (owner){ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_STROKE_ROUNDRECT ); - owner->session->WriteRect( r ); - owner->session->WriteFloat( xRadius ); - owner->session->WriteFloat( yRadius ); + owner->fLink->StartMessage( AS_STROKE_ROUNDRECT ); + owner->fLink->Attach( r ); + owner->fLink->Attach( xRadius ); + owner->fLink->Attach( yRadius ); } } //--------------------------------------------------------------------------- void BView::FillRoundRect(BRect r, float xRadius, float yRadius, - pattern p) + pattern p) { if (owner){ check_lock(); @@ -2410,20 +2639,22 @@ void BView::FillRoundRect(BRect r, float xRadius, float yRadius, if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_FILL_ROUNDRECT ); - owner->session->WriteRect( r ); - owner->session->WriteFloat( xRadius ); - owner->session->WriteFloat( yRadius ); + owner->fLink->StartMessage( AS_FILL_ROUNDRECT ); + owner->fLink->Attach( r ); + owner->fLink->Attach( xRadius ); + owner->fLink->Attach( yRadius ); } } //--------------------------------------------------------------------------- -void BView::FillRegion(BRegion* a_region, pattern p){ +void BView::FillRegion(BRegion* a_region, pattern p) +{ if ( !a_region ) return; - if (owner){ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) @@ -2431,86 +2662,85 @@ void BView::FillRegion(BRegion* a_region, pattern p){ int32 rectsNo = a_region->CountRects(); - owner->session->WriteInt32( AS_FILL_REGION ); - owner->session->WriteInt32( rectsNo ); + owner->fLink->StartMessage( AS_FILL_REGION ); + owner->fLink->Attach( rectsNo ); - for (int32 i = 0; isession->WriteRect( a_region->RectAt(i) ); - } + for (int32 i = 0; ifLink->Attach( a_region->RectAt(i) ); } } //--------------------------------------------------------------------------- void BView::StrokeTriangle(BPoint pt1, BPoint pt2, BPoint pt3, - BRect bounds, pattern p) + BRect bounds, pattern p) { - if (owner){ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_STROKE_TRIANGLE ); - owner->session->WritePoint( pt1 ); - owner->session->WritePoint( pt2 ); - owner->session->WritePoint( pt3 ); - // ???: Do we need this? - owner->session->WriteRect( bounds ); + owner->fLink->StartMessage( AS_STROKE_TRIANGLE ); + owner->fLink->Attach( pt1 ); + owner->fLink->Attach( pt2 ); + owner->fLink->Attach( pt3 ); + owner->fLink->Attach( bounds ); } } //--------------------------------------------------------------------------- -void BView::StrokeTriangle(BPoint pt1, BPoint pt2, BPoint pt3, - pattern p) +void BView::StrokeTriangle(BPoint pt1, BPoint pt2, BPoint pt3, pattern p) { - if (owner){ - // we construct the smallest rectangle that contains the 3 points - // for the 1st point + if (owner) + { + // we construct the smallest rectangle that contains the 3 points + // for the 1st point BRect bounds(pt1, pt1); - - // for the 2nd point + + // for the 2nd point if (pt2.x < bounds.left) bounds.left = pt2.x; - + if (pt2.y < bounds.top) bounds.top = pt2.y; - + if (pt2.x > bounds.right) bounds.right = pt2.x; - + if (pt2.y > bounds.bottom) bounds.bottom = pt2.y; - // for the 3rd point + // for the 3rd point if (pt3.x < bounds.left) bounds.left = pt3.x; - + if (pt3.y < bounds.top) bounds.top = pt3.y; - + if (pt3.x > bounds.right) bounds.right = pt3.x; - + if (pt3.y > bounds.bottom) bounds.bottom = pt3.y; - + StrokeTriangle( pt1, pt2, pt3, bounds, p ); } } //--------------------------------------------------------------------------- -void BView::FillTriangle(BPoint pt1, BPoint pt2, BPoint pt3, - pattern p) +void BView::FillTriangle(BPoint pt1, BPoint pt2, BPoint pt3, pattern p) { - if (owner){ - // we construct the smallest rectangle that contains the 3 points - // for the 1st point + if (owner) + { + // we construct the smallest rectangle that contains the 3 points + // for the 1st point BRect bounds(pt1, pt1); - // for the 2nd point + // for the 2nd point if (pt2.x < bounds.left) bounds.left = pt2.x; @@ -2523,7 +2753,7 @@ void BView::FillTriangle(BPoint pt1, BPoint pt2, BPoint pt3, if (pt2.y > bounds.bottom) bounds.bottom = pt2.y; - // for the 3rd point + // for the 3rd point if (pt3.x < bounds.left) bounds.left = pt3.x; @@ -2543,50 +2773,54 @@ void BView::FillTriangle(BPoint pt1, BPoint pt2, BPoint pt3, //--------------------------------------------------------------------------- void BView::FillTriangle(BPoint pt1, BPoint pt2, BPoint pt3, - BRect bounds, pattern p) + BRect bounds, pattern p) { - if (owner){ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_FILL_TRIANGLE ); - owner->session->WritePoint( pt1 ); - owner->session->WritePoint( pt2 ); - owner->session->WritePoint( pt3 ); - // ???: Do we need this? - owner->session->WriteRect( bounds ); + owner->fLink->StartMessage( AS_FILL_TRIANGLE ); + owner->fLink->Attach( pt1 ); + owner->fLink->Attach( pt2 ); + owner->fLink->Attach( pt3 ); + owner->fLink->Attach( bounds ); } } //--------------------------------------------------------------------------- -void BView::StrokeLine(BPoint toPt, pattern p){ +void BView::StrokeLine(BPoint toPt, pattern p) +{ StrokeLine( PenLocation(), toPt, p); } //--------------------------------------------------------------------------- -void BView::StrokeLine(BPoint pt0, BPoint pt1, pattern p){ - if (owner){ +void BView::StrokeLine(BPoint pt0, BPoint pt1, pattern p) +{ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_STROKE_LINE ); - owner->session->WritePoint( pt0 ); - owner->session->WritePoint( pt1 ); + owner->fLink->StartMessage( AS_STROKE_LINE ); + owner->fLink->Attach( pt0 ); + owner->fLink->Attach( pt1 ); - // this modifies our pen location, so we invalidate the flag. + // this modifies our pen location, so we invalidate the flag. fState->flags |= B_VIEW_PEN_LOC_BIT; } } //--------------------------------------------------------------------------- -void BView::StrokeShape(BShape* shape, pattern p){ +void BView::StrokeShape(BShape* shape, pattern p) +{ if ( !shape ) return; @@ -2594,25 +2828,26 @@ void BView::StrokeShape(BShape* shape, pattern p){ if ( sd->opCount == 0 || sd->ptCount == 0) return; - if (owner){ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_STROKE_SHAPE ); - // ???: Do we need this? - owner->session->WriteRect( shape->Bounds() ); - owner->session->WriteInt32( sd->opCount ); - owner->session->WriteInt32( sd->ptCount ); - owner->session->WriteData( sd->opList, sd->opCount ); - owner->session->WriteData( sd->ptList, sd->ptCount ); + owner->fLink->StartMessage( AS_STROKE_SHAPE ); + owner->fLink->Attach( shape->Bounds() ); + owner->fLink->Attach( sd->opCount ); + owner->fLink->Attach( sd->ptCount ); + owner->fLink->Attach( sd->opList, sd->opCount ); + owner->fLink->Attach( sd->ptList, sd->ptCount ); } } //--------------------------------------------------------------------------- -void BView::FillShape(BShape* shape, pattern p){ +void BView::FillShape(BShape* shape, pattern p) +{ if ( !shape ) return; @@ -2620,33 +2855,36 @@ void BView::FillShape(BShape* shape, pattern p){ if ( sd->opCount == 0 || sd->ptCount == 0) return; - if (owner){ + if (owner) + { check_lock(); if ( _is_new_pattern( fState->patt, p ) ) SetPattern( p ); - owner->session->WriteInt32( AS_FILL_SHAPE ); - // ???: Do we need this? - owner->session->WriteRect( shape->Bounds() ); - owner->session->WriteInt32( sd->opCount ); - owner->session->WriteInt32( sd->ptCount ); - owner->session->WriteData( sd->opList, sd->opCount ); - owner->session->WriteData( sd->ptList, sd->ptCount ); + owner->fLink->StartMessage( AS_FILL_SHAPE ); + owner->fLink->Attach( shape->Bounds() ); + owner->fLink->Attach( sd->opCount ); + owner->fLink->Attach( sd->ptCount ); + owner->fLink->Attach( sd->opList, sd->opCount ); + owner->fLink->Attach( sd->ptList, sd->ptCount ); } } //--------------------------------------------------------------------------- -void BView::BeginLineArray(int32 count){ - if (owner){ +void BView::BeginLineArray(int32 count) +{ + if (owner) + { if (count <= 0) debugger("Calling BeginLineArray with a count <= 0"); check_lock_no_pick(); - if (comm){ - delete comm->array; + if (comm) + { + delete [] comm->array; delete comm; } @@ -2660,14 +2898,17 @@ void BView::BeginLineArray(int32 count){ //--------------------------------------------------------------------------- -void BView::AddLine(BPoint pt0, BPoint pt1, rgb_color col){ - if (owner){ +void BView::AddLine(BPoint pt0, BPoint pt1, rgb_color col) +{ + if (owner) + { if (!comm) - debugger("Can't call AddLine before BeginLineArray"); + debugger("BeginLineArray must be called before using AddLine"); check_lock_no_pick(); - if (comm->count < comm->maxCount){ + if (comm->count < comm->maxCount) + { comm->array[ comm->count ].startX = pt0.x; comm->array[ comm->count ].startY = pt0.y; comm->array[ comm->count ].endX = pt1.x; @@ -2682,19 +2923,19 @@ void BView::AddLine(BPoint pt0, BPoint pt1, rgb_color col){ //--------------------------------------------------------------------------- -void BView::EndLineArray(){ +void BView::EndLineArray() +{ if(owner){ if (!comm) debugger("Can't call EndLineArray before BeginLineArray"); check_lock(); - owner->session->WriteInt32( AS_LAYER_LINE_ARRAY ); - owner->session->WriteInt32( comm->count ); - owner->session->WriteData( comm->array, - comm->count * sizeof(_array_hdr_) ); + owner->fLink->StartMessage( AS_LAYER_LINE_ARRAY ); + owner->fLink->Attach( comm->count ); + owner->fLink->Attach(comm->array,comm->count * sizeof(_array_hdr_) ); - delete comm->array; + delete [] comm->array; delete comm; comm = NULL; } @@ -2702,77 +2943,86 @@ void BView::EndLineArray(){ //--------------------------------------------------------------------------- -void BView::BeginPicture(BPicture* a_picture){ - if (do_owner_check()){ - if (a_picture && a_picture->usurped == NULL){ +void BView::BeginPicture(BPicture* a_picture) +{ + if (do_owner_check()) + { + if (a_picture && a_picture->usurped == NULL) + { a_picture->usurp(cpicture); cpicture = a_picture; - owner->session->WriteInt32( AS_LAYER_BEGIN_PICTURE ); + owner->fLink->StartMessage( AS_LAYER_BEGIN_PICTURE ); } } } //--------------------------------------------------------------------------- -void BView::AppendToPicture(BPicture* a_picture){ +void BView::AppendToPicture(BPicture* a_picture) +{ check_lock(); - if (a_picture && a_picture->usurped == NULL){ + if (a_picture && a_picture->usurped == NULL) + { int32 token = a_picture->token; - if (token == -1){ + if (token == -1) + { BeginPicture(a_picture); } - else{ + else + { a_picture->usurped = cpicture; a_picture->set_token(-1); - owner->session->WriteInt32(AS_LAYER_APPEND_TO_PICTURE); - owner->session->WriteInt32( token ); + owner->fLink->StartMessage(AS_LAYER_APPEND_TO_PICTURE); + owner->fLink->Attach( token ); } } } //--------------------------------------------------------------------------- -BPicture* BView::EndPicture(){ - if (do_owner_check()){ - if (cpicture){ +BPicture* BView::EndPicture() +{ + if (do_owner_check()) + { + if (cpicture) + { int32 token; - owner->session->WriteInt32(AS_LAYER_END_PICTURE); - owner->session->Sync(); + owner->fLink->StartMessage(AS_LAYER_END_PICTURE); + owner->fLink->Flush(); - owner->session->ReadInt32( &token ); - - BPicture *a_picture = cpicture; - cpicture = a_picture->step_down(); - a_picture->set_token(token); - - return a_picture; + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + { + if(owner->fLink->Read( &token ) == B_OK) + { + BPicture *a_picture = cpicture; + cpicture = a_picture->step_down(); + a_picture->set_token(token); + return a_picture; + } + } } - else - return NULL; } - else - return NULL; + + return NULL; } //--------------------------------------------------------------------------- -void BView::SetViewBitmap(const BBitmap* bitmap, - BRect srcRect, BRect dstRect, - uint32 followFlags, - uint32 options) +void BView::SetViewBitmap(const BBitmap* bitmap, BRect srcRect, BRect dstRect, + uint32 followFlags, uint32 options) { setViewImage(bitmap, srcRect, dstRect, followFlags, options); } //--------------------------------------------------------------------------- -void BView::SetViewBitmap(const BBitmap* bitmap, - uint32 followFlags, - uint32 options) +void BView::SetViewBitmap(const BBitmap* bitmap,uint32 followFlags,uint32 options) { BRect rect; if (bitmap) @@ -2785,22 +3035,23 @@ void BView::SetViewBitmap(const BBitmap* bitmap, //--------------------------------------------------------------------------- -void BView::ClearViewBitmap(){ +void BView::ClearViewBitmap() +{ setViewImage(NULL, BRect(), BRect(), 0, 0); } //--------------------------------------------------------------------------- -status_t BView::SetViewOverlay(const BBitmap* overlay, - BRect srcRect, BRect dstRect, - rgb_color* colorKey, - uint32 followFlags, - uint32 options) +status_t BView::SetViewOverlay(const BBitmap* overlay, BRect srcRect, BRect dstRect, + rgb_color *colorKey, uint32 followFlags, uint32 options) { status_t err = setViewImage(overlay, srcRect, dstRect, followFlags, - options | 0x4); - // read the color that will be treated as transparent - owner->session->ReadData( colorKey, sizeof(rgb_color) ); + options | 0x4); + + // TODO: Incomplete? + + // read the color that will be treated as transparent + owner->fLink->Read( colorKey ); return err; } @@ -2808,8 +3059,7 @@ status_t BView::SetViewOverlay(const BBitmap* overlay, //--------------------------------------------------------------------------- status_t BView::SetViewOverlay(const BBitmap* overlay, rgb_color* colorKey, - uint32 followFlags, - uint32 options) + uint32 followFlags, uint32 options) { BRect rect; if (overlay) @@ -2818,80 +3068,99 @@ status_t BView::SetViewOverlay(const BBitmap* overlay, rgb_color* colorKey, rect.OffsetTo(0, 0); status_t err = setViewImage(overlay, rect, rect, followFlags, - options | 0x4); - // read the color that will be treated as transparent - owner->session->ReadData( colorKey, sizeof(rgb_color) ); - + options | 0x4); + + // TODO: Incomplete? + + // read the color that will be treated as transparent + owner->fLink->Read( colorKey ); + return err; } //--------------------------------------------------------------------------- -void BView::ClearViewOverlay(){ +void BView::ClearViewOverlay() +{ setViewImage(NULL, BRect(), BRect(), 0, 0); } //--------------------------------------------------------------------------- -void BView::CopyBits(BRect src, BRect dst){ +void BView::CopyBits(BRect src, BRect dst) +{ if ( !src.IsValid() || !dst.IsValid() ) return; - if (do_owner_check()){ - owner->session->WriteInt32(AS_LAYER_COPY_BITS); - owner->session->WriteRect( src ); - owner->session->WriteRect( dst ); + if (do_owner_check()) + { + owner->fLink->StartMessage( AS_LAYER_COPY_BITS); + owner->fLink->Attach( src ); + owner->fLink->Attach( dst ); } } //--------------------------------------------------------------------------- -void BView::DrawPicture(const BPicture* a_picture){ +void BView::DrawPicture(const BPicture* a_picture) +{ if (!a_picture) return; status_t err; DrawPictureAsync(a_picture, PenLocation()); - owner->session->WriteInt32( SERVER_TRUE ); - owner->session->Sync(); - - owner->session->ReadInt32( &err ); + owner->fLink->Attach( SERVER_TRUE ); + owner->fLink->Flush(); + + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + owner->fLink->Read( &err ); } //--------------------------------------------------------------------------- -void BView::DrawPicture(const BPicture* a_picture, BPoint where){ +void BView::DrawPicture(const BPicture* a_picture, BPoint where) +{ if (!a_picture) return; status_t err; DrawPictureAsync( a_picture, where ); - owner->session->WriteInt32( SERVER_TRUE ); - owner->session->Sync(); + owner->fLink->Attach( SERVER_TRUE ); + owner->fLink->Flush(); - owner->session->ReadInt32( &err ); + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + owner->fLink->Read( &err ); } //--------------------------------------------------------------------------- -void BView::DrawPicture(const char* filename, long offset, BPoint where){ +void BView::DrawPicture(const char* filename, long offset, BPoint where) +{ if (!filename) return; status_t err; DrawPictureAsync( filename, offset, where ); - owner->session->WriteInt32( SERVER_TRUE ); - owner->session->Sync(); + owner->fLink->Attach( SERVER_TRUE ); + owner->fLink->Flush(); - owner->session->ReadInt32( &err ); + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode == SERVER_TRUE) + owner->fLink->Read( &err ); } //--------------------------------------------------------------------------- -void BView::DrawPictureAsync(const BPicture* a_picture){ +void BView::DrawPictureAsync(const BPicture* a_picture) +{ if (!a_picture) return; @@ -2900,94 +3169,105 @@ void BView::DrawPictureAsync(const BPicture* a_picture){ //--------------------------------------------------------------------------- -void BView::DrawPictureAsync(const BPicture* a_picture, BPoint where){ +void BView::DrawPictureAsync(const BPicture* a_picture, BPoint where) +{ if (!a_picture) return; - if (do_owner_check() && a_picture->token > 0) { - owner->session->WriteInt32( AS_LAYER_DRAW_PICTURE ); - owner->session->WriteInt32( a_picture->token ); - owner->session->WritePoint( where ); + if (do_owner_check() && a_picture->token > 0) + { + owner->fLink->StartMessage( AS_LAYER_DRAW_PICTURE ); + owner->fLink->Attach( a_picture->token ); + owner->fLink->Attach( where ); } } //--------------------------------------------------------------------------- -void BView::DrawPictureAsync(const char* filename, long offset, BPoint where){ +void BView::DrawPictureAsync(const char* filename, long offset, BPoint where) +{ if (!filename) return; -// TODO: test, implement + // TODO: test and implement } //--------------------------------------------------------------------------- -void BView::Invalidate(BRect invalRect){ +void BView::Invalidate(BRect invalRect) +{ if ( !invalRect.IsValid() ) return; - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_INVAL_RECT ); - owner->session->WriteRect( invalRect ); - // ... because we want to see the results ASAP - owner->session->Sync(); + owner->fLink->StartMessage( AS_LAYER_INVAL_RECT ); + owner->fLink->Attach( invalRect ); + owner->fLink->Flush(); } } //--------------------------------------------------------------------------- -void BView::Invalidate(const BRegion* invalRegion){ +void BView::Invalidate(const BRegion* invalRegion) +{ if ( !invalRegion ) return; - if (owner){ + if (owner) + { check_lock(); int32 noOfRects = 0; noOfRects = const_cast(invalRegion)->CountRects(); - owner->session->WriteInt32( AS_LAYER_INVAL_REGION ); - owner->session->WriteInt32( noOfRects ); + owner->fLink->StartMessage( AS_LAYER_INVAL_REGION ); + owner->fLink->Attach( noOfRects ); - for (int i=0; isession->WriteRect( const_cast(invalRegion)->RectAt(i) ); - } - // ... becasue we want to see the results ASAP - owner->session->Sync(); + for (int i=0; ifLink->Attach( const_cast(invalRegion)->RectAt(i) ); + + owner->fLink->Flush(); } } //--------------------------------------------------------------------------- -void BView::Invalidate(){ +void BView::Invalidate() +{ Invalidate( Bounds() ); } //--------------------------------------------------------------------------- -void BView::InvertRect(BRect r){ +void BView::InvertRect(BRect r) +{ - if (owner){ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_INVERT_RECT ); - owner->session->WriteRect( r ); + owner->fLink->StartMessage( AS_LAYER_INVERT_RECT ); + owner->fLink->Attach( r ); } } // View Hierarchy Functions //--------------------------------------------------------------------------- -void BView::AddChild(BView* child, BView* before){ -STRACE(("BView(%s)::AddChild(child='%s' before='%s')\n", this->Name(), - child? child->Name(): "NULL", - before? before->Name(): "NULL")); +void BView::AddChild(BView* child, BView* before) +{ + STRACE(("BView(%s)::AddChild(child='%s' before='%s')\n", + this->Name() ? this->Name(): "NULL", + child && child->Name() ? child->Name(): "NULL", + before && before->Name() ? before->Name(): "NULL")); + if ( !child ) return; if (child->parent != NULL) - debugger("AddChild failed - the view already belongs to someone else."); + debugger("AddChild failed - the view already has a parent."); bool lockedByAddChild = false; if ( owner && !(owner->IsLocked()) ){ @@ -2998,44 +3278,52 @@ STRACE(("BView(%s)::AddChild(child='%s' before='%s')\n", this->Name(), if ( !addToList( child, before ) ) debugger("AddChild failed - cannot find 'before' view."); - if ( owner ){ + if ( owner ) + { check_lock(); - - STRACE(("BView(%s)::AddChild(child='%s' before='%s')... contacting app_server\n", this->Name(), - child? child->Name(): "NULL", - before? before->Name(): "NULL")); + + STRACE(("BView(%s)::AddChild(child='%s' before='%s')... contacting app_server\n", + this->Name() ? this->Name(): "NULL", + child && child->Name() ? child->Name(): "NULL", + before && before->Name() ? before->Name(): "NULL")); child->setOwner( this->owner); attachView( child ); - + if ( lockedByAddChild ) owner->Unlock(); } + // BVTRACE; - PrintTree(); +// PrintTree(); // PrintToStream(); } //--------------------------------------------------------------------------- -bool BView::RemoveChild(BView* child){ -STRACE(("BView(%s)::RemoveChild(%s)\n", this->Name(), child->Name() )); +bool BView::RemoveChild(BView* child) +{ + STRACE(("BView(%s)::RemoveChild(%s)\n", this->Name(), child->Name() )); if (!child) return false; - + bool rv = child->removeSelf(); + // BVTRACE; - PrintTree(); +// PrintTree(); + return rv; } //--------------------------------------------------------------------------- -int32 BView::CountChildren() const{ +int32 BView::CountChildren() const +{ uint32 noOfChildren = 0; BView *aChild = first_child; - while ( aChild != NULL ) { + while ( aChild != NULL ) + { noOfChildren++; aChild = aChild->next_sibling; } @@ -3045,11 +3333,13 @@ int32 BView::CountChildren() const{ //--------------------------------------------------------------------------- -BView* BView::ChildAt(int32 index) const{ +BView* BView::ChildAt(int32 index) const +{ int32 noOfChildren = 0; BView *aChild = first_child; - while ( aChild != NULL && noOfChildren < index ) { + while ( aChild != NULL && noOfChildren < index ) + { noOfChildren++; aChild = aChild->next_sibling; } @@ -3059,63 +3349,71 @@ BView* BView::ChildAt(int32 index) const{ //--------------------------------------------------------------------------- -BView* BView::NextSibling() const{ +BView* BView::NextSibling() const +{ return next_sibling; } //--------------------------------------------------------------------------- -BView* BView::PreviousSibling() const{ +BView* BView::PreviousSibling() const +{ return prev_sibling; } //--------------------------------------------------------------------------- -bool BView::RemoveSelf(){ +bool BView::RemoveSelf() +{ return removeSelf(); } //--------------------------------------------------------------------------- -BView* BView::Parent() const{ +BView* BView::Parent() const +{ return parent; } //--------------------------------------------------------------------------- -BView* BView::FindView(const char* name) const{ +BView* BView::FindView(const char* name) const +{ return findView(this, name); } //--------------------------------------------------------------------------- -void BView::MoveBy(float dh, float dv){ +void BView::MoveBy(float dh, float dv) +{ MoveTo( originX + dh, originY + dv ); } //--------------------------------------------------------------------------- -void BView::MoveTo(BPoint where){ +void BView::MoveTo(BPoint where) +{ MoveTo(where.x, where.y); } //--------------------------------------------------------------------------- -void BView::MoveTo(float x, float y){ +void BView::MoveTo(float x, float y) +{ if ( x == originX && y == originY ) return; - // BeBook sez we should do this. We'll do it without. So... - /*x = roundf( x ); - y = roundf( y );*/ + // BeBook says we should do this. We'll do it without. So... +// x = roundf( x ); +// y = roundf( y ); - check_lock(); - - if (owner){ - owner->session->WriteInt32( AS_LAYER_MOVETO ); - owner->session->WriteFloat( x ); - owner->session->WriteFloat( y ); + if (owner) + { + check_lock(); + owner->fLink->StartMessage( AS_LAYER_MOVETO ); + owner->fLink->Attach( x ); + owner->fLink->Attach( y ); fState->flags |= B_VIEW_COORD_BIT; } @@ -3126,27 +3424,28 @@ void BView::MoveTo(float x, float y){ //--------------------------------------------------------------------------- -void BView::ResizeBy(float dh, float dv){ +void BView::ResizeBy(float dh, float dv) +{ ResizeTo( fBounds.right + dh, fBounds.bottom + dv ); } //--------------------------------------------------------------------------- -void BView::ResizeTo(float width, float height){ - if ( width == fBounds.Width() && - height == fBounds.Height() ) +void BView::ResizeTo(float width, float height) +{ + if ( width == fBounds.Width() && height == fBounds.Height() ) return; - // BeBook sez we should do this. We'll do it without. So... - /*width = roundf( width ); - height = roundf( height );*/ + // BeBook says we should do this. We'll do it without. So... +// width = roundf( width ); +// height = roundf( height ); - check_lock(); - - if (owner){ - owner->session->WriteInt32( AS_LAYER_RESIZETO ); - owner->session->WriteFloat( width ); - owner->session->WriteFloat( height ); + if (owner) + { + check_lock(); + owner->fLink->StartMessage( AS_LAYER_RESIZETO ); + owner->fLink->Attach( width ); + owner->fLink->Attach( height ); fState->flags |= B_VIEW_COORD_BIT; } @@ -3156,23 +3455,25 @@ void BView::ResizeTo(float width, float height){ } //--------------------------------------------------------------------------- - // Inherited Methods (virtual) //--------------------------------------------------------------------------- -status_t BView::GetSupportedSuites(BMessage* data){ +status_t BView::GetSupportedSuites(BMessage* data) +{ status_t err = B_OK; if (!data) err = B_BAD_VALUE; - if (!err){ + if (!err) + { err = data->AddString("Suites", "suite/vnd.Be-view"); - if (!err){ + if (!err) + { BPropertyInfo propertyInfo(viewPropInfo); err = data->AddFlat("message", &propertyInfo); - if (!err){ + + if (!err) err = BHandler::GetSupportedSuites(data); - } } } return err; @@ -3180,8 +3481,8 @@ status_t BView::GetSupportedSuites(BMessage* data){ //------------------------------------------------------------------------------ -BHandler* BView::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier, - int32 what, const char* property) +BHandler* BView::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier, + int32 what, const char* property) { if (msg->what == B_WINDOW_MOVE_BY) return this; @@ -3193,19 +3494,24 @@ BHandler* BView::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifie { case B_ERROR: break; + case 0: case 1: case 2: case 3: case 5: return this; - + + case 4: - if (fShelf){ + { + if (fShelf) + { msg->PopSpecifier(); return fShelf; } - else{ + else + { BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD); replyMsg.AddInt32( "error", B_NAME_NOT_FOUND ); replyMsg.AddString( "message", "This window doesn't have a self"); @@ -3213,57 +3519,73 @@ BHandler* BView::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifie return NULL; } break; + } + case 6: case 7: case 8: - if (first_child){ + { + if (first_child) + { BView *child; - switch( msg->what ){ + switch( msg->what ) + { case B_INDEX_SPECIFIER: + { int32 index; msg->FindInt32("data", &index); child = ChildAt( index ); break; - + } case B_REVERSE_INDEX_SPECIFIER: + { int32 rindex; msg->FindInt32("data", &rindex); child = ChildAt( CountChildren() - rindex ); break; - + } case B_NAME_SPECIFIER: + { const char *name; msg->FindString("data", &name); child = FindView( name ); delete name; break; - + } default: + { child = NULL; break; + } } - if ( child != NULL ){ + + if ( child != NULL ) + { msg->PopSpecifier(); return child; } - else{ - BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD); + else + { + BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD); replyMsg.AddInt32( "error", B_BAD_INDEX ); replyMsg.AddString( "message", "Cannot find view at/with specified index/name."); msg->SendReply( &replyMsg ); return NULL; } } - else{ - BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD); + else + { + BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD); replyMsg.AddInt32( "error", B_NAME_NOT_FOUND ); replyMsg.AddString( "message", "This window doesn't have children."); msg->SendReply( &replyMsg ); return NULL; } - break; + break; + } + default: + break; } - return BHandler::ResolveSpecifier(msg, index, specifier, what, property); } @@ -3276,8 +3598,12 @@ void BView::MessageReceived( BMessage *msg ) int32 index; status_t err; - if (msg->HasSpecifiers()){ - + if (!msg->HasSpecifiers()) + { + BHandler::MessageReceived( msg ); + return; + } + err = msg->GetCurrentSpecifier(&index, &specifier, &what, &prop); if (err == B_OK) { @@ -3285,107 +3611,120 @@ void BView::MessageReceived( BMessage *msg ) switch (msg->what) { - case B_GET_PROPERTY:{ + case B_GET_PROPERTY: + { replyMsg.what = B_NO_ERROR; replyMsg.AddInt32( "error", B_OK ); if (strcmp(prop, "Frame") ==0 ) - { replyMsg.AddRect( "result", Frame()); - } - else if (strcmp(prop, "Hidden") ==0 ) - { + else + if (strcmp(prop, "Hidden") ==0 ) replyMsg.AddBool( "result", IsHidden()); - } - }break; - - case B_SET_PROPERTY:{ + + break; + } + case B_SET_PROPERTY: + { if (strcmp(prop, "Frame") ==0 ) { BRect newFrame; - if (msg->FindRect( "data", &newFrame ) == B_OK){ + if (msg->FindRect( "data", &newFrame ) == B_OK) + { MoveTo( newFrame.LeftTop() ); ResizeTo( newFrame.right, newFrame.bottom); replyMsg.what = B_NO_ERROR; replyMsg.AddInt32( "error", B_OK ); } - else{ + else + { replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD; replyMsg.AddInt32( "error", B_BAD_SCRIPT_SYNTAX ); replyMsg.AddString( "message", "Didn't understand the specifier(s)" ); } } - - else if (strcmp(prop, "Hidden") ==0 ) + else + if (strcmp(prop, "Hidden") ==0 ) { - bool newHiddenState; - if (msg->FindBool( "data", &newHiddenState ) == B_OK){ - if ( !IsHidden() && newHiddenState == true ){ + bool newHiddenState; + if (msg->FindBool( "data", &newHiddenState ) == B_OK) + { + if ( !IsHidden() && newHiddenState == true ) + { Hide(); replyMsg.what = B_NO_ERROR; replyMsg.AddInt32( "error", B_OK ); } - else if ( IsHidden() && newHiddenState == false ){ + else + if ( IsHidden() && newHiddenState == false ) + { Show(); - replyMsg.what = B_NO_ERROR; + replyMsg.what = B_NO_ERROR; replyMsg.AddInt32( "error", B_OK ); } - else{ - replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD; + else + { + replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD; replyMsg.AddInt32( "error", B_BAD_SCRIPT_SYNTAX ); replyMsg.AddString( "message", "Didn't understand the specifier(s)" ); } } - else{ - replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD; + else + { + replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD; replyMsg.AddInt32( "error", B_BAD_SCRIPT_SYNTAX ); replyMsg.AddString( "message", "Didn't understand the specifier(s)" ); } } - }break; - - case B_COUNT_PROPERTIES:{ + break; + } + case B_COUNT_PROPERTIES: + { if (strcmp(prop, "View") ==0 ) { replyMsg.what = B_NO_ERROR; replyMsg.AddInt32( "error", B_OK ); replyMsg.AddInt32( "result", CountChildren()); } - - }break; + break; + } } + msg->SendReply( &replyMsg ); + } - else{ + else + { BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD); replyMsg.AddInt32( "error" , B_BAD_SCRIPT_SYNTAX ); replyMsg.AddString( "message", "Didn't understand the specifier(s)" ); msg->SendReply( &replyMsg ); - } + } // end if(err==B_OK) - } // END: if (msg->HasSpecifiers()) - else - BHandler::MessageReceived( msg ); } //--------------------------------------------------------------------------- -status_t BView::Perform(perform_code d, void* arg){ +status_t BView::Perform(perform_code d, void* arg) +{ return B_BAD_VALUE; } +//--------------------------------------------------------------------------- // Private Functions //--------------------------------------------------------------------------- -void BView::InitData(BRect frame, const char *name, uint32 resizingMode, uint32 flags){ - - // Info: The name of the view is set by BHandler constructor - +void BView::InitData(BRect frame, const char *name, uint32 resizingMode, uint32 flags) +{ + // Info: The name of the view is set by BHandler constructor + + STRACE(("BView::InitData: enter\n")); + // initialize members fFlags = (resizingMode & _RESIZE_MASK_) | (flags & ~_RESIZE_MASK_); @@ -3425,9 +3764,11 @@ void BView::InitData(BRect frame, const char *name, uint32 resizingMode, uint32 //--------------------------------------------------------------------------- -void BView::removeCommArray(){ - if( comm ){ - delete comm->array; +void BView::removeCommArray() +{ + if( comm ) + { + delete [] comm->array; delete comm; comm = NULL; } @@ -3437,9 +3778,8 @@ void BView::removeCommArray(){ void BView::setOwner(BWindow *theOwner) { - if (!theOwner){ + if (!theOwner) removeCommArray(); - } if (owner != theOwner && owner) { @@ -3474,43 +3814,44 @@ void BView::setOwner(BWindow *theOwner) //--------------------------------------------------------------------------- -bool BView::removeSelf(){ -STRACE(("BView(%s)::removeSelf()...\n", this->Name() )); -/* # check for dirty flags - by updateCachedState() - * # check for dirty flags on 'child' children - by updateCachedState() - * # handle if in middle of Begin/EndLineArray() - by setOwner(NULL) - * # remove trom the main tree - by removeFromList() - * # handle if child is the default button - HERE - * # handle if child is the focus view - by setOwner(NULL) - * # handle if child is the menu bar - HERE - * # handle if child token is = fLastViewToken - by setOwner(NULL) - * # contact app_server - HERE - * # set a new owner = NULL - by setOwner(NULL) - */ +bool BView::removeSelf() +{ + STRACE(("BView(%s)::removeSelf()...\n", this->Name() )); + +/* + # check for dirty flags - by updateCachedState() + # check for dirty flags on 'child' children - by updateCachedState() + # handle if in middle of Begin/EndLineArray() - by setOwner(NULL) + # remove trom the main tree - by removeFromList() + # handle if child is the default button - HERE + # handle if child is the focus view - by setOwner(NULL) + # handle if child is the menu bar - HERE + # handle if child token is = fLastViewToken - by setOwner(NULL) + # contact app_server - HERE + # set a new owner = NULL - by setOwner(NULL) +*/ bool returnValue = true; - if (!parent){ + if (!parent) + { STRACE(("BView(%s)::removeSelf()... NO parent\n", this->Name())); return false; } - check_lock(); - - if (owner){ + if (owner) + { + check_lock(); updateCachedState(); - if (owner->fDefaultButton == this){ + if (owner->fDefaultButton == this) owner->SetDefaultButton( NULL ); - } - if (owner->fKeyMenuBar == this){ + if (owner->fKeyMenuBar == this) owner->fKeyMenuBar = NULL; - } - if (owner->fLastViewToken == _get_object_token_(this)){ + if (owner->fLastViewToken == _get_object_token_(this)) owner->fLastViewToken = B_NULL_TOKEN; - } callDetachHooks( this ); @@ -3518,7 +3859,7 @@ STRACE(("BView(%s)::removeSelf()...\n", this->Name() )); setOwner( NULL ); - ownerZ->session->WriteInt32( AS_LAYER_DELETE ); + ownerZ->fLink->StartMessage( AS_LAYER_DELETE ); } returnValue = removeFromList(); @@ -3527,27 +3868,31 @@ STRACE(("BView(%s)::removeSelf()...\n", this->Name() )); next_sibling = NULL; prev_sibling = NULL; -STRACE(("DONE: BView(%s)::removeSelf()\n", this->Name())); + STRACE(("DONE: BView(%s)::removeSelf()\n", this->Name())); + return returnValue; } //--------------------------------------------------------------------------- -bool BView::callDetachHooks( BView *aView ){ +bool BView::callDetachHooks( BView *aView ) +{ // check_clock(); - // call the hook function: + // call the hook function: aView->DetachedFromWindow(); - // we attach all its children + // we attach all its children BView *child; child = aView->first_child; - while( child ) { + while( child ) + { aView->callDetachHooks(child); child = child->next_sibling; } - // call the hook function: + + // call the hook function: aView->AllDetached(); return true; @@ -3555,15 +3900,18 @@ bool BView::callDetachHooks( BView *aView ){ //--------------------------------------------------------------------------- -bool BView::removeFromList(){ +bool BView::removeFromList() +{ - if (parent->first_child == this){ + if (parent->first_child == this) + { parent->first_child = next_sibling; if (next_sibling) next_sibling->prev_sibling = NULL; } - else{ + else + { prev_sibling->next_sibling = next_sibling; if (next_sibling) @@ -3574,14 +3922,16 @@ bool BView::removeFromList(){ //--------------------------------------------------------------------------- -bool BView::addToList(BView *aView, BView *before){ +bool BView::addToList(BView *aView, BView *before) +{ if ( !aView ) return false; BView *current = first_child; BView *last = current; - while( current && current != before){ + while( current && current != before) + { last = current; current = current->next_sibling; } @@ -3589,95 +3939,103 @@ bool BView::addToList(BView *aView, BView *before){ if( !current && before ) return false; - // we're at begining of the list, OR between two elements - if( current ){ - if ( current == first_child ){ + // we're at begining of the list, OR between two elements + if( current ) + { + if ( current == first_child ) + { aView->next_sibling = current; current->prev_sibling = aView; first_child = aView; } - else{ + else + { aView->next_sibling = current; aView->prev_sibling = current->prev_sibling; current->prev_sibling->next_sibling = aView; current->prev_sibling = aView; } } + else + { // we have reached the end of the list - else{ - // if last!=NULL then we add to the end. - if ( last ){ + + // if last!=NULL then we add to the end. Otherwise, aView is the + // first chiild in the list + if ( last ) + { last->next_sibling = aView; aView->prev_sibling = last; } - // if last==NULL, then aView is the first child in the list - else{ + else first_child = aView; - } } - aView->parent = this; + aView->parent = this; return true; } //--------------------------------------------------------------------------- -bool BView::attachView(BView *aView){ -// LEAVE the following line commented!!! +bool BView::attachView(BView *aView) +{ + // LEAVE the following line commented!!! // check_lock(); -/* INFO: - * 'check_lock()' checks for a lock on the window and then, modifies - * BWindow::fLastViewToken with the one of the view witch called check_lock() - * , and sends it to the app_server to be the view for witch current actions - * are made. - * This is a good solution for attaching a view to the server, but, this is done - * many times, and because I suspect app_server holds ALL the 'Layer' pointers - * in a hash list indexed by view tokens, a costly search action is made - * for each view to be attached. - * I think a better solution(also programming-wise), is to attach the number - * of a view's children. Although this requires a list , the - * time to do it will be much smaller than searching a hash list. - * On the server, only a recursive method is needed for building the tree... - */ +/* + INFO: - owner->session->WriteInt32( AS_LAYER_CREATE ); - owner->session->WriteInt32( _get_object_token_( aView ) ); - owner->session->WriteString( aView->Name() ); - owner->session->WriteRect( aView->Frame() ); - owner->session->WriteUInt32( aView->ResizingMode() ); - owner->session->WriteUInt32( aView->Flags() ); - owner->session->WriteBool( aView->IsHidden(aView) ); - owner->session->WriteInt32( aView->CountChildren() ); + 'check_lock()' checks for a lock on the window and then, sets + BWindow::fLastViewToken to the one of the view which called check_lock(), + and sends it to the app_server to be the view for which current actions + are made. +*/ + + if (aView->top_level_view) + owner->fLink->StartMessage( AS_LAYER_CREATE_ROOT ); + else + owner->fLink->StartMessage( AS_LAYER_CREATE ); + owner->fLink->Attach( _get_object_token_( aView ) ); + owner->fLink->AttachString( aView->Name() ); + owner->fLink->Attach( aView->Frame() ); + owner->fLink->Attach( aView->ResizingMode() ); + owner->fLink->Attach( aView->Flags() ); + owner->fLink->Attach( aView->IsHidden(aView) ); + owner->fLink->Attach( aView->CountChildren() ); aView->setCachedState(); - - // call the hook function: + + // call the hook function: aView->AttachedToWindow(); - // we attach all its children + // we attach all its children BView *child; child = aView->first_child; - while( child ) { + while( child ) + { aView->attachView(child); child = child->next_sibling; } - // call the hook function: + + // call the hook function: aView->AllAttached(); + owner->fLink->Flush(); return true; } //--------------------------------------------------------------------------- -void BView::deleteView( BView* aView){ +void BView::deleteView( BView* aView) +{ BView *child; child = aView->first_child; - while( child ) { + while( child ) + { deleteView(child); child = child->next_sibling; } @@ -3687,13 +4045,16 @@ void BView::deleteView( BView* aView){ //--------------------------------------------------------------------------- -BView* BView::findView(const BView* aView, const char* viewName) const{ +BView* BView::findView(const BView* aView, const char* viewName) const +{ if ( strcmp( viewName, aView->Name() ) == 0) return const_cast(aView); BView *child; - if ( (child = aView->first_child) ){ - while ( child ) { + if ( (child = aView->first_child) ) + { + while ( child ) + { BView* view = NULL; if ( (view = findView( child, viewName )) ) return view; @@ -3706,88 +4067,100 @@ BView* BView::findView(const BView* aView, const char* viewName) const{ //--------------------------------------------------------------------------- -void BView::setCachedState(){ +void BView::setCachedState() +{ setFontState( &(fState->font), fState->fontFlags ); - owner->session->WriteInt32( AS_LAYER_SET_STATE ); - owner->session->WritePoint( fState->penPosition ); - owner->session->WriteFloat( fState->penSize ); - owner->session->WriteData( &(fState->highColor), sizeof(rgb_color) ); - owner->session->WriteData( &(fState->lowColor), sizeof(rgb_color) ); - owner->session->WriteData( &(fState->viewColor), sizeof(rgb_color) ); - owner->session->WriteData( &(fState->patt), sizeof(pattern) ); - owner->session->WriteInt8( (int8)fState->drawingMode ); - owner->session->WritePoint( fState->coordSysOrigin ); - owner->session->WriteInt8( (int8)fState->lineJoin ); - owner->session->WriteInt8( (int8)fState->lineCap ); - owner->session->WriteFloat( fState->miterLimit ); - owner->session->WriteInt8( (int8)fState->alphaSrcMode ); - owner->session->WriteInt8( (int8)fState->alphaFncMode ); - owner->session->WriteFloat( fState->scale ); - owner->session->WriteBool( fState->fontAliasing ); - // we send the 'local' clipping region... if we have one... + owner->fLink->StartMessage( AS_LAYER_SET_STATE ); + owner->fLink->Attach( fState->penPosition ); + owner->fLink->Attach( fState->penSize ); + owner->fLink->Attach( fState->highColor ); + owner->fLink->Attach( fState->lowColor ); + owner->fLink->Attach( fState->viewColor ); + owner->fLink->Attach( fState->patt ); + owner->fLink->Attach( (int8)fState->drawingMode ); + owner->fLink->Attach( fState->coordSysOrigin ); + owner->fLink->Attach( (int8)fState->lineJoin ); + owner->fLink->Attach( (int8)fState->lineCap ); + owner->fLink->Attach( fState->miterLimit ); + owner->fLink->Attach( (int8)fState->alphaSrcMode ); + owner->fLink->Attach( (int8)fState->alphaFncMode ); + owner->fLink->Attach( fState->scale ); + owner->fLink->Attach( fState->fontAliasing ); + + // we send the 'local' clipping region... if we have one... int32 noOfRects = fState->clippingRegion.CountRects(); - owner->session->WriteInt32( noOfRects ); - for (int32 i = 0; i < noOfRects; i++){ - owner->session->WriteRect( fState->clippingRegion.RectAt(i) ); - } + owner->fLink->Attach( noOfRects ); + for (int32 i = 0; i < noOfRects; i++) + owner->fLink->Attach( fState->clippingRegion.RectAt(i) ); - /* Although we might have a 'local' clipping region, when we call - * BView::GetClippingRegion(...); - * we ask for the 'global' one; and that is kept on server, so we - * must invalidate B_VIEW_CLIP_REGION_BIT flag! - */ + // Although we might have a 'local' clipping region, when we call + // BView::GetClippingRegion() we ask for the 'global' one and it + // is kept on server, so we must invalidate B_VIEW_CLIP_REGION_BIT flag + fState->flags = B_VIEW_CLIP_REGION_BIT; } //--------------------------------------------------------------------------- -void BView::setFontState(const BFont* font, uint16 mask){ +void BView::setFontState(const BFont* font, uint16 mask) +{ + do_owner_check(); + + owner->fLink->StartMessage( AS_LAYER_SET_FONT_STATE ); + owner->fLink->Attach( mask ); - owner->session->WriteInt32( AS_LAYER_SET_FONT_STATE ); - owner->session->WriteUInt16( mask ); - - // always present. - if ( mask & B_FONT_FAMILY_AND_STYLE ){ + // always present. + if ( mask & B_FONT_FAMILY_AND_STYLE ) + { uint32 fontID; fontID = font->FamilyAndStyle( ); - owner->session->WriteUInt32( fontID ); + owner->fLink->Attach( fontID ); } - if ( mask & B_FONT_SIZE ){ - owner->session->WriteFloat( font->Size() ); - } + if ( mask & B_FONT_SIZE ) + owner->fLink->Attach( font->Size() ); - if ( mask & B_FONT_SHEAR ){ - owner->session->WriteFloat( font->Shear() ); - } + if ( mask & B_FONT_SHEAR ) + owner->fLink->Attach( font->Shear() ); - if ( mask & B_FONT_ROTATION ){ - owner->session->WriteFloat( font->Rotation() ); - } + if ( mask & B_FONT_ROTATION ) + owner->fLink->Attach( font->Rotation() ); - if ( mask & B_FONT_SPACING ){ - owner->session->WriteUInt8( font->Spacing() ); // uint8 - } + if ( mask & B_FONT_SPACING ) + owner->fLink->Attach( font->Spacing() ); // uint8 - if ( mask & B_FONT_ENCODING ){ - owner->session->WriteUInt8( font->Encoding() ); // uint8 - } + if ( mask & B_FONT_ENCODING ) + owner->fLink->Attach( font->Encoding() ); // uint8 - if ( mask & B_FONT_FACE ){ - owner->session->WriteUInt16( font->Face() ); // uint16 - } + if ( mask & B_FONT_FACE ) + owner->fLink->Attach( font->Face() ); // uint16 - if ( mask & B_FONT_FLAGS ){ - owner->session->WriteUInt32( font->Flags() ); // uint32 - } + if ( mask & B_FONT_FLAGS ) + owner->fLink->Attach( font->Flags() ); // uint32 } //--------------------------------------------------------------------------- -void BView::initCachedState(){ +BShelf *BView::shelf() const +{ + return fShelf; +} + +//--------------------------------------------------------------------------- + +void BView::set_shelf(BShelf *shelf) +{ + // TODO: is this all that needs done? + fShelf=shelf; +} + +//--------------------------------------------------------------------------- + +void BView::initCachedState() +{ fState->font = *be_plain_font; fState->penPosition.Set( 0.0, 0.0 ); @@ -3826,27 +4199,36 @@ void BView::initCachedState(){ fState->scale = 1.0; fState->fontAliasing = false; - - /* INFO: We include(invalidate) only B_VIEW_CLIP_REGION_BIT flag, - * because we should get the clipping region from app_server. - * The other flags do not need to be included because the data they - * represent is already in sync with app_server - app_server uses the - * same init(default) values. - */ + +/* + INFO: We include(invalidate) only B_VIEW_CLIP_REGION_BIT flag + because we should get the clipping region from app_server. + The other flags do not need to be included because the data they + represent is already in sync with app_server - app_server uses the + same init(default) values. +*/ fState->flags = B_VIEW_CLIP_REGION_BIT; - // (default) flags used to determine witch fields to archive + + // (default) flags used to determine witch fields to archive fState->archivingFlags = B_VIEW_COORD_BIT; } //--------------------------------------------------------------------------- +void BView::updateCachedState() +{ + STRACE(("BView(%s)::updateCachedState()\n", Name() )); -void BView::updateCachedState(){ - // fail if we do not have an owner -STRACE(("BView(%s)::updateCachedState()\n", Name() )); + // fail if we do not have an owner do_owner_check(); - owner->session->WriteInt32( AS_LAYER_GET_STATE ); - owner->session->Sync(); + owner->fLink->StartMessage( AS_LAYER_GET_STATE ); + owner->fLink->Flush(); + + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + + if (rCode != SERVER_TRUE) + return; uint32 fontID; float size; @@ -3859,15 +4241,15 @@ STRACE(("BView(%s)::updateCachedState()\n", Name() )); int32 noOfRects; BRect rect; - // read and set the font state - owner->session->ReadInt32( (int32*)&fontID ); - owner->session->ReadFloat( &size ); - owner->session->ReadFloat( &shear ); - owner->session->ReadFloat( &rotation ); - owner->session->ReadInt8( (int8*)&spacing ); - owner->session->ReadInt8( (int8*)&encoding ); - owner->session->ReadInt16( (int16*)&face ); - owner->session->ReadInt32( (int32*)&flags ); + // read and set the font state + owner->fLink->Read( (int32*)&fontID ); + owner->fLink->Read( &size ); + owner->fLink->Read( &shear ); + owner->fLink->Read( &rotation ); + owner->fLink->Read( (int8*)&spacing ); + owner->fLink->Read( (int8*)&encoding ); + owner->fLink->Read( (int16*)&face ); + owner->fLink->Read( (int32*)&flags ); fState->fontFlags = B_FONT_ALL; fState->font.SetFamilyAndStyle( fontID ); @@ -3879,38 +4261,39 @@ STRACE(("BView(%s)::updateCachedState()\n", Name() )); fState->font.SetFace( face ); fState->font.SetFlags( flags ); - // read and set view's state - owner->session->ReadPoint( &(fState->penPosition) ); - owner->session->ReadFloat( &(fState->penSize) ); - owner->session->ReadData( &(fState->highColor), sizeof(rgb_color) ); - owner->session->ReadData( &(fState->lowColor), sizeof(rgb_color) ); - owner->session->ReadData( &(fState->viewColor), sizeof(rgb_color) ); - owner->session->ReadData( &(fState->patt), sizeof(pattern) ); - owner->session->ReadPoint( &(fState->coordSysOrigin) ); - owner->session->ReadInt8( (int8*)&(fState->drawingMode) ); - owner->session->ReadInt8( (int8*)&(fState->lineCap) ); - owner->session->ReadInt8( (int8*)&(fState->lineJoin) ); - owner->session->ReadFloat( &(fState->miterLimit) ); - owner->session->ReadInt8( (int8*)&(fState->alphaSrcMode) ); - owner->session->ReadInt8( (int8*)&(fState->alphaFncMode) ); - owner->session->ReadFloat( &(fState->scale) ); - owner->session->ReadBool( &(fState->fontAliasing) ); + // read and set view's state + owner->fLink->Read( &(fState->penPosition) ); + owner->fLink->Read( &(fState->penSize) ); + owner->fLink->Read( &(fState->highColor) ); + owner->fLink->Read( &(fState->lowColor) ); + owner->fLink->Read( &(fState->viewColor) ); + owner->fLink->Read( &(fState->patt) ); + owner->fLink->Read( &(fState->coordSysOrigin) ); + owner->fLink->Read( (int8*)&(fState->drawingMode) ); + owner->fLink->Read( (int8*)&(fState->lineCap) ); + owner->fLink->Read( (int8*)&(fState->lineJoin) ); + owner->fLink->Read( &(fState->miterLimit) ); + owner->fLink->Read( (int8*)&(fState->alphaSrcMode) ); + owner->fLink->Read( (int8*)&(fState->alphaFncMode) ); + owner->fLink->Read( &(fState->scale) ); + owner->fLink->Read( &(fState->fontAliasing) ); - owner->session->ReadInt32( &noOfRects ); + owner->fLink->Read( &noOfRects ); fState->clippingRegion.MakeEmpty(); - for (int32 i = 0; i < noOfRects; i++){ - owner->session->ReadRect( &rect ); + for (int32 i = 0; i < noOfRects; i++) + { + owner->fLink->Read( &rect ); fState->clippingRegion.Include( rect ); } - //------------------ - owner->session->ReadFloat( &originX ); - owner->session->ReadFloat( &originY ); - owner->session->ReadRect( &fBounds ); + owner->fLink->Read( &originX ); + owner->fLink->Read( &originY ); + owner->fLink->Read( &fBounds ); fState->flags = B_VIEW_CLIP_REGION_BIT; -STRACE(("BView(%s)::updateCachedState() - DONE\n", Name() )); + + STRACE(("BView(%s)::updateCachedState() - DONE\n", Name() )); } //--------------------------------------------------------------------------- @@ -3924,26 +4307,39 @@ status_t BView::setViewImage(const BBitmap *bitmap, BRect srcRect, int32 serverToken = bitmap ? bitmap->get_server_token() : -1; status_t err; - owner->session->WriteInt32( AS_LAYER_SET_VIEW_IMAGE ); - owner->session->WriteInt32( serverToken ); - owner->session->WriteRect( srcRect ); - owner->session->WriteRect( dstRect ); - owner->session->WriteInt32( followFlags ); - owner->session->WriteInt32( options ); - owner->session->Sync(); - owner->session->ReadData( &err, sizeof(status_t) ); + owner->fLink->StartMessage( AS_LAYER_SET_VIEW_IMAGE ); + owner->fLink->Attach( serverToken ); + owner->fLink->Attach( srcRect ); + owner->fLink->Attach( dstRect ); + owner->fLink->Attach( followFlags ); + owner->fLink->Attach( options ); + owner->fLink->Flush(); + + + // TODO: this needs fixed between here and the server. + // The server should return whatever error code is needed, whether it + // is B_OK or whatever, not SERVER_TRUE. + + int32 rCode = SERVER_FALSE; + owner->fLink->GetNextReply( &rCode ); + if (rCode != SERVER_TRUE) + return B_ERROR; + + owner->fLink->Read( &err ); return err; } //--------------------------------------------------------------------------- -void BView::SetPattern(pattern pat){ - if (owner){ +void BView::SetPattern(pattern pat) +{ + if (owner) + { check_lock(); - owner->session->WriteInt32( AS_LAYER_SET_PATTERN ); - owner->session->WriteData( &pat, sizeof(pattern) ); + owner->fLink->StartMessage( AS_LAYER_SET_PATTERN ); + owner->fLink->Attach( pat ); } fState->patt = pat; @@ -3951,71 +4347,81 @@ void BView::SetPattern(pattern pat){ //--------------------------------------------------------------------------- -bool BView::do_owner_check() const{ -STRACE(("BView(%s)::do_owner_check()...", Name())); +bool BView::do_owner_check() const +{ + STRACE(("BView(%s)::do_owner_check()...", Name())); int32 serverToken = _get_object_token_(this); - if (owner){ - owner->AssertLocked(); - - if (owner->fLastViewToken != serverToken){ - STRACE(("contacting app_server... sending token: %ld\n", serverToken)); - owner->session->WriteInt32( AS_SET_CURRENT_LAYER ); - owner->session->WriteInt32( serverToken ); - - owner->fLastViewToken = serverToken; - } - else{ - STRACE(("this is the lastViewToken\n")); - } - return true; - } - else{ + if(!owner) + { debugger("View method requires owner and doesn't have one."); return false; } + + owner->AssertLocked(); + + if (owner->fLastViewToken != serverToken) + { + STRACE(("contacting app_server... sending token: %ld\n", serverToken)); + owner->fLink->StartMessage( AS_SET_CURRENT_LAYER ); + owner->fLink->Attach( serverToken ); + + owner->fLastViewToken = serverToken; + } + else + STRACE(("this is the lastViewToken\n")); + + return true; } //--------------------------------------------------------------------------- -void BView::check_lock() const{ -STRACE(("BView(%s)::check_lock()...", Name())); +void BView::check_lock() const +{ + STRACE(("BView(%s)::check_lock()...", Name() ? Name(): "NULL")); int32 serverToken = _get_object_token_(this); - - if (owner){ - owner->AssertLocked(); - - if (owner->fLastViewToken != serverToken){ - STRACE(("contacting app_server... sending token: %ld\n", serverToken)); - owner->session->WriteInt32( AS_SET_CURRENT_LAYER ); - owner->session->WriteInt32( serverToken ); - - owner->fLastViewToken = serverToken; - } - else{ - STRACE(("quiet2\n")); - } - } - else{ + + if (!owner) + { STRACE(("quiet1\n")); + return; + } + + owner->AssertLocked(); + + if (owner->fLastViewToken != serverToken) + { + STRACE(("contacting app_server... sending token: %ld\n", serverToken)); + owner->fLink->StartMessage( AS_SET_CURRENT_LAYER ); + owner->fLink->Attach( serverToken ); + + owner->fLastViewToken = serverToken; + } + else + { + STRACE(("quiet2\n")); } } //--------------------------------------------------------------------------- -void BView::check_lock_no_pick() const{ +void BView::check_lock_no_pick() const +{ if (owner) owner->AssertLocked(); } //--------------------------------------------------------------------------- -bool BView::do_owner_check_no_pick() const{ - if (owner){ +bool BView::do_owner_check_no_pick() const +{ + if (owner) + { owner->AssertLocked(); return true; } - else{ + else + { debugger("View method requires owner and doesn't have one."); return false; } @@ -4023,43 +4429,30 @@ bool BView::do_owner_check_no_pick() const{ //--------------------------------------------------------------------------- -void BView::_ReservedView2(){ -} -void BView::_ReservedView3(){ -} -void BView::_ReservedView4(){ -} -void BView::_ReservedView5(){ -} -void BView::_ReservedView6(){ -} -void BView::_ReservedView7(){ -} -void BView::_ReservedView8(){ -} +void BView::_ReservedView2(){} +void BView::_ReservedView3(){} +void BView::_ReservedView4(){} +void BView::_ReservedView5(){} +void BView::_ReservedView6(){} +void BView::_ReservedView7(){} +void BView::_ReservedView8(){} + #if !_PR3_COMPATIBLE_ -void BView::_ReservedView9(){ -} -void BView::_ReservedView10(){ -} -void BView::_ReservedView11(){ -} -void BView::_ReservedView12(){ -} -void BView::_ReservedView13(){ -} -void BView::_ReservedView14(){ -} -void BView::_ReservedView15(){ -} -void BView::_ReservedView16(){ -} +void BView::_ReservedView9(){} +void BView::_ReservedView10(){} +void BView::_ReservedView11(){} +void BView::_ReservedView12(){} +void BView::_ReservedView13(){} +void BView::_ReservedView14(){} +void BView::_ReservedView15(){} +void BView::_ReservedView16(){} #endif //--------------------------------------------------------------------------- -inline rgb_color _get_rgb_color( uint32 color ){ +inline rgb_color _get_rgb_color( uint32 color ) +{ rgb_color c; c.red = (color & 0xFF000000) >> 24; c.green = (color & 0x00FF0000) >> 16; @@ -4071,7 +4464,8 @@ inline rgb_color _get_rgb_color( uint32 color ){ //--------------------------------------------------------------------------- -inline uint32 _get_uint32_color( rgb_color c ){ +inline uint32 _get_uint32_color( rgb_color c ) +{ uint32 color; color = (c.red << 24) + (c.green << 16) + @@ -4082,7 +4476,8 @@ inline uint32 _get_uint32_color( rgb_color c ){ //--------------------------------------------------------------------------- -inline rgb_color _set_static_rgb_color( uint8 r, uint8 g, uint8 b, uint8 a ){ +inline rgb_color _set_static_rgb_color( uint8 r, uint8 g, uint8 b, uint8 a ) +{ rgb_color color; color.red = r; color.green = g; @@ -4094,8 +4489,7 @@ inline rgb_color _set_static_rgb_color( uint8 r, uint8 g, uint8 b, uint8 a ){ //--------------------------------------------------------------------------- -inline void _set_ptr_rgb_color( rgb_color* c, uint8 r, uint8 g, - uint8 b, uint8 a ) +inline void _set_ptr_rgb_color( rgb_color* c, uint8 r, uint8 g,uint8 b, uint8 a ) { c->red = r; c->green = g; @@ -4105,13 +4499,15 @@ inline void _set_ptr_rgb_color( rgb_color* c, uint8 r, uint8 g, //--------------------------------------------------------------------------- -inline bool _rgb_color_are_equal( rgb_color c1, rgb_color c2 ){ +inline bool _rgb_color_are_equal( rgb_color c1, rgb_color c2 ) +{ return _get_uint32_color( c1 ) == _get_uint32_color( c2 ); } //--------------------------------------------------------------------------- -inline bool _is_new_pattern( const pattern& p1, const pattern& p2 ){ +inline bool _is_new_pattern( const pattern& p1, const pattern& p2 ) +{ if ( memcmp( &p1, &p2, sizeof(pattern) ) == 0 ) return false; else @@ -4120,26 +4516,27 @@ inline bool _is_new_pattern( const pattern& p1, const pattern& p2 ){ //--------------------------------------------------------------------------- -void BView::PrintToStream(){ +void BView::PrintToStream() +{ printf("BView::PrintToStream()\n"); - printf("\tName: %s -\tParent: %s -\tFirstChild: %s -\tNextSibling: %s -\tPrevSibling: %s -\tOwner(Window): %s -\tToken: %ld -\tFlags: %ld -\tView origin: (%f,%f) -\tView Bounds rectangle: (%f,%f,%f,%f) -\tShow level: %d -\tTopView?: %s -\tBPicture: %s -\tVertical Scrollbar %s -\tHorizontal Scrollbar %s -\tIs Printing?: %s + printf("\tName: %s\ +\tParent: %s\ +\tFirstChild: %s\ +\tNextSibling: %s\ +\tPrevSibling: %s\ +\tOwner(Window): %s\ +\tToken: %ld\ +\tFlags: %ld\ +\tView origin: (%f,%f)\ +\tView Bounds rectangle: (%f,%f,%f,%f)\ +\tShow level: %d\ +\tTopView?: %s\ +\tBPicture: %s\ +\tVertical Scrollbar %s\ +\tHorizontal Scrollbar %s\ +\tIs Printing?: %s\ \tShelf?: %s -\tEventMask: %ld +\tEventMask: %ld\ \tEventOptions: %ld\n", Name(), parent? parent->Name() : "NULL", @@ -4161,22 +4558,22 @@ void BView::PrintToStream(){ fEventMask, fEventOptions); - printf("\tState status: -\t\tLocalCoordianteSystem: (%f,%f) -\t\tPenLocation: (%f,%f) -\t\tPenSize: %f -\t\tHighColor: [%d,%d,%d,%d] -\t\tLowColor: [%d,%d,%d,%d] -\t\tViewColor: [%d,%d,%d,%d] -\t\tPattern: %llx -\t\tDrawingMode: %d -\t\tLineJoinMode: %d -\t\tLineCapMode: %d -\t\tMiterLimit: %f -\t\tAlphaSource: %d -\t\tAlphaFuntion: %d -\t\tScale: %f -\t\t(Print)FontAliasing: %s + printf("\tState status:\ +\t\tLocalCoordianteSystem: (%f,%f)\ +\t\tPenLocation: (%f,%f)\ +\t\tPenSize: %f\ +\t\tHighColor: [%d,%d,%d,%d]\ +\t\tLowColor: [%d,%d,%d,%d]\ +\t\tViewColor: [%d,%d,%d,%d]\ +\t\tPattern: %llx\ +\t\tDrawingMode: %d\ +\t\tLineJoinMode: %d\ +\t\tLineCapMode: %d\ +\t\tMiterLimit: %f\ +\t\tAlphaSource: %d\ +\t\tAlphaFuntion: %d\ +\t\tScale: %f\ +\t\t(Print)FontAliasing: %s\ \t\tFont Info:\n", fState->coordSysOrigin.x, fState->coordSysOrigin.y, fState->penPosition.x, fState->penPosition.y, @@ -4195,18 +4592,21 @@ void BView::PrintToStream(){ fState->fontAliasing? "YES" : "NO"); fState->font.PrintToStream(); -// TODO: also print the line array. + + // TODO: also print the line array. } //--------------------------------------------------------------------------- -void BView::PrintTree(){ - +void BView::PrintTree() +{ int32 spaces = 2; BView *c = first_child; //c = short for: current printf( "'%s'\n", Name() ); if( c != NULL ) - while( true ){ + { + while( true ) + { // action block { for( int i = 0; i < spaces; i++) @@ -4214,32 +4614,39 @@ void BView::PrintTree(){ printf( "'%s'\n", c->Name() ); } - - // go deep - if( c->first_child ){ + + // go deep + if( c->first_child ) + { c = c->first_child; spaces += 2; } - // go right or up else - // go right - if( c->next_sibling ){ + { + // go right + if( c->next_sibling ) + { c = c->next_sibling; } + else + { // go up - else{ - while( !c->parent->next_sibling && c->parent != this ){ + while( !c->parent->next_sibling && c->parent != this ) + { c = c->parent; spaces -= 2; } - // that enough! We've reached this view. + + // that enough! We've reached this view. if( c->parent == this ) break; c = c->parent->next_sibling; spaces -= 2; } + } } + } } ViewAttr::ViewAttr(void) @@ -4282,13 +4689,8 @@ ViewAttr::ViewAttr(void) //--------------------------------------------------------------------------- -/* TODOs - * -implement SetDiskMode() what's with this method? what does it do? test! - * does it has something to do with DrawPictureAsync( filename* .. )? - * -implement DrawAfterChildren() - */ -/* - @log: - - * some changes in ConvertXXXYYYY(...) methods. +/* TODO: + -implement SetDiskMode(). What's with this method? What does it do? test! + does it has something to do with DrawPictureAsync( filename* .. )? + -implement DrawAfterChildren() */ diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index 3f72ae9b25..c5c46fe63f 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -46,8 +46,6 @@ // Project Includes ------------------------------------------------------------ #include #include -#include -#include #include #include #include @@ -126,24 +124,16 @@ static property_info windowPropInfo[] = { 0, { 0 }, { 0 }, 0, 0 } }; //------------------------------------------------------------------------------ - - -// TODO: Move this to a better place ? -void -_set_menu_sem_(BWindow *window, sem_id sem) +void _set_menu_sem_(BWindow *window, sem_id sem) { - window->fMenuSem = sem; + window->fMenuSem=sem; } - // Constructors //------------------------------------------------------------------------------ -BWindow::BWindow(BRect frame, - const char* title, - window_type type, - uint32 flags, - uint32 workspace) - : BLooper( title ) +BWindow::BWindow(BRect frame, const char* title, window_type type, + uint32 flags,uint32 workspace) + : BLooper( title ) { #ifdef DEBUG_WIN printf("BWindow::BWindow()\n"); @@ -152,19 +142,15 @@ BWindow::BWindow(BRect frame, window_feel feel; decomposeType(type, &look, &feel); - + InitData( frame, title, look, feel, flags, workspace); } //------------------------------------------------------------------------------ -BWindow::BWindow(BRect frame, - const char* title, - window_look look, - window_feel feel, - uint32 flags, - uint32 workspace) - : BLooper( title ) +BWindow::BWindow(BRect frame, const char* title, window_look look, window_feel feel, + uint32 flags,uint32 workspace) + : BLooper( title ) { InitData( frame, title, look, feel, flags, workspace ); } @@ -226,8 +212,9 @@ BWindow::BWindow(BMessage* data) //------------------------------------------------------------------------------ -BWindow::~BWindow(){ - // the following lines, remove all existing shortcuts and delete accelList +BWindow::~BWindow() +{ + // the following lines, remove all existing shortcuts and delete accelList int32 noOfItems; noOfItems = accelList.CountItems(); @@ -242,22 +229,23 @@ BWindow::~BWindow(){ delete cmdKey; } -// TODO: release other dinamicaly alocated objects + // TODO: release other dynamically-allocated objects - // disable pulsing + // disable pulsing SetPulseRate( 0 ); - delete session; + delete fLink; delete_port( receive_port ); } //------------------------------------------------------------------------------ -BArchivable* BWindow::Instantiate(BMessage* data){ - - if ( !validate_instantiation( data , "BWindow" ) ) - return NULL; - return new BWindow(data); +BArchivable* BWindow::Instantiate(BMessage* data) +{ + if ( !validate_instantiation( data , "BWindow" ) ) + return NULL; + + return new BWindow(data); } //------------------------------------------------------------------------------ @@ -382,9 +370,9 @@ void BWindow::Minimize(bool minimize){ return; Lock(); - session->WriteInt32( AS_WINDOW_MINIMIZE ); - session->WriteBool( minimize ); - session->Sync( ); + fLink->StartMessage( AS_WINDOW_MINIMIZE ); + fLink->Attach( minimize ); + fLink->Flush(); Unlock(); } //------------------------------------------------------------------------------ @@ -397,10 +385,10 @@ status_t BWindow::SendBehind(const BWindow* window){ int32 rCode; Lock(); - session->WriteInt32( AS_SEND_BEHIND ); - session->WriteInt32( _get_object_token_(window) ); - session->Sync(); - session->ReadInt32( &rCode ); + fLink->StartMessage( AS_SEND_BEHIND ); + fLink->Attach( _get_object_token_(window) ); + fLink->Flush(); + fLink->GetNextReply( &rCode ); Unlock(); return rCode == SERVER_TRUE? B_OK : B_ERROR; @@ -410,7 +398,7 @@ status_t BWindow::SendBehind(const BWindow* window){ void BWindow::Flush() const{ const_cast(this)->Lock(); - session->Sync(); + fLink->Flush(); const_cast(this)->Unlock(); } @@ -421,38 +409,40 @@ void BWindow::Sync() const{ int32 rCode; const_cast(this)->Lock(); - session->WriteInt32( AS_SYNC ); - session->Sync(); - session->ReadInt32( &rCode ); + fLink->StartMessage( AS_SYNC ); + fLink->Flush(); + fLink->GetNextReply( &rCode ); const_cast(this)->Unlock(); } //------------------------------------------------------------------------------ -void BWindow::DisableUpdates(){ - +void BWindow::DisableUpdates() +{ Lock(); - session->WriteInt32( AS_DISABLE_UPDATES ); - session->Sync(); + fLink->StartMessage( AS_DISABLE_UPDATES ); + fLink->Flush(); Unlock(); } //------------------------------------------------------------------------------ -void BWindow::EnableUpdates(){ - +void BWindow::EnableUpdates() +{ Lock(); - session->WriteInt32( AS_ENABLE_UPDATES ); - session->Sync( ); + fLink->StartMessage( AS_ENABLE_UPDATES ); + fLink->Flush(); Unlock(); } //------------------------------------------------------------------------------ -void BWindow::BeginViewTransaction(){ - if ( !fInTransaction ){ +void BWindow::BeginViewTransaction() +{ + if ( !fInTransaction ) + { Lock(); - session->WriteInt32( AS_BEGIN_TRANSACTION ); + fLink->StartMessage( AS_BEGIN_TRANSACTION ); Unlock(); fInTransaction = true; @@ -461,11 +451,13 @@ void BWindow::BeginViewTransaction(){ //------------------------------------------------------------------------------ -void BWindow::EndViewTransaction(){ - if ( fInTransaction ){ +void BWindow::EndViewTransaction() +{ + if ( fInTransaction ) + { Lock(); - session->WriteInt32( AS_END_TRANSACTION ); - session->Sync(); + fLink->StartMessage( AS_END_TRANSACTION ); + fLink->Flush(); Unlock(); fInTransaction = false; @@ -474,7 +466,8 @@ void BWindow::EndViewTransaction(){ //------------------------------------------------------------------------------ -bool BWindow::IsFront() const{ +bool BWindow::IsFront() const +{ if (IsActive()) return true; @@ -647,7 +640,6 @@ void BWindow::MessageReceived( BMessage *msg ) replyMsg.AddInt32( "error", B_BAD_SCRIPT_SYNTAX ); replyMsg.AddString( "message", "Didn't understand the specifier(s)" ); } - delete newTitle; } else if (strcmp(prop, "Workspaces") ==0 ) @@ -687,281 +679,320 @@ void BWindow::MessageReceived( BMessage *msg ) void BWindow::DispatchMessage(BMessage *msg, BHandler *target) { - if (!msg){ - BLooper::DispatchMessage( msg, target ); + if (!msg) return; - } - switch ( msg->what ) { - case B_ZOOM:{ - Zoom(); - break; - } - case B_MINIMIZE:{ - bool minimize; - - msg->FindBool("minimize", &minimize); - - fMinimized = minimize; - Minimize( minimize ); - break; - } - case B_WINDOW_RESIZED:{ - BPoint offset; - int32 width, height; - - msg->FindInt32("width", &width); - msg->FindInt32("height", &height); - offset.x = width; - offset.y = height; - - fFrame.SetRightBottom( fFrame.LeftTop() + offset ); - FrameResized( offset.x, offset.y ); - break; - } - case B_WINDOW_MOVED:{ - BPoint origin; - - msg->FindPoint("where", &origin); - - fFrame.OffsetTo( origin ); - FrameMoved( origin ); - break; - } - // this is NOT an app_server message and we have to be cautious - case B_WINDOW_MOVE_BY:{ - BPoint offset; - - if (msg->FindPoint("data", &offset) == B_OK) - MoveBy( offset.x, offset.y ); - else - msg->SendReply( B_MESSAGE_NOT_UNDERSTOOD ); - break; - } - // this is NOT an app_server message and we have to be cautious - case B_WINDOW_MOVE_TO:{ - BPoint origin; - - if (msg->FindPoint("data", &origin) == B_OK) + switch ( msg->what ) + { + case B_ZOOM: + { + Zoom(); + break; + } + case B_MINIMIZE: + { + bool minimize; + + msg->FindBool("minimize", &minimize); + + fMinimized = minimize; + Minimize( minimize ); + break; + } + case B_WINDOW_RESIZED: + { + float width, height; + + msg->FindFloat("width", &width); + msg->FindFloat("height", &height); + + ResizeTo(width,height); + FrameResized(width,height); + break; + } + case B_WINDOW_MOVED: + { + BPoint origin; + + msg->FindPoint("where", &origin); + MoveTo( origin ); - else - msg->SendReply( B_MESSAGE_NOT_UNDERSTOOD ); - break; - } - case B_WINDOW_ACTIVATED:{ - bool active; - - msg->FindBool("active", &active); - - fActive = active; - handleActivation( active ); - break; - } - case B_SCREEN_CHANGED:{ - BRect frame; - uint32 mode; - - msg->FindRect("frame", &frame); - msg->FindInt32("mode", (int32*)&mode); - ScreenChanged( frame, (color_space)mode ); - break; - } - case B_WORKSPACE_ACTIVATED:{ - uint32 workspace; - bool active; - - msg->FindInt32( "workspace", (int32*)&workspace ); - msg->FindBool( "active", &active ); - WorkspaceActivated( workspace, active ); - break; - } - case B_WORKSPACES_CHANGED:{ - uint32 oldWorkspace; - uint32 newWorkspace; - - msg->FindInt32( "old", (int32*)&oldWorkspace ); - msg->FindInt32( "new", (int32*)&newWorkspace ); - WorkspacesChanged( oldWorkspace, newWorkspace ); - break; - } - case B_KEY_DOWN:{ - uint32 modifiers; - int32 raw_char; - const char *string; - - msg->FindInt32( "modifiers", (int32*)&modifiers ); - msg->FindInt32( "raw_char", &raw_char ); - 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) ) - fFocus->KeyDown( string, strlen(string)-1 ); - break; - } - case B_KEY_UP:{ - const char *string; - - msg->FindString( "bytes", &string ); - fFocus->KeyUp( string, strlen(string)-1 ); - break; - } - case B_UNMAPPED_KEY_DOWN:{ - if (fFocus) - fFocus->MessageReceived( msg ); - break; - } - case B_UNMAPPED_KEY_UP:{ - if (fFocus) - fFocus->MessageReceived( msg ); - break; - } - case B_MODIFIERS_CHANGED:{ - if (fFocus) - fFocus->MessageReceived( msg ); - break; - } - case B_MOUSE_WHEEL_CHANGED:{ - if (fFocus) - fFocus->MessageReceived( msg ); - break; - } - case B_MOUSE_DOWN:{ - BPoint where; - uint32 modifiers; - uint32 buttons; - int32 clicks; - - msg->FindPoint( "where", &where ); - msg->FindInt32( "modifiers", (int32*)&modifiers ); - msg->FindInt32( "buttons", (int32*)&buttons ); - msg->FindInt32( "clicks", &clicks ); - - sendMessageUsingEventMask( B_MOUSE_DOWN, where ); - break; - } - case B_MOUSE_UP:{ - BPoint where; - uint32 modifiers; - - msg->FindPoint( "where", &where ); - msg->FindInt32( "modifiers", (int32*)&modifiers ); - - sendMessageUsingEventMask( B_MOUSE_UP, where ); - break; - } - case B_MOUSE_MOVED:{ - BPoint where; - uint32 buttons; - - msg->FindPoint( "where", &where ); - msg->FindInt32( "buttons", (int32*)&buttons ); - - sendMessageUsingEventMask( B_MOUSE_MOVED, where ); - break; - } - case B_PULSE:{ - if (fPulseEnabled) - sendPulse( top_view ); - break; - } - case B_QUIT_REQUESTED:{ - if (QuitRequested()) - Quit(); - break; - } - case _UPDATE_:{ - BRect updateRect; - msg->FindRect("_rect", &updateRect); - - DoUpdate(top_view, updateRect); - 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 ); + FrameMoved( origin ); + break; } - 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"); + + // this is NOT an app_server message and we have to be cautious + case B_WINDOW_MOVE_BY: + { + BPoint offset; - view = findView(top_view, token); - if (view){ - STRACE(("Calling BView(%s)::FrameResized( %f, %f )\n", view->Name(), newWidth, newHeight)); - view->FrameResized( newWidth, newHeight ); + if (msg->FindPoint("data", &offset) == B_OK) + MoveBy( offset.x, offset.y ); + else + msg->SendReply( B_MESSAGE_NOT_UNDERSTOOD ); + break; } - else - printf("***PANIC: BW: Can't find view with ID: %ld !***\n", token); - - break; - } - default:{ - BLooper::DispatchMessage(msg, target); - break; - } - } + // this is NOT an app_server message and we have to be cautious + case B_WINDOW_MOVE_TO: + { + BPoint origin; + + if (msg->FindPoint("data", &origin) == B_OK) + MoveTo( origin ); + else + msg->SendReply( B_MESSAGE_NOT_UNDERSTOOD ); + break; + } + case B_WINDOW_ACTIVATED: + { + bool active; + + msg->FindBool("active", &active); + + fActive = active; + handleActivation( active ); + break; + } + case B_SCREEN_CHANGED: + { + BRect frame; + uint32 mode; + + msg->FindRect("frame", &frame); + msg->FindInt32("mode", (int32*)&mode); + ScreenChanged( frame, (color_space)mode ); + break; + } + case B_WORKSPACE_ACTIVATED: + { + uint32 workspace; + bool active; + + msg->FindInt32( "workspace", (int32*)&workspace ); + msg->FindBool( "active", &active ); + WorkspaceActivated( workspace, active ); + break; + } + case B_WORKSPACES_CHANGED: + { + uint32 oldWorkspace; + uint32 newWorkspace; + + msg->FindInt32( "old", (int32*)&oldWorkspace ); + msg->FindInt32( "new", (int32*)&newWorkspace ); + WorkspacesChanged( oldWorkspace, newWorkspace ); + break; + } + case B_KEY_DOWN: + { + uint32 modifiers; + int32 raw_char; + const char *string=NULL; + + msg->FindInt32( "modifiers", (int32*)&modifiers ); + msg->FindInt32( "raw_char", &raw_char ); + 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(fFocus && string) + fFocus->KeyDown( string, strlen(string)-1 ); + break; + } + case B_KEY_UP: + { + const char *string=NULL; + + msg->FindString( "bytes", &string ); + if(fFocus && string) + fFocus->KeyUp( string, strlen(string)-1 ); + break; + } + case B_UNMAPPED_KEY_DOWN: + { + if (fFocus) + fFocus->MessageReceived( msg ); + break; + } + case B_UNMAPPED_KEY_UP: + { + if (fFocus) + fFocus->MessageReceived( msg ); + break; + } + case B_MODIFIERS_CHANGED: + { + if (fFocus) + fFocus->MessageReceived( msg ); + break; + } + case B_MOUSE_WHEEL_CHANGED: + { + if (fFocus) + fFocus->MessageReceived( msg ); + break; + } + case B_MOUSE_DOWN: + { + BPoint where; + uint32 modifiers; + uint32 buttons; + int32 clicks; + + msg->FindPoint( "where", &where ); + msg->FindInt32( "modifiers", (int32*)&modifiers ); + msg->FindInt32( "buttons", (int32*)&buttons ); + msg->FindInt32( "clicks", &clicks ); + + sendMessageUsingEventMask( B_MOUSE_DOWN, where ); + break; + } + case B_MOUSE_UP: + { + BPoint where; + uint32 modifiers; + + msg->FindPoint( "where", &where ); + msg->FindInt32( "modifiers", (int32*)&modifiers ); + + sendMessageUsingEventMask( B_MOUSE_UP, where ); + break; + } + case B_MOUSE_MOVED: + { + BPoint where; + uint32 buttons; + + msg->FindPoint( "where", &where ); + msg->FindInt32( "buttons", (int32*)&buttons ); + + sendMessageUsingEventMask( B_MOUSE_MOVED, where ); + break; + } + case B_PULSE: + { + if (fPulseEnabled) + sendPulse( top_view ); + break; + } + case B_QUIT_REQUESTED: + { + if (QuitRequested()) + Quit(); + break; + } + case _UPDATE_: + { + STRACE(("info:BWindow handling _UPDATE_.\n")); + BRect updateRect; + int32 token; + BView *view; + + msg->FindRect("_rect", &updateRect); + msg->FindInt32("_token",&token); + + view=findView(top_view,token); + if(view) + DoUpdate(top_view, updateRect); + 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: + { + BLooper::DispatchMessage(msg, target); + break; + } + } // end switch(msg->what) } //------------------------------------------------------------------------------ -void BWindow::FrameMoved(BPoint new_position){ +void BWindow::FrameMoved(BPoint new_position) +{ // does nothing // Hook function } //------------------------------------------------------------------------------ -void BWindow::FrameResized(float new_width, float new_height){ +void BWindow::FrameResized(float new_width, float new_height) +{ // does nothing // Hook function } //------------------------------------------------------------------------------ -void BWindow::WorkspacesChanged(uint32 old_ws, uint32 new_ws){ +void BWindow::WorkspacesChanged(uint32 old_ws, uint32 new_ws) +{ // does nothing // Hook function } //------------------------------------------------------------------------------ -void BWindow::WorkspaceActivated(int32 ws, bool state){ +void BWindow::WorkspaceActivated(int32 ws, bool state) +{ // does nothing // Hook function } //------------------------------------------------------------------------------ -void BWindow::MenusBeginning(){ +void BWindow::MenusBeginning() +{ // does nothing // Hook function } //------------------------------------------------------------------------------ -void BWindow::MenusEnded(){ +void BWindow::MenusEnded() +{ // does nothing // Hook function } @@ -969,7 +1000,8 @@ void BWindow::MenusEnded(){ //------------------------------------------------------------------------------ void BWindow::SetSizeLimits(float minWidth, float maxWidth, - float minHeight, float maxHeight){ + float minHeight, float maxHeight) +{ int32 rCode; if (minWidth > maxWidth) @@ -978,13 +1010,13 @@ void BWindow::SetSizeLimits(float minWidth, float maxWidth, return; Lock(); - session->WriteInt32( AS_SET_SIZE_LIMITS ); - session->WriteFloat( fMinWindWidth ); - session->WriteFloat( fMaxWindWidth ); - session->WriteFloat( fMinWindHeight ); - session->WriteFloat( fMaxWindHeight ); - session->Sync(); - session->ReadInt32( &rCode ); + fLink->StartMessage( AS_SET_SIZE_LIMITS ); + fLink->Attach( fMinWindWidth ); + fLink->Attach( fMaxWindWidth ); + fLink->Attach( fMinWindHeight ); + fLink->Attach( fMaxWindHeight ); + fLink->Flush(); + fLink->GetNextReply( &rCode ); Unlock(); if (rCode == SERVER_TRUE){ @@ -998,7 +1030,8 @@ void BWindow::SetSizeLimits(float minWidth, float maxWidth, //------------------------------------------------------------------------------ void BWindow::GetSizeLimits(float *minWidth, float *maxWidth, - float *minHeight, float *maxHeight){ + float *minHeight, float *maxHeight) +{ *minHeight = fMinWindHeight; *minWidth = fMinWindWidth; *maxHeight = fMaxWindHeight; @@ -1007,7 +1040,8 @@ void BWindow::GetSizeLimits(float *minWidth, float *maxWidth, //------------------------------------------------------------------------------ -void BWindow::SetZoomLimits(float maxWidth, float maxHeight){ +void BWindow::SetZoomLimits(float maxWidth, float maxHeight) +{ if (maxWidth > fMaxWindWidth) maxWidth = fMaxWindWidth; else @@ -1021,9 +1055,10 @@ void BWindow::SetZoomLimits(float maxWidth, float maxHeight){ //------------------------------------------------------------------------------ -void BWindow::Zoom( BPoint rec_position, float rec_width, float rec_height){ +void BWindow::Zoom( BPoint rec_position, float rec_width, float rec_height) +{ - // this is also a Hook function! + // this is also a Hook function! MoveTo( rec_position ); ResizeTo( rec_width, rec_height ); @@ -1031,34 +1066,40 @@ void BWindow::Zoom( BPoint rec_position, float rec_width, float rec_height){ //------------------------------------------------------------------------------ -void BWindow::Zoom(){ +void BWindow::Zoom() +{ float minWidth, minHeight; BScreen screen; -/* from BeBook: + +/* + from BeBook: However, if the window's rectangle already matches these "zoom" dimensions (give or take a few pixels), Zoom() passes the window's previous ("non-zoomed") size and location. (??????) */ - if (Frame().Width() == fMaxZoomWidth && Frame().Height() == fMaxZoomHeight) { + + if (Frame().Width() == fMaxZoomWidth && Frame().Height() == fMaxZoomHeight) + { BPoint position( Frame().left, Frame().top); Zoom( position, fMaxZoomWidth, fMaxZoomHeight ); return; } -/* from BeBook: +/* + from BeBook: The dimensions that non-virtual Zoom() passes to hook Zoom() are deduced from the smallest of three rectangles: 3) the screen rectangle, 1) the rectangle defined by SetZoomLimits(), 2) the rectangle defined by SetSizeLimits() */ - // 1 + // 1 minHeight = fMaxZoomHeight; minWidth = fMaxZoomWidth; - - // 2 + + // 2 if ( fMaxWindHeight < minHeight ) { minHeight = fMaxWindHeight; } if ( fMaxWindWidth < minWidth ) { minWidth = fMaxWindWidth; } - - // 3 + + // 3 if ( screen.Frame().Width() < minWidth ) { minWidth = screen.Frame().Width(); } if ( screen.Frame().Height() < minHeight ) { minHeight = screen.Frame().Height(); } @@ -1067,14 +1108,16 @@ void BWindow::Zoom(){ //------------------------------------------------------------------------------ -void BWindow::ScreenChanged(BRect screen_size, color_space depth){ +void BWindow::ScreenChanged(BRect screen_size, color_space depth) +{ // Hook function // does nothing } //------------------------------------------------------------------------------ -void BWindow::SetPulseRate(bigtime_t rate){ +void BWindow::SetPulseRate(bigtime_t rate) +{ if ( rate < 0 ) return; @@ -1127,9 +1170,8 @@ BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *msg) void BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *msg, BHandler *target) { -/* - NOTE: I'm not sure if it is OK to use 'key' -*/ + // NOTE: I'm not sure if it is OK to use 'key' + if (msg == NULL) return; @@ -1139,7 +1181,7 @@ BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *msg, BHandler *targ when = real_time_clock_usecs(); msg->AddInt64("when", when); -// TODO: make sure key is a lowercase char !!! + // TODO: make sure key is a lowercase char !!! modifiers = modifiers | B_COMMAND_KEY; @@ -1152,7 +1194,7 @@ BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *msg, BHandler *targ else cmdKey->targetToken = _get_object_token_(target); - // removes the shortcut from accelList if it exists! + // removes the shortcut from accelList if it exists! RemoveShortcut( key, modifiers ); accelList.AddItem( cmdKey ); @@ -1161,17 +1203,19 @@ BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *msg, BHandler *targ //------------------------------------------------------------------------------ -void BWindow::RemoveShortcut(uint32 key, uint32 modifiers){ +void BWindow::RemoveShortcut(uint32 key, uint32 modifiers) +{ int32 index; modifiers = modifiers | B_COMMAND_KEY; - + index = findShortcut( key, modifiers ); - if ( index >=0 ) { + if ( index >=0 ) + { _BCmdKey *cmdKey; - + cmdKey = (_BCmdKey*)accelList.ItemAt( index ); - + accelList.RemoveItem(index); delete cmdKey->message; @@ -1181,15 +1225,18 @@ void BWindow::RemoveShortcut(uint32 key, uint32 modifiers){ //------------------------------------------------------------------------------ -BButton* BWindow::DefaultButton() const{ +BButton* BWindow::DefaultButton() const +{ return fDefaultButton; } //------------------------------------------------------------------------------ -void BWindow::SetDefaultButton(BButton* button){ +void BWindow::SetDefaultButton(BButton* button) +{ /* -Note: for developers! + Note: for developers: + He he, if you really want to understand what is happens here, take a piece of paper and start taking possible values and then walk with them through the code. @@ -1199,14 +1246,16 @@ Note: for developers! if ( fDefaultButton == button ) return; - if ( fDefaultButton ){ + if ( fDefaultButton ) + { aux = fDefaultButton; fDefaultButton = NULL; aux->MakeDefault( false ); aux->Invalidate(); } - if ( button == NULL ){ + if ( button == NULL ) + { fDefaultButton = NULL; return; } @@ -1218,14 +1267,15 @@ Note: for developers! //------------------------------------------------------------------------------ -bool BWindow::NeedsUpdate() const{ +bool BWindow::NeedsUpdate() const +{ int32 rCode; const_cast(this)->Lock(); - session->WriteInt32( AS_NEEDS_UPDATE ); - session->Sync(); - session->ReadInt32( &rCode ); + fLink->StartMessage( AS_NEEDS_UPDATE ); + fLink->Flush(); + fLink->GetNextReply( &rCode ); const_cast(this)->Unlock(); return rCode == SERVER_TRUE; @@ -1233,64 +1283,90 @@ bool BWindow::NeedsUpdate() const{ //------------------------------------------------------------------------------ -void BWindow::UpdateIfNeeded(){ - // works only from this thread - if (find_thread(NULL) == Thread()){ - Sync(); - drawAllViews( top_view ); +void BWindow::UpdateIfNeeded() +{ + // works only from this thread + if (find_thread(NULL) != Thread()) + return; + + BMessageQueue *queue; + BMessage *msg; + + queue = MessageQueue(); + + //process all _UPDATE_ BMessages in message queue + //we lock the queue because we don't want to be stuck in this + //function if there is a continuous stream of updates + queue->Lock(); + while ((msg = queue->FindMessage(_UPDATE_, 0))) + { + Lock(); + DispatchMessage( msg, this ); + Unlock(); + + queue->RemoveMessage( msg ); + delete msg; } + queue->Unlock(); } //------------------------------------------------------------------------------ -BView* BWindow::FindView(const char* viewName) const{ +BView* BWindow::FindView(const char* viewName) const +{ return findView( top_view, viewName ); } //------------------------------------------------------------------------------ -BView* BWindow::FindView(BPoint point) const{ +BView* BWindow::FindView(BPoint point) const +{ return findView( top_view, point ); } //------------------------------------------------------------------------------ -BView* BWindow::CurrentFocus() const{ +BView* BWindow::CurrentFocus() const +{ return fFocus; } //------------------------------------------------------------------------------ -void BWindow::Activate(bool active){ +void BWindow::Activate(bool active) +{ if (IsHidden()) return; Lock(); - session->WriteInt32( AS_ACTIVATE_WINDOW ); - session->WriteBool( active ); - session->Sync( ); + fLink->StartMessage( AS_ACTIVATE_WINDOW ); + fLink->Attach( active ); + fLink->Flush(); Unlock(); } //------------------------------------------------------------------------------ -void BWindow::WindowActivated(bool state){ +void BWindow::WindowActivated(bool state) +{ // hook function // does nothing } //------------------------------------------------------------------------------ -void BWindow::ConvertToScreen(BPoint* pt) const{ +void BWindow::ConvertToScreen(BPoint* pt) const +{ pt->x += fFrame.left; pt->y += fFrame.top; } //------------------------------------------------------------------------------ -BPoint BWindow::ConvertToScreen(BPoint pt) const{ +BPoint BWindow::ConvertToScreen(BPoint pt) const +{ pt.x += fFrame.left; pt.y += fFrame.top; @@ -1299,14 +1375,16 @@ BPoint BWindow::ConvertToScreen(BPoint pt) const{ //------------------------------------------------------------------------------ -void BWindow::ConvertFromScreen(BPoint* pt) const{ +void BWindow::ConvertFromScreen(BPoint* pt) const +{ pt->x -= fFrame.left; pt->y -= fFrame.top; } //------------------------------------------------------------------------------ -BPoint BWindow::ConvertFromScreen(BPoint pt) const{ +BPoint BWindow::ConvertFromScreen(BPoint pt) const +{ pt.x -= fFrame.left; pt.y -= fFrame.top; @@ -1315,7 +1393,8 @@ BPoint BWindow::ConvertFromScreen(BPoint pt) const{ //------------------------------------------------------------------------------ -void BWindow::ConvertToScreen(BRect* rect) const{ +void BWindow::ConvertToScreen(BRect* rect) const +{ rect->top += fFrame.top; rect->left += fFrame.left; rect->bottom += fFrame.top; @@ -1324,7 +1403,8 @@ void BWindow::ConvertToScreen(BRect* rect) const{ //------------------------------------------------------------------------------ -BRect BWindow::ConvertToScreen(BRect rect) const{ +BRect BWindow::ConvertToScreen(BRect rect) const +{ rect.top += fFrame.top; rect.left += fFrame.left; rect.bottom += fFrame.top; @@ -1335,7 +1415,8 @@ BRect BWindow::ConvertToScreen(BRect rect) const{ //------------------------------------------------------------------------------ -void BWindow::ConvertFromScreen(BRect* rect) const{ +void BWindow::ConvertFromScreen(BRect* rect) const +{ rect->top -= fFrame.top; rect->left -= fFrame.left; rect->bottom -= fFrame.top; @@ -1344,7 +1425,8 @@ void BWindow::ConvertFromScreen(BRect* rect) const{ //------------------------------------------------------------------------------ -BRect BWindow::ConvertFromScreen(BRect rect) const{ +BRect BWindow::ConvertFromScreen(BRect rect) const +{ rect.top -= fFrame.top; rect.left -= fFrame.left; rect.bottom -= fFrame.top; @@ -1355,8 +1437,9 @@ BRect BWindow::ConvertFromScreen(BRect rect) const{ //------------------------------------------------------------------------------ -bool BWindow::IsMinimized() const{ - // Hiding takes precendence over minimization!!! +bool BWindow::IsMinimized() const +{ + // Hiding takes precendence over minimization!!! if ( IsHidden() ) return false; @@ -1365,55 +1448,62 @@ bool BWindow::IsMinimized() const{ //------------------------------------------------------------------------------ -BRect BWindow::Bounds() const{ - BRect bounds( 0.0, 0.0, fFrame.Width(), fFrame.Height() ); +BRect BWindow::Bounds() const +{ + BRect bounds( 0.0, 0.0, fFrame.Width(), fFrame.Height() ); return bounds; } //------------------------------------------------------------------------------ -BRect BWindow::Frame() const{ +BRect BWindow::Frame() const +{ return fFrame; } //------------------------------------------------------------------------------ -const char* BWindow::Title() const{ +const char* BWindow::Title() const +{ return fTitle; } //------------------------------------------------------------------------------ -void BWindow::SetTitle(const char* title){ +void BWindow::SetTitle(const char* title) +{ if (!title) return; - if (fTitle){ - delete fTitle; + if (fTitle) + { + free(fTitle); fTitle = NULL; } - fTitle = strdup( title ); + fTitle = strdup( title ); - // we will change BWindow's thread name to "w>window_title" + // we will change BWindow's thread name to "w>window_title" int32 length; length = strlen( fTitle ); - char *threadName; - threadName = new char[32]; + char threadName[B_OS_NAME_LENGTH]; strcpy(threadName, "w>"); - strncat(threadName, fTitle, (length>=29) ? 29: length); + length=min_c(length,B_OS_NAME_LENGTH-3); + strncat(threadName, fTitle, length); + threadName[B_OS_NAME_LENGTH-1] = '\0'; - // if the message loop has been started... - if (Thread() != B_ERROR ){ + // if the message loop has been started... + if (Thread() != B_ERROR ) + { SetName( threadName ); rename_thread( Thread(), threadName ); - - // we notify the app_server so we can actually see the change + + // we notify the app_server so we can actually see the change Lock(); - session->WriteInt32( AS_WINDOW_TITLE); - session->WriteString( fTitle ); - session->Sync( ); + fLink->StartMessage( AS_WINDOW_TITLE); + fLink->AttachString( fTitle ); + fLink->Flush(); Unlock(); } else @@ -1422,25 +1512,29 @@ void BWindow::SetTitle(const char* title){ //------------------------------------------------------------------------------ -bool BWindow::IsActive() const{ +bool BWindow::IsActive() const +{ return fActive; } //------------------------------------------------------------------------------ -void BWindow::SetKeyMenuBar(BMenuBar* bar){ +void BWindow::SetKeyMenuBar(BMenuBar* bar) +{ fKeyMenuBar = bar; } //------------------------------------------------------------------------------ -BMenuBar* BWindow::KeyMenuBar() const{ +BMenuBar* BWindow::KeyMenuBar() const +{ return fKeyMenuBar; } //------------------------------------------------------------------------------ -bool BWindow::IsModal() const{ +bool BWindow::IsModal() const +{ if ( fFeel == B_MODAL_SUBSET_WINDOW_FEEL) return true; if ( fFeel == B_MODAL_APP_WINDOW_FEEL) @@ -1454,7 +1548,8 @@ bool BWindow::IsModal() const{ //------------------------------------------------------------------------------ -bool BWindow::IsFloating() const{ +bool BWindow::IsFloating() const +{ if ( fFeel == B_FLOATING_SUBSET_WINDOW_FEEL) return true; if ( fFeel == B_FLOATING_APP_WINDOW_FEEL) @@ -1467,7 +1562,8 @@ bool BWindow::IsFloating() const{ //------------------------------------------------------------------------------ -status_t BWindow::AddToSubset(BWindow* window){ +status_t BWindow::AddToSubset(BWindow* window) +{ if ( !window ) return B_ERROR; @@ -1475,16 +1571,16 @@ status_t BWindow::AddToSubset(BWindow* window){ if (window->Feel() == B_NORMAL_WINDOW_FEEL && (fFeel == B_MODAL_SUBSET_WINDOW_FEEL || - fFeel == B_FLOATING_SUBSET_WINDOW_FEEL)){ - + fFeel == B_FLOATING_SUBSET_WINDOW_FEEL) ) + { team_id team = Team(); Lock(); - session->WriteInt32( AS_ADD_TO_SUBSET ); - session->WriteInt32( _get_object_token_(window) ); - session->WriteData( &team, sizeof(team_id) ); - session->Sync(); - session->ReadInt32( &rCode ); + fLink->StartMessage( AS_ADD_TO_SUBSET ); + fLink->Attach( _get_object_token_(window) ); + fLink->Attach( team ); + fLink->Flush(); + fLink->GetNextReply( &rCode ); Unlock(); return rCode == SERVER_TRUE? B_OK : B_ERROR; @@ -1495,7 +1591,8 @@ status_t BWindow::AddToSubset(BWindow* window){ //------------------------------------------------------------------------------ -status_t BWindow::RemoveFromSubset(BWindow* window){ +status_t BWindow::RemoveFromSubset(BWindow* window) +{ if ( !window ) return B_ERROR; @@ -1508,11 +1605,11 @@ status_t BWindow::RemoveFromSubset(BWindow* window){ team_id team = Team(); Lock(); - session->WriteInt32( AS_REM_FROM_SUBSET ); - session->WriteInt32( _get_object_token_(window) ); - session->WriteData( &team, sizeof(team_id) ); - session->Sync(); - session->ReadInt32( &rCode ); + fLink->StartMessage( AS_REM_FROM_SUBSET ); + fLink->Attach( _get_object_token_(window) ); + fLink->Attach( team ); + fLink->Flush(); + fLink->GetNextReply( &rCode ); Unlock(); return rCode == SERVER_TRUE? B_OK : B_ERROR; @@ -1523,13 +1620,15 @@ status_t BWindow::RemoveFromSubset(BWindow* window){ //------------------------------------------------------------------------------ -status_t BWindow::Perform(perform_code d, void* arg){ +status_t BWindow::Perform(perform_code d, void* arg) +{ return BLooper::Perform( d, arg ); } //------------------------------------------------------------------------------ -status_t BWindow::SetType(window_type type){ +status_t BWindow::SetType(window_type type) +{ decomposeType(type, &fLook, &fFeel); status_t stat1, stat2; @@ -1543,24 +1642,27 @@ status_t BWindow::SetType(window_type type){ //------------------------------------------------------------------------------ -window_type BWindow::Type() const{ +window_type BWindow::Type() const +{ return composeType( fLook, fFeel ); } //------------------------------------------------------------------------------ -status_t BWindow::SetLook(window_look look){ +status_t BWindow::SetLook(window_look look) +{ int32 rCode; Lock(); - session->WriteInt32( AS_SET_LOOK ); - session->WriteInt32( (int32)look ); - session->Sync(); - session->ReadInt32( &rCode ); + fLink->StartMessage( AS_SET_LOOK ); + fLink->Attach( (int32)look ); + fLink->Flush(); + fLink->GetNextReply( &rCode ); Unlock(); - if (rCode == SERVER_TRUE){ + if (rCode == SERVER_TRUE) + { fLook = look; return B_OK; } @@ -1570,26 +1672,29 @@ status_t BWindow::SetLook(window_look look){ //------------------------------------------------------------------------------ -window_look BWindow::Look() const{ +window_look BWindow::Look() const +{ return fLook; } //------------------------------------------------------------------------------ -status_t BWindow::SetFeel(window_feel feel){ -/* TODO: See what happens when a window that is part of a subset, changes its - feel!? should it be removed from the subset??? -*/ +status_t BWindow::SetFeel(window_feel feel) +{ + // TODO: See what happens when a window that is part of a subset, changes its + // feel. Should it be removed from the subset? + int32 rCode; Lock(); - session->WriteInt32( AS_SET_FEEL ); - session->WriteInt32( (int32)feel ); - session->Sync(); - session->ReadInt32( &rCode ); + fLink->StartMessage( AS_SET_FEEL ); + fLink->Attach( (int32)feel ); + fLink->Flush(); + fLink->GetNextReply( &rCode ); Unlock(); - if (rCode == SERVER_TRUE){ + if (rCode == SERVER_TRUE) + { fFeel = feel; return B_OK; } @@ -1599,24 +1704,27 @@ status_t BWindow::SetFeel(window_feel feel){ //------------------------------------------------------------------------------ -window_feel BWindow::Feel() const{ +window_feel BWindow::Feel() const +{ return fFeel; } //------------------------------------------------------------------------------ -status_t BWindow::SetFlags(uint32 flags){ +status_t BWindow::SetFlags(uint32 flags) +{ int32 rCode; Lock(); - session->WriteInt32( AS_SET_FLAGS ); - session->WriteUInt32( flags ); - session->Sync(); - session->ReadInt32( &rCode ); + fLink->StartMessage( AS_SET_FLAGS ); + fLink->Attach( flags ); + fLink->Flush(); + fLink->GetNextReply( &rCode ); Unlock(); - if (rCode == SERVER_TRUE){ + if (rCode == SERVER_TRUE) + { fFlags = flags; return B_OK; } @@ -1656,25 +1764,26 @@ status_t BWindow::SetWindowAlignment(window_alignment mode, if ( 0 <= heightOffset && heightOffset <=height ) return B_ERROR; -// TODO: test if hOffset = 0 and set it to 1 if true. + // TODO: test if hOffset = 0 and set it to 1 if true. int32 rCode; Lock(); - session->WriteInt32( AS_SET_ALIGNMENT ); - session->WriteInt32( (int32)mode ); - session->WriteInt32( h ); - session->WriteInt32( hOffset ); - session->WriteInt32( width ); - session->WriteInt32( widthOffset ); - session->WriteInt32( v ); - session->WriteInt32( vOffset ); - session->WriteInt32( height ); - session->WriteInt32( heightOffset ); - session->Sync(); - session->ReadInt32( &rCode ); + fLink->StartMessage( AS_SET_ALIGNMENT ); + fLink->Attach( (int32)mode ); + fLink->Attach( h ); + fLink->Attach( hOffset ); + fLink->Attach( width ); + fLink->Attach( widthOffset ); + fLink->Attach( v ); + fLink->Attach( vOffset ); + fLink->Attach( height ); + fLink->Attach( heightOffset ); + fLink->Flush(); + fLink->GetNextReply( &rCode ); Unlock(); - if ( rCode == SERVER_TRUE){ + if ( rCode == SERVER_TRUE) + { return B_NO_ERROR; } @@ -1692,37 +1801,42 @@ status_t BWindow::GetWindowAlignment(window_alignment* mode, int32 rCode; const_cast(this)->Lock(); - session->WriteInt32( AS_GET_ALIGNMENT ); - session->Sync(); - session->ReadInt32( &rCode ); + fLink->StartMessage( AS_GET_ALIGNMENT ); + fLink->Flush(); + fLink->GetNextReply( &rCode ); - if (rCode == SERVER_TRUE){ - session->ReadInt32( (int32*)mode ); - session->ReadInt32( h ); - session->ReadInt32( hOffset ); - session->ReadInt32( width ); - session->ReadInt32( widthOffset ); - session->ReadInt32( v ); - session->ReadInt32( hOffset ); - session->ReadInt32( height ); - session->ReadInt32( heightOffset ); + if (rCode == SERVER_TRUE) + { + fLink->Read( (int32*)mode ); + fLink->Read( h ); + fLink->Read( hOffset ); + fLink->Read( width ); + fLink->Read( widthOffset ); + fLink->Read( v ); + fLink->Read( hOffset ); + fLink->Read( height ); + rCode=fLink->Read( heightOffset ); return B_NO_ERROR; } const_cast(this)->Unlock(); - return B_ERROR; + if(rCode!=B_OK) + return B_ERROR; + + return B_OK; } //------------------------------------------------------------------------------ -uint32 BWindow::Workspaces() const{ +uint32 BWindow::Workspaces() const +{ uint32 workspaces; const_cast(this)->Lock(); - session->WriteInt32( AS_GET_WORKSPACES ); - session->Sync(); - session->ReadInt32( (int32*)&workspaces ); + fLink->StartMessage( AS_GET_WORKSPACES ); + fLink->Flush(); + fLink->GetNextReply( (int32*)&workspaces ); const_cast(this)->Unlock(); return workspaces; @@ -1730,52 +1844,68 @@ uint32 BWindow::Workspaces() const{ //------------------------------------------------------------------------------ -void BWindow::SetWorkspaces(uint32 workspaces){ +void BWindow::SetWorkspaces(uint32 workspaces) +{ Lock(); - session->WriteInt32( AS_SET_WORKSPACES ); - session->WriteInt32( (int32)workspaces ); - session->Sync( ); + fLink->StartMessage( AS_SET_WORKSPACES ); + fLink->Attach( (int32)workspaces ); + fLink->Flush(); Unlock(); } //------------------------------------------------------------------------------ -BView* BWindow::LastMouseMovedView() const{ +BView* BWindow::LastMouseMovedView() const +{ return fLastMouseMovedView; } //------------------------------------------------------------------------------ -void BWindow::MoveBy(float dx, float dy){ +void BWindow::MoveBy(float dx, float dy) +{ Lock(); - session->WriteInt32( AS_WINDOW_MOVE ); - session->WriteFloat( dx ); - session->WriteFloat( dy ); - session->Sync(); + fLink->StartMessage( AS_WINDOW_MOVE ); + fLink->Attach( dx ); + fLink->Attach( dy ); + fLink->Flush(); Unlock(); } //------------------------------------------------------------------------------ -void BWindow::MoveTo( BPoint point ){ - MoveTo( point.x, point.y ); +void BWindow::MoveTo( BPoint point ) +{ + + if (fFrame.left == point.x && fFrame.top == point.y) + return; + + fFrame.OffsetTo(point); + Lock(); + fLink->StartMessage( AS_WINDOW_MOVE ); + fLink->Attach( fFrame.left ); + fLink->Attach( fFrame.top ); + fLink->Flush(); + Unlock(); } //------------------------------------------------------------------------------ -void BWindow::MoveTo(float x, float y){ - MoveBy(x - fFrame.left, y - fFrame.top); +void BWindow::MoveTo(float x, float y) +{ + MoveTo(BPoint(x,y)); } //------------------------------------------------------------------------------ -void BWindow::ResizeBy(float dx, float dy){ +void BWindow::ResizeBy(float dx, float dy) +{ float dxNew; float dyNew; - - // stay in minimum & maximum frame limits + + // stay in minimum & maximum frame limits dxNew = (fFrame.Width() + dx) < fMinWindWidth ? fFrame.Width() - fMinWindWidth : dx; if (dxNew == dx) dxNew = (fFrame.Width() + dx) > fMaxWindWidth ? fMaxWindWidth - fFrame.Width() : dx; @@ -1784,39 +1914,50 @@ void BWindow::ResizeBy(float dx, float dy){ if (dyNew == dy) dyNew = (fFrame.Height() + dy) > fMaxWindHeight ? fMaxWindHeight - fFrame.Height() : dy; + if (dxNew == 0.0 && dyNew == 0.0) + return; + + fFrame.SetRightBottom( fFrame.RightBottom() + BPoint(dxNew, dyNew)); + Lock(); - session->WriteInt32( AS_WINDOW_RESIZE ); - session->WriteFloat( dxNew ); - session->WriteFloat( dyNew ); - session->Sync( ); - Unlock(); + fLink->StartMessage( AS_WINDOW_RESIZE ); + fLink->Attach( fFrame.Width() ); + fLink->Attach( fFrame.Height() ); + fLink->Flush(); + + top_view->ResizeBy(dxNew, dyNew); } //------------------------------------------------------------------------------ -void BWindow::ResizeTo(float width, float height){ +void BWindow::ResizeTo(float width, float height) +{ ResizeBy(width - fFrame.Width(), height - fFrame.Height()); } //------------------------------------------------------------------------------ -void BWindow::Show(){ +void BWindow::Show() +{ bool isLocked = this->IsLocked(); fShowLevel--; - if (fShowLevel == 0){ + if (fShowLevel == 0) + { STRACE(("BWindow(%s): sending AS_SHOW_WINDOW message...\n", Name() )); - if ( !isLocked ) Lock(); - session->WriteInt32( AS_SHOW_WINDOW ); - session->Sync(); - if ( !isLocked ) Unlock(); + if (Lock()) + { + fLink->StartMessage( AS_SHOW_WINDOW ); + fLink->Flush(); + Unlock(); + } } - // if it's the fist time Show() is called... start the Looper thread. + // if it's the fist time Show() is called... start the Looper thread. if ( Thread() == B_ERROR ) { - // normaly this won't happen, but I want to be sure! + // normally this won't happen, but I want to be sure! if ( !isLocked ) Lock(); Run(); } @@ -1825,12 +1966,14 @@ void BWindow::Show(){ //------------------------------------------------------------------------------ -void BWindow::Hide(){ - if (fShowLevel == 0){ +void BWindow::Hide() +{ + if (fShowLevel == 0) + { Lock(); top_view->Hide(); - session->WriteInt32( AS_HIDE_WINDOW ); - session->Sync(); + fLink->StartMessage( AS_HIDE_WINDOW ); + fLink->Flush(); Unlock(); } fShowLevel++; @@ -1838,37 +1981,43 @@ void BWindow::Hide(){ //------------------------------------------------------------------------------ -bool BWindow::IsHidden() const{ +bool BWindow::IsHidden() const +{ return fShowLevel > 0; } //------------------------------------------------------------------------------ -bool BWindow::QuitRequested(){ +bool BWindow::QuitRequested() +{ return BLooper::QuitRequested(); } //------------------------------------------------------------------------------ -thread_id BWindow::Run(){ +thread_id BWindow::Run() +{ return BLooper::Run(); } //------------------------------------------------------------------------------ -status_t BWindow::GetSupportedSuites(BMessage* data){ +status_t BWindow::GetSupportedSuites(BMessage* data) +{ status_t err = B_OK; if (!data) err = B_BAD_VALUE; - if (!err){ + if (!err) + { err = data->AddString("Suites", "suite/vnd.Be-window"); - if (!err){ + if (!err) + { BPropertyInfo propertyInfo(windowPropInfo); err = data->AddFlat("message", &propertyInfo); - if (!err){ + + if (!err) err = BLooper::GetSupportedSuites(data); - } } } return err; @@ -1888,7 +2037,10 @@ BHandler* BWindow::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specif switch (propertyInfo.FindMatch(msg, index, specifier, what, property)) { case B_ERROR: + { break; + } + case 0: case 1: case 2: @@ -1903,26 +2055,37 @@ BHandler* BWindow::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specif case 11: case 12: case 13: + { return this; - + } + case 14: - if (fKeyMenuBar){ + { + if (fKeyMenuBar) + { msg->PopSpecifier(); return fKeyMenuBar; } - else{ - BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD); + else + { + BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD); replyMsg.AddInt32( "error", B_NAME_NOT_FOUND ); replyMsg.AddString( "message", "This window doesn't have a main MenuBar"); msg->SendReply( &replyMsg ); return NULL; } + } + case 15: - // we will NOT pop the current specifier + { + // we will NOT pop the current specifier return top_view; - + } + case 16: + { return this; + } } return BLooper::ResolveSpecifier(msg, index, specifier, what, property); @@ -1932,17 +2095,15 @@ BHandler* BWindow::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specif //--------------------Private Methods------------------------------------------- // PRIVATE -void BWindow::InitData( BRect frame, - const char* title, - window_look look, - window_feel feel, - uint32 flags, - uint32 workspace){ +void BWindow::InitData( BRect frame, const char* title, window_look look, + window_feel feel, uint32 flags, uint32 workspace) +{ STRACE(("BWindow::InitData(...)\n")); fTitle=NULL; - if ( be_app == NULL ){ + if ( be_app == NULL ) + { debugger("You need a valid BApplication object before interacting with the app_server"); return; } @@ -1951,7 +2112,9 @@ void BWindow::InitData( BRect frame, if (title) SetTitle( title ); - + else + SetTitle("no_name_window"); + fFeel = feel; fLook = look; fFlags = flags; @@ -1978,22 +2141,22 @@ void BWindow::InitData( BRect frame, fPulseRate = 0; fPulseRunner = NULL; -// TODO: is this correct??? should the thread loop be started??? + // TODO: is this correct??? should the thread loop be started??? //SetPulseRate( 500000 ); -// TODO: see if you can use 'fViewsNeedPulse' + // TODO: see if you can use 'fViewsNeedPulse' fIsFilePanel = false; -// TODO: see WHEN is this used! + // TODO: see WHEN is this used! fMaskActivated = false; -// TODO: see WHEN is this used! + // TODO: see WHEN is this used! fWaitingForMenu = false; fMinimized = false; -// TODO: see WHERE you can use 'fMenuSem' + // TODO: see WHERE you can use 'fMenuSem' fMaxZoomHeight = 32768.0; fMaxZoomWidth = 32768.0; @@ -2003,15 +2166,16 @@ void BWindow::InitData( BRect frame, fMaxWindWidth = 32768.0; fLastViewToken = B_NULL_TOKEN; -// TODO: other initializations! + + // TODO: other initializations! -/* - 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 , - "w_rcv_port"); - if (receive_port==B_BAD_VALUE || receive_port==B_NO_MORE_PORTS){ + // 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 ,"w_rcv_port"); + + if (receive_port<0) + { debugger("Could not create BWindow's receive port, used for interacting with the app_server!"); delete this; } @@ -2019,49 +2183,54 @@ void BWindow::InitData( BRect frame, STRACE(("BWindow::InitData(): contacting app_server...\n")); // let app_server to know that a window has been created. - session = new BSession( receive_port, be_app->fServerFrom ); + fLink = new BPortLink(be_app->fServerTo, receive_port); // 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 - bool locked = false; + bool locked = false; if ( !(be_app->IsLocked()) ) - { be_app->Lock(); locked = true; } + { + be_app->Lock(); + locked = true; + } - PortMessage pmsg; - PortLink link(be_app->fServerFrom); - link.SetOpCode(AS_CREATE_WINDOW); + STRACE(("be_app->fServerTo is %ld\n", be_app->fServerTo)); + + status_t err; + fLink->StartMessage(AS_CREATE_WINDOW); + fLink->Attach( fFrame ); + fLink->Attach( (int32)fLook ); + fLink->Attach( (int32)fFeel ); + fLink->Attach( fFlags ); + fLink->Attach( workspace ); + fLink->Attach( _get_object_token_(this) ); + fLink->Attach( receive_port ); + fLink->Attach( fMsgPort ); + fLink->AttachString( title ); + fLink->Attach(receive_port); + fLink->Flush(); + + send_port = -1; + int32 rCode = SERVER_FALSE; + err = fLink->GetNextReply( &rCode ); + if (err == B_OK && rCode == SERVER_TRUE) + fLink->Read(&send_port); + fLink->SetSendPort(send_port); - link.Attach( fFrame ); - link.Attach( (int32)fLook ); - link.Attach( (int32)fFeel ); - link.Attach( fFlags ); - link.Attach( workspace ); - link.Attach( _get_object_token_(this) ); - link.Attach( receive_port ); - link.Attach( fMsgPort ); - link.AttachString( title ); - link.FlushWithReply(&pmsg); - - pmsg.Read(&send_port); - - // unlock, so other threads can do their job. - if( locked ) - be_app->Unlock(); - - session->SetSendPort(send_port); - - STRACE(("\tapp_server link established.\n")); - STRACE(("Window locked?: %s\n", IsLocked()?"True":"False")); - - // build and register top_view with app_server - BuildTopView(); -// top_view->PrintToStream(); + STRACE(("Server says that our send port is %ld\n", send_port)); + + STRACE(("Window locked?: %s\n", IsLocked()?"True":"False")); + + // build and register top_view with app_server + BuildTopView(); } //------------------------------------------------------------------------------ -void BWindow::task_looper(){ - +void BWindow::task_looper() +{ + STRACE(("info: BWindow::task_looper() started.\n")); + // Check that looper is locked (should be) AssertLocked(); @@ -2074,17 +2243,19 @@ void BWindow::task_looper(){ // loop: As long as we are not terminating. while (!fTerminating) { + STRACE(("info: BWindow::task_looper() waiting for message.\n")); msg = MessageFromPort(); // Did we get a message? - if (msg){ + if (msg) + { // Add to queue - fQueue->Lock(); fQueue->AddMessage(msg); - fQueue->Unlock(); + STRACE(("info: BWindow::task_looper() queued a message.\n")); } // Get message count from port + STRACE(("info: BWindow::task_looper() getting port_count...\n")); int32 msgCount = port_count(fMsgPort); if (msgCount > 0){ fQueue->Lock(); @@ -2092,43 +2263,48 @@ void BWindow::task_looper(){ { // Read 'count' messages from port (so we will not block) // We use zero as our timeout since we know there is stuff there + STRACE(("info: BWindow::task_looper() zero-wait pre-fetch messages...\n")); msg = MessageFromPort(0); + // Add messages to queue if (msg) fQueue->AddMessage(msg); } - fQueue->Unlock(); } - - // loop: As long as there are messages in the queue and - // and we are not terminating. + + STRACE(("info: BWindow::task_looper() pre-fetching complete.\n")); + // loop as long as there are messages in the queue and + // and we are not terminating. dispatchNextMessage = true; while (!fTerminating && dispatchNextMessage) { fQueue->Lock(); fLastMessage = fQueue->NextMessage(); fQueue->Unlock(); - + Lock(); - - // TODO: add code for drag & drop + + // TODO: add code for drag & drop if (!fLastMessage) { // No more messages: Unlock the looper and terminate the // dispatch loop. + STRACE(("info: BWindow::task_looper() no more pre-fetched messages.\n")); dispatchNextMessage = false; } else { + STRACE(("info: BWindow::task_looper() dispatching...\n")); + STRACE(("info: BWindow::task_looper() ")); + // Get the target handler BHandler* handler; if (_use_preferred_target_(fLastMessage)) handler = fPreferred; else gDefaultTokens.GetToken(_get_message_target_(fLastMessage), - B_HANDLER_TOKEN, - (void**)&handler); - + B_HANDLER_TOKEN, (void**)&handler); + if (!handler) handler = this; @@ -2140,6 +2316,8 @@ void BWindow::task_looper(){ if (fLastMessage->GetCurrentSpecifier(&index) == B_OK) handler = resolve_specifier(handler, fLastMessage); } + else + STRACE(("info: BWindow::task_looper() no handler for dispatch.\n")); if (handler) { @@ -2150,7 +2328,7 @@ void BWindow::task_looper(){ } } // empty our message buffer - session->Sync(); + fLink->Flush(); Unlock(); @@ -2181,38 +2359,49 @@ window_type BWindow::composeType(window_look look, switch(feel) { - case B_NORMAL_WINDOW_FEEL: - switch (look) + case B_NORMAL_WINDOW_FEEL: { - case B_TITLED_WINDOW_LOOK: - returnValue = B_TITLED_WINDOW; + switch (look) + { + case B_TITLED_WINDOW_LOOK: + { + returnValue = B_TITLED_WINDOW; + break; + } + case B_DOCUMENT_WINDOW_LOOK: + { + returnValue = B_DOCUMENT_WINDOW; + break; + } + case B_BORDERED_WINDOW_LOOK: + { + returnValue = B_BORDERED_WINDOW; + break; + } + default: + { + returnValue = B_UNTYPED_WINDOW; + } + } + break; - - case B_DOCUMENT_WINDOW_LOOK: - returnValue = B_DOCUMENT_WINDOW; + } + case B_MODAL_APP_WINDOW_FEEL: + { + if (look == B_MODAL_WINDOW_LOOK) + returnValue = B_MODAL_WINDOW; break; - - case B_BORDERED_WINDOW_LOOK: - returnValue = B_BORDERED_WINDOW; + } + case B_FLOATING_APP_WINDOW_FEEL: + { + if (look == B_FLOATING_WINDOW_LOOK) + returnValue = B_FLOATING_WINDOW; break; - + } default: + { returnValue = B_UNTYPED_WINDOW; } - break; - - case B_MODAL_APP_WINDOW_FEEL: - if (look == B_MODAL_WINDOW_LOOK) - returnValue = B_MODAL_WINDOW; - break; - - case B_FLOATING_APP_WINDOW_FEEL: - if (look == B_FLOATING_WINDOW_LOOK) - returnValue = B_FLOATING_WINDOW; - break; - - default: - returnValue = B_UNTYPED_WINDOW; } return returnValue; @@ -2220,99 +2409,119 @@ window_type BWindow::composeType(window_look look, //------------------------------------------------------------------------------ -void BWindow::decomposeType(window_type type, - window_look* look, - window_feel* feel) const +void BWindow::decomposeType(window_type type, window_look* look, + window_feel* feel) const { switch (type) { - case B_TITLED_WINDOW: - *look = B_TITLED_WINDOW_LOOK; - *feel = B_NORMAL_WINDOW_FEEL; - break; - case B_DOCUMENT_WINDOW: - *look = B_DOCUMENT_WINDOW_LOOK; - *feel = B_NORMAL_WINDOW_FEEL; - break; - case B_MODAL_WINDOW: - *look = B_MODAL_WINDOW_LOOK; - *feel = B_MODAL_APP_WINDOW_FEEL; - break; - case B_FLOATING_WINDOW: - *look = B_FLOATING_WINDOW_LOOK; - *feel = B_FLOATING_APP_WINDOW_FEEL; - break; - case B_BORDERED_WINDOW: - *look = B_BORDERED_WINDOW_LOOK; - *feel = B_NORMAL_WINDOW_FEEL; - break; - case B_UNTYPED_WINDOW: - *look = B_TITLED_WINDOW_LOOK; - *feel = B_NORMAL_WINDOW_FEEL; - break; - default: - *look = B_TITLED_WINDOW_LOOK; - *feel = B_NORMAL_WINDOW_FEEL; - break; + case B_TITLED_WINDOW: + { + *look = B_TITLED_WINDOW_LOOK; + *feel = B_NORMAL_WINDOW_FEEL; + break; + } + case B_DOCUMENT_WINDOW: + { + *look = B_DOCUMENT_WINDOW_LOOK; + *feel = B_NORMAL_WINDOW_FEEL; + break; + } + case B_MODAL_WINDOW: + { + *look = B_MODAL_WINDOW_LOOK; + *feel = B_MODAL_APP_WINDOW_FEEL; + break; + } + case B_FLOATING_WINDOW: + { + *look = B_FLOATING_WINDOW_LOOK; + *feel = B_FLOATING_APP_WINDOW_FEEL; + break; + } + case B_BORDERED_WINDOW: + { + *look = B_BORDERED_WINDOW_LOOK; + *feel = B_NORMAL_WINDOW_FEEL; + break; + } + case B_UNTYPED_WINDOW: + { + *look = B_TITLED_WINDOW_LOOK; + *feel = B_NORMAL_WINDOW_FEEL; + break; + } + default: + { + *look = B_TITLED_WINDOW_LOOK; + *feel = B_NORMAL_WINDOW_FEEL; + break; + } } } //------------------------------------------------------------------------------ -void BWindow::BuildTopView(){ - - top_view = new BView( fFrame, "top_view", - B_FOLLOW_ALL, B_WILL_DRAW); - top_view->top_level_view = true; - - // set top_view's owner, add it to window's eligible handler list - // and also set its next handler to this window. - top_view->setOwner( this ); - - // send top_view's information to app_server - session->WriteInt32( AS_LAYER_CREATE_ROOT ); - fLastViewToken = _get_object_token_( top_view ); - - top_view->attachView(top_view); - -STRACE(("BuildTopView ended\n")); +void BWindow::BuildTopView() +{ + STRACE(("BuildTopView(): enter\n")); + BRect frame = fFrame; + frame.OffsetTo(0,0); + + top_view = new BView( frame, "top_view", + B_FOLLOW_ALL, B_WILL_DRAW); + top_view->top_level_view = true; + + //inhibit check_lock() + fLastViewToken = _get_object_token_( top_view ); + + // set top_view's owner, add it to window's eligible handler list + // and also set its next handler to be this window. + + STRACE(("Calling setowner top_view=%08x this=%08x.\n", (unsigned)top_view, + (unsigned)this)); + + top_view->setOwner(this); + + //we can't use AddChild() because this is the top_view + top_view->attachView(top_view); + + STRACE(("BuildTopView ended\n")); } //------------------------------------------------------------------------------ -void BWindow::stopConnection(){ +void BWindow::stopConnection() +{ Lock(); - session->WriteInt32( AS_DELETE_WINDOW ); -// session->Sync(); + fLink->StartMessage( AS_DELETE_WINDOW ); + fLink->Flush(); Unlock(); } //------------------------------------------------------------------------------ -void BWindow::prepareView(BView *aView){ - -// TODO: implement - +void BWindow::prepareView(BView *aView) +{ + // TODO: implement } //------------------------------------------------------------------------------ -void BWindow::attachView(BView *aView){ - -// TODO: implement - +void BWindow::attachView(BView *aView) +{ + // TODO: implement } //------------------------------------------------------------------------------ -void BWindow::detachView(BView *aView){ - -// TODO: implement - +void BWindow::detachView(BView *aView) +{ + // TODO: implement } //------------------------------------------------------------------------------ -void BWindow::setFocus(BView *focusView, bool notifyInputServer){ +void BWindow::setFocus(BView *focusView, bool notifyInputServer) +{ BView* previousFocus = fFocus; if (previousFocus == focusView) @@ -2328,8 +2537,9 @@ void BWindow::setFocus(BView *focusView, bool notifyInputServer){ if (focusView != NULL) focusView->Invalidate(); -// TODO: find out why do we have to notify input server. - if (notifyInputServer){ + // TODO: find out why do we have to notify input server. + if (notifyInputServer) + { // what am I suppose to do here?? } } @@ -2338,15 +2548,16 @@ void BWindow::setFocus(BView *focusView, bool notifyInputServer){ void BWindow::handleActivation( bool active ){ - if (active){ -// TODO: talk to Ingo to make BWindow a friend for BRoster -// be_roster->UpdateActiveApp( be_app->Team() ); + if (active) + { + // TODO: talk to Ingo to make BWindow a friend for BRoster + // be_roster->UpdateActiveApp( be_app->Team() ); } - + WindowActivated( active ); - - // recursively call hook function 'WindowActivated(bool)' - // for all views attached to this window. + + // recursively call hook function 'WindowActivated(bool)' + // for all views attached to this window. activateView( top_view, active ); } @@ -2357,8 +2568,10 @@ void BWindow::activateView( BView *aView, bool active ){ aView->WindowActivated( active ); BView *child; - if ( (child = aView->first_child) ){ - while ( child ) { + if ( (child = aView->first_child) ) + { + while ( child ) + { activateView( child, active ); child = child->next_sibling; } @@ -2369,44 +2582,49 @@ void BWindow::activateView( BView *aView, bool active ){ bool BWindow::handleKeyDown( int32 raw_char, uint32 modifiers){ -// TODO: ask people if using 'raw_char' is OK ? + // TODO: ask people if using 'raw_char' is OK ? // handle BMenuBar key if ( (raw_char == B_ESCAPE) && (modifiers & B_COMMAND_KEY) && fKeyMenuBar) { -// TODO: ask Marc about 'fWaitingForMenu' member! + // TODO: ask Marc about 'fWaitingForMenu' member! // fWaitingForMenu = true; fKeyMenuBar->StartMenuBar(0, true, false, NULL); return true; } - // Command+q has been pressed, so, we will quit - if ( (raw_char == 'Q' || raw_char == 'q') && modifiers & B_COMMAND_KEY){ + // Command+q has been pressed, so, we will quit + if ( (raw_char == 'Q' || raw_char == 'q') && modifiers & B_COMMAND_KEY) + { be_app->PostMessage(B_QUIT_REQUESTED); return true; } - // Keyboard navigation through views!!!! - if ( raw_char == B_TAB){ + // Keyboard navigation through views!!!! + if ( raw_char == B_TAB) + { - // even if we have no focus view, we'll say that we will handle TAB key + // even if we have no focus view, we'll say that we will handle TAB key if (!fFocus) return true; BView *nextFocus; - if (modifiers & B_CONTROL_KEY & B_SHIFT_KEY){ + if (modifiers & B_CONTROL_KEY & B_SHIFT_KEY) + { nextFocus = findPrevView( fFocus, B_NAVIGABLE_JUMP ); } else - if (modifiers & B_CONTROL_KEY){ + if (modifiers & B_CONTROL_KEY) + { nextFocus = findNextView( fFocus, B_NAVIGABLE_JUMP ); } else - if (modifiers & B_SHIFT_KEY){ + if (modifiers & B_SHIFT_KEY) + { nextFocus = findPrevView( fFocus, B_NAVIGABLE ); } else @@ -2420,30 +2638,34 @@ bool BWindow::handleKeyDown( int32 raw_char, uint32 modifiers){ // Handle shortcuts int index; - if ( (index = findShortcut(raw_char, modifiers)) >=0){ + if ( (index = findShortcut(raw_char, modifiers)) >=0) + { _BCmdKey *cmdKey; cmdKey = (_BCmdKey*)accelList.ItemAt( index ); // we'll give the message to the focus view - if (cmdKey->targetToken == B_ANY_TOKEN){ + if (cmdKey->targetToken == B_ANY_TOKEN) + { fFocus->MessageReceived( cmdKey->message ); return true; } - else{ + else + { BHandler *handler; BHandler *aHandler; int noOfHandlers; - // search for a match through BLooper's list of eligible handlers + // search for a match through BLooper's list of eligible handlers handler = NULL; noOfHandlers = CountHandlers(); for( int i=0; i < noOfHandlers; i++ ) - // do we have a match? + + // do we have a match? if ( _get_object_token_( aHandler = HandlerAt(i) ) == cmdKey->targetToken) { - // yes, we do. + // yes, we do. handler = aHandler; break; } @@ -2451,14 +2673,15 @@ bool BWindow::handleKeyDown( int32 raw_char, uint32 modifiers){ if ( handler ) handler->MessageReceived( cmdKey->message ); else - // if no handler was found, BWindow will handle the message + // if no handler was found, BWindow will handle the message MessageReceived( cmdKey->message ); } return true; } - // if is pressed and we have a default button - if (DefaultButton() && (raw_char == B_ENTER)){ + // if is pressed and we have a default button + if (DefaultButton() && (raw_char == B_ENTER)) + { const char *chars; // just to be sure CurrentMessage()->FindString("bytes", &chars); @@ -2471,57 +2694,67 @@ bool BWindow::handleKeyDown( int32 raw_char, uint32 modifiers){ } //------------------------------------------------------------------------------ - -BView* BWindow::sendMessageUsingEventMask2( BView* aView, int32 message, BPoint where ){ - +BView* BWindow::sendMessageUsingEventMask2( BView* aView, int32 message, BPoint where ) +{ BView *destView; destView = NULL; - if ( aView->fBounds.Contains( aView->ConvertFromScreen(where) ) && - !aView->first_child ){ - return aView; + STRACE(("info: BWindow::sendMessageUsingEventMask2() recursing to view %s with point %f,%f.\n", + aView->Name() ? aView->Name() : "", aView->ConvertFromScreen(where).x, aView->ConvertFromScreen(where).y)); + + if ( aView->fBounds.Contains( aView->ConvertFromScreen(where) )) + { + destView = aView; //this is the lower-most view under the mouse so far + STRACE(("info: BWindow::sendMessageUsingEventMask() targeted view %s.\n", + aView->Name() ? aView->Name() : "")); } - // Code for Event Masks - BView *child; - if ( (child = aView->first_child) ){ - while ( child ) { - // see if a BView registered for mouse events and it's not the current focus view - if ( child->fEventMask & B_POINTER_EVENTS && - aView != fFocus ){ - switch (message){ - case B_MOUSE_DOWN:{ - child->MouseDown( child->ConvertFromScreen( where ) ); - } - break; - - case B_MOUSE_UP:{ - child->MouseUp( child->ConvertFromScreen( where ) ); - } - break; - - case B_MOUSE_MOVED:{ - BMessage *dragMessage; - -// TODO: get the dragMessage if any - // for now... - dragMessage = NULL; - -/* TODO: after you have an example working, see if a view that registered for such events, - does reveive B_MOUSE_MOVED with other options than B_OUTDIDE_VIEW !!! - like: B_INSIDE_VIEW, B_ENTERED_VIEW, B_EXITED_VIEW -*/ - child->MouseMoved( ConvertFromScreen(where), B_OUTSIDE_VIEW , dragMessage); - } - break; + // Code for Event Masks + BView *child = aView->first_child; + while ( child ) + { + // see if a BView registered for mouse events and it's not the current focus view + if ( aView != fFocus && + child->fEventMask & (B_POINTER_EVENTS | B_POINTER_EVENTS << 16)) + { + switch (message) + { + case B_MOUSE_DOWN: + { + child->MouseDown( child->ConvertFromScreen( where ) ); } + break; + + case B_MOUSE_UP: + { + //clear MouseEventMask on MouseUp + child->fEventMask &= 0x0000FFFF; + child->MouseUp( child->ConvertFromScreen( where ) ); + } + break; + + case B_MOUSE_MOVED: + { + BMessage *dragMessage; + + // TODO: get the dragMessage if any for now... + dragMessage = NULL; + + // TODO: after you have an example working, see if a view that registered for such events, + // does reveive B_MOUSE_MOVED with other options than B_OUTDIDE_VIEW !!! + // like: B_INSIDE_VIEW, B_ENTERED_VIEW, B_EXITED_VIEW + + child->MouseMoved( child->ConvertFromScreen(where), B_OUTSIDE_VIEW , dragMessage); + } + break; } - if (destView == NULL) - destView = sendMessageUsingEventMask2( child, message, where ); - else - sendMessageUsingEventMask2( child, message, where ); - child = child->next_sibling; } + BView *target = sendMessageUsingEventMask2( child, message, where ); + + // one of the children contains the point + if (target) + destView = target; + child = child->next_sibling; } return destView; @@ -2529,64 +2762,81 @@ BView* BWindow::sendMessageUsingEventMask2( BView* aView, int32 message, BPoint //------------------------------------------------------------------------------ -void BWindow::sendMessageUsingEventMask( int32 message, BPoint where ){ - BView* destView; +void BWindow::sendMessageUsingEventMask( int32 message, BPoint where ) +{ + BView *destView = NULL; - destView = sendMessageUsingEventMask2(top_view, message, where); + destView = sendMessageUsingEventMask2(top_view, message, where); - // I'm SURE this is NEVER going to happen, but, durring development of BWindow, it may slip a NULL value - if (!destView){ + // I'm SURE this is NEVER going to happen, but, during development of + // BWindow, it may slip a NULL value + if (!destView) + { // debugger("There is no BView under the mouse;"); return; } - switch( message ){ - case B_MOUSE_DOWN:{ + switch( message ) + { + case B_MOUSE_DOWN: + { setFocus( destView ); destView->MouseDown( destView->ConvertFromScreen( where ) ); - break;} - - case B_MOUSE_UP:{ + break; + } + case B_MOUSE_UP: + { destView->MouseUp( destView->ConvertFromScreen( where ) ); - break;} - - case B_MOUSE_MOVED:{ + break; + } + case B_MOUSE_MOVED: + { BMessage *dragMessage; -// TODO: add code for drag and drop - // for now... + // TODO: add code for drag and drop + // for now... dragMessage = NULL; - if (destView != fLastMouseMovedView){ - fLastMouseMovedView->MouseMoved( destView->ConvertFromScreen( where ), B_EXITED_VIEW , dragMessage); - destView->MouseMoved( ConvertFromScreen( where ), B_ENTERED_VIEW, dragMessage); - fLastMouseMovedView = destView; + if (destView != fLastMouseMovedView) + { + fLastMouseMovedView->MouseMoved( destView->ConvertFromScreen( where ), B_EXITED_VIEW , dragMessage); + destView->MouseMoved( ConvertFromScreen( where ), B_ENTERED_VIEW, dragMessage); + fLastMouseMovedView = destView; } - else{ - destView->MouseMoved( ConvertFromScreen( where ), B_INSIDE_VIEW , dragMessage); + else + { + destView->MouseMoved( ConvertFromScreen( where ), B_INSIDE_VIEW , dragMessage); } - // I'm guessing that B_OUTSIDE_VIEW is given to the view that has focus, I'll have to check -// TODO: Do a research on mouse capturing, maybe it has something to do with this - if (fFocus != destView) - fFocus->MouseMoved( ConvertFromScreen( where ), B_OUTSIDE_VIEW , dragMessage); + // I'm guessing that B_OUTSIDE_VIEW is given to the view that has focus, + // I'll have to check + + // TODO: Do research on mouse capturing -- maybe it has something to do + // with this + if (fFocus != destView) + fFocus->MouseMoved( ConvertFromScreen( where ), B_OUTSIDE_VIEW , dragMessage); break;} } } //------------------------------------------------------------------------------ -BMessage* BWindow::ConvertToMessage(void* raw, int32 code){ +BMessage* BWindow::ConvertToMessage(void* raw, int32 code) +{ return BLooper::ConvertToMessage( raw, code ); } //------------------------------------------------------------------------------ -void BWindow::sendPulse( BView* aView ){ +void BWindow::sendPulse( BView* aView ) +{ BView *child; - if ( (child = aView->first_child) ){ - while ( child ) { - if ( child->Flags() & B_PULSE_NEEDED ) child->Pulse(); + if ( (child = aView->first_child) ) + { + while ( child ) + { + if ( child->Flags() & B_PULSE_NEEDED ) + child->Pulse(); sendPulse( child ); child = child->next_sibling; } @@ -2595,18 +2845,21 @@ void BWindow::sendPulse( BView* aView ){ //------------------------------------------------------------------------------ -int32 BWindow::findShortcut( uint32 key, uint32 modifiers ){ +int32 BWindow::findShortcut( uint32 key, uint32 modifiers ) +{ int32 index, noOfItems; index = -1; noOfItems = accelList.CountItems(); - for ( int32 i = 0; i < noOfItems; i++ ) { + for ( int32 i = 0; i < noOfItems; i++ ) + { _BCmdKey* tempCmdKey; tempCmdKey = (_BCmdKey*)accelList.ItemAt(i); - if (tempCmdKey->key == key && tempCmdKey->modifiers == modifiers){ + if (tempCmdKey->key == key && tempCmdKey->modifiers == modifiers) + { index = i; break; } @@ -2617,14 +2870,17 @@ int32 BWindow::findShortcut( uint32 key, uint32 modifiers ){ //------------------------------------------------------------------------------ -BView* BWindow::findView(BView* aView, int32 token){ +BView* BWindow::findView(BView* aView, int32 token) +{ if ( _get_object_token_(aView) == token ) return aView; BView *child; - if ( (child = aView->first_child) ){ - while ( child ) { + if ( (child = aView->first_child) ) + { + while ( child ) + { BView* view; if ( (view = findView( child, token )) ) return view; @@ -2637,14 +2893,17 @@ BView* BWindow::findView(BView* aView, int32 token){ //------------------------------------------------------------------------------ -BView* BWindow::findView(BView* aView, const char* viewName) const{ +BView* BWindow::findView(BView* aView, const char* viewName) const +{ if ( strcmp( viewName, aView->Name() ) == 0) return aView; BView *child; - if ( (child = aView->first_child) ){ - while ( child ) { + if ( (child = aView->first_child) ) + { + while ( child ) + { BView* view; if ( (view = findView( child, viewName )) ) return view; @@ -2657,15 +2916,17 @@ BView* BWindow::findView(BView* aView, const char* viewName) const{ //------------------------------------------------------------------------------ -BView* BWindow::findView(BView* aView, BPoint point) const{ +BView* BWindow::findView(BView* aView, BPoint point) const +{ - if ( aView->Bounds().Contains(point) && - !aView->first_child ) + if ( aView->Bounds().Contains(point) && !aView->first_child ) return aView; BView *child; - if ( (child = aView->first_child) ){ - while ( child ) { + if ( (child = aView->first_child) ) + { + while ( child ) + { BView* view; if ( (view = findView( child, point )) ) return view; @@ -2678,39 +2939,41 @@ BView* BWindow::findView(BView* aView, BPoint point) const{ //------------------------------------------------------------------------------ -BView* BWindow::findNextView( BView *focus, uint32 flags){ +BView* BWindow::findNextView( BView *focus, uint32 flags) +{ bool found; found = false; BView *nextFocus; nextFocus = focus; - /* Ufff... this toked me some time... this is the best form I've reached. - This algorithm searches the tree for BViews that accept focus. - */ - while (!found){ + // Ufff... this toked me some time... this is the best form I've reached. + // This algorithm searches the tree for BViews that accept focus. + while (!found) + { if (nextFocus->first_child) nextFocus = nextFocus->first_child; - else + else + { if (nextFocus->next_sibling) nextFocus = nextFocus->next_sibling; - else{ - while( !nextFocus->next_sibling && nextFocus->parent ){ + else + { + while( !nextFocus->next_sibling && nextFocus->parent ) nextFocus = nextFocus->parent; - } if (nextFocus == top_view) nextFocus = nextFocus->first_child; else nextFocus = nextFocus->next_sibling; } - + } + if (nextFocus->Flags() & flags) found = true; - /* It means that the hole tree has been searched and there is no - view with B_NAVIGABLE_JUMP flag set! - */ + // It means that the hole tree has been searched and there is no + // view with B_NAVIGABLE_JUMP flag set! if (nextFocus == focus) return NULL; } @@ -2720,7 +2983,8 @@ BView* BWindow::findNextView( BView *focus, uint32 flags){ //------------------------------------------------------------------------------ -BView* BWindow::findPrevView( BView *focus, uint32 flags){ +BView* BWindow::findPrevView( BView *focus, uint32 flags) +{ bool found; found = false; @@ -2729,30 +2993,32 @@ BView* BWindow::findPrevView( BView *focus, uint32 flags){ BView *aView; - while (!found){ + while (!found) + { if ( (aView = findLastChild(prevFocus)) ) prevFocus = aView; - else + else + { if (prevFocus->prev_sibling) prevFocus = prevFocus->prev_sibling; - else{ - while( !prevFocus->prev_sibling && prevFocus->parent ){ + else + { + while( !prevFocus->prev_sibling && prevFocus->parent ) prevFocus = prevFocus->parent; - } if (prevFocus == top_view) prevFocus = findLastChild( prevFocus ); else prevFocus = prevFocus->prev_sibling; } - + } + if (prevFocus->Flags() & flags) found = true; - /* It means that the hole tree has been searched and there is no - view with B_NAVIGABLE_JUMP flag set! - */ + // It means that the hole tree has been searched and there is no + // view with B_NAVIGABLE_JUMP flag set! if (prevFocus == focus) return NULL; } @@ -2762,9 +3028,11 @@ BView* BWindow::findPrevView( BView *focus, uint32 flags){ //------------------------------------------------------------------------------ -BView* BWindow::findLastChild(BView *parent){ +BView* BWindow::findLastChild(BView *parent) +{ BView *aView; - if ( (aView = parent->first_child) ){ + if ( (aView = parent->first_child) ) + { while (aView->next_sibling) aView = aView->next_sibling; @@ -2776,75 +3044,48 @@ BView* BWindow::findLastChild(BView *parent){ //------------------------------------------------------------------------------ -void BWindow::drawAllViews(BView* aView){ - - BMessageQueue *queue; - BMessage *msg; - - queue = MessageQueue(); - - // process all update BMessages from message queue - queue->Lock(); - while ( (msg = queue->FindMessage( (uint32)_UPDATE_ )) ) +void BWindow::drawAllViews(BView* aView) +{ + if(Lock()) { Lock(); - DispatchMessage( msg, this ); + top_view->Invalidate(); Unlock(); - - queue->RemoveMessage( msg ); - } - queue->Unlock(); - - // we'll send a message to app_server, tell him that we want all our views updated - Lock(); - session->WriteInt32( AS_UPDATE_IF_NEEDED ); - session->Sync(); - Unlock(); - -// TODO: update!!!!!!!!!!!!!!!!!!! - // process all update messages from receive port queue - bool over = false; - while (!over) - { - msg = MessageFromPort(0); - if (msg){ - switch (msg->what){ - - case _ALL_UPDATED_:{ - over = true; - }break; - - case _UPDATE_:{ - Lock(); - DispatchMessage( msg, this ); - Unlock(); - }break; - - default:{ - queue->Lock(); - queue->AddMessage(msg); - queue->Unlock(); - }break; - } - } } + Sync(); } //------------------------------------------------------------------------------ -void BWindow::DoUpdate(BView* aView, BRect& area){ - aView->do_owner_check(); -printf("------------\n"); -area.PrintToStream(); -printf("------------\n"); - session->WriteInt32( AS_BEGIN_UPDATE ); - aView->Draw( area ); - session->WriteInt32( AS_END_UPDATE ); - - BView *child; - if ( (child = aView->first_child) ){ - while ( child ) { - if ( area.Intersects( child->Frame() ) ){ +void BWindow::DoUpdate(BView* aView, BRect& area) +{ + + STRACE(("info: BWindow::drawView() BRect(%f,%f,%f,%f) called.\n", + area.left, area.top, area.right, area.bottom)); + + aView->check_lock(); + fLink->StartMessage(AS_BEGIN_UPDATE); + + if (aView->Flags() & B_WILL_DRAW) + aView->Draw( area ); + else + { + rgb_color c = aView->HighColor(); + aView->SetHighColor(aView->ViewColor()); + aView->FillRect(aView->Bounds(), B_SOLID_HIGH); + aView->SetHighColor(c); + } + + aView->check_lock(); + fLink->StartMessage(AS_END_UPDATE); + + BView *child; + if ( (child = aView->first_child) ) + { + while ( child ) + { + if ( area.Intersects( child->Frame() ) ) + { BRect newArea; newArea = area & child->Frame(); child->ConvertFromParent( &newArea ); @@ -2853,19 +3094,21 @@ printf("------------\n"); child = child->next_sibling; } } + fLink->Flush(); } //------------------------------------------------------------------------------ -void BWindow::SetIsFilePanel(bool yes){ - -// TODO: is this not enough? +void BWindow::SetIsFilePanel(bool yes) +{ + // TODO: is this not enough? fIsFilePanel = yes; } //------------------------------------------------------------------------------ -bool BWindow::IsFilePanel() const{ +bool BWindow::IsFilePanel() const +{ return fIsFilePanel; } @@ -2902,7 +3145,7 @@ void BWindow::PrintToStream() const{ top_view name = %s\ focus view name = %s\ lastMouseMoved = %s\ - session = %s\ + fLink = %s\ KeyMenuBar name = %s\ DefaultButton = %s\ # of shortcuts = %ld", @@ -2918,7 +3161,7 @@ void BWindow::PrintToStream() const{ top_view!=NULL? top_view->Name():"NULL", fFocus!=NULL? fFocus->Name():"NULL", fLastMouseMovedView!=NULL? fLastMouseMovedView->Name():"NULL", - session!=NULL? "In place":"NULL", + fLink!=NULL? "In place":"NULL", fKeyMenuBar!=NULL? fKeyMenuBar->Name():"NULL", fDefaultButton!=NULL? fDefaultButton->Name():"NULL", accelList.CountItems());