1 /* 2 * Copyright 2001-2009, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm <bpmagic@columbus.rr.com> 7 * Adrian Oanca <adioanca@gmail.com> 8 * Stephan Aßmus <superstippi@gmx.de> 9 * Stefano Ceccherini (burton666@libero.it) 10 * Axel Dörfler, axeld@pinc-software.de 11 */ 12 #ifndef SERVER_WINDOW_H 13 #define SERVER_WINDOW_H 14 15 16 #include "EventDispatcher.h" 17 #include "MessageLooper.h" 18 19 #include <PortLink.h> 20 #include <TokenSpace.h> 21 22 #include <GraphicsDefs.h> 23 #include <Locker.h> 24 #include <Message.h> 25 #include <Messenger.h> 26 #include <Rect.h> 27 #include <Region.h> 28 #include <String.h> 29 #include <Window.h> 30 31 class BString; 32 class BMessenger; 33 class BPoint; 34 class BMessage; 35 36 class Desktop; 37 class ServerApp; 38 class Decorator; 39 class Window; 40 class Workspace; 41 class View; 42 class ServerPicture; 43 struct direct_window_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 clientToken); 55 virtual ~ServerWindow(); 56 57 status_t Init(BRect frame, window_look look, 58 window_feel feel, uint32 flags, 59 uint32 workspace); 60 virtual port_id MessagePort() const { return fMessagePort; } 61 62 ::EventTarget& EventTarget() { return fEventTarget; } 63 64 // methods for sending various messages to client. 65 void NotifyQuitRequested(); 66 void NotifyMinimize(bool minimize); 67 void NotifyZoom(); 68 69 // util methods. 70 const BMessenger& FocusMessenger() const 71 { return fFocusMessenger; } 72 const BMessenger& HandlerMessenger() const 73 { return fHandlerMessenger; } 74 75 status_t SendMessageToClient(const BMessage* msg, 76 int32 target = B_NULL_TOKEN) const; 77 78 virtual ::Window* MakeWindow(BRect frame, const char* name, 79 window_look look, window_feel feel, 80 uint32 flags, uint32 workspace); 81 82 // to who we belong. who do we own. our title. 83 inline ServerApp* App() const { return fServerApp; } 84 ::Desktop* Desktop() const { return fDesktop; } 85 ::Window* Window() const; 86 87 void SetTitle(const char* newTitle); 88 inline const char* Title() const { return fTitle; } 89 90 // related thread/team_id(s). 91 inline team_id ClientTeam() const { return fClientTeam; } 92 93 void HandleDirectConnection(int32 bufferState = -1, 94 int32 driverState = -1); 95 96 inline int32 ClientToken() const { return fClientToken; } 97 inline int32 ServerToken() const { return fServerToken; } 98 99 void RequestRedraw(); 100 101 void GetInfo(window_info& info); 102 103 void ResyncDrawState(); 104 105 // TODO: Change this 106 inline void UpdateCurrentDrawingRegion() 107 { _UpdateCurrentDrawingRegion(); }; 108 109 private: 110 View* _CreateView(BPrivate::LinkReceiver &link, 111 View **_parent); 112 113 void _Show(); 114 void _Hide(); 115 116 // message handling methods. 117 void _DispatchMessage(int32 code, 118 BPrivate::LinkReceiver &link); 119 void _DispatchViewMessage(int32 code, 120 BPrivate::LinkReceiver &link); 121 void _DispatchViewDrawingMessage(int32 code, 122 BPrivate::LinkReceiver &link); 123 bool _DispatchPictureMessage(int32 code, 124 BPrivate::LinkReceiver &link); 125 void _MessageLooper(); 126 virtual void _PrepareQuit(); 127 virtual void _GetLooperName(char* name, size_t size); 128 129 status_t _EnableDirectWindowMode(); 130 131 void _SetCurrentView(View* view); 132 void _UpdateDrawState(View* view); 133 void _UpdateCurrentDrawingRegion(); 134 135 bool _MessageNeedsAllWindowsLocked( 136 uint32 code) const; 137 138 void _DirectWindowSetFullScreen(bool set); 139 140 // TODO: Move me elsewhere 141 status_t PictureToRegion(ServerPicture *picture, 142 BRegion& region, bool inverse, 143 BPoint where); 144 145 private: 146 char* fTitle; 147 148 ::Desktop* fDesktop; 149 ServerApp* fServerApp; 150 ::Window* fWindow; 151 bool fWindowAddedToDesktop; 152 153 team_id fClientTeam; 154 155 port_id fMessagePort; 156 port_id fClientReplyPort; 157 port_id fClientLooperPort; 158 BMessenger fFocusMessenger; 159 BMessenger fHandlerMessenger; 160 ::EventTarget fEventTarget; 161 162 int32 fRedrawRequested; 163 164 int32 fServerToken; 165 int32 fClientToken; 166 167 View* fCurrentView; 168 BRegion fCurrentDrawingRegion; 169 bool fCurrentDrawingRegionValid; 170 171 direct_window_data* fDirectWindowData; 172 window_feel fDirectWindowFeel; 173 }; 174 175 #endif // SERVER_WINDOW_H 176