llwindow.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLWINDOW_H
00033 #define LL_LLWINDOW_H
00034 
00035 #include <sys/stat.h>
00036 
00037 #include "llrect.h"
00038 #include "llcoord.h"
00039 #include "llstring.h"
00040 
00041 
00042 enum ECursorType {
00043         UI_CURSOR_ARROW,
00044         UI_CURSOR_WAIT,
00045         UI_CURSOR_HAND,
00046         UI_CURSOR_IBEAM,
00047         UI_CURSOR_CROSS,
00048         UI_CURSOR_SIZENWSE,
00049         UI_CURSOR_SIZENESW,
00050         UI_CURSOR_SIZEWE,
00051         UI_CURSOR_SIZENS,
00052         UI_CURSOR_NO,
00053         UI_CURSOR_WORKING,
00054         UI_CURSOR_TOOLGRAB,
00055         UI_CURSOR_TOOLLAND,
00056         UI_CURSOR_TOOLFOCUS,
00057         UI_CURSOR_TOOLCREATE,
00058         UI_CURSOR_ARROWDRAG,
00059         UI_CURSOR_ARROWCOPY,    // drag with copy
00060         UI_CURSOR_ARROWDRAGMULTI,
00061         UI_CURSOR_ARROWCOPYMULTI,       // drag with copy
00062         UI_CURSOR_NOLOCKED,
00063         UI_CURSOR_ARROWLOCKED,
00064         UI_CURSOR_GRABLOCKED,
00065         UI_CURSOR_TOOLTRANSLATE,
00066         UI_CURSOR_TOOLROTATE,
00067         UI_CURSOR_TOOLSCALE,
00068         UI_CURSOR_TOOLCAMERA,
00069         UI_CURSOR_TOOLPAN,
00070         UI_CURSOR_TOOLZOOMIN,
00071         UI_CURSOR_TOOLPICKOBJECT3,
00072         UI_CURSOR_TOOLSIT,
00073         UI_CURSOR_TOOLBUY,
00074         UI_CURSOR_TOOLPAY,
00075         UI_CURSOR_TOOLOPEN,
00076         UI_CURSOR_PIPETTE,
00077         UI_CURSOR_COUNT                 // Number of elements in this enum (NOT a cursor)
00078 };
00079 
00080 enum EStereoMode 
00081 { 
00082         STEREO_MODE_NONE = 0, 
00083         STEREO_MODE_ANAGLYPH = 1, 
00084         STEREO_MODE_ACTIVE = 2 
00085 };
00086 
00087 
00088 
00089 class LLSplashScreen;
00090 
00091 class LLWindow;
00092 
00093 class LLWindowCallbacks
00094 {
00095 public:
00096         virtual ~LLWindowCallbacks() {}
00097         virtual BOOL handleTranslatedKeyDown(KEY key,  MASK mask, BOOL repeated);
00098         virtual BOOL handleTranslatedKeyUp(KEY key,  MASK mask);
00099         virtual void handleScanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key_level);
00100         virtual BOOL handleUnicodeChar(llwchar uni_char, MASK mask);
00101 
00102         virtual BOOL handleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
00103         virtual BOOL handleMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
00104         virtual void handleMouseLeave(LLWindow *window);
00105         // return TRUE to allow window to close, which will then cause handleQuit to be called
00106         virtual BOOL handleCloseRequest(LLWindow *window);
00107         // window is about to be destroyed, clean up your business
00108         virtual void handleQuit(LLWindow *window);
00109         virtual BOOL handleRightMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
00110         virtual BOOL handleRightMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
00111         virtual BOOL handleMiddleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
00112         virtual BOOL handleMiddleMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
00113         virtual BOOL handleActivate(LLWindow *window, BOOL activated);
00114         virtual void handleMouseMove(LLWindow *window,  LLCoordGL pos, MASK mask);
00115         virtual void handleScrollWheel(LLWindow *window,  S32 clicks);
00116         virtual void handleResize(LLWindow *window,  S32 width,  S32 height);
00117         virtual void handleFocus(LLWindow *window);
00118         virtual void handleFocusLost(LLWindow *window);
00119         virtual void handleMenuSelect(LLWindow *window,  S32 menu_item);
00120         virtual BOOL handlePaint(LLWindow *window,  S32 x,  S32 y,  S32 width,  S32 height);
00121         virtual BOOL handleDoubleClick(LLWindow *window,  LLCoordGL pos, MASK mask);                    // double-click of left mouse button
00122         virtual void handleWindowBlock(LLWindow *window);                                                       // window is taking over CPU for a while
00123         virtual void handleWindowUnblock(LLWindow *window);                                                     // window coming back after taking over CPU for a while
00124         virtual void handleDataCopy(LLWindow *window, S32 data_type, void *data);
00125 };
00126 
00127 // Refer to llwindow_test in test/common/llwindow for usage example
00128 
00129 class LLWindow
00130 {
00131 public:
00132         struct LLWindowResolution
00133         {
00134                 S32 mWidth;
00135                 S32 mHeight;
00136         };
00137         enum ESwapMethod
00138         {
00139                 SWAP_METHOD_UNDEFINED,
00140                 SWAP_METHOD_EXCHANGE,
00141                 SWAP_METHOD_COPY
00142         };
00143         enum EFlags
00144         {
00145                 // currently unused
00146         };
00147 
00148 public:
00149         virtual void show() = 0;
00150         virtual void hide() = 0;
00151         virtual void close() = 0;
00152         virtual BOOL getVisible() = 0;
00153         virtual BOOL getMinimized() = 0;
00154         virtual BOOL getMaximized() = 0;
00155         virtual BOOL maximize() = 0;
00156         BOOL getFullscreen()    { return mFullscreen; };
00157         virtual BOOL getPosition(LLCoordScreen *position) = 0;
00158         virtual BOOL getSize(LLCoordScreen *size) = 0;
00159         virtual BOOL getSize(LLCoordWindow *size) = 0;
00160         virtual BOOL setPosition(LLCoordScreen position) = 0;
00161         virtual BOOL setSize(LLCoordScreen size) = 0;
00162         virtual BOOL switchContext(BOOL fullscreen, LLCoordScreen size, BOOL disable_vsync) = 0;
00163         virtual BOOL setCursorPosition(LLCoordWindow position) = 0;
00164         virtual BOOL getCursorPosition(LLCoordWindow *position) = 0;
00165         virtual void showCursor() = 0;
00166         virtual void hideCursor() = 0;
00167         virtual BOOL isCursorHidden() = 0;
00168         virtual void showCursorFromMouseMove() = 0;
00169         virtual void hideCursorUntilMouseMove() = 0;
00170 
00171         // These two functions create a way to make a busy cursor instead
00172         // of an arrow when someone's busy doing something. Draw an
00173         // arrow/hour if busycount > 0.
00174         virtual void incBusyCount();
00175         virtual void decBusyCount();
00176         virtual void resetBusyCount() { mBusyCount = 0; }
00177         virtual S32 getBusyCount() const { return mBusyCount; }
00178 
00179         // Sets cursor, may set to arrow+hourglass
00180         virtual void setCursor(ECursorType cursor) = 0;
00181         virtual ECursorType getCursor() const { return mCurrentCursor; }
00182 
00183         virtual void captureMouse() = 0;
00184         virtual void releaseMouse() = 0;
00185         virtual void setMouseClipping( BOOL b ) = 0;
00186         virtual BOOL isClipboardTextAvailable() = 0;
00187         virtual BOOL pasteTextFromClipboard(LLWString &dst) = 0;
00188         virtual BOOL copyTextToClipboard(const LLWString &src) = 0;
00189         virtual void flashIcon(F32 seconds) = 0;
00190         virtual F32 getGamma() = 0;
00191         virtual BOOL setGamma(const F32 gamma) = 0; // Set the gamma
00192         virtual BOOL restoreGamma() = 0;                        // Restore original gamma table (before updating gamma)
00193         virtual ESwapMethod getSwapMethod() { return mSwapMethod; }
00194         virtual void gatherInput() = 0;
00195         virtual void delayInputProcessing() = 0;
00196         virtual void swapBuffers() = 0;
00197         virtual void bringToFront() = 0;
00198         virtual void focusClient() { };         // this may not have meaning or be required on other platforms, therefore, it's not abstract
00199         
00200         virtual S32 stat( const char* file_name, struct stat* stat_info ) = 0;
00201         virtual BOOL sendEmail(const char* address,const char* subject,const char* body_text, const char* attachment=NULL, const char* attachment_displayed_name=NULL ) = 0;
00202 
00203 
00204         // handy coordinate space conversion routines
00205         // NB: screen to window and vice verse won't work on width/height coordinate pairs,
00206         // as the conversion must take into account left AND right border widths, etc.
00207         virtual BOOL convertCoords( LLCoordScreen from, LLCoordWindow *to) = 0;
00208         virtual BOOL convertCoords( LLCoordWindow from, LLCoordScreen *to) = 0;
00209         virtual BOOL convertCoords( LLCoordWindow from, LLCoordGL *to) = 0;
00210         virtual BOOL convertCoords( LLCoordGL from, LLCoordWindow *to) = 0;
00211         virtual BOOL convertCoords( LLCoordScreen from, LLCoordGL *to) = 0;
00212         virtual BOOL convertCoords( LLCoordGL from, LLCoordScreen *to) = 0;
00213 
00214         // query supported resolutions
00215         virtual LLWindowResolution* getSupportedResolutions(S32 &num_resolutions) = 0;
00216         virtual F32     getNativeAspectRatio() = 0;
00217         virtual F32 getPixelAspectRatio() = 0;
00218         virtual void setNativeAspectRatio(F32 aspect) = 0;
00219         
00220         F32 getJoystickAxis(U32 axis);
00221         U8 getJoystickButton(U32 button);
00222 
00223         void setCallbacks(LLWindowCallbacks *callbacks);
00224 
00225         virtual void beforeDialog() {}; // prepare to put up an OS dialog (if special measures are required, such as in fullscreen mode)
00226         virtual void afterDialog() {};  // undo whatever was done in beforeDialog()
00227 
00228 // opens system default color picker
00229         virtual BOOL dialog_color_picker (F32 *r, F32 *g, F32 *b) { return FALSE; };
00230 
00231 // return a platform-specific window reference (HWND on Windows, WindowRef on the Mac)
00232         virtual void *getPlatformWindow() = 0;
00233         
00234         // control platform's Language Text Input mechanisms.
00235         virtual void allowLanguageTextInput( BOOL b ) {};
00236         virtual void setLanguageTextInput( const LLCoordGL & pos ) {};
00237         virtual void setStereoMode( S32 mode ) { mStereoMode = mode; }
00238         virtual S32 getStereoMode() const { return mStereoMode; }
00239 
00240 protected:
00241         LLWindow(BOOL fullscreen, U32 flags);
00242         virtual ~LLWindow() {}
00243         virtual BOOL isValid() {return TRUE;}
00244         virtual BOOL canDelete() {return TRUE;}
00245 protected:
00246         static LLWindowCallbacks        sDefaultCallbacks;
00247 
00248 protected:
00249         LLWindowCallbacks*      mCallbacks;
00250 
00251         BOOL            mPostQuit;              // should this window post a quit message when destroyed?
00252         BOOL            mFullscreen;
00253         S32                     mFullscreenWidth;
00254         S32                     mFullscreenHeight;
00255         S32                     mFullscreenBits;
00256         S32                     mFullscreenRefresh;
00257         LLWindowResolution* mSupportedResolutions;
00258         S32                     mNumSupportedResolutions;
00259         ECursorType     mCurrentCursor;
00260         BOOL            mCursorHidden;
00261         S32                     mBusyCount;     // how deep is the "cursor busy" stack?
00262         BOOL            mIsMouseClipping;  // Is this window currently clipping the mouse
00263         ESwapMethod mSwapMethod;
00264         BOOL            mHideCursorPermanent;
00265         U32                     mFlags;
00266         F32                     mJoyAxis[6]; 
00267         U8                      mJoyButtonState[16];
00268         U16                     mHighSurrogate;
00269     S32                 mStereoMode;
00270 
00271         // Handle a UTF-16 encoding unit received from keyboard.
00272         // Converting the series of UTF-16 encoding units to UTF-32 data,
00273         // this method passes the resulting UTF-32 data to mCallback's
00274         // handleUnicodeChar.  The mask should be that to be passed to the
00275         // callback.  This method uses mHighSurrogate as a dedicated work
00276         // variable.
00277         void handleUnicodeUTF16(U16 utf16, MASK mask);
00278 
00279         friend class LLWindowManager;
00280 };
00281 
00282 
00283 // LLSplashScreen
00284 // A simple, OS-specific splash screen that we can display
00285 // while initializing the application and before creating a GL
00286 // window
00287 
00288 
00289 class LLSplashScreen
00290 {
00291 public:
00292         LLSplashScreen() { };
00293         virtual ~LLSplashScreen() { };
00294 
00295 
00296         // Call to display the window.
00297         static LLSplashScreen * create();
00298         static void show();
00299         static void hide();
00300         static void update(const char* string);
00301 
00302         static bool isVisible();
00303 protected:
00304         // These are overridden by the platform implementation
00305         virtual void showImpl() = 0;
00306         virtual void updateImpl(const char* string) = 0;
00307         virtual void hideImpl() = 0;
00308 
00309         static BOOL sVisible;
00310 
00311 };
00312 
00313 // Platform-neutral for accessing the platform specific message box
00314 S32 OSMessageBox(const char* text, const char* caption, U32 type);
00315 const U32 OSMB_OK = 0;
00316 const U32 OSMB_OKCANCEL = 1;
00317 const U32 OSMB_YESNO = 2;
00318 
00319 const S32 OSBTN_YES = 0;
00320 const S32 OSBTN_NO = 1;
00321 const S32 OSBTN_OK = 2;
00322 const S32 OSBTN_CANCEL = 3;
00323 
00324 //
00325 // LLWindowManager
00326 // Manages window creation and error checking
00327 
00328 class LLWindowManager
00329 {
00330 public:
00331         static LLWindow* createWindow(
00332                 char *title,
00333                 char *name,
00334                 LLCoordScreen upper_left = LLCoordScreen(10, 10),
00335                 LLCoordScreen size = LLCoordScreen(320, 240),
00336                 U32 flags = 0,
00337                 BOOL fullscreen = FALSE,
00338                 BOOL clearBg = FALSE,
00339                 BOOL disable_vsync = TRUE,
00340                 BOOL use_gl = TRUE,
00341                 BOOL ignore_pixel_depth = FALSE,
00342                 S32 stereo_mode = 0);
00343         static LLWindow *createWindow(
00344                 char* title, char* name, S32 x, S32 y, S32 width, S32 height,
00345                 U32 flags = 0,
00346                 BOOL fullscreen = FALSE,
00347                 BOOL clearBg = FALSE,
00348                 BOOL disable_vsync = TRUE,
00349                 BOOL use_gl = TRUE,
00350                 BOOL ignore_pixel_depth = FALSE,
00351                 S32 stereo_mode = 0);
00352         static BOOL destroyWindow(LLWindow* window);
00353         static BOOL isWindowValid(LLWindow *window);
00354 };
00355 
00356 //
00357 // helper funcs
00358 //
00359 extern BOOL gDebugWindowProc;
00360 
00361 // Protocols, like "http" and "https" we support in URLs
00362 extern const S32 gURLProtocolWhitelistCount;
00363 extern const char* gURLProtocolWhitelist[];
00364 extern const char* gURLProtocolWhitelistHandler[];
00365 
00366 // Loads a URL with the user's default browser
00367 void spawn_web_browser(const char* escaped_url);
00368 
00369 // Opens a file with ShellExecute. Security risk!
00370 void shell_open(const char* file_path);
00371 
00372 void simpleEscapeString ( std::string& stringIn  );
00373 
00374 #endif // _LL_window_h_

Generated on Thu Jul 1 06:09:46 2010 for Second Life Viewer by  doxygen 1.4.7