0_Tutorial/Custom Cursor.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"
        "http://www.w3.org/MarkUp/Wilbur/HTML32.dtd">
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>Custom Cursor</title>
    <meta name="generator" content="BBEdit 8.2">
<style type="text/css">
<!--
.mybox {
    background-color: #F7F7F7;
    margin: 4px;
    padding: 4px;
    border: 1px solid #999999;
}
-->
<!--
.mycodebox {
    background-color: #F1F5F9;
    margin: 4px;
    padding: 4px;
    border: 1px solid #999999;
}
-->
</style>
</head>
<body>
 
<h1>
Tutorial: Writing a custom HIView
</h1>
 
<h2>
D) Implementing support for custom cursor appearance
</h2>
 
<p>
The support for custom cursor appearance is done by handling the kEventControlTrackingAreaEntered and kEventControlTrackingAreaExited events.
</p>
 
<p>
As usual, we add those two events to the event list that we register in GetHICustomViewClass and we add the two very simple cases in the function Internal_HICustomViewHandler:
</p>
 
<div class="mycodebox"><pre>
case kEventControlTrackingAreaEntered:
   {
   // setting the cursor when we pass over our custom view
   SetThemeCursor(kThemeCountingUpHandCursor);
   break;
   }
 
case kEventControlTrackingAreaExited:
   {
   // resetting the cursor when we leave custom view
   SetThemeCursor(kThemeArrowCursor);
   break;
   }
</pre></div>
 
<p>
Of course, if you have multiple parts, you may grab the precise mouse location and key modifiers if any from the EventRef and determine which cursor should be used.
</p>
 
<p>
Since we want our custom HIView to have automatic cursor tracking when created, we need to adjust our kEventHIObjectInitialize event handler which now does something useful:
</p>
 
<div class="mycodebox"><pre>
case kEventHIObjectInitialize:
   {
   // always begin kEventHIObjectInitialize by calling through to the previous handler
   status = CallNextEventHandler(inHandlerCallRef, inEvent);
   require_noerr(status, InitializeExit);
   
   // if that succeeded, do our own initialization
   HIViewTrackingAreaRef trackRef;
   status = HIViewNewTrackingArea(myData->view, NULL, 0, &trackRef);
   require_noerr(status, InitializeExit);
 
InitializeExit:
   break;
   }
</pre></div>
 
<p>
We do not need to clean after ourselves in the kEventHIObjectDestruct event handler since the HIToolbox will automatically dispose any tracking area associated with your view when that view is destroyed.
</p>
 
<p>
In our example you will simply see:
</p>
 
<img src="../0_Tutorial/Picture%205.png" alt="" width="535" height="468">
 
<p>
You can test the custom HIView for this step by using the project located in the folder “5_Tracking_Area”.
</p>
 
<br>
 
<a href="../0_Tutorial/Drag%20and%20Drop.html">Next Page
</a>
 
<br>
<br>
 
<a href="../0_Tutorial/Tracking.html">Previous Page
</a>
 
<br>
<br>
 
<a href="../0_%20Tutorial%20Start%20Here.html">Return to Main Page
</a>
 
</body>
</html>