]>
Commit | Line | Data |
---|---|---|
03e11df5 | 1 | #include "wx/defs.h" |
5fde6fcc | 2 | #include "wx/dc.h" |
03e11df5 | 3 | #include "wx/mac/uma.h" |
b03e4fcd | 4 | #include <MacTextEditor.h> |
72e7876b | 5 | |
f5c6eb5c | 6 | #ifndef __DARWIN__ |
a3d3d3bf GD |
7 | # include <Navigation.h> |
8 | # if defined(TARGET_CARBON) | |
9 | # if PM_USE_SESSION_APIS | |
10 | # include <PMCore.h> | |
11 | # endif | |
12 | # include <PMApplication.h> | |
66a09d47 SC |
13 | # else |
14 | # include <Printing.h> | |
a3d3d3bf | 15 | # endif |
03e11df5 | 16 | #endif |
5b781a67 | 17 | |
72055702 SC |
18 | // since we have decided that we only support 8.6 upwards we are |
19 | // checking for these minimum requirements in the startup code of | |
20 | // the application so all wxWindows code can safely assume that appearance 1.1 | |
21 | // windows manager, control manager, navigation services etc. are | |
22 | // present | |
e7b596fb | 23 | |
72e7876b SC |
24 | static bool sUMAHasAppearance = false ; |
25 | static long sUMAAppearanceVersion = 0 ; | |
0888ccc7 | 26 | static bool sUMAHasAquaLayout = false ; |
0e5a4d20 SC |
27 | static bool sUMASystemInitialized = false ; |
28 | ||
72e7876b SC |
29 | extern int gAGABackgroundColor ; |
30 | bool UMAHasAppearance() { return sUMAHasAppearance ; } | |
31 | long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; } | |
32 | ||
33 | static bool sUMAHasWindowManager = false ; | |
34 | static long sUMAWindowManagerAttr = 0 ; | |
35 | ||
36 | bool UMAHasWindowManager() { return sUMAHasWindowManager ; } | |
37 | long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; } | |
0888ccc7 | 38 | bool UMAHasAquaLayout() { return sUMAHasAquaLayout ; } |
0e5a4d20 | 39 | bool UMASystemIsInitialized() { return sUMASystemInitialized ; } |
72055702 | 40 | |
5b781a67 SC |
41 | void UMACleanupToolbox() |
42 | { | |
5b781a67 SC |
43 | if ( sUMAHasAppearance ) |
44 | { | |
45 | UnregisterAppearanceClient() ; | |
46 | } | |
5b781a67 SC |
47 | if ( NavServicesAvailable() ) |
48 | { | |
49 | NavUnload() ; | |
50 | } | |
f8eebb95 SC |
51 | if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress ) |
52 | TXNTerminateTextension( ) ; | |
5b781a67 | 53 | } |
72e7876b SC |
54 | void UMAInitToolbox( UInt16 inMoreMastersCalls ) |
55 | { | |
56 | #if !TARGET_CARBON | |
57 | ::MaxApplZone(); | |
58 | for (long i = 1; i <= inMoreMastersCalls; i++) | |
59 | ::MoreMasters(); | |
60 | ||
61 | ::InitGraf(&qd.thePort); | |
62 | ::InitFonts(); | |
72e7876b SC |
63 | ::InitMenus(); |
64 | ::TEInit(); | |
65 | ::InitDialogs(0L); | |
66 | ::FlushEvents(everyEvent, 0); | |
67 | ::InitCursor(); | |
68 | long total,contig; | |
69 | PurgeSpace(&total, &contig); | |
70 | #else | |
2f1ae414 | 71 | InitCursor(); |
72e7876b SC |
72 | #endif |
73 | ||
72e7876b SC |
74 | long theAppearance ; |
75 | if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr ) | |
76 | { | |
77 | sUMAHasAppearance = true ; | |
78 | RegisterAppearanceClient(); | |
79 | if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr ) | |
80 | { | |
81 | sUMAAppearanceVersion = theAppearance ; | |
82 | } | |
83 | else | |
84 | { | |
85 | sUMAAppearanceVersion = 0x0100 ; | |
86 | } | |
87 | } | |
72e7876b SC |
88 | if ( Gestalt( gestaltWindowMgrAttr, &sUMAWindowManagerAttr ) == noErr ) |
89 | { | |
90 | sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ; | |
91 | } | |
5b781a67 | 92 | |
8e8d3ba8 SC |
93 | #if TARGET_CARBON |
94 | // Call currently implicitely done : InitFloatingWindows() ; | |
95 | #else | |
5b781a67 SC |
96 | if ( sUMAHasWindowManager ) |
97 | InitFloatingWindows() ; | |
98 | else | |
99 | InitWindows(); | |
03e11df5 | 100 | #endif |
5b781a67 SC |
101 | |
102 | if ( NavServicesAvailable() ) | |
103 | { | |
104 | NavLoad() ; | |
105 | } | |
b03e4fcd | 106 | |
f8eebb95 SC |
107 | if ( TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress ) |
108 | { | |
564bf1ea SC |
109 | FontFamilyID fontId ; |
110 | Str255 fontName ; | |
111 | SInt16 fontSize ; | |
112 | Style fontStyle ; | |
113 | GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; | |
114 | GetFNum( fontName, &fontId ); | |
115 | ||
116 | TXNMacOSPreferredFontDescription fontDescriptions[] = | |
117 | { | |
118 | { fontId , (fontSize << 16) ,kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } , | |
119 | } ; | |
120 | int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ; | |
54ddeb7e | 121 | #if 0 // TARGET_CARBON |
564bf1ea SC |
122 | --noOfFontDescriptions ; |
123 | #endif | |
124 | // kTXNAlwaysUseQuickDrawTextMask might be desirable because of speed increases but it crashes the app under OS X upon key stroke | |
54ddeb7e SC |
125 | OptionBits options = kTXNWantMoviesMask | kTXNWantSoundMask | kTXNWantGraphicsMask ; |
126 | #if TARGET_CARBON | |
127 | if ( !UMAHasAquaLayout() ) | |
128 | #endif | |
129 | { | |
130 | options |= kTXNAlwaysUseQuickDrawTextMask ; | |
131 | } | |
132 | TXNInitTextension(fontDescriptions, noOfFontDescriptions, options ); | |
133 | } | |
f8eebb95 | 134 | |
0888ccc7 SC |
135 | long menuMgrAttr ; |
136 | Gestalt( gestaltMenuMgrAttr , &menuMgrAttr ) ; | |
137 | if ( menuMgrAttr & gestaltMenuMgrAquaLayoutMask ) | |
138 | sUMAHasAquaLayout = true ; | |
0e5a4d20 | 139 | sUMASystemInitialized = true ; |
66a09d47 | 140 | |
72e7876b SC |
141 | } |
142 | ||
66a09d47 SC |
143 | /* |
144 | Boolean CanUseATSUI() | |
145 | { | |
146 | long result; | |
147 | OSErr err = Gestalt(gestaltATSUVersion, &result); | |
148 | return (err == noErr); | |
149 | } | |
150 | */ | |
72e7876b SC |
151 | // process manager |
152 | long UMAGetProcessMode() | |
153 | { | |
154 | OSErr err ; | |
155 | ProcessInfoRec processinfo; | |
156 | ProcessSerialNumber procno ; | |
157 | ||
158 | procno.highLongOfPSN = NULL ; | |
159 | procno.lowLongOfPSN = kCurrentProcess ; | |
160 | processinfo.processInfoLength = sizeof(ProcessInfoRec); | |
161 | processinfo.processName = NULL; | |
162 | processinfo.processAppSpec = NULL; | |
163 | ||
164 | err = ::GetProcessInformation( &procno , &processinfo ) ; | |
165 | wxASSERT( err == noErr ) ; | |
166 | return processinfo.processMode ; | |
167 | } | |
168 | ||
169 | bool UMAGetProcessModeDoesActivateOnFGSwitch() | |
170 | { | |
171 | return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ; | |
172 | } | |
173 | ||
174 | // menu manager | |
175 | ||
2f1ae414 | 176 | void UMASetMenuTitle( MenuRef menu , StringPtr title ) |
72e7876b | 177 | { |
76a5e5d2 | 178 | /* |
72e7876b SC |
179 | #if !TARGET_CARBON |
180 | long size = GetHandleSize( (Handle) menu ) ; | |
181 | const long headersize = 14 ; | |
182 | int oldlen = (**menu).menuData[0] + 1; | |
183 | int newlen = title[0] + 1 ; | |
184 | ||
185 | if ( oldlen < newlen ) | |
186 | { | |
187 | // enlarge before adjusting | |
188 | SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ); | |
189 | } | |
190 | ||
191 | if ( oldlen != newlen ) | |
192 | memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ; | |
193 | ||
194 | memcpy( (char*) (**menu).menuData , title , newlen ) ; | |
195 | if ( oldlen > newlen ) | |
196 | { | |
197 | // shrink after | |
198 | SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ; | |
199 | } | |
200 | #else | |
76a5e5d2 | 201 | */ |
72e7876b | 202 | SetMenuTitle( menu , title ) ; |
76a5e5d2 | 203 | //#endif |
72e7876b SC |
204 | } |
205 | ||
206 | UInt32 UMAMenuEvent( EventRecord *inEvent ) | |
207 | { | |
72e7876b | 208 | return MenuEvent( inEvent ) ; |
72e7876b SC |
209 | } |
210 | ||
211 | void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem ) | |
212 | { | |
72e7876b | 213 | EnableMenuItem( inMenu , inItem ) ; |
72e7876b SC |
214 | } |
215 | ||
216 | void UMADisableMenuItem( MenuRef inMenu , MenuItemIndex inItem ) | |
217 | { | |
72e7876b | 218 | DisableMenuItem( inMenu , inItem ) ; |
72e7876b | 219 | } |
2f1ae414 SC |
220 | |
221 | void UMAAppendSubMenuItem( MenuRef menu , StringPtr l , SInt16 id ) | |
222 | { | |
223 | Str255 label ; | |
224 | memcpy( label , l , l[0]+1 ) ; | |
225 | // hardcoded adding of the submenu combination for mac | |
226 | ||
227 | int theEnd = label[0] + 1; | |
228 | if (theEnd > 251) | |
229 | theEnd = 251; // mac allows only 255 characters | |
230 | label[theEnd++] = '/'; | |
231 | label[theEnd++] = hMenuCmd; | |
232 | label[theEnd++] = '!'; | |
233 | label[theEnd++] = id ; | |
234 | label[theEnd] = 0x00; | |
235 | label[0] = theEnd; | |
236 | MacAppendMenu(menu, label); | |
237 | } | |
238 | ||
239 | void UMAInsertSubMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 id ) | |
240 | { | |
241 | Str255 label ; | |
242 | memcpy( label , l , l[0]+1 ) ; | |
243 | // hardcoded adding of the submenu combination for mac | |
244 | ||
245 | int theEnd = label[0] + 1; | |
246 | if (theEnd > 251) | |
247 | theEnd = 251; // mac allows only 255 characters | |
248 | label[theEnd++] = '/'; | |
249 | label[theEnd++] = hMenuCmd; | |
250 | label[theEnd++] = '!'; | |
251 | label[theEnd++] = id; | |
252 | label[theEnd] = 0x00; | |
253 | label[0] = theEnd; | |
254 | MacInsertMenuItem(menu, label , item); | |
255 | } | |
256 | ||
257 | void UMAAppendMenuItem( MenuRef menu , StringPtr l , SInt16 key, UInt8 modifiers ) | |
258 | { | |
259 | Str255 label ; | |
260 | memcpy( label , l , l[0]+1 ) ; | |
261 | if ( key ) | |
262 | { | |
263 | int pos = label[0] ; | |
264 | label[++pos] = '/'; | |
265 | label[++pos] = toupper( key ); | |
266 | label[0] = pos ; | |
267 | } | |
268 | MacAppendMenu( menu , label ) ; | |
269 | } | |
270 | ||
271 | void UMAInsertMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 key, UInt8 modifiers ) | |
272 | { | |
273 | Str255 label ; | |
274 | memcpy( label , l , l[0]+1 ) ; | |
275 | if ( key ) | |
276 | { | |
277 | int pos = label[0] ; | |
278 | label[++pos] = '/'; | |
279 | label[++pos] = toupper( key ); | |
280 | label[0] = pos ; | |
281 | } | |
282 | MacInsertMenuItem( menu , label , item) ; | |
283 | } | |
284 | ||
72e7876b SC |
285 | // quickdraw |
286 | ||
2f1ae414 SC |
287 | int gPrOpenCounter = 0 ; |
288 | ||
a3d3d3bf | 289 | OSStatus UMAPrOpen(void *macPrintSession) |
2f1ae414 SC |
290 | { |
291 | #if !TARGET_CARBON | |
292 | OSErr err = noErr ; | |
293 | ++gPrOpenCounter ; | |
294 | if ( gPrOpenCounter == 1 ) | |
295 | { | |
296 | PrOpen() ; | |
297 | err = PrError() ; | |
298 | wxASSERT( err == noErr ) ; | |
299 | } | |
5b781a67 | 300 | return err ; |
2f1ae414 | 301 | #else |
5b781a67 SC |
302 | OSStatus err = noErr ; |
303 | ++gPrOpenCounter ; | |
304 | if ( gPrOpenCounter == 1 ) | |
305 | { | |
a689a4d0 | 306 | #if PM_USE_SESSION_APIS |
a3d3d3bf | 307 | err = PMCreateSession((PMPrintSession *)macPrintSession) ; |
a689a4d0 GD |
308 | #else |
309 | err = PMBegin() ; | |
310 | #endif | |
5b781a67 SC |
311 | wxASSERT( err == noErr ) ; |
312 | } | |
313 | return err ; | |
2f1ae414 SC |
314 | #endif |
315 | } | |
316 | ||
a3d3d3bf | 317 | OSStatus UMAPrClose(void *macPrintSession) |
2f1ae414 SC |
318 | { |
319 | #if !TARGET_CARBON | |
320 | OSErr err = noErr ; | |
321 | wxASSERT( gPrOpenCounter >= 1 ) ; | |
322 | if ( gPrOpenCounter == 1 ) | |
323 | { | |
324 | PrClose() ; | |
325 | err = PrError() ; | |
326 | wxASSERT( err == noErr ) ; | |
327 | } | |
328 | --gPrOpenCounter ; | |
5b781a67 | 329 | return err ; |
2f1ae414 | 330 | #else |
5b781a67 SC |
331 | OSStatus err = noErr ; |
332 | wxASSERT( gPrOpenCounter >= 1 ) ; | |
333 | if ( gPrOpenCounter == 1 ) | |
334 | { | |
a689a4d0 | 335 | #if PM_USE_SESSION_APIS |
a3d3d3bf GD |
336 | err = PMRelease(*(PMPrintSession *)macPrintSession) ; |
337 | *(PMPrintSession *)macPrintSession = kPMNoReference; | |
a689a4d0 GD |
338 | #else |
339 | err = PMEnd() ; | |
340 | #endif | |
5b781a67 SC |
341 | } |
342 | --gPrOpenCounter ; | |
343 | return err ; | |
2f1ae414 SC |
344 | #endif |
345 | } | |
346 | ||
72e7876b SC |
347 | #if !TARGET_CARBON |
348 | ||
72055702 | 349 | pascal QDGlobalsPtr GetQDGlobalsPtr (void) ; |
72e7876b SC |
350 | pascal QDGlobalsPtr GetQDGlobalsPtr (void) |
351 | { | |
352 | return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA); | |
353 | } | |
354 | ||
355 | #endif | |
356 | ||
357 | void UMAShowWatchCursor() | |
358 | { | |
359 | OSErr err = noErr; | |
360 | ||
361 | CursHandle watchFob = GetCursor (watchCursor); | |
362 | ||
363 | if (!watchFob) | |
364 | err = nilHandleErr; | |
365 | else | |
366 | { | |
367 | #if TARGET_CARBON | |
72055702 SC |
368 | // Cursor preservedArrow; |
369 | // GetQDGlobalsArrow (&preservedArrow); | |
370 | // SetQDGlobalsArrow (*watchFob); | |
371 | // InitCursor ( ); | |
372 | // SetQDGlobalsArrow (&preservedArrow); | |
373 | SetCursor (*watchFob); | |
72e7876b SC |
374 | #else |
375 | SetCursor (*watchFob); | |
376 | #endif | |
377 | } | |
378 | } | |
379 | ||
380 | void UMAShowArrowCursor() | |
381 | { | |
382 | #if TARGET_CARBON | |
383 | Cursor arrow; | |
384 | SetCursor (GetQDGlobalsArrow (&arrow)); | |
385 | #else | |
386 | SetCursor (&(qd.arrow)); | |
387 | #endif | |
388 | } | |
389 | ||
390 | // window manager | |
391 | ||
392 | GrafPtr UMAGetWindowPort( WindowRef inWindowRef ) | |
393 | { | |
394 | wxASSERT( inWindowRef != NULL ) ; | |
395 | #if TARGET_CARBON | |
cf6674a4 | 396 | return (GrafPtr) GetWindowPort( inWindowRef ) ; |
72e7876b SC |
397 | #else |
398 | return (GrafPtr) inWindowRef ; | |
399 | #endif | |
400 | } | |
401 | ||
402 | void UMADisposeWindow( WindowRef inWindowRef ) | |
403 | { | |
404 | wxASSERT( inWindowRef != NULL ) ; | |
405 | DisposeWindow( inWindowRef ) ; | |
406 | } | |
407 | ||
408 | void UMASetWTitleC( WindowRef inWindowRef , const char *title ) | |
409 | { | |
410 | Str255 ptitle ; | |
411 | strncpy( (char*)ptitle , title , 96 ) ; | |
412 | ptitle[96] = 0 ; | |
03e11df5 GD |
413 | #if TARGET_CARBON |
414 | c2pstrcpy( ptitle, (char *)ptitle ) ; | |
415 | #else | |
72e7876b | 416 | c2pstr( (char*)ptitle ) ; |
03e11df5 | 417 | #endif |
72e7876b SC |
418 | SetWTitle( inWindowRef , ptitle ) ; |
419 | } | |
03e11df5 | 420 | |
72e7876b SC |
421 | void UMAGetWTitleC( WindowRef inWindowRef , char *title ) |
422 | { | |
423 | GetWTitle( inWindowRef , (unsigned char*)title ) ; | |
03e11df5 GD |
424 | #if TARGET_CARBON |
425 | p2cstrcpy( title, (unsigned char *)title ) ; | |
426 | #else | |
72e7876b | 427 | p2cstr( (unsigned char*)title ) ; |
03e11df5 | 428 | #endif |
72e7876b SC |
429 | } |
430 | ||
72e7876b SC |
431 | // appearance additions |
432 | ||
433 | void UMAActivateControl( ControlHandle inControl ) | |
434 | { | |
22e751a5 SC |
435 | // we have to add the control after again to the update rgn |
436 | // otherwise updates get lost | |
437 | if ( !IsControlActive( inControl ) ) | |
438 | { | |
fdaf613a SC |
439 | bool visible = IsControlVisible( inControl ) ; |
440 | if ( visible ) | |
441 | SetControlVisibility( inControl , false , false ) ; | |
3f4902f5 | 442 | ::ActivateControl( inControl ) ; |
fdaf613a SC |
443 | if ( visible ) { |
444 | SetControlVisibility( inControl , true , false ) ; | |
c36f0244 SC |
445 | Rect ctrlBounds ; |
446 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
fdaf613a | 447 | } |
22e751a5 | 448 | } |
72e7876b SC |
449 | } |
450 | ||
451 | void UMADrawControl( ControlHandle inControl ) | |
452 | { | |
3f4902f5 GD |
453 | WindowRef theWindow = GetControlOwner(inControl) ; |
454 | RgnHandle updateRgn = NewRgn() ; | |
3f4902f5 | 455 | GetWindowUpdateRgn( theWindow , updateRgn ) ; |
22e751a5 SC |
456 | Point zero = { 0 , 0 } ; |
457 | LocalToGlobal( &zero ) ; | |
458 | OffsetRgn( updateRgn , -zero.h , -zero.v ) ; | |
459 | ::DrawControlInCurrentPort( inControl ) ; | |
460 | InvalWindowRgn( theWindow, updateRgn) ; | |
461 | DisposeRgn( updateRgn ) ; | |
72e7876b SC |
462 | } |
463 | ||
464 | void UMAMoveControl( ControlHandle inControl , short x , short y ) | |
465 | { | |
72055702 SC |
466 | bool visible = IsControlVisible( inControl ) ; |
467 | if ( visible ) { | |
468 | SetControlVisibility( inControl , false , false ) ; | |
469 | Rect ctrlBounds ; | |
470 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
471 | } | |
472 | ::MoveControl( inControl , x , y ) ; | |
473 | if ( visible ) { | |
474 | SetControlVisibility( inControl , true , false ) ; | |
475 | Rect ctrlBounds ; | |
476 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
477 | } | |
72e7876b SC |
478 | } |
479 | ||
480 | void UMASizeControl( ControlHandle inControl , short x , short y ) | |
481 | { | |
72055702 SC |
482 | bool visible = IsControlVisible( inControl ) ; |
483 | if ( visible ) { | |
484 | SetControlVisibility( inControl , false , false ) ; | |
485 | Rect ctrlBounds ; | |
486 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
b03e4fcd | 487 | } |
72055702 SC |
488 | ::SizeControl( inControl , x , y ) ; |
489 | if ( visible ) { | |
490 | SetControlVisibility( inControl , true , false ) ; | |
491 | Rect ctrlBounds ; | |
492 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
493 | } | |
72e7876b SC |
494 | } |
495 | ||
496 | void UMADeactivateControl( ControlHandle inControl ) | |
497 | { | |
22e751a5 SC |
498 | // we have to add the control after again to the update rgn |
499 | // otherwise updates get lost | |
72055702 SC |
500 | bool visible = IsControlVisible( inControl ) ; |
501 | if ( visible ) | |
502 | SetControlVisibility( inControl , false , false ) ; | |
503 | ::DeactivateControl( inControl ) ; | |
504 | if ( visible ) { | |
505 | SetControlVisibility( inControl , true , false ) ; | |
506 | Rect ctrlBounds ; | |
507 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
508 | } | |
72e7876b | 509 | } |
fdaf613a | 510 | // shows the control and adds the region to the update region |
3f4902f5 | 511 | void UMAShowControl (ControlHandle inControl) |
72e7876b | 512 | { |
fdaf613a | 513 | SetControlVisibility( inControl , true , false ) ; |
c36f0244 SC |
514 | Rect ctrlBounds ; |
515 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
72e7876b SC |
516 | } |
517 | ||
22e751a5 SC |
518 | // shows the control and adds the region to the update region |
519 | void UMAHideControl (ControlHandle inControl) | |
520 | { | |
521 | SetControlVisibility( inControl , false , false ) ; | |
522 | Rect ctrlBounds ; | |
523 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
524 | } | |
72e7876b SC |
525 | // keyboard focus |
526 | OSErr UMASetKeyboardFocus (WindowPtr inWindow, | |
527 | ControlHandle inControl, | |
528 | ControlFocusPart inPart) | |
529 | { | |
2f1ae414 SC |
530 | OSErr err = noErr; |
531 | GrafPtr port ; | |
532 | GetPort( &port ) ; | |
72055702 SC |
533 | |
534 | SetPortWindowPort( inWindow ) ; | |
535 | ||
72055702 | 536 | err = SetKeyboardFocus( inWindow , inControl , inPart ) ; |
2f1ae414 SC |
537 | SetPort( port ) ; |
538 | return err ; | |
72e7876b SC |
539 | } |
540 | ||
541 | ||
542 | ||
543 | ||
544 | // events | |
72e7876b SC |
545 | void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn ) |
546 | { | |
72055702 SC |
547 | RgnHandle updateRgn = NewRgn() ; |
548 | GetWindowUpdateRgn( inWindow , updateRgn ) ; | |
549 | ||
be57fda6 SC |
550 | Point zero = { 0 , 0 } ; |
551 | LocalToGlobal( &zero ) ; | |
552 | OffsetRgn( updateRgn , -zero.h , -zero.v ) ; | |
72e7876b | 553 | |
72055702 SC |
554 | UpdateControls( inWindow , inRgn ) ; |
555 | InvalWindowRgn( inWindow, updateRgn) ; | |
556 | DisposeRgn( updateRgn ) ; | |
72e7876b | 557 | |
72e7876b SC |
558 | } |
559 | ||
560 | bool UMAIsWindowFloating( WindowRef inWindow ) | |
561 | { | |
562 | WindowClass cl ; | |
563 | ||
72055702 | 564 | GetWindowClass( inWindow , &cl ) ; |
72e7876b SC |
565 | return cl == kFloatingWindowClass ; |
566 | } | |
567 | ||
568 | bool UMAIsWindowModal( WindowRef inWindow ) | |
569 | { | |
570 | WindowClass cl ; | |
571 | ||
72055702 | 572 | GetWindowClass( inWindow , &cl ) ; |
72e7876b SC |
573 | return cl < kFloatingWindowClass ; |
574 | } | |
575 | ||
576 | // others | |
577 | ||
578 | void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ) | |
579 | { | |
580 | if ( inWindowRef ) | |
581 | { | |
582 | // bool isHighlighted = IsWindowHighlited( inWindowRef ) ; | |
583 | // if ( inActivate != isHightlited ) | |
c809f3be SC |
584 | GrafPtr port ; |
585 | GetPort( &port ) ; | |
72055702 | 586 | SetPortWindowPort( inWindowRef ) ; |
c809f3be SC |
587 | HiliteWindow( inWindowRef , inActivate ) ; |
588 | ControlHandle control = NULL ; | |
72055702 | 589 | ::GetRootControl( inWindowRef , & control ) ; |
c809f3be SC |
590 | if ( control ) |
591 | { | |
592 | if ( inActivate ) | |
593 | UMAActivateControl( control ) ; | |
594 | else | |
595 | UMADeactivateControl( control ) ; | |
596 | } | |
597 | SetPort( port ) ; | |
72e7876b SC |
598 | } |
599 | } | |
2f1ae414 SC |
600 | OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ) |
601 | { | |
72055702 | 602 | return ::DrawThemePlacard( inRect , inState ) ; |
2f1ae414 | 603 | } |
72e7876b | 604 | |
2f056c85 | 605 | #if !TARGET_CARBON |
b03e4fcd | 606 | static OSStatus helpMenuStatus = noErr ; |
b03e4fcd | 607 | static MenuItemIndex firstCustomItemIndex = 0 ; |
2f056c85 | 608 | #endif |
b03e4fcd SC |
609 | |
610 | OSStatus UMAGetHelpMenu( | |
611 | MenuRef * outHelpMenu, | |
612 | MenuItemIndex * outFirstCustomItemIndex) | |
613 | { | |
614 | #if TARGET_CARBON | |
615 | return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ; | |
616 | #else | |
ca5e5bad SC |
617 | MenuRef helpMenuHandle ; |
618 | helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ; | |
619 | if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr ) | |
b03e4fcd | 620 | { |
ca5e5bad | 621 | firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ; |
b03e4fcd SC |
622 | } |
623 | if ( outFirstCustomItemIndex ) | |
624 | { | |
625 | *outFirstCustomItemIndex = firstCustomItemIndex ; | |
626 | } | |
627 | *outHelpMenu = helpMenuHandle ; | |
628 | return helpMenuStatus ; | |
629 | #endif | |
630 | } | |
76a5e5d2 SC |
631 | |
632 | wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport) | |
633 | { | |
634 | m_clip = NULL ; | |
635 | Setup( newport ) ; | |
636 | } | |
637 | ||
638 | wxMacPortStateHelper::wxMacPortStateHelper() | |
639 | { | |
640 | m_clip = NULL ; | |
641 | } | |
642 | ||
643 | void wxMacPortStateHelper::Setup( GrafPtr newport ) | |
644 | { | |
645 | GetPort( &m_oldPort ) ; | |
646 | SetPort( newport ) ; | |
647 | wxASSERT_MSG( m_clip == NULL , "Cannot call setup twice" ) ; | |
648 | m_clip = NewRgn() ; | |
649 | GetClip( m_clip ); | |
650 | m_textFont = GetPortTextFont( (CGrafPtr) newport); | |
651 | m_textSize = GetPortTextSize( (CGrafPtr) newport); | |
652 | m_textStyle = GetPortTextFace( (CGrafPtr) newport); | |
653 | m_textMode = GetPortTextMode( (CGrafPtr) newport); | |
654 | GetThemeDrawingState( &m_drawingState ) ; | |
655 | m_currentPort = newport ; | |
656 | } | |
657 | void wxMacPortStateHelper::Clear() | |
658 | { | |
659 | if ( m_clip ) | |
660 | { | |
661 | DisposeRgn( m_clip ) ; | |
662 | DisposeThemeDrawingState( m_drawingState ) ; | |
663 | m_clip = NULL ; | |
664 | } | |
665 | } | |
666 | ||
667 | wxMacPortStateHelper::~wxMacPortStateHelper() | |
668 | { | |
669 | if ( m_clip ) | |
670 | { | |
671 | SetPort( m_currentPort ) ; | |
672 | SetClip( m_clip ) ; | |
673 | DisposeRgn( m_clip ) ; | |
674 | TextFont( m_textFont ); | |
675 | TextSize( m_textSize ); | |
676 | TextFace( m_textStyle ); | |
677 | TextMode( m_textMode ); | |
678 | SetThemeDrawingState( m_drawingState , true ) ; | |
679 | SetPort( m_oldPort ) ; | |
680 | } | |
681 | } | |
682 |