-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlisting1.html
executable file
·779 lines (653 loc) · 30 KB
/
listing1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>HIDoubleSlider - /HIDoubleSlider.cp</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/Carbon/index.html">Carbon</a> > <a href="../../samplecode/Carbon/idxHumanInterfaceToolbox-date.html">Human Interface Toolbox</a> > <A HREF="javascript:location.replace('index.html');">HIDoubleSlider</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">HIDoubleSlider</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/HIDoubleSlider.cp</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/HIDoubleSlider.cp</option>
<option value="listing2.html">/HIDoubleSlider.h</option>
<option value="listing3.html">/TestHIView.cp</option>
<option value="listing4.html">/TestHIView.r</option></select>
</p>
</form>
<p><strong><a href="HIDoubleSlider.zip">Download Sample</a></strong> (“HIDoubleSlider.zip”, 62.3K)<BR>
<strong><a href="HIDoubleSlider.dmg">Download Sample</a></strong> (“HIDoubleSlider.dmg”, 121.1K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/* File: HIDoubleSlider.cp Contains: Demonstrates creating a double slider using the HIView APIs. Version: 1.0 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Copyright © 2002 Apple Computer, Inc., All Rights Reserved*/#include <Carbon/Carbon.h>#include "HIDoubleSlider.h"// structure in which we hold our custom push button's datatypedef struct { HIViewRef view; // the HIViewRef for our button SInt32 hiValue; // our settings SInt32 loValue; ControlRef invisibleHiSlider; ControlRef invisibleLoSlider; }DoubleSliderData;pascal OSStatus ViewHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon);CFStringRef GetDoubleSliderClass();void SetControlHiLoValue(ControlRef theControl, SInt32 newValue, Boolean hiOrLo);/* * HICreateDoubleSlider() * * Summary: * Creates a double slider control. * * Parameters: * * boundsRect: * The bounding box of the control. * * minimum: * maximum: * loValue: * hiValue: * 32 Bits settings. * * outDoubleSlider: * On exit, contains the new control. * * Availability: * Mac OS X: in version 10.2 and later since it needs the HIView APIs * CarbonLib: not available * Non-Carbon CFM: not available */OSStatus HICreateDoubleSlider( const HIRect * boundsRect, SInt32 minimum, SInt32 maximum, SInt32 loValue, SInt32 hiValue, HIViewRef * outDoubleSlider) { EventRef theInitializeEvent = NULL; HIObjectRef hiObject = NULL; OSStatus theStatus = CreateEvent(NULL, kEventClassHIObject, kEventHIObjectInitialize, GetCurrentEventTime(), kEventAttributeUserEvent, &theInitializeEvent); if (theStatus != noErr) goto exitCreation; // settings SetEventParameter(theInitializeEvent, kControlLoValueTag, typeSInt32, sizeof(loValue), &loValue); SetEventParameter(theInitializeEvent, kControlHiValueTag, typeSInt32, sizeof(hiValue), &hiValue); SetEventParameter(theInitializeEvent, kControlCollectionTagMinimum, typeSInt32, sizeof(minimum), &minimum); SetEventParameter(theInitializeEvent, kControlCollectionTagMaximum, typeSInt32, sizeof(maximum), &maximum); SetEventParameter(theInitializeEvent, kControlCollectionTagBounds, typeHIRect, sizeof(HIRect), boundsRect); theStatus = HIObjectCreate(GetDoubleSliderClass(), theInitializeEvent, &hiObject); if (theStatus != noErr) goto exitCreation; exitCreation: *outDoubleSlider = (HIViewRef)hiObject; if (theInitializeEvent != NULL) ReleaseEvent(theInitializeEvent); return theStatus; }UInt32 GetHIToolboxVersion() { CFBundleRef bundle; CFStringRef versionStr = NULL; static UInt32 version = 0; if (version != 0) return version; bundle = CFBundleGetBundleWithIdentifier( CFSTR("com.apple.HIToolbox") ); if ( bundle != NULL ) versionStr = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( bundle, CFSTR("CFBundleShortVersionString") ); if ( versionStr != NULL && CFGetTypeID( versionStr ) == CFStringGetTypeID() ) { int major = 0, minor = 0, bugfix = 0; char sz[20]; CFStringGetCString( versionStr, sz, sizeof( sz ), kCFStringEncodingUTF8 ); sscanf( sz, "%d.%d.%d", &major, &minor, &bugfix ); version = ( major << 8 ) + ( minor << 4 ) + bugfix; } return version; }/*----------------------------------------------------------------------------------------------------------*/// * GetDoubleSliderClass// Registers and returns an HIObject class for a double slider./*----------------------------------------------------------------------------------------------------------*/CFStringRef GetDoubleSliderClass() { // following code is pretty much boiler plate. static HIObjectClassRef theClass; if (theClass == NULL) { static EventTypeSpec kFactoryEvents[] = { // the next 3 messages are boiler plate { kEventClassHIObject, kEventHIObjectConstruct }, { kEventClassHIObject, kEventHIObjectInitialize }, { kEventClassHIObject, kEventHIObjectDestruct }, // the next 2 messages are specific to our class { kEventClassDoubleSlider, kEventControlHiValueFieldChanged }, { kEventClassDoubleSlider, kEventControlLoValueFieldChanged }, // the next messages are the minimum messages we need to // implement the double slider control. { kEventClassControl, kEventControlInitialize }, { kEventClassControl, kEventControlHitTest }, { kEventClassControl, kEventControlTrack }, { kEventClassControl, kEventControlHiliteChanged }, { kEventClassControl, kEventControlActivate }, { kEventClassControl, kEventControlDeactivate }, { kEventClassControl, kEventControlDraw } }; HIObjectRegisterSubclass(kDoubleSliderClassID, kHIViewClassID, 0, ViewHandler, GetEventTypeCount(kFactoryEvents), kFactoryEvents, 0, &theClass); } return kDoubleSliderClassID; }/*----------------------------------------------------------------------------------------------------------*/// * GetLoHiRects// returns the Rects of both our indicators./*----------------------------------------------------------------------------------------------------------*/void GetLoHiRects(DoubleSliderData* myData, Rect *loRect, Rect *hiRect) { SetControl32BitValue(myData->invisibleLoSlider, myData->loValue); SetControl32BitValue(myData->invisibleHiSlider, myData->hiValue); RgnHandle theRgn = NewRgn(); GetControlRegion(myData->invisibleLoSlider, kControlIndicatorPart, theRgn); GetRegionBounds(theRgn, loRect); GetControlRegion(myData->invisibleHiSlider, kControlIndicatorPart, theRgn); GetRegionBounds(theRgn, hiRect); DisposeRgn(theRgn); }enum { kControlHiIndicatorPart = 170, kControlLoIndicatorPart = 171 };/*----------------------------------------------------------------------------------------------------------*/// * FindPart// returns which part the Point (from the EventRef) is in or kControlNoPart if not./*----------------------------------------------------------------------------------------------------------*/ControlPartCode FindPart(EventRef inEvent, DoubleSliderData* myData) { ControlPartCode part = kControlNoPart; // the point parameter is in view-local coords. Point qdPoint; GetEventParameter(inEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(qdPoint), NULL, &qdPoint); Rect loRect, hiRect; GetLoHiRects(myData, &loRect, &hiRect); if (PtInRect(qdPoint, &loRect)) part = kControlLoIndicatorPart; if (PtInRect(qdPoint, &hiRect)) part = kControlHiIndicatorPart; // if both values are at the maximum, we need to return the Lo indicator part or nothing will move ever again! if (myData->loValue == myData->hiValue) { SInt32 max = GetControl32BitMaximum(myData->view); if (max == myData->loValue) part = kControlLoIndicatorPart; } return part; }/*----------------------------------------------------------------------------------------------------------*/// * DrawSlider// Draws the bar and both indicators using ONLY Appearance calls./*----------------------------------------------------------------------------------------------------------*/void DrawSliderJaguar(DoubleSliderData* myData) { ThemeTrackDrawInfo drawInfo; drawInfo.kind = kThemeSlider; HIRect hiBounds; HIViewGetBounds(myData->view, &hiBounds); drawInfo.bounds.left = drawInfo.bounds.top = 0; drawInfo.bounds.right = (int)hiBounds.size.width; drawInfo.bounds.bottom = (int)hiBounds.size.height; drawInfo.min = GetControl32BitMinimum(myData->view); drawInfo.max = GetControl32BitMaximum(myData->view); drawInfo.enableState = (IsControlActive(myData->view) && IsControlEnabled(myData->view))?kThemeTrackActive:kThemeTrackInactive; drawInfo.trackInfo.slider.pressState = 0; drawInfo.attributes = kThemeTrackRightToLeft; drawInfo.trackInfo.slider.thumbDir = kThemeThumbPlain; DrawThemeTrack(&drawInfo, NULL, NULL, NULL); Rect loRect, hiRect; GetLoHiRects(myData, &loRect, &hiRect); drawInfo.attributes = kThemeTrackRightToLeft | kThemeTrackShowThumb; drawInfo.bounds.top = loRect.top + 2; drawInfo.bounds.bottom = drawInfo.bounds.top + 16; drawInfo.value = myData->loValue; drawInfo.trackInfo.slider.thumbDir = kThemeThumbUpward; if (IsControlHilited(myData->view)) if (GetControlHilite(myData->view) == kControlLoIndicatorPart) drawInfo.trackInfo.slider.pressState = kThemeThumbPressed; DrawThemeTrack(&drawInfo, NULL, NULL, NULL); drawInfo.trackInfo.slider.pressState = 0; drawInfo.bounds.top = hiRect.top + 2; drawInfo.bounds.bottom = drawInfo.bounds.top + 16; drawInfo.value = myData->hiValue; drawInfo.trackInfo.slider.thumbDir = kThemeThumbDownward; if (IsControlHilited(myData->view)) if (GetControlHilite(myData->view) == kControlHiIndicatorPart) drawInfo.trackInfo.slider.pressState = kThemeThumbPressed; DrawThemeTrack(&drawInfo, NULL, NULL, NULL); }void DrawSliderPanther(DoubleSliderData* myData, CGContextRef context) { HIThemeTrackDrawInfo drawInfo; drawInfo.version = 0; drawInfo.kind = kThemeSlider; HIViewGetBounds(myData->view, &drawInfo.bounds); drawInfo.min = GetControl32BitMinimum(myData->view); drawInfo.max = GetControl32BitMaximum(myData->view); drawInfo.enableState = (IsControlActive(myData->view) && IsControlEnabled(myData->view))?kThemeTrackActive:kThemeTrackInactive; drawInfo.trackInfo.slider.pressState = 0; drawInfo.attributes = kThemeTrackRightToLeft; drawInfo.trackInfo.slider.thumbDir = kThemeThumbPlain; HIThemeDrawTrack(&drawInfo, NULL, context, kHIThemeOrientationNormal); Rect loRect, hiRect; GetLoHiRects(myData, &loRect, &hiRect); drawInfo.attributes = kThemeTrackRightToLeft | kThemeTrackShowThumb; drawInfo.bounds.origin.y = loRect.top + 2; drawInfo.bounds.size.height = 16; drawInfo.value = myData->loValue; drawInfo.trackInfo.slider.thumbDir = kThemeThumbUpward; if (IsControlHilited(myData->view)) if (GetControlHilite(myData->view) == kControlLoIndicatorPart) drawInfo.trackInfo.slider.pressState = kThemeThumbPressed; HIThemeDrawTrack(&drawInfo, NULL, context, kHIThemeOrientationNormal); drawInfo.trackInfo.slider.pressState = 0; drawInfo.bounds.origin.y = hiRect.top + 2;// drawInfo.bounds.bottom = drawInfo.bounds.top + 16; drawInfo.value = myData->hiValue; drawInfo.trackInfo.slider.thumbDir = kThemeThumbDownward; if (IsControlHilited(myData->view)) if (GetControlHilite(myData->view) == kControlHiIndicatorPart) drawInfo.trackInfo.slider.pressState = kThemeThumbPressed; HIThemeDrawTrack(&drawInfo, NULL, context, kHIThemeOrientationNormal); }/*----------------------------------------------------------------------------------------------------------*/// * ViewHandler// Event handler that implements our double slider./*----------------------------------------------------------------------------------------------------------*/pascal OSStatus ViewHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon) { OSStatus result = eventNotHandledErr; DoubleSliderData* myData = (DoubleSliderData*)inRefcon; switch (GetEventClass(inEvent)) { case kEventClassHIObject: switch (GetEventKind(inEvent)) { case kEventHIObjectConstruct: { // allocate some instance data myData = (DoubleSliderData*) calloc(1, sizeof(DoubleSliderData)); // get our superclass instance HIViewRef epView; GetEventParameter(inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(epView), NULL, &epView); // remember our superclass in our instance data and initialize other fields myData->view = epView; myData->invisibleHiSlider = NULL; myData->invisibleLoSlider = NULL; // store our instance data into the event result = SetEventParameter(inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof(myData), &myData); break; } case kEventHIObjectDestruct: { if (myData->invisibleLoSlider) DisposeControl(myData->invisibleLoSlider); if (myData->invisibleHiSlider) DisposeControl(myData->invisibleHiSlider); free(myData); result = noErr; break; } case kEventHIObjectInitialize: { // always begin kEventHIObjectInitialize by calling through to the previous handler result = CallNextEventHandler(inCaller, inEvent); // if that succeeded, do our own initialization if (result == noErr) { // settings GetEventParameter(inEvent, kControlLoValueTag, typeSInt32, NULL, sizeof(myData->loValue), NULL, &myData->loValue); GetEventParameter(inEvent, kControlHiValueTag, typeSInt32, NULL, sizeof(myData->hiValue), NULL, &myData->hiValue); SInt32 minimum; GetEventParameter(inEvent, kControlCollectionTagMinimum, typeSInt32, NULL, sizeof(minimum), NULL, &minimum); SetControl32BitMinimum(myData->view, minimum); SInt32 maximum; GetEventParameter(inEvent, kControlCollectionTagMaximum, typeSInt32, NULL, sizeof(maximum), NULL, &maximum); SetControl32BitMaximum(myData->view, maximum); HIRect bounds; GetEventParameter(inEvent, kControlCollectionTagBounds, typeHIRect, NULL, sizeof(bounds), NULL, &bounds); HIViewSetFrame(myData->view, &bounds); Rect cBounds = { 0, 0, (int)bounds.size.height - 1, (int)bounds.size.width }; // creating 2 invisible sliders to steal information from when needed. CreateSliderControl(NULL, &cBounds, 0, minimum, maximum, kControlSliderPointsDownOrRight, 0, false, NULL, &myData->invisibleLoSlider); CreateSliderControl(NULL, &cBounds, 0, minimum, maximum, kControlSliderPointsUpOrLeft, 0, false, NULL, &myData->invisibleHiSlider); HIViewSetVisible(myData->invisibleLoSlider, false); HIViewSetVisible(myData->invisibleHiSlider, false); // we're embedding those invisible sliders in our own view so that they move along HIViewAddSubview(myData->view, myData->invisibleLoSlider); HIViewAddSubview(myData->view, myData->invisibleHiSlider); } break; } default: break; } break; case kEventClassDoubleSlider: switch (GetEventKind(inEvent)) { case kEventControlHiValueFieldChanged: case kEventControlLoValueFieldChanged: HIViewSetNeedsDisplay(myData->view, true); result = noErr; break; default: break; } break; case kEventClassControl: switch (GetEventKind(inEvent)) { case kEventControlInitialize: { CallNextEventHandler(inCaller, inEvent); UInt32 features = 0; result = GetEventParameter(inEvent, kEventParamControlFeatures, typeUInt32, NULL, sizeof(features), NULL, &features); if (result == noErr) features |= kControlSupportsEmbedding; else features = kControlSupportsEmbedding; result = SetEventParameter(inEvent, kEventParamControlFeatures, typeUInt32, sizeof features, &features); break; }#pragma mark -#pragma mark case kEventControlDraw case kEventControlDraw: { static bool hiToolboxVersionTested = false; static bool canUseHITheme = false; if (! hiToolboxVersionTested) { hiToolboxVersionTested = true; canUseHITheme = (GetHIToolboxVersion() >= 0x130); } CGContextRef context; result = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(context), NULL, &context); if (canUseHITheme && (result == noErr) && (context != NULL)) DrawSliderPanther(myData, context); else DrawSliderJaguar(myData); result = noErr; break; }#pragma mark case kEventControlHitTest case kEventControlHitTest: { ControlPartCode part = FindPart(inEvent, myData); SetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, sizeof(part), &part); result = noErr; break; }#pragma mark case kEventControlTrack case kEventControlTrack: { ControlPartCode part = FindPart(inEvent, myData); // was part clicked hilited before? If not, hilite it. if (part != GetControlHilite(myData->view)) HiliteControl(myData->view, part); ControlRef theControl = NULL; if (part == kControlHiIndicatorPart) theControl = myData->invisibleHiSlider; if (part == kControlLoIndicatorPart) theControl = myData->invisibleLoSlider; if (theControl == NULL) break; Rect loRect, hiRect; GetLoHiRects(myData, &loRect, &hiRect); SInt32 height = hiRect.bottom - hiRect.top; SInt32 min = GetControl32BitMinimum(theControl); SInt32 max = GetControl32BitMaximum(theControl); // we need the location of our invisible sliders in local coordinates of the window (actually the content view) HIRect hiFrame; HIViewGetFrame(theControl, &hiFrame); HIViewRef contentView; HIViewFindByID(HIViewGetRoot(GetControlOwner(myData->view)), kHIViewWindowContentID, &contentView); HIViewConvertRect(&hiFrame, myData->view, contentView); SInt32 fTop = (int)hiFrame.origin.y; SInt32 fBottom = fTop + (int)hiFrame.size.height; // determining (as best as can be done) the delta value which comes from the fact // that we clicked in any point of the indicator, but the value associated with the indicator // is for only one line within. Point pt; GetEventParameter(inEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(pt), NULL, &pt); pt.v += fTop; SInt32 deltaValue = min + ((fBottom - pt.v - (height / 2)) * (max - min)) / (fBottom - fTop - height); SInt32 value = (part == kControlHiIndicatorPart)?myData->hiValue:myData->loValue; deltaValue -= value; // tracking (needs a QD Grafport. Actually it doesn't but it's simpler that way for managing local vs. global coords) GrafPtr savePort; GetPort(&savePort); SetPort(GetWindowPort(GetControlOwner(myData->view))); MouseTrackingResult mouse = kMouseTrackingMouseDown; for (; mouse != kMouseTrackingMouseUp; ) { TrackMouseLocation(NULL, &pt, &mouse); if (mouse == kMouseTrackingMouseDragged) { SInt32 newValue = min - deltaValue + ((fBottom - pt.v - (height / 2)) * (max - min)) / (fBottom - fTop - height); if (part == kControlHiIndicatorPart) SetControlHiValue(myData->view, newValue); if (part == kControlLoIndicatorPart) SetControlLoValue(myData->view, newValue); } } SetPort(savePort); // let's not forget to un-hilite HiliteControl(myData->view, 0); SetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, sizeof(part), &part); result = noErr; break; }#pragma mark case kEventControlHiliteChanged#pragma mark - // If anything changed, let's ask for a redraw case kEventControlActivate: case kEventControlDeactivate: case kEventControlHiliteChanged: HIViewSetNeedsDisplay(myData->view, true); result = noErr; break; default: break; } break; default: break; } return result; }void SetControlHiLoValue(ControlRef theControl, SInt32 newValue, Boolean hiOrLo) { DoubleSliderData* myData = (DoubleSliderData*)HIObjectDynamicCast((HIObjectRef)theControl, kDoubleSliderClassID); if (myData == NULL) return; SInt32 min = GetControl32BitMinimum(myData->invisibleHiSlider); SInt32 max = GetControl32BitMaximum(myData->invisibleHiSlider); Boolean hiChanged = false, loChanged = false; if (hiOrLo) { if (newValue > max) newValue = max; if (newValue < myData->loValue) newValue = myData->loValue; if (hiChanged = (newValue != myData->hiValue)) myData->hiValue = newValue; } else { if (newValue < min) newValue = min; if (newValue > myData->hiValue) newValue = myData->hiValue; if (loChanged = (newValue != myData->loValue)) myData->loValue = newValue; } if (hiChanged || loChanged) { EventRef theEvent; UInt32 kind = hiChanged?kEventControlHiValueFieldChanged:kEventControlLoValueFieldChanged; CreateEvent(NULL, kEventClassDoubleSlider, kind, 0, 0, &theEvent); SetEventParameter(theEvent, kEventParamDirectObject, typeControlRef, sizeof(ControlRef), &theControl); SendEventToEventTarget(theEvent, GetControlEventTarget(theControl)); ReleaseEvent(theEvent); } }// Convenience accessorsSInt32 GetControlLoValue(ControlRef theControl) { DoubleSliderData* myData = (DoubleSliderData*)HIObjectDynamicCast((HIObjectRef)theControl, kDoubleSliderClassID); if (myData) return myData->loValue; else return 0; }void SetControlLoValue( ControlRef theControl, SInt32 newLoValue) { SetControlHiLoValue(theControl, newLoValue, false); }SInt32 GetControlHiValue(ControlRef theControl) { DoubleSliderData* myData = (DoubleSliderData*)HIObjectDynamicCast((HIObjectRef)theControl, kDoubleSliderClassID); if (myData) return myData->hiValue; else return 0; }void SetControlHiValue( ControlRef theControl, SInt32 newHiValue) { SetControlHiLoValue(theControl, newHiValue, true); }</pre>
<!--googleoff: index -->
</td>
</tr>
</table>
<!-- END WIDE COLUMN -->
<!-- END MAIN CONTENT -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div style="width: 100%; height: 1px; background-color: #919699; margin-top: 5px; margin-bottom: 15px"></div></td>
</tr>
<tr>
<td align="center"><br/>
<table border="0" cellpadding="0" cellspacing="0" class="graybox">
<tr>
<th>Did this document help you?</th>
</tr>
<tr>
<td>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=1&url=/samplecode/HIDoubleSlider/listing1.html%3Fid%3DDTS10000637-1.0&media=dvd" target=_new>Yes</a>: Tell us what works for you.</div>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=2&url=/samplecode/HIDoubleSlider/listing1.html%3Fid%3DDTS10000637-1.0&media=dvd" target=_new>It’s good, but:</a> Report typos, inaccuracies, and so forth.</div>
<div><a href="http://developer.apple.com/feedback/?v=3&url=/samplecode/HIDoubleSlider/listing1.html%3Fid%3DDTS10000637-1.0&media=dvd" target=_new>It wasn’t helpful</a>: Tell us what would have helped.</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- START BOTTOM APPLE NAVIGATION -->
<!--#include virtual="/includes/footer"-->
<!-- END BOTTOM APPLE NAVIGATION -->
<!-- START CENTER CLOSE -->
</center>
<!-- END CENTER CLOSE -->
</body>
</html>