]>
Commit | Line | Data |
---|---|---|
03e11df5 | 1 | #include "wx/defs.h" |
5fde6fcc | 2 | #include "wx/dc.h" |
b03e4fcd | 3 | #include <MacTextEditor.h> |
72e7876b | 4 | |
f5c6eb5c | 5 | #ifndef __DARWIN__ |
a3d3d3bf GD |
6 | # include <Navigation.h> |
7 | # if defined(TARGET_CARBON) | |
8 | # if PM_USE_SESSION_APIS | |
9 | # include <PMCore.h> | |
10 | # endif | |
11 | # include <PMApplication.h> | |
66a09d47 SC |
12 | # else |
13 | # include <Printing.h> | |
a3d3d3bf | 14 | # endif |
03e11df5 | 15 | #endif |
5b781a67 | 16 | |
9c3c5849 SC |
17 | #ifndef __DARWIN__ |
18 | #include <Scrap.h> | |
19 | #endif | |
20 | #include "wx/mac/uma.h" | |
21 | ||
72055702 SC |
22 | // since we have decided that we only support 8.6 upwards we are |
23 | // checking for these minimum requirements in the startup code of | |
24 | // the application so all wxWindows code can safely assume that appearance 1.1 | |
25 | // windows manager, control manager, navigation services etc. are | |
26 | // present | |
e7b596fb | 27 | |
72e7876b SC |
28 | static bool sUMAHasAppearance = false ; |
29 | static long sUMAAppearanceVersion = 0 ; | |
2b5f62a0 | 30 | static long sUMASystemVersion = 0 ; |
0888ccc7 | 31 | static bool sUMAHasAquaLayout = false ; |
0e5a4d20 SC |
32 | static bool sUMASystemInitialized = false ; |
33 | ||
72e7876b SC |
34 | extern int gAGABackgroundColor ; |
35 | bool UMAHasAppearance() { return sUMAHasAppearance ; } | |
36 | long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; } | |
2b5f62a0 | 37 | long UMAGetSystemVersion() { return sUMASystemVersion ; } |
72e7876b SC |
38 | |
39 | static bool sUMAHasWindowManager = false ; | |
40 | static long sUMAWindowManagerAttr = 0 ; | |
41 | ||
42 | bool UMAHasWindowManager() { return sUMAHasWindowManager ; } | |
43 | long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; } | |
0888ccc7 | 44 | bool UMAHasAquaLayout() { return sUMAHasAquaLayout ; } |
0e5a4d20 | 45 | bool UMASystemIsInitialized() { return sUMASystemInitialized ; } |
72055702 | 46 | |
5b781a67 SC |
47 | void UMACleanupToolbox() |
48 | { | |
5b781a67 SC |
49 | if ( sUMAHasAppearance ) |
50 | { | |
51 | UnregisterAppearanceClient() ; | |
52 | } | |
5b781a67 SC |
53 | if ( NavServicesAvailable() ) |
54 | { | |
55 | NavUnload() ; | |
56 | } | |
f8eebb95 SC |
57 | if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress ) |
58 | TXNTerminateTextension( ) ; | |
5b781a67 | 59 | } |
72e7876b SC |
60 | void UMAInitToolbox( UInt16 inMoreMastersCalls ) |
61 | { | |
62 | #if !TARGET_CARBON | |
63 | ::MaxApplZone(); | |
64 | for (long i = 1; i <= inMoreMastersCalls; i++) | |
65 | ::MoreMasters(); | |
66 | ||
67 | ::InitGraf(&qd.thePort); | |
68 | ::InitFonts(); | |
72e7876b SC |
69 | ::InitMenus(); |
70 | ::TEInit(); | |
71 | ::InitDialogs(0L); | |
72 | ::FlushEvents(everyEvent, 0); | |
73 | ::InitCursor(); | |
74 | long total,contig; | |
75 | PurgeSpace(&total, &contig); | |
76 | #else | |
2f1ae414 | 77 | InitCursor(); |
72e7876b SC |
78 | #endif |
79 | ||
2b5f62a0 VZ |
80 | if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr) |
81 | sUMASystemVersion = 0x0000 ; | |
82 | ||
72e7876b SC |
83 | long theAppearance ; |
84 | if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr ) | |
85 | { | |
86 | sUMAHasAppearance = true ; | |
87 | RegisterAppearanceClient(); | |
88 | if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr ) | |
89 | { | |
90 | sUMAAppearanceVersion = theAppearance ; | |
91 | } | |
92 | else | |
93 | { | |
94 | sUMAAppearanceVersion = 0x0100 ; | |
95 | } | |
96 | } | |
72e7876b SC |
97 | if ( Gestalt( gestaltWindowMgrAttr, &sUMAWindowManagerAttr ) == noErr ) |
98 | { | |
99 | sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ; | |
100 | } | |
5b781a67 | 101 | |
8e8d3ba8 SC |
102 | #if TARGET_CARBON |
103 | // Call currently implicitely done : InitFloatingWindows() ; | |
104 | #else | |
5b781a67 SC |
105 | if ( sUMAHasWindowManager ) |
106 | InitFloatingWindows() ; | |
107 | else | |
108 | InitWindows(); | |
03e11df5 | 109 | #endif |
5b781a67 SC |
110 | |
111 | if ( NavServicesAvailable() ) | |
112 | { | |
113 | NavLoad() ; | |
114 | } | |
b03e4fcd | 115 | |
ded4fa5b SC |
116 | long menuMgrAttr ; |
117 | Gestalt( gestaltMenuMgrAttr , &menuMgrAttr ) ; | |
118 | if ( menuMgrAttr & gestaltMenuMgrAquaLayoutMask ) | |
119 | sUMAHasAquaLayout = true ; | |
120 | ||
f8eebb95 SC |
121 | if ( TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress ) |
122 | { | |
564bf1ea SC |
123 | FontFamilyID fontId ; |
124 | Str255 fontName ; | |
125 | SInt16 fontSize ; | |
126 | Style fontStyle ; | |
127 | GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; | |
128 | GetFNum( fontName, &fontId ); | |
129 | ||
130 | TXNMacOSPreferredFontDescription fontDescriptions[] = | |
131 | { | |
132 | { fontId , (fontSize << 16) ,kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } , | |
133 | } ; | |
134 | int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ; | |
54ddeb7e | 135 | #if 0 // TARGET_CARBON |
564bf1ea SC |
136 | --noOfFontDescriptions ; |
137 | #endif | |
138 | // kTXNAlwaysUseQuickDrawTextMask might be desirable because of speed increases but it crashes the app under OS X upon key stroke | |
54ddeb7e SC |
139 | OptionBits options = kTXNWantMoviesMask | kTXNWantSoundMask | kTXNWantGraphicsMask ; |
140 | #if TARGET_CARBON | |
141 | if ( !UMAHasAquaLayout() ) | |
142 | #endif | |
143 | { | |
144 | options |= kTXNAlwaysUseQuickDrawTextMask ; | |
145 | } | |
146 | TXNInitTextension(fontDescriptions, noOfFontDescriptions, options ); | |
147 | } | |
f8eebb95 | 148 | |
ded4fa5b | 149 | |
0e5a4d20 | 150 | sUMASystemInitialized = true ; |
66a09d47 | 151 | |
72e7876b SC |
152 | } |
153 | ||
66a09d47 SC |
154 | /* |
155 | Boolean CanUseATSUI() | |
156 | { | |
157 | long result; | |
158 | OSErr err = Gestalt(gestaltATSUVersion, &result); | |
159 | return (err == noErr); | |
160 | } | |
161 | */ | |
72e7876b SC |
162 | // process manager |
163 | long UMAGetProcessMode() | |
164 | { | |
165 | OSErr err ; | |
166 | ProcessInfoRec processinfo; | |
167 | ProcessSerialNumber procno ; | |
168 | ||
169 | procno.highLongOfPSN = NULL ; | |
170 | procno.lowLongOfPSN = kCurrentProcess ; | |
171 | processinfo.processInfoLength = sizeof(ProcessInfoRec); | |
172 | processinfo.processName = NULL; | |
173 | processinfo.processAppSpec = NULL; | |
174 | ||
175 | err = ::GetProcessInformation( &procno , &processinfo ) ; | |
176 | wxASSERT( err == noErr ) ; | |
177 | return processinfo.processMode ; | |
178 | } | |
179 | ||
180 | bool UMAGetProcessModeDoesActivateOnFGSwitch() | |
181 | { | |
182 | return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ; | |
183 | } | |
184 | ||
185 | // menu manager | |
186 | ||
bf918b97 | 187 | MenuRef UMANewMenu( SInt16 id , const wxString& title ) |
72e7876b | 188 | { |
bf918b97 SC |
189 | wxString str = wxStripMenuCodes( title ) ; |
190 | MenuRef menu ; | |
191 | #if TARGET_CARBON | |
192 | CFStringRef cfs = wxMacCreateCFString( str ) ; | |
193 | CreateNewMenu( id , 0 , &menu ) ; | |
194 | SetMenuTitleWithCFString( menu , cfs ) ; | |
195 | CFRelease( cfs ) ; | |
196 | #else | |
197 | Str255 ptitle ; | |
198 | wxMacStringToPascal( str , ptitle ) ; | |
199 | menu = ::NewMenu( id , ptitle ) ; | |
200 | #endif | |
201 | return menu ; | |
202 | } | |
72e7876b | 203 | |
bf918b97 SC |
204 | void UMASetMenuTitle( MenuRef menu , const wxString& title ) |
205 | { | |
206 | wxString str = wxStripMenuCodes( title ) ; | |
207 | #if TARGET_CARBON | |
208 | CFStringRef cfs = wxMacCreateCFString( str ) ; | |
209 | SetMenuTitleWithCFString( menu , cfs ) ; | |
210 | CFRelease( cfs ) ; | |
72e7876b | 211 | #else |
bf918b97 SC |
212 | Str255 ptitle ; |
213 | wxMacStringToPascal( str , ptitle ) ; | |
214 | SetMenuTitle( menu , ptitle ) ; | |
215 | #endif | |
72e7876b SC |
216 | } |
217 | ||
bf918b97 | 218 | void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title ) |
72e7876b | 219 | { |
bf918b97 SC |
220 | wxString str = wxStripMenuCodes( title ) ; |
221 | #if TARGET_CARBON | |
222 | CFStringRef cfs = wxMacCreateCFString( str ) ; | |
223 | SetMenuItemTextWithCFString( menu , item , cfs ) ; | |
224 | CFRelease( cfs ) ; | |
225 | #else | |
226 | Str255 ptitle ; | |
227 | wxMacStringToPascal( str , ptitle ) ; | |
228 | SetMenuItemText( menu , item , ptitle ) ; | |
229 | #endif | |
72e7876b SC |
230 | } |
231 | ||
bf918b97 SC |
232 | |
233 | UInt32 UMAMenuEvent( EventRecord *inEvent ) | |
72e7876b | 234 | { |
bf918b97 | 235 | return MenuEvent( inEvent ) ; |
72e7876b SC |
236 | } |
237 | ||
bf918b97 | 238 | void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable) |
72e7876b | 239 | { |
bf918b97 SC |
240 | if ( enable ) |
241 | EnableMenuItem( inMenu , inItem ) ; | |
242 | else | |
243 | DisableMenuItem( inMenu , inItem ) ; | |
72e7876b | 244 | } |
2f1ae414 | 245 | |
bf918b97 | 246 | void UMAAppendSubMenuItem( MenuRef menu , const wxString& title , SInt16 id ) |
2f1ae414 | 247 | { |
bf918b97 SC |
248 | MacAppendMenu(menu, "\pA"); |
249 | UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title ); | |
867e99f5 | 250 | SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ; |
2f1ae414 SC |
251 | } |
252 | ||
bf918b97 | 253 | void UMAInsertSubMenuItem( MenuRef menu , const wxString& title , MenuItemIndex item , SInt16 id ) |
2f1ae414 | 254 | { |
bf918b97 SC |
255 | MacInsertMenuItem(menu, "\pA" , item); |
256 | UMASetMenuItemText(menu, item , title ); | |
867e99f5 | 257 | SetMenuItemHierarchicalID( menu , item , id ) ; |
2f1ae414 SC |
258 | } |
259 | ||
bf918b97 | 260 | void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry ) |
2f1ae414 | 261 | { |
bf918b97 SC |
262 | if ( !entry ) |
263 | return ; | |
264 | ||
265 | UInt8 modifiers = 0 ; | |
266 | SInt16 key = entry->GetKeyCode() ; | |
2f1ae414 SC |
267 | if ( key ) |
268 | { | |
bf918b97 SC |
269 | bool explicitCommandKey = false ; |
270 | ||
271 | if ( entry->GetFlags() & wxACCEL_CTRL ) | |
272 | { | |
273 | explicitCommandKey = true ; | |
274 | } | |
275 | ||
276 | if (entry->GetFlags() & wxACCEL_ALT ) | |
277 | { | |
278 | modifiers |= kMenuOptionModifier ; | |
279 | } | |
280 | ||
281 | if (entry->GetFlags() & wxACCEL_SHIFT) | |
282 | { | |
283 | modifiers |= kMenuShiftModifier ; | |
284 | } | |
285 | ||
2b5f62a0 VZ |
286 | SInt16 glyph = 0 ; |
287 | SInt16 macKey = key ; | |
288 | if ( key >= WXK_F1 && key <= WXK_F15 ) | |
289 | { | |
290 | macKey = kFunctionKeyCharCode ; | |
291 | glyph = kMenuF1Glyph + ( key - WXK_F1 ) ; | |
292 | if ( key >= WXK_F13 ) | |
293 | glyph += 13 ; | |
bf918b97 SC |
294 | if ( !explicitCommandKey ) |
295 | modifiers |= kMenuNoCommandModifier ; | |
296 | ||
297 | switch( key ) | |
2b5f62a0 VZ |
298 | { |
299 | case WXK_F1 : | |
300 | macKey += ( 0x7a << 8 ) ; | |
301 | break ; | |
302 | case WXK_F2 : | |
303 | macKey += ( 0x78 << 8 ) ; | |
304 | break ; | |
305 | case WXK_F3 : | |
306 | macKey += ( 0x63 << 8 ) ; | |
307 | break ; | |
308 | case WXK_F4 : | |
309 | macKey += ( 0x76 << 8 ) ; | |
310 | break ; | |
311 | case WXK_F5 : | |
312 | macKey += ( 0x60 << 8 ) ; | |
313 | break ; | |
314 | case WXK_F6 : | |
315 | macKey += ( 0x61 << 8 ) ; | |
316 | break ; | |
317 | case WXK_F7 : | |
318 | macKey += ( 0x62 << 8 ) ; | |
319 | break ; | |
320 | case WXK_F8 : | |
321 | macKey += ( 0x64 << 8 ) ; | |
322 | break ; | |
323 | case WXK_F9 : | |
324 | macKey += ( 0x65 << 8 ) ; | |
325 | break ; | |
326 | case WXK_F10 : | |
327 | macKey += ( 0x6D << 8 ) ; | |
328 | break ; | |
329 | case WXK_F11 : | |
330 | macKey += ( 0x67 << 8 ) ; | |
331 | break ; | |
332 | case WXK_F12 : | |
333 | macKey += ( 0x6F << 8 ) ; | |
334 | break ; | |
335 | case WXK_F13 : | |
336 | macKey += ( 0x69 << 8 ) ; | |
337 | break ; | |
338 | case WXK_F14 : | |
339 | macKey += ( 0x6B << 8 ) ; | |
340 | break ; | |
341 | case WXK_F15 : | |
342 | macKey += ( 0x71 << 8 ) ; | |
343 | break ; | |
344 | default : | |
345 | break ; | |
346 | } ; | |
347 | // unfortunately this does not yet trigger the right key , | |
348 | // for some reason mac justs picks the first function key menu | |
349 | // defined, so we turn this off | |
350 | macKey = 0 ; | |
351 | glyph = 0 ; | |
352 | } | |
353 | else | |
354 | { | |
355 | switch( key ) | |
356 | { | |
357 | case WXK_BACK : | |
358 | macKey = kBackspaceCharCode ; | |
359 | glyph = kMenuDeleteLeftGlyph ; | |
360 | break ; | |
361 | case WXK_TAB : | |
362 | macKey = kTabCharCode ; | |
363 | glyph = kMenuTabRightGlyph ; | |
364 | break ; | |
365 | case kEnterCharCode : | |
366 | macKey = kEnterCharCode ; | |
367 | glyph = kMenuEnterGlyph ; | |
368 | break ; | |
369 | case WXK_RETURN : | |
370 | macKey = kReturnCharCode ; | |
371 | glyph = kMenuReturnGlyph ; | |
372 | break ; | |
373 | case WXK_ESCAPE : | |
374 | macKey = kEscapeCharCode ; | |
375 | glyph = kMenuEscapeGlyph ; | |
376 | break ; | |
377 | case WXK_SPACE : | |
378 | macKey = ' ' ; | |
379 | glyph = kMenuSpaceGlyph ; | |
380 | break ; | |
381 | case WXK_DELETE : | |
382 | macKey = kDeleteCharCode ; | |
383 | glyph = kMenuDeleteRightGlyph ; | |
384 | break ; | |
385 | case WXK_CLEAR : | |
386 | macKey = kClearCharCode ; | |
387 | glyph = kMenuClearGlyph ; | |
388 | break ; | |
389 | case WXK_PRIOR : // PAGE UP | |
390 | macKey = kPageUpCharCode ; | |
391 | glyph = kMenuPageUpGlyph ; | |
392 | break ; | |
393 | case WXK_NEXT : | |
394 | macKey = kPageDownCharCode ; | |
395 | glyph = kMenuPageDownGlyph ; | |
396 | break ; | |
397 | case WXK_LEFT : | |
398 | macKey = kLeftArrowCharCode ; | |
399 | glyph = kMenuLeftArrowGlyph ; | |
400 | break ; | |
401 | case WXK_UP : | |
402 | macKey = kUpArrowCharCode ; | |
403 | glyph = kMenuUpArrowGlyph ; | |
404 | break ; | |
405 | case WXK_RIGHT : | |
406 | macKey = kRightArrowCharCode ; | |
407 | glyph = kMenuRightArrowGlyph ; | |
408 | break ; | |
409 | case WXK_DOWN : | |
410 | macKey = kDownArrowCharCode ; | |
411 | glyph = kMenuDownArrowGlyph ; | |
412 | break ; | |
413 | } | |
414 | } | |
bf918b97 | 415 | |
2b5f62a0 VZ |
416 | SetItemCmd( menu, item , macKey ); |
417 | SetMenuItemModifiers(menu, item , modifiers ) ; | |
418 | ||
419 | if ( glyph ) | |
420 | SetMenuItemKeyGlyph(menu, item , glyph ) ; | |
2f1ae414 | 421 | } |
2b5f62a0 VZ |
422 | } |
423 | ||
bf918b97 | 424 | void UMAAppendMenuItem( MenuRef menu , const wxString& title , wxAcceleratorEntry *entry ) |
2b5f62a0 VZ |
425 | { |
426 | MacAppendMenu(menu, "\pA"); | |
bf918b97 SC |
427 | UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title ); |
428 | UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ; | |
2f1ae414 SC |
429 | } |
430 | ||
bf918b97 | 431 | void UMAInsertMenuItem( MenuRef menu , const wxString& title , MenuItemIndex item , wxAcceleratorEntry *entry ) |
2f1ae414 | 432 | { |
2b5f62a0 | 433 | MacInsertMenuItem( menu , "\p" , item) ; |
bf918b97 SC |
434 | UMASetMenuItemText(menu, item , title ); |
435 | UMASetMenuItemShortcut( menu , item , entry ) ; | |
2f1ae414 SC |
436 | } |
437 | ||
72e7876b SC |
438 | // quickdraw |
439 | ||
2f1ae414 SC |
440 | int gPrOpenCounter = 0 ; |
441 | ||
a3d3d3bf | 442 | OSStatus UMAPrOpen(void *macPrintSession) |
2f1ae414 SC |
443 | { |
444 | #if !TARGET_CARBON | |
445 | OSErr err = noErr ; | |
446 | ++gPrOpenCounter ; | |
447 | if ( gPrOpenCounter == 1 ) | |
448 | { | |
449 | PrOpen() ; | |
450 | err = PrError() ; | |
451 | wxASSERT( err == noErr ) ; | |
452 | } | |
5b781a67 | 453 | return err ; |
2f1ae414 | 454 | #else |
5b781a67 SC |
455 | OSStatus err = noErr ; |
456 | ++gPrOpenCounter ; | |
457 | if ( gPrOpenCounter == 1 ) | |
458 | { | |
a689a4d0 | 459 | #if PM_USE_SESSION_APIS |
a3d3d3bf | 460 | err = PMCreateSession((PMPrintSession *)macPrintSession) ; |
a689a4d0 GD |
461 | #else |
462 | err = PMBegin() ; | |
463 | #endif | |
5b781a67 SC |
464 | wxASSERT( err == noErr ) ; |
465 | } | |
466 | return err ; | |
2f1ae414 SC |
467 | #endif |
468 | } | |
469 | ||
a3d3d3bf | 470 | OSStatus UMAPrClose(void *macPrintSession) |
2f1ae414 SC |
471 | { |
472 | #if !TARGET_CARBON | |
473 | OSErr err = noErr ; | |
474 | wxASSERT( gPrOpenCounter >= 1 ) ; | |
475 | if ( gPrOpenCounter == 1 ) | |
476 | { | |
477 | PrClose() ; | |
478 | err = PrError() ; | |
479 | wxASSERT( err == noErr ) ; | |
480 | } | |
481 | --gPrOpenCounter ; | |
5b781a67 | 482 | return err ; |
2f1ae414 | 483 | #else |
5b781a67 SC |
484 | OSStatus err = noErr ; |
485 | wxASSERT( gPrOpenCounter >= 1 ) ; | |
486 | if ( gPrOpenCounter == 1 ) | |
487 | { | |
a689a4d0 | 488 | #if PM_USE_SESSION_APIS |
a3d3d3bf GD |
489 | err = PMRelease(*(PMPrintSession *)macPrintSession) ; |
490 | *(PMPrintSession *)macPrintSession = kPMNoReference; | |
a689a4d0 GD |
491 | #else |
492 | err = PMEnd() ; | |
493 | #endif | |
5b781a67 SC |
494 | } |
495 | --gPrOpenCounter ; | |
496 | return err ; | |
2f1ae414 SC |
497 | #endif |
498 | } | |
499 | ||
72e7876b SC |
500 | #if !TARGET_CARBON |
501 | ||
72055702 | 502 | pascal QDGlobalsPtr GetQDGlobalsPtr (void) ; |
72e7876b SC |
503 | pascal QDGlobalsPtr GetQDGlobalsPtr (void) |
504 | { | |
505 | return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA); | |
506 | } | |
507 | ||
508 | #endif | |
509 | ||
510 | void UMAShowWatchCursor() | |
511 | { | |
512 | OSErr err = noErr; | |
513 | ||
514 | CursHandle watchFob = GetCursor (watchCursor); | |
515 | ||
516 | if (!watchFob) | |
517 | err = nilHandleErr; | |
518 | else | |
519 | { | |
520 | #if TARGET_CARBON | |
72055702 SC |
521 | // Cursor preservedArrow; |
522 | // GetQDGlobalsArrow (&preservedArrow); | |
523 | // SetQDGlobalsArrow (*watchFob); | |
524 | // InitCursor ( ); | |
525 | // SetQDGlobalsArrow (&preservedArrow); | |
526 | SetCursor (*watchFob); | |
72e7876b SC |
527 | #else |
528 | SetCursor (*watchFob); | |
529 | #endif | |
530 | } | |
531 | } | |
532 | ||
533 | void UMAShowArrowCursor() | |
534 | { | |
535 | #if TARGET_CARBON | |
536 | Cursor arrow; | |
537 | SetCursor (GetQDGlobalsArrow (&arrow)); | |
538 | #else | |
539 | SetCursor (&(qd.arrow)); | |
540 | #endif | |
541 | } | |
542 | ||
543 | // window manager | |
544 | ||
545 | GrafPtr UMAGetWindowPort( WindowRef inWindowRef ) | |
546 | { | |
547 | wxASSERT( inWindowRef != NULL ) ; | |
548 | #if TARGET_CARBON | |
cf6674a4 | 549 | return (GrafPtr) GetWindowPort( inWindowRef ) ; |
72e7876b SC |
550 | #else |
551 | return (GrafPtr) inWindowRef ; | |
552 | #endif | |
553 | } | |
554 | ||
555 | void UMADisposeWindow( WindowRef inWindowRef ) | |
556 | { | |
557 | wxASSERT( inWindowRef != NULL ) ; | |
558 | DisposeWindow( inWindowRef ) ; | |
559 | } | |
560 | ||
561 | void UMASetWTitleC( WindowRef inWindowRef , const char *title ) | |
562 | { | |
563 | Str255 ptitle ; | |
564 | strncpy( (char*)ptitle , title , 96 ) ; | |
565 | ptitle[96] = 0 ; | |
03e11df5 GD |
566 | #if TARGET_CARBON |
567 | c2pstrcpy( ptitle, (char *)ptitle ) ; | |
568 | #else | |
72e7876b | 569 | c2pstr( (char*)ptitle ) ; |
03e11df5 | 570 | #endif |
72e7876b SC |
571 | SetWTitle( inWindowRef , ptitle ) ; |
572 | } | |
03e11df5 | 573 | |
72e7876b SC |
574 | void UMAGetWTitleC( WindowRef inWindowRef , char *title ) |
575 | { | |
576 | GetWTitle( inWindowRef , (unsigned char*)title ) ; | |
03e11df5 GD |
577 | #if TARGET_CARBON |
578 | p2cstrcpy( title, (unsigned char *)title ) ; | |
579 | #else | |
72e7876b | 580 | p2cstr( (unsigned char*)title ) ; |
03e11df5 | 581 | #endif |
72e7876b SC |
582 | } |
583 | ||
72e7876b SC |
584 | // appearance additions |
585 | ||
586 | void UMAActivateControl( ControlHandle inControl ) | |
587 | { | |
22e751a5 SC |
588 | // we have to add the control after again to the update rgn |
589 | // otherwise updates get lost | |
590 | if ( !IsControlActive( inControl ) ) | |
591 | { | |
fdaf613a SC |
592 | bool visible = IsControlVisible( inControl ) ; |
593 | if ( visible ) | |
594 | SetControlVisibility( inControl , false , false ) ; | |
3f4902f5 | 595 | ::ActivateControl( inControl ) ; |
fdaf613a SC |
596 | if ( visible ) { |
597 | SetControlVisibility( inControl , true , false ) ; | |
c36f0244 SC |
598 | Rect ctrlBounds ; |
599 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
fdaf613a | 600 | } |
22e751a5 | 601 | } |
72e7876b SC |
602 | } |
603 | ||
604 | void UMADrawControl( ControlHandle inControl ) | |
605 | { | |
3f4902f5 GD |
606 | WindowRef theWindow = GetControlOwner(inControl) ; |
607 | RgnHandle updateRgn = NewRgn() ; | |
3f4902f5 | 608 | GetWindowUpdateRgn( theWindow , updateRgn ) ; |
22e751a5 SC |
609 | Point zero = { 0 , 0 } ; |
610 | LocalToGlobal( &zero ) ; | |
611 | OffsetRgn( updateRgn , -zero.h , -zero.v ) ; | |
612 | ::DrawControlInCurrentPort( inControl ) ; | |
613 | InvalWindowRgn( theWindow, updateRgn) ; | |
614 | DisposeRgn( updateRgn ) ; | |
72e7876b SC |
615 | } |
616 | ||
617 | void UMAMoveControl( ControlHandle inControl , short x , short y ) | |
618 | { | |
72055702 SC |
619 | bool visible = IsControlVisible( inControl ) ; |
620 | if ( visible ) { | |
621 | SetControlVisibility( inControl , false , false ) ; | |
622 | Rect ctrlBounds ; | |
623 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
624 | } | |
625 | ::MoveControl( inControl , x , y ) ; | |
626 | if ( visible ) { | |
627 | SetControlVisibility( inControl , true , false ) ; | |
628 | Rect ctrlBounds ; | |
629 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
630 | } | |
72e7876b SC |
631 | } |
632 | ||
633 | void UMASizeControl( ControlHandle inControl , short x , short y ) | |
634 | { | |
72055702 SC |
635 | bool visible = IsControlVisible( inControl ) ; |
636 | if ( visible ) { | |
637 | SetControlVisibility( inControl , false , false ) ; | |
638 | Rect ctrlBounds ; | |
639 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
b03e4fcd | 640 | } |
72055702 SC |
641 | ::SizeControl( inControl , x , y ) ; |
642 | if ( visible ) { | |
643 | SetControlVisibility( inControl , true , false ) ; | |
644 | Rect ctrlBounds ; | |
645 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
646 | } | |
72e7876b SC |
647 | } |
648 | ||
649 | void UMADeactivateControl( ControlHandle inControl ) | |
650 | { | |
22e751a5 SC |
651 | // we have to add the control after again to the update rgn |
652 | // otherwise updates get lost | |
72055702 SC |
653 | bool visible = IsControlVisible( inControl ) ; |
654 | if ( visible ) | |
655 | SetControlVisibility( inControl , false , false ) ; | |
656 | ::DeactivateControl( inControl ) ; | |
657 | if ( visible ) { | |
658 | SetControlVisibility( inControl , true , false ) ; | |
659 | Rect ctrlBounds ; | |
660 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
661 | } | |
72e7876b | 662 | } |
fdaf613a | 663 | // shows the control and adds the region to the update region |
3f4902f5 | 664 | void UMAShowControl (ControlHandle inControl) |
72e7876b | 665 | { |
fdaf613a | 666 | SetControlVisibility( inControl , true , false ) ; |
c36f0244 SC |
667 | Rect ctrlBounds ; |
668 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
72e7876b SC |
669 | } |
670 | ||
22e751a5 SC |
671 | // shows the control and adds the region to the update region |
672 | void UMAHideControl (ControlHandle inControl) | |
673 | { | |
674 | SetControlVisibility( inControl , false , false ) ; | |
675 | Rect ctrlBounds ; | |
676 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
677 | } | |
72e7876b SC |
678 | // keyboard focus |
679 | OSErr UMASetKeyboardFocus (WindowPtr inWindow, | |
680 | ControlHandle inControl, | |
681 | ControlFocusPart inPart) | |
682 | { | |
2f1ae414 SC |
683 | OSErr err = noErr; |
684 | GrafPtr port ; | |
685 | GetPort( &port ) ; | |
72055702 SC |
686 | |
687 | SetPortWindowPort( inWindow ) ; | |
688 | ||
72055702 | 689 | err = SetKeyboardFocus( inWindow , inControl , inPart ) ; |
2f1ae414 SC |
690 | SetPort( port ) ; |
691 | return err ; | |
72e7876b SC |
692 | } |
693 | ||
694 | ||
695 | ||
696 | ||
697 | // events | |
72e7876b SC |
698 | void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn ) |
699 | { | |
72055702 SC |
700 | RgnHandle updateRgn = NewRgn() ; |
701 | GetWindowUpdateRgn( inWindow , updateRgn ) ; | |
702 | ||
be57fda6 SC |
703 | Point zero = { 0 , 0 } ; |
704 | LocalToGlobal( &zero ) ; | |
705 | OffsetRgn( updateRgn , -zero.h , -zero.v ) ; | |
72e7876b | 706 | |
72055702 SC |
707 | UpdateControls( inWindow , inRgn ) ; |
708 | InvalWindowRgn( inWindow, updateRgn) ; | |
709 | DisposeRgn( updateRgn ) ; | |
72e7876b | 710 | |
72e7876b SC |
711 | } |
712 | ||
713 | bool UMAIsWindowFloating( WindowRef inWindow ) | |
714 | { | |
715 | WindowClass cl ; | |
716 | ||
72055702 | 717 | GetWindowClass( inWindow , &cl ) ; |
72e7876b SC |
718 | return cl == kFloatingWindowClass ; |
719 | } | |
720 | ||
721 | bool UMAIsWindowModal( WindowRef inWindow ) | |
722 | { | |
723 | WindowClass cl ; | |
724 | ||
72055702 | 725 | GetWindowClass( inWindow , &cl ) ; |
72e7876b SC |
726 | return cl < kFloatingWindowClass ; |
727 | } | |
728 | ||
729 | // others | |
730 | ||
731 | void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ) | |
732 | { | |
733 | if ( inWindowRef ) | |
734 | { | |
735 | // bool isHighlighted = IsWindowHighlited( inWindowRef ) ; | |
736 | // if ( inActivate != isHightlited ) | |
c809f3be SC |
737 | GrafPtr port ; |
738 | GetPort( &port ) ; | |
72055702 | 739 | SetPortWindowPort( inWindowRef ) ; |
c809f3be SC |
740 | HiliteWindow( inWindowRef , inActivate ) ; |
741 | ControlHandle control = NULL ; | |
72055702 | 742 | ::GetRootControl( inWindowRef , & control ) ; |
c809f3be SC |
743 | if ( control ) |
744 | { | |
745 | if ( inActivate ) | |
746 | UMAActivateControl( control ) ; | |
747 | else | |
748 | UMADeactivateControl( control ) ; | |
749 | } | |
750 | SetPort( port ) ; | |
72e7876b SC |
751 | } |
752 | } | |
2f1ae414 SC |
753 | OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ) |
754 | { | |
72055702 | 755 | return ::DrawThemePlacard( inRect , inState ) ; |
2f1ae414 | 756 | } |
72e7876b | 757 | |
2f056c85 | 758 | #if !TARGET_CARBON |
b03e4fcd | 759 | static OSStatus helpMenuStatus = noErr ; |
b03e4fcd | 760 | static MenuItemIndex firstCustomItemIndex = 0 ; |
2f056c85 | 761 | #endif |
b03e4fcd SC |
762 | |
763 | OSStatus UMAGetHelpMenu( | |
764 | MenuRef * outHelpMenu, | |
765 | MenuItemIndex * outFirstCustomItemIndex) | |
766 | { | |
767 | #if TARGET_CARBON | |
768 | return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ; | |
769 | #else | |
ca5e5bad SC |
770 | MenuRef helpMenuHandle ; |
771 | helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ; | |
772 | if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr ) | |
b03e4fcd | 773 | { |
ca5e5bad | 774 | firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ; |
b03e4fcd SC |
775 | } |
776 | if ( outFirstCustomItemIndex ) | |
777 | { | |
778 | *outFirstCustomItemIndex = firstCustomItemIndex ; | |
779 | } | |
780 | *outHelpMenu = helpMenuHandle ; | |
781 | return helpMenuStatus ; | |
782 | #endif | |
783 | } | |
76a5e5d2 SC |
784 | |
785 | wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport) | |
786 | { | |
787 | m_clip = NULL ; | |
788 | Setup( newport ) ; | |
789 | } | |
790 | ||
791 | wxMacPortStateHelper::wxMacPortStateHelper() | |
792 | { | |
793 | m_clip = NULL ; | |
794 | } | |
795 | ||
796 | void wxMacPortStateHelper::Setup( GrafPtr newport ) | |
797 | { | |
798 | GetPort( &m_oldPort ) ; | |
799 | SetPort( newport ) ; | |
800 | wxASSERT_MSG( m_clip == NULL , "Cannot call setup twice" ) ; | |
801 | m_clip = NewRgn() ; | |
802 | GetClip( m_clip ); | |
803 | m_textFont = GetPortTextFont( (CGrafPtr) newport); | |
804 | m_textSize = GetPortTextSize( (CGrafPtr) newport); | |
805 | m_textStyle = GetPortTextFace( (CGrafPtr) newport); | |
806 | m_textMode = GetPortTextMode( (CGrafPtr) newport); | |
807 | GetThemeDrawingState( &m_drawingState ) ; | |
808 | m_currentPort = newport ; | |
809 | } | |
810 | void wxMacPortStateHelper::Clear() | |
811 | { | |
812 | if ( m_clip ) | |
813 | { | |
814 | DisposeRgn( m_clip ) ; | |
815 | DisposeThemeDrawingState( m_drawingState ) ; | |
816 | m_clip = NULL ; | |
817 | } | |
818 | } | |
819 | ||
820 | wxMacPortStateHelper::~wxMacPortStateHelper() | |
821 | { | |
822 | if ( m_clip ) | |
823 | { | |
824 | SetPort( m_currentPort ) ; | |
825 | SetClip( m_clip ) ; | |
826 | DisposeRgn( m_clip ) ; | |
827 | TextFont( m_textFont ); | |
828 | TextSize( m_textSize ); | |
829 | TextFace( m_textStyle ); | |
830 | TextMode( m_textMode ); | |
831 | SetThemeDrawingState( m_drawingState , true ) ; | |
832 | SetPort( m_oldPort ) ; | |
833 | } | |
834 | } | |
835 | ||
9c3c5849 SC |
836 | OSStatus UMAPutScrap( Size size , OSType type , void *data ) |
837 | { | |
838 | OSStatus err = noErr ; | |
839 | #if !TARGET_CARBON | |
840 | err = PutScrap( size , type , data ) ; | |
841 | #else | |
842 | ScrapRef scrap; | |
843 | err = GetCurrentScrap (&scrap); | |
844 | if ( !err ) | |
845 | { | |
846 | err = PutScrapFlavor (scrap, type , 0, size, data); | |
847 | } | |
848 | #endif | |
849 | return err ; | |
850 | } | |
851 |