PageRenderTime 177ms CodeModel.GetById 129ms app.highlight 43ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llwindow/llwindowmacosx.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 243 lines | 161 code | 42 blank | 40 comment | 0 complexity | 01adaa276e45bf4cc8ab670c1b396917 MD5 | raw file
  1/** 
  2 * @file llwindowmacosx.h
  3 * @brief Mac implementation of LLWindow 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_LLWINDOWMACOSX_H
 28#define LL_LLWINDOWMACOSX_H
 29
 30#include "llwindow.h"
 31#include "llwindowcallbacks.h"
 32
 33#include "lltimer.h"
 34
 35#include <Carbon/Carbon.h>
 36#include <AGL/agl.h>
 37
 38// AssertMacros.h does bad things.
 39#undef verify
 40#undef check
 41#undef require
 42
 43
 44class LLWindowMacOSX : public LLWindow
 45{
 46public:
 47	/*virtual*/ void show();
 48	/*virtual*/ void hide();
 49	/*virtual*/ void close();
 50	/*virtual*/ BOOL getVisible();
 51	/*virtual*/ BOOL getMinimized();
 52	/*virtual*/ BOOL getMaximized();
 53	/*virtual*/ BOOL maximize();
 54	/*virtual*/ void minimize();
 55	/*virtual*/ void restore();
 56	/*virtual*/ BOOL getFullscreen();
 57	/*virtual*/ BOOL getPosition(LLCoordScreen *position);
 58	/*virtual*/ BOOL getSize(LLCoordScreen *size);
 59	/*virtual*/ BOOL getSize(LLCoordWindow *size);
 60	/*virtual*/ BOOL setPosition(LLCoordScreen position);
 61	/*virtual*/ BOOL setSizeImpl(LLCoordScreen size);
 62	/*virtual*/ BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp = NULL);
 63	/*virtual*/ BOOL setCursorPosition(LLCoordWindow position);
 64	/*virtual*/ BOOL getCursorPosition(LLCoordWindow *position);
 65	/*virtual*/ void showCursor();
 66	/*virtual*/ void hideCursor();
 67	/*virtual*/ void showCursorFromMouseMove();
 68	/*virtual*/ void hideCursorUntilMouseMove();
 69	/*virtual*/ BOOL isCursorHidden();
 70	/*virtual*/ void updateCursor();
 71	/*virtual*/ ECursorType getCursor() const;
 72	/*virtual*/ void captureMouse();
 73	/*virtual*/ void releaseMouse();
 74	/*virtual*/ void setMouseClipping( BOOL b );
 75	/*virtual*/ BOOL isClipboardTextAvailable();
 76	/*virtual*/ BOOL pasteTextFromClipboard(LLWString &dst);
 77	/*virtual*/ BOOL copyTextToClipboard(const LLWString & src);
 78	/*virtual*/ void flashIcon(F32 seconds);
 79	/*virtual*/ F32 getGamma();
 80	/*virtual*/ BOOL setGamma(const F32 gamma); // Set the gamma
 81	/*virtual*/ U32 getFSAASamples();
 82	/*virtual*/ void setFSAASamples(const U32 fsaa_samples);
 83	/*virtual*/ BOOL restoreGamma();			// Restore original gamma table (before updating gamma)
 84	/*virtual*/ ESwapMethod getSwapMethod() { return mSwapMethod; }
 85	/*virtual*/ void gatherInput();
 86	/*virtual*/ void delayInputProcessing() {};
 87	/*virtual*/ void swapBuffers();
 88
 89	// handy coordinate space conversion routines
 90	/*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordWindow *to);
 91	/*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordScreen *to);
 92	/*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordGL *to);
 93	/*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordWindow *to);
 94	/*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordGL *to);
 95	/*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordScreen *to);
 96
 97	/*virtual*/ LLWindowResolution* getSupportedResolutions(S32 &num_resolutions);
 98	/*virtual*/ F32	getNativeAspectRatio();
 99	/*virtual*/ F32 getPixelAspectRatio();
100	/*virtual*/ void setNativeAspectRatio(F32 ratio) { mOverrideAspectRatio = ratio; }
101
102	/*virtual*/ void beforeDialog();
103	/*virtual*/ void afterDialog();
104
105	/*virtual*/ BOOL dialogColorPicker(F32 *r, F32 *g, F32 *b);
106
107	/*virtual*/ void *getPlatformWindow();
108	/*virtual*/ void *getMediaWindow();
109	/*virtual*/ void bringToFront() {};
110	
111	/*virtual*/ void allowLanguageTextInput(LLPreeditor *preeditor, BOOL b);
112	/*virtual*/ void interruptLanguageTextInput();
113	/*virtual*/ void spawnWebBrowser(const std::string& escaped_url, bool async);
114
115	static std::vector<std::string> getDynamicFallbackFontList();
116
117	// Provide native key event data
118	/*virtual*/ LLSD getNativeKeyData();
119
120
121protected:
122	LLWindowMacOSX(LLWindowCallbacks* callbacks,
123		const std::string& title, const std::string& name, int x, int y, int width, int height, U32 flags,
124		BOOL fullscreen, BOOL clearBg, BOOL disable_vsync, BOOL use_gl,
125		BOOL ignore_pixel_depth,
126		U32 fsaa_samples);
127	~LLWindowMacOSX();
128
129	void	initCursors();
130	BOOL	isValid();
131	void	moveWindow(const LLCoordScreen& position,const LLCoordScreen& size);
132
133
134	// Changes display resolution. Returns true if successful
135	BOOL	setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh);
136
137	// Go back to last fullscreen display resolution.
138	BOOL	setFullscreenResolution();
139
140	// Restore the display resolution to its value before we ran the app.
141	BOOL	resetDisplayResolution();
142
143	BOOL	shouldPostQuit() { return mPostQuit; }
144
145
146protected:
147	//
148	// Platform specific methods
149	//
150
151	// create or re-create the GL context/window.  Called from the constructor and switchContext().
152	BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync);
153	void destroyContext();
154	void setupFailure(const std::string& text, const std::string& caption, U32 type);
155	static pascal OSStatus staticEventHandler (EventHandlerCallRef myHandler, EventRef event, void* userData);
156	static pascal Boolean staticMoveEventComparator( EventRef event, void* data);
157	OSStatus eventHandler (EventHandlerCallRef myHandler, EventRef event);
158	void adjustCursorDecouple(bool warpingMouse = false);
159	void stopDockTileBounce();
160	static MASK modifiersToMask(SInt16 modifiers);
161	
162#if LL_OS_DRAGDROP_ENABLED
163	static OSErr dragTrackingHandler(DragTrackingMessage message, WindowRef theWindow,
164									 void * handlerRefCon, DragRef theDrag);
165	static OSErr dragReceiveHandler(WindowRef theWindow, void * handlerRefCon,	DragRef theDrag);
166	OSErr handleDragNDrop(DragRef theDrag, LLWindowCallbacks::DragNDropAction action);
167#endif // LL_OS_DRAGDROP_ENABLED
168	
169	//
170	// Platform specific variables
171	//
172	WindowRef		mWindow;
173	AGLContext		mContext;
174	AGLPixelFormat	mPixelFormat;
175	CGDirectDisplayID	mDisplay;
176	CFDictionaryRef		mOldDisplayMode;
177	EventLoopTimerRef	mTimer;
178	EventHandlerUPP 	mEventHandlerUPP;
179	EventHandlerRef		mGlobalHandlerRef;
180	EventHandlerRef		mWindowHandlerRef;
181	EventComparatorUPP  mMoveEventCampartorUPP;
182	
183	Rect		mOldMouseClip;  // Screen rect to which the mouse cursor was globally constrained before we changed it in clipMouse()
184	Rect		mPreviousWindowRect;  // Save previous window for un-maximize event
185	Str255 		mWindowTitle;
186	double		mOriginalAspectRatio;
187	BOOL		mSimulatedRightClick;
188	UInt32		mLastModifiers;
189	BOOL		mHandsOffEvents;	// When true, temporarially disable CarbonEvent processing.
190	// Used to allow event processing when putting up dialogs in fullscreen mode.
191	BOOL		mCursorDecoupled;
192	S32			mCursorLastEventDeltaX;
193	S32			mCursorLastEventDeltaY;
194	BOOL		mCursorIgnoreNextDelta;
195	BOOL		mNeedsResize;		// Constructor figured out the window is too big, it needs a resize.
196	LLCoordScreen   mNeedsResizeSize;
197	F32			mOverrideAspectRatio;
198	BOOL		mMaximized;
199	BOOL		mMinimized;
200	U32			mFSAASamples;
201	BOOL		mForceRebuild;
202	
203	S32			mDragOverrideCursor;
204	
205	F32			mBounceTime;
206	NMRec		mBounceRec;
207	LLTimer		mBounceTimer;
208
209	// Input method management through Text Service Manager.
210	TSMDocumentID	mTSMDocument;
211	BOOL		mLanguageTextInputAllowed;
212	ScriptCode	mTSMScriptCode;
213	LangCode	mTSMLangCode;
214	LLPreeditor*	mPreeditor;
215	
216	static BOOL	sUseMultGL;
217
218	friend class LLWindowManager;
219	static WindowRef sMediaWindow;
220	EventRef 	mRawKeyEvent;
221
222};
223
224
225class LLSplashScreenMacOSX : public LLSplashScreen
226{
227public:
228	LLSplashScreenMacOSX();
229	virtual ~LLSplashScreenMacOSX();
230
231	/*virtual*/ void showImpl();
232	/*virtual*/ void updateImpl(const std::string& mesg);
233	/*virtual*/ void hideImpl();
234
235private:
236	WindowRef   mWindow;
237};
238
239S32 OSMessageBoxMacOSX(const std::string& text, const std::string& caption, U32 type);
240
241void load_url_external(const char* url);
242
243#endif //LL_LLWINDOWMACOSX_H