PageRenderTime 26ms CodeModel.GetById 8ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llwindow/llwindow.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 285 lines | 179 code | 43 blank | 63 comment | 0 complexity | c659b30bb06d099935b8cab327db30f1 MD5 | raw file
  1/** 
  2 * @file llwindow.h
  3 * @brief Basic graphical window class
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLWINDOW_H
 28#define LL_LLWINDOW_H
 29
 30#include "llrect.h"
 31#include "llcoord.h"
 32#include "llstring.h"
 33#include "llcursortypes.h"
 34#include "llsd.h"
 35
 36class LLSplashScreen;
 37class LLPreeditor;
 38class LLWindowCallbacks;
 39
 40// Refer to llwindow_test in test/common/llwindow for usage example
 41
 42class LLWindow
 43{
 44public:
 45	struct LLWindowResolution
 46	{
 47		S32 mWidth;
 48		S32 mHeight;
 49	};
 50	enum ESwapMethod
 51	{
 52		SWAP_METHOD_UNDEFINED,
 53		SWAP_METHOD_EXCHANGE,
 54		SWAP_METHOD_COPY
 55	};
 56	enum EFlags
 57	{
 58		// currently unused
 59	};
 60public:
 61	virtual void show() = 0;
 62	virtual void hide() = 0;
 63	virtual void close() = 0;
 64	virtual BOOL getVisible() = 0;
 65	virtual BOOL getMinimized() = 0;
 66	virtual BOOL getMaximized() = 0;
 67	virtual BOOL maximize() = 0;
 68	virtual void minimize() = 0;
 69	virtual void restore() = 0;
 70	BOOL getFullscreen()	{ return mFullscreen; };
 71	virtual BOOL getPosition(LLCoordScreen *position) = 0;
 72	virtual BOOL getSize(LLCoordScreen *size) = 0;
 73	virtual BOOL getSize(LLCoordWindow *size) = 0;
 74	virtual BOOL setPosition(LLCoordScreen position) = 0;
 75	BOOL setSize(LLCoordScreen size);
 76	virtual void setMinSize(U32 min_width, U32 min_height, bool enforce_immediately = true);
 77	virtual BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp = NULL) = 0;
 78	virtual BOOL setCursorPosition(LLCoordWindow position) = 0;
 79	virtual BOOL getCursorPosition(LLCoordWindow *position) = 0;
 80	virtual void showCursor() = 0;
 81	virtual void hideCursor() = 0;
 82	virtual BOOL isCursorHidden() = 0;
 83	virtual void showCursorFromMouseMove() = 0;
 84	virtual void hideCursorUntilMouseMove() = 0;
 85
 86	// These two functions create a way to make a busy cursor instead
 87	// of an arrow when someone's busy doing something. Draw an
 88	// arrow/hour if busycount > 0.
 89	virtual void incBusyCount();
 90	virtual void decBusyCount();
 91	virtual void resetBusyCount();
 92	virtual S32 getBusyCount() const;
 93
 94	// Sets cursor, may set to arrow+hourglass
 95	virtual void setCursor(ECursorType cursor) { mNextCursor = cursor; };
 96	virtual ECursorType getCursor() const;
 97	virtual void updateCursor() = 0;
 98
 99	virtual void captureMouse() = 0;
100	virtual void releaseMouse() = 0;
101	virtual void setMouseClipping( BOOL b ) = 0;
102
103	virtual BOOL isClipboardTextAvailable() = 0;
104	virtual BOOL pasteTextFromClipboard(LLWString &dst) = 0;
105	virtual BOOL copyTextToClipboard(const LLWString &src) = 0;
106
107	virtual BOOL isPrimaryTextAvailable();
108	virtual BOOL pasteTextFromPrimary(LLWString &dst);
109	virtual BOOL copyTextToPrimary(const LLWString &src);
110 
111	virtual void flashIcon(F32 seconds) = 0;
112	virtual F32 getGamma() = 0;
113	virtual BOOL setGamma(const F32 gamma) = 0; // Set the gamma
114	virtual void setFSAASamples(const U32 fsaa_samples) = 0; //set number of FSAA samples
115	virtual U32	 getFSAASamples() = 0;
116	virtual BOOL restoreGamma() = 0;			// Restore original gamma table (before updating gamma)
117	virtual ESwapMethod getSwapMethod() { return mSwapMethod; }
118	virtual void processMiscNativeEvents();
119	virtual void gatherInput() = 0;
120	virtual void delayInputProcessing() = 0;
121	virtual void swapBuffers() = 0;
122	virtual void bringToFront() = 0;
123	virtual void focusClient() { };		// this may not have meaning or be required on other platforms, therefore, it's not abstract
124	
125	// handy coordinate space conversion routines
126	// NB: screen to window and vice verse won't work on width/height coordinate pairs,
127	// as the conversion must take into account left AND right border widths, etc.
128	virtual BOOL convertCoords( LLCoordScreen from, LLCoordWindow *to) = 0;
129	virtual BOOL convertCoords( LLCoordWindow from, LLCoordScreen *to) = 0;
130	virtual BOOL convertCoords( LLCoordWindow from, LLCoordGL *to) = 0;
131	virtual BOOL convertCoords( LLCoordGL from, LLCoordWindow *to) = 0;
132	virtual BOOL convertCoords( LLCoordScreen from, LLCoordGL *to) = 0;
133	virtual BOOL convertCoords( LLCoordGL from, LLCoordScreen *to) = 0;
134
135	// query supported resolutions
136	virtual LLWindowResolution* getSupportedResolutions(S32 &num_resolutions) = 0;
137	virtual F32	getNativeAspectRatio() = 0;
138	virtual F32 getPixelAspectRatio() = 0;
139	virtual void setNativeAspectRatio(F32 aspect) = 0;
140	
141	virtual void beforeDialog() {};	// prepare to put up an OS dialog (if special measures are required, such as in fullscreen mode)
142	virtual void afterDialog() {};	// undo whatever was done in beforeDialog()
143
144	// opens system default color picker, modally
145	// Returns TRUE if valid color selected
146	virtual BOOL dialogColorPicker(F32 *r, F32 *g, F32 *b);
147
148// return a platform-specific window reference (HWND on Windows, WindowRef on the Mac, Gtk window on Linux)
149	virtual void *getPlatformWindow() = 0;
150
151// return the platform-specific window reference we use to initialize llmozlib (HWND on Windows, WindowRef on the Mac, Gtk window on Linux)
152	virtual void *getMediaWindow();
153	
154	// control platform's Language Text Input mechanisms.
155	virtual void allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) {}
156	virtual void setLanguageTextInput( const LLCoordGL & pos ) {};
157	virtual void updateLanguageTextInputArea() {}
158	virtual void interruptLanguageTextInput() {}
159	virtual void spawnWebBrowser(const std::string& escaped_url, bool async) {};
160
161	static std::vector<std::string> getDynamicFallbackFontList();
162	
163	// Provide native key event data
164	virtual LLSD getNativeKeyData() { return LLSD::emptyMap(); }
165
166protected:
167	LLWindow(LLWindowCallbacks* callbacks, BOOL fullscreen, U32 flags);
168	virtual ~LLWindow();
169	// Defaults to true
170	virtual BOOL isValid();
171	// Defaults to true
172	virtual BOOL canDelete();
173
174	virtual BOOL setSizeImpl(LLCoordScreen size) = 0;
175
176protected:
177	LLWindowCallbacks*	mCallbacks;
178
179	BOOL		mPostQuit;		// should this window post a quit message when destroyed?
180	BOOL		mFullscreen;
181	S32			mFullscreenWidth;
182	S32			mFullscreenHeight;
183	S32			mFullscreenBits;
184	S32			mFullscreenRefresh;
185	LLWindowResolution* mSupportedResolutions;
186	S32			mNumSupportedResolutions;
187	ECursorType	mCurrentCursor;
188	ECursorType	mNextCursor;
189	BOOL		mCursorHidden;
190	S32			mBusyCount;	// how deep is the "cursor busy" stack?
191	BOOL		mIsMouseClipping;  // Is this window currently clipping the mouse
192	ESwapMethod mSwapMethod;
193	BOOL		mHideCursorPermanent;
194	U32			mFlags;
195	U16			mHighSurrogate;
196	S32			mMinWindowWidth;
197	S32			mMinWindowHeight;
198
199 	// Handle a UTF-16 encoding unit received from keyboard.
200 	// Converting the series of UTF-16 encoding units to UTF-32 data,
201 	// this method passes the resulting UTF-32 data to mCallback's
202 	// handleUnicodeChar.  The mask should be that to be passed to the
203 	// callback.  This method uses mHighSurrogate as a dedicated work
204 	// variable.
205	void handleUnicodeUTF16(U16 utf16, MASK mask);
206
207	friend class LLWindowManager;
208};
209
210
211// LLSplashScreen
212// A simple, OS-specific splash screen that we can display
213// while initializing the application and before creating a GL
214// window
215
216
217class LLSplashScreen
218{
219public:
220	LLSplashScreen() { };
221	virtual ~LLSplashScreen() { };
222
223
224	// Call to display the window.
225	static LLSplashScreen * create();
226	static void show();
227	static void hide();
228	static void update(const std::string& string);
229
230	static bool isVisible();
231protected:
232	// These are overridden by the platform implementation
233	virtual void showImpl() = 0;
234	virtual void updateImpl(const std::string& string) = 0;
235	virtual void hideImpl() = 0;
236
237	static BOOL sVisible;
238
239};
240
241// Platform-neutral for accessing the platform specific message box
242S32 OSMessageBox(const std::string& text, const std::string& caption, U32 type);
243const U32 OSMB_OK = 0;
244const U32 OSMB_OKCANCEL = 1;
245const U32 OSMB_YESNO = 2;
246
247const S32 OSBTN_YES = 0;
248const S32 OSBTN_NO = 1;
249const S32 OSBTN_OK = 2;
250const S32 OSBTN_CANCEL = 3;
251
252//
253// LLWindowManager
254// Manages window creation and error checking
255
256class LLWindowManager
257{
258public:
259	static LLWindow *createWindow(
260		LLWindowCallbacks* callbacks,
261		const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height,
262		U32 flags = 0,
263		BOOL fullscreen = FALSE,
264		BOOL clearBg = FALSE,
265		BOOL disable_vsync = TRUE,
266		BOOL use_gl = TRUE,
267		BOOL ignore_pixel_depth = FALSE,
268		U32 fsaa_samples = 0);
269	static BOOL destroyWindow(LLWindow* window);
270	static BOOL isWindowValid(LLWindow *window);
271};
272
273//
274// helper funcs
275//
276extern BOOL gDebugWindowProc;
277
278// Protocols, like "http" and "https" we support in URLs
279extern const S32 gURLProtocolWhitelistCount;
280extern const std::string gURLProtocolWhitelist[];
281extern const std::string gURLProtocolWhitelistHandler[];
282
283void simpleEscapeString ( std::string& stringIn  );
284
285#endif // _LL_window_h_