Cursor Class Reference

Encapsulates OIL cursors, hiding OS specific functions behind a standard sensible interface. More...

#include <cursor.h>

List of all members.

Public Member Functions

 Cursor (LPCSTR lpStdCsrName)
 Loads a standard cursor from the operting system's resources.
 Cursor (UINT32 wCsrID)
 Loads the specified cursor from the kernel's application module.
 Cursor (Tool_v1 *pTool, UINT32 wCsrID)
 Loads the specified cursor from the specified tool.
 Cursor (UINT32 wToolID, UINT32 wCsrID)
 Loads the specified cursor from the specified tool.
 Cursor (wxBitmap *pbmpAND, wxBitmap *pbmpXOR)
 Creates a cursor from two bitmap masks (AND & XOR). See the Windows SDK documentation for the CreateCursor() function to understand how this is done.
virtual ~Cursor ()
 Destroys a cursor (if necessary).
BOOL IsValid () const
 Tests that this object was constructed without any errors.
void SetActive (bool fOnlyRendWnd=false) const
 Makes this Cursor object the active operating system cursor.
wxCursor * Handle ()
BOOL Show ()
 Increments the cursor's semaphore, generally making the cursor visible.
BOOL Hide ()
 Decrements the cursor's semaphore, generally making the cursor invisible.

Static Public Member Functions

static BOOL Init ()
 Loads some standard GUI cursors from the operating system resources. Only three are found on most platforms - the arrow, the hour-glass, and the insertion beam.
static void DeInit ()
 Deallocates the Cursor objects created by Init().
static INT32 Width ()
 (see above)
static INT32 Height ()
 (see above)

Static Public Attributes

static CursorArrow
static CursorBusy
static CursorInsert
static CursorCrossHair
static CursorProgress
static CursorPointingHand
static CursorSizeNWSE

Private Member Functions

 CC_DECLARE_MEMDUMP (Cursor)

Private Attributes

wxCursor hCursor
BOOL bMustDestroy


Detailed Description

Encapsulates OIL cursors, hiding OS specific functions behind a standard sensible interface.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
15 November 1993

Definition at line 117 of file cursor.h.


Constructor & Destructor Documentation

Cursor::Cursor LPCSTR  lpStdCsrName  ) 
 

Loads a standard cursor from the operting system's resources.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/93
Parameters:
The (string) identifier of a standard Windows cursor, eg. _R(IDC_WAIT). [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: Will trap in debugging version if the load fails.

See also:
-

Definition at line 240 of file cursor.cpp.

00241   : hCursor(0), bMustDestroy(FALSE)             // we must not try to destroy standard cursors!
00242 {
00243     PORTNOTETRACE("other","Cursor::Cursor(LPCSTR) - do nothing");
00244     // Try to load the cursor (it is likely to be loaded already).
00245 //  hCursor = wxCursor(lpStdCsrName);
00246 
00247 /*  hCursor = AfxGetApp()->LoadStandardCursor(lpStdCsrName);
00248     if (hCursor == 0)
00249     {
00250         if (IsWin32c() && lpStdCsrName == _R(IDC_SIZE))
00251         {
00252             // ChicagoBodge
00253             // when marked as a 4.0 .exe it is unable to load _R(IDC_SIZE) or _R(IDC_ICON) resources, so we fall
00254             // back to _R(IDC_SIZEALL)
00255             hCursor = AfxGetApp()->LoadStandardCursor( _R(IDC_SIZEALL) );
00256         }
00257 
00258     #ifdef RALPH
00259         if(hCursor == 0)
00260         {
00261             TRACEUSER( "JustinF", _T("Cursor '%s' not found\n"), lpStdCsrName);
00262             hCursor = AfxGetApp()->LoadStandardCursor(_R(IDC_CROSS));
00263         }
00264     #endif
00265         
00266         if (hCursor == 0)
00267             ERROR3_PF(("Failed to load standard cursor %u", (INT32) LOWORD(lpStdCsrName)));
00268     }
00269 */
00270 }

Cursor::Cursor UINT32  wCsrID  ) 
 

Loads the specified cursor from the kernel's application module.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/11/93
Parameters:
The numeric identifier of the cursor in the kernel's resources. [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: ENSURE failure if the cursor can't be loaded.

See also:
-

Definition at line 290 of file cursor.cpp.

00291   : bMustDestroy(FALSE)
00292 {
00293     if (wCsrID > 0 && wCsrID <= wxCURSOR_MAX)
00294     {
00295         // Simply set the standard wxCursor
00296         hCursor = wxCursor(wCsrID);
00297     }
00298     else
00299     {
00300         wxImage        *pImage = (CamArtProvider::Get())->FindImage( wCsrID );
00301         ENSURE( NULL != pImage, "Failed to find cursor in Cursor::Cursor!\n");
00302 
00303         if (NULL == pImage)
00304         {
00305             hCursor = wxCursor(wxCURSOR_CROSS);
00306             return;
00307         }
00308 
00309         // Try to load the specified cursor from the OILTool's module.
00310         hCursor = wxCursor(*pImage);
00311     }
00312 
00313 //  // Check that the resource ID is valid for a kernel resource.
00314 //
00315 // We no longer do this, as we are now using some non-system cursors which have
00316 // IDs outside this range.
00317 //
00318 //  ENSURE(wCsrID >= KID_FIRST && wCsrID <= KID_LAST,
00319 //         "Kernel cursor has out-of-range resource ID!\n");
00320 
00321     // Load from the application's global (ie. kernel) resources.
00322 //  hCursor = wxCursor(wCsrID);
00323 /*
00324     hCursor = ::LoadCursor(AfxGetResourceHandle(), MAKEINTRESOURCE(wCsrID));
00325 
00326 #ifdef RALPH
00327     if(hCursor == 0)
00328     {
00329         TRACEUSER( "JustinF", _T("Cursor '%d' not found 2\n"), wCsrID);
00330         hCursor = AfxGetApp()->LoadStandardCursor(_R(IDC_CROSS));
00331     }
00332 #endif
00333 */
00334 //  ENSURE(hCursor != 0, "Failed to load a kernel cursor in Cursor::Cursor!\n");
00335 }

Cursor::Cursor Tool_v1 pTool,
UINT32  wCsrID
 

Loads the specified cursor from the specified tool.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/93
Parameters:
A pointer to the tool associated with the desired cursor and the numeric [INPUTS] resource identifier of the particular cursor.
- [OUTPUTS]
Returns:
-

Errors: In the debugging version traps a failure to load.

See also:
-

Definition at line 356 of file cursor.cpp.

00357   : bMustDestroy(FALSE)
00358 {
00359     wxImage        *pImage = (CamArtProvider::Get())->FindImage( wCsrID );
00360     ENSURE( NULL != pImage, "Failed to find cursor in Cursor::Cursor!\n");
00361 
00362     if( NULL == pImage )
00363     {
00364         hCursor = wxCursor( wxCURSOR_CROSS );
00365         return;
00366     }
00367 
00368     // Try to load the specified cursor from the OILTool's module.
00369     hCursor = wxCursor( *pImage );
00370 }

Cursor::Cursor UINT32  wToolID,
UINT32  wCsrID
 

Loads the specified cursor from the specified tool.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/93
Parameters:
The ID of the tool associated with the desired cursor and the numeric [INPUTS] resource identifier of the particular cursor.
- [OUTPUTS]
Returns:
-

Errors: In the debugging version traps a failure to load.

See also:
-

Definition at line 391 of file cursor.cpp.

00392   : hCursor(wxCURSOR_ARROW), bMustDestroy(FALSE)
00393 {
00394     wxImage        *pImage = (CamArtProvider::Get())->FindImage( wCsrID );
00395     ENSURE( NULL != pImage, "Failed to find cursor in Cursor::Cursor!\n");
00396 
00397     if( NULL == pImage )
00398     {
00399         hCursor = wxCursor( wxCURSOR_CROSS );
00400         return;
00401     }
00402 
00403     // Try to load the specified cursor from the OILTool's module.
00404     hCursor = wxCursor( *pImage );
00405     
00406 //  PORTNOTETRACE("other","Cursor::Cursor - do nothing");
00407 #ifndef EXCLUDE_FROM_XARALX
00408     // Check that the resource ID is in the valid range for tools.
00409 /*  ENSURE(wCsrID < KID_FIRST || wCsrID > KID_LAST,
00410            "Tool cursor has out-of-range resource ID!\n");*/
00411     // Find the OILTool object associated with this tool.
00412     OILTool* ptOil = Tool::GetOILTool(wToolID);
00413     ENSURE(ptOil != 0, "Failed to find OIL tool in Cursor::Cursor!\n");
00414     
00415     // Try to load the specified cursor from the OILTool's module.
00416     hCursor = ptOil->LoadCursor(wCsrID);
00417 
00418 #ifdef RALPH
00419     if(hCursor == 0)
00420     {
00421         TRACEUSER( "Richard", _T("Cursor '%d' not found 4\n"), wCsrID);
00422         hCursor = AfxGetApp()->LoadStandardCursor(_R(IDC_CROSS));
00423     }
00424 #endif
00425 
00426     ENSURE(hCursor != 0, "Failed to load a tool's cursor in Cursor::Cursor!\n");
00427 #endif
00428 }

Cursor::Cursor wxBitmap *  pbmpAND,
wxBitmap *  pbmpXOR
 

Creates a cursor from two bitmap masks (AND & XOR). See the Windows SDK documentation for the CreateCursor() function to understand how this is done.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/93
Parameters:
Two pointers to the bitmaps which are used as masks when creating the [INPUTS] cursor.
- [OUTPUTS]
Returns:
-

Errors: Checks that the bitmaps are of the same size as cursors.

See also:
-

Definition at line 451 of file cursor.cpp.

00452   : hCursor(0), bMustDestroy(TRUE)                              // destroy any cursor we create
00453 {
00454     PORTNOTETRACE("other","Cursor::Cursor(wxBitmap*, wxBitmap*) - do nothing");
00455 #ifndef EXCLUDE_FROM_XARALX
00456     // Make the cursor from the bitmaps.  The bitmaps must be of the correct size.
00457     BITMAP andInfo;
00458     pbmpAND->GetObject(sizeof(BITMAP), &andInfo);
00459 
00460     // In the debug version make this check for both parameters.
00461     INT32 w = Width();
00462     INT32 h = Height();
00463 
00464 #ifdef  _DEBUG
00465     BITMAP xorInfo;
00466     pbmpXOR->GetObject(sizeof(BITMAP), &xorInfo);
00467     ENSURE((andInfo.bmWidth == w) && (andInfo.bmHeight == h) &&
00468            (xorInfo.bmWidth == w) && (xorInfo.bmHeight == h),
00469            "Mask bitmaps are not cursor-sized in Cursor::Cursor!\n");
00470 #endif  // _DEBUG
00471     
00472     // Copy the pixel data of the two masks into buffers allocated on the heap.
00473     size_t dwSize = andInfo.bmWidthBytes * andInfo.bmHeight;
00474     LPWORD lpwAndBits = new WORD[dwSize / 2 + 1];
00475     LPWORD lpwXorBits = new WORD[dwSize / 2 + 1];
00476     if (!lpwAndBits ||
00477         !lpwXorBits ||
00478         !pbmpAND->GetBitmapBits(dwSize, lpwAndBits) ||
00479         !pbmpXOR->GetBitmapBits(dwSize, lpwXorBits))
00480     {
00481     #ifdef  _DEBUG
00482         if (IsUserName("JustinF"))
00483             TRACE( _T("Failed to allocate heap space for mask buffers in Cursor::Cursor!\n"));
00484     #endif  // _DEBUG
00485 
00486         delete[] lpwAndBits;
00487         delete[] lpwXorBits;
00488         return;
00489     }
00490 
00491     // Now make the cursor.
00492     hCursor = ::CreateCursor(AfxGetApp()->m_hInstance,
00493                              w / 2, h / 2, w, h,
00494                              lpwAndBits, lpwXorBits);
00495     #ifdef  _DEBUG
00496         if (hCursor == 0 && IsUserName("JustinF"))
00497             TRACE( _T("Failed to create cursor in Cursor::Cursor!\n"));
00498     #endif  // _DEBUG
00499 
00500     // Finally, deallocate all resources.
00501     delete[] lpwAndBits;
00502     delete[] lpwXorBits;
00503 #endif
00504 }

Cursor::~Cursor  )  [virtual]
 

Destroys a cursor (if necessary).

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 524 of file cursor.cpp.

00525 {
00526 //  if (hCursor != 0 && bMustDestroy) ::DestroyCursor(hCursor);
00527 }


Member Function Documentation

Cursor::CC_DECLARE_MEMDUMP Cursor   )  [private]
 

void Cursor::DeInit void   )  [static]
 

Deallocates the Cursor objects created by Init().

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
Cursor::Init; CursorStack::DeInit

Definition at line 205 of file cursor.cpp.

00206 {
00207     delete Arrow;
00208     delete Busy;
00209     delete Insert;
00210     delete CrossHair;
00211     delete SizeNWSE;
00212 
00213     Arrow = Busy = Insert = CrossHair = SizeNWSE = 0;
00214 
00215 #ifdef RALPH
00216     delete PointingHand;
00217     PointingHand = 0;
00218 #endif
00219     
00220 }

wxCursor* Cursor::Handle  )  [inline]
 

Definition at line 141 of file cursor.h.

00141 {return &hCursor;}          // returns the (wxWindows) handle of the cursor

INT32 Cursor::Height  )  [static]
 

(see above)

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The height of a cursor, in pixels, for this system & video mode.

Errors: -

See also:
-

Definition at line 721 of file cursor.cpp.

00722 {
00723     return wxSystemSettings::GetMetric( wxSYS_CURSOR_Y );
00724 }

BOOL Cursor::Hide  ) 
 

Decrements the cursor's semaphore, generally making the cursor invisible.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the cursor is no longer visible.

Errors: -

See also:
Cursor::Show

Definition at line 673 of file cursor.cpp.

00674 {
00675 //  return ::ShowCursor(FALSE) < 0;
00676     ::wxSetCursor(wxNullCursor);
00677     return true;
00678 }

BOOL Cursor::Init void   )  [static]
 

Loads some standard GUI cursors from the operating system resources. Only three are found on most platforms - the arrow, the hour-glass, and the insertion beam.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if initialisation successful.

Errors: -

See also:
Cursor::DeInit; CursorStack::Init

Definition at line 159 of file cursor.cpp.

00160 {
00161     Arrow     = new Cursor( wxCURSOR_ARROW );
00162     Busy      = new Cursor( wxCURSOR_WAIT );
00163     Insert    = new Cursor( wxCURSOR_IBEAM );
00164     CrossHair = new Cursor( wxCURSOR_CROSS );
00165     SizeNWSE  = new Cursor( wxCURSOR_SIZENWSE );
00166     Progress  = 0;
00167 
00168 #ifdef RALPH
00169     //Graham 6/9/96: This is used in Ralph's No Tool mode. The No Tool mode is
00170     //implemented in DocView, but we can't initiate a cursor there, because we end up
00171     //creating a new cursor every time a new view is created.
00172     PointingHand = new Cursor(_R(IDC_POINTINGHANDCURSOR));
00173 #endif //RALPH
00174 
00175     return Arrow != 0
00176         && Busy != 0
00177         && Insert != 0
00178         && CrossHair != 0
00179         && SizeNWSE != 0
00180         && Arrow->IsValid()
00181         && Busy->IsValid()
00182         && Insert->IsValid()
00183         && CrossHair->IsValid()
00184         && SizeNWSE->IsValid();
00185 }

BOOL Cursor::IsValid  )  const
 

Tests that this object was constructed without any errors.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the Cursor object was successfully loaded/created.

Errors: -

See also:
-

Definition at line 547 of file cursor.cpp.

00548 {
00549     PORTNOTETRACE( "other", "Cursor::IsValid - pretend cursor is valid even though not supported" );
00550 #ifndef EXCLUDE_FROM_XARALX
00551     return !hCursor.IsNull();
00552 #else
00553     return true;
00554 #endif
00555 }

void Cursor::SetActive bool  fOnlyRendWnd = false  )  const
 

Makes this Cursor object the active operating system cursor.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: If the cursor could not be loaded or created, this call does nothing.

See also:
Cursor::Show; Cursor::Hide

Definition at line 575 of file cursor.cpp.

00576 {
00577     // If we have captured the mouse then release it
00578     wxWindow* pCaptureWnd = wxWindow::GetCapture();
00579     if (pCaptureWnd)
00580         pCaptureWnd->ReleaseMouse();
00581 
00582     // Set the global cursor (but only if we have a Render window to
00583     // control its scope). Also make sure we're in the Render window,
00584     // this stops the cursor being hijacked when we pop.
00585     wxWindow*   pRenderWnd = DocView::GetCurrentRenderWindow();
00586     wxPoint     ptDontCare;
00587     wxWindow*   pWndAtPtr  = wxFindWindowAtPointer( ptDontCare );
00588     if( NULL != pRenderWnd )
00589     {
00590         bool    fDrawCtrl = NULL != pWndAtPtr ? pWndAtPtr->IsKindOf( CLASSINFO(wxCamDrawControl) ) : false;
00591         if( !fOnlyRendWnd || fDrawCtrl || pWndAtPtr == pRenderWnd )
00592             wxSetCursor(hCursor);
00593         else
00594             wxSetCursor( *wxSTANDARD_CURSOR );
00595     }
00596     
00597     // If we have a RenderWindow and it doesn't have the capture then set its cursor
00598     if( pRenderWnd != NULL && pCaptureWnd != pRenderWnd)
00599         pRenderWnd->SetCursor(hCursor);
00600 
00601     // If we did have the capture
00602     if (pCaptureWnd)
00603     {
00604         // Set the cursor on the relevant window and recapture the mouse
00605         pCaptureWnd->SetCursor(hCursor);
00606         pCaptureWnd->CaptureMouse();
00607     }
00608 
00609 #if FALSE   // Phil's version
00610     // This works around various problems concerning cursor shape changing while the mouse is captured by gdk_pointer_grab
00611     // Note1: At the time of writing wxWindow::DoCaptureMouse won't use the global cursor if the local one is unset so we need to set both versions
00612     // Note2: At the time of writing gdk_pointer_grab seems to prevent cursor changes
00613     CNativeWnd* pRenderWnd = DocView::GetCurrentRenderWindow();
00614     if (pRenderWnd && pRenderWnd->HasCapture())
00615     {
00616         pRenderWnd->ReleaseMouse();
00617         wxSetCursor(hCursor);
00618         pRenderWnd->SetCursor(hCursor);
00619         pRenderWnd->CaptureMouse();
00620     }
00621     else
00622     {
00623         wxSetCursor(hCursor);
00624         if (pRenderWnd)
00625             pRenderWnd->SetCursor(hCursor);
00626     }
00627 #endif
00628 }

BOOL Cursor::Show  ) 
 

Increments the cursor's semaphore, generally making the cursor visible.

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the cursor is visible after this function call.

Errors: -

See also:
Cursor::Hide

Definition at line 648 of file cursor.cpp.

00649 {
00650 //  return ::ShowCursor(TRUE) >= 0;
00651     SetActive();
00652     return true;
00653 }

INT32 Cursor::Width  )  [static]
 

(see above)

Author:
Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/11/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The width of a cursor, in pixels, for this system & video mode.

Errors: -

See also:
Cursor::Height

Definition at line 698 of file cursor.cpp.

00699 {
00700     return wxSystemSettings::GetMetric( wxSYS_CURSOR_X );
00701 }


Member Data Documentation

Cursor * Cursor::Arrow [static]
 

Definition at line 120 of file cursor.h.

BOOL Cursor::bMustDestroy [private]
 

Definition at line 155 of file cursor.h.

Cursor * Cursor::Busy [static]
 

Definition at line 121 of file cursor.h.

Cursor * Cursor::CrossHair [static]
 

Definition at line 123 of file cursor.h.

wxCursor Cursor::hCursor [private]
 

Definition at line 154 of file cursor.h.

Cursor * Cursor::Insert [static]
 

Definition at line 122 of file cursor.h.

Cursor* Cursor::PointingHand [static]
 

Definition at line 125 of file cursor.h.

Cursor * Cursor::Progress [static]
 

Definition at line 124 of file cursor.h.

Cursor * Cursor::SizeNWSE [static]
 

Definition at line 126 of file cursor.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:53:18 2007 for Camelot by  doxygen 1.4.4