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