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