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