From f0577aea09839e38f83a2a90429bb2252bce36de Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Sat, 23 Nov 2002 01:23:43 +0000 Subject: [PATCH] Complete server update. Fix for garbage text in window titles Updates to decorator and API git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2066 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/proto7/AppServer.cpp | 24 ++++++--- src/servers/app/proto7/AppServer.h | 5 +- src/servers/app/proto7/BeDecorator.cpp | 49 +++++++++++-------- src/servers/app/proto7/BeDecorator.h | 7 ++- src/servers/app/proto7/Decorator.cpp | 48 ++++++++++-------- src/servers/app/proto7/Decorator.h | 11 +++-- src/servers/app/proto7/ScreenDriver.cpp | 5 +- src/servers/app/proto7/ServerApp.h | 1 - src/servers/app/proto7/ServerWindow.cpp | 14 +++--- src/servers/app/proto7/ViewDriver.cpp | 1 + src/servers/app/proto7/WindowBorder.cpp | 10 ++-- src/servers/app/proto7/WindowBorder.h | 1 + src/servers/app/proto7/testobapp/OBWindow.cpp | 7 ++- 13 files changed, 110 insertions(+), 73 deletions(-) diff --git a/src/servers/app/proto7/AppServer.cpp b/src/servers/app/proto7/AppServer.cpp index afe04b22ac..7245f0cc68 100644 --- a/src/servers/app/proto7/AppServer.cpp +++ b/src/servers/app/proto7/AppServer.cpp @@ -59,8 +59,8 @@ printf("Server input port: %ld\n",mouseport); // fontserver->ScanDirectory("/boot/home/config/fonts/psfonts/"); fontserver->SaveList(); - if(!fontserver->SetSystemPlain("Dutch801 Rm BT","Roman",12)) - printf("Couldn't set plain to Dutch801 Rm BT, Roman 12 pt\n"); + if(!fontserver->SetSystemPlain("Swis721 BT","Roman",12)) + printf("Couldn't set plain to Swis721 BT, Roman 12 pt\n"); if(!fontserver->SetSystemBold("Dutch801 Rm BT","Bold",12)) printf("Couldn't set bold to Dutch801 Rm BT, Bold 12 pt\n"); if(!fontserver->SetSystemFixed("Courier10 BT","Roman",12)) @@ -236,9 +236,18 @@ printf("AppServer: Create App\n"); // Find the necessary data port_id reply_port=*((port_id*)index); index+=sizeof(port_id); +#ifdef DEBUG_APPSERVER_THREAD +printf("\tCreate App: reply port is %lu\n",reply_port); +#endif port_id app_port=*((port_id*)index); index+=sizeof(port_id); +#ifdef DEBUG_APPSERVER_THREAD +printf("\tCreate App: ServerApp port is %lu\n", app_port); +#endif char *app_signature=(char *)index; +#ifdef DEBUG_APPSERVER_THREAD +printf("\tCreate App: Signature received is %s\n", app_signature); +#endif // Create the ServerApp subthread for this app applist_lock->Lock(); @@ -463,7 +472,8 @@ void AppServer::LoadDefaultDecorator(void) } -Decorator *instantiate_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags) +Decorator *instantiate_decorator(BRect rect, const char *title, int32 wlook, int32 wfeel, int32 wflags, + DisplayDriver *ddriver) { Decorator *decor=NULL; @@ -471,11 +481,8 @@ Decorator *instantiate_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wfl if(app_server->make_decorator!=NULL) decor=app_server->make_decorator(rect,wlook,wfeel,wflags); else - { - decor=new BeDecorator(rect,wlook,wfeel,wflags); -// decor=new WinDecorator(lay, dflags, wlook); -// decor=new YMakDecorator(lay, dflags, wlook); - } + decor=new BeDecorator(rect,title,wlook,wfeel,wflags,ddriver); + decor->SetDriver(get_gfxdriver()); app_server->UnlockDecorator(); return decor; @@ -508,6 +515,7 @@ void AppServer::Poller(void) #ifdef DEBUG_POLLER_THREAD printf("Poller: MouseDown() - Empty buffer\n"); #endif + ServerWindow::HandleMouseEvent(msgcode,msgbuffer); break; } case B_MOUSE_UP: diff --git a/src/servers/app/proto7/AppServer.h b/src/servers/app/proto7/AppServer.h index 7991e86e24..5c03eb9186 100644 --- a/src/servers/app/proto7/AppServer.h +++ b/src/servers/app/proto7/AppServer.h @@ -27,7 +27,7 @@ public: void UnlockDecorator(void) { if(decor_lock) decor_lock->Unlock(); } create_decorator *make_decorator; // global function pointer private: - friend Decorator *instantiate_decorator(Layer *lay, uint32 dflags, uint32 wlook); + friend Decorator *instantiate_decorator(Layer *lay, const char *title, uint32 dflags, uint32 wlook); void DispatchMessage(int32 code, int8 *buffer); static int32 PollerThread(void *data); @@ -47,5 +47,6 @@ private: DisplayDriver *driver; }; -Decorator *instantiate_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags); +Decorator *instantiate_decorator(BRect rect, const char *title, int32 wlook, int32 wfeel, + int32 wflags, DisplayDriver *ddriver); #endif \ No newline at end of file diff --git a/src/servers/app/proto7/BeDecorator.cpp b/src/servers/app/proto7/BeDecorator.cpp index db27f9f22a..d54b38f693 100644 --- a/src/servers/app/proto7/BeDecorator.cpp +++ b/src/servers/app/proto7/BeDecorator.cpp @@ -13,8 +13,9 @@ #include #endif -BeDecorator::BeDecorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags) - : Decorator(rect,wlook,wfeel,wflags) +BeDecorator::BeDecorator(BRect rect, const char *title, int32 wlook, int32 wfeel, int32 wflags, + DisplayDriver *ddriver) + : Decorator(rect,title,wlook,wfeel,wflags,ddriver) { #ifdef DEBUG_DECOR printf("BeDecorator()\n"); @@ -147,16 +148,14 @@ printf("BeDecorator()::_DoLayout()"); rect.PrintToStream(); resizerect.left=resizerect.right-18; tabrect.bottom=tabrect.top+18; -/* if(GetTitle()) + if(titlewidth>0) { - float titlewidth=closerect.right - +driver->StringWidth(layer->name->String(), - layer->name->Length()) - +35; - tabrect.right=(titlewidthframe.right) + tabrect.right=frame.right; } else -*/ tabrect.right=tabrect.left+tabrect.Width()/2; + tabrect.right=tabrect.left+tabrect.Width()/2; if(look==WLOOK_FLOATING) tabrect.top+=4; @@ -169,6 +168,17 @@ printf("BeDecorator()::_DoLayout()"); rect.PrintToStream(); zoomrect.bottom=zoomrect.top+10; textoffset=(look==WLOOK_FLOATING)?5:7; +// titlechars=_ClipTitle(zoomrect.left-(closerect.right+textoffset)); + titlechars=_ClipTitle(zoomrect.left-closerect.right); +} + +void BeDecorator::SetTitle(const char *string) +{ + Decorator::SetTitle(string); + if(string && driver) + titlewidth=driver->StringWidth(GetTitle(),strlen(GetTitle()),&layerdata); + else + titlewidth=0; } void BeDecorator::MoveBy(float x, float y) @@ -214,14 +224,12 @@ void BeDecorator::_DrawTitle(BRect r) { // Designed simply to redraw the title when it has changed on // the client side. -/* driver->SetDrawingMode(B_OP_OVER); - rgb_color tmpcol=driver->HighColor(); - driver->SetHighColor(textcol.red,textcol.green,textcol.blue); - driver->DrawString((char *)string,strlen(string), - BPoint(closerect.right+textoffset,closerect.bottom-1)); - driver->SetHighColor(tmpcol.red,tmpcol.green,tmpcol.blue); - driver->SetDrawingMode(B_OP_COPY); -*/ + layerdata.draw_mode=B_OP_OVER; + layerdata.highcolor=colors->window_tab_text; + driver->DrawString(GetTitle(),titlechars, + BPoint(closerect.right+textoffset,closerect.bottom),&layerdata); + layerdata.draw_mode=B_OP_COPY; + } void BeDecorator::_SetFocus(void) @@ -313,8 +321,6 @@ void BeDecorator::_DrawTab(BRect r) layerdata.highcolor=frame_lowcol; driver->StrokeRect(tabrect,&layerdata,(int8*)&solidhigh); -// UpdateTitle(layer->name->String()); - layerdata.highcolor=colors->window_tab; driver->FillRect(tabrect.InsetByCopy(1,1),&layerdata,(int8*)&solidhigh); @@ -494,7 +500,8 @@ extern "C" float get_decorator_version(void) return 1.00; } -extern "C" Decorator *instantiate_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags) +extern "C" Decorator *instantiate_decorator(BRect rect, const char *title, + int32 wlook, int32 wfeel, int32 wflags,DisplayDriver *ddriver) { - return new BeDecorator(rect,wlook,wfeel,wflags); + return new BeDecorator(rect,title, wlook,wfeel,wflags,ddriver); } \ No newline at end of file diff --git a/src/servers/app/proto7/BeDecorator.h b/src/servers/app/proto7/BeDecorator.h index 94a408e805..c19836ceb6 100644 --- a/src/servers/app/proto7/BeDecorator.h +++ b/src/servers/app/proto7/BeDecorator.h @@ -7,9 +7,11 @@ class BeDecorator: public Decorator { public: - BeDecorator(BRect frame, int32 wlook, int32 wfeel, int32 wflags); + BeDecorator(BRect frame, const char *title, int32 wlook, int32 wfeel, int32 wflags, + DisplayDriver *ddriver); ~BeDecorator(void); + void SetTitle(const char *string); void MoveBy(float x, float y); void MoveBy(BPoint pt); void ResizeBy(float x, float y); @@ -36,9 +38,10 @@ protected: frame_lowercol; RGBColor textcol; uint64 solidhigh, solidlow; + float titlewidth; bool slidetab; - int textoffset; + int textoffset, titlechars; }; #endif \ No newline at end of file diff --git a/src/servers/app/proto7/Decorator.cpp b/src/servers/app/proto7/Decorator.cpp index eadb95dc59..736484d2ae 100644 --- a/src/servers/app/proto7/Decorator.cpp +++ b/src/servers/app/proto7/Decorator.cpp @@ -1,13 +1,14 @@ #include "Decorator.h" -#include +#include "DisplayDriver.h" -Decorator::Decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags) +Decorator::Decorator(BRect rect, const char *title, int32 wlook, int32 wfeel, int32 wflags, + DisplayDriver *ddriver) { close_state=false; minimize_state=false; zoom_state=false; - title_string=NULL; - driver=NULL; + title_string=new BString(title); + driver=ddriver; closerect.Set(0,0,1,1); zoomrect.Set(0,0,1,1); @@ -41,7 +42,10 @@ void Decorator::SetColors(ColorSet cset) void Decorator::SetDriver(DisplayDriver *d) { + // lots of subclasses will depend on the driver for text support, so call + // _DoLayout() after this driver=d; + _DoLayout(); } void Decorator::SetClose(bool is_down) @@ -106,25 +110,12 @@ int32 Decorator::GetFlags(void) void Decorator::SetTitle(const char *string) { - if(string) - { - size_t size=strlen(string); - if(!(size>0)) - return; - delete title_string; - title_string=new char[size]; - strcpy(title_string,string); - } - else - { - delete title_string; - title_string=NULL; - } + title_string->SetTo(string); } const char *Decorator::GetTitle(void) { - return title_string; + return title_string->String(); } void Decorator::SetFocus(bool is_active) @@ -138,8 +129,24 @@ void Decorator::SetFont(SFont *sf) { } */ -void Decorator::_ClipTitle(void) +int32 Decorator::_ClipTitle(float width) { + if(driver) + { + int32 strlength=title_string->CountChars(); + float pixwidth=driver->StringWidth(title_string->String(),strlength,&layerdata); + + while(strlength>=0) + { + if(pixwidthStringWidth(title_string->String(),strlength,&layerdata); + } + + return strlength; + } + return 0; } //------------------------------------------------------------------------- @@ -230,6 +237,7 @@ void Decorator::_DrawTitle(BRect r) void Decorator::_DrawZoom(BRect r) { } + /* SRegion Decorator::GetFootprint(void) { diff --git a/src/servers/app/proto7/Decorator.h b/src/servers/app/proto7/Decorator.h index efe014807e..59ddfa2fa6 100644 --- a/src/servers/app/proto7/Decorator.h +++ b/src/servers/app/proto7/Decorator.h @@ -3,6 +3,7 @@ #include #include +#include #include "ColorSet.h" #include "LayerData.h" @@ -55,7 +56,8 @@ typedef enum { CLICK_NONE=0, CLICK_ZOOM, CLICK_CLOSE, CLICK_MINIMIZE, class Decorator { public: - Decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags); + Decorator(BRect rect, const char *title, int32 wlook, int32 wfeel, int32 wflags, + DisplayDriver *ddriver); virtual ~Decorator(void); void SetColors(ColorSet cset); void SetDriver(DisplayDriver *d); @@ -71,12 +73,11 @@ public: int32 GetLook(void); int32 GetFeel(void); int32 GetFlags(void); - void SetTitle(const char *string); + virtual void SetTitle(const char *string); void SetFocus(bool is_active); bool GetFocus(void) { return has_focus; }; const char *GetTitle(void); // void SetFont(SFont *sf); - void _ClipTitle(void); ColorSet GetColors(void) { if(colors) return *colors; else return ColorSet(); } virtual void MoveBy(float x, float y); @@ -95,6 +96,8 @@ public: virtual click_type Clicked(BPoint pt, int32 buttons, int32 modifiers); protected: + int32 _ClipTitle(float width); + int32 TitleWidth(void) { return (title_string)?title_string->CountChars():0; } virtual void _DrawClose(BRect r); virtual void _DrawFrame(BRect r); virtual void _DrawMinimize(BRect r); @@ -112,7 +115,7 @@ protected: private: bool close_state, zoom_state, minimize_state; bool has_focus; - char *title_string; + BString *title_string; }; typedef float get_version(void); diff --git a/src/servers/app/proto7/ScreenDriver.cpp b/src/servers/app/proto7/ScreenDriver.cpp index adc90c8fa6..a30fa4266c 100644 --- a/src/servers/app/proto7/ScreenDriver.cpp +++ b/src/servers/app/proto7/ScreenDriver.cpp @@ -41,7 +41,7 @@ // Define this if you want to use the spacebar to launch the server prototype's // test application -//#define LAUNCH_TESTAPP +#define LAUNCH_TESTAPP #ifdef LAUNCH_TESTAPP #include @@ -1348,7 +1348,7 @@ void ScreenDriver::SetCursor(ServerBitmap *csr, const BPoint &spot) #ifdef DEBUG_DRIVER printf("ScreenDriver::SetCursor\n"); #endif - if(!csr) +/* if(!csr) return; Lock(); @@ -1380,6 +1380,7 @@ printf("ScreenDriver::SetCursor\n"); BlitBitmap(cursor,cursor->Bounds(),cursorframe); Unlock(); +*/ } void ScreenDriver::HLine(int32 x1, int32 x2, int32 y, RGBColor color) diff --git a/src/servers/app/proto7/ServerApp.h b/src/servers/app/proto7/ServerApp.h index 90b2a88327..39a184115c 100644 --- a/src/servers/app/proto7/ServerApp.h +++ b/src/servers/app/proto7/ServerApp.h @@ -6,7 +6,6 @@ class BMessage; class PortLink; class BList; -class ServerCursor; class DisplayDriver; class ServerApp diff --git a/src/servers/app/proto7/ServerWindow.cpp b/src/servers/app/proto7/ServerWindow.cpp index 677abdc575..d47ede4a71 100644 --- a/src/servers/app/proto7/ServerWindow.cpp +++ b/src/servers/app/proto7/ServerWindow.cpp @@ -36,7 +36,7 @@ ServerWindow::ServerWindow(BRect rect, const char *string, uint32 wlook, else title->SetTo("Window"); #ifdef DEBUG_SERVERWIN -printf("ServerWindow() %s\n",title->String()); +printf("ServerWindow(%s)\n",title->String()); #endif // This must happen before the WindowBorder object - it needs this object's frame @@ -53,14 +53,14 @@ printf("ServerWindow() %s\n",title->String()); // hard code this for now - window look also needs to be attached and sent to // server by BWindow constructor - decorator=instantiate_decorator(frame,winlook,winfeel,winflags); + decorator=instantiate_decorator(frame,title->String(),winlook,winfeel,winflags,get_gfxdriver()); #ifdef DEBUG_SERVERWIN if(decorator==NULL) - printf("ServerWindow() %s: NULL decorator returned\n",title->String()); + printf("\tNULL decorator returned\n"); #endif winborder->SetDecorator(decorator); #ifdef DEBUG_SERVERWIN -printf("ServerWindow() %s: decorator set\n",title->String()); +printf("\tdecorator set\n"); #endif // sender is the monitored app's event port @@ -72,7 +72,7 @@ printf("ServerWindow() %s: decorator set\n",title->String()); else applink=NULL; #ifdef DEBUG_SERVERWIN -printf("ServerWindow() %s: PortLink established\n",title->String()); +printf("\tPortLink established\n"); #endif // receiver is the port to which the app sends messages for the server @@ -86,14 +86,14 @@ printf("ServerWindow() %s: PortLink established\n",title->String()); if(thread!=B_NO_MORE_THREADS && thread!=B_NO_MEMORY) resume_thread(thread); #ifdef DEBUG_SERVERWIN -printf("ServerWindow() %s: MonitorThread spawned\n",title->String()); +printf("\tMonitorThread spawned\n"); #endif workspace=index; AddWindowToDesktop(this,index); #ifdef DEBUG_SERVERWIN -printf("ServerWindow() %s: Added to Desktop\n",title->String()); +printf("\tAdded to Desktop\n"); #endif } diff --git a/src/servers/app/proto7/ViewDriver.cpp b/src/servers/app/proto7/ViewDriver.cpp index 3e5b8ec562..1b72f40cfc 100644 --- a/src/servers/app/proto7/ViewDriver.cpp +++ b/src/servers/app/proto7/ViewDriver.cpp @@ -504,6 +504,7 @@ printf("ViewDriver:: CopyBits()\n"); src.PrintToStream(); dest.PrintToStream(); framebuffer->Lock(); drawview->CopyBits(src,dest); drawview->Sync(); + screenwin->view->Invalidate(src); screenwin->view->Invalidate(dest); framebuffer->Unlock(); screenwin->Unlock(); diff --git a/src/servers/app/proto7/WindowBorder.cpp b/src/servers/app/proto7/WindowBorder.cpp index 8ff01eac02..720a2f830f 100644 --- a/src/servers/app/proto7/WindowBorder.cpp +++ b/src/servers/app/proto7/WindowBorder.cpp @@ -4,11 +4,12 @@ #include #include "View.h" // for mouse button defines #include "ServerWindow.h" -#include "WindowBorder.h" #include "Decorator.h" +#include "DisplayDriver.h" #include "Desktop.h" +#include "WindowBorder.h" -#define DEBUG_WINBORDER +//#define DEBUG_WINBORDER #ifdef DEBUG_WINBORDER #include @@ -23,7 +24,7 @@ WindowBorder::WindowBorder(ServerWindow *win, const char *bordertitle) (win==NULL)?NULL:win->title->String()) { #ifdef DEBUG_WINBORDER -printf("WindowBorder()\n"); +printf("WindowBorder(%s)\n",bordertitle); #endif mbuttons=0; swin=win; @@ -33,7 +34,6 @@ printf("WindowBorder()\n"); title=new BString(bordertitle); hresizewin=false; vresizewin=false; - } WindowBorder::~WindowBorder(void) @@ -276,6 +276,8 @@ printf("WindowBorder::SetDecorator(%p)\n",newdecor); if(newdecor) { decor=newdecor; + decor->SetTitle(title->String()); + decor->ResizeBy(0,0); // if(visible) // delete visible; // visible=decor->GetFootprint(); diff --git a/src/servers/app/proto7/WindowBorder.h b/src/servers/app/proto7/WindowBorder.h index c1090e28c0..ecdf4390fd 100644 --- a/src/servers/app/proto7/WindowBorder.h +++ b/src/servers/app/proto7/WindowBorder.h @@ -7,6 +7,7 @@ class ServerWindow; class Decorator; +class DisplayDriver; class WindowBorder : public Layer { diff --git a/src/servers/app/proto7/testobapp/OBWindow.cpp b/src/servers/app/proto7/testobapp/OBWindow.cpp index 0409391af1..71f48a506d 100644 --- a/src/servers/app/proto7/testobapp/OBWindow.cpp +++ b/src/servers/app/proto7/testobapp/OBWindow.cpp @@ -38,7 +38,7 @@ printf("OBWindow(%s)\n",title); if(inport==B_BAD_VALUE || inport==B_NO_MORE_PORTS) printf("OBWindow: Couldn't create message port\n"); - // Notify app that we exist + // Notify BApplication that we exist OBWindow *win=this; PortLink *link=new PortLink(obe_app->messageport); link->SetOpCode(ADDWINDOW); @@ -67,7 +67,10 @@ printf("OBWindow(%s)\n",title); serverlink->Attach((int32)wflags); serverlink->Attach(&inport,sizeof(port_id)); serverlink->Attach((int32)wkspace); - serverlink->Attach((char*)wtitle->String(),wtitle->Length()); + //We add one so that the string will end up NULL-terminated. Otherwise, when + // we go to use the thing in the app_server, it will sometimes get junk + // characters at the end. + serverlink->Attach((char*)wtitle->String(),wtitle->CountChars()+1); // Send and wait for ServerWindow port. Necessary here so we can respond to // messages as soon as Show() is called.