]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/aga.cpp
a base for geometry operations
[wxWidgets.git] / src / mac / carbon / aga.cpp
1 #include <wx/mac/uma.h>
2 #include <wx/mac/aga.h>
3 #include <extcdef.h>
4 #include <PictUtils.h>
5
6 pascal SInt32 AGAProgressBarDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param);
7 pascal SInt32 AGAPlacardDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param);
8 pascal SInt32 AGAStaticTextDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param) ;
9 pascal SInt32 AGAListControlDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param) ;
10 pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param) ;
11 pascal SInt32 AGAStaticGroupBoxTextDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param) ;
12
13 #define B 13
14 #define W 0
15
16 SInt16 kAGARootControlProcID ;
17 int gAGABackgroundColor = 0 ;
18
19 const RGBColor gAGAColorArray[] = { {0xFFFF, 0xFFFF, 0xFFFF}, // W
20 {0xEEEE, 0xEEEE, 0xEEEE}, // 1
21 {0xDDDD, 0xDDDD, 0xDDDD}, // 2
22 {0xCCCC, 0xCCCC, 0xCCCC}, // 3
23 {0xBBBB, 0xBBBB, 0xBBBB}, // 4
24 {0xAAAA, 0xAAAA, 0xAAAA}, // 5
25 {0x9999, 0x9999, 0x9999}, // 6
26 {0x8888, 0x8888, 0x8888}, // 7
27 {0x7777, 0x7777, 0x7777}, // 8
28 {0x6666, 0x6666, 0x6666}, // 9
29 {0x5555, 0x5555, 0x5555}, // 10
30 {0x4444, 0x4444, 0x4444}, // 11
31 {0x2222, 0x2222, 0x2222}, // 12
32 {0x0000, 0x0000, 0x0000} // B
33 };
34
35 char LAGADefaultOutline_mCorners[4][5][5] = {
36 // topleft
37 {
38 { -1, -1, -1, 12, B },
39 { -1, -1, B, 2, 2 },
40 { -1, B, 2, 2, 5 },
41 { 12, 2, 2, 2, 8 },
42 { B, 2, 5, 8, -1 }
43 },
44 // topright
45 {
46 { B, 12, -1, -1, -1 },
47 { 2, 3, B, -1, -1 },
48 { 5, 5, 4, B, -1 },
49 { 8, 5, 5, 7, 12 },
50 { -1, 8, 5, 8, B }
51 },
52 // bottomleft
53 {
54 { B, 2, 5, 8, -1 },
55 { 12, 3, 5, 5, 8 },
56 { -1, B, 4, 5, 5 },
57 { -1, -1, B, 7, 8 },
58 { -1, -1, -1, 12, B }
59 },
60 // bottomright
61 {
62 { -1, 8, 5, 8, B },
63 { 8, 5, 7, 8, 12 },
64 { 5, 7, 8, B, -1 },
65 { 8, 8, B, -1, -1 },
66 { B, 12, -1, -1, -1 }
67 }
68 };
69
70 char LAGAPushButton_mCorners[3][4][4][4] = {
71 // Enabled
72 {
73 // topleft
74 {
75 { -1, -1, 12, B },
76 { -1, B, 4, 2 },
77 { 12, 4, W, W },
78 { B, 2, W, W }
79 },
80 // topright
81 {
82 { B, 12, -1, -1 },
83 { 2, 4, B, -1 },
84 { W, 2, 5, 12 },
85 { 2, 5, 8, B }
86 },
87 // bottomleft
88 {
89 { B, 2, W, 2 },
90 { 12, 4, 2, 5 },
91 { -1, B, 4, 8 },
92 { -1, -1, 12, B }
93 },
94 // bottomright
95 {
96 { 5, 5, 8, B },
97 { 5, 8, 8, 12 },
98 { 8, 8, B, -1 },
99 { B, 12, -1, -1 }
100 }
101 },
102 // Pressed
103 {
104 // topleft
105 {
106 { -1, -1, 12, B },
107 { -1, B, 10, 8 },
108 { 12, 10, 8, 4 },
109 { B, 8, 4, 4 }
110 },
111 // topright
112 {
113 { B, 12, -1, -1 },
114 { 8, 10, B, -1 },
115 { 4, 4, 8, 12 },
116 { 4, 4, 4, B }
117 },
118 // bottomleft
119 {
120 { B, 8, 4, 4 },
121 { 12, 10, 4, 4 },
122 { -1, B, 10, 4 },
123 { -1, -1, 12, B }
124 },
125 // bottomright
126 {
127 { 4, 4, 4, B },
128 { 4, 4, 10, 12 },
129 { 4, 10, B, -1 },
130 { B, 12, -1, -1 }
131 }
132 },
133 // Disabled
134 {
135 // topleft
136 {
137 { -1, -1, 7, 7 },
138 { -1, 7, 4, 2 },
139 { 7, 4, 1, 1 },
140 { 7, 2, 1, 1 }
141 },
142 // topright
143 {
144 { 7, 7, -1, -1 },
145 { 2, 4, 7, -1 },
146 { 1, 2, 4, 7 },
147 { 2, 4, 5, 7 }
148 },
149 // bottomleft
150 {
151 { 7, 2, 1, 2 },
152 { 7, 4, 2, 4 },
153 { -1, 7, 4, 5 },
154 { -1, -1, 7, 7 }
155 },
156 // bottomright
157 {
158 { 4, 4, 5, 7 },
159 { 4, 5, 5, 7 },
160 { 5, 5, 7, -1 },
161 { 7, 7, -1, -1 }
162 }
163 }
164 };
165
166 RGBColor gAGARamp[] =
167 {
168 /* black */
169 { 0 , 0 , 0 } ,
170 /* white */
171 { 65535 , 65535 , 65535 } ,
172 /* 1 */
173 { 61166 , 61166 , 61166 } ,
174 /* 2 */
175 { 56797 , 56797 , 56797 } ,
176 /* 3 */
177 { 52428 , 52428 , 52428 } ,
178 /* 4 */
179 { 48059 , 48059 , 48059 } ,
180 /* 5 */
181 { 43690 , 43690 , 43690 } ,
182 /* 6 */
183 { 39321 , 39321 , 39321 } ,
184 /* 7 */
185 { 34952 , 34952 , 34952 } ,
186 /* 8 */
187 { 30583 , 30583 , 30583 } ,
188 /* 9 */
189 { 26214 , 26214 , 26214 } ,
190 /* 10 */
191 { 21845 , 21845 , 21845 } ,
192 /* 11 */
193 { 17476 , 17476 , 17476 } ,
194 /* 12 */
195 { 13107 , 13107 , 13107 } ,
196 /* A1 */
197 { 8738 , 8738 , 8738 } ,
198 /* A2 */
199 { 4369 , 4369 , 4369 } ,
200
201 } ;
202
203 RGBColor gAGABlueRamp[] =
204 {
205 /* black */
206 { 0 , 0 , 0 } ,
207 /* white */
208 { 65535 , 65535 , 65535 } ,
209 /* 1 */
210 { 61166 , 61166 , 65535 } ,
211 /* 2 */
212 { 56797 , 56797 , 65535 } ,
213 /* 3 */
214 { 52428 , 52428 , 65535 } ,
215 /* 4 */
216 { 48059 , 48059 , 65535 } ,
217 /* 5 */
218 { 43690 , 43690 , 65535 } ,
219 /* 6 */
220 { 39321 , 39321 , 65535 } ,
221 /* 7 */
222 { 34952 , 34952 , 65535 } ,
223 /* 8 */
224 { 30583 , 30583 , 65535 } ,
225 /* 9 */
226 { 26214 , 26214 , 65535 } ,
227 /* 10 */
228 { 21845 , 21845 , 65535 } ,
229 /* 11 */
230 { 17476 , 17476 , 65535 } ,
231 /* 12 */
232 { 13107 , 13107 , 65535 } ,
233 /* A1 */
234 { 8738 , 8738 , 65535 } ,
235 /* A2 */
236 { 4369 , 4369 , 65535 } ,
237
238 } ;
239
240 enum eAGARampColor {
241 kAGATransparent = -1 ,
242 kAGABlack = 0 ,
243 kAGAWhite = 1 ,
244 kAGA1 = 2 ,
245 kAGA2 = 3 ,
246 kAGA3 = 4 ,
247 kAGA4 = 5 ,
248 kAGA5 = 6 ,
249 kAGA6 = 7 ,
250 kAGA7 = 8 ,
251 kAGA8 = 9 ,
252 kAGA9 = 10 ,
253 kAGA10 = 11 ,
254 kAGA11 = 12 ,
255 kAGA12 = 13 ,
256 kAGAA1 = 14 ,
257 kAGAA2 = 15 ,
258 } ;
259 // defprocs
260
261 enum eAGAState {
262 kAGAStateEnabled = 0 ,
263 kAGAStatePressed = 1 ,
264 kAGAStateDisabled = 2 ,
265 kAGAStateInactive = 3
266 } ;
267
268 /*
269 typedef struct sControlData
270 {
271 ControlPartCode m_part ;
272 ResType m_tag ;
273 Size m_size ;
274 } ;
275
276 OSErr AGAFindControlData( ControlHandle inControl , ControlPartCode inPart , ResType inTagName , long *outOffset) ;
277 OSErr AGAFindControlData( ControlHandle inControl , ControlPartCode inPart , ResType inTagName , long *outOffset)
278 {
279 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
280 long offset = 0 ;
281 long size = GetHandleSize( info->data ) ;
282 char* data = *(info->data) ;
283 sControlData* current ;
284 while( offset + sizeof( sControlData ) <= size )
285 {
286 current = (sControlData*) (data+offset ) ;
287 if ( ( inPart == kControlEntireControl || inPart == current->m_part ) && inTagName == current->m_tag )
288 {
289 *outOffset = offset ;
290 return noErr ;
291 }
292 }
293 return errDataNotSupported ; // nothing found
294 }
295
296 OSErr AGARemoveControlData( ControlHandle inControl , ControlPartCode inPart , ResType inTagName ) ;
297 OSErr AGARemoveControlData( ControlHandle inControl , ControlPartCode inPart , ResType inTagName )
298 {
299 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
300 long offset = 0 ;
301 long size = GetHandleSize( info->data ) ;
302 char* data = *(info->data) ;
303 sControlData* current ;
304 while( offset + sizeof( sControlData ) <= size )
305 {
306 current = (sControlData*) (data+offset ) ;
307 if ( ( inPart == kControlEntireControl || inPart == current->m_part ) && inTagName == current->m_tag )
308 {
309 long chunkSize = current->m_size + sizeof ( sControlData ) ;
310 memcpy( data + offset , data + offset + chunkSize , size - offset - chunkSize ) ;
311 SetHandleSize( info->data , size - chunkSize ) ;
312 return noErr ;
313 }
314 }
315 return noErr ;
316 }
317
318 OSErr AGAAddControlData( ControlHandle inControl , ControlPartCode inPart , ResType inTagName , Size inSize, Ptr inData) ;
319 OSErr AGAAddControlData( ControlHandle inControl , ControlPartCode inPart , ResType inTagName , Size inSize, Ptr inData)
320 {
321 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
322 long offset = 0 ;
323 long size = GetHandleSize( info->data ) ;
324 SetHandleSize( info->data , size + sizeof( sControlData ) + inSize ) ;
325 if ( MemError() == noErr )
326 {
327 char* data = *(info->data) ;
328 sControlData* current = (sControlData*)( data + size ) ;
329 current->m_tag = inTagName ;
330 current->m_part = inPart ;
331 current->m_size = inSize ;
332 memcpy( data + size + sizeof( sControlData ) , inData , inSize ) ;
333 return noErr ;
334 }
335 return errDataNotSupported ;
336 }
337
338
339 OSErr AGAGetControlDataSize (ControlHandle inControl,
340 ControlPartCode inPart,
341 ResType inTagName,
342 Size * outMaxSize)
343 {
344 long offset ;
345 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
346 char* data = *(info->data) ;
347
348 OSErr err = AGAFindControlData( inControl , inPart , inTagName , &offset ) ;
349 if ( !err )
350 {
351 sControlData* current = (sControlData*) (data+offset ) ;
352 *outMaxSize = current->m_size ;
353 }
354 return err ;
355 }
356
357 OSErr AGAGetControlData (ControlHandle inControl,
358 ControlPartCode inPart,
359 ResType inTagName,
360 Size inBufferSize,
361 Ptr outBuffer,
362 Size * outActualSize)
363 {
364 long offset ;
365 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
366 char* data = *(info->data) ;
367
368 OSErr err = AGAFindControlData( inControl , inPart , inTagName , &offset ) ;
369 if ( !err )
370 {
371 sControlData* current = (sControlData*) (data+offset ) ;
372 *outActualSize = current->m_size ;
373 if ( outBuffer )
374 {
375 if ( inBufferSize <= current->m_size )
376 memcpy( outBuffer , data + offset + sizeof( sControlData ) , current->m_size ) ;
377 else
378 err = errDataNotSupported ;
379 }
380 }
381 return err ;
382 }
383
384 OSErr AGASetControlData (ControlHandle inControl,
385 ControlPartCode inPart,
386 ResType inTagName,
387 Size inSize,
388 Ptr inData)
389 {
390 long offset ;
391 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
392 char* data = *(info->data) ;
393
394 OSErr err = AGAFindControlData( inControl , inPart , inTagName , &offset ) ;
395 if ( !err )
396 {
397 sControlData* current = (sControlData*) (data+offset ) ;
398 if ( current->m_size == inSize )
399 {
400 memcpy( data + offset + sizeof( sControlData ) , inData , inSize) ;
401 }
402 else
403 {
404 AGARemoveControlData( inControl , inPart , inTagName ) ;
405 AGAAddControlData( inControl , inPart , inTagName , inSize , inData ) ;
406 }
407 }
408 else
409 {
410 AGAAddControlData( inControl , inPart , inTagName , inSize , inData ) ;
411 }
412 return err ;
413 }
414 */
415
416 OSErr AGASetControlFontStyle (ControlHandle inControl,
417 const ControlFontStyleRec * inStyle)
418 {
419 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
420 if ( inStyle->flags == 0 )
421 {
422 // back to defaults
423 }
424 else
425 {
426 if ( inStyle->flags & kControlUseFontMask )
427 {
428 info->fontStyle.font = inStyle->font ;
429 }
430 if ( inStyle->flags & kControlUseSizeMask )
431 {
432 info->fontStyle.size = inStyle->size ;
433 }
434 if ( inStyle->flags & kControlUseFaceMask )
435 {
436 info->fontStyle.style = inStyle->style ;
437 }
438 if ( inStyle->flags & kControlUseModeMask )
439 {
440 info->fontStyle.mode = inStyle->mode ;
441 }
442 if ( inStyle->flags & kControlUseJustMask )
443 {
444 info->fontStyle.just = inStyle->just ;
445 }
446 if ( inStyle->flags & kControlUseForeColorMask )
447 {
448 info->fontStyle.foreColor = inStyle->foreColor ;
449 }
450 if ( inStyle->flags & kControlUseBackColorMask )
451 {
452 info->fontStyle.backColor = inStyle->backColor ;
453 }
454 }
455 return noErr ;
456 }
457
458 OSErr AGASetControlData (ControlHandle inControl,
459 ControlPartCode inPart,
460 ResType inTagName,
461 Size inSize,
462 Ptr inData)
463 {
464 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
465 ControlDataAccessRec rec ;
466
467 rec.tag = inTagName ;
468 rec.part = inPart ;
469 rec.size = inSize ;
470 rec.dataPtr = inData ;
471
472 return info->defProc( info->procID , inControl , kControlMsgSetData , (long) &rec ) ;
473 }
474
475 SInt16 AGAHandleControlKey (ControlHandle inControl,
476 SInt16 inKeyCode,
477 SInt16 inCharCode,
478 SInt16 inModifiers)
479 {
480 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
481 ControlKeyDownRec rec ;
482
483 rec.modifiers = inModifiers ;
484 rec.keyCode = inKeyCode ;
485 rec.charCode = inCharCode ;
486
487 return info->defProc( info->procID , inControl , kControlMsgKeyDown , (long) &rec ) ;
488 }
489
490 ControlPartCode AGAHandleControlClick (ControlHandle inControl,
491 Point inWhere,
492 SInt16 inModifiers,
493 ControlActionUPP inAction)
494 {
495 return TrackControl( inControl , inWhere , inAction ) ;
496 }
497
498 Boolean AGATestForNewControl( ControlHandle inControl )
499 {
500 if ( (**inControl).contrlRfCon > 0x100 && !( (**inControl).contrlRfCon % 2 ) )
501 {
502 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
503 return info->magic == kExtCDEFMagic ;
504 }
505 return FALSE ;
506 }
507 void AGAIdleControls (WindowPtr inWindow)
508 {
509 ControlHandle iter = (ControlHandle) ((WindowPeek)inWindow)->controlList ;
510 while ( iter )
511 {
512 if ( AGATestForNewControl( iter ) )
513 {
514 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**iter).contrlRfCon ;
515 if ( info->defProc( info->procID , iter , kControlMsgTestNewMsgSupport , 0 ) == kControlSupportsNewMessages )
516 {
517 if ( info->defProc( info->procID , iter , kControlMsgGetFeatures , 0 ) & kControlWantsIdle )
518 {
519 info->defProc( info->procID , iter , kControlMsgIdle , 0 ) ;
520 }
521 }
522 }
523
524 iter = (**iter).nextControl ;
525 }
526 }
527
528 void AGAUpdateOneControl( ControlHandle control , RgnHandle inRgn )
529 {
530 DrawOneControl( control ) ;
531 ControlHandle iter = (ControlHandle) ((WindowPeek)(**control).contrlOwner)->controlList ;
532 while ( iter )
533 {
534 if ( AGATestForNewControl( iter ) )
535 {
536 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**iter).contrlRfCon ;
537 if ( info->containerControl == control )
538 {
539 AGAUpdateOneControl( iter , inRgn ) ;
540 }
541 }
542
543 iter = (**iter).nextControl ;
544 }
545 }
546
547 void AGAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
548 {
549 ControlHandle root ;
550 AGAGetRootControl( inWindow , &root ) ;
551 AGAUpdateOneControl( root , inRgn ) ;
552
553 // and then all others
554
555 ControlHandle iter = (ControlHandle) ((WindowPeek)inWindow)->controlList ;
556 while ( iter )
557 {
558 if ( AGATestForNewControl( iter ) )
559 {
560 }
561 else
562 {
563 DrawOneControl( iter ) ;
564 }
565
566 iter = (**iter).nextControl ;
567 }
568 }
569
570 OSErr AGAGetRootControl( WindowPtr inWindow , ControlHandle *outControl )
571 {
572 ControlHandle iter = (ControlHandle) ((WindowPeek)inWindow)->controlList ;
573 while ( iter )
574 {
575 if ( AGATestForNewControl( iter ) )
576 {
577 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**iter).contrlRfCon ;
578 if ( info->procID == kAGARootControlProcID )
579 {
580 *outControl = iter ;
581 return noErr ;
582 }
583 }
584
585 iter = (**iter).nextControl ;
586 }
587 return -1 ;
588 }
589
590 void AGADeactivateControl( ControlHandle inControl )
591 {
592 if ( AGATestForNewControl( inControl ) )
593 {
594 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
595 if ( info->defProc( info->procID , inControl , kControlMsgTestNewMsgSupport , 0 ) == kControlSupportsNewMessages )
596 {
597 if ( info->defProc( info->procID , inControl , kControlMsgGetFeatures , 0 ) & kControlWantsActivate )
598 {
599 info->defProc( info->procID , inControl , kControlMsgActivate , 0 ) ;
600 }
601 }
602 }
603 }
604
605 void AGAActivateControl( ControlHandle inControl )
606 {
607 if ( AGATestForNewControl( inControl ) )
608 {
609 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
610 if ( info->defProc( info->procID , inControl , kControlMsgTestNewMsgSupport , 0 ) == kControlSupportsNewMessages )
611 {
612 if ( info->defProc( info->procID , inControl , kControlMsgGetFeatures , 0 ) & kControlWantsActivate )
613 {
614 info->defProc( info->procID , inControl , kControlMsgActivate , 1 ) ;
615 }
616 }
617 }
618 }
619
620 OSErr AGASetKeyboardFocus (WindowPtr inWindow,
621 ControlHandle inControl,
622 ControlFocusPart inPart)
623 {
624 if ( AGATestForNewControl( inControl ) )
625 {
626 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
627 if ( info->defProc( info->procID , inControl , kControlMsgTestNewMsgSupport , 0 ) == kControlSupportsNewMessages )
628 {
629 if ( info->defProc( info->procID , inControl , kControlMsgGetFeatures , 0 ) & kControlSupportsFocus )
630 {
631 return info->defProc( info->procID , inControl , kControlMsgFocus , inPart ) ;
632 }
633 }
634 }
635 return errControlDoesntSupportFocus ;
636 }
637
638 OSErr AGAGetBestControlRect (ControlHandle inControl,
639 Rect * outRect,
640 SInt16 * outBaseLineOffset)
641 {
642 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
643 ControlCalcSizeRec rec ;
644 rec.width = (**inControl).contrlRect.right - (**inControl).contrlRect.left ;
645 rec.height = (**inControl).contrlRect.bottom - (**inControl).contrlRect.top ;
646 rec.baseLine = 0;
647
648 OSErr err = info->defProc( info->procID , inControl , kControlMsgCalcBestRect , (long) &rec ) ;
649 if ( !err )
650 {
651 outRect->left = outRect->top = 0 ;
652 outRect->right = rec. width ;
653 outRect->bottom = rec. height ;
654 *outBaseLineOffset = rec. baseLine ;
655 }
656 return err ;
657 }
658
659
660 OSErr AGAGetControlData (ControlHandle inControl,
661 ControlPartCode inPart,
662 ResType inTagName,
663 Size inBufferSize,
664 Ptr outBuffer,
665 Size * outActualSize)
666 {
667 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
668 ControlDataAccessRec rec ;
669
670 rec.tag = inTagName ;
671 rec.part = inPart ;
672 rec.size = inBufferSize ;
673 rec.dataPtr = outBuffer ;
674
675 OSErr err = info->defProc( info->procID , inControl , kControlMsgGetData , (long) &rec ) ;
676 *outActualSize = rec.size ;
677 return err ;
678 }
679
680 OSErr AGAGetControlDataSize (ControlHandle inControl,
681 ControlPartCode inPart,
682 ResType inTagName,
683 Size * outMaxSize)
684 {
685 return AGAGetControlData( inControl , inPart , inTagName , 0 , NULL , outMaxSize ) ;
686 }
687
688
689 void NewExtCDEFInfo( ControlHandle theControl , ControlDefProcPtr defproc , SInt16 procID , long refcon )
690 {
691 ExtCDEFInfo* info = (ExtCDEFInfo* ) malloc( sizeof( ExtCDEFInfo ) ) ;
692 info->defProc = defproc ;
693 info->hasFocus = false ;
694 info->magic = kExtCDEFMagic ;
695 info->contrlRfCon = refcon ;
696 info->procID = procID ;
697 info->containerControl = NULL ;
698 info->children = NewHandle(0) ;
699 info->fontStyle.flags = 0 ;
700 info->fontStyle.font = 0 ;
701 info->fontStyle.size = 12 ;
702 info->fontStyle.style = 0 ;
703 info->fontStyle.mode = 0 ;
704 info->fontStyle.just = 0 ;
705 info->fontStyle.foreColor = gAGARamp[ kAGABlack ] ;
706 info->fontStyle.backColor = gAGARamp[ kAGA2 ] ;
707 (**theControl).contrlRfCon = (long) info ;
708 defproc( info->procID, theControl, initCntl, 0) ;
709 }
710
711 void DisposeExtCDEFInfo( ControlHandle theControl)
712 {
713 if ( AGATestForNewControl( theControl ) )
714 {
715 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**theControl).contrlRfCon ;
716 if ( info )
717 {
718 DisposeHandle( info->children ) ;
719 info->children = NULL ;
720 free( (void*) (**theControl).contrlRfCon ) ;
721 }
722 }
723 }
724
725 const short kAGAProgressHeight = 14 ;
726
727 void AGADrawRectPlacard( const Rect *inRect , eAGAState inState , bool fill = false ) ;
728 void AGADrawRectProgress( const Rect *inRect , eAGAState inState , double percentage ) ;
729
730 void AGADrawRectPlacard( const Rect *inRect , eAGAState inState , bool fill )
731 {
732 Rect rect = *inRect ;
733 RGBColor pixelColor ;
734 if ( inState == kAGAStateInactive )
735 {
736 RGBForeColor( &gAGARamp[ kAGA10 ] ) ;
737 FrameRect( &rect ) ;
738 if ( fill )
739 {
740 InsetRect( &rect , 1 , 1 ) ;
741 RGBForeColor( &gAGARamp[ kAGA1 ] ) ;
742 PaintRect( &rect ) ;
743 }
744 return ;
745 }
746
747 RGBForeColor( &gAGARamp[ kAGABlack ] ) ;
748 FrameRect( &rect ) ;
749 InsetRect( &rect , 1 , 1 ) ;
750
751 if ( inState == kAGAStateEnabled || inState == kAGAStateDisabled )
752 RGBForeColor( &gAGARamp[ kAGAWhite ] ) ;
753 else
754 RGBForeColor( &gAGARamp[ kAGABlack ] ) ;
755
756 MoveTo( rect.left , rect.bottom - 1 -1 ) ;
757 LineTo( rect.left , rect.top ) ;
758 LineTo( rect.right-1-1 , rect.top ) ;
759
760 if ( inState == kAGAStateEnabled || inState == kAGAStateDisabled )
761 pixelColor = gAGARamp[ kAGA2 ] ;
762 else
763 pixelColor = gAGARamp[ kAGA8 ] ;
764
765 SetCPixel( rect.right-1 , rect.top , &pixelColor ) ;
766 SetCPixel( rect.left , rect.bottom-1 , &pixelColor ) ;
767
768 if ( inState == kAGAStateEnabled )
769 RGBForeColor( &gAGARamp[ kAGA5 ] ) ;
770 else if ( inState == kAGAStateDisabled )
771 RGBForeColor( &gAGARamp[ kAGA4 ] ) ;
772 else
773 RGBForeColor( &gAGARamp[ kAGA6 ] ) ;
774
775 MoveTo( rect.left + 1 , rect.bottom-1 ) ;
776 LineTo( rect.right-1 , rect.bottom-1 ) ;
777 LineTo( rect.right-1 , rect.top-1 ) ;
778
779 if ( fill )
780 {
781 InsetRect( &rect , 1 , 1 ) ;
782 if ( inState == kAGAStateEnabled || inState == kAGAStateDisabled )
783 RGBForeColor( &gAGARamp[ kAGA2 ] ) ;
784 else
785 RGBForeColor( &gAGARamp[ kAGA8 ] ) ;
786 PaintRect( &rect ) ;
787 }
788 }
789
790 void AGADrawRectProgress( const Rect *inRect , eAGAState inState , double percentage )
791 {
792 Rect rect = *inRect ;
793 rect.bottom = rect.top + 14 ;
794 RGBColor pixelColor ;
795
796 RGBForeColor( &gAGARamp[ kAGA5 ]) ;
797 MoveTo( rect.left , rect.bottom - 1 -1 ) ;
798 LineTo( rect.left , rect.top ) ;
799 LineTo( rect.right-1-1 , rect.top ) ;
800
801 RGBForeColor( &gAGARamp[ kAGAWhite ] ) ;
802 MoveTo( rect.left + 1 , rect.bottom -1 ) ;
803 LineTo( rect.right-1 , rect.bottom -1 ) ;
804 LineTo( rect.right-1 , rect.top-1 ) ;
805
806 InsetRect( &rect , 1 , 1 ) ;
807 RGBForeColor( &gAGARamp[ kAGABlack ] ) ;
808
809 Rect barLeft = rect , barRight = rect ;
810
811 int position = percentage * ( rect.right - rect.left ) ;
812 barLeft.right = barLeft.left + position ;
813 barRight.left = barLeft.left + position ;
814 FrameRect( &barLeft ) ;
815 FrameRect( &barRight ) ;
816
817 InsetRect( &barLeft , 1 , 1 ) ;
818
819 InsetRect( &barRight , 1 , 1 ) ;
820
821 if ( !EmptyRect( &barRight ) )
822 {
823 RGBForeColor( &gAGARamp[ kAGA10 ] ) ;
824 MoveTo( barRight.left , barRight.bottom -1 ) ;
825 LineTo( barRight.left , barRight.top ) ;
826 barRight.left += 1 ;
827 if ( !EmptyRect( &barRight ) )
828 {
829 RGBForeColor( &gAGARamp[ kAGA7 ] ) ;
830 MoveTo( barRight.left , barRight.bottom-1 ) ;
831 LineTo( barRight.left , barRight.top ) ;
832 LineTo( barRight.right-1-1 , barRight.top ) ;
833 RGBForeColor( &gAGARamp[ kAGA2 ] ) ;
834 MoveTo( barRight.left + 1 , barRight.bottom -1 ) ;
835 LineTo( barRight.right-1 , barRight.bottom -1 ) ;
836 LineTo( barRight.right-1 , barRight.top - 1) ;
837 pixelColor = gAGARamp[ kAGA4 ] ;
838 SetCPixel( barRight.right-1 , barRight.top , &pixelColor ) ;
839 InsetRect( &barRight , 1 , 1) ;
840 if ( !EmptyRect( &barRight ) )
841 {
842 RGBForeColor( &gAGARamp[ kAGA4 ] ) ;
843 PaintRect( &barRight ) ;
844 }
845 }
846 if ( !EmptyRect( &barLeft ) )
847 {
848 RGBForeColor( &gAGABlueRamp[ kAGA8 ] ) ;
849 MoveTo( barLeft.left , barLeft.bottom -1 ) ;
850 LineTo( barLeft.left , barLeft.top ) ;
851 LineTo( barLeft.left+1 , barLeft.top ) ;
852 RGBForeColor( &gAGABlueRamp[ kAGA12 ] ) ;
853 MoveTo( barLeft.left + 2, barLeft.bottom-1 ) ;
854 LineTo( barLeft.right-1 , barLeft.bottom-1 ) ;
855 LineTo( barLeft.right-1 , barLeft.top -1 ) ;
856 RGBForeColor( &gAGABlueRamp[ kAGA10 ] ) ;
857 MoveTo( barLeft.left + 2, barLeft.top ) ;
858 LineTo( barLeft.right-1 , barLeft.top ) ;
859 pixelColor = gAGABlueRamp[ kAGA10] ;
860 SetCPixel( barLeft.left + 1, barLeft.bottom-1 , &pixelColor ) ;
861 InsetRect( &barLeft , 1 , 1 ) ;
862 if ( !EmptyRect( &barLeft ) )
863 {
864 // do more here
865 RGBForeColor( &gAGABlueRamp[ kAGA3 ] ) ;
866 PaintRect( &barLeft ) ;
867 }
868 }
869 }
870 }
871
872 SInt32 AGAGetDataHelper( ControlDataAccessRec *rec , Size size , Ptr data ) ;
873 SInt32 AGAGetDataHelper( ControlDataAccessRec *rec , Size size , Ptr data )
874 {
875 if ( rec->dataPtr == NULL )
876 {
877 rec->size = size ;
878 return noErr ;
879 }
880 else
881 {
882 if ( rec->size < size )
883 return errDataSizeMismatch ;
884
885 rec->size = size ;
886 memcpy( rec->dataPtr , data , size ) ;
887 return noErr ;
888 }
889 }
890
891 void AGASetFontStyle( ControlFontStyleRec *fontstyle ) ;
892 void AGASetFontStyle( ControlFontStyleRec *fontstyle )
893 {
894 if( fontstyle->font >= 0 )
895 {
896 ::TextFont( fontstyle->font ) ;
897 ::TextSize( fontstyle->size ) ;
898 ::TextFace( fontstyle->style ) ;
899 }
900 else
901 {
902 switch( fontstyle->font )
903 {
904 case kControlFontBigSystemFont :
905 ::TextFont( systemFont ) ;
906 ::TextSize( 12 ) ;
907 ::TextFace( 0 ) ;
908 break ;
909 case kControlFontSmallSystemFont :
910 ::TextFont( kFontIDGeneva ) ;
911 ::TextSize( 10 ) ;
912 ::TextFace( 0 ) ;
913 break ;
914 case kControlFontSmallBoldSystemFont :
915 ::TextFont( kFontIDGeneva ) ;
916 ::TextSize( 10 ) ;
917 ::TextFace( bold ) ;
918 break ;
919 }
920 }
921 ::RGBForeColor( &fontstyle->foreColor ) ;
922 ::RGBBackColor( &fontstyle->backColor ) ;
923 } ;
924
925 class AGAPortHelper
926 {
927 public :
928 AGAPortHelper()
929 {
930 GetPenState( &oldPenState ) ;
931 GetBackColor( &oldBackColor ) ;
932 GetForeColor( &oldForeColor ) ;
933
934 GetPort( &port ) ;
935 clip = NewRgn() ;
936 GetClip( clip );
937 font = port->txFont;
938 size = port->txSize;
939 style = port->txFace;
940 mode = port->txMode;
941
942 }
943 ~AGAPortHelper()
944 {
945 SetPort( port ) ;
946 SetClip( clip ) ;
947 DisposeRgn( clip ) ;
948 RGBForeColor(&oldForeColor);
949 RGBBackColor(&oldBackColor);
950 SetPenState(&oldPenState);
951
952 TextFont( font );
953 TextSize( size );
954 TextFace( style );
955 TextMode( mode );
956 }
957
958 private :
959 GrafPtr port ;
960 PenState oldPenState ;
961 RGBColor oldForeColor ;
962 RGBColor oldBackColor ;
963 RgnHandle clip ;
964 short font ;
965 short size ;
966 short style ;
967 short mode ;
968 } ;
969
970 pascal SInt32 AGAProgressBarDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param)
971 {
972 switch( message )
973 {
974 case drawCntl :
975 {
976 if (!(**theControl).contrlVis)
977 return 0 ;
978 PenState oldPenState;
979 RGBColor oldForeColor ;
980 RGBColor oldBackColor ;
981 RGBColor backColor ;
982 RGBColor foreColor ;
983
984 GetPenState( &oldPenState ) ;
985 GetBackColor( &oldBackColor ) ;
986 GetForeColor( &oldForeColor ) ;
987
988 {
989 int theValue = GetControlValue(theControl) ;
990 int theMinimum = GetControlMinimum(theControl) ;
991 int theMaximum = GetControlMaximum(theControl) ;
992
993 AGADrawRectProgress( &(**theControl).contrlRect , kAGAStateEnabled , (( double )( theValue - theMinimum )) / ( theMaximum-theMinimum ) ) ;
994 }
995
996 RGBForeColor(&oldForeColor);
997 RGBBackColor(&oldBackColor);
998 SetPenState(&oldPenState);
999 }
1000 break ;
1001 case calcCntlRgn :
1002 RectRgn((RgnHandle) param , &(**theControl).contrlRect ) ;
1003 break ;
1004 default :
1005 break ;
1006 }
1007
1008 return 0 ;
1009 }
1010
1011
1012 pascal SInt32 AGAPlacardDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param)
1013 {
1014 switch( message )
1015 {
1016 case drawCntl :
1017 {
1018 if (!(**theControl).contrlVis)
1019 return 0 ;
1020 PenState oldPenState;
1021 RGBColor oldForeColor ;
1022 RGBColor oldBackColor ;
1023 RGBColor backColor ;
1024 RGBColor foreColor ;
1025
1026 GetPenState( &oldPenState ) ;
1027 GetBackColor( &oldBackColor ) ;
1028 GetForeColor( &oldForeColor ) ;
1029
1030 {
1031 AGADrawRectPlacard( &(**theControl).contrlRect , kAGAStateEnabled , true ) ;
1032 }
1033
1034 RGBForeColor(&oldForeColor);
1035 RGBBackColor(&oldBackColor);
1036 SetPenState(&oldPenState);
1037 }
1038 break ;
1039 default :
1040 break ;
1041 }
1042
1043 return 0 ;
1044 }
1045
1046 pascal SInt32 AGABevelButtonDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param)
1047 {
1048 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**theControl).contrlRfCon ;
1049 switch( message )
1050 {
1051 case initCntl :
1052 info->privateData = (long) malloc( sizeof( ControlButtonContentInfo ) ) ;
1053 memset( (char*) info->privateData , 0 , sizeof( ControlButtonContentInfo ) ) ;
1054 break ;
1055 case dispCntl :
1056 free( (void*) info->privateData ) ;
1057 break ;
1058 case kControlMsgSetData :
1059 {
1060 ControlDataAccessRec *rec = (ControlDataAccessRec *) param ;
1061 if ( rec->tag == kControlBevelButtonContentTag )
1062 {
1063 memcpy( (char*) info->privateData , rec->dataPtr , rec->size ) ;
1064 return noErr ;
1065 }
1066 return errDataNotSupported ;
1067 }
1068 case kControlMsgCalcBestRect :
1069 {
1070 ControlCalcSizeRec *rec = (ControlCalcSizeRec *) param ;
1071 rec->width = 0 ;
1072 rec->height = 20 ;
1073 rec->baseLine = 0;
1074 }
1075 break ;
1076 case drawCntl :
1077 {
1078 if (!(**theControl).contrlVis)
1079 return 0 ;
1080
1081 {
1082 AGAPortHelper help() ;
1083 AGASetFontStyle( &info->fontStyle ) ;
1084 Boolean mRadioBehavior = false ;
1085
1086 int mValue = GetControlValue( theControl ) ;
1087 long theValue = (mRadioBehavior ? mValue : 0);
1088 Boolean inPushed = (**theControl).contrlHilite ;
1089 Boolean down = inPushed || (theValue != 0);
1090 Boolean hasColor = 1;
1091 int mEnabled = 1 ;
1092 int triState_Off = 3 ;
1093 Boolean disabled = (mEnabled == triState_Off);
1094
1095 Rect frame = (**theControl).contrlRect ;
1096
1097 // Draw the black frame;
1098 ::MoveTo(frame.left + 1, frame.top);
1099 ::LineTo(frame.right - 2, frame.top);
1100 ::MoveTo(frame.right - 1, frame.top + 1);
1101 ::LineTo(frame.right - 1, frame.bottom - 2);
1102 ::MoveTo(frame.right - 2, frame.bottom - 1);
1103 ::LineTo(frame.left + 1, frame.bottom - 1);
1104 ::MoveTo(frame.left, frame.bottom - 2);
1105 ::LineTo(frame.left, frame.top + 1);
1106
1107 // Draw the inside (w/o the Icon)
1108 ::InsetRect(&frame, 1, 1);
1109 if (hasColor)
1110 {
1111 AGASetFontStyle( &info->fontStyle ) ;
1112 if (down)
1113 ::RGBBackColor(&gAGAColorArray[4]);
1114 }
1115 ::EraseRect(&frame);
1116
1117 // Draw the shadows
1118 if (hasColor)
1119 {
1120 ::RGBForeColor(&gAGAColorArray[7]);
1121 if (down)
1122 {
1123 ::MoveTo(frame.left, frame.bottom - 1);
1124 ::LineTo(frame.left, frame.top);
1125 ::LineTo(frame.right - 1, frame.top);
1126 }
1127 else
1128 {
1129 ::MoveTo(frame.right - 1, frame.top);
1130 ::LineTo(frame.right - 1, frame.bottom - 1);
1131 ::LineTo(frame.left, frame.bottom - 1);
1132 ::MoveTo(frame.right - 2, frame.top + 1);
1133 ::LineTo(frame.right - 2, frame.bottom - 2);
1134 ::LineTo(frame.left + 1, frame.bottom - 2);
1135 ::ForeColor(whiteColor);
1136 ::MoveTo(frame.left, frame.bottom - 2);
1137 ::LineTo(frame.left, frame.top);
1138 ::LineTo(frame.right - 2, frame.top);
1139 }
1140 }
1141
1142 // Draw the Icon
1143
1144 frame = (**theControl).contrlRect ;
1145 PictInfo theInfo ;
1146 PicHandle thePict = ((ControlButtonContentInfo*) info->privateData)->u.picture ;
1147 if ( thePict )
1148 {
1149 GetPictInfo( thePict , &theInfo , 0 , 0 , systemMethod , 0 ) ;
1150 Rect bitmaprect = { 0 , 0 , theInfo.sourceRect.bottom - theInfo.sourceRect.top ,
1151 theInfo.sourceRect.right - theInfo.sourceRect.left } ;
1152 ::OffsetRect( &bitmaprect , (frame.right + frame.left)/2 - bitmaprect.right / 2 , (frame.bottom + frame.top) / 2 - bitmaprect.bottom / 2 ) ;
1153 if (inPushed)
1154 ::OffsetRect( &bitmaprect , 1 , 1 ) ;
1155 ::DrawPicture( thePict , &bitmaprect ) ;
1156 }
1157 }
1158 }
1159 break ;
1160 case testCntl :
1161 {
1162 Point pt ;
1163 pt.h = LoWord( param ) ;
1164 pt.v = HiWord( param ) ;
1165 if ( PtInRect( pt , &(**theControl).contrlRect ) )
1166 return kControlButtonPart ;
1167 else
1168 return NULL ;
1169 }
1170 break ;
1171 case calcCntlRgn :
1172 RectRgn((RgnHandle) param , &(**theControl).contrlRect ) ;
1173 break ;
1174 case posCntl :
1175 {
1176 Point pt ;
1177 pt.h = LoWord( param ) ;
1178 pt.v = HiWord( param ) ;
1179 if ( PtInRect( pt , &(**theControl).contrlRect ) )
1180 return kControlButtonPart ;
1181 else
1182 return NULL ;
1183 }
1184 break ;
1185 default :
1186 break ;
1187 }
1188
1189 return 0 ;
1190 }
1191
1192 pascal SInt32 AGAButtonDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param)
1193 {
1194 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**theControl).contrlRfCon ;
1195 switch( message )
1196 {
1197 case initCntl :
1198 (**theControl).contrlData = NULL ;
1199 break ;
1200 case kControlMsgSetData :
1201 {
1202 ControlDataAccessRec *rec = (ControlDataAccessRec *) param ;
1203 Boolean isDefault = *((Boolean*)rec->dataPtr ) ;
1204 (**theControl).contrlData = (Handle) isDefault ;
1205 return noErr ;
1206 }
1207 break ;
1208 case kControlMsgCalcBestRect :
1209 {
1210 ControlCalcSizeRec *rec = (ControlCalcSizeRec *) param ;
1211 rec->width = 0 ;
1212 rec->height = 20 ;
1213 rec->baseLine = 0;
1214 }
1215 break ;
1216 case drawCntl :
1217 {
1218 if (!(**theControl).contrlVis)
1219 return 0 ;
1220
1221 {
1222 AGAPortHelper help() ;
1223 AGASetFontStyle( &info->fontStyle ) ;
1224 Boolean mRadioBehavior = false ;
1225
1226 Rect frame, tempRect;
1227 int mValue = GetControlValue( theControl ) ;
1228 long theValue = (mRadioBehavior ? mValue : 0);
1229 Boolean inPushed = (**theControl).contrlHilite ;
1230 Boolean down = inPushed || (theValue != 0);
1231 Boolean hasColor = 1;
1232 int mEnabled = 1 ;
1233 int triState_Off = 3 ;
1234 Boolean disabled = (mEnabled == triState_Off);
1235
1236 // theState.Normalize();
1237 // CalcLocalFrameRect(frame);
1238 frame= (**theControl).contrlRect ;
1239
1240 if ( (**theControl).contrlData )
1241 {
1242 InsetRect( &frame , -3 , -3 ) ;
1243 {
1244 ::MoveTo(frame.left + 3, frame.top);
1245 ::LineTo(frame.right - 4, frame.top);
1246 ::LineTo(frame.right - 1, frame.top + 3);
1247 ::LineTo(frame.right - 1, frame.bottom - 4);
1248 ::LineTo(frame.right - 4, frame.bottom - 1);
1249 ::LineTo(frame.left + 3, frame.bottom - 1);
1250 ::LineTo(frame.left, frame.bottom - 4);
1251 ::LineTo(frame.left, frame.top + 3);
1252 ::LineTo(frame.left + 3, frame.top);
1253
1254 if (hasColor)
1255 {
1256 const RGBColor *col = gAGAColorArray;
1257 for (int i = 0; i < 5; i++)
1258 for (int j = 0; j < 5; j++)
1259 {
1260 if (LAGADefaultOutline_mCorners[0][i][j] != -1)
1261 ::SetCPixel(frame.left + j, frame.top + i, &col[LAGADefaultOutline_mCorners[0][i][j]]);
1262 if (LAGADefaultOutline_mCorners[1][i][j] != -1)
1263 ::SetCPixel(frame.right - 5 + j, frame.top + i, &col[LAGADefaultOutline_mCorners[1][i][j]]);
1264 if (LAGADefaultOutline_mCorners[2][i][j] != -1)
1265 ::SetCPixel(frame.left + j, frame.bottom - 5 + i, &col[LAGADefaultOutline_mCorners[2][i][j]]);
1266 if (LAGADefaultOutline_mCorners[3][i][j] != -1)
1267 ::SetCPixel(frame.right - 5 + j, frame.bottom - 5 + i, &col[LAGADefaultOutline_mCorners[3][i][j]]);
1268 }
1269
1270 ::RGBForeColor(&gAGAColorArray[2]);
1271 ::MoveTo(frame.left + 1, frame.top + 5);
1272 ::LineTo(frame.left + 1, frame.bottom - 6);
1273 ::MoveTo(frame.left + 5, frame.top + 1);
1274 ::LineTo(frame.right - 6, frame.top + 1);
1275
1276 ::RGBForeColor(&gAGAColorArray[5]);
1277 ::MoveTo(frame.left + 4, frame.top + 2);
1278 ::LineTo(frame.right - 5, frame.top + 2);
1279 ::LineTo(frame.right - 3, frame.top + 4);
1280 ::LineTo(frame.right - 3, frame.bottom - 5);
1281 ::LineTo(frame.right - 5, frame.bottom - 3);
1282 ::LineTo(frame.left + 4, frame.bottom - 3);
1283 ::LineTo(frame.left + 2, frame.bottom - 5);
1284 ::LineTo(frame.left + 2, frame.top + 4);
1285 ::LineTo(frame.left + 4, frame.top + 2);
1286
1287 ::RGBForeColor(&gAGAColorArray[8]);
1288 ::MoveTo(frame.right - 2, frame.top + 5);
1289 ::LineTo(frame.right - 2, frame.bottom - 6);
1290 ::MoveTo(frame.left + 5, frame.bottom - 2);
1291 ::LineTo(frame.right - 6, frame.bottom - 2);
1292 }
1293 }
1294 }
1295
1296 AGASetFontStyle( &info->fontStyle ) ;
1297 frame= (**theControl).contrlRect ;
1298
1299 tempRect = frame;
1300 ::InsetRect(&tempRect, 1, 1);
1301 if (hasColor)
1302 {
1303 if (down)
1304 ::RGBBackColor(&gAGAColorArray[4]);
1305 }
1306 EraseRect(&tempRect);
1307
1308 // Draw the frame;
1309 if (disabled)
1310 {
1311 if (hasColor)
1312 ::RGBForeColor(&gAGAColorArray[7]);
1313 else
1314 ::PenPat(&qd.gray);
1315 }
1316 ::MoveTo(frame.left + 2, frame.top);
1317 ::LineTo(frame.right - 3, frame.top);
1318 ::LineTo(frame.right - 1, frame.top + 2);
1319 ::LineTo(frame.right - 1, frame.bottom - 3);
1320 ::LineTo(frame.right - 3, frame.bottom - 1);
1321 ::LineTo(frame.left + 2, frame.bottom - 1);
1322 ::LineTo(frame.left, frame.bottom - 3);
1323 ::LineTo(frame.left, frame.top + 2);
1324 ::LineTo(frame.left + 2, frame.top);
1325 if (disabled && !hasColor)
1326 ::PenNormal();
1327
1328 // Draw the four corners around
1329 if (hasColor)
1330 {
1331 short pattern = (disabled ? 2 : (down ? 1 : 0));
1332 const RGBColor *col = gAGAColorArray;
1333 for (int i = 0; i < 4; i++)
1334 for (int j = 0; j < 4; j++)
1335 {
1336 if (LAGAPushButton_mCorners[pattern][0][i][j] != -1)
1337 ::SetCPixel(frame.left + j, frame.top + i, &col[LAGAPushButton_mCorners[pattern][0][i][j]]);
1338 if (LAGAPushButton_mCorners[pattern][1][i][j] != -1)
1339 ::SetCPixel(frame.right - 4 + j, frame.top + i, &col[LAGAPushButton_mCorners[pattern][1][i][j]]);
1340 if (LAGAPushButton_mCorners[pattern][2][i][j] != -1)
1341 ::SetCPixel(frame.left + j, frame.bottom - 4 + i, &col[LAGAPushButton_mCorners[pattern][2][i][j]]);
1342 if (LAGAPushButton_mCorners[pattern][3][i][j] != -1)
1343 ::SetCPixel(frame.right - 4 + j, frame.bottom - 4 + i, &col[LAGAPushButton_mCorners[pattern][3][i][j]]);
1344 }
1345
1346 if (down)
1347 ::RGBForeColor(&gAGAColorArray[8]);
1348 else
1349 ::RGBForeColor(&gAGAColorArray[2]);
1350 ::MoveTo(frame.left + 1, frame.top + 4);
1351 ::LineTo(frame.left + 1, frame.bottom - 5);
1352 ::MoveTo(frame.left + 4, frame.top + 1);
1353 ::LineTo(frame.right - 5, frame.top + 1);
1354
1355 if (!down)
1356 {
1357 if (disabled)
1358 ::RGBForeColor(&gAGAColorArray[1]);
1359 else
1360 ::ForeColor(whiteColor);
1361 ::MoveTo(frame.left + 2, frame.bottom - 5);
1362 ::LineTo(frame.left + 2, frame.top + 2);
1363 ::LineTo(frame.right - 5, frame.top + 2);
1364
1365 if (disabled)
1366 ::RGBForeColor(&gAGAColorArray[5]);
1367 else
1368 ::RGBForeColor(&gAGAColorArray[8]);
1369 ::MoveTo(frame.left + 4, frame.bottom - 2);
1370 ::LineTo(frame.right - 5, frame.bottom - 2);
1371 ::MoveTo(frame.right - 2, frame.bottom - 5);
1372 ::LineTo(frame.right - 2, frame.top + 4);
1373
1374 if (disabled)
1375 ::RGBForeColor(&gAGAColorArray[4]);
1376 else
1377 ::RGBForeColor(&gAGAColorArray[5]);
1378 ::MoveTo(frame.left + 4, frame.bottom - 3);
1379 ::LineTo(frame.right - 5, frame.bottom - 3);
1380 ::MoveTo(frame.right - 3, frame.bottom - 5);
1381 ::LineTo(frame.right - 3, frame.top + 4);
1382 }
1383 }
1384 AGASetFontStyle( &info->fontStyle ) ;
1385 int x = ( (**theControl).contrlRect.left + (**theControl).contrlRect.right ) / 2 ;
1386 int y = ( (**theControl).contrlRect.top + (**theControl).contrlRect.bottom ) / 2 ;
1387 FontInfo fi ;
1388 ::GetFontInfo( &fi ) ;
1389
1390 y += fi.ascent / 2 ;
1391 int length = (**theControl).contrlTitle[0] ;
1392 if ( length )
1393 {
1394 int width = TextWidth( &(**theControl).contrlTitle[1] , 0, length ) ;
1395 x -= width / 2 ;
1396 ::MoveTo( x , y );
1397 ::DrawText( &(**theControl).contrlTitle[1] , 0, length);
1398 }
1399
1400 }
1401 }
1402 break ;
1403 case testCntl :
1404 {
1405 Point pt ;
1406 pt.h = LoWord( param ) ;
1407 pt.v = HiWord( param ) ;
1408 if ( PtInRect( pt , &(**theControl).contrlRect ) )
1409 return kControlButtonPart ;
1410 else
1411 return NULL ;
1412 }
1413 break ;
1414 case calcCntlRgn :
1415 RectRgn((RgnHandle) param , &(**theControl).contrlRect ) ;
1416 break ;
1417 case posCntl :
1418 {
1419 Point pt ;
1420 pt.h = LoWord( param ) ;
1421 pt.v = HiWord( param ) ;
1422 if ( PtInRect( pt , &(**theControl).contrlRect ) )
1423 return kControlButtonPart ;
1424 else
1425 return NULL ;
1426 }
1427 break ;
1428 default :
1429 break ;
1430 }
1431
1432 return 0 ;
1433 }
1434
1435 const int kAGACheckBoxWidth = 12 ;
1436 const int kAGACheckBoxHeigth = 12 ;
1437
1438 pascal SInt32 AGACheckBoxDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param)
1439 {
1440 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**theControl).contrlRfCon ;
1441 switch( message )
1442 {
1443 case drawCntl :
1444 {
1445 if (!(**theControl).contrlVis)
1446 return 0 ;
1447 PenState oldPenState;
1448 RGBColor oldForeColor ;
1449 RGBColor oldBackColor ;
1450 RGBColor backColor ;
1451 RGBColor foreColor ;
1452
1453
1454 {
1455 if (!(**theControl).contrlVis)
1456 return 0 ;
1457
1458 {
1459 AGAPortHelper help() ;
1460 Rect frame = (**theControl).contrlRect ;
1461 Boolean hasColor = true;
1462 Boolean disabled = (*theControl)->contrlHilite == 255 ;
1463 int mValue = GetControlValue( theControl ) ;
1464 Boolean inPushed = (**theControl).contrlHilite ;
1465 int mEnabled = 1 ;
1466 int triState_Off = 3 ;
1467
1468 frame.right = frame.left + kAGACheckBoxWidth;
1469 frame.bottom = frame.top + kAGACheckBoxHeigth;
1470
1471 // Draw the frame of the checkbox
1472 if (disabled)
1473 if (hasColor)
1474 ::RGBForeColor(&gAGAColorArray[7]);
1475 else
1476 PenPat(&qd.gray);
1477
1478 ::FrameRect(&frame);
1479
1480 if (!hasColor)
1481 PenNormal();
1482
1483 ::InsetRect(&frame, 1, 1);
1484 if (hasColor)
1485 ::RGBBackColor(inPushed ? &gAGAColorArray[8] : &gAGAColorArray[2]);
1486 ::EraseRect(&frame);
1487
1488 if (hasColor)
1489 {
1490 if (inPushed)
1491 ::RGBForeColor(&gAGAColorArray[10]);
1492 else
1493 ForeColor(whiteColor);
1494 ::MoveTo(frame.left, frame.bottom - 2);
1495 ::LineTo(frame.left, frame.top);
1496 ::LineTo(frame.right - 2, frame.top);
1497
1498 if (inPushed)
1499 ::RGBForeColor(&gAGAColorArray[6]);
1500 else
1501 ::RGBForeColor(mEnabled != triState_Off ? &gAGAColorArray[7] : &gAGAColorArray[5]);
1502 ::MoveTo(frame.left + 1, frame.bottom - 1);
1503 ::LineTo(frame.right - 1, frame.bottom - 1);
1504 ::LineTo(frame.right - 1, frame.top + 1);
1505 }
1506
1507 if (mValue)
1508 {
1509 if (mValue == 1)
1510 {
1511 // Checked state
1512 if (hasColor)
1513 {
1514 ::RGBForeColor(inPushed ? &gAGAColorArray[10] : &gAGAColorArray[5]);
1515 ::MoveTo(frame.left + 3, frame.bottom - 2);
1516 ::LineTo(frame.right - 2, frame.top + 3);
1517 ::MoveTo(frame.right - 2, frame.bottom - 2);
1518 ::LineTo(frame.right - 2, frame.bottom - 2);
1519
1520 if (mEnabled != triState_Off)
1521 ::RGBForeColor(inPushed ? &gAGAColorArray[11] : &gAGAColorArray[8]);
1522 ::MoveTo(frame.left + 3, frame.bottom - 3);
1523 ::LineTo(frame.right - 2, frame.top + 2);
1524 ::MoveTo(frame.right - 2, frame.bottom - 3);
1525 ::LineTo(frame.right - 2, frame.bottom - 3);
1526
1527 if (mEnabled != triState_Off)
1528 ::ForeColor(blackColor);
1529 else
1530 ::RGBForeColor(&gAGAColorArray[7]);
1531 }
1532 ::MoveTo(frame.left + 2, frame.top + 1);
1533 ::LineTo(frame.right - 3, frame.bottom - 4);
1534 ::MoveTo(frame.left + 2, frame.top + 2);
1535 ::LineTo(frame.right - 3, frame.bottom - 3);
1536 ::MoveTo(frame.left + 2, frame.bottom - 4);
1537 ::LineTo(frame.right - 3, frame.top + 1);
1538 ::MoveTo(frame.left + 2, frame.bottom - 3);
1539 ::LineTo(frame.right - 3, frame.top + 2);
1540 }
1541 else
1542 {
1543 // Mixed state
1544 if (hasColor)
1545 {
1546 ::RGBForeColor(inPushed ? &gAGAColorArray[10] : &gAGAColorArray[5]);
1547 ::MoveTo(frame.left + 3, frame.top + 6);
1548 ::LineTo(frame.right - 2, frame.top + 6);
1549 ::LineTo(frame.right - 2, frame.top + 4);
1550
1551 if (mEnabled != triState_Off)
1552 ::ForeColor(blackColor);
1553 else
1554 ::RGBForeColor(&gAGAColorArray[7]);
1555 }
1556 ::MoveTo(frame.left + 2, frame.top + 4);
1557 ::LineTo(frame.right - 3, frame.top + 4);
1558 ::MoveTo(frame.left + 2, frame.top + 5);
1559 ::LineTo(frame.right - 3, frame.top + 5);
1560 }
1561 }
1562
1563 if (inPushed && !hasColor)
1564 InvertRect(&frame);
1565
1566 AGASetFontStyle( &info->fontStyle ) ;
1567 int x = (**theControl).contrlRect.left + kAGACheckBoxWidth + 5 ;
1568 int y = ( (**theControl).contrlRect.top + (**theControl).contrlRect.bottom ) / 2 ;
1569 FontInfo fi ;
1570 ::GetFontInfo( &fi ) ;
1571
1572 y += fi.ascent / 2 ;
1573 ::MoveTo( x , y );
1574 int length = (**theControl).contrlTitle[0] ;
1575 if ( length )
1576 {
1577 ::DrawText( &(**theControl).contrlTitle[1] , 0, length);
1578 }
1579 }
1580 }
1581
1582 }
1583 break ;
1584 case testCntl :
1585 {
1586 Point pt ;
1587 pt.h = LoWord( param ) ;
1588 pt.v = HiWord( param ) ;
1589 if ( PtInRect( pt , &(**theControl).contrlRect ) && ((*theControl)->contrlVis != 0) && ((*theControl)->contrlHilite != 255) )
1590 return kControlCheckBoxPart ;
1591 else
1592 return NULL ;
1593 }
1594 break ;
1595 case posCntl :
1596 {
1597 Point pt ;
1598 pt.h = LoWord( param ) ;
1599 pt.v = HiWord( param ) ;
1600 if ( PtInRect( pt , &(**theControl).contrlRect ) )
1601 {
1602 if ( (**theControl).contrlValue )
1603 (**theControl).contrlValue = 0 ;
1604 else
1605 (**theControl).contrlValue = 1 ;
1606
1607 return 0 ;
1608 }
1609 else
1610 return 0 ;
1611 }
1612 break ;
1613 case calcThumbRgn :
1614 case calcCntlRgn :
1615 if ( !EmptyRect(&(**theControl).contrlRect ) )
1616 RectRgn((RgnHandle) param , &(**theControl).contrlRect ) ;
1617 break ;
1618 case kControlMsgCalcBestRect :
1619 {
1620 ControlCalcSizeRec *rec = (ControlCalcSizeRec *) param ;
1621 rec->width = (**theControl).contrlRect.right - (**theControl).contrlRect.left ;
1622 rec->height = kAGACheckBoxHeigth ;
1623 rec->baseLine = 0;
1624 }
1625 break ;
1626 default :
1627 break ;
1628 }
1629
1630 return 0 ;
1631 }
1632
1633 pascal SInt32 AGARadioButtonDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param)
1634 {
1635 //TO DO
1636 /* ExtCDEFInfo* info = (ExtCDEFInfo* ) (**theControl).contrlRfCon ;
1637 switch( message )
1638 {
1639 case drawCntl :
1640 {
1641 if (!(**theControl).contrlVis)
1642 return 0 ;
1643 PenState oldPenState;
1644 RGBColor oldForeColor ;
1645 RGBColor oldBackColor ;
1646 RGBColor backColor ;
1647 RGBColor foreColor ;
1648
1649
1650 {
1651 if (!(**theControl).contrlVis)
1652 return 0 ;
1653
1654 {
1655 AGAPortHelper help() ;
1656 Rect frame = (**theControl).contrlRect ;
1657 Boolean hasColor = true;
1658 Boolean disabled = (*theControl)->contrlHilite == 255 ;
1659 int mValue = GetControlValue( theControl ) ;
1660 Boolean inPushed = (**theControl).contrlHilite ;
1661 int mEnabled = 1 ;
1662 int triState_Off = 3 ;
1663
1664 frame.right = frame.left + kAGACheckBoxWidth;
1665 frame.bottom = frame.top + kAGACheckBoxHeigth;
1666
1667 // Draw the frame of the checkbox
1668 if (disabled)
1669 if (hasColor)
1670 ::RGBForeColor(&gAGAColorArray[7]);
1671 else
1672 PenPat(&qd.gray);
1673
1674 ::FrameRect(&frame);
1675
1676 if (!hasColor)
1677 PenNormal();
1678
1679 ::InsetRect(&frame, 1, 1);
1680 if (hasColor)
1681 ::RGBBackColor(inPushed ? &gAGAColorArray[8] : &gAGAColorArray[2]);
1682 ::EraseRect(&frame);
1683
1684 if (hasColor)
1685 {
1686 if (inPushed)
1687 ::RGBForeColor(&gAGAColorArray[10]);
1688 else
1689 ForeColor(whiteColor);
1690 ::MoveTo(frame.left, frame.bottom - 2);
1691 ::LineTo(frame.left, frame.top);
1692 ::LineTo(frame.right - 2, frame.top);
1693
1694 if (inPushed)
1695 ::RGBForeColor(&gAGAColorArray[6]);
1696 else
1697 ::RGBForeColor(mEnabled != triState_Off ? &gAGAColorArray[7] : &gAGAColorArray[5]);
1698 ::MoveTo(frame.left + 1, frame.bottom - 1);
1699 ::LineTo(frame.right - 1, frame.bottom - 1);
1700 ::LineTo(frame.right - 1, frame.top + 1);
1701 }
1702
1703 if (mValue)
1704 {
1705 if (mValue == 1)
1706 {
1707 // Checked state
1708 if (hasColor)
1709 {
1710 ::RGBForeColor(inPushed ? &gAGAColorArray[10] : &gAGAColorArray[5]);
1711 ::MoveTo(frame.left + 3, frame.bottom - 2);
1712 ::LineTo(frame.right - 2, frame.top + 3);
1713 ::MoveTo(frame.right - 2, frame.bottom - 2);
1714 ::LineTo(frame.right - 2, frame.bottom - 2);
1715
1716 if (mEnabled != triState_Off)
1717 ::RGBForeColor(inPushed ? &gAGAColorArray[11] : &gAGAColorArray[8]);
1718 ::MoveTo(frame.left + 3, frame.bottom - 3);
1719 ::LineTo(frame.right - 2, frame.top + 2);
1720 ::MoveTo(frame.right - 2, frame.bottom - 3);
1721 ::LineTo(frame.right - 2, frame.bottom - 3);
1722
1723 if (mEnabled != triState_Off)
1724 ::ForeColor(blackColor);
1725 else
1726 ::RGBForeColor(&gAGAColorArray[7]);
1727 }
1728 ::MoveTo(frame.left + 2, frame.top + 1);
1729 ::LineTo(frame.right - 3, frame.bottom - 4);
1730 ::MoveTo(frame.left + 2, frame.top + 2);
1731 ::LineTo(frame.right - 3, frame.bottom - 3);
1732 ::MoveTo(frame.left + 2, frame.bottom - 4);
1733 ::LineTo(frame.right - 3, frame.top + 1);
1734 ::MoveTo(frame.left + 2, frame.bottom - 3);
1735 ::LineTo(frame.right - 3, frame.top + 2);
1736 }
1737 else
1738 {
1739 // Mixed state
1740 if (hasColor)
1741 {
1742 ::RGBForeColor(inPushed ? &gAGAColorArray[10] : &gAGAColorArray[5]);
1743 ::MoveTo(frame.left + 3, frame.top + 6);
1744 ::LineTo(frame.right - 2, frame.top + 6);
1745 ::LineTo(frame.right - 2, frame.top + 4);
1746
1747 if (mEnabled != triState_Off)
1748 ::ForeColor(blackColor);
1749 else
1750 ::RGBForeColor(&gAGAColorArray[7]);
1751 }
1752 ::MoveTo(frame.left + 2, frame.top + 4);
1753 ::LineTo(frame.right - 3, frame.top + 4);
1754 ::MoveTo(frame.left + 2, frame.top + 5);
1755 ::LineTo(frame.right - 3, frame.top + 5);
1756 }
1757 }
1758
1759 if (inPushed && !hasColor)
1760 InvertRect(&frame);
1761
1762 AGASetFontStyle( &info->fontStyle ) ;
1763 int x = (**theControl).contrlRect.left + kAGACheckBoxWidth + 5 ;
1764 int y = ( (**theControl).contrlRect.top + (**theControl).contrlRect.bottom ) / 2 ;
1765 FontInfo fi ;
1766 ::GetFontInfo( &fi ) ;
1767
1768 y += fi.ascent / 2 ;
1769 ::MoveTo( x , y );
1770 int length = (**theControl).contrlTitle[0] ;
1771 if ( length )
1772 {
1773 ::DrawText( &(**theControl).contrlTitle[1] , 0, length);
1774 }
1775 }
1776 }
1777
1778 }
1779 break ;
1780 case testCntl :
1781 {
1782 Point pt ;
1783 pt.h = LoWord( param ) ;
1784 pt.v = HiWord( param ) ;
1785 if ( PtInRect( pt , &(**theControl).contrlRect ) && ((*theControl)->contrlVis != 0) && ((*theControl)->contrlHilite != 255) )
1786 return kControlCheckBoxPart ;
1787 else
1788 return NULL ;
1789 }
1790 break ;
1791 case posCntl :
1792 {
1793 Point pt ;
1794 pt.h = LoWord( param ) ;
1795 pt.v = HiWord( param ) ;
1796 if ( PtInRect( pt , &(**theControl).contrlRect ) )
1797 {
1798 if ( (**theControl).contrlValue )
1799 (**theControl).contrlValue = 0 ;
1800 else
1801 (**theControl).contrlValue = 1 ;
1802
1803 return 0 ;
1804 }
1805 else
1806 return 0 ;
1807 }
1808 break ;
1809 case calcThumbRgn :
1810 case calcCntlRgn :
1811 if ( !EmptyRect(&(**theControl).contrlRect ) )
1812 RectRgn((RgnHandle) param , &(**theControl).contrlRect ) ;
1813 break ;
1814 case kControlMsgCalcBestRect :
1815 {
1816 ControlCalcSizeRec *rec = (ControlCalcSizeRec *) param ;
1817 rec->width = (**theControl).contrlRect.right - (**theControl).contrlRect.left ;
1818 rec->height = kAGACheckBoxHeigth ;
1819 rec->baseLine = 0;
1820 }
1821 break ;
1822 default :
1823 break ;
1824 }
1825 */
1826 return 0 ;
1827 }
1828
1829 pascal SInt32 AGAStaticGroupBoxTextDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param)
1830 {
1831 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**theControl).contrlRfCon ;
1832
1833 switch( message )
1834 {
1835 case initCntl :
1836 break ;
1837 case dispCntl :
1838 break ;
1839 case drawCntl :
1840 {
1841 if (!(**theControl).contrlVis)
1842 return 0 ;
1843
1844 {
1845 bool disabled = false ;
1846 bool hasColor = true ;
1847 AGAPortHelper help() ;
1848 AGASetFontStyle( &info->fontStyle ) ;
1849 FontInfo fi ;
1850 ::GetFontInfo( &fi ) ;
1851
1852 Rect labelRect = (**theControl).contrlRect ;
1853 Rect theFrame = (**theControl).contrlRect ;
1854 int width = StringWidth((**theControl).contrlTitle) ;
1855 theFrame.top += fi.ascent + fi.leading >> 1 ;
1856 labelRect.bottom = theFrame.top + 8 ;
1857 labelRect.left += 10 ;
1858 labelRect.right =labelRect.left + width + 6 ;
1859
1860 theFrame.bottom--;
1861 theFrame.right--;
1862
1863 if (disabled)
1864 {
1865 RGBForeColor( &gAGAColorArray[4] ) ;
1866 }
1867 else
1868 {
1869 RGBForeColor( &gAGAColorArray[7] ) ;
1870 }
1871 FrameRect( &theFrame ) ;
1872
1873 if (disabled)
1874 ::RGBForeColor(&gAGAColorArray[1]);
1875 else
1876 ::ForeColor(whiteColor);
1877 ::MoveTo(theFrame.left + 1, theFrame.bottom - 2);
1878 ::LineTo(theFrame.left + 1, theFrame.top + 1);
1879 ::LineTo(theFrame.right - 2, theFrame.top + 1);
1880 ::MoveTo(theFrame.left , theFrame.bottom);
1881 ::LineTo(theFrame.right, theFrame.bottom);
1882 ::LineTo(theFrame.right, theFrame.top);
1883
1884 AGASetFontStyle( &info->fontStyle ) ;
1885 ::EraseRect( &labelRect ) ;
1886 ::MoveTo(labelRect.left + 3, labelRect.top + fi.ascent + (fi.leading >> 1));
1887 ::DrawString((**theControl).contrlTitle);
1888 }
1889 }
1890 break ;
1891 case kControlMsgCalcBestRect :
1892 {
1893 ControlCalcSizeRec *rec = (ControlCalcSizeRec *) param ;
1894 rec->width = (**theControl).contrlRect.right - (**theControl).contrlRect.left ;
1895 rec->height = (**theControl).contrlRect.bottom - (**theControl).contrlRect.top ;
1896 rec->baseLine = 0;
1897 }
1898 break ;
1899 case kControlMsgSetData :
1900 break ;
1901 case calcCntlRgn :
1902 RectRgn((RgnHandle) param , &(**theControl).contrlRect ) ;
1903 break ;
1904 default :
1905 break ;
1906 }
1907
1908 return 0 ;
1909 }
1910
1911 pascal SInt32 AGAStaticTextDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param)
1912 {
1913 Handle macText = (**theControl).contrlData ;
1914 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**theControl).contrlRfCon ;
1915
1916 switch( message )
1917 {
1918 case initCntl :
1919 {
1920 macText = NewHandle(0) ;
1921 (**theControl).contrlData = (Handle) macText ;
1922 }
1923 break ;
1924 case dispCntl :
1925 DisposeHandle( macText ) ;
1926 break ;
1927 case drawCntl :
1928 {
1929 if (!(**theControl).contrlVis)
1930 return 0 ;
1931
1932 {
1933 AGAPortHelper help() ;
1934 AGASetFontStyle( &info->fontStyle ) ;
1935 int x = (**theControl).contrlRect.left ;
1936 int y = (**theControl).contrlRect.top ;
1937 int lineheight ;
1938 FontInfo fi ;
1939 ::GetFontInfo( &fi ) ;
1940
1941 y += fi.ascent ;
1942 lineheight = fi.ascent + fi.descent + fi.leading ;
1943 int length = GetHandleSize( macText ) ;
1944 if ( length )
1945 {
1946 int laststop = 0 ;
1947 int i = 0 ;
1948 HLock( macText ) ;
1949 RGBColor gray = { 0xDDDD , 0xDDDD, 0xDDDD } ;
1950 ::RGBBackColor( &gray ) ;
1951 while( i < length )
1952 {
1953 if ( (*macText)[i] == 0x0d )
1954 {
1955 ::MoveTo( x , y );
1956 ::DrawText( *macText , laststop, i-laststop);
1957 laststop = i+1 ;
1958 y += lineheight ;
1959 }
1960 i++ ;
1961 }
1962 ::MoveTo( x , y );
1963 ::DrawText( *macText , laststop, i-laststop);
1964 laststop = i+1 ;
1965 HUnlock( macText ) ;
1966 }
1967 }
1968 }
1969 break ;
1970 case kControlMsgCalcBestRect :
1971 {
1972 ControlCalcSizeRec *rec = (ControlCalcSizeRec *) param ;
1973 rec->width = (**theControl).contrlRect.right - (**theControl).contrlRect.left ;
1974 rec->height = (**theControl).contrlRect.bottom - (**theControl).contrlRect.top ;
1975 rec->baseLine = 0;
1976 }
1977 break ;
1978 case kControlMsgSetData :
1979 {
1980 ControlDataAccessRec *rec = (ControlDataAccessRec *) param ;
1981 if ( rec->tag == kControlStaticTextTextTag )
1982 {
1983 SetHandleSize( macText , rec->size ) ;
1984 memcpy( *macText , rec->dataPtr , rec->size ) ;
1985 return noErr ;
1986 }
1987 return errDataNotSupported ;
1988 }
1989 default :
1990 break ;
1991 }
1992
1993 return 0 ;
1994 }
1995
1996 void AGAMoveControl(ControlHandle inControl , short x , short y )
1997 {
1998 if ( AGATestForNewControl( inControl ) )
1999 {
2000 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
2001 if ( info->magic == kExtCDEFMagic )
2002 {
2003 if ( info->procID == kControlEditTextProc)
2004 {
2005 int dx ;
2006 int dy ;
2007
2008 dx= x - (**inControl).contrlRect.left ;
2009 dy= y - (**inControl).contrlRect.top ;
2010
2011 MoveControl( inControl , x ,y ) ;
2012 TEHandle macTE ;
2013
2014 macTE = (TEHandle) (**inControl).contrlData ;
2015 (**macTE).destRect.left += dx ;
2016 (**macTE).destRect.top += dy ;
2017 (**macTE).destRect.right += dx ;
2018 (**macTE).destRect.bottom += dy ;
2019 (**macTE).viewRect.left += dx ;
2020 (**macTE).viewRect.top += dy ;
2021 (**macTE).viewRect.right += dx ;
2022 (**macTE).viewRect.bottom += dy ;
2023 return ;
2024 }
2025 if ( info->procID == kControlListBoxProc)
2026 {
2027 int dx ;
2028 int dy ;
2029
2030 dx= x - (**inControl).contrlRect.left ;
2031 dy= y - (**inControl).contrlRect.top ;
2032
2033 MoveControl( inControl , x ,y ) ;
2034 ListHandle macList ;
2035
2036 macList = (ListHandle) (**inControl).contrlData ;
2037 (**macList).rView.left += dx ;
2038 (**macList).rView.top += dy ;
2039 (**macList).rView.right += dx ;
2040 (**macList).rView.bottom += dy ;
2041 return ;
2042 }
2043 }
2044 }
2045 MoveControl( inControl , x ,y ) ;
2046 }
2047
2048 void AGASizeControl(ControlHandle inControl , short x , short y )
2049 {
2050 if ( AGATestForNewControl( inControl ) )
2051 {
2052 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
2053 if ( info->magic == kExtCDEFMagic )
2054 {
2055 if ( info->procID == kControlEditTextProc)
2056 {
2057 int dx ;
2058 int dy ;
2059
2060 dx= x - ( (**inControl).contrlRect.right - (**inControl).contrlRect.left ) ;
2061 dy= y - ( (**inControl).contrlRect.bottom - (**inControl).contrlRect.top ) ;
2062
2063 SizeControl( inControl , x ,y ) ;
2064 TEHandle macTE ;
2065
2066 macTE = (TEHandle) (**inControl).contrlData ;
2067 (**macTE).destRect.right += dx ;
2068 (**macTE).destRect.bottom += dy ;
2069 (**macTE).viewRect.right += dx ;
2070 (**macTE).viewRect.bottom += dy ;
2071 return ;
2072 }
2073 if ( info->procID == kControlListBoxProc)
2074 {
2075 int dx ;
2076 int dy ;
2077
2078 dx= x - ( (**inControl).contrlRect.right - (**inControl).contrlRect.left ) ;
2079 dy= y - ( (**inControl).contrlRect.bottom - (**inControl).contrlRect.top ) ;
2080
2081 SizeControl( inControl , x ,y ) ;
2082 ListHandle macList ;
2083
2084 macList = (ListHandle) (**inControl).contrlData ;
2085 (**macList).rView.right += dx ;
2086 (**macList).rView.bottom += dy ;
2087 return ;
2088 }
2089 }
2090 }
2091 SizeControl( inControl , x ,y ) ;
2092 }
2093
2094 pascal SInt32 AGARootControlDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param)
2095 {
2096 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**theControl).contrlRfCon ;
2097
2098 switch( message )
2099 {
2100 case initCntl :
2101 break ;
2102 case dispCntl :
2103 break ;
2104 case drawCntl :
2105 break ;
2106 case kControlMsgCalcBestRect :
2107 break ;
2108 case kControlMsgSetData :
2109 default :
2110 break ;
2111 }
2112
2113 return 0 ;
2114 }
2115
2116 pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param)
2117 {
2118 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**theControl).contrlRfCon ;
2119 Size result ;
2120 TEHandle macTE ;
2121
2122 macTE = (TEHandle) (**theControl).contrlData ;
2123
2124 switch( message )
2125 {
2126 case initCntl :
2127 {
2128 AGAPortHelper help() ;
2129 SetPort( (**theControl).contrlOwner ) ;
2130 ::TextFont( kFontIDGeneva ) ;
2131 ::TextSize( 10 ) ;
2132 ::TextFace( 0 ) ;
2133 RGBBackColor( &gAGARamp[ kAGAWhite ] ) ;
2134 RGBForeColor( &gAGARamp[ kAGABlack ] ) ;
2135 Rect bounds = (**theControl).contrlRect ;
2136 InsetRect( &bounds , 4 , 1 ) ;
2137 FontInfo fi ;
2138 ::GetFontInfo( &fi ) ;
2139
2140 bounds.top = bounds.bottom - abs( fi.descent ) - fi.ascent - 3;
2141 macTE = TENew( &bounds , &bounds) ;
2142 (**theControl).contrlData = (Handle) macTE ;
2143 }
2144 break ;
2145 case dispCntl :
2146 TEDispose( macTE ) ;
2147 break ;
2148 case drawCntl :
2149 {
2150 AGAPortHelper help() ;
2151 AGASetFontStyle( &info->fontStyle ) ;
2152 SetPort( (**theControl).contrlOwner ) ;
2153 RGBBackColor( &gAGARamp[ kAGAWhite ] ) ;
2154 RGBForeColor( &gAGARamp[ kAGABlack ] ) ;
2155 EraseRect( &(**theControl).contrlRect ) ;
2156 FrameRect( &(**theControl).contrlRect ) ;
2157 TEUpdate( &(**theControl).contrlRect , macTE ) ;
2158 }
2159 break ;
2160 case testCntl :
2161 {
2162 Point pt ;
2163 pt.h = LoWord( param ) ;
2164 pt.v = HiWord( param ) ;
2165 if ( PtInRect( pt , &(**theControl).contrlRect ) )
2166 return kControlButtonPart ;
2167 else
2168 return NULL ;
2169 }
2170 break ;
2171 case posCntl :
2172 {
2173 Point pt ;
2174 pt.h = LoWord( param ) ;
2175 pt.v = HiWord( param ) ;
2176 if ( PtInRect( pt , &(**theControl).contrlRect ) )
2177 {
2178 TEClick( pt , false , macTE ) ;
2179 }
2180 }
2181 break ;
2182 case kControlMsgGetData :
2183 {
2184 ControlDataAccessRec *rec = (ControlDataAccessRec *) param ;
2185 if ( rec->tag == kControlEditTextTEHandleTag )
2186 {
2187 return AGAGetDataHelper( rec , sizeof( TEHandle ) , (char*) &macTE ) ;
2188 }
2189 else if ( rec->tag == kControlEditTextTextTag )
2190 {
2191 return AGAGetDataHelper( rec , (**macTE).teLength , (char*) *(**macTE).hText ) ;
2192 }
2193 else if ( rec->tag == kControlEditTextSelectionTag )
2194 {
2195 }
2196 return errDataNotSupported ;
2197 }
2198 break ;
2199 case kControlMsgSetData :
2200 {
2201 ControlDataAccessRec *rec = (ControlDataAccessRec *) param ;
2202 if ( rec->tag == kControlEditTextTextTag )
2203 {
2204 TESetText( rec->dataPtr , rec->size , macTE ) ;
2205 return noErr ;
2206 }
2207 return errDataNotSupported ;
2208 }
2209 case kControlMsgCalcBestRect :
2210 {
2211 ControlCalcSizeRec *rec = (ControlCalcSizeRec *) param ;
2212 rec->width = (**theControl).contrlRect.right - (**theControl).contrlRect.left ;
2213 rec->height = (**theControl).contrlRect.bottom - (**theControl).contrlRect.top ;
2214 rec->baseLine = 0;
2215 }
2216 case kControlMsgFocus :
2217 {
2218 if ( param == kControlFocusNoPart )
2219 {
2220 info->hasFocus = false ;
2221 TEDeactivate( macTE ) ;
2222 return kControlFocusNoPart ;
2223 }
2224 else if ( param == kControlFocusNextPart || param == kControlFocusPrevPart )
2225 {
2226 if ( info->hasFocus )
2227 {
2228 info->hasFocus = false ;
2229 TEDeactivate( macTE ) ;
2230 return kControlFocusNoPart ;
2231 }
2232 else
2233 {
2234 info->hasFocus = true ;
2235 TEActivate( macTE ) ;
2236 return kControlEditTextPart ;
2237 }
2238 }
2239 else if ( param == kControlEditTextPart )
2240 {
2241 if ( !info->hasFocus )
2242 {
2243 info->hasFocus = true ;
2244 TEActivate( macTE ) ;
2245 return kControlEditTextPart ;
2246 }
2247 }
2248 }
2249 break ;
2250 case kControlMsgIdle :
2251 {
2252 TEIdle( macTE ) ;
2253 }
2254 break ;
2255 case kControlMsgKeyDown :
2256 {
2257 AGAPortHelper help() ;
2258 AGASetFontStyle( &info->fontStyle ) ;
2259 SetPort( (**theControl).contrlOwner ) ;
2260 RGBBackColor( &gAGARamp[ kAGAWhite ] ) ;
2261 RGBForeColor( &gAGARamp[ kAGABlack ] ) ;
2262 ControlKeyDownRec * rec = (ControlKeyDownRec*) param ;
2263 TEKey( rec->charCode , macTE ) ;
2264 }
2265 break ;
2266 case kControlMsgActivate :
2267 {
2268 /*
2269 if ( param )
2270 TEActivate( macTE ) ;
2271 else
2272 TEDeactivate( macTE ) ;
2273 */
2274 }
2275 break ;
2276 case calcCntlRgn :
2277 RectRgn((RgnHandle) param , &(**theControl).contrlRect ) ;
2278 break ;
2279 case kControlMsgTestNewMsgSupport :
2280 return kControlSupportsNewMessages ;
2281 case kControlMsgGetFeatures :
2282 return
2283 // kControlSupportsGhosting |
2284 // kControlSupportsEmbedding |
2285 kControlSupportsFocus |
2286 kControlWantsIdle |
2287 kControlWantsActivate |
2288 // kControlHandlesTracking |
2289 kControlSupportsDataAccess |
2290 // kControlHasSpecialBackground |
2291 // kControlGetsFocusOnClick |
2292 kControlSupportsCalcBestRect |
2293 // kControlSupportsLiveFeedback |
2294 // kControlHasRadioBehavior |
2295 0 ;
2296 default :
2297 break ;
2298 }
2299
2300 return 0 ;
2301 }
2302
2303 pascal SInt32 AGAListControlDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param)
2304 {
2305 Size result ;
2306 ListHandle macList ;
2307 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**theControl).contrlRfCon ;
2308
2309 macList = (ListHandle) (**theControl).contrlData ;
2310
2311 static inLoop = false ;
2312 static lastClick = NULL ;
2313
2314 switch( message )
2315 {
2316 case initCntl :
2317 {
2318 Rect databounds = { 0,0,0,0} ;
2319 Point cellsize = { 0,0} ;
2320 Rect listBounds = (**theControl).contrlRect ;
2321
2322 InsetRect( &listBounds , 1 , 1 ) ;
2323
2324 macList = LNew( &listBounds , &databounds , cellsize , 128 ,
2325 (**theControl).contrlOwner , false /*drawit*/ , false /*hasGrow*/,
2326 false /* horzScroll */, true /*vertScroll*/ ) ;
2327 (**theControl).contrlData = (Handle) macList ;
2328 info->privateData = NULL ;
2329 }
2330 break ;
2331 case dispCntl :
2332 (**macList).vScroll = NULL ; // will be disposed by the window itself
2333 (**macList).hScroll = NULL ; // will be disposed by the window itself
2334 LDispose( macList ) ;
2335 break ;
2336 case calcCntlRgn :
2337 RectRgn((RgnHandle) param , &(**theControl).contrlRect ) ;
2338 break ;
2339 case testCntl :
2340 {
2341 Point pt ;
2342 pt.h = LoWord( param ) ;
2343 pt.v = HiWord( param ) ;
2344 Rect listRect ;
2345 Rect allRect = (**theControl).contrlRect ;
2346 listRect = allRect ;
2347 if ( !inLoop )
2348 allRect.right += 16 ;
2349 if ( PtInRect( pt , &allRect ) )
2350 {
2351 if ( !inLoop && StillDown() )
2352 {
2353 inLoop = true ;
2354 LActivate( true , macList ) ;
2355 Boolean doubleClick = LClick( pt , 0 /* todo modifiers*/ , macList ) ;
2356 info->privateData = doubleClick ;
2357 inLoop = false ;
2358 }
2359 return kControlListBoxPart ;
2360 }
2361 else
2362 return NULL ;
2363 }
2364 break ;
2365 case drawCntl :
2366 {
2367 AGAPortHelper help() ;
2368 AGASetFontStyle( &info->fontStyle ) ;
2369 RGBBackColor( &gAGARamp[ kAGAWhite ] ) ;
2370 EraseRect( &(**theControl).contrlRect ) ;
2371 FrameRect( &(**theControl).contrlRect ) ;
2372 RgnHandle controlRgn = NewRgn() ;
2373 SetRectRgn( controlRgn, (**theControl).contrlRect.left ,
2374 (**theControl).contrlRect.top,
2375 (**theControl).contrlRect.right,
2376 (**theControl).contrlRect.bottom ) ;
2377 LUpdate( controlRgn, macList ) ;
2378 }
2379 break ;
2380 case posCntl :
2381 {
2382 Point pt ;
2383 pt.h = LoWord( param ) ;
2384 pt.v = HiWord( param ) ;
2385 Rect listRect ;
2386 Rect allRect = (**theControl).contrlRect ;
2387 listRect = allRect ;
2388 allRect.right += 16 ;
2389 if ( PtInRect( pt , &listRect ) )
2390 {
2391 if ( !inLoop && StillDown() )
2392 {
2393 inLoop = true ;
2394 LActivate( true , macList ) ;
2395 Boolean doubleClick = LClick( pt , 0 /* todo modifiers*/ , macList ) ;
2396 info->privateData = doubleClick ;
2397 inLoop = false ;
2398 }
2399 return kControlListBoxPart ;
2400 }
2401 else if ( PtInRect( pt , &allRect ) )
2402 {
2403 if ( !inLoop && StillDown() )
2404 {
2405 inLoop = true ;
2406 // LActivate( true , macList ) ;
2407 Boolean doubleClick = LClick( pt , 0 /* todo modifiers*/ , macList ) ;
2408 info->privateData = doubleClick ;
2409 inLoop = false ;
2410 }
2411 return kControlPageDownPart ;
2412 }
2413 else
2414 return NULL ;
2415 }
2416 break ;
2417 case kControlMsgGetData :
2418 {
2419 ControlDataAccessRec *rec = (ControlDataAccessRec *) param ;
2420 if ( rec->tag == kControlListBoxListHandleTag )
2421 {
2422 return AGAGetDataHelper( rec , sizeof( ListHandle ) , (char*) &macList ) ;
2423 }
2424 else if ( rec->tag == kControlListBoxDoubleClickTag )
2425 {
2426 Boolean doubleClick = info->privateData ;
2427 return AGAGetDataHelper( rec , sizeof( Boolean ) , (char*) &doubleClick ) ;
2428 }
2429 return errDataNotSupported ;
2430 }
2431 break ;
2432 default :
2433 break ;
2434 }
2435
2436 return 0 ;
2437 }
2438
2439 OSErr AGACreateRootControl (WindowPtr inWindow,
2440 ControlHandle * outControl)
2441 {
2442 ControlHandle theControl = NULL ;
2443
2444 SInt16 extCDEFID = kExtCDEFID << 4 + 0 ;
2445
2446 theControl = NewControl( inWindow , &inWindow->portRect , "\p" , true ,
2447 0 , 0 , 1 , extCDEFID , 0 ) ;
2448 NewExtCDEFInfo( theControl , AGARootControlDefProc , kAGARootControlProcID , 0 ) ;
2449
2450 *outControl = theControl ;
2451 return noErr ;
2452 }
2453
2454 OSErr AGAEmbedControl (ControlHandle inControl,
2455 ControlHandle inContainer)
2456 {
2457 if ( AGATestForNewControl( inControl ) )
2458 {
2459 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**inControl).contrlRfCon ;
2460 info->containerControl = inContainer ;
2461 }
2462 return noErr ;
2463 }
2464
2465 void AGADrawControl( ControlHandle control )
2466 {
2467 DrawOneControl( control ) ;
2468 ControlHandle iter = (ControlHandle) ((WindowPeek)(**control).contrlOwner)->controlList ;
2469 while ( iter )
2470 {
2471 if ( AGATestForNewControl( iter ) )
2472 {
2473 ExtCDEFInfo* info = (ExtCDEFInfo* ) (**iter).contrlRfCon ;
2474 if ( info->containerControl == control )
2475 {
2476 AGADrawControl( iter ) ;
2477 }
2478 }
2479
2480 iter = (**iter).nextControl ;
2481 }
2482 }
2483
2484
2485 ControlHandle AGANewControl(WindowPtr owningWindow,
2486 const Rect * bounds,
2487 ConstStr255Param controlTitle,
2488 Boolean initiallyVisible,
2489 SInt16 initialValue,
2490 SInt16 minimumValue,
2491 SInt16 maximumValue,
2492 SInt16 procID,
2493 SInt32 controlReference)
2494 {
2495 ControlHandle theControl = NULL ;
2496 Rect boundsRect = *bounds ;
2497 SInt16 extCDEFID = kExtCDEFID << 4 + 0 ;
2498 SInt16 oldProcID = extCDEFID ;
2499 switch( procID )
2500 {
2501 case kControlScrollBarProc :
2502 case kControlScrollBarLiveProc :
2503 oldProcID = scrollBarProc ;
2504 break ;
2505 case kControlListBoxProc :
2506 initialValue = 0 ;
2507 default :
2508 break ;
2509 }
2510 if ( oldProcID == extCDEFID && procID == kControlListBoxProc )
2511 {
2512 boundsRect.right -= 16 ;
2513 }
2514 theControl = NewControl( owningWindow , &boundsRect , controlTitle , initiallyVisible ,
2515 initialValue , minimumValue , maximumValue , oldProcID , controlReference ) ;
2516 if ( oldProcID == extCDEFID )
2517 {
2518 ControlDefProcPtr theProcPtr = NULL ;
2519 SInt16 theVarCode = 0 ;
2520 switch( procID )
2521 {
2522 case kControlPushButtonProc :
2523 theProcPtr = AGAButtonDefProc ;
2524 break ;
2525 case kControlCheckBoxProc :
2526 theProcPtr = AGACheckBoxDefProc ;
2527 break ;
2528 case kControlRadioButtonProc :
2529 theProcPtr = AGARadioButtonDefProc ;
2530 break ;
2531 case kControlProgressBarProc :
2532 theProcPtr = AGAProgressBarDefProc ;
2533 break ;
2534 case kControlPlacardProc :
2535 theProcPtr = AGAPlacardDefProc ;
2536 break ;
2537 case kControlStaticTextProc :
2538 theProcPtr = AGAStaticTextDefProc ;
2539 break ;
2540 case kControlListBoxProc :
2541 theProcPtr = AGAListControlDefProc ;
2542 break ;
2543 case kControlEditTextProc :
2544 theProcPtr = AGAEditTextDefProc ;
2545 break ;
2546 case kControlGroupBoxTextTitleProc :
2547 theProcPtr = AGAStaticGroupBoxTextDefProc ;
2548 break ;
2549 case kControlBevelButtonNormalBevelProc :
2550 theProcPtr = AGABevelButtonDefProc ;
2551 break ;
2552 }
2553
2554 if ( theProcPtr )
2555 {
2556 NewExtCDEFInfo( theControl , theProcPtr , procID , controlReference ) ;
2557 }
2558 }
2559 return theControl ;
2560 }
2561
2562 void AGASetThemeWindowBackground (WindowRef inWindow,
2563 ThemeBrush inBrush,
2564 Boolean inUpdate)
2565 {
2566 GrafPtr port ;
2567 GetPort( &port ) ;
2568 SetPort( inWindow ) ;
2569 if ( inBrush == kThemeBrushDialogBackgroundActive )
2570 {
2571 gAGABackgroundColor = 2 ;
2572 }
2573 else
2574 {
2575 gAGABackgroundColor = 0 ;
2576 }
2577 RGBBackColor( &gAGAColorArray[gAGABackgroundColor] ) ;
2578 SetPort( port ) ;
2579 }
2580
2581