1 /* 2 * Copyright 2001-2008, 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 void ReplaceDecorator(); 65 66 // methods for sending various messages to client. 67 void NotifyQuitRequested(); 68 void NotifyMinimize(bool minimize); 69 void NotifyZoom(); 70 71 // util methods. 72 const BMessenger& FocusMessenger() const 73 { return fFocusMessenger; } 74 const BMessenger& HandlerMessenger() const 75 { return fHandlerMessenger; } 76 77 status_t SendMessageToClient(const BMessage* msg, 78 int32 target = B_NULL_TOKEN) const; 79 80 virtual ::Window* MakeWindow(BRect frame, const char* name, 81 window_look look, window_feel feel, 82 uint32 flags, uint32 workspace); 83 84 // to who we belong. who do we own. our title. 85 inline ServerApp* App() const { return fServerApp; } 86 ::Desktop* Desktop() const { return fDesktop; } 87 ::Window* Window() const; 88 89 void SetTitle(const char* newTitle); 90 inline const char* Title() const { return fTitle; } 91 92 // related thread/team_id(s). 93 inline team_id ClientTeam() const { return fClientTeam; } 94 95 void HandleDirectConnection(int32 bufferState = -1, 96 int32 driverState = -1); 97 98 inline int32 ClientToken() const { return fClientToken; } 99 inline int32 ServerToken() const { return fServerToken; } 100 101 void RequestRedraw(); 102 103 void GetInfo(window_info& info); 104 105 void ResyncDrawState(); 106 107 private: 108 View* _CreateView(BPrivate::LinkReceiver &link, 109 View **_parent); 110 111 void _Show(); 112 void _Hide(); 113 114 // message handling methods. 115 void _DispatchMessage(int32 code, BPrivate::LinkReceiver &link); 116 void _DispatchViewMessage(int32 code, 117 BPrivate::LinkReceiver &link); 118 void _DispatchViewDrawingMessage(int32 code, 119 BPrivate::LinkReceiver &link); 120 bool _DispatchPictureMessage(int32 code, 121 BPrivate::LinkReceiver &link); 122 void _MessageLooper(); 123 virtual void _PrepareQuit(); 124 virtual void _GetLooperName(char* name, size_t size); 125 126 status_t _EnableDirectWindowMode(); 127 128 void _SetCurrentView(View* view); 129 void _UpdateDrawState(View* view); 130 void _UpdateCurrentDrawingRegion(); 131 132 bool _MessageNeedsAllWindowsLocked(uint32 code) const; 133 134 // TODO: Move me elsewhere 135 status_t PictureToRegion(ServerPicture *picture, 136 BRegion& region, bool inverse, 137 BPoint where); 138 139 private: 140 char* fTitle; 141 142 ::Desktop* fDesktop; 143 ServerApp* fServerApp; 144 ::Window* fWindow; 145 bool fWindowAddedToDesktop; 146 147 team_id fClientTeam; 148 149 port_id fMessagePort; 150 port_id fClientReplyPort; 151 port_id fClientLooperPort; 152 BMessenger fFocusMessenger; 153 BMessenger fHandlerMessenger; 154 ::EventTarget fEventTarget; 155 156 int32 fRedrawRequested; 157 158 int32 fServerToken; 159 int32 fClientToken; 160 161 View* fCurrentView; 162 BRegion fCurrentDrawingRegion; 163 bool fCurrentDrawingRegionValid; 164 165 direct_window_data* fDirectWindowData; 166 window_feel fDirectWindowFeel; 167 }; 168 169 #endif // SERVER_WINDOW_H 170