1 /* 2 * Copyright 2001-2005, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm <bpmagic@columbus.rr.com> 7 * Adrian Oanca <adioanca@cotty.iren.ro> 8 * Stephan Aßmus <superstippi@gmx.de> 9 * Stefano Ceccherini (burton666@libero.it) 10 * Axel Dörfler, axeld@pinc-software.de 11 */ 12 #ifndef _SERVERWIN_H_ 13 #define _SERVERWIN_H_ 14 15 16 #include <DirectWindow.h> // for direct_buffer_state 17 #include <GraphicsDefs.h> 18 #include <PortLink.h> 19 #include <Locker.h> 20 #include <Message.h> 21 #include <OS.h> 22 #include <Rect.h> 23 #include <String.h> 24 #include <Window.h> 25 26 #include "MessageLooper.h" 27 #include "SubWindowList.h" 28 #include "TokenSpace.h" 29 30 class BString; 31 class BMessenger; 32 class BPoint; 33 class BMessage; 34 35 class Desktop; 36 class ServerApp; 37 class Decorator; 38 class WinBorder; 39 class Workspace; 40 class RootLayer; 41 class Layer; 42 class ServerPicture; 43 struct dw_data; 44 struct window_info; 45 46 #define AS_UPDATE_DECORATOR 'asud' 47 #define AS_UPDATE_COLORS 'asuc' 48 #define AS_UPDATE_FONTS 'asuf' 49 50 class ServerWindow : public MessageLooper { 51 public: 52 ServerWindow(const char *title, ServerApp *app, 53 port_id clientPort, port_id looperPort, 54 int32 handlerID); 55 virtual ~ServerWindow(); 56 57 status_t Init(BRect frame, uint32 look, 58 uint32 feel, uint32 flags, 59 uint32 workspace); 60 virtual bool Run(); 61 virtual port_id MessagePort() const { return fMessagePort; } 62 63 void ReplaceDecorator(); 64 void Show(); 65 void Hide(); 66 67 // methods for sending various messages to client. 68 void NotifyQuitRequested(); 69 void NotifyMinimize(bool minimize); 70 void NotifyZoom(); 71 void NotifyScreenModeChanged(const BRect frame, 72 const color_space cspace); 73 74 // util methods. 75 status_t SendMessageToClient(const BMessage* msg, 76 int32 target = B_NULL_TOKEN, 77 bool usePreferred = false) const; 78 79 virtual WinBorder* MakeWinBorder(BRect frame, 80 const char* name, 81 uint32 look, uint32 feel, 82 uint32 flags, uint32 workspace); 83 84 85 // TODO: Ouch, that's not exactly a nice name 86 inline BMessage &ClientViewsWithInvalidCoords() 87 { return fClientViewsWithInvalidCoords; }; 88 89 // to who we belong. who do we own. our title. 90 inline ServerApp* App() const { return fServerApp; } 91 inline const WinBorder* GetWinBorder() const { return fWinBorder; } 92 93 void SetTitle(const char* newTitle); 94 inline const char* Title() const { return fTitle; } 95 96 // related thread/team_id(s). 97 inline team_id ClientTeam() const { return fClientTeam; } 98 99 // server "private" - try not to use. 100 inline int32 ClientToken() const { return fHandlerToken; } 101 inline int32 ServerToken() const { return fServerToken; } 102 103 void GetInfo(window_info& info); 104 105 // ToDo: public?? 106 SubWindowList fSubWindowList; 107 108 private: 109 // methods for retrieving and creating a tree strcture of Layers. 110 Layer* CreateLayerTree(BPrivate::LinkReceiver &link, Layer **_parent); 111 void SetLayerState(Layer *layer, BPrivate::LinkReceiver &link); 112 void SetLayerFontState(Layer *layer, BPrivate::LinkReceiver &link); 113 114 // message handling methods. 115 void _DispatchMessage(int32 code, BPrivate::LinkReceiver &link); 116 void _DispatchGraphicsMessage(int32 code, BPrivate::LinkReceiver &link); 117 void _MessageLooper(); 118 virtual void _PrepareQuit(); 119 virtual void _GetLooperName(char* name, size_t size); 120 121 status_t _EnableDirectWindowMode(); 122 void _HandleDirectConnection(direct_buffer_state state); 123 124 // TODO: Move me elsewhere 125 status_t PictureToRegion(ServerPicture *picture, 126 BRegion &, 127 bool inverse, 128 BPoint where); 129 130 private: 131 const char* fTitle; 132 133 Desktop* fDesktop; 134 ServerApp* fServerApp; 135 WinBorder* fWinBorder; 136 137 team_id fClientTeam; 138 139 port_id fMessagePort; 140 port_id fClientReplyPort; 141 port_id fClientLooperPort; 142 143 BMessage fClientViewsWithInvalidCoords; 144 145 int32 fServerToken; 146 int32 fHandlerToken; 147 148 Layer* fCurrentLayer; 149 150 dw_data* fDirectWindowData; 151 }; 152 153 #endif // _SERVERWIN_H_ 154