00001 //--------------------------------------------------------------------------- 00002 /// \file CATWindow.h 00003 /// \brief Basic windowing class 00004 /// \ingroup CATGUI 00005 /// 00006 /// Copyright (c) 2003-2008 by Michael Ellison. 00007 /// See COPYING.txt for the \ref gaslicense License (MIT License). 00008 /// 00009 // $Author: mikeellison $ 00010 // $Date: 2008-01-29 07:01:23 -0600 (Tue, 29 Jan 2008) $ 00011 // $Revision: $ 00012 // $NoKeywords: $ 00013 // 00014 //--------------------------------------------------------------------------- 00015 #ifndef _GGWindow_H_ 00016 #define _GGWindow_H_ 00017 00018 #include "CATGUIInternal.h" 00019 00020 #include <time.h> 00021 #include "CATImage.h" 00022 #include "CATGuiObj.h" 00023 #include "CATEvent.h" 00024 #include "CATCursor.h" 00025 #include "CATKeystroke.h" 00026 #include "CATStack.h" 00027 #include "CATQueue.h" 00028 #include "CATMutex.h" 00029 #include "CATSignal.h" 00030 #include "CATApp.h" 00031 #include "CATKnob.h" 00032 00033 class CATWindow; 00034 class CATSkin; 00035 class CATControl; 00036 class CATLabel; 00037 class CATControlWnd; 00038 class CATMenu; 00039 00040 #ifdef CAT_CONFIG_WIN32 00041 #define CATWM_START_MESSAGE WM_USER 00042 #else 00043 #define CATWM_START_MESSAGE 0 // unknown? 00044 #endif 00045 00046 // time before tool tip pops up in ms 00047 const CATUInt32 kTOOLTIPHOVERTIME = 1000; 00048 00049 /// Information about a control and its siblings 00050 struct CATFINDCONTROLSTRUCT 00051 { 00052 CATString Name; 00053 CATString TypeName; 00054 CATControl* FirstControl; 00055 CATControl* FoundControl; 00056 CATControl* PrevControl; 00057 CATControl* NextControl; 00058 CATControl* CurControl; 00059 CATControl* TargetControl; 00060 }; 00061 00062 00063 enum CATWM_MESSAGES 00064 { 00065 /// Messages for Internal (CATWindow) usage. 00066 CATWM_INTERNAL = CATWM_START_MESSAGE + 100, 00067 00068 /// Kill window is used to terminate windows internally... 00069 CATWM_KILLWINDOW, 00070 00071 /// Timer during mouse tracking that allows filter-only updates. 00072 /// Frequency is determined by kMOUSEFILTERFREQ 00073 CATWM_MOUSETIMER, 00074 00075 // User update timer 00076 CATWM_UPDATETIMER, 00077 00078 /// Messages for Framework usage 00079 CATWM_FRAMEWORK = CATWM_START_MESSAGE + 250, 00080 CATWM_EVENTPOSTED, 00081 CATWM_ENDWAIT, 00082 CATWM_SETWAITLABEL, 00083 CATWM_SETWAITPROGRESS, 00084 00085 /// Messages for Application-specific usage 00086 CATWM_APPLICATION = CATWM_START_MESSAGE + 500, 00087 //------------------------------- 00088 CATWM_LAST 00089 }; 00090 00091 /// kMOUSEFILTERFREQ is the milliseconds between updates while the mouse is 00092 /// being tracked if mouse is held still. This allows us to filter knobs 00093 /// and yet eventually get to the right place if the user holds the mouse still. 00094 const CATUInt32 kMOUSEFILTERFREQ = 50; 00095 00096 /// \class CATWindow CATWindow.h 00097 /// \brief Basic windowing class 00098 /// 00099 class CATWindow : public CATGuiObj 00100 { 00101 public: 00102 /// CATWindow() constructor - based off CATXMLObject 00103 CATWindow( const CATString& element, 00104 const CATString& rootDir); 00105 00106 /// CATWindow destructor 00107 virtual ~CATWindow(); 00108 00109 /// Show() shows the window. Will create the window if it does not 00110 /// already exist. 00111 virtual void Show ( CATWindow* parent = 0, 00112 CATPOINT* origin = 0); 00113 00114 /// Show as a child with external hwnd.... 00115 virtual void Show ( CATWND parentWnd); 00116 00117 /// Hide() hides (or destroys) the window. 00118 /// 00119 /// It does not destroy the base CATWindow object - just the operating 00120 /// system specific Window itself. 00121 /// 00122 /// \param destroy - if true, destroys the OS's window. Otherwise, 00123 /// simply hids the window. 00124 virtual void Hide ( bool destroy = false ); 00125 00126 /// IsVisible() returns true if the window is currently visible. 00127 /// \sa Show(), Hide() 00128 virtual bool IsVisible ( const CATGuiObj* child = 0) const; 00129 00130 /// IsPrimary() returns true if the window is the 00131 /// primary application window. 00132 /// 00133 /// This is mainly used to tell if the program should 00134 /// exit when the App received notification that a window 00135 /// was destroyed. If the window was the primary window, 00136 /// then the app should generally exit. 00137 /// 00138 /// \return bool - true if the window is the Primary window. 00139 virtual bool IsPrimary ( ); 00140 00141 virtual bool IsOverlapped(); 00142 00143 virtual void DisplayMessage( const CATString& msg); 00144 virtual void DisplayError( const CATResult& result); 00145 virtual CATResult DisplayPrompt( const CATString& msg, 00146 CATApp::CATPROMPTTYPE prompt); 00147 00148 /// FindControlAndVerify() finds a control object by name, then verifies 00149 /// that it is of the appropriate type before returning it. 00150 /// 00151 /// It will also return the index of the control in the window's child 00152 /// list if desired. 00153 /// 00154 /// If the type doesn't match then NULL is returned. 00155 /// 00156 /// \param controlName - name of the control to find. 00157 /// \param controlName - name of the control type to check against. 00158 /// \param index - ptr to CATUInt32 to receive index, or 0 00159 /// \return CATControl* - ptr to matching control, or 0 if none is found. 00160 CATControl* FindControlAndVerify( const CATString& controlName, 00161 const CATString& typeName, 00162 CATUInt32* index = 0); 00163 00164 CATResult EnableObject( const CATString& controlName, 00165 bool enabled); 00166 00167 /// MarkDirty() marks a section of the window as dirty and invalidates 00168 /// it / notifies the OS that the window needs to be repainted. 00169 /// 00170 /// \param dirtyRect - specifies the area of the window that is 00171 /// dirty. If null, the entire window is marked as dirty. 00172 virtual void MarkDirty ( CATRect* dirtyRect = 0, 00173 bool force = false); 00174 00175 /// Update() forces an immediate paint of any dirty regions 00176 /// in the window. 00177 virtual void Update(); 00178 00179 /// Draw() is called when the window should paint itself. 00180 /// 00181 /// \param background - ptr to image to draw into 00182 /// \param dirtyRect - part of window to redraw. 00183 virtual void Draw ( CATImage* background, 00184 const CATRect& dirtyRect); 00185 00186 /// PostDraw() is used to paint controls that do not 00187 /// support, or are not easy to do with, the PNG architecture. 00188 /// These will mainly be platform specific controls. 00189 /// 00190 /// Post-Drawn controls are drawn after the normal 00191 /// image-based controls, and are layered on top. They are, 00192 /// however, drawn on a back buffer so they shouldn't flicker. 00193 /// 00194 /// \param drawContext - OS specific drawing context. 00195 /// \param dirtyRect - area of window to paint 00196 virtual void PostDraw ( CATDRAWCONTEXT drawContext, 00197 const CATRect& dirtyRect); 00198 00199 /// PostDrawText() draws text from a post-drawn control. 00200 virtual void PostDrawText( const CATString& text, 00201 CATDRAWCONTEXT context, 00202 const CATRect& textRect, 00203 const CATRect& dirtyRect, 00204 const CATColor& textColor, 00205 const CATString& fontName, 00206 CATFloat32 fontSize, 00207 bool multiline = false, 00208 CATColor* bgColor = 0, 00209 bool italics = false, 00210 bool centered = false, 00211 bool autosize = false); 00212 00213 /// OnSize() is called when the window changes size. 00214 virtual void OnSize ( const CATRect& newRect); 00215 00216 /// OnEvent() is called when events occur that we should know about. 00217 virtual CATResult OnEvent ( const CATEvent& event, 00218 CATInt32& retVal); 00219 00220 typedef void (CATWindow::*GGCOMMANDFUNC)( CATCommand& command, 00221 CATControl* control); 00222 00223 struct GGWINDOWCMDFUNC 00224 { 00225 char* CommandName; 00226 GGCOMMANDFUNC CommandFunc; 00227 bool DisableWindow; // Disable window during command? 00228 bool Threaded; // Should be run threaded? 00229 }; 00230 00231 00232 /// OnCommand() is called by child controls when they are pressed / 00233 /// changed. 00234 /// 00235 /// Each clickable control has an XML-scripted 00236 /// command string and parameter, as well as the control's value. 00237 /// By default, commands are sent from the control to its parent, 00238 /// then up to the window's parent skin, and from there to the 00239 /// application. 00240 /// 00241 /// \param command - the command 00242 /// \param ctrl - the control that sent it, or 0. 00243 virtual void OnCommand(CATCommand& command, CATControl* ctrl); 00244 00245 /// OnThreadedCommand is called on the background command thread. 00246 /// It should be used for commands that will take a long time, using 00247 /// the PostThreadedCommand() function. 00248 /// 00249 /// \param command - the command 00250 virtual void OnThreadedCommand(CATCommand& command); 00251 00252 /// OnDestroy() is called just before the OS's window is destroyed. 00253 virtual void OnDestroy(); 00254 00255 /// OnCreate() is called when a new window is created. 00256 virtual void OnCreate(); 00257 00258 /// OnClose() is called when a window close message is received. 00259 /// Return true to allow close, false to disallow. 00260 virtual bool OnClose(); 00261 00262 /// OnMove() is called whenever the window moves. 00263 virtual void OnMove(const CATPOINT& newPos); 00264 00265 /// OnMoving() is called while the window is being moved. 00266 /// If the move rectangle is changed, return true to let the 00267 /// framework know. 00268 /// 00269 /// \param moveRect - the move rectangle. This may be changed by OnMoving(). 00270 /// \param wndRect - actual (OS) window rectangle of current window 00271 /// \return bool - true if the rect is changed, false otherwise. 00272 virtual bool OnMoving(CATRect& moveRect, const CATRect& wndRect); 00273 00274 /// Load() translates the XML attributes into object variables and 00275 /// objects for the window and its children. 00276 /// 00277 /// CATGuiObj does most of the work here, but any custom stuff should 00278 /// be checked after the parent returns. 00279 /// 00280 /// \return CATResult - CAT_SUCCESS on success. 00281 virtual CATResult Load( CATPROGRESSCB progressCB = 0, 00282 void* progressParam = 0, 00283 CATFloat32 progMin = 0.0f, 00284 CATFloat32 progMax = 1.0f); 00285 00286 /// OSSetMouse() - Operating system specific call to set the mouse 00287 /// location and cursor. 00288 /// 00289 /// This is mainly used by linear knobs to hold the cursor in one 00290 /// location. 00291 /// 00292 /// \param point - location to set the cursor to 00293 /// \param cursor - cursor to set 00294 /// 00295 void OSSetMouse(const CATPOINT& point, CATCursor& cursor); 00296 00297 00298 /// SetCursorType() sets the active cursor type for the window. 00299 void SetCursorType(CATCURSORTYPE type); 00300 00301 /// OSSetCursor activates the current cursor 00302 void OSSetCursor(); 00303 00304 /// OSSetCursor for a specific cursor type.. 00305 void OSSetCursor(CATCursor& cursor); 00306 00307 /// OSDrawCursor() - Operating system specific call to draw a 00308 /// copy of the mouse cursor. 00309 /// 00310 /// This is used with linear knobs to draw a stationary cursor 00311 /// while the knob is turned. The actual cursor is hidden, as 00312 /// it jumps around a bit even with the framework resetting its 00313 /// position. 00314 /// 00315 /// \param context - drawing context to draw the cursor to 00316 /// \param point - location to draw the cursor 00317 /// \param cursor - the cursor object to draw 00318 void OSDrawCursor(CATDRAWCONTEXT context, const CATPOINT& point, CATCursor& cursor); 00319 00320 /// OSGetWnd() returns the operating system-specific window handle for 00321 /// the window. 00322 /// \return CATWND - window handle (win32 - HWND for the window) 00323 CATWND OSGetWnd(); 00324 00325 /// OSGetWndRect() retrieves the actual window rectangle 00326 /// of the window - including non-client areas like borders 00327 /// and menu bars. 00328 virtual CATRect OSGetWndRect(); 00329 00330 // Minimize the window 00331 void OSMinimize(); 00332 00333 // Maximize the window 00334 void OSMaximize(); 00335 00336 /// OSWndToScreen() converts x/y coordinates from within the window to screen 00337 /// coordinates. 00338 /// \param x - x position to convert 00339 /// \param y - y position to convert 00340 void OSWndToScreen( CATInt32& x, CATInt32& y); 00341 00342 /// OSScreenToWnd() converts x/y coordinates from within the screen to within 00343 /// the window. 00344 /// \param x - x position to convert 00345 /// \param y - y position to convert 00346 void OSScreenToWnd( CATInt32& x, CATInt32& y); 00347 00348 /// OSSetFocus sets the operating system-specific window focus. 00349 /// 00350 /// This is mainly used by child controls that have their own 00351 /// windows. 00352 /// 00353 /// \param window - new focus target. 00354 void OSSetFocus(CATWND window = 0); 00355 00356 /// OSMoveWnd() moves and/or resizes the specified window (or the base window) 00357 /// to the requested rectangle. 00358 /// 00359 /// If window == 0, then the base window is used. 00360 /// \param rect - new window rect 00361 /// \param wnd - the window, or 0 for base 00362 virtual void OSMoveWnd(const CATRect& rect, CATWND wnd = 0); 00363 00364 /// OSDestroyWnd() is called to specifically destroy a window. 00365 /// 00366 /// If window == 0, then the window object's window is destroyed. 00367 /// Otherwise, you can pass it the window of a control or other 00368 /// window to nuke. 00369 /// \param window - window to destroy. 00370 virtual void OSDestroyWnd(CATWND window = 0); 00371 00372 /// SetFocus() sets the currently focused control. 00373 /// 00374 /// \param control - ptr to control to set the focus to. 00375 virtual void SetFocus(CATControl* control); 00376 00377 /// KillFocus() removes the focus from all controls. 00378 virtual void KillFocus(); 00379 00380 /// SetFocusNext() goes to the next control, or wraps around 00381 /// to the beginning. 00382 /// 00383 /// This is mainly used when the user pressed TAB. 00384 /// 00385 virtual void SetFocusNext(); 00386 00387 /// SetFocusPrev() goes to the previous control, or 00388 /// wraps around the list to the end. 00389 /// 00390 /// This is mainly used by shift-tab. 00391 /// 00392 virtual void SetFocusPrev(); 00393 00394 /// GetFocusControl() retrieves the currently focused control, 00395 /// or 0 if none. 00396 virtual CATControl* GetFocusControl(); 00397 00398 /// RegCtlWnd() registers a window handle from a CATControlWnd. 00399 /// This allows us to send messages w/o doing full scans for the 00400 /// control through the skin's tree. 00401 /// 00402 /// \param wndCtl - window control 00403 /// \param wndHandle - window handle of the control 00404 /// \return CATResult - CAT_SUCCESS on success 00405 /// \sa UnRegCtlWnd() 00406 virtual CATResult RegCtlWnd(CATControlWnd* wndCtl, CATWND wndHandle); 00407 00408 /// UnRegCtlWnd() unregisters a window handle from a CATControlWnd. 00409 /// This should be called when the control destroys its handle to 00410 /// prevent mis-sends. 00411 /// \param wndHandle - old window handle of the control 00412 /// \return CATResult - CAT_SUCCESS on success 00413 /// \sa RegCtlWnd() 00414 virtual CATResult UnRegCtlWnd(CATWND wndHandle); 00415 00416 /// GetCtlWnd() retrieves a CATControlWnd for a given 00417 /// handle, or 0 if none is registered. 00418 virtual CATControlWnd* GetCtlWnd(CATWND wndHandle); 00419 00420 /// RectFromAttribs() recalculates the control's rectangle from 00421 /// the attributes. This can only be called after ParseAttributes() has 00422 /// loaded the images. 00423 virtual CATResult RectFromAttribs(); 00424 00425 virtual void SetEnabled(bool enabled); 00426 virtual void SetActive(); 00427 00428 static void SetTrackMouse(CATWND hwnd); 00429 00430 // Woopsie - this needs to be public for now, 'cause some controls (e.g. menus!) need 00431 // to kill tooltips on clicks! 00432 virtual void OSHideToolTip(); 00433 00434 virtual bool IsTemplate(); 00435 virtual void SetIsTemplate(bool isTemplate); 00436 00437 virtual CATFONT AutoFontSize( const CATString& text, 00438 CATRect rect, 00439 const CATString& fontName, 00440 CATFloat32 fontSize, 00441 bool bold = false, 00442 bool italic = false, 00443 bool underlined = false); 00444 00445 00446 00447 virtual CATFONT OSGetFont( const CATString& fontName, 00448 CATFloat32 fontSize, 00449 // these are currently not implemented. 00450 bool bold = false, 00451 bool italic = false, 00452 bool underlined = false); 00453 00454 virtual void OSReleaseFont( CATFONT& font); 00455 00456 /// OnMouseWheel() is called when the mouse wheel is turned. 00457 /// 00458 /// If the mouse is over a control, then this function 00459 /// typically calls the control's TrackMouseWheel() function. 00460 /// 00461 /// \param point - location of mouse poitner 00462 /// \param wheelMove - amount of wheel movement. 00463 /// Currently, 1 notch should be about 1.0 in distance. 00464 /// Positive is 'forward' or away from the user, negative 00465 /// is backwards or towards the user. 00466 /// \param modKey - Key state modifiers for ctrl/shift/alt/etc. 00467 virtual void OnMouseWheel( const CATPOINT& point, 00468 CATFloat32 wheelMove, 00469 CATMODKEY modKey ); 00470 00471 /// SetKnobOverride() overrides any knobs in a window to behave 00472 /// as specified (circular or linearly) 00473 virtual void SetKnobOverride(CATKNOB_STYLE knobStyle); 00474 00475 00476 /// OnKeyDown() is called when a key is initially pushed down. 00477 /// See CATKeystroke.h for details on keystroke decoding. 00478 /// 00479 /// \param keystroke - the key that was pushed. 00480 virtual void OnKeyDown(const CATKeystroke& keystroke); 00481 00482 /// OnKeyUp() is called when a key is released.. 00483 /// See CATKeystroke.h for details on keystroke decoding. 00484 /// 00485 /// \param keystroke - the key that was released. 00486 virtual void OnKeyUp(const CATKeystroke& keystroke); 00487 00488 /// OnKeyPressed() is called when a key event is received 00489 /// (the key was pushed down then released). 00490 /// 00491 /// See CATKeystroke.h for details on keystroke decoding. 00492 /// 00493 /// \param keystroke - the key that was pressed. 00494 virtual void OnKeyPress(const CATKeystroke& keystroke); 00495 00496 /// OnHelp() is called by the framework when the user requests 00497 /// help from an item in the window. 00498 virtual void OnHelp(); 00499 00500 // MoveWindow() manually moves a window's top-left. 00501 virtual void CenterWindow( CATWindow* parent ); 00502 00503 /// GetWindow() retrieves the parent window. 00504 virtual CATWindow* GetWindow() const; 00505 00506 virtual void WindowToWidget( CATGuiObj* widget, CATPOINT& pt); 00507 virtual void WindowToWidget( CATGuiObj* widget, CATRect& rect); 00508 virtual void WidgetToWindow( CATGuiObj* widget, CATPOINT& pt); 00509 virtual void WidgetToWindow( CATGuiObj* widget, CATRect& rect); 00510 /// ResetBackground() resets the fImageCopy background image. 00511 /// \return CATResult - CAT_SUCCESS on success. 00512 virtual CATResult ResetBackground(); 00513 00514 00515 virtual CATResult OnDropFile(const CATString& filePath); 00516 00517 // Command handlers 00518 virtual void OnClose (CATCommand& command, CATControl* ctrl); 00519 virtual void OnMinimize(CATCommand& command, CATControl* ctrl); 00520 virtual void OnMaximize(CATCommand& command, CATControl* ctrl); 00521 00522 virtual void OnNoop (CATCommand& command, CATControl* ctrl); 00523 00524 00525 /// GetPref() retrieves the value of the requested preference. 00526 /// 00527 /// \param prefName - name of preference 00528 /// \param prefValue - ref to value of preference (several overloaded types) 00529 /// \return bool - true if the preference existed, false otherwise. 00530 /// If not found, prefValue remains unchanged. 00531 /// \sa SetPref() 00532 bool GetPref(const CATString& prefName, CATString& prefValue); 00533 bool GetPref(const CATString& prefName, CATInt32& prefValue); 00534 bool GetPref(const CATString& prefName, CATUInt32& prefValue); 00535 bool GetPref(const CATString& prefName, CATFloat32& prefValue); 00536 bool GetPref(const CATString& prefName, bool& prefValue); 00537 00538 00539 /// SetPref() sets the value of the specified preference. 00540 /// 00541 /// \param prefSection - section name of preference (window name, etc.) 00542 /// \param prefName - name of preference 00543 /// \param prefValue - value of preference (several overloaded types) 00544 /// \return bool - true on success. 00545 /// \sa SetPref() 00546 bool SetPref(const CATString& prefName, const CATString& prefValue); 00547 bool SetPref(const CATString& prefName, CATInt32 prefValue); 00548 bool SetPref(const CATString& prefName, CATUInt32 prefValue); 00549 bool SetPref(const CATString& prefName, CATFloat32 prefValue); 00550 bool SetPref(const CATString& prefName, bool prefValue); 00551 00552 00553 virtual void OnBuildMenu(CATMenu* menu) {}; 00554 00555 CATWND GetBaseWindow(); 00556 CATResult PostEvent(CATEvent* event); 00557 CATResult PostThreadedCommand(CATCommand& cmd); 00558 00559 /// GetRectAbs() retrieves the rect of the GUI object in 00560 /// absolute coordinates (e.g. w/o layer relocation). 00561 /// 00562 /// \param screenCoordinates - if true, returns the rect in screen 00563 /// coordinates. Otherwise, they are in 00564 /// client coordinates. 00565 virtual CATRect GetRectAbs( bool screenCoordinates = false); 00566 00567 /// HitTest() checks to see if there is a focuseable control 00568 /// under the point, and returns it if so. 00569 /// 00570 /// \param point - location to check 00571 /// \return CATControl* - ptr to control under the point or 0. 00572 virtual CATControl* HitTest(const CATPOINT& point); 00573 00574 virtual CATUInt32 GetAccessRole() {return CAT_ROLE_SYSTEM_WINDOW;} 00575 00576 /// Returns the scale factors for controls on the window. 00577 /// If scaling is not enabled, returns an error and 1.0f for scale values. 00578 virtual CATResult GetScale(CATFloat32& xScale, CATFloat32& yScale); 00579 00580 void GetControlStruct(CATFINDCONTROLSTRUCT& ctrlStruct, CATControl* control); 00581 protected: 00582 // SendEvent() sends an event to the app, and if this window is 00583 // templated, to the window and its children as well. 00584 CATResult SendEvent( const CATEvent& event, CATInt32& lRes); 00585 00586 CATResult ProcessCommandTable( CATCommand& cmd, 00587 CATControl* control, 00588 const GGWINDOWCMDFUNC* cmdTable, 00589 CATUInt32 cmdTableLen, 00590 bool inThread); 00591 00592 /// CalcSlack is a utility function for calculating docking offsets 00593 /// \param movePos - requested move position, may be changed on ret 00594 /// \param opposite - opposite side of requested move, may be changed on ret 00595 /// \param dockPos - position to check against 00596 /// \param slackCounter - counter tracking distance we've docked so far on pos 00597 /// \param inside - are we docking inside the rect or outside? 00598 /// \return true if movePos/opposite changed and docked, false otherwise. 00599 bool CalcSlack( CATInt32& movePos, 00600 CATInt32& opposite, 00601 const CATInt32& dockPos, 00602 CATInt32& slackCounter, 00603 bool inside = false); 00604 00605 00606 /// CleanBackground() cleans the dirty rectangle in the background 00607 /// 00608 /// This keeps us from having to perform a full copy of the background 00609 /// image each draw. 00610 /// 00611 /// \param dirtyRect - the rectangle to draw, or 0 to draw everything. 00612 /// \return CATResult - CAT_SUCCESS on success. 00613 virtual CATResult CleanBackground( CATRect* dirtyRect ); 00614 00615 00616 /// ParseAttributes() parses the known attributes for an object. 00617 virtual CATResult ParseAttributes(); 00618 00619 // OS specific functions - implemented in GGWindow_Win32.cpp (or mac, etc) 00620 00621 /// OSDraw() performs the operating system specific drawing. 00622 /// 00623 /// OSDraw() will call back into the window to perform the normal 00624 /// Draw() command, copy the resulting image into a system-dependant 00625 /// image, then perform any system-specific control drawing through 00626 /// PostDraw(). After that, it will display the results to the screen. 00627 /// 00628 /// \param drawContext - drawing context for the system / window 00629 /// \param dirtyRect - the portion of the window to draw, or 0 for all. 00630 virtual void OSDraw( CATDRAWCONTEXT drawContext, 00631 CATRect* dirtyRect); 00632 00633 /// OSGenRegion() generates a region from a stack of rectangles to 00634 /// use for clipping. 00635 /// 00636 /// You should call OSFreeRegion() on the region handle when done. 00637 /// 00638 /// \return CATOSREGION - regions we can draw in for clipping 00639 /// \sa OSFreeRegion() 00640 virtual CATOSREGION OSGenRegion(CATStack<CATRect>& rectStack); 00641 00642 /// OSFreeRegion() frees a region previously created by 00643 /// OSGenRegion(). 00644 /// 00645 /// \param rgn - region to free, generally previously allocated 00646 /// by OSGenRegion(). 00647 /// \sa OSGenRegion() 00648 virtual void OSFreeRegion(CATOSREGION rgn); 00649 00650 /// OSGetDockRect() retrieves either the coordinates of the 00651 /// parent window, or of the screen if no parent window. 00652 /// \return CATRect - parent bounding rect 00653 virtual CATRect OSGetDockRect(); 00654 00655 /// OSCreateWnd() performs the actual OS-specific grunt work 00656 /// for creating a window. 00657 /// 00658 /// \return CATResult - CAT_SUCCESS on success. 00659 virtual CATResult OSCreateWnd( CATWND wnd = 0); 00660 00661 /// OSShowWnd() shows the window. If the GUI window has not been 00662 /// created yet, you should call OSCreateWnd() instead. 00663 /// \sa OSHideWindow() 00664 virtual void OSShowWnd(); 00665 00666 00667 /// OSShowToolTip() shows a tooltip for the specified control. 00668 /// 00669 /// \param control - ptr to the CATControl 00670 virtual void OSShowToolTip(CATControl* toolTip, const CATPOINT& point); 00671 00672 virtual void OSUpdateToolTip(); 00673 00674 /// OSBuildToolTips() builds up the initial tool tip window(s) for the window 00675 virtual void OSBuildToolTips(); 00676 00677 /// OSHideWindow() hides the window. It does not destroy it. 00678 /// 00679 /// \sa OSShowWnd() 00680 virtual void OSHideWnd(); 00681 00682 /// Retrieve window style indicator based on our parameters for window 00683 virtual CATUInt32 OSGetWindowStyle(); 00684 00685 /// OSBeginMouseTrack() requests the operating system to begin 00686 /// sending all mouse movement commands to the interface. When 00687 /// we start mouse tracking, typically we'll send all mouse 00688 /// events only to the control that began it. 00689 /// 00690 /// This is called when the mouse is pressed on a focuseable 00691 /// control. 00692 virtual void OSBeginMouseTrack(); 00693 00694 /// OSEndMouseTrack() ends a previously started mouse tracking. 00695 /// 00696 /// The is called when the mouse is released. 00697 /// \sa OSBeginMouseTrack() 00698 virtual void OSEndMouseTrack(); 00699 00700 /// OnMouseMove() is called each time the mouse moves in the window. 00701 /// 00702 /// If the mouse is being tracked, it should send the message to 00703 /// the focused control's TrackMouseMove(). 00704 /// 00705 /// \param point - location of the mouse 00706 /// \param leftButton - true if left button is pressed 00707 /// \param modKey - Key state modifiers for ctrl/shift/alt/etc. 00708 virtual void OnMouseMove( const CATPOINT& point, 00709 bool leftButton, 00710 CATMODKEY modKey); 00711 00712 /// OnMouseHover() is called each time the mouse hovers for a bit 00713 /// 00714 /// \param point - location of the mouse 00715 /// \param leftButton - true if left button is pressed 00716 /// \param modKey - Key state modifiers for ctrl/shift/alt/etc. 00717 virtual void OnMouseHover( const CATPOINT& point, 00718 bool leftButton, 00719 CATMODKEY modKey); 00720 00721 /// OnMouseDown() is called when a mouse button is presesd. 00722 /// 00723 /// It handles the mouse press, finds the control (if any) 00724 /// that is pressed, and begins tracking. 00725 /// 00726 /// \param point - location mouse is pressed 00727 /// \param modKey - Key state modifiers for ctrl/shift/alt/etc. 00728 virtual void OnMouseDown( const CATPOINT& point, 00729 CATMODKEY modKey); 00730 00731 /// OnMouseUp() is called when a previously pressed button is 00732 /// released. 00733 /// 00734 /// This function will end tracking if needed and notify 00735 /// the control of the release. 00736 /// 00737 /// \param point - location mouse was released 00738 /// \param modKey - Key state modifiers for ctrl/shift/alt/etc. 00739 virtual void OnMouseUp( const CATPOINT& point, 00740 CATMODKEY modKey); 00741 00742 /// OnRightMouseDown() is called when the right mouse button is presesd. 00743 /// 00744 /// \param point - location mouse is pressed 00745 /// \param modKey - Key state modifiers for ctrl/shift/alt/etc. 00746 virtual void OnRightMouseDown( const CATPOINT& point, 00747 CATMODKEY modKey); 00748 00749 /// OnRightMouseUp() is called when the right mouse button 00750 /// is released. 00751 /// 00752 /// \param point - location mouse was released 00753 /// \param modKey - Key state modifiers for ctrl/shift/alt/etc. 00754 virtual void OnRightMouseUp( const CATPOINT& point, 00755 CATMODKEY modKey); 00756 00757 00758 00759 /// OnMouseDoubleClick() is called the mouse is double clicked. 00760 /// 00761 /// \param point - location mouse was released 00762 /// \param modKey - Key state modifiers for ctrl/shift/alt/etc. 00763 virtual void OnMouseDoubleClick(const CATPOINT& point, 00764 CATMODKEY modKey); 00765 00766 00767 00768 00769 /// OnMouseLeave() is called when the mouse leaves the window. 00770 /// 00771 /// This function will typically remove the active state of 00772 /// any controls, in case the mouse left the window without 00773 /// 'hitting' the background. 00774 virtual void OnMouseLeave(); 00775 00776 /// OnMouseTimer() is called while the mouse is being tracked 00777 /// if enough time has occurred since the last movement 00778 /// of the mouse. 00779 /// 00780 /// This is used for filtered controls which must receive multiple 00781 /// messages to achieve the 'real' value, such as knobs. 00782 /// 00783 /// \param modKey - Key state modifiers for ctrl/shift/alt/etc. 00784 virtual void OnMouseTimer(CATMODKEY modKey); 00785 00786 // OnWindowTimer is called when a window timer event occurs 00787 // These are not accurate. Use for updates and the like. 00788 virtual void SetWindowTimer (CATFloat32 frequencyHz); 00789 virtual void KillWindowTimer(); 00790 virtual void OnWindowTimer () {} 00791 00792 /// SetStatusBarHint() sets the status bar, if present, to the 00793 /// specified hint text. 00794 virtual void SetStatusBarHint(const CATString& hintText); 00795 00796 /// GetStatusBarHint() retrieves the current text in the 00797 /// status bar. 00798 virtual CATString GetStatusBarHint(); 00799 00800 /// RegWindow() registers a window class if needed, 00801 /// providing a string to reference it in the future. 00802 /// \return CATResult - CAT_SUCCESS on success. 00803 CATResult RegWindow(); 00804 00805 /// GGUnRegWindow() unregisters the image app's window class. 00806 void GGUnregWindow(); 00807 00808 00809 void PostEventNotification(); 00810 void ProcessPostedEvent(); 00811 00812 00813 static bool FindControlCallback(CATControl* curControl, void* userParam); 00814 static bool GetControlSiblingsCallback(CATControl* curControl, void* userParam); 00815 static bool SetKnobCallback(CATControl* curControl, void* userParam); 00816 00817 00818 virtual void OSWaitOnCmdThread(); 00819 #ifdef CAT_CONFIG_WIN32 00820 00821 LRESULT OSOnSize (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool& handled); 00822 LRESULT OSOnKeyUp (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool& handled); 00823 LRESULT OSOnKeyDown (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool& handled); 00824 LRESULT OSOnMinMax (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool& handled); 00825 LRESULT OSDropFiles (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool& handled); 00826 LRESULT OSGetControlColors(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool& handled); 00827 LRESULT OSOnAppCmd (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool& handled); 00828 LRESULT OSOnPaint (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool& handled); 00829 LRESULT OSOnMeasureItem (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool& handled); 00830 LRESULT OSOnDrawItem (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool& handled); 00831 LRESULT OSGetObject (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool& handled); 00832 00833 00834 00835 static unsigned int _stdcall OSCmdThread(void *param); 00836 00837 /// window procedure for win32 - the implementation is in CATWindow_Win32.cpp 00838 static LRESULT CALLBACK WindowProc( 00839 HWND hwnd, // handle to window 00840 UINT uMsg, // message identifier 00841 WPARAM wParam, // first message parameter 00842 LPARAM lParam // second message parameter 00843 ); 00844 00845 #endif 00846 00847 /// fStatusBarHint is the current hint text for the window, whether from 00848 /// the window itself, the active control, or current process. 00849 CATString fStatusBarHint; 00850 00851 /// If non-zero, fMouseTrackTarget is a control with the mouse 00852 /// currently captured. 00853 CATControl* fMouseTrackTarget; 00854 00855 /// If non-zero, fRightTrack is the control the right mouse was 00856 /// pressed on. 00857 CATControl* fRightTrack; 00858 00859 /// fActiveControl points to the currently active control, if any. 00860 /// This is the control that the mouse is over 00861 CATControl* fActiveControl; 00862 00863 /// fFocusControl points to the currently focused control, if any. 00864 /// This differs from the active control in that focus does not 00865 /// change from mouse movements - only clicking and hotkeys. 00866 CATControl* fFocusControl; 00867 00868 /// fMouseInWindow is true if the mouse is currently in the window 00869 bool fMouseInWindow; 00870 00871 /// fPrimary determines if the application exits when the window is closed. 00872 /// If true, then the application will close with the iwndow. 00873 bool fPrimary; 00874 00875 /// fSizeable determines if the window is sizeable. 00876 bool fSizeable; 00877 00878 /// If fScale is true, elements that support scaling will be scaled when the 00879 /// window is resized. NOT IMPLEMENTED YET 00880 bool fScale; 00881 00882 /// Base width/height for scaling NOT IMPLEMENTED YET 00883 CATSIZE fBaseSize; 00884 00885 /// fCaptionBar determines if we use an OS-specific caption bar or not 00886 bool fCaptionBar; 00887 00888 /// fDragAnywhere - if true, the window can be dragged from any non-control 00889 /// area 00890 bool fDragAnywhere; 00891 bool fDragging; 00892 CATPOINT fDragLastPoint; 00893 00894 /// fPostRegion is an OS-specific combination of rectangles describing 00895 /// areas that should *not* be drawn over by the background or 00896 /// imaged controls. This includes the areas occupied by controls 00897 /// such as the browser, edit boxes, etc. that are drawn seperately. 00898 CATOSREGION fPostRegion; 00899 00900 /// fImageCopy is a copy of the background image that is drawn into by 00901 /// the child controls. It is refreshed when 'dirty' by CleanBackground(), 00902 /// and completely reset by ResetBackground(). 00903 CATImage* fImageCopy; 00904 00905 /// Window class name. This may just be a win32 thing... 00906 CATString fClassName; 00907 00908 /// Window title - may differ from name. 00909 CATString fTitle; 00910 00911 /// Path to icon, if any 00912 CATString fIconPath; 00913 HICON fUserIcon; 00914 00915 /// fSkin is the base skin object (the Window's parent) 00916 CATSkin* fSkin; 00917 00918 /// fWindow is an OS-specific identifier for the window 00919 CATWND fWindow; 00920 00921 // ToolTip stuff... 00922 bool fUseToolTips; 00923 CATString fLastTipText; 00924 CATPOINT fLastTipPos; 00925 /// fToolTip is an OS-specific identifier for the tooltip window 00926 CATWND fToolTip; 00927 CATControl* fCurTool; 00928 CATColor fToolTipFore; 00929 CATColor fToolTipBg; 00930 00931 /// fRegistered is true if the window has been registered 00932 bool fRegistered; 00933 00934 /// fCursor holds the window's current cursor 00935 CATCursor fCursor; 00936 00937 /// fLastMouseUpdate is the time of the last mouse update from 00938 /// OnMouseMove(). This is used to determine if a timer event 00939 /// should be sent to the currently active control or not. 00940 clock_t fLastMouseUpdate; 00941 00942 /// If a control called "StatusLabel" is available in the window, 00943 /// this will be pointing at it. 00944 CATLabel* fStatusLabel; 00945 00946 /// fLastPoint 00947 CATPOINT fLastPoint; 00948 00949 /// fAutoDock - if true, snaps to other windows and edges 00950 bool fAutoDock; 00951 00952 /// Slack counters for docking... 00953 CATInt32 fLeftSlack; 00954 CATInt32 fTopSlack; 00955 CATInt32 fRightSlack; 00956 CATInt32 fBottomSlack; 00957 00958 // MAximized ? 00959 bool fMaximized; 00960 00961 // Is the window object a template and not 00962 // a standalone singleton? 00963 bool fIsTemplate; 00964 00965 // Are we an overlapped child window? 00966 // Generally only true with VST and other plugin types. 00967 bool fIsOverlapped; 00968 00969 /// Control window tree - maps HWND's to controls for 00970 /// certain messages. 00971 std::map<CATWND, CATControlWnd*> fCWT; 00972 CATQueue<CATEvent*> fEventQueue; 00973 00974 /// Threaded commands 00975 void ThreadedCmdThread(); 00976 void OSStartCmdThread(); 00977 00978 CATQueue<CATCommand> fThreadedCmdQueue; 00979 CATSignal fThreadedCmdSignal; 00980 CATMutex fThreadedCmdLock; 00981 00982 void* fCmdThread; 00983 00984 CATMutex fEventLock; 00985 bool fExiting; 00986 bool fExitThread; 00987 00988 // Actual rect of the window 00989 CATPOINT fScreenPos; 00990 }; 00991 00992 00993 #endif // _GGWindow_H_ 00994 00995 00996