]>
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 | |
e40298d5 | 28 | static bool sUMAHasAppearance = false ; |
72e7876b | 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 | 38 | |
e40298d5 | 39 | static bool sUMAHasWindowManager = false ; |
72e7876b SC |
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 | { | |
e40298d5 JS |
49 | if ( sUMAHasAppearance ) |
50 | { | |
51 | UnregisterAppearanceClient() ; | |
52 | } | |
53 | if ( NavServicesAvailable() ) | |
54 | { | |
55 | NavUnload() ; | |
56 | } | |
f8eebb95 | 57 | if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress ) |
e40298d5 | 58 | TXNTerminateTextension( ) ; |
5b781a67 | 59 | } |
72e7876b SC |
60 | void UMAInitToolbox( UInt16 inMoreMastersCalls ) |
61 | { | |
62 | #if !TARGET_CARBON | |
e40298d5 JS |
63 | ::MaxApplZone(); |
64 | for (long i = 1; i <= inMoreMastersCalls; i++) | |
65 | ::MoreMasters(); | |
66 | ||
67 | ::InitGraf(&qd.thePort); | |
68 | ::InitFonts(); | |
69 | ::InitMenus(); | |
70 | ::TEInit(); | |
71 | ::InitDialogs(0L); | |
72 | ::FlushEvents(everyEvent, 0); | |
73 | ::InitCursor(); | |
74 | long total,contig; | |
75 | PurgeSpace(&total, &contig); | |
72e7876b | 76 | #else |
e40298d5 | 77 | InitCursor(); |
72e7876b SC |
78 | #endif |
79 | ||
2b5f62a0 | 80 | if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr) |
e40298d5 JS |
81 | sUMASystemVersion = 0x0000 ; |
82 | ||
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 | } | |
97 | if ( Gestalt( gestaltWindowMgrAttr, &sUMAWindowManagerAttr ) == noErr ) | |
98 | { | |
99 | sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ; | |
100 | } | |
101 | ||
8e8d3ba8 | 102 | #if TARGET_CARBON |
e40298d5 | 103 | // Call currently implicitely done : InitFloatingWindows() ; |
8e8d3ba8 | 104 | #else |
e40298d5 JS |
105 | if ( sUMAHasWindowManager ) |
106 | InitFloatingWindows() ; | |
107 | else | |
108 | InitWindows(); | |
03e11df5 | 109 | #endif |
5b781a67 | 110 | |
e40298d5 JS |
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 | 123 | FontFamilyID fontId ; |
e40298d5 JS |
124 | Str255 fontName ; |
125 | SInt16 fontSize ; | |
126 | Style fontStyle ; | |
127 | GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; | |
564bf1ea SC |
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 | |
e40298d5 JS |
138 | // kTXNAlwaysUseQuickDrawTextMask might be desirable because of speed increases but it crashes the app under OS X upon key stroke |
139 | OptionBits options = kTXNWantMoviesMask | kTXNWantSoundMask | kTXNWantGraphicsMask ; | |
54ddeb7e SC |
140 | #if TARGET_CARBON |
141 | if ( !UMAHasAquaLayout() ) | |
142 | #endif | |
143 | { | |
144 | options |= kTXNAlwaysUseQuickDrawTextMask ; | |
145 | } | |
e40298d5 | 146 | TXNInitTextension(fontDescriptions, noOfFontDescriptions, options ); |
54ddeb7e | 147 | } |
f8eebb95 | 148 | |
ded4fa5b | 149 | |
0e5a4d20 | 150 | sUMASystemInitialized = true ; |
66a09d47 | 151 | |
72e7876b SC |
152 | } |
153 | ||
66a09d47 SC |
154 | /* |
155 | Boolean CanUseATSUI() | |
e40298d5 JS |
156 | { |
157 | long result; | |
158 | OSErr err = Gestalt(gestaltATSUVersion, &result); | |
159 | return (err == noErr); | |
160 | } | |
66a09d47 | 161 | */ |
72e7876b SC |
162 | // process manager |
163 | long UMAGetProcessMode() | |
164 | { | |
e40298d5 JS |
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; | |
72e7876b | 174 | |
e40298d5 JS |
175 | err = ::GetProcessInformation( &procno , &processinfo ) ; |
176 | wxASSERT( err == noErr ) ; | |
177 | return processinfo.processMode ; | |
72e7876b SC |
178 | } |
179 | ||
180 | bool UMAGetProcessModeDoesActivateOnFGSwitch() | |
181 | { | |
e40298d5 | 182 | return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ; |
72e7876b SC |
183 | } |
184 | ||
185 | // menu manager | |
186 | ||
bf918b97 | 187 | MenuRef UMANewMenu( SInt16 id , const wxString& title ) |
72e7876b | 188 | { |
e40298d5 JS |
189 | wxString str = wxStripMenuCodes( title ) ; |
190 | MenuRef menu ; | |
bf918b97 | 191 | #if TARGET_CARBON |
e40298d5 JS |
192 | CFStringRef cfs = wxMacCreateCFString( str ) ; |
193 | CreateNewMenu( id , 0 , &menu ) ; | |
194 | SetMenuTitleWithCFString( menu , cfs ) ; | |
195 | CFRelease( cfs ) ; | |
bf918b97 | 196 | #else |
e40298d5 JS |
197 | Str255 ptitle ; |
198 | wxMacStringToPascal( str , ptitle ) ; | |
199 | menu = ::NewMenu( id , ptitle ) ; | |
bf918b97 | 200 | #endif |
e40298d5 | 201 | return menu ; |
bf918b97 | 202 | } |
72e7876b | 203 | |
bf918b97 SC |
204 | void UMASetMenuTitle( MenuRef menu , const wxString& title ) |
205 | { | |
e40298d5 | 206 | wxString str = wxStripMenuCodes( title ) ; |
bf918b97 | 207 | #if TARGET_CARBON |
e40298d5 JS |
208 | CFStringRef cfs = wxMacCreateCFString( str ) ; |
209 | SetMenuTitleWithCFString( menu , cfs ) ; | |
210 | CFRelease( cfs ) ; | |
72e7876b | 211 | #else |
e40298d5 JS |
212 | Str255 ptitle ; |
213 | wxMacStringToPascal( str , ptitle ) ; | |
214 | SetMenuTitle( menu , ptitle ) ; | |
bf918b97 | 215 | #endif |
72e7876b SC |
216 | } |
217 | ||
bf918b97 | 218 | void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title ) |
72e7876b | 219 | { |
e40298d5 | 220 | wxString str = wxStripMenuCodes( title ) ; |
bf918b97 | 221 | #if TARGET_CARBON |
e40298d5 JS |
222 | CFStringRef cfs = wxMacCreateCFString( str ) ; |
223 | SetMenuItemTextWithCFString( menu , item , cfs ) ; | |
224 | CFRelease( cfs ) ; | |
bf918b97 | 225 | #else |
e40298d5 JS |
226 | Str255 ptitle ; |
227 | wxMacStringToPascal( str , ptitle ) ; | |
228 | SetMenuItemText( menu , item , ptitle ) ; | |
bf918b97 | 229 | #endif |
72e7876b SC |
230 | } |
231 | ||
bf918b97 SC |
232 | |
233 | UInt32 UMAMenuEvent( EventRecord *inEvent ) | |
72e7876b | 234 | { |
e40298d5 | 235 | return MenuEvent( inEvent ) ; |
72e7876b SC |
236 | } |
237 | ||
bf918b97 | 238 | void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable) |
72e7876b | 239 | { |
e40298d5 JS |
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 | { |
e40298d5 JS |
248 | MacAppendMenu(menu, "\pA"); |
249 | UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title ); | |
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 | { |
e40298d5 JS |
255 | MacInsertMenuItem(menu, "\pA" , item); |
256 | UMASetMenuItemText(menu, item , title ); | |
257 | SetMenuItemHierarchicalID( menu , item , id ) ; | |
2f1ae414 SC |
258 | } |
259 | ||
bf918b97 | 260 | void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry ) |
2f1ae414 | 261 | { |
e40298d5 JS |
262 | if ( !entry ) |
263 | return ; | |
264 | ||
265 | UInt8 modifiers = 0 ; | |
266 | SInt16 key = entry->GetKeyCode() ; | |
267 | if ( key ) | |
268 | { | |
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 | ||
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 | 294 | if ( !explicitCommandKey ) |
e40298d5 JS |
295 | modifiers |= kMenuNoCommandModifier ; |
296 | ||
297 | switch( key ) | |
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 ; | |
2b5f62a0 VZ |
413 | } |
414 | } | |
bf918b97 | 415 | |
e40298d5 JS |
416 | SetItemCmd( menu, item , macKey ); |
417 | SetMenuItemModifiers(menu, item , modifiers ) ; | |
2b5f62a0 VZ |
418 | |
419 | if ( glyph ) | |
420 | SetMenuItemKeyGlyph(menu, item , glyph ) ; | |
e40298d5 | 421 | } |
2b5f62a0 VZ |
422 | } |
423 | ||
bf918b97 | 424 | void UMAAppendMenuItem( MenuRef menu , const wxString& title , wxAcceleratorEntry *entry ) |
2b5f62a0 | 425 | { |
e40298d5 JS |
426 | MacAppendMenu(menu, "\pA"); |
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 | { |
e40298d5 JS |
433 | MacInsertMenuItem( menu , "\p" , item) ; |
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 | |
e40298d5 JS |
445 | OSErr err = noErr ; |
446 | ++gPrOpenCounter ; | |
447 | if ( gPrOpenCounter == 1 ) | |
448 | { | |
449 | PrOpen() ; | |
450 | err = PrError() ; | |
451 | wxASSERT( err == noErr ) ; | |
452 | } | |
453 | return err ; | |
2f1ae414 | 454 | #else |
e40298d5 JS |
455 | OSStatus err = noErr ; |
456 | ++gPrOpenCounter ; | |
457 | if ( gPrOpenCounter == 1 ) | |
458 | { | |
a689a4d0 | 459 | #if PM_USE_SESSION_APIS |
e40298d5 | 460 | err = PMCreateSession((PMPrintSession *)macPrintSession) ; |
a689a4d0 | 461 | #else |
e40298d5 | 462 | err = PMBegin() ; |
a689a4d0 | 463 | #endif |
e40298d5 JS |
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 | |
e40298d5 JS |
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 ; | |
482 | return err ; | |
2f1ae414 | 483 | #else |
e40298d5 JS |
484 | OSStatus err = noErr ; |
485 | wxASSERT( gPrOpenCounter >= 1 ) ; | |
486 | if ( gPrOpenCounter == 1 ) | |
487 | { | |
a689a4d0 | 488 | #if PM_USE_SESSION_APIS |
e40298d5 JS |
489 | err = PMRelease(*(PMPrintSession *)macPrintSession) ; |
490 | *(PMPrintSession *)macPrintSession = kPMNoReference; | |
a689a4d0 | 491 | #else |
e40298d5 | 492 | err = PMEnd() ; |
a689a4d0 | 493 | #endif |
e40298d5 JS |
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 | { | |
e40298d5 | 505 | return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA); |
72e7876b SC |
506 | } |
507 | ||
508 | #endif | |
509 | ||
510 | void UMAShowWatchCursor() | |
511 | { | |
e40298d5 | 512 | OSErr err = noErr; |
72e7876b | 513 | |
e40298d5 | 514 | CursHandle watchFob = GetCursor (watchCursor); |
72e7876b | 515 | |
e40298d5 JS |
516 | if (!watchFob) |
517 | err = nilHandleErr; | |
518 | else | |
519 | { | |
520 | #if TARGET_CARBON | |
521 | // Cursor preservedArrow; | |
522 | // GetQDGlobalsArrow (&preservedArrow); | |
523 | // SetQDGlobalsArrow (*watchFob); | |
524 | // InitCursor ( ); | |
525 | // SetQDGlobalsArrow (&preservedArrow); | |
526 | SetCursor (*watchFob); | |
527 | #else | |
528 | SetCursor (*watchFob); | |
529 | #endif | |
530 | } | |
72e7876b SC |
531 | } |
532 | ||
e40298d5 | 533 | void UMAShowArrowCursor() |
72e7876b SC |
534 | { |
535 | #if TARGET_CARBON | |
e40298d5 JS |
536 | Cursor arrow; |
537 | SetCursor (GetQDGlobalsArrow (&arrow)); | |
72e7876b | 538 | #else |
e40298d5 | 539 | SetCursor (&(qd.arrow)); |
72e7876b SC |
540 | #endif |
541 | } | |
542 | ||
543 | // window manager | |
544 | ||
e40298d5 | 545 | GrafPtr UMAGetWindowPort( WindowRef inWindowRef ) |
72e7876b | 546 | { |
e40298d5 | 547 | wxASSERT( inWindowRef != NULL ) ; |
72e7876b | 548 | #if TARGET_CARBON |
e40298d5 | 549 | return (GrafPtr) GetWindowPort( inWindowRef ) ; |
72e7876b | 550 | #else |
e40298d5 | 551 | return (GrafPtr) inWindowRef ; |
72e7876b SC |
552 | #endif |
553 | } | |
554 | ||
e40298d5 | 555 | void UMADisposeWindow( WindowRef inWindowRef ) |
72e7876b | 556 | { |
e40298d5 JS |
557 | wxASSERT( inWindowRef != NULL ) ; |
558 | DisposeWindow( inWindowRef ) ; | |
72e7876b SC |
559 | } |
560 | ||
e40298d5 | 561 | void UMASetWTitleC( WindowRef inWindowRef , const char *title ) |
72e7876b | 562 | { |
e40298d5 JS |
563 | Str255 ptitle ; |
564 | strncpy( (char*)ptitle , title , 96 ) ; | |
565 | ptitle[96] = 0 ; | |
03e11df5 | 566 | #if TARGET_CARBON |
e40298d5 | 567 | c2pstrcpy( ptitle, (char *)ptitle ) ; |
03e11df5 | 568 | #else |
e40298d5 | 569 | c2pstr( (char*)ptitle ) ; |
03e11df5 | 570 | #endif |
e40298d5 | 571 | SetWTitle( inWindowRef , ptitle ) ; |
72e7876b | 572 | } |
03e11df5 | 573 | |
e40298d5 | 574 | void UMAGetWTitleC( WindowRef inWindowRef , char *title ) |
72e7876b | 575 | { |
e40298d5 | 576 | GetWTitle( inWindowRef , (unsigned char*)title ) ; |
03e11df5 | 577 | #if TARGET_CARBON |
e40298d5 | 578 | p2cstrcpy( title, (unsigned char *)title ) ; |
03e11df5 | 579 | #else |
e40298d5 | 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 | |
e40298d5 JS |
590 | if ( !IsControlActive( inControl ) ) |
591 | { | |
fdaf613a SC |
592 | bool visible = IsControlVisible( inControl ) ; |
593 | if ( visible ) | |
e40298d5 | 594 | SetControlVisibility( inControl , false , false ) ; |
3f4902f5 | 595 | ::ActivateControl( inControl ) ; |
fdaf613a | 596 | if ( visible ) { |
e40298d5 JS |
597 | SetControlVisibility( inControl , true , false ) ; |
598 | Rect ctrlBounds ; | |
599 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
fdaf613a | 600 | } |
e40298d5 | 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 ) ; |
e40298d5 JS |
609 | Point zero = { 0 , 0 } ; |
610 | LocalToGlobal( &zero ) ; | |
611 | OffsetRgn( updateRgn , -zero.h , -zero.v ) ; | |
22e751a5 SC |
612 | ::DrawControlInCurrentPort( inControl ) ; |
613 | InvalWindowRgn( theWindow, updateRgn) ; | |
e40298d5 | 614 | DisposeRgn( updateRgn ) ; |
72e7876b SC |
615 | } |
616 | ||
617 | void UMAMoveControl( ControlHandle inControl , short x , short y ) | |
618 | { | |
e40298d5 JS |
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 | { | |
e40298d5 JS |
635 | bool visible = IsControlVisible( inControl ) ; |
636 | if ( visible ) { | |
637 | SetControlVisibility( inControl , false , false ) ; | |
638 | Rect ctrlBounds ; | |
639 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
640 | } | |
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 | |
e40298d5 JS |
653 | bool visible = IsControlVisible( inControl ) ; |
654 | if ( visible ) | |
655 | SetControlVisibility( inControl , false , false ) ; | |
656 | ::DeactivateControl( inControl ) ; | |
657 | if ( visible ) { | |
fdaf613a | 658 | SetControlVisibility( inControl , true , false ) ; |
c36f0244 SC |
659 | Rect ctrlBounds ; |
660 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
e40298d5 JS |
661 | } |
662 | } | |
663 | // shows the control and adds the region to the update region | |
664 | void UMAShowControl (ControlHandle inControl) | |
665 | { | |
666 | SetControlVisibility( inControl , true , false ) ; | |
667 | Rect ctrlBounds ; | |
668 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
72e7876b SC |
669 | } |
670 | ||
22e751a5 | 671 | // shows the control and adds the region to the update region |
e40298d5 | 672 | void UMAHideControl (ControlHandle inControl) |
22e751a5 | 673 | { |
e40298d5 JS |
674 | SetControlVisibility( inControl , false , false ) ; |
675 | Rect ctrlBounds ; | |
676 | InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; | |
22e751a5 | 677 | } |
72e7876b | 678 | // keyboard focus |
e40298d5 JS |
679 | OSErr UMASetKeyboardFocus (WindowPtr inWindow, |
680 | ControlHandle inControl, | |
681 | ControlFocusPart inPart) | |
72e7876b | 682 | { |
e40298d5 JS |
683 | OSErr err = noErr; |
684 | GrafPtr port ; | |
685 | GetPort( &port ) ; | |
72055702 | 686 | |
e40298d5 | 687 | SetPortWindowPort( inWindow ) ; |
72055702 | 688 | |
e40298d5 JS |
689 | err = SetKeyboardFocus( inWindow , inControl , inPart ) ; |
690 | SetPort( port ) ; | |
691 | return err ; | |
72e7876b SC |
692 | } |
693 | ||
694 | ||
72e7876b | 695 | // events |
72e7876b SC |
696 | void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn ) |
697 | { | |
e40298d5 JS |
698 | RgnHandle updateRgn = NewRgn() ; |
699 | GetWindowUpdateRgn( inWindow , updateRgn ) ; | |
700 | ||
701 | Point zero = { 0 , 0 } ; | |
702 | LocalToGlobal( &zero ) ; | |
703 | OffsetRgn( updateRgn , -zero.h , -zero.v ) ; | |
704 | ||
705 | UpdateControls( inWindow , inRgn ) ; | |
706 | InvalWindowRgn( inWindow, updateRgn) ; | |
707 | DisposeRgn( updateRgn ) ; | |
72e7876b SC |
708 | } |
709 | ||
710 | bool UMAIsWindowFloating( WindowRef inWindow ) | |
711 | { | |
e40298d5 JS |
712 | WindowClass cl ; |
713 | ||
714 | GetWindowClass( inWindow , &cl ) ; | |
715 | return cl == kFloatingWindowClass ; | |
72e7876b SC |
716 | } |
717 | ||
718 | bool UMAIsWindowModal( WindowRef inWindow ) | |
719 | { | |
e40298d5 JS |
720 | WindowClass cl ; |
721 | ||
722 | GetWindowClass( inWindow , &cl ) ; | |
723 | return cl < kFloatingWindowClass ; | |
72e7876b SC |
724 | } |
725 | ||
726 | // others | |
727 | ||
728 | void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ) | |
729 | { | |
e40298d5 JS |
730 | if ( inWindowRef ) |
731 | { | |
732 | // bool isHighlighted = IsWindowHighlited( inWindowRef ) ; | |
733 | // if ( inActivate != isHightlited ) | |
734 | GrafPtr port ; | |
735 | GetPort( &port ) ; | |
736 | SetPortWindowPort( inWindowRef ) ; | |
737 | HiliteWindow( inWindowRef , inActivate ) ; | |
738 | ControlHandle control = NULL ; | |
739 | ::GetRootControl( inWindowRef , & control ) ; | |
740 | if ( control ) | |
741 | { | |
742 | if ( inActivate ) | |
743 | UMAActivateControl( control ) ; | |
744 | else | |
745 | UMADeactivateControl( control ) ; | |
746 | } | |
747 | SetPort( port ) ; | |
748 | } | |
72e7876b | 749 | } |
e40298d5 | 750 | |
2f1ae414 SC |
751 | OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ) |
752 | { | |
e40298d5 | 753 | return ::DrawThemePlacard( inRect , inState ) ; |
2f1ae414 | 754 | } |
72e7876b | 755 | |
2f056c85 | 756 | #if !TARGET_CARBON |
b03e4fcd | 757 | static OSStatus helpMenuStatus = noErr ; |
b03e4fcd | 758 | static MenuItemIndex firstCustomItemIndex = 0 ; |
2f056c85 | 759 | #endif |
b03e4fcd SC |
760 | |
761 | OSStatus UMAGetHelpMenu( | |
762 | MenuRef * outHelpMenu, | |
763 | MenuItemIndex * outFirstCustomItemIndex) | |
764 | { | |
765 | #if TARGET_CARBON | |
e40298d5 | 766 | return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ; |
b03e4fcd | 767 | #else |
e40298d5 JS |
768 | MenuRef helpMenuHandle ; |
769 | helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ; | |
770 | if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr ) | |
771 | { | |
772 | firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ; | |
773 | } | |
774 | if ( outFirstCustomItemIndex ) | |
775 | { | |
776 | *outFirstCustomItemIndex = firstCustomItemIndex ; | |
777 | } | |
778 | *outHelpMenu = helpMenuHandle ; | |
779 | return helpMenuStatus ; | |
b03e4fcd SC |
780 | #endif |
781 | } | |
76a5e5d2 SC |
782 | |
783 | wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport) | |
784 | { | |
e40298d5 JS |
785 | m_clip = NULL ; |
786 | Setup( newport ) ; | |
76a5e5d2 SC |
787 | } |
788 | ||
789 | wxMacPortStateHelper::wxMacPortStateHelper() | |
790 | { | |
e40298d5 | 791 | m_clip = NULL ; |
76a5e5d2 SC |
792 | } |
793 | ||
794 | void wxMacPortStateHelper::Setup( GrafPtr newport ) | |
795 | { | |
e40298d5 JS |
796 | GetPort( &m_oldPort ) ; |
797 | SetPort( newport ) ; | |
798 | wxASSERT_MSG( m_clip == NULL , "Cannot call setup twice" ) ; | |
799 | m_clip = NewRgn() ; | |
800 | GetClip( m_clip ); | |
801 | m_textFont = GetPortTextFont( (CGrafPtr) newport); | |
802 | m_textSize = GetPortTextSize( (CGrafPtr) newport); | |
803 | m_textStyle = GetPortTextFace( (CGrafPtr) newport); | |
804 | m_textMode = GetPortTextMode( (CGrafPtr) newport); | |
805 | GetThemeDrawingState( &m_drawingState ) ; | |
806 | m_currentPort = newport ; | |
76a5e5d2 SC |
807 | } |
808 | void wxMacPortStateHelper::Clear() | |
809 | { | |
e40298d5 JS |
810 | if ( m_clip ) |
811 | { | |
812 | DisposeRgn( m_clip ) ; | |
813 | DisposeThemeDrawingState( m_drawingState ) ; | |
814 | m_clip = NULL ; | |
815 | } | |
76a5e5d2 SC |
816 | } |
817 | ||
818 | wxMacPortStateHelper::~wxMacPortStateHelper() | |
819 | { | |
e40298d5 JS |
820 | if ( m_clip ) |
821 | { | |
822 | SetPort( m_currentPort ) ; | |
823 | SetClip( m_clip ) ; | |
824 | DisposeRgn( m_clip ) ; | |
825 | TextFont( m_textFont ); | |
826 | TextSize( m_textSize ); | |
827 | TextFace( m_textStyle ); | |
828 | TextMode( m_textMode ); | |
829 | SetThemeDrawingState( m_drawingState , true ) ; | |
830 | SetPort( m_oldPort ) ; | |
831 | } | |
76a5e5d2 SC |
832 | } |
833 | ||
9c3c5849 SC |
834 | OSStatus UMAPutScrap( Size size , OSType type , void *data ) |
835 | { | |
e40298d5 | 836 | OSStatus err = noErr ; |
9c3c5849 SC |
837 | #if !TARGET_CARBON |
838 | err = PutScrap( size , type , data ) ; | |
839 | #else | |
840 | ScrapRef scrap; | |
841 | err = GetCurrentScrap (&scrap); | |
842 | if ( !err ) | |
843 | { | |
844 | err = PutScrapFlavor (scrap, type , 0, size, data); | |
845 | } | |
846 | #endif | |
e40298d5 | 847 | return err ; |
9c3c5849 SC |
848 | } |
849 |