diff --git a/headers/private/app/LinkMsgReader.h b/headers/private/app/LinkMsgReader.h index 8fd5310764..c486c88032 100644 --- a/headers/private/app/LinkMsgReader.h +++ b/headers/private/app/LinkMsgReader.h @@ -22,7 +22,7 @@ class LinkMsgReader { void SetPort(port_id port); port_id Port(void) { return fReceivePort; } - status_t GetNextMessage(int32 *code, bigtime_t timeout = B_INFINITE_TIMEOUT); + status_t GetNextMessage(int32 &code, bigtime_t timeout = B_INFINITE_TIMEOUT); status_t Read(void *data, ssize_t size); status_t ReadString(char **string); template status_t Read(Type *data) diff --git a/headers/private/app/LinkMsgSender.h b/headers/private/app/LinkMsgSender.h index e3b5ef7d9e..ab11112cfd 100644 --- a/headers/private/app/LinkMsgSender.h +++ b/headers/private/app/LinkMsgSender.h @@ -34,7 +34,7 @@ class LinkMsgSender { //status_t FlushWithReply(int32 *code); status_t Attach(const void *data, size_t size); - status_t AttachString(const char *string); + status_t AttachString(const char *string, int32 length = -1); template status_t Attach(const Type& data) { return Attach(&data, sizeof(Type)); diff --git a/headers/private/app/PortLink.h b/headers/private/app/PortLink.h index 347dbc1526..4c0fbb8ad3 100644 --- a/headers/private/app/PortLink.h +++ b/headers/private/app/PortLink.h @@ -51,7 +51,7 @@ class BPortLink { status_t Flush(bigtime_t timeout = B_INFINITE_TIMEOUT, bool needsReply = false); status_t Attach(const void *data, ssize_t size); - status_t AttachString(const char *string); + status_t AttachString(const char *string, int32 length = -1); status_t AttachRegion(const BRegion ®ion); status_t AttachShape(BShape &shape); template status_t Attach(const Type& data); @@ -61,13 +61,17 @@ class BPortLink { void SetReplyPort(port_id port); port_id ReplyPort(); - status_t GetNextReply(int32 *code, bigtime_t timeout = B_INFINITE_TIMEOUT); + status_t GetNextReply(int32 &code, bigtime_t timeout = B_INFINITE_TIMEOUT); status_t Read(void *data, ssize_t size); status_t ReadString(char **string); status_t ReadRegion(BRegion *region); status_t ReadShape(BShape *shape); template status_t Read(Type *data); + // convenience methods + + status_t FlushWithReply(int32 &code); + protected: LinkMsgReader *fReader; LinkMsgSender *fSender; @@ -118,9 +122,9 @@ BPortLink::Attach(const void *data, ssize_t size) } inline status_t -BPortLink::AttachString(const char *string) +BPortLink::AttachString(const char *string, int32 length) { - return fSender->AttachString(string); + return fSender->AttachString(string, length); } template status_t @@ -144,7 +148,7 @@ BPortLink::ReplyPort() } inline status_t -BPortLink::GetNextReply(int32 *code, bigtime_t timeout) +BPortLink::GetNextReply(int32 &code, bigtime_t timeout) { return fReader->GetNextMessage(code, timeout); } diff --git a/src/kits/app/AppServerLink.cpp b/src/kits/app/AppServerLink.cpp index 22c9cbc4ba..273ee775f1 100644 --- a/src/kits/app/AppServerLink.cpp +++ b/src/kits/app/AppServerLink.cpp @@ -75,7 +75,7 @@ BAppServerLink::FlushWithReply(int32 *code) if (err < B_OK) return err; - return GetNextReply(code); + return GetNextReply(*code); } } // namespace BPrivate diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp index 9e1a337326..76b54e3c2f 100644 --- a/src/kits/app/Application.cpp +++ b/src/kits/app/Application.cpp @@ -1109,7 +1109,7 @@ BApplication::connect_to_app_server() // 4) int32 - handler ID token of the app // 5) char * - signature of the regular app BPortLink link(fServerFrom, fServerTo); - int32 code = SERVER_FALSE; + int32 code; link.StartMessage(AS_CREATE_APP); link.Attach(fServerTo); @@ -1117,13 +1117,9 @@ BApplication::connect_to_app_server() link.Attach(Team()); link.Attach(_get_object_token_(this)); link.AttachString(fAppName); - link.Flush(); - link.GetNextReply(&code); - // Reply code: SERVER_TRUE - // Reply data: - // 1) port_id server-side application port (fServerFrom value) - if (code == SERVER_TRUE) + if (link.FlushWithReply(code) == B_OK + && code == SERVER_TRUE) link.Read(&fServerFrom); else debugger("BApplication: couldn't obtain new app_server comm port"); diff --git a/src/kits/app/LinkMsgReader.cpp b/src/kits/app/LinkMsgReader.cpp index 54a68d56ee..9da821dadd 100644 --- a/src/kits/app/LinkMsgReader.cpp +++ b/src/kits/app/LinkMsgReader.cpp @@ -54,7 +54,7 @@ LinkMsgReader::SetPort(port_id port) status_t -LinkMsgReader::GetNextMessage(int32 *code, bigtime_t timeout) +LinkMsgReader::GetNextMessage(int32 &code, bigtime_t timeout) { int32 remaining; @@ -92,7 +92,7 @@ LinkMsgReader::GetNextMessage(int32 *code, bigtime_t timeout) return B_ERROR; } - *code = header->code; + code = header->code; fRecvPosition += sizeof(message_header); STRACE(("info: LinkMsgReader got header %s [%ld %ld %ld] from port %ld.\n", @@ -247,8 +247,8 @@ LinkMsgReader::ReadString(char **_string) if (status < B_OK) return status; - if (length > 0) { - char *string = (char *)malloc(length); + if (length >= 0) { + char *string = (char *)malloc(length + 1); if (string == NULL) { fRecvPosition -= sizeof(int32); // rewind the transaction return B_NO_MEMORY; @@ -261,8 +261,8 @@ LinkMsgReader::ReadString(char **_string) return status; } - // make sure the string is null terminated (although it already should be) - string[length - 1] = '\0'; + // make sure the string is null terminated + string[length] = '\0'; *_string = string; return B_OK; diff --git a/src/kits/app/LinkMsgSender.cpp b/src/kits/app/LinkMsgSender.cpp index 3ff425d2ed..d20e3e0fbb 100644 --- a/src/kits/app/LinkMsgSender.cpp +++ b/src/kits/app/LinkMsgSender.cpp @@ -156,19 +156,23 @@ LinkMsgSender::Attach(const void *data, size_t size) status_t -LinkMsgSender::AttachString(const char *string) +LinkMsgSender::AttachString(const char *string, int32 length) { if (string == NULL) string = ""; - int32 length = strlen(string) + 1; + if (length == -1) + length = strlen(string); + status_t status = Attach(length); if (status < B_OK) return status; - status = Attach(string, length); - if (status < B_OK) - fCurrentEnd -= sizeof(int32); // rewind the transaction + if (length > 0) { + status = Attach(string, length); + if (status < B_OK) + fCurrentEnd -= sizeof(int32); // rewind the transaction + } return status; } diff --git a/src/kits/app/PortLink.cpp b/src/kits/app/PortLink.cpp index 81726d9323..db71038ddc 100644 --- a/src/kits/app/PortLink.cpp +++ b/src/kits/app/PortLink.cpp @@ -87,3 +87,14 @@ BPortLink::AttachShape(BShape &shape) fSender->Attach(opList, opCount * sizeof(uint32)); return fSender->Attach(ptList, ptCount * sizeof(BPoint)); } + + +status_t +BPortLink::FlushWithReply(int32 &code) +{ + status_t status = Flush(); + if (status < B_OK) + return status; + + return GetNextReply(code); +} diff --git a/src/kits/app/ServerMemIO.cpp b/src/kits/app/ServerMemIO.cpp index c350c3a5dd..6ad5bcd7fe 100644 --- a/src/kits/app/ServerMemIO.cpp +++ b/src/kits/app/ServerMemIO.cpp @@ -39,42 +39,36 @@ #include #include "ServerMemIO.h" + ServerMemIO::ServerMemIO(size_t size) : fLen(0), fPhys(0), fPos(0) { - if(size>0) - { - BPrivate::BAppServerLink link; - link.StartMessage(AS_ACQUIRE_SERVERMEM); - link.Attach(size); - link.Attach(link.ReplyPort()); - link.Flush(); - - int32 code; - link.GetNextReply(&code); - - if(code==SERVER_TRUE) - { - area_info ai; - - link.Read(&fSourceArea); - link.Read(&fOffset); - - if(fSourceArea>0 && get_area_info(fSourceArea,&ai)==B_OK) - { - fPhys=size; - - fArea=clone_area("ServerMemIO area",(void**)&fBuf,B_CLONE_ADDRESS, - B_READ_AREA|B_WRITE_AREA,fSourceArea); - - fBuf+=fOffset; - } - else - { - debugger("PANIC: bad data or something in ServerMemIO constructor"); - } + if (size == 0) + return; + + BPrivate::BAppServerLink link; + link.StartMessage(AS_ACQUIRE_SERVERMEM); + link.Attach(size); + link.Attach(link.ReplyPort()); + + int32 code; + if (link.FlushWithReply(&code) == B_OK + && code == SERVER_TRUE) { + area_info info; + + link.Read(&fSourceArea); + link.Read(&fOffset); + + if (fSourceArea >= B_OK && get_area_info(fSourceArea, &info) == B_OK) { + fPhys = size; + fArea = clone_area("ServerMemIO area", (void **)&fBuf, B_CLONE_ADDRESS, + B_READ_AREA|B_WRITE_AREA, fSourceArea); + + fBuf += fOffset; + } else { + debugger("PANIC: bad data or something in ServerMemIO constructor"); } } } diff --git a/src/kits/interface/ClientFontList.cpp b/src/kits/interface/ClientFontList.cpp index f38f4435fd..664f9da28a 100644 --- a/src/kits/interface/ClientFontList.cpp +++ b/src/kits/interface/ClientFontList.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS +// Copyright (c) 2001-2005, Haiku // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -44,312 +44,274 @@ # define STRACE(x) ; #endif -class FontListFamily -{ -public: - FontListFamily(void); - ~FontListFamily(void); - BString name; - BList *styles; - int32 flags; + +class FontListFamily { + public: + FontListFamily(void); + ~FontListFamily(void); + + BString name; + BList *styles; + int32 flags; }; + FontListFamily::FontListFamily(void) { - styles=new BList(0); - flags=0; + styles = new BList(0); + flags = 0; } + FontListFamily::~FontListFamily(void) { - BString *s; - s=(BString*)styles->RemoveItem(0L); - while(s) - { - delete s; - s=(BString*)styles->RemoveItem(0L); + for (int32 i = styles->CountItems(); i-- > 0; ) { + delete (BString *)styles->ItemAt(i); } + delete styles; } + ClientFontList::ClientFontList(void) { STRACE(("ClientFontList()\n")); - familylist=new BList(0); - fontlock=create_sem(1,"fontlist_sem"); + familylist = new BList(0); + fontlock = create_sem(1,"fontlist_sem"); } + ClientFontList::~ClientFontList(void) { STRACE(("~ClientFontList()\n")); acquire_sem(fontlock); - font_family *fam; - while(familylist->ItemAt(0L)!=NULL) - { - fam=(font_family *)familylist->RemoveItem(0L); - delete fam; + for (int32 i = familylist->CountItems(); i-- > 0; ) { + delete (font_family *)familylist->ItemAt(i); } - familylist->MakeEmpty(); + delete familylist; delete_sem(fontlock); } -bool ClientFontList::Update(bool check_only) + +bool +ClientFontList::Update(bool checkOnly) { - STRACE(("ClientFontList::Update(%s) - %s\n", (check_only)?"true":"false",SERVER_FONT_LIST)); - + STRACE(("ClientFontList::Update(%s) - %s\n", checkOnly ? "true" : "false", + SERVER_FONT_LIST)); + // Open the font list kept in font list acquire_sem(fontlock); // We're going to ask the server whether the list has changed - port_id serverport; - serverport=find_port(SERVER_PORT_NAME); - - bool needs_update=true; - BPortLink serverlink(serverport); + port_id port = find_port(SERVER_PORT_NAME); - if(serverport!=B_NAME_NOT_FOUND) - { - 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=(code==SERVER_TRUE)?true:false; - } - else - { + bool needsUpdate = true; + BPortLink link(port); + + if (port >= B_OK) { + link.StartMessage(AS_QUERY_FONTS_CHANGED); + + int32 code; + if (link.FlushWithReply(code) == B_OK) + needsUpdate = code == SERVER_TRUE; + } else { STRACE(("ClientFontList::Update(): Couldn't find app_server port\n")); } - if(check_only) - { + if (checkOnly || !needsUpdate) { release_sem(fontlock); - return needs_update; + return needsUpdate; } - // Don't update the list if nothing has changed - if(needs_update) - { - BFile file(SERVER_FONT_LIST,B_READ_ONLY); - BMessage fontmsg, familymsg; - - if(file.InitCheck()==B_OK) - { - if(fontmsg.Unflatten(&file)==B_OK) - { - #ifdef DEBUG_CLIENT_FONT_LIST - printf("Font message contents:\n"); - fontmsg.PrintToStream(); - #endif + BFile file(SERVER_FONT_LIST,B_READ_ONLY); + BMessage fontMessage; - // Empty the font list - FontListFamily *flf=(FontListFamily*)familylist->RemoveItem(0L); - BString sty, extra; - int32 famindex, styindex; - bool tempbool; - - while(flf) - { - STRACE(("Removing %s from list\n",flf->name.String())); - delete flf; - flf=(FontListFamily*)familylist->RemoveItem(0L); - } - STRACE(("\n")); - - famindex=0; - - // Repopulate with new listings - while(fontmsg.FindMessage("family",famindex,&familymsg)==B_OK) - { - famindex++; - - flf=new FontListFamily(); - familylist->AddItem(flf); - familymsg.FindString("name",&(flf->name)); + if (file.InitCheck() == B_OK + && fontMessage.Unflatten(&file) == B_OK) { +#ifdef DEBUG_CLIENT_FONT_LIST + printf("Font message contents:\n"); + fontmsg.PrintToStream(); +#endif - STRACE(("Adding %s to list\n",flf->name.String())); - styindex=0; + // Empty the font list + FontListFamily *family; + while ((family = (FontListFamily *)familylist->RemoveItem(0L)) != NULL) { + STRACE(("Removing %s from list\n", family->name.String())); + delete family; + + } + STRACE(("\n")); - // populate family with styles - while(familymsg.FindString("styles",styindex,&sty)==B_OK) - { - STRACE(("\tAdding %s\n",sty.String())); - styindex++; - flf->styles->AddItem(new BString(sty)); - } - - if(familymsg.FindBool("tuned",&tempbool)==B_OK) - { - STRACE(("Family %s has tuned fonts\n", flf->name.String())); - flf->flags|=B_HAS_TUNED_FONT; - } - - if(familymsg.FindBool("fixed",&tempbool)==B_OK) - { - STRACE(("Family %s is fixed-width\n", flf->name.String())); - flf->flags|=B_IS_FIXED; - } - familymsg.MakeEmpty(); - - } + // Repopulate with new listings + int32 familyIndex = 0; + BMessage familyMessage; + while (fontMessage.FindMessage("family", familyIndex++, &familyMessage) == B_OK) { + family = new FontListFamily(); + familylist->AddItem(family); + familyMessage.FindString("name", &family->name); - serverlink.StartMessage(AS_UPDATED_CLIENT_FONTLIST); - serverlink.Flush(); - - release_sem(fontlock); - return false; + STRACE(("Adding %s to list\n", family->name.String())); + + int32 styleIndex = 0; + + // populate family with styles + BString string; + while (familyMessage.FindString("styles", styleIndex++, &string) == B_OK) { + STRACE(("\tAdding %s\n", string.String())); + family->styles->AddItem(new BString(string)); + } + + if (familyMessage.FindBool("tuned")) { + STRACE(("Family %s has tuned fonts\n", family->name.String())); + family->flags |= B_HAS_TUNED_FONT; + } + + if (familyMessage.FindBool("fixed")) { + STRACE(("Family %s is fixed-width\n", family->name.String())); + family->flags |= B_IS_FIXED; + } + familyMessage.MakeEmpty(); + } + + link.StartMessage(AS_UPDATED_CLIENT_FONTLIST); + link.Flush(); + } - } // end if Unflatten==B_OK - } // end if InitCheck==B_OK - } // end if needs_update - release_sem(fontlock); return false; } -int32 ClientFontList::CountFamilies(void) + +int32 +ClientFontList::CountFamilies(void) { -STRACE(("ClientFontList::CountFamilies\n")); + STRACE(("ClientFontList::CountFamilies\n")); acquire_sem(fontlock); - int32 count=familylist->CountItems(); + int32 count = familylist->CountItems(); release_sem(fontlock); return count; } -status_t ClientFontList::GetFamily(int32 index, font_family *name, uint32 *flags) + +status_t +ClientFontList::GetFamily(int32 index, font_family *name, uint32 *flags) { STRACE(("ClientFontList::GetFamily(%ld)\n",index)); - if(!name) - { + if (!name) { STRACE(("ClientFontList::GetFamily: NULL font_family parameter\n")); - return B_ERROR; + return B_BAD_VALUE; } - + acquire_sem(fontlock); - FontListFamily *flf=(FontListFamily*)familylist->ItemAt(index); - if(!flf) - { + + FontListFamily *family = (FontListFamily *)familylist->ItemAt(index); + if (family == NULL) { STRACE(("ClientFontList::GetFamily: index not found\n")); return B_ERROR; } - strcpy(*name,flf->name.String()); - - - release_sem(fontlock); + // ToDo: respect size of "name" + strcpy(*name, family->name.String()); + + release_sem(fontlock); return B_OK; } -int32 ClientFontList::CountStyles(font_family f) + +int32 +ClientFontList::CountStyles(font_family f) { acquire_sem(fontlock); - - FontListFamily *flf=NULL; - int32 i, count=familylist->CountItems(); - bool found=false; - for(i=0; iItemAt(i); - if(!flf) + FontListFamily *family = NULL; + int32 i, count = familylist->CountItems(); + bool found = false; + + for (i = 0; i < count; i++) { + family = (FontListFamily *)familylist->ItemAt(i); + if (!family) continue; - if(flf->name.ICompare(f)==0) - { - found=true; + + if (family->name.ICompare(f) == 0) { + found = true; break; } } - - count=(found)?flf->styles->CountItems():0; - + + count = found ? family->styles->CountItems() : 0; + release_sem(fontlock); return count; } -status_t ClientFontList::GetStyle(font_family family, int32 index, font_style *name,uint32 *flags, uint16 *face) -{ - if(!name || !(*name) || !family) - return B_ERROR; - - acquire_sem(fontlock); - - FontListFamily *flf=NULL; - BString *style; - int32 i, count=familylist->CountItems(); - bool found=false; - for(i=0; iItemAt(i); - if(!flf) +status_t +ClientFontList::GetStyle(font_family fontFamily, int32 index, font_style *name, + uint32 *flags, uint16 *face) +{ + if (!name || !*name || !fontFamily) + return B_ERROR; + + acquire_sem(fontlock); + + FontListFamily *family = NULL; + BString *style; + int32 i, count = familylist->CountItems(); + bool found = false; + + for (i = 0; i < count; i++) { + family = (FontListFamily *)familylist->ItemAt(i); + if (!family) continue; - if(flf->name.ICompare(family)==0) - { - found=true; + + if (family->name.ICompare(fontFamily) == 0) { + found = true; break; } } - - if(!found) - { - release_sem(fontlock); - return B_ERROR; - } - - style=(BString*)flf->styles->ItemAt(index); - if(!style) - { + + if (!found) { release_sem(fontlock); return B_ERROR; } - strcpy(*name,style->String()); + style = (BString *)family->styles->ItemAt(index); + if (!style) { + release_sem(fontlock); + return B_ERROR; + } - if(flags) - *flags=flf->flags; + strcpy(*name, style->String()); - if(face) - { - if(style->ICompare("Roman")==0 || - style->ICompare("Regular")==0 || - style->ICompare("Normal")==0 || - style->ICompare("Light")==0 || - style->ICompare("Medium")==0 || - style->ICompare("Plain")==0) - { - *face|=B_REGULAR_FACE; + if (flags) + *flags = family->flags; + + if (face) { + if (!style->ICompare("Roman") + || !style->ICompare("Regular") + || !style->ICompare("Normal") + || !style->ICompare("Light") + || !style->ICompare("Medium") + || !style->ICompare("Plain")) { + *face |= B_REGULAR_FACE; STRACE(("GetStyle: %s Roman face\n", style->String())); - } - else - if(style->ICompare("Bold")==0) - { - *face|=B_BOLD_FACE; + } else if (!style->ICompare("Bold")) { + *face |= B_BOLD_FACE; STRACE(("GetStyle: %s Bold face\n")); - } - else - if(style->ICompare("Italic")==0) - { - *face|=B_ITALIC_FACE; - STRACE(("GetStyle: %s Italic face\n")); - } - else - if(style->ICompare("Bold Italic")==0) - { - *face|=B_ITALIC_FACE | B_BOLD_FACE; - STRACE(("GetStyle: %s Bold Italic face\n")); - } - else - { - STRACE(("GetStyle: %s Unknown face %s\n", style->String())); - } - } - + } else if (!style->ICompare("Italic")) { + *face|=B_ITALIC_FACE; + STRACE(("GetStyle: %s Italic face\n")); + } else if (!style->ICompare("Bold Italic")) { + *face|=B_ITALIC_FACE | B_BOLD_FACE; + STRACE(("GetStyle: %s Bold Italic face\n")); + } else { + STRACE(("GetStyle: %s Unknown face %s\n", style->String())); + } + } + release_sem(fontlock); return B_OK; } diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 2781306061..ef4fdf76e7 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -1,34 +1,13 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2005, Haiku -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: View.cpp -// Author: Adrian Oanca -// Description: A BView object represents a rectangular area within a window. -// The object draws within this rectangle and responds to user -// events that are directed at the window. -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Adrian Oanca + * Axel Dörfler, axeld@pinc-software.de + */ -// Standard Includes ----------------------------------------------------------- -// System Includes ------------------------------------------------------------- #include #include #include @@ -54,7 +33,6 @@ #include #include -// Project Includes ------------------------------------------------------------ #include #include #include @@ -64,10 +42,8 @@ #include #include -// Local Includes -------------------------------------------------------------- #include -// Local Defines --------------------------------------------------------------- //#define DEBUG_BVIEW #ifdef DEBUG_BVIEW @@ -86,9 +62,7 @@ #define MAX_ATTACHMENT_SIZE 49152 -// Globals --------------------------------------------------------------------- -static property_info viewPropInfo[] = -{ +static property_info sViewPropInfo[] = { { "Frame", { B_GET_PROPERTY, 0 }, { B_DIRECT_SPECIFIER, 0 }, "Returns the view's frame rectangle.",0 }, @@ -390,11 +364,10 @@ BView::Bounds() const check_lock(); owner->fLink->StartMessage(AS_LAYER_GET_COORD); - owner->fLink->Flush(); - int32 rCode = SERVER_FALSE; - owner->fLink->GetNextReply(&rCode); - if (rCode == SERVER_TRUE) { + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { owner->fLink->Read(const_cast(&originX)); owner->fLink->Read(const_cast(&originY)); owner->fLink->Read(const_cast(&fBounds)); @@ -789,11 +762,10 @@ BView::Origin() const 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) { + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { owner->fLink->Read(&fState->coordSysOrigin); fState->flags &= ~B_VIEW_ORIGIN_BIT; } @@ -839,14 +811,11 @@ BView::SetViewCursor(const BCursor *cursor, bool sync) check_lock(); - if (sync) { - owner->fLink->StartMessage(AS_LAYER_CURSOR); - owner->fLink->Attach(cursor->m_serverToken); + owner->fLink->StartMessage(AS_LAYER_CURSOR); + owner->fLink->Attach(cursor->m_serverToken); + + if (sync) owner->fLink->Flush(); - } else { - owner->fLink->StartMessage(AS_LAYER_CURSOR); - owner->fLink->Attach(cursor->m_serverToken); - } } @@ -1211,19 +1180,17 @@ BView::GetMouse(BPoint *location, uint32 *buttons, bool checkMessageQueue) // we get the current mouse location and buttons from the app_server owner->fLink->StartMessage(AS_LAYER_GET_MOUSE_COORDS); - owner->fLink->Flush(); - - int32 rCode = SERVER_FALSE; - owner->fLink->GetNextReply(&rCode); - if (rCode == SERVER_TRUE) { + + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { owner->fLink->Read(location); owner->fLink->Read(buttons); - + // TODO: See above comment about coordinates ConvertFromScreen(location); - } else { + } else buttons = 0; - } } @@ -1395,9 +1362,9 @@ BView::LineJoinMode() const return fState->lineJoin; } -//--------------------------------------------------------------------------- -cap_mode BView::LineCapMode() const +cap_mode +BView::LineCapMode() const { if (fState->flags & B_VIEW_LINE_MODES_BIT) LineMiterLimit(); @@ -1405,307 +1372,284 @@ cap_mode BView::LineCapMode() const return fState->lineCap; } -//--------------------------------------------------------------------------- -float BView::LineMiterLimit() const +float +BView::LineMiterLimit() const { - if ( (fState->flags & B_VIEW_LINE_MODES_BIT) && owner) - { + if ((fState->flags & B_VIEW_LINE_MODES_BIT) != 0 && owner) { check_lock(); - - owner->fLink->StartMessage( AS_LAYER_GET_LINE_MODE ); - owner->fLink->Flush(); - - 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) ); + + owner->fLink->StartMessage(AS_LAYER_GET_LINE_MODE); + + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == 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; + + fState->flags &= ~B_VIEW_LINE_MODES_BIT; } - + return fState->miterLimit; } -//--------------------------------------------------------------------------- -void BView::PushState() +void +BView::PushState() { do_owner_check(); - - owner->fLink->StartMessage( AS_LAYER_PUSH_STATE ); - + + owner->fLink->StartMessage(AS_LAYER_PUSH_STATE); + initCachedState(); } -//--------------------------------------------------------------------------- -void BView::PopState() +void +BView::PopState() { do_owner_check(); - owner->fLink->StartMessage( AS_LAYER_POP_STATE ); + owner->fLink->StartMessage(AS_LAYER_POP_STATE); - // this avoids a compiler warning - uint32 dummy = 0xffffffffUL; - // invalidate all flags - fState->flags = dummy; + fState->flags = 0xffff; } -//--------------------------------------------------------------------------- -void BView::SetScale(float scale) const +void +BView::SetScale(float scale) const { if (scale == fState->scale) return; - - if (owner) - { + + if (owner) { check_lock(); - - owner->fLink->StartMessage( AS_LAYER_SET_SCALE ); - owner->fLink->Attach( 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. - fState->flags |= B_VIEW_SCALE_BIT; + fState->flags |= B_VIEW_SCALE_BIT; } - - fState->scale = scale; - fState->archivingFlags |= B_VIEW_SCALE_BIT; + fState->scale = scale; + fState->archivingFlags |= B_VIEW_SCALE_BIT; } -//--------------------------------------------------------------------------- -float BView::Scale() const + +float +BView::Scale() const { - if ( (fState->flags & B_VIEW_SCALE_BIT) && owner) - { + if ((fState->flags & B_VIEW_SCALE_BIT) != 0 && owner) { check_lock(); - - 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) ); - } - - fState->flags &= ~B_VIEW_SCALE_BIT; + + owner->fLink->StartMessage(AS_LAYER_GET_SCALE); + + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) + owner->fLink->Read(&fState->scale); + + fState->flags &= ~B_VIEW_SCALE_BIT; } return fState->scale; } -//--------------------------------------------------------------------------- -void BView::SetDrawingMode(drawing_mode mode) +void +BView::SetDrawingMode(drawing_mode mode) { if (mode == fState->drawingMode) return; - - if (owner) - { - check_lock(); - - owner->fLink->StartMessage( AS_LAYER_SET_DRAW_MODE ); - owner->fLink->Attach( (int8)mode ); - - fState->flags |= B_VIEW_DRAW_MODE_BIT; - } - - fState->drawingMode = mode; - fState->archivingFlags |= B_VIEW_DRAW_MODE_BIT; + if (owner) { + check_lock(); + + owner->fLink->StartMessage(AS_LAYER_SET_DRAW_MODE); + owner->fLink->Attach((int8)mode); + + fState->flags |= B_VIEW_DRAW_MODE_BIT; + } + + fState->drawingMode = mode; + fState->archivingFlags |= B_VIEW_DRAW_MODE_BIT; } -//--------------------------------------------------------------------------- -drawing_mode BView::DrawingMode() const +drawing_mode +BView::DrawingMode() const { - if ( (fState->flags & B_VIEW_DRAW_MODE_BIT) && owner) - { + if ((fState->flags & B_VIEW_DRAW_MODE_BIT) != 0 && owner) { check_lock(); - int8 drawingMode; - owner->fLink->StartMessage( AS_LAYER_GET_DRAW_MODE ); - owner->fLink->Flush(); - - int32 rCode = SERVER_FALSE; - owner->fLink->GetNextReply( &rCode ); - if (rCode == SERVER_TRUE) - owner->fLink->Read( &drawingMode ); - - fState->drawingMode = (drawing_mode)drawingMode; - - fState->flags &= ~B_VIEW_DRAW_MODE_BIT; + owner->fLink->StartMessage(AS_LAYER_GET_DRAW_MODE); + + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { + int8 drawingMode; + owner->fLink->Read(&drawingMode); + + fState->drawingMode = (drawing_mode)drawingMode; + fState->flags &= ~B_VIEW_DRAW_MODE_BIT; + } } - + return fState->drawingMode; } -//--------------------------------------------------------------------------- -void BView::SetBlendingMode(source_alpha srcAlpha, alpha_function alphaFunc) +void +BView::SetBlendingMode(source_alpha srcAlpha, alpha_function alphaFunc) { - if (srcAlpha == fState->alphaSrcMode && alphaFunc == fState->alphaFncMode) + if (srcAlpha == fState->alphaSrcMode && alphaFunc == fState->alphaFncMode) return; - - if (owner) - { - check_lock(); - - owner->fLink->StartMessage( AS_LAYER_SET_BLEND_MODE ); - owner->fLink->Attach( (int8)srcAlpha ); - owner->fLink->Attach( (int8)alphaFunc ); - - fState->flags |= B_VIEW_BLENDING_BIT; - } - - fState->alphaSrcMode = srcAlpha; - fState->alphaFncMode = alphaFunc; - fState->archivingFlags |= B_VIEW_BLENDING_BIT; + if (owner) { + check_lock(); + + owner->fLink->StartMessage(AS_LAYER_SET_BLEND_MODE); + owner->fLink->Attach((int8)srcAlpha); + owner->fLink->Attach((int8)alphaFunc); + + fState->flags |= B_VIEW_BLENDING_BIT; + } + + fState->alphaSrcMode = srcAlpha; + fState->alphaFncMode = alphaFunc; + + fState->archivingFlags |= B_VIEW_BLENDING_BIT; } -//--------------------------------------------------------------------------- -void BView::GetBlendingMode(source_alpha* srcAlpha, alpha_function* alphaFunc) const +void +BView::GetBlendingMode(source_alpha *_srcAlpha, alpha_function *_alphaFunc) const { - if ( (fState->flags & B_VIEW_BLENDING_BIT) && owner) - { + if ((fState->flags & B_VIEW_BLENDING_BIT) != 0 && owner) { check_lock(); - int8 alphaSrcMode, alphaFncMode; - owner->fLink->StartMessage( AS_LAYER_GET_BLEND_MODE ); - owner->fLink->Flush(); - - int32 rCode = SERVER_FALSE; - owner->fLink->GetNextReply( &rCode ); - if (rCode == SERVER_TRUE) - { - owner->fLink->Read( &alphaSrcMode ); - owner->fLink->Read( &alphaFncMode ); + owner->fLink->StartMessage(AS_LAYER_GET_BLEND_MODE); + + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { + int8 alphaSrcMode, alphaFuncMode; + owner->fLink->Read(&alphaSrcMode); + owner->fLink->Read(&alphaFuncMode); + + fState->alphaSrcMode = (source_alpha)alphaSrcMode; + fState->alphaFncMode = (alpha_function)alphaFuncMode; + + fState->flags &= ~B_VIEW_BLENDING_BIT; } - - fState->alphaSrcMode = (source_alpha)alphaSrcMode; - fState->alphaFncMode = (alpha_function)alphaFncMode; - - fState->flags &= ~B_VIEW_BLENDING_BIT; } - - if (srcAlpha) - *srcAlpha = fState->alphaSrcMode; - - if (alphaFunc) - *alphaFunc = fState->alphaFncMode; + + if (_srcAlpha) + *_srcAlpha = fState->alphaSrcMode; + + if (_alphaFunc) + *_alphaFunc = fState->alphaFncMode; } -//--------------------------------------------------------------------------- -void BView::MovePenTo(BPoint pt) +void +BView::MovePenTo(BPoint pt) { - MovePenTo( pt.x, pt.y ); + MovePenTo(pt.x, pt.y); } -//--------------------------------------------------------------------------- -void BView::MovePenTo(float x, float y) +void +BView::MovePenTo(float x, float y) { - if (x == fState->penPosition.x && y == fState->penPosition.y) + if (x == fState->penPosition.x && y == fState->penPosition.y) return; - - if (owner) - { - check_lock(); - - owner->fLink->StartMessage( AS_LAYER_SET_PEN_LOC ); - owner->fLink->Attach( x ); - owner->fLink->Attach( y ); - - fState->flags |= B_VIEW_PEN_LOC_BIT; - } - - fState->penPosition.x = x; - fState->penPosition.y = y; - fState->archivingFlags |= B_VIEW_PEN_LOC_BIT; + if (owner) { + check_lock(); + + owner->fLink->StartMessage(AS_LAYER_SET_PEN_LOC); + owner->fLink->Attach(x); + owner->fLink->Attach(y); + + fState->flags |= B_VIEW_PEN_LOC_BIT; + } + + fState->penPosition.x = x; + fState->penPosition.y = y; + + fState->archivingFlags |= B_VIEW_PEN_LOC_BIT; } -//--------------------------------------------------------------------------- -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 +BPoint +BView::PenLocation() const { - if ( (fState->flags & B_VIEW_PEN_LOC_BIT) && owner) - { + if ((fState->flags & B_VIEW_PEN_LOC_BIT) != 0 && owner) { check_lock(); - owner->fLink->StartMessage( AS_LAYER_GET_PEN_LOC ); - owner->fLink->Flush(); - - int32 rCode = SERVER_FALSE; - owner->fLink->GetNextReply( &rCode ); - if (rCode == SERVER_TRUE) - owner->fLink->Read( &(fState->penPosition) ); - - fState->flags &= ~B_VIEW_PEN_LOC_BIT; + owner->fLink->StartMessage(AS_LAYER_GET_PEN_LOC); + + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { + owner->fLink->Read(&fState->penPosition); + + fState->flags &= ~B_VIEW_PEN_LOC_BIT; + } } return fState->penPosition; } -//--------------------------------------------------------------------------- -void BView::SetPenSize(float size){ +void +BView::SetPenSize(float size) +{ if (size == fState->penSize) return; - - if (owner){ - check_lock(); - - owner->fLink->StartMessage( AS_LAYER_SET_PEN_SIZE ); - owner->fLink->Attach( size ); - - fState->flags |= B_VIEW_PEN_SIZE_BIT; - } - - fState->penSize = size; + if (owner) { + check_lock(); + + owner->fLink->StartMessage(AS_LAYER_SET_PEN_SIZE); + owner->fLink->Attach(size); + + fState->flags |= B_VIEW_PEN_SIZE_BIT; + } + + fState->penSize = size; fState->archivingFlags |= B_VIEW_PEN_SIZE_BIT; } -//--------------------------------------------------------------------------- -float BView::PenSize() const +float +BView::PenSize() const { - if (fState->flags & B_VIEW_PEN_SIZE_BIT) - { - if (owner) - { + if (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; + + owner->fLink->StartMessage(AS_LAYER_GET_PEN_SIZE); + + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { + owner->fLink->Read(&fState->penSize); + + fState->flags &= ~B_VIEW_PEN_SIZE_BIT; + } } } return fState->penSize; @@ -1730,7 +1674,7 @@ BView::SetHighColor(rgb_color a_color) set_rgb_color(fState->highColor, a_color.red, a_color.green, a_color.blue, a_color.alpha); - fState->archivingFlags |= B_VIEW_COLORS_BIT; + fState->archivingFlags |= B_VIEW_COLORS_BIT; } @@ -1742,17 +1686,16 @@ BView::HighColor() const check_lock(); owner->fLink->StartMessage(AS_LAYER_GET_COLORS); - owner->fLink->Flush(); + + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { + owner->fLink->Read(&fState->highColor); + owner->fLink->Read(&fState->lowColor); + owner->fLink->Read(&fState->viewColor); - 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; } - - fState->flags &= ~B_VIEW_COLORS_BIT; } } @@ -1966,276 +1909,247 @@ BView::ClipToInversePicture(BPicture *picture, DoPictureClip(picture, where, true, sync); } -//--------------------------------------------------------------------------- -void BView::GetClippingRegion(BRegion* region) const +void +BView::GetClippingRegion(BRegion* region) const { if (!region) return; - if (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 ); - + if (fState->flags & B_VIEW_CLIP_REGION_BIT) { + if (do_owner_check()) { + owner->fLink->StartMessage(AS_LAYER_GET_CLIP_REGION); + + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { + int32 count; + owner->fLink->Read(&count); + fState->clippingRegion.MakeEmpty(); - for (int32 i = 0; i < noOfRects; i++) - { - BRect rect; - - owner->fLink->Read( &rect ); - - fState->clippingRegion.Include( rect ); + for (int32 i = 0; i < count; i++) { + BRect rect; + owner->fLink->Read(&rect); + + fState->clippingRegion.Include(rect); } - fState->flags &= ~B_VIEW_CLIP_REGION_BIT; + fState->flags &= ~B_VIEW_CLIP_REGION_BIT; } } } - *region = fState->clippingRegion; + + *region = fState->clippingRegion; } -//--------------------------------------------------------------------------- -void BView::ConstrainClippingRegion(BRegion* region) +void +BView::ConstrainClippingRegion(BRegion* region) { - if (do_owner_check()) - { - int32 noOfRects = 0; - + if (do_owner_check()) { + int32 count = 0; if (region) - noOfRects = region->CountRects(); - - owner->fLink->StartMessage( AS_LAYER_SET_CLIP_REGION ); + count = region->CountRects(); + + 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) - + // TODO: note this in the specs - owner->fLink->Attach( noOfRects ); - - for (int32 i = 0; ifLink->Attach( region->RectAt(i) ); - + owner->fLink->Attach(count); + + for (int32 i = 0; i < count; i++) + owner->fLink->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; + fState->flags |= B_VIEW_CLIP_REGION_BIT; + fState->archivingFlags |= B_VIEW_CLIP_REGION_BIT; } } + +// #pragma mark - Drawing Functions //--------------------------------------------------------------------------- -// Drawing Functions -//--------------------------------------------------------------------------- - -void BView::DrawBitmapAsync(const BBitmap* aBitmap, BRect srcRect, BRect dstRect) +void +BView::DrawBitmapAsync(const BBitmap *bitmap, BRect srcRect, BRect dstRect) { - if ( !aBitmap || !srcRect.IsValid() || !dstRect.IsValid()) + if (!bitmap || !srcRect.IsValid() || !dstRect.IsValid()) return; - - if (owner) - { + + if (owner) { check_lock(); - - 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 ); + + owner->fLink->StartMessage(AS_LAYER_DRAW_BITMAP_ASYNC_IN_RECT); + owner->fLink->Attach(bitmap->get_server_token()); + owner->fLink->Attach(srcRect); + owner->fLink->Attach(dstRect); } } -//--------------------------------------------------------------------------- -void BView::DrawBitmapAsync(const BBitmap* aBitmap, BRect dstRect) +void +BView::DrawBitmapAsync(const BBitmap *bitmap, BRect dstRect) { - if ( !aBitmap || !dstRect.IsValid()) + if (!bitmap || !dstRect.IsValid()) return; - - DrawBitmapAsync( aBitmap, aBitmap->Bounds(), dstRect); + + DrawBitmapAsync(bitmap, bitmap->Bounds(), dstRect); } -//--------------------------------------------------------------------------- -void BView::DrawBitmapAsync(const BBitmap* aBitmap) +void +BView::DrawBitmapAsync(const BBitmap *bitmap) { - DrawBitmapAsync( aBitmap, PenLocation() ); + DrawBitmapAsync(bitmap, PenLocation()); } -//--------------------------------------------------------------------------- -void BView::DrawBitmapAsync(const BBitmap* aBitmap, BPoint where) +void +BView::DrawBitmapAsync(const BBitmap *bitmap, BPoint where) { - if ( !aBitmap ) + if (bitmap == NULL) return; - - if (owner) - { + + if (owner) { check_lock(); - - owner->fLink->StartMessage( AS_LAYER_DRAW_BITMAP_ASYNC_AT_POINT ); - owner->fLink->Attach( aBitmap->get_server_token() ); - owner->fLink->Attach( where ); + + owner->fLink->StartMessage(AS_LAYER_DRAW_BITMAP_ASYNC_AT_POINT); + owner->fLink->Attach(bitmap->get_server_token()); + owner->fLink->Attach(where); } } -//--------------------------------------------------------------------------- -void BView::DrawBitmap(const BBitmap* aBitmap) +void +BView::DrawBitmap(const BBitmap *bitmap) { - DrawBitmap( aBitmap, PenLocation() ); + DrawBitmap(bitmap, PenLocation()); } -//--------------------------------------------------------------------------- -void BView::DrawBitmap(const BBitmap* aBitmap, BPoint where) +void +BView::DrawBitmap(const BBitmap *bitmap, BPoint where) { - if ( !aBitmap ) + if (bitmap == NULL) return; - - if (owner) - { + + if (owner) { check_lock(); - - owner->fLink->StartMessage( AS_LAYER_DRAW_BITMAP_SYNC_AT_POINT ); - owner->fLink->Attach( aBitmap->get_server_token() ); - owner->fLink->Attach( where ); + + owner->fLink->StartMessage(AS_LAYER_DRAW_BITMAP_SYNC_AT_POINT); + owner->fLink->Attach(bitmap->get_server_token()); + owner->fLink->Attach(where); owner->fLink->Flush(); } } -//--------------------------------------------------------------------------- -void BView::DrawBitmap(const BBitmap* aBitmap, BRect dstRect) +void +BView::DrawBitmap(const BBitmap *bitmap, BRect dstRect) { - if ( !aBitmap || !dstRect.IsValid()) + if (!bitmap || !dstRect.IsValid()) return; - - DrawBitmap( aBitmap, aBitmap->Bounds(), dstRect); + + DrawBitmap(bitmap, bitmap->Bounds(), dstRect); } -//--------------------------------------------------------------------------- -void BView::DrawBitmap(const BBitmap* aBitmap, BRect srcRect, BRect dstRect) +void +BView::DrawBitmap(const BBitmap *bitmap, BRect srcRect, BRect dstRect) { - if ( !aBitmap || !srcRect.IsValid() || !dstRect.IsValid()) + if ( !bitmap || !srcRect.IsValid() || !dstRect.IsValid()) return; - - if (owner) - { + + if (owner) { check_lock(); - - 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->StartMessage(AS_LAYER_DRAW_BITMAP_SYNC_IN_RECT); + owner->fLink->Attach(bitmap->get_server_token()); + owner->fLink->Attach(dstRect); + owner->fLink->Attach(srcRect); owner->fLink->Flush(); } } -//--------------------------------------------------------------------------- -void BView::DrawChar(char aChar) +void +BView::DrawChar(char c) { - DrawChar( aChar, PenLocation() ); + DrawString(&c, 1, PenLocation()); } -//--------------------------------------------------------------------------- -void BView::DrawChar(char aChar, BPoint location) +void +BView::DrawChar(char c, BPoint location) { - char ch[2]; - ch[0] = aChar; - ch[1] = '\0'; - - DrawString( ch, strlen(ch), location ); + DrawString(&c, 1, location); } -//--------------------------------------------------------------------------- -void BView::DrawString(const char* aString, escapement_delta* delta) +void +BView::DrawString(const char *string, escapement_delta *delta) { - if ( !aString ) + DrawString(string, strlen(string), PenLocation()); +} + + +void +BView::DrawString(const char *string, BPoint location, escapement_delta *delta) +{ + DrawString(string, strlen(string), location); +} + + +void +BView::DrawString(const char *string, int32 length, escapement_delta *delta) +{ + DrawString(string, length, PenLocation()); +} + + +void +BView::DrawString(const char *string, int32 length, BPoint location, + escapement_delta *delta) +{ + if (string == NULL || length < 1) return; - DrawString( aString, strlen(aString), PenLocation() ); -} - -//--------------------------------------------------------------------------- - -void BView::DrawString(const char* aString, BPoint location, escapement_delta* delta) -{ - if ( !aString ) - return; - - DrawString( aString, strlen(aString), location ); -} - -//--------------------------------------------------------------------------- - -void BView::DrawString(const char* aString, int32 length, escapement_delta* delta) -{ - if ( !aString ) - return; - - DrawString( aString, length, PenLocation() ); -} - -//--------------------------------------------------------------------------- - -void BView::DrawString(const char* aString, int32 length, BPoint location, - escapement_delta* delta) -{ - if ( !aString || length<1) - return; - - if (owner) - { + if (owner) { check_lock(); - - owner->fLink->StartMessage( AS_DRAW_STRING ); - owner->fLink->Attach( length ); - owner->fLink->Attach( location ); - + + owner->fLink->StartMessage(AS_DRAW_STRING); + owner->fLink->Attach(length); + owner->fLink->Attach(location); + // Quite often delta will be NULL, so we have to accomodate this. - if(delta) - owner->fLink->Attach( *delta ); - else - { + if (delta) + owner->fLink->Attach(*delta); + else { escapement_delta tdelta; - tdelta.space=0; - tdelta.nonspace=0; - - owner->fLink->Attach( tdelta ); + tdelta.space = 0; + tdelta.nonspace = 0; + + owner->fLink->Attach(tdelta); } - owner->fLink->AttachString( aString ); + + owner->fLink->AttachString(string, length); // this modifies our pen location, so we invalidate the flag. - fState->flags |= B_VIEW_PEN_LOC_BIT; + 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) - { - StrokeEllipse( BRect(center.x-xRadius, center.y-yRadius, center.x+xRadius, - center.y+yRadius), p ); - } + StrokeEllipse(BRect(center.x - xRadius, center.y - yRadius, center.x + xRadius, + center.y + yRadius), p); } @@ -2259,10 +2173,8 @@ void BView::FillEllipse(BPoint center, float xRadius, float yRadius, pattern p) { - if (owner) { - FillEllipse(BRect(center.x - xRadius, center.y - yRadius, - center.x + xRadius, center.y + yRadius), p); - } + FillEllipse(BRect(center.x - xRadius, center.y - yRadius, + center.x + xRadius, center.y + yRadius), p); } @@ -2377,30 +2289,30 @@ BView::FillBezier(BPoint *controlPoints, pattern p) void -BView::StrokePolygon(const BPolygon* aPolygon,bool closed, pattern p) +BView::StrokePolygon(const BPolygon *polygon, bool closed, pattern p) { - if(!aPolygon) + if (!polygon) return; - - StrokePolygon(aPolygon->fPts, aPolygon->fCount, aPolygon->Frame(), closed, p); + + StrokePolygon(polygon->fPts, polygon->fCount, polygon->Frame(), closed, p); } void -BView::StrokePolygon(const BPoint *ptArray, int32 numPts, bool closed, pattern p) +BView::StrokePolygon(const BPoint *ptArray, int32 numPoints, bool closed, pattern p) { - BPolygon aPolygon(ptArray, numPts); + BPolygon polygon(ptArray, numPoints); - StrokePolygon(aPolygon.fPts, aPolygon.fCount, aPolygon.Frame(), closed, p); + StrokePolygon(polygon.fPts, polygon.fCount, polygon.Frame(), closed, p); } void -BView::StrokePolygon(const BPoint *ptArray, int32 numPts, BRect bounds, +BView::StrokePolygon(const BPoint *ptArray, int32 numPoints, BRect bounds, bool closed, pattern p) { if (!ptArray - || numPts <= 2 + || numPoints <= 2 || owner == NULL) return; @@ -2409,17 +2321,19 @@ BView::StrokePolygon(const BPoint *ptArray, int32 numPts, BRect bounds, if (!(fState->patt == p)) SetPattern(p); - BPolygon polygon(ptArray, numPts); + BPolygon polygon(ptArray, numPoints); polygon.MapTo(polygon.Frame(), bounds); - if (polygon.fCount * sizeof(BPoint) < MAX_ATTACHMENT_SIZE) { - owner->fLink->StartMessage(AS_STROKE_POLYGON); + if (owner->fLink->StartMessage(AS_STROKE_POLYGON, + polygon.fCount * sizeof(BPoint) + sizeof(BRect) + sizeof(bool) + sizeof(int32)) + == B_OK) { owner->fLink->Attach(polygon.Frame()); owner->fLink->Attach(closed); owner->fLink->Attach(polygon.fCount); owner->fLink->Attach(polygon.fPts, polygon.fCount * sizeof(BPoint)); } else { // TODO: send via an area + fprintf(stderr, "ERROR: polygon to big for BPortLink!\n"); } } @@ -2437,12 +2351,13 @@ BView::FillPolygon(const BPolygon *polygon, pattern p) if (!(fState->patt == p)) SetPattern(p); - if (polygon->fCount * sizeof(BPoint) < MAX_ATTACHMENT_SIZE) { - owner->fLink->StartMessage(AS_FILL_POLYGON); + if (owner->fLink->StartMessage(AS_FILL_POLYGON, + polygon->fCount * sizeof(BPoint) + sizeof(int32)) == B_OK) { owner->fLink->Attach(polygon->fCount); owner->fLink->Attach(polygon->fPts, polygon->fCount * sizeof(BPoint)); } else { // TODO: send via an area + fprintf(stderr, "ERROR: polygon to big for BPortLink!\n"); } } @@ -2468,7 +2383,7 @@ BView::FillPolygon(const BPoint *ptArray, int32 numPts, BRect bounds, BPolygon polygon(ptArray, numPts); polygon.MapTo(polygon.Frame(), bounds); - FillPolygon(&polygon, p ); + FillPolygon(&polygon, p); } @@ -2876,27 +2791,20 @@ BView::AppendToPicture(BPicture *picture) BPicture * BView::EndPicture() { - if (do_owner_check()) - { - if (cpicture) - { - int32 token; + if (do_owner_check() && cpicture) { + int32 token; - owner->fLink->StartMessage(AS_LAYER_END_PICTURE); - owner->fLink->Flush(); - - 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; - } - } + owner->fLink->StartMessage(AS_LAYER_END_PICTURE); + + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE + && owner->fLink->Read(&token) == B_OK) { + BPicture *picture = cpicture; + cpicture = picture->step_down(); + picture->set_token(token); + + return picture; } } @@ -2999,11 +2907,11 @@ BView::DrawPicture(const BPicture *picture) DrawPictureAsync(picture, PenLocation()); owner->fLink->Attach(SERVER_TRUE); - owner->fLink->Flush(); - int32 rCode = SERVER_FALSE; - owner->fLink->GetNextReply(&rCode); - if (rCode == SERVER_TRUE) { + // ToDo: why a reply? + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { status_t err; owner->fLink->Read(&err); } @@ -3018,11 +2926,11 @@ BView::DrawPicture(const BPicture *picture, BPoint where) DrawPictureAsync(picture, where); owner->fLink->Attach(SERVER_TRUE); - owner->fLink->Flush(); - int32 rCode = SERVER_FALSE; - owner->fLink->GetNextReply(&rCode); - if (rCode == SERVER_TRUE) { + // ToDo: why a reply? + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { status_t err; owner->fLink->Read(&err); } @@ -3037,11 +2945,11 @@ BView::DrawPicture(const char *filename, long offset, BPoint where) DrawPictureAsync(filename, offset, where); owner->fLink->Attach(SERVER_TRUE); - owner->fLink->Flush(); - int32 rCode = SERVER_FALSE; - owner->fLink->GetNextReply(&rCode); - if (rCode == SERVER_TRUE) { + // ToDo: why a reply? + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { status_t err; owner->fLink->Read(&err); } @@ -3340,13 +3248,13 @@ BView::ResizeTo(float width, float height) fState->flags |= B_VIEW_COORD_BIT; } - fBounds.right = fBounds.left + width; - fBounds.bottom = fBounds.top + height; + fBounds.right = fBounds.left + width; + fBounds.bottom = fBounds.top + height; -// TODO: investigate R5 behaviour for unattached views -// maybe the message is generated, but postponed until the view is added -if (!owner && fFlags & B_FRAME_EVENTS) - FrameResized(width, height); + // TODO: investigate R5 behaviour for unattached views + // maybe the message is generated, but postponed until the view is added + if (!owner && fFlags & B_FRAME_EVENTS) + FrameResized(width, height); } @@ -3362,7 +3270,7 @@ BView::GetSupportedSuites(BMessage *data) status_t status = data->AddString("Suites", "suite/vnd.Be-view"); if (status == B_OK) { - BPropertyInfo propertyInfo(viewPropInfo); + BPropertyInfo propertyInfo(sViewPropInfo); status = data->AddFlat("message", &propertyInfo); if (status == B_OK) @@ -3380,7 +3288,7 @@ BView::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier, || msg->what == B_WINDOW_MOVE_TO) return this; - BPropertyInfo propertyInfo(viewPropInfo); + BPropertyInfo propertyInfo(sViewPropInfo); switch (propertyInfo.FindMatch(msg, index, specifier, what, property)) { case B_ERROR: @@ -4021,40 +3929,40 @@ BView::initCachedState() fState->penPosition.Set(0.0, 0.0); fState->penSize = 1.0; - fState->highColor.red = 0; - fState->highColor.blue = 0; - fState->highColor.green = 0; - fState->highColor.alpha = 255; + fState->highColor.red = 0; + fState->highColor.blue = 0; + fState->highColor.green = 0; + fState->highColor.alpha = 255; - fState->lowColor.red = 255; - fState->lowColor.blue = 255; - fState->lowColor.green = 255; - fState->lowColor.alpha = 255; + fState->lowColor.red = 255; + fState->lowColor.blue = 255; + fState->lowColor.green = 255; + fState->lowColor.alpha = 255; - fState->viewColor.red = 255; - fState->viewColor.blue = 255; - fState->viewColor.green = 255; - fState->viewColor.alpha = 255; + fState->viewColor.red = 255; + fState->viewColor.blue = 255; + fState->viewColor.green = 255; + fState->viewColor.alpha = 255; - fState->patt = B_SOLID_HIGH; + fState->patt = B_SOLID_HIGH; - fState->drawingMode = B_OP_COPY; + fState->drawingMode = B_OP_COPY; // clippingRegion is empty by default fState->coordSysOrigin.Set(0.0, 0.0); - fState->lineCap = B_BUTT_CAP; - fState->lineJoin = B_BEVEL_JOIN; - fState->miterLimit = B_DEFAULT_MITER_LIMIT; + fState->lineCap = B_BUTT_CAP; + fState->lineJoin = B_BEVEL_JOIN; + fState->miterLimit = B_DEFAULT_MITER_LIMIT; - fState->alphaSrcMode = B_PIXEL_ALPHA; - fState->alphaFncMode = B_ALPHA_OVERLAY; + fState->alphaSrcMode = B_PIXEL_ALPHA; + fState->alphaFncMode = B_ALPHA_OVERLAY; - fState->scale = 1.0; + fState->scale = 1.0; + + fState->fontAliasing = false; - fState->fontAliasing = false; - /* INFO: We include(invalidate) only B_VIEW_CLIP_REGION_BIT flag because we should get the clipping region from app_server. @@ -4062,10 +3970,10 @@ BView::initCachedState() represent is already in sync with app_server - app_server uses the same init(default) values. */ - fState->flags = B_VIEW_CLIP_REGION_BIT; - + fState->flags = B_VIEW_CLIP_REGION_BIT; + // (default) flags used to determine witch fields to archive - fState->archivingFlags = B_VIEW_COORD_BIT; + fState->archivingFlags = B_VIEW_COORD_BIT; } @@ -4075,80 +3983,78 @@ BView::updateCachedState() STRACE(("BView(%s)::updateCachedState()\n", Name() )); // fail if we do not have an owner - do_owner_check(); - - owner->fLink->StartMessage(AS_LAYER_GET_STATE); - owner->fLink->Flush(); + do_owner_check(); - int32 rCode = SERVER_FALSE; - owner->fLink->GetNextReply(&rCode); + owner->fLink->StartMessage(AS_LAYER_GET_STATE); - if (rCode != SERVER_TRUE) + int32 code; + if (owner->fLink->FlushWithReply(code) != B_OK + || code != SERVER_TRUE) return; - uint32 fontID; - float size; - float shear; - float rotation; - uint8 spacing; - uint8 encoding; - uint16 face; - uint32 flags; - int32 noOfRects; - BRect rect; + uint32 fontID; + float size; + float shear; + float rotation; + uint8 spacing; + uint8 encoding; + uint16 face; + uint32 flags; + int32 noOfRects; + BRect rect; // 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 ); + 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 ); - fState->font.SetSize( size ); - fState->font.SetShear( shear ); - fState->font.SetRotation( rotation ); - fState->font.SetSpacing( spacing ); - fState->font.SetEncoding( encoding ); - fState->font.SetFace( face ); - fState->font.SetFlags( flags ); + fState->font.SetFamilyAndStyle(fontID); + fState->font.SetSize(size); + fState->font.SetShear(shear); + fState->font.SetRotation(rotation); + fState->font.SetSpacing(spacing); + fState->font.SetEncoding(encoding); + fState->font.SetFace(face); + fState->font.SetFlags(flags); // 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->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->fLink->Read( &noOfRects ); + owner->fLink->Read(&noOfRects); fState->clippingRegion.MakeEmpty(); for (int32 i = 0; i < noOfRects; i++) { - owner->fLink->Read( &rect ); - fState->clippingRegion.Include( rect ); + owner->fLink->Read(&rect); + fState->clippingRegion.Include(rect); } - - owner->fLink->Read( &originX ); - owner->fLink->Read( &originY ); - owner->fLink->Read( &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())); } @@ -4160,27 +4066,25 @@ BView::setViewImage(const BBitmap *bitmap, BRect srcRect, return B_ERROR; int32 serverToken = bitmap ? bitmap->get_server_token() : -1; - status_t err; - 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(); + 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); // 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; + status_t status = B_ERROR; + int32 code; + if (owner->fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) + owner->fLink->Read(&status); - owner->fLink->Read(&err); - return err; + return status; } diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index fabeab87eb..c0dd28671a 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -1,31 +1,13 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2005, Haiku -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: Window.cpp -// Author: Adrian Oanca (adioanca@mymail.ro) -// Description: A BWindow object represents a window that can be displayed -// on the screen, and that can be the target of user events -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Adrian Oanca + * Axel Dörfler, axeld@pinc-software.de + */ + -// System Includes ------------------------------------------------------------- #include #include #include @@ -43,7 +25,6 @@ #include #include -// Project Includes ------------------------------------------------------------ #include #include #include @@ -51,10 +32,10 @@ #include #include -// Standard Includes ----------------------------------------------------------- #include #include + //#define DEBUG_WIN #ifdef DEBUG_WIN # include @@ -65,8 +46,7 @@ using BPrivate::gDefaultTokens; -static property_info -sWindowPropInfo[] = { +static property_info sWindowPropInfo[] = { { "Feel", { B_GET_PROPERTY, B_SET_PROPERTY }, { B_DIRECT_SPECIFIER }, NULL, 0, { B_INT32_TYPE } @@ -391,16 +371,16 @@ BWindow::SendBehind(const BWindow *window) if (!window) return B_ERROR; - int32 rCode; - Lock(); fLink->StartMessage(AS_SEND_BEHIND); fLink->Attach(_get_object_token_(window)); - fLink->Flush(); - fLink->GetNextReply(&rCode); + + int32 code = SERVER_FALSE; + fLink->FlushWithReply(code); + Unlock(); - return rCode == SERVER_TRUE ? B_OK : B_ERROR; + return code == SERVER_TRUE ? B_OK : B_ERROR; } @@ -416,12 +396,13 @@ BWindow::Flush() const void BWindow::Sync() const { - int32 rCode; - const_cast(this)->Lock(); fLink->StartMessage(AS_SYNC); - fLink->Flush(); - fLink->GetNextReply(&rCode); + + // ToDo: why with reply? + int32 code; + if (fLink->FlushWithReply(code) == B_OK) + const_cast(this)->Unlock(); } @@ -1030,12 +1011,10 @@ BWindow::SetSizeLimits(float minWidth, float maxWidth, fLink->Attach(maxWidth); fLink->Attach(minHeight); fLink->Attach(maxHeight); - fLink->Flush(); - int32 rCode; - fLink->GetNextReply(&rCode); - - if (rCode == SERVER_TRUE) { + int32 code; + if (fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { // read the values that were really enforced on // the server side fLink->Read(&fMinWindWidth); @@ -1269,15 +1248,16 @@ bool BWindow::NeedsUpdate() const { // TODO: What about locking?!? - int32 rCode; const_cast(this)->Lock(); fLink->StartMessage(AS_NEEDS_UPDATE); - fLink->Flush(); - fLink->GetNextReply(&rCode); + + int32 code = SERVER_FALSE; + fLink->FlushWithReply(code); + const_cast(this)->Unlock(); - return rCode == SERVER_TRUE; + return code == SERVER_TRUE; } @@ -1538,17 +1518,18 @@ BWindow::AddToSubset(BWindow *window) return B_BAD_VALUE; team_id team = Team(); - int32 rCode; Lock(); fLink->StartMessage(AS_ADD_TO_SUBSET); fLink->Attach(_get_object_token_(window)); fLink->Attach(team); - fLink->Flush(); - fLink->GetNextReply(&rCode); + + int32 code = SERVER_FALSE; + fLink->FlushWithReply(code); + Unlock(); - return rCode == SERVER_TRUE ? B_OK : B_ERROR; + return code == SERVER_TRUE ? B_OK : B_ERROR; } @@ -1561,17 +1542,17 @@ BWindow::RemoveFromSubset(BWindow *window) return B_BAD_VALUE; team_id team = Team(); - int32 rCode; Lock(); fLink->StartMessage(AS_REM_FROM_SUBSET); fLink->Attach(_get_object_token_(window)); fLink->Attach(team); - fLink->Flush(); - fLink->GetNextReply(&rCode); + + int32 code; + fLink->FlushWithReply(code); Unlock(); - return rCode == SERVER_TRUE ? B_OK : B_ERROR; + return code == SERVER_TRUE ? B_OK : B_ERROR; } @@ -1607,17 +1588,18 @@ BWindow::Type() const status_t BWindow::SetLook(window_look look) { - int32 rCode; Lock(); fLink->StartMessage(AS_SET_LOOK); fLink->Attach((int32)look); - fLink->Flush(); - fLink->GetNextReply(&rCode); + + int32 code = SERVER_FALSE; + fLink->FlushWithReply(code); + Unlock(); // ToDo: the server should probably return something more meaningful, anyway - if (rCode == SERVER_TRUE) { + if (code == SERVER_TRUE) { fLook = look; return B_OK; } @@ -1669,16 +1651,17 @@ BWindow::Feel() const status_t BWindow::SetFlags(uint32 flags) { - int32 rCode; Lock(); fLink->StartMessage(AS_SET_FLAGS); fLink->Attach(flags); - fLink->Flush(); - fLink->GetNextReply(&rCode); + + int32 code = SERVER_FALSE; + fLink->FlushWithReply(code); + Unlock(); - if (rCode == SERVER_TRUE) { + if (code == SERVER_TRUE) { fFlags = flags; return B_OK; } @@ -1707,7 +1690,6 @@ BWindow::SetWindowAlignment(window_alignment mode, return B_BAD_VALUE; // TODO: test if hOffset = 0 and set it to 1 if true. - int32 rCode; Lock(); fLink->StartMessage(AS_SET_ALIGNMENT); @@ -1720,11 +1702,13 @@ BWindow::SetWindowAlignment(window_alignment mode, fLink->Attach(vOffset); fLink->Attach(height); fLink->Attach(heightOffset); - fLink->Flush(); - fLink->GetNextReply(&rCode); + + int32 code = SERVER_FALSE; + fLink->FlushWithReply(code); + Unlock(); - if (rCode == SERVER_TRUE) + if (code == SERVER_TRUE) return B_OK; return B_ERROR; @@ -1736,14 +1720,12 @@ BWindow::GetWindowAlignment(window_alignment *mode, int32 *h, int32 *hOffset, int32 *width, int32 *widthOffset, int32 *v, int32 *vOffset, int32 *height, int32 *heightOffset) const { - int32 rCode; - - const_cast(this)->Lock(); + const_cast(this)->Lock(); fLink->StartMessage(AS_GET_ALIGNMENT); - fLink->Flush(); - fLink->GetNextReply(&rCode); - if (rCode == SERVER_TRUE) { + int32 code = SERVER_FALSE; + if (fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) { fLink->Read((int32 *)mode); fLink->Read(h); fLink->Read(hOffset); @@ -1752,15 +1734,14 @@ BWindow::GetWindowAlignment(window_alignment *mode, fLink->Read(v); fLink->Read(hOffset); fLink->Read(height); - rCode = fLink->Read(heightOffset); - - return B_NO_ERROR; + fLink->Read(heightOffset); } + const_cast(this)->Unlock(); - - if(rCode!=B_OK) + + if (code != SERVER_TRUE) return B_ERROR; - + return B_OK; } @@ -1768,14 +1749,16 @@ BWindow::GetWindowAlignment(window_alignment *mode, uint32 BWindow::Workspaces() const { - uint32 workspaces; - int32 rCode; + uint32 workspaces = 0; const_cast(this)->Lock(); fLink->StartMessage(AS_GET_WORKSPACES); - fLink->Flush(); - fLink->GetNextReply(&rCode); - fLink->Read(&workspaces); + + int32 code; + if (fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE) + fLink->Read(&workspaces); + const_cast(this)->Unlock(); // TODO: shouldn't we cache? @@ -2087,14 +2070,13 @@ BWindow::InitData(BRect frame, const char* title, window_look look, // 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; - if (!(be_app->IsLocked())) { + if (!be_app->IsLocked()) { be_app->Lock(); locked = true; } STRACE(("be_app->fServerTo is %ld\n", be_app->fServerFrom)); - status_t err; fLink->StartMessage(AS_CREATE_WINDOW); fLink->Attach(fFrame); fLink->Attach((int32)fLook); @@ -2105,21 +2087,21 @@ BWindow::InitData(BRect frame, const char* title, window_look look, fLink->Attach(receive_port); fLink->Attach(fMsgPort); fLink->AttachString(title); - 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); + int32 code; + if (fLink->FlushWithReply(code) == B_OK + && code == SERVER_TRUE + && fLink->Read(&send_port) == B_OK) + fLink->SetSendPort(send_port); + else + send_port = -1; if (locked) be_app->Unlock(); STRACE(("Server says that our send port is %ld\n", send_port)); - STRACE(("Window locked?: %s\n", IsLocked()?"True":"False")); + STRACE(("Window locked?: %s\n", IsLocked() ? "True" : "False")); // build and register top_view with app_server BuildTopView(); diff --git a/src/servers/app/AppServer.cpp b/src/servers/app/AppServer.cpp index 7b75b43d09..027c8b6108 100644 --- a/src/servers/app/AppServer.cpp +++ b/src/servers/app/AppServer.cpp @@ -401,23 +401,19 @@ AppServer::Run(void) void AppServer::MainLoop(void) { - BPortLink pmsg(-1,fMessagePort); - int32 code=0; - status_t err=B_OK; - - while(1) - { - STRACE(("info: AppServer::MainLoop listening on port %ld.\n", fMessagePort)); - err=pmsg.GetNextReply(&code); + BPortLink pmsg(-1, fMessagePort); - if(errfListenPort); + int32 code = 0; + status_t err = B_OK; + RootLayer *oneRootLayer = (RootLayer*)data; + BPortLink messageQueue(-1, oneRootLayer->fListenPort); // first make sure we are actualy visible oneRootLayer->Lock(); @@ -206,18 +207,16 @@ int32 RootLayer::WorkingThread(void *data) oneRootLayer->Unlock(); STRACE(("info: RootLayer(%s)::WorkingThread listening on port %ld.\n", oneRootLayer->GetName(), oneRootLayer->fListenPort)); - for(;;) - { - err = messageQueue.GetNextReply(&code); - if(err < B_OK) { + for (;;) { + err = messageQueue.GetNextReply(code); + if (err < B_OK) { STRACE(("WorkingThread: messageQueue.GetNextReply failed\n")); continue; } oneRootLayer->Lock(); - - switch(code) - { + + switch (code) { // We don't need to do anything with these two, so just pass them // onto the active application. Eventually, we will end up passing // them onto the window which is currently under the cursor. @@ -242,22 +241,22 @@ int32 RootLayer::WorkingThread(void *data) case AS_ROOTLAYER_SHOW_WINBORDER: { - WinBorder *winBorder = NULL; + WinBorder *winBorder = NULL; messageQueue.Read(&winBorder); oneRootLayer->show_winBorder(winBorder); break; } case AS_ROOTLAYER_HIDE_WINBORDER: { - WinBorder *winBorder = NULL; + WinBorder *winBorder = NULL; messageQueue.Read(&winBorder); oneRootLayer->hide_winBorder(winBorder); break; } case AS_ROOTLAYER_DO_INVALIDATE: { - BRegion invalidRegion; - Layer *layer = NULL; + BRegion invalidRegion; + Layer *layer = NULL; messageQueue.Read(&layer); messageQueue.ReadRegion(&invalidRegion); oneRootLayer->invalidate_layer(layer, invalidRegion); @@ -265,8 +264,8 @@ int32 RootLayer::WorkingThread(void *data) } case AS_ROOTLAYER_DO_REDRAW: { - BRegion redrawRegion; - Layer *layer = NULL; + BRegion redrawRegion; + Layer *layer = NULL; messageQueue.Read(&layer); messageQueue.ReadRegion(&redrawRegion); oneRootLayer->redraw_layer(layer, redrawRegion); @@ -274,8 +273,8 @@ int32 RootLayer::WorkingThread(void *data) } case AS_ROOTLAYER_LAYER_MOVE: { - Layer *layer = NULL; - float x, y; + Layer *layer = NULL; + float x, y; messageQueue.Read(&layer); messageQueue.Read(&x); messageQueue.Read(&y); @@ -284,8 +283,8 @@ int32 RootLayer::WorkingThread(void *data) } case AS_ROOTLAYER_LAYER_RESIZE: { - Layer *layer = NULL; - float x, y; + Layer *layer = NULL; + float x, y; messageQueue.Read(&layer); messageQueue.Read(&x); messageQueue.Read(&y); @@ -294,8 +293,8 @@ int32 RootLayer::WorkingThread(void *data) } case AS_ROOTLAYER_ADD_TO_SUBSET: { - WinBorder *winBorder = NULL; - WinBorder *toWinBorder = NULL; + WinBorder *winBorder = NULL; + WinBorder *toWinBorder = NULL; messageQueue.Read(&winBorder); messageQueue.Read(&toWinBorder); oneRootLayer->fDesktop->AddWinBorderToSubset(winBorder, toWinBorder); @@ -303,8 +302,8 @@ int32 RootLayer::WorkingThread(void *data) } case AS_ROOTLAYER_REMOVE_FROM_SUBSET: { - WinBorder *winBorder = NULL; - WinBorder *fromWinBorder = NULL; + WinBorder *winBorder = NULL; + WinBorder *fromWinBorder = NULL; messageQueue.Read(&winBorder); messageQueue.Read(&fromWinBorder); oneRootLayer->fDesktop->RemoveWinBorderFromSubset(winBorder, fromWinBorder); @@ -312,8 +311,8 @@ int32 RootLayer::WorkingThread(void *data) } case AS_ROOTLAYER_WINBORDER_SET_WORKSPACES: { - WinBorder *winBorder = NULL; - uint32 oldWks = 0, newWks = 0; + WinBorder *winBorder = NULL; + uint32 oldWks = 0, newWks = 0; messageQueue.Read(&winBorder); messageQueue.Read(&oldWks); @@ -323,8 +322,8 @@ int32 RootLayer::WorkingThread(void *data) } case AS_ROOTLAYER_DO_CHANGE_WINBORDER_FEEL: { - WinBorder *winBorder = NULL; - int32 newFeel = 0; + WinBorder *winBorder = NULL; + int32 newFeel = 0; messageQueue.Read(&winBorder); messageQueue.Read(&newFeel); @@ -345,9 +344,11 @@ int32 RootLayer::WorkingThread(void *data) return 0; } -void RootLayer::GoInvalidate(const Layer *layer, const BRegion ®ion) + +void +RootLayer::GoInvalidate(const Layer *layer, const BRegion ®ion) { - BPortLink msg(fListenPort, -1); + BPortLink msg(fListenPort, -1); msg.StartMessage(AS_ROOTLAYER_DO_INVALIDATE); msg.Attach(layer); msg.AttachRegion(region); diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 8dff406aac..81031fa648 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -297,7 +297,7 @@ ServerApp::MonitorApp(void *data) while (!app->fQuitting) { STRACE(("info: ServerApp::MonitorApp listening on port %ld.\n", app->fMessagePort)); - err = msgqueue.GetNextMessage(&code); + err = msgqueue.GetNextMessage(code); if (err < B_OK) { STRACE(("ServerApp::MonitorApp(): GetNextMessage returned %s\n", strerror(err))); diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 2c819ff4c8..8e3ec6cba1 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -1969,7 +1969,7 @@ ServerWindow::MonitorWin(void *data) while (!quitting) { // printf("info: ServerWindow::MonitorWin listening on port %ld.\n", win->fMessagePort); code = AS_CLIENT_DEAD; - err = ses->GetNextMessage(&code); + err = ses->GetNextMessage(code); if (err < B_OK) return err;