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 <GraphicsDefs.h> 17 #include <Locker.h> 18 #include <Message.h> 19 #include <Messenger.h> 20 #include <Rect.h> 21 #include <Region.h> 22 #include <String.h> 23 #include <Window.h> 24 25 #include <PortLink.h> 26 #include <TokenSpace.h> 27 28 #include "EventDispatcher.h" 29 #include "MessageLooper.h" 30 31 32 class BString; 33 class BMessenger; 34 class BPoint; 35 class BMessage; 36 37 class Desktop; 38 class ServerApp; 39 class Decorator; 40 class Window; 41 class Workspace; 42 class View; 43 class ServerPicture; 44 class DirectWindowInfo; 45 struct window_info; 46 47 #define AS_UPDATE_DECORATOR 'asud' 48 #define AS_UPDATE_COLORS 'asuc' 49 #define AS_UPDATE_FONTS 'asuf' 50 51 52 class ServerWindow : public MessageLooper { 53 public: 54 ServerWindow(const char *title, ServerApp *app, 55 port_id clientPort, port_id looperPort, 56 int32 clientToken); 57 virtual ~ServerWindow(); 58 59 status_t Init(BRect frame, window_look look, 60 window_feel feel, uint32 flags, 61 uint32 workspace); 62 63 virtual port_id MessagePort() const { return fMessagePort; } 64 65 ::EventTarget& EventTarget() { return fEventTarget; } 66 67 inline ServerApp* App() const { return fServerApp; } 68 ::Desktop* Desktop() const { return fDesktop; } 69 ::Window* Window() const; 70 71 // methods for sending various messages to client. 72 void NotifyQuitRequested(); 73 void NotifyMinimize(bool minimize); 74 void NotifyZoom(); 75 76 // util methods. 77 const BMessenger& FocusMessenger() const 78 { return fFocusMessenger; } 79 const BMessenger& HandlerMessenger() const 80 { return fHandlerMessenger; } 81 82 void ScreenChanged(const BMessage* message); 83 status_t SendMessageToClient(const BMessage* message, 84 int32 target = B_NULL_TOKEN) const; 85 86 virtual ::Window* MakeWindow(BRect frame, const char* name, 87 window_look look, window_feel feel, 88 uint32 flags, uint32 workspace); 89 90 void SetTitle(const char* newTitle); 91 inline const char* Title() const { return fTitle; } 92 93 // related thread/team_id(s). 94 inline team_id ClientTeam() const { return fClientTeam; } 95 96 inline port_id ClientLooperPort () const 97 { return fClientLooperPort; } 98 99 inline int32 ClientToken() const { return fClientToken; } 100 inline int32 ServerToken() const { return fServerToken; } 101 102 void RequestRedraw(); 103 104 void GetInfo(window_info& info); 105 106 void HandleDirectConnection(int32 bufferState, 107 int32 driverState = 0); 108 bool HasDirectFrameBufferAccess() const 109 { return fDirectWindowInfo != NULL; } 110 bool IsDirectlyAccessing() const 111 { return fIsDirectlyAccessing; } 112 113 void ResyncDrawState(); 114 115 // TODO: Change this 116 inline void UpdateCurrentDrawingRegion() 117 { _UpdateCurrentDrawingRegion(); }; 118 119 private: 120 View* _CreateView(BPrivate::LinkReceiver &link, 121 View **_parent); 122 123 void _Show(); 124 void _Hide(); 125 126 // message handling methods. 127 void _DispatchMessage(int32 code, 128 BPrivate::LinkReceiver &link); 129 void _DispatchViewMessage(int32 code, 130 BPrivate::LinkReceiver &link); 131 void _DispatchViewDrawingMessage(int32 code, 132 BPrivate::LinkReceiver &link); 133 bool _DispatchPictureMessage(int32 code, 134 BPrivate::LinkReceiver &link); 135 void _MessageLooper(); 136 virtual void _PrepareQuit(); 137 virtual void _GetLooperName(char* name, size_t size); 138 139 void _ResizeToFullScreen(); 140 status_t _EnableDirectWindowMode(); 141 void _DirectWindowSetFullScreen(bool set); 142 143 void _SetCurrentView(View* view); 144 void _UpdateDrawState(View* view); 145 void _UpdateCurrentDrawingRegion(); 146 147 bool _MessageNeedsAllWindowsLocked( 148 uint32 code) const; 149 150 private: 151 char* fTitle; 152 153 ::Desktop* fDesktop; 154 ServerApp* fServerApp; 155 ::Window* fWindow; 156 bool fWindowAddedToDesktop; 157 158 team_id fClientTeam; 159 160 port_id fMessagePort; 161 port_id fClientReplyPort; 162 port_id fClientLooperPort; 163 BMessenger fFocusMessenger; 164 BMessenger fHandlerMessenger; 165 ::EventTarget fEventTarget; 166 167 int32 fRedrawRequested; 168 169 int32 fServerToken; 170 int32 fClientToken; 171 172 View* fCurrentView; 173 BRegion fCurrentDrawingRegion; 174 bool fCurrentDrawingRegionValid; 175 176 DirectWindowInfo* fDirectWindowInfo; 177 bool fIsDirectlyAccessing; 178 }; 179 180 #endif // SERVER_WINDOW_H 181