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