]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
fb5246be | 2 | // Name: src/mac/carbon/utils.cpp |
e9576ca5 | 3 | // Purpose: Various utilities |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
88a7a4e1 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
e9576ca5 | 14 | #include "wx/utils.h" |
88a7a4e1 WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/intl.h" | |
670f9935 | 18 | #include "wx/app.h" |
1832043f WS |
19 | #if wxUSE_GUI |
20 | #include "wx/toplevel.h" | |
48a1108e | 21 | #include "wx/font.h" |
1832043f | 22 | #endif |
88a7a4e1 WS |
23 | #endif |
24 | ||
2bf2d09e | 25 | #include "wx/apptrait.h" |
b6ed2b86 VZ |
26 | |
27 | #if wxUSE_GUI | |
28 | #include "wx/mac/uma.h" | |
29 | #endif | |
e9576ca5 SC |
30 | |
31 | #include <ctype.h> | |
32 | ||
33 | #include <stdio.h> | |
34 | #include <stdlib.h> | |
35 | #include <string.h> | |
36 | #include <stdarg.h> | |
37 | ||
a2b77260 | 38 | #include "MoreFilesX.h" |
518af45b | 39 | |
66a09d47 | 40 | #ifndef __DARWIN__ |
8638e69b DS |
41 | #include <Threads.h> |
42 | #include <Sound.h> | |
66a09d47 SC |
43 | #endif |
44 | ||
7d9bf1f1 | 45 | #if wxUSE_GUI |
29d91661 | 46 | #if TARGET_API_MAC_OSX |
8638e69b | 47 | #include <CoreServices/CoreServices.h> |
29d91661 | 48 | #else |
8638e69b DS |
49 | #include <DriverServices.h> |
50 | #include <Multiprocessing.h> | |
29d91661 SC |
51 | #endif |
52 | ||
768c6e8b | 53 | #ifdef __DARWIN__ |
8638e69b | 54 | #include <Carbon/Carbon.h> |
768c6e8b | 55 | #else |
8638e69b DS |
56 | #include <ATSUnicode.h> |
57 | #include <TextCommon.h> | |
58 | #include <TextEncodingConverter.h> | |
768c6e8b | 59 | #endif |
c2ca375c VZ |
60 | |
61 | #include "wx/mac/private/timer.h" | |
7d9bf1f1 | 62 | #endif // wxUSE_GUI |
427ff662 | 63 | |
b46b1d59 | 64 | #include "wx/evtloop.h" |
8638e69b | 65 | #include "wx/mac/private.h" |
a434b43f VZ |
66 | |
67 | #if defined(__MWERKS__) && wxUSE_UNICODE | |
6cce68ea | 68 | #if __MWERKS__ < 0x4100 || !defined(__DARWIN__) |
a434b43f VZ |
69 | #include <wtime.h> |
70 | #endif | |
6cce68ea | 71 | #endif |
a434b43f | 72 | |
c655557f | 73 | #if wxUSE_BASE |
659b3e8b VZ |
74 | |
75 | // our OS version is the same in non GUI and GUI cases | |
c655557f | 76 | wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn) |
659b3e8b | 77 | { |
e6c3d3e6 | 78 | SInt32 theSystem; |
6cce68ea | 79 | Gestalt(gestaltSystemVersion, &theSystem); |
8638e69b | 80 | |
c655557f | 81 | if ( majorVsn != NULL ) |
6cce68ea | 82 | *majorVsn = (theSystem >> 8); |
8638e69b | 83 | |
c655557f VZ |
84 | if ( minorVsn != NULL ) |
85 | *minorVsn = (theSystem & 0xFF); | |
86 | ||
8bb6b2c0 VZ |
87 | #if defined( __DARWIN__ ) |
88 | return wxOS_MAC_OSX_DARWIN; | |
659b3e8b | 89 | #else |
8bb6b2c0 | 90 | return wxOS_MAC_OS; |
659b3e8b VZ |
91 | #endif |
92 | } | |
93 | ||
e5a9c663 SC |
94 | // ---------------------------------------------------------------------------- |
95 | // debugging support | |
96 | // ---------------------------------------------------------------------------- | |
97 | ||
e2fccedf | 98 | #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400) |
e5a9c663 SC |
99 | |
100 | // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds... | |
101 | ||
102 | #ifndef __MetroNubUtils__ | |
103 | #include "MetroNubUtils.h" | |
104 | #endif | |
105 | ||
106 | #ifndef __GESTALT__ | |
107 | #include <Gestalt.h> | |
108 | #endif | |
109 | ||
110 | #if TARGET_API_MAC_CARBON | |
111 | ||
8638e69b | 112 | #include <CodeFragments.h> |
e5a9c663 | 113 | |
8638e69b | 114 | extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...); |
e5a9c663 | 115 | |
8638e69b | 116 | ProcPtr gCallUniversalProc_Proc = NULL; |
e5a9c663 SC |
117 | |
118 | #endif | |
119 | ||
120 | static MetroNubUserEntryBlock* gMetroNubEntry = NULL; | |
121 | ||
122 | static long fRunOnce = false; | |
123 | ||
e5a9c663 SC |
124 | |
125 | Boolean IsMetroNubInstalled() | |
126 | { | |
127 | if (!fRunOnce) | |
128 | { | |
129 | long result, value; | |
130 | ||
131 | fRunOnce = true; | |
132 | gMetroNubEntry = NULL; | |
133 | ||
134 | if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000) | |
135 | { | |
8638e69b | 136 | // look for MetroNub's Gestalt selector |
e5a9c663 SC |
137 | if (Gestalt(kMetroNubUserSignature, &result) == noErr) |
138 | { | |
8638e69b | 139 | #if TARGET_API_MAC_CARBON |
e5a9c663 SC |
140 | if (gCallUniversalProc_Proc == NULL) |
141 | { | |
142 | CFragConnectionID connectionID; | |
143 | Ptr mainAddress; | |
144 | Str255 errorString; | |
145 | ProcPtr symbolAddress; | |
146 | OSErr err; | |
147 | CFragSymbolClass symbolClass; | |
148 | ||
149 | symbolAddress = NULL; | |
150 | err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag, | |
151 | &connectionID, &mainAddress, errorString); | |
152 | ||
153 | if (err != noErr) | |
154 | { | |
155 | gCallUniversalProc_Proc = NULL; | |
156 | goto end; | |
157 | } | |
158 | ||
159 | err = FindSymbol(connectionID, "\pCallUniversalProc", | |
160 | (Ptr *) &gCallUniversalProc_Proc, &symbolClass); | |
161 | ||
162 | if (err != noErr) | |
163 | { | |
164 | gCallUniversalProc_Proc = NULL; | |
165 | goto end; | |
166 | } | |
167 | } | |
8638e69b | 168 | #endif |
e5a9c663 SC |
169 | |
170 | { | |
171 | MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result; | |
172 | ||
8638e69b | 173 | // make sure the version of the API is compatible |
e5a9c663 SC |
174 | if (block->apiLowVersion <= kMetroNubUserAPIVersion && |
175 | kMetroNubUserAPIVersion <= block->apiHiVersion) | |
8638e69b DS |
176 | { |
177 | // success! | |
88a7a4e1 | 178 | gMetroNubEntry = block; |
8638e69b | 179 | } |
e5a9c663 | 180 | } |
e5a9c663 SC |
181 | } |
182 | } | |
183 | } | |
184 | ||
185 | end: | |
186 | ||
187 | #if TARGET_API_MAC_CARBON | |
188 | return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL); | |
189 | #else | |
190 | return (gMetroNubEntry != NULL); | |
191 | #endif | |
192 | } | |
193 | ||
e5a9c663 SC |
194 | Boolean IsMWDebuggerRunning() |
195 | { | |
196 | if (IsMetroNubInstalled()) | |
197 | return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning); | |
e5a9c663 | 198 | |
8638e69b DS |
199 | return false; |
200 | } | |
e5a9c663 SC |
201 | |
202 | Boolean AmIBeingMWDebugged() | |
203 | { | |
204 | if (IsMetroNubInstalled()) | |
205 | return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged); | |
8638e69b DS |
206 | |
207 | return false; | |
e5a9c663 SC |
208 | } |
209 | ||
210 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
211 | { | |
212 | return IsMWDebuggerRunning() && AmIBeingMWDebugged(); | |
213 | } | |
214 | ||
215 | #else | |
216 | ||
217 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
218 | { | |
219 | return false; | |
220 | } | |
221 | ||
222 | #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400) | |
223 | ||
a434b43f | 224 | |
f5c6eb5c | 225 | #ifndef __DARWIN__ |
03e11df5 GD |
226 | // defined in unix/utilsunx.cpp for Mac OS X |
227 | ||
2f1ae414 SC |
228 | // get full hostname (with domain name if possible) |
229 | bool wxGetFullHostName(wxChar *buf, int maxSize) | |
230 | { | |
231 | return wxGetHostName(buf, maxSize); | |
232 | } | |
233 | ||
8638e69b DS |
234 | // Get user ID e.g. jacs |
235 | bool wxGetUserId(wxChar *buf, int maxSize) | |
236 | { | |
6cce68ea | 237 | return wxGetUserName( buf , maxSize ); |
8638e69b DS |
238 | } |
239 | ||
240 | const wxChar* wxGetHomeDir(wxString *pstr) | |
241 | { | |
6cce68ea SC |
242 | *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ); |
243 | return pstr->c_str(); | |
8638e69b DS |
244 | } |
245 | ||
2f1ae414 | 246 | // Get hostname only (without domain name) |
427ff662 | 247 | bool wxGetHostName(wxChar *buf, int maxSize) |
e9576ca5 | 248 | { |
e40298d5 | 249 | // Gets Chooser name of user by examining a System resource. |
6cce68ea | 250 | buf[0] = 0; |
e40298d5 JS |
251 | |
252 | const short kComputerNameID = -16413; | |
5be55d56 | 253 | |
6cce68ea | 254 | short oldResFile = CurResFile(); |
e40298d5 JS |
255 | UseResFile(0); |
256 | StringHandle chooserName = (StringHandle)::GetString(kComputerNameID); | |
257 | UseResFile(oldResFile); | |
258 | ||
259 | if (chooserName && *chooserName) | |
260 | { | |
6cce68ea SC |
261 | HLock( (Handle) chooserName ); |
262 | wxString name = wxMacMakeStringFromPascal( *chooserName ); | |
263 | HUnlock( (Handle) chooserName ); | |
264 | ReleaseResource( (Handle) chooserName ); | |
265 | wxStrncpy( buf , name , maxSize - 1 ); | |
e40298d5 | 266 | } |
0a67a93b | 267 | |
9d8aca48 | 268 | return true; |
e9576ca5 SC |
269 | } |
270 | ||
a31a5f85 | 271 | // Get user name e.g. Stefan Csomor |
427ff662 | 272 | bool wxGetUserName(wxChar *buf, int maxSize) |
e9576ca5 | 273 | { |
e40298d5 | 274 | // Gets Chooser name of user by examining a System resource. |
6cce68ea | 275 | buf[0] = 0; |
e40298d5 JS |
276 | |
277 | const short kChooserNameID = -16096; | |
5be55d56 | 278 | |
6cce68ea | 279 | short oldResFile = CurResFile(); |
e40298d5 JS |
280 | UseResFile(0); |
281 | StringHandle chooserName = (StringHandle)::GetString(kChooserNameID); | |
282 | UseResFile(oldResFile); | |
283 | ||
284 | if (chooserName && *chooserName) | |
285 | { | |
6cce68ea SC |
286 | HLock( (Handle) chooserName ); |
287 | wxString name = wxMacMakeStringFromPascal( *chooserName ); | |
288 | HUnlock( (Handle) chooserName ); | |
289 | ReleaseResource( (Handle) chooserName ); | |
290 | wxStrncpy( buf , name , maxSize - 1 ); | |
e40298d5 | 291 | } |
0a67a93b | 292 | |
9d8aca48 | 293 | return true; |
e9576ca5 SC |
294 | } |
295 | ||
e0f6b731 | 296 | int wxKill(long pid, wxSignal sig , wxKillError *rc, int flags) |
e9576ca5 SC |
297 | { |
298 | // TODO | |
299 | return 0; | |
300 | } | |
301 | ||
5dbb17e2 SC |
302 | WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value) |
303 | { | |
e40298d5 | 304 | // TODO : under classic there is no environement support, under X yes |
6cce68ea | 305 | return false; |
5dbb17e2 SC |
306 | } |
307 | ||
9d8aca48 | 308 | // set the env var name to the given value, return true on success |
90a77e64 VS |
309 | WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxString& value) |
310 | { | |
311 | // TODO : under classic there is no environement support, under X yes | |
312 | return false; | |
313 | } | |
314 | ||
315 | WXDLLEXPORT bool wxUnsetEnv(const wxString& var) | |
5dbb17e2 | 316 | { |
e40298d5 | 317 | // TODO : under classic there is no environement support, under X yes |
6cce68ea | 318 | return false; |
5dbb17e2 SC |
319 | } |
320 | ||
e9576ca5 | 321 | // Execute a program in an Interactive Shell |
e9576ca5 SC |
322 | bool wxShell(const wxString& command) |
323 | { | |
324 | // TODO | |
9d8aca48 | 325 | return false; |
e9576ca5 SC |
326 | } |
327 | ||
5be55d56 | 328 | // Shutdown or reboot the PC |
f6ba47d9 VZ |
329 | bool wxShutdown(wxShutdownFlags wFlags) |
330 | { | |
331 | // TODO | |
9d8aca48 | 332 | return false; |
f6ba47d9 VZ |
333 | } |
334 | ||
e9576ca5 | 335 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) |
9d8aca48 | 336 | wxMemorySize wxGetFreeMemory() |
e9576ca5 | 337 | { |
6cce68ea | 338 | return (wxMemorySize)FreeMem(); |
0a67a93b SC |
339 | } |
340 | ||
7f7b52b4 SC |
341 | #ifndef __DARWIN__ |
342 | ||
343 | void wxMicroSleep(unsigned long microseconds) | |
0a67a93b | 344 | { |
9d8aca48 WS |
345 | AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime()); |
346 | MPDelayUntil( & wakeup); | |
7f7b52b4 SC |
347 | } |
348 | ||
349 | void wxMilliSleep(unsigned long milliseconds) | |
350 | { | |
9d8aca48 WS |
351 | AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime()); |
352 | MPDelayUntil( & wakeup); | |
e9576ca5 SC |
353 | } |
354 | ||
355 | void wxSleep(int nSecs) | |
356 | { | |
7f7b52b4 | 357 | wxMilliSleep(1000*nSecs); |
e9576ca5 SC |
358 | } |
359 | ||
7f7b52b4 SC |
360 | #endif |
361 | ||
e9576ca5 SC |
362 | // Consume all events until no more left |
363 | void wxFlushEvents() | |
364 | { | |
365 | } | |
366 | ||
f5c6eb5c | 367 | #endif // !__DARWIN__ |
e9576ca5 SC |
368 | |
369 | // Emit a beeeeeep | |
370 | void wxBell() | |
371 | { | |
e6c3d3e6 | 372 | #ifndef __LP64__ |
0a67a93b | 373 | SysBeep(30); |
e6c3d3e6 | 374 | #endif |
e9576ca5 SC |
375 | } |
376 | ||
29c99ad3 | 377 | |
b6ed2b86 VZ |
378 | #endif // wxUSE_BASE |
379 | ||
380 | #if wxUSE_GUI | |
536732e4 | 381 | |
8bb6b2c0 | 382 | wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const |
29c99ad3 | 383 | { |
8bb6b2c0 VZ |
384 | // We suppose that toolkit version is the same as OS version under Mac |
385 | wxGetOsVersion(verMaj, verMin); | |
8638e69b | 386 | |
8bb6b2c0 | 387 | return wxPORT_MAC; |
29c99ad3 VZ |
388 | } |
389 | ||
2ddff00c | 390 | wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() |
b46b1d59 VZ |
391 | { |
392 | return new wxEventLoop; | |
393 | } | |
394 | ||
c2ca375c VZ |
395 | wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer) |
396 | { | |
397 | return new wxCarbonTimerImpl(timer); | |
398 | } | |
399 | ||
6b57b49a | 400 | int gs_wxBusyCursorCount = 0; |
6cce68ea SC |
401 | extern wxCursor gMacCurrentCursor; |
402 | wxCursor gMacStoredActiveCursor; | |
e9576ca5 SC |
403 | |
404 | // Set the cursor to the busy cursor for all windows | |
f516d986 | 405 | void wxBeginBusyCursor(const wxCursor *cursor) |
e9576ca5 | 406 | { |
e40298d5 JS |
407 | if (gs_wxBusyCursorCount++ == 0) |
408 | { | |
6cce68ea SC |
409 | gMacStoredActiveCursor = gMacCurrentCursor; |
410 | cursor->MacInstall(); | |
e40298d5 JS |
411 | } |
412 | //else: nothing to do, already set | |
e9576ca5 SC |
413 | } |
414 | ||
415 | // Restore cursor to normal | |
416 | void wxEndBusyCursor() | |
417 | { | |
6b57b49a | 418 | wxCHECK_RET( gs_wxBusyCursorCount > 0, |
e40298d5 | 419 | wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") ); |
5be55d56 | 420 | |
e40298d5 JS |
421 | if (--gs_wxBusyCursorCount == 0) |
422 | { | |
6cce68ea SC |
423 | gMacStoredActiveCursor.MacInstall(); |
424 | gMacStoredActiveCursor = wxNullCursor; | |
e40298d5 | 425 | } |
e9576ca5 SC |
426 | } |
427 | ||
9d8aca48 | 428 | // true if we're between the above two calls |
e9576ca5 SC |
429 | bool wxIsBusy() |
430 | { | |
e40298d5 | 431 | return (gs_wxBusyCursorCount > 0); |
ec5d7799 | 432 | } |
e9576ca5 | 433 | |
2dbc444a RD |
434 | #endif // wxUSE_GUI |
435 | ||
436 | #if wxUSE_BASE | |
437 | ||
17af82fb | 438 | wxString wxMacFindFolderNoSeparator( short vol, |
e40298d5 JS |
439 | OSType folderType, |
440 | Boolean createFolder) | |
2f1ae414 | 441 | { |
6cce68ea SC |
442 | FSRef fsRef; |
443 | wxString strDir; | |
5be55d56 | 444 | |
a2b77260 | 445 | if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr) |
17af82fb VZ |
446 | { |
447 | strDir = wxMacFSRefToPath( &fsRef ); | |
448 | } | |
a2b77260 | 449 | |
6cce68ea | 450 | return strDir; |
2f1ae414 SC |
451 | } |
452 | ||
17af82fb VZ |
453 | wxString wxMacFindFolder( short vol, |
454 | OSType folderType, | |
455 | Boolean createFolder) | |
456 | { | |
457 | return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH; | |
458 | } | |
459 | ||
2dbc444a RD |
460 | #endif // wxUSE_BASE |
461 | ||
462 | #if wxUSE_GUI | |
463 | ||
e9576ca5 SC |
464 | // Check whether this window wants to process messages, e.g. Stop button |
465 | // in long calculations. | |
89954433 | 466 | bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd)) |
e9576ca5 SC |
467 | { |
468 | // TODO | |
9d8aca48 | 469 | return false; |
e9576ca5 SC |
470 | } |
471 | ||
472 | void wxGetMousePosition( int* x, int* y ) | |
473 | { | |
6cce68ea | 474 | Point pt; |
e6c3d3e6 SC |
475 | #if wxMAC_USE_CORE_GRAPHICS |
476 | GetGlobalMouse(&pt); | |
477 | #else | |
6cce68ea SC |
478 | GetMouse( &pt ); |
479 | LocalToGlobal( &pt ); | |
e6c3d3e6 | 480 | #endif |
6cce68ea SC |
481 | *x = pt.h; |
482 | *y = pt.v; | |
e9576ca5 SC |
483 | }; |
484 | ||
9d8aca48 | 485 | // Return true if we have a colour display |
e9576ca5 SC |
486 | bool wxColourDisplay() |
487 | { | |
9d8aca48 | 488 | return true; |
e9576ca5 SC |
489 | } |
490 | ||
491 | // Returns depth of screen | |
492 | int wxDisplayDepth() | |
493 | { | |
e6c3d3e6 SC |
494 | int theDepth = 8; |
495 | #if wxMAC_USE_CORE_GRAPHICS | |
496 | theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID()); | |
497 | #else | |
6cce68ea | 498 | Rect globRect; |
e40298d5 JS |
499 | SetRect(&globRect, -32760, -32760, 32760, 32760); |
500 | GDHandle theMaxDevice; | |
2f1ae414 | 501 | |
e40298d5 | 502 | theMaxDevice = GetMaxDevice(&globRect); |
8638e69b | 503 | if (theMaxDevice != NULL) |
e40298d5 | 504 | theDepth = (**(**theMaxDevice).gdPMap).pixelSize; |
e6c3d3e6 | 505 | #endif |
6cce68ea | 506 | return theDepth; |
e9576ca5 SC |
507 | } |
508 | ||
509 | // Get size of display | |
510 | void wxDisplaySize(int *width, int *height) | |
511 | { | |
e6c3d3e6 | 512 | #if wxMAC_USE_CORE_GRAPHICS |
e6c3d3e6 | 513 | // TODO adapt for multi-displays |
a2d6d210 | 514 | CGRect bounds = CGDisplayBounds(CGMainDisplayID()); |
e6c3d3e6 | 515 | if ( width ) |
a2d6d210 | 516 | *width = (int)bounds.size.width ; |
e6c3d3e6 | 517 | if ( height ) |
a2d6d210 | 518 | *height = (int)bounds.size.height; |
e6c3d3e6 | 519 | #else |
e40298d5 JS |
520 | BitMap screenBits; |
521 | GetQDGlobalsScreenBits( &screenBits ); | |
5be55d56 | 522 | |
8638e69b | 523 | if (width != NULL) |
6cce68ea | 524 | *width = screenBits.bounds.right - screenBits.bounds.left; |
8638e69b DS |
525 | |
526 | if (height != NULL) | |
6cce68ea | 527 | *height = screenBits.bounds.bottom - screenBits.bounds.top; |
e6c3d3e6 | 528 | #endif |
e9576ca5 SC |
529 | } |
530 | ||
5fde6fcc GD |
531 | void wxDisplaySizeMM(int *width, int *height) |
532 | { | |
5b028d57 | 533 | wxDisplaySize(width, height); |
6cce68ea | 534 | // on mac 72 is fixed (at least now;-) |
5b028d57 | 535 | float cvPt2Mm = 25.4 / 72; |
e8ca7105 | 536 | |
8638e69b | 537 | if (width != NULL) |
e8ca7105 | 538 | *width = int( *width * cvPt2Mm ); |
8638e69b DS |
539 | |
540 | if (height != NULL) | |
e8ca7105 | 541 | *height = int( *height * cvPt2Mm ); |
5fde6fcc GD |
542 | } |
543 | ||
ec5d7799 RD |
544 | void wxClientDisplayRect(int *x, int *y, int *width, int *height) |
545 | { | |
e6c3d3e6 SC |
546 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 |
547 | HIRect bounds ; | |
548 | HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal, | |
549 | &bounds); | |
550 | if ( x ) | |
551 | *x = bounds.origin.x; | |
552 | if ( y ) | |
553 | *y = bounds.origin.y; | |
554 | if ( width ) | |
555 | *width = bounds.size.width; | |
556 | if ( height ) | |
557 | *height = bounds.size.height; | |
558 | #else | |
6cce68ea | 559 | Rect r; |
6cce68ea | 560 | GetAvailableWindowPositioningBounds( GetMainDevice() , &r ); |
ee658398 | 561 | if ( x ) |
6cce68ea | 562 | *x = r.left; |
ee658398 | 563 | if ( y ) |
6cce68ea | 564 | *y = r.top; |
ee658398 | 565 | if ( width ) |
6cce68ea | 566 | *width = r.right - r.left; |
ee658398 | 567 | if ( height ) |
6cce68ea | 568 | *height = r.bottom - r.top; |
e6c3d3e6 | 569 | #endif |
ec5d7799 RD |
570 | } |
571 | ||
57591e0e JS |
572 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) |
573 | { | |
574 | return wxGenericFindWindowAtPoint(pt); | |
575 | } | |
5dbb17e2 | 576 | |
b6ed2b86 VZ |
577 | #endif // wxUSE_GUI |
578 | ||
579 | #if wxUSE_BASE | |
580 | ||
5dbb17e2 SC |
581 | wxString wxGetOsDescription() |
582 | { | |
6e73695c GD |
583 | #ifdef WXWIN_OS_DESCRIPTION |
584 | // use configure generated description if available | |
5f3f0f17 | 585 | return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")")); |
6e73695c | 586 | #else |
6cce68ea | 587 | return wxT("MacOS"); //TODO:define further |
6e73695c GD |
588 | #endif |
589 | } | |
590 | ||
b6ed2b86 | 591 | #ifndef __DARWIN__ |
14d63513 | 592 | wxString wxGetUserHome (const wxString& user) |
b6ed2b86 VZ |
593 | { |
594 | // TODO | |
14d63513 | 595 | return wxString(); |
b6ed2b86 VZ |
596 | } |
597 | ||
7ba7c4e6 | 598 | bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree) |
b6ed2b86 VZ |
599 | { |
600 | if ( path.empty() ) | |
9d8aca48 | 601 | return false; |
b6ed2b86 | 602 | |
6cce68ea | 603 | wxString p = path; |
8638e69b | 604 | if (p[0u] == ':' ) |
6cce68ea | 605 | p = wxGetCwd() + p; |
b6ed2b86 | 606 | |
6cce68ea | 607 | int pos = p.Find(':'); |
8638e69b | 608 | if ( pos != wxNOT_FOUND ) |
6cce68ea | 609 | p = p.Mid(1,pos); |
b6ed2b86 | 610 | |
6cce68ea | 611 | p = p + wxT(":"); |
b6ed2b86 | 612 | |
6cce68ea | 613 | OSErr err = noErr; |
9d8aca48 | 614 | |
6cce68ea SC |
615 | FSRef fsRef; |
616 | err = wxMacPathToFSRef( p , &fsRef ); | |
a2b77260 SC |
617 | if ( noErr == err ) |
618 | { | |
6cce68ea SC |
619 | FSVolumeRefNum vRefNum; |
620 | err = FSGetVRefNum( &fsRef , &vRefNum ); | |
a2b77260 SC |
621 | if ( noErr == err ) |
622 | { | |
6cce68ea SC |
623 | UInt64 freeBytes , totalBytes; |
624 | err = FSGetVInfo( vRefNum , NULL , &freeBytes , &totalBytes ); | |
a2b77260 SC |
625 | if ( noErr == err ) |
626 | { | |
9d8aca48 | 627 | if ( pTotal ) |
6cce68ea | 628 | *pTotal = wxDiskspaceSize_t( totalBytes ); |
a2b77260 | 629 | if ( pFree ) |
6cce68ea | 630 | *pFree = wxDiskspaceSize_t( freeBytes ); |
a2b77260 SC |
631 | } |
632 | } | |
b6ed2b86 | 633 | } |
9d8aca48 | 634 | |
6cce68ea | 635 | return err == noErr; |
b6ed2b86 VZ |
636 | } |
637 | #endif // !__DARWIN__ | |
638 | ||
3d963f81 SC |
639 | //--------------------------------------------------------------------------- |
640 | // wxMac Specific utility functions | |
641 | //--------------------------------------------------------------------------- | |
642 | ||
5be55d56 | 643 | void wxMacStringToPascal( const wxString&from , StringPtr to ) |
427ff662 | 644 | { |
6cce68ea SC |
645 | wxCharBuffer buf = from.mb_str( wxConvLocal ); |
646 | int len = strlen(buf); | |
427ff662 SC |
647 | |
648 | if ( len > 255 ) | |
6cce68ea SC |
649 | len = 255; |
650 | to[0] = len; | |
651 | memcpy( (char*) &to[1] , buf , len ); | |
427ff662 SC |
652 | } |
653 | ||
5be55d56 | 654 | wxString wxMacMakeStringFromPascal( ConstStringPtr from ) |
427ff662 | 655 | { |
6cce68ea | 656 | return wxString( (char*) &from[1] , wxConvLocal , from[0] ); |
427ff662 SC |
657 | } |
658 | ||
73280e05 SC |
659 | // ---------------------------------------------------------------------------- |
660 | // Common Event Support | |
661 | // ---------------------------------------------------------------------------- | |
662 | ||
6cce68ea | 663 | extern ProcessSerialNumber gAppProcess; |
73280e05 SC |
664 | |
665 | void wxMacWakeUp() | |
666 | { | |
6cce68ea SC |
667 | ProcessSerialNumber psn; |
668 | Boolean isSame; | |
669 | psn.highLongOfPSN = 0; | |
670 | psn.lowLongOfPSN = kCurrentProcess; | |
671 | SameProcess( &gAppProcess , &psn , &isSame ); | |
73280e05 SC |
672 | if ( isSame ) |
673 | { | |
674 | #if TARGET_CARBON | |
6cce68ea | 675 | OSStatus err = noErr; |
8638e69b | 676 | |
41ab357e SC |
677 | #if 0 |
678 | // lead sometimes to race conditions, although all calls used should be thread safe ... | |
6cce68ea | 679 | static wxMacCarbonEvent s_wakeupEvent; |
8dfef0c2 | 680 | if ( !s_wakeupEvent.IsValid() ) |
d6c69b17 | 681 | { |
8dfef0c2 | 682 | err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), |
6cce68ea | 683 | kEventAttributeNone ); |
d6c69b17 | 684 | } |
8dfef0c2 | 685 | if ( err == noErr ) |
73280e05 | 686 | { |
88a7a4e1 | 687 | |
8dfef0c2 | 688 | if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) ) |
6cce68ea SC |
689 | return; |
690 | s_wakeupEvent.SetCurrentTime(); | |
d6c69b17 | 691 | err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent, |
41ab357e | 692 | kEventPriorityHigh ); |
8dfef0c2 | 693 | } |
41ab357e | 694 | #else |
6cce68ea | 695 | wxMacCarbonEvent wakeupEvent; |
41ab357e | 696 | wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), |
6cce68ea | 697 | kEventAttributeNone ); |
41ab357e SC |
698 | err = PostEventToQueue(GetMainEventQueue(), wakeupEvent, |
699 | kEventPriorityHigh ); | |
700 | #endif | |
73280e05 | 701 | #else |
6cce68ea | 702 | PostEvent( nullEvent , 0 ); |
73280e05 SC |
703 | #endif |
704 | } | |
705 | else | |
706 | { | |
6cce68ea | 707 | WakeUpProcess( &gAppProcess ); |
73280e05 SC |
708 | } |
709 | } | |
710 | ||
d13ea1bd RD |
711 | #endif // wxUSE_BASE |
712 | ||
713 | #if wxUSE_GUI | |
714 | ||
1f1c8bd4 SC |
715 | // ---------------------------------------------------------------------------- |
716 | // Native Struct Conversions | |
717 | // ---------------------------------------------------------------------------- | |
718 | ||
fb5246be | 719 | void wxMacRectToNative( const wxRect *wx , Rect *n ) |
1f1c8bd4 | 720 | { |
6cce68ea SC |
721 | n->left = wx->x; |
722 | n->top = wx->y; | |
723 | n->right = wx->x + wx->width; | |
724 | n->bottom = wx->y + wx->height; | |
1f1c8bd4 SC |
725 | } |
726 | ||
fb5246be | 727 | void wxMacNativeToRect( const Rect *n , wxRect* wx ) |
1f1c8bd4 | 728 | { |
6cce68ea SC |
729 | wx->x = n->left; |
730 | wx->y = n->top; | |
731 | wx->width = n->right - n->left; | |
732 | wx->height = n->bottom - n->top; | |
1f1c8bd4 SC |
733 | } |
734 | ||
fb5246be | 735 | void wxMacPointToNative( const wxPoint* wx , Point *n ) |
1f1c8bd4 | 736 | { |
6cce68ea SC |
737 | n->h = wx->x; |
738 | n->v = wx->y; | |
1f1c8bd4 SC |
739 | } |
740 | ||
fb5246be | 741 | void wxMacNativeToPoint( const Point *n , wxPoint* wx ) |
1f1c8bd4 | 742 | { |
6cce68ea SC |
743 | wx->x = n->h; |
744 | wx->y = n->v; | |
1f1c8bd4 | 745 | } |
d13ea1bd | 746 | |
facd6764 SC |
747 | // ---------------------------------------------------------------------------- |
748 | // Carbon Event Support | |
749 | // ---------------------------------------------------------------------------- | |
750 | ||
facd6764 SC |
751 | OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) |
752 | { | |
6cce68ea | 753 | return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ); |
facd6764 SC |
754 | } |
755 | ||
21fd5529 | 756 | OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData) |
facd6764 | 757 | { |
6cce68ea | 758 | return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ); |
facd6764 SC |
759 | } |
760 | ||
86d8b744 SC |
761 | // ---------------------------------------------------------------------------- |
762 | // Control Access Support | |
763 | // ---------------------------------------------------------------------------- | |
764 | ||
bf9a1615 SC |
765 | IMPLEMENT_DYNAMIC_CLASS( wxMacControl , wxObject ) |
766 | ||
767 | wxMacControl::wxMacControl() | |
768 | { | |
769 | Init(); | |
770 | } | |
771 | ||
1f1c8bd4 | 772 | wxMacControl::wxMacControl(wxWindow* peer , bool isRootControl ) |
9b89f11a | 773 | { |
6cce68ea SC |
774 | Init(); |
775 | m_peer = peer; | |
776 | m_isRootControl = isRootControl; | |
9b89f11a SC |
777 | } |
778 | ||
fb5246be | 779 | wxMacControl::wxMacControl( wxWindow* peer , ControlRef control ) |
9b89f11a | 780 | { |
6cce68ea SC |
781 | Init(); |
782 | m_peer = peer; | |
6cce68ea | 783 | m_controlRef = control; |
9b89f11a SC |
784 | } |
785 | ||
786 | wxMacControl::wxMacControl( wxWindow* peer , WXWidget control ) | |
787 | { | |
6cce68ea SC |
788 | Init(); |
789 | m_peer = peer; | |
6cce68ea | 790 | m_controlRef = (ControlRef) control; |
9b89f11a SC |
791 | } |
792 | ||
793 | wxMacControl::~wxMacControl() | |
794 | { | |
795 | } | |
796 | ||
797 | void wxMacControl::Init() | |
798 | { | |
6cce68ea SC |
799 | m_peer = NULL; |
800 | m_controlRef = NULL; | |
801 | m_needsFocusRect = false; | |
6cce68ea | 802 | m_isRootControl = false; |
9b89f11a SC |
803 | } |
804 | ||
5ca0d812 SC |
805 | void wxMacControl::Dispose() |
806 | { | |
b5d59f11 | 807 | wxASSERT_MSG( m_controlRef != NULL , wxT("Control Handle already NULL, Dispose called twice ?") ); |
8c981ec6 SC |
808 | wxASSERT_MSG( IsValidControlHandle(m_controlRef) , wxT("Invalid Control Handle (maybe already released) in Dispose") ); |
809 | ||
83f787ba | 810 | // we cannot check the ref count here anymore, as autorelease objects might delete their refs later |
3cfcae3b SC |
811 | // we can have situations when being embedded, where the control gets deleted behind our back, so only |
812 | // CFRelease if we are safe | |
813 | if ( IsValidControlHandle(m_controlRef) ) | |
814 | CFRelease(m_controlRef); | |
6cce68ea | 815 | m_controlRef = NULL; |
5ca0d812 SC |
816 | } |
817 | ||
e6c3d3e6 | 818 | void wxMacControl::SetReference( URefCon data ) |
5ca0d812 | 819 | { |
6cce68ea | 820 | SetControlReference( m_controlRef , data ); |
5ca0d812 SC |
821 | } |
822 | ||
29d91661 | 823 | OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const |
86d8b744 | 824 | { |
6cce68ea | 825 | return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ); |
86d8b744 SC |
826 | } |
827 | ||
29d91661 | 828 | OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const |
86d8b744 | 829 | { |
6cce68ea | 830 | return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ); |
86d8b744 SC |
831 | } |
832 | ||
833 | OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData) | |
834 | { | |
6cce68ea | 835 | return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ); |
86d8b744 SC |
836 | } |
837 | ||
8638e69b | 838 | OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions ) |
21fd5529 | 839 | { |
e996f509 | 840 | #if TARGET_API_MAC_OSX |
9d8aca48 | 841 | return SendEventToEventTargetWithOptions( event, |
8638e69b | 842 | HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions ); |
e996f509 | 843 | #else |
9d8aca48 | 844 | #pragma unused(inOptions) |
6cce68ea | 845 | return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ); |
e996f509 | 846 | #endif |
21fd5529 SC |
847 | } |
848 | ||
9d8aca48 | 849 | OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions ) |
21fd5529 | 850 | { |
6cce68ea | 851 | wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ); |
8638e69b | 852 | |
6cce68ea | 853 | event.SetParameter<HICommand>(kEventParamDirectObject,command); |
8638e69b | 854 | |
6cce68ea | 855 | return SendEvent( event , inOptions ); |
21fd5529 SC |
856 | } |
857 | ||
9d8aca48 | 858 | OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions ) |
21fd5529 | 859 | { |
6cce68ea | 860 | HICommand command; |
8638e69b | 861 | |
6cce68ea SC |
862 | memset( &command, 0 , sizeof(command) ); |
863 | command.commandID = commandID; | |
864 | return SendHICommand( command , inOptions ); | |
21fd5529 SC |
865 | } |
866 | ||
9d8aca48 | 867 | void wxMacControl::Flash( ControlPartCode part , UInt32 ticks ) |
21fd5529 | 868 | { |
6cce68ea | 869 | unsigned long finalTicks; |
8638e69b | 870 | |
6cce68ea SC |
871 | HiliteControl( m_controlRef , part ); |
872 | Delay( ticks , &finalTicks ); | |
873 | HiliteControl( m_controlRef , kControlNoPart ); | |
21fd5529 SC |
874 | } |
875 | ||
7f7b52b4 | 876 | SInt32 wxMacControl::GetValue() const |
9d8aca48 | 877 | { |
6cce68ea | 878 | return ::GetControl32BitValue( m_controlRef ); |
7f7b52b4 SC |
879 | } |
880 | ||
881 | SInt32 wxMacControl::GetMaximum() const | |
9d8aca48 | 882 | { |
6cce68ea | 883 | return ::GetControl32BitMaximum( m_controlRef ); |
7f7b52b4 SC |
884 | } |
885 | ||
886 | SInt32 wxMacControl::GetMinimum() const | |
9d8aca48 | 887 | { |
6cce68ea | 888 | return ::GetControl32BitMinimum( m_controlRef ); |
7f7b52b4 SC |
889 | } |
890 | ||
9d8aca48 WS |
891 | void wxMacControl::SetValue( SInt32 v ) |
892 | { | |
6cce68ea | 893 | ::SetControl32BitValue( m_controlRef , v ); |
7f7b52b4 SC |
894 | } |
895 | ||
9d8aca48 WS |
896 | void wxMacControl::SetMinimum( SInt32 v ) |
897 | { | |
6cce68ea | 898 | ::SetControl32BitMinimum( m_controlRef , v ); |
7f7b52b4 SC |
899 | } |
900 | ||
9d8aca48 WS |
901 | void wxMacControl::SetMaximum( SInt32 v ) |
902 | { | |
6cce68ea | 903 | ::SetControl32BitMaximum( m_controlRef , v ); |
7f7b52b4 SC |
904 | } |
905 | ||
906 | void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) | |
907 | { | |
6cce68ea SC |
908 | ::SetControl32BitMinimum( m_controlRef , minimum ); |
909 | ::SetControl32BitMaximum( m_controlRef , maximum ); | |
910 | ::SetControl32BitValue( m_controlRef , value ); | |
7f7b52b4 SC |
911 | } |
912 | ||
9d8aca48 | 913 | OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart ) |
5ca0d812 | 914 | { |
6cce68ea | 915 | return SetKeyboardFocus( GetControlOwner( m_controlRef ), m_controlRef, focusPart ); |
5ca0d812 SC |
916 | } |
917 | ||
9d8aca48 | 918 | bool wxMacControl::HasFocus() const |
5ca0d812 | 919 | { |
6cce68ea SC |
920 | ControlRef control; |
921 | GetKeyboardFocus( GetUserFocusWindow() , &control ); | |
922 | return control == m_controlRef; | |
5ca0d812 SC |
923 | } |
924 | ||
fb5246be | 925 | void wxMacControl::SetNeedsFocusRect( bool needs ) |
9b89f11a | 926 | { |
6cce68ea | 927 | m_needsFocusRect = needs; |
9b89f11a SC |
928 | } |
929 | ||
9d8aca48 | 930 | bool wxMacControl::NeedsFocusRect() const |
5ca0d812 | 931 | { |
6cce68ea | 932 | return m_needsFocusRect; |
5ca0d812 SC |
933 | } |
934 | ||
89954433 | 935 | void wxMacControl::VisibilityChanged(bool WXUNUSED(shown)) |
29d91661 SC |
936 | { |
937 | } | |
938 | ||
89a66f11 SC |
939 | void wxMacControl::SuperChangedPosition() |
940 | { | |
941 | } | |
942 | ||
9d8aca48 | 943 | void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) |
29d91661 | 944 | { |
6cce68ea | 945 | m_font = font; |
6239ee05 | 946 | #ifndef __LP64__ |
9d8aca48 WS |
947 | ControlFontStyleRec fontStyle; |
948 | if ( font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
949 | { | |
8638e69b | 950 | switch ( font.MacGetThemeFontID() ) |
9d8aca48 | 951 | { |
8638e69b | 952 | case kThemeSmallSystemFont : |
6cce68ea SC |
953 | fontStyle.font = kControlFontSmallSystemFont; |
954 | break; | |
8638e69b DS |
955 | |
956 | case 109 : // mini font | |
6cce68ea SC |
957 | fontStyle.font = -5; |
958 | break; | |
8638e69b DS |
959 | |
960 | case kThemeSystemFont : | |
6cce68ea SC |
961 | fontStyle.font = kControlFontBigSystemFont; |
962 | break; | |
8638e69b DS |
963 | |
964 | default : | |
6cce68ea SC |
965 | fontStyle.font = kControlFontBigSystemFont; |
966 | break; | |
9d8aca48 | 967 | } |
8638e69b | 968 | |
6cce68ea | 969 | fontStyle.flags = kControlUseFontMask; |
9d8aca48 WS |
970 | } |
971 | else | |
972 | { | |
6cce68ea SC |
973 | fontStyle.font = font.MacGetFontNum(); |
974 | fontStyle.style = font.MacGetFontStyle(); | |
975 | fontStyle.size = font.MacGetFontSize(); | |
976 | fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask; | |
9d8aca48 | 977 | } |
29d91661 | 978 | |
6cce68ea SC |
979 | fontStyle.just = teJustLeft; |
980 | fontStyle.flags |= kControlUseJustMask; | |
29d91661 | 981 | if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL ) |
6cce68ea | 982 | fontStyle.just = teJustCenter; |
29d91661 | 983 | else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT ) |
6cce68ea | 984 | fontStyle.just = teJustRight; |
29d91661 | 985 | |
9d8aca48 | 986 | |
29d91661 SC |
987 | // we only should do this in case of a non-standard color, as otherwise 'disabled' controls |
988 | // won't get grayed out by the system anymore | |
9d8aca48 | 989 | |
29d91661 SC |
990 | if ( foreground != *wxBLACK ) |
991 | { | |
6cce68ea SC |
992 | fontStyle.foreColor = MAC_WXCOLORREF( foreground.GetPixel() ); |
993 | fontStyle.flags |= kControlUseForeColorMask; | |
29d91661 | 994 | } |
9d8aca48 WS |
995 | |
996 | ::SetControlFontStyle( m_controlRef , &fontStyle ); | |
6239ee05 | 997 | #endif |
29d91661 SC |
998 | } |
999 | ||
9d8aca48 | 1000 | void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) ) |
7ea087b7 | 1001 | { |
9d8aca48 | 1002 | // TODO |
7ea087b7 SC |
1003 | // setting up a color proc is not recommended anymore |
1004 | } | |
1005 | ||
7f7b52b4 SC |
1006 | void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum ) |
1007 | { | |
6cce68ea SC |
1008 | ::SetControl32BitMinimum( m_controlRef , minimum ); |
1009 | ::SetControl32BitMaximum( m_controlRef , maximum ); | |
7f7b52b4 SC |
1010 | } |
1011 | ||
8638e69b | 1012 | short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) |
5ca0d812 | 1013 | { |
e6c3d3e6 | 1014 | #ifndef __LP64__ |
6cce68ea | 1015 | return HandleControlKey( m_controlRef , keyCode , charCode , modifiers ); |
e6c3d3e6 SC |
1016 | #else |
1017 | return 0; | |
1018 | #endif | |
5ca0d812 SC |
1019 | } |
1020 | ||
1021 | void wxMacControl::SetActionProc( ControlActionUPP actionProc ) | |
1022 | { | |
6cce68ea | 1023 | SetControlAction( m_controlRef , actionProc ); |
5ca0d812 SC |
1024 | } |
1025 | ||
1026 | void wxMacControl::SetViewSize( SInt32 viewSize ) | |
1027 | { | |
6cce68ea | 1028 | SetControlViewSize(m_controlRef , viewSize ); |
5ca0d812 SC |
1029 | } |
1030 | ||
1031 | SInt32 wxMacControl::GetViewSize() const | |
1032 | { | |
6cce68ea | 1033 | return GetControlViewSize( m_controlRef ); |
5ca0d812 SC |
1034 | } |
1035 | ||
9d8aca48 | 1036 | bool wxMacControl::IsVisible() const |
5ca0d812 | 1037 | { |
6cce68ea | 1038 | return IsControlVisible( m_controlRef ); |
5ca0d812 SC |
1039 | } |
1040 | ||
9d8aca48 | 1041 | void wxMacControl::SetVisibility( bool visible , bool redraw ) |
5ca0d812 | 1042 | { |
6cce68ea | 1043 | SetControlVisibility( m_controlRef , visible , redraw ); |
5ca0d812 SC |
1044 | } |
1045 | ||
9d8aca48 | 1046 | bool wxMacControl::IsEnabled() const |
5ca0d812 SC |
1047 | { |
1048 | #if TARGET_API_MAC_OSX | |
6cce68ea | 1049 | return IsControlEnabled( m_controlRef ); |
5ca0d812 | 1050 | #else |
6cce68ea | 1051 | return IsControlActive( m_controlRef ); |
5ca0d812 SC |
1052 | #endif |
1053 | } | |
1054 | ||
9d8aca48 | 1055 | bool wxMacControl::IsActive() const |
5ca0d812 | 1056 | { |
6cce68ea | 1057 | return IsControlActive( m_controlRef ); |
5ca0d812 SC |
1058 | } |
1059 | ||
9d8aca48 | 1060 | void wxMacControl::Enable( bool enable ) |
5ca0d812 | 1061 | { |
5ca0d812 | 1062 | if ( enable ) |
6cce68ea | 1063 | EnableControl( m_controlRef ); |
5ca0d812 | 1064 | else |
6cce68ea | 1065 | DisableControl( m_controlRef ); |
5ca0d812 SC |
1066 | } |
1067 | ||
9d8aca48 | 1068 | void wxMacControl::SetDrawingEnabled( bool enable ) |
5ca0d812 | 1069 | { |
6cce68ea | 1070 | HIViewSetDrawingEnabled( m_controlRef , enable ); |
5ca0d812 SC |
1071 | } |
1072 | ||
9d8aca48 | 1073 | bool wxMacControl::GetNeedsDisplay() const |
5ca0d812 | 1074 | { |
e779b609 | 1075 | return HIViewGetNeedsDisplay( m_controlRef ); |
5ca0d812 SC |
1076 | } |
1077 | ||
1f1c8bd4 | 1078 | void wxMacControl::SetNeedsDisplay( RgnHandle where ) |
5ca0d812 | 1079 | { |
1f1c8bd4 | 1080 | if ( !IsVisible() ) |
6cce68ea | 1081 | return; |
fb5246be | 1082 | |
e779b609 | 1083 | HIViewSetNeedsDisplayInRegion( m_controlRef , where , true ); |
5ca0d812 | 1084 | } |
1f1c8bd4 SC |
1085 | |
1086 | void wxMacControl::SetNeedsDisplay( Rect* where ) | |
1087 | { | |
1088 | if ( !IsVisible() ) | |
6cce68ea | 1089 | return; |
1f1c8bd4 | 1090 | |
e779b609 | 1091 | if ( where != NULL ) |
1f1c8bd4 | 1092 | { |
e779b609 SC |
1093 | RgnHandle update = NewRgn(); |
1094 | RectRgn( update , where ); | |
1095 | HIViewSetNeedsDisplayInRegion( m_controlRef , update , true ); | |
1096 | DisposeRgn( update ); | |
1f1c8bd4 SC |
1097 | } |
1098 | else | |
e779b609 | 1099 | HIViewSetNeedsDisplay( m_controlRef , true ); |
1f1c8bd4 | 1100 | } |
5ca0d812 | 1101 | |
9d8aca48 | 1102 | void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to ) |
5ca0d812 | 1103 | { |
e779b609 | 1104 | HIPoint hiPoint; |
8638e69b | 1105 | |
e779b609 SC |
1106 | hiPoint.x = pt->x; |
1107 | hiPoint.y = pt->y; | |
1108 | HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef ); | |
1109 | pt->x = (int)hiPoint.x; | |
1110 | pt->y = (int)hiPoint.y; | |
5ca0d812 SC |
1111 | } |
1112 | ||
9d8aca48 | 1113 | void wxMacControl::SetRect( Rect *r ) |
5ca0d812 | 1114 | { |
9b89f11a SC |
1115 | //A HIRect is actually a CGRect on OSX - which consists of two structures - |
1116 | //CGPoint and CGSize, which have two floats each | |
6cce68ea SC |
1117 | HIRect hir = { { r->left , r->top }, { r->right - r->left , r->bottom - r->top } }; |
1118 | HIViewSetFrame ( m_controlRef , &hir ); | |
1119 | // eventuall we might have to do a SetVisibility( false , true ); | |
1120 | // before and a SetVisibility( true , true ); after | |
8bb6b2c0 | 1121 | } |
5ca0d812 | 1122 | |
9d8aca48 | 1123 | void wxMacControl::GetRect( Rect *r ) |
5ca0d812 | 1124 | { |
6cce68ea | 1125 | GetControlBounds( m_controlRef , r ); |
5ca0d812 SC |
1126 | } |
1127 | ||
9d8aca48 | 1128 | void wxMacControl::GetRectInWindowCoords( Rect *r ) |
5ca0d812 | 1129 | { |
6cce68ea | 1130 | UMAGetControlBoundsInWindowCoords( m_controlRef , r ); |
5ca0d812 SC |
1131 | } |
1132 | ||
9d8aca48 | 1133 | void wxMacControl::GetBestRect( Rect *r ) |
5ca0d812 | 1134 | { |
6cce68ea | 1135 | short baselineoffset; |
8638e69b | 1136 | |
6cce68ea | 1137 | GetBestControlRect( m_controlRef , r , &baselineoffset ); |
5ca0d812 SC |
1138 | } |
1139 | ||
fb5246be | 1140 | void wxMacControl::SetLabel( const wxString &title ) |
5ca0d812 | 1141 | { |
10a59880 RD |
1142 | wxFontEncoding encoding; |
1143 | ||
1144 | if ( m_font.Ok() ) | |
1145 | encoding = m_font.GetEncoding(); | |
1146 | else | |
1147 | encoding = wxFont::GetDefaultEncoding(); | |
9d8aca48 | 1148 | |
6cce68ea | 1149 | UMASetControlTitle( m_controlRef , title , encoding ); |
5ca0d812 SC |
1150 | } |
1151 | ||
1152 | void wxMacControl::GetFeatures( UInt32 * features ) | |
1153 | { | |
6cce68ea | 1154 | GetControlFeatures( m_controlRef , features ); |
5ca0d812 SC |
1155 | } |
1156 | ||
9d8aca48 | 1157 | OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region ) |
5ca0d812 | 1158 | { |
6cce68ea | 1159 | OSStatus err = GetControlRegion( m_controlRef , partCode , region ); |
6cce68ea | 1160 | return err; |
5ca0d812 SC |
1161 | } |
1162 | ||
9d8aca48 | 1163 | OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other ) |
5ca0d812 SC |
1164 | { |
1165 | #if TARGET_API_MAC_OSX | |
9d8aca48 | 1166 | return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow, |
6cce68ea | 1167 | (other != NULL) ? other->m_controlRef : NULL); |
5ca0d812 | 1168 | #else |
6cce68ea | 1169 | return 0; |
5ca0d812 SC |
1170 | #endif |
1171 | } | |
1172 | ||
5ca0d812 SC |
1173 | #if TARGET_API_MAC_OSX |
1174 | // SetNeedsDisplay would not invalidate the children | |
1175 | static void InvalidateControlAndChildren( HIViewRef control ) | |
1176 | { | |
6cce68ea SC |
1177 | HIViewSetNeedsDisplay( control , true ); |
1178 | UInt16 childrenCount = 0; | |
1179 | OSStatus err = CountSubControls( control , &childrenCount ); | |
5ca0d812 | 1180 | if ( err == errControlIsNotEmbedder ) |
6cce68ea | 1181 | return; |
8638e69b | 1182 | |
6cce68ea | 1183 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ); |
5ca0d812 | 1184 | |
6cce68ea | 1185 | for ( UInt16 i = childrenCount; i >=1; --i ) |
5ca0d812 | 1186 | { |
6cce68ea | 1187 | HIViewRef child; |
8638e69b | 1188 | |
6cce68ea | 1189 | err = GetIndexedSubControl( control , i , & child ); |
5ca0d812 | 1190 | if ( err == errControlIsNotEmbedder ) |
6cce68ea | 1191 | return; |
8638e69b | 1192 | |
6cce68ea | 1193 | InvalidateControlAndChildren( child ); |
5ca0d812 SC |
1194 | } |
1195 | } | |
1196 | #endif | |
1197 | ||
9d8aca48 | 1198 | void wxMacControl::InvalidateWithChildren() |
5ca0d812 SC |
1199 | { |
1200 | #if TARGET_API_MAC_OSX | |
6cce68ea | 1201 | InvalidateControlAndChildren( m_controlRef ); |
5ca0d812 SC |
1202 | #endif |
1203 | } | |
1204 | ||
fb5246be | 1205 | void wxMacControl::ScrollRect( wxRect *r , int dx , int dy ) |
5ca0d812 | 1206 | { |
6cce68ea | 1207 | wxASSERT( r != NULL ); |
8638e69b | 1208 | |
e779b609 SC |
1209 | HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height); |
1210 | HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ); | |
5ca0d812 SC |
1211 | } |
1212 | ||
6cce68ea SC |
1213 | OSType wxMacCreator = 'WXMC'; |
1214 | OSType wxMacControlProperty = 'MCCT'; | |
1215 | ||
88a7a4e1 | 1216 | void wxMacControl::SetReferenceInNativeControl() |
6cce68ea SC |
1217 | { |
1218 | void * data = this; | |
1219 | verify_noerr( SetControlProperty ( m_controlRef , | |
1220 | wxMacCreator,wxMacControlProperty, sizeof(data), &data ) ); | |
1221 | } | |
1222 | ||
88a7a4e1 | 1223 | wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control) |
6cce68ea SC |
1224 | { |
1225 | wxMacControl* ctl = NULL; | |
e6c3d3e6 | 1226 | ByteCount actualSize; |
6cce68ea SC |
1227 | if ( GetControlProperty( control ,wxMacCreator,wxMacControlProperty, sizeof(ctl) , |
1228 | &actualSize , &ctl ) == noErr ) | |
1229 | { | |
1230 | return ctl; | |
1231 | } | |
1232 | return NULL; | |
1233 | } | |
1234 | ||
1235 | // ============================================================================ | |
1236 | // DataBrowser Wrapper | |
1237 | // ============================================================================ | |
1238 | // | |
1239 | // basing on DataBrowserItemIDs | |
1240 | // | |
1241 | ||
bf9a1615 SC |
1242 | IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl , wxMacControl ) |
1243 | ||
6cce68ea SC |
1244 | pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc( |
1245 | ControlRef browser, | |
1246 | DataBrowserItemID itemID, | |
1247 | DataBrowserItemNotification message, | |
1248 | DataBrowserItemDataRef itemData ) | |
1249 | { | |
bf9a1615 | 1250 | wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl); |
6cce68ea SC |
1251 | if ( ctl != 0 ) |
1252 | { | |
1253 | ctl->ItemNotification(itemID, message, itemData); | |
1254 | } | |
1255 | } | |
1256 | ||
1257 | pascal OSStatus wxMacDataBrowserControl::DataBrowserGetSetItemDataProc( | |
1258 | ControlRef browser, | |
1259 | DataBrowserItemID itemID, | |
1260 | DataBrowserPropertyID property, | |
1261 | DataBrowserItemDataRef itemData, | |
1262 | Boolean changeValue ) | |
1263 | { | |
1264 | OSStatus err = errDataBrowserPropertyNotSupported; | |
bf9a1615 | 1265 | wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl); |
6cce68ea SC |
1266 | if ( ctl != 0 ) |
1267 | { | |
1268 | err = ctl->GetSetItemData(itemID, property, itemData, changeValue); | |
1269 | } | |
1270 | return err; | |
1271 | } | |
1272 | ||
1273 | pascal Boolean wxMacDataBrowserControl::DataBrowserCompareProc( | |
88a7a4e1 WS |
1274 | ControlRef browser, |
1275 | DataBrowserItemID itemOneID, | |
1276 | DataBrowserItemID itemTwoID, | |
1277 | DataBrowserPropertyID sortProperty) | |
6cce68ea | 1278 | { |
bf9a1615 | 1279 | wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl); |
6cce68ea SC |
1280 | if ( ctl != 0 ) |
1281 | { | |
1282 | return ctl->CompareItems(itemOneID, itemTwoID, sortProperty); | |
1283 | } | |
1284 | return false; | |
1285 | } | |
1286 | ||
1287 | DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL; | |
1288 | DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL; | |
1289 | DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL; | |
1290 | ||
89954433 VZ |
1291 | wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow* peer, |
1292 | const wxPoint& pos, | |
1293 | const wxSize& size, | |
1294 | long WXUNUSED(style)) | |
1295 | : wxMacControl( peer ) | |
88a7a4e1 | 1296 | { |
6cce68ea SC |
1297 | Rect bounds = wxMacGetBoundsForControl( peer, pos, size ); |
1298 | OSStatus err = ::CreateDataBrowserControl( | |
1299 | MAC_WXHWND(peer->MacGetTopLevelWindowRef()), | |
1300 | &bounds, kDataBrowserListView, &m_controlRef ); | |
1301 | SetReferenceInNativeControl(); | |
1302 | verify_noerr( err ); | |
1303 | if ( gDataBrowserItemCompareUPP == NULL ) | |
1304 | gDataBrowserItemCompareUPP = NewDataBrowserItemCompareUPP(DataBrowserCompareProc); | |
1305 | if ( gDataBrowserItemDataUPP == NULL ) | |
1306 | gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc); | |
1307 | if ( gDataBrowserItemNotificationUPP == NULL ) | |
1308 | { | |
1309 | gDataBrowserItemNotificationUPP = | |
1310 | #if TARGET_API_MAC_OSX | |
1311 | (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc); | |
1312 | #else | |
1313 | NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc); | |
1314 | #endif | |
1315 | } | |
1316 | ||
1317 | DataBrowserCallbacks callbacks; | |
1318 | InitializeDataBrowserCallbacks( &callbacks, kDataBrowserLatestCallbacks ); | |
1319 | ||
1320 | callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP; | |
1321 | callbacks.u.v1.itemCompareCallback = gDataBrowserItemCompareUPP; | |
1322 | callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP; | |
1323 | SetCallbacks( &callbacks ); | |
1324 | ||
1325 | } | |
1326 | ||
1327 | OSStatus wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container, | |
1328 | Boolean recurse, | |
1329 | DataBrowserItemState state, | |
e6c3d3e6 | 1330 | ItemCount *numItems) const |
6cce68ea | 1331 | { |
88a7a4e1 | 1332 | return GetDataBrowserItemCount( m_controlRef, container, recurse, state, numItems ); |
6cce68ea SC |
1333 | } |
1334 | ||
1335 | OSStatus wxMacDataBrowserControl::GetItems( DataBrowserItemID container, | |
1336 | Boolean recurse, | |
1337 | DataBrowserItemState state, | |
88a7a4e1 | 1338 | Handle items) const |
6cce68ea | 1339 | { |
88a7a4e1 | 1340 | return GetDataBrowserItems( m_controlRef, container, recurse, state, items ); |
6cce68ea SC |
1341 | } |
1342 | ||
1343 | OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options ) | |
1344 | { | |
1345 | return SetDataBrowserSelectionFlags( m_controlRef, options ); | |
1346 | } | |
1347 | ||
1348 | OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc, | |
1349 | DataBrowserTableViewColumnIndex position ) | |
1350 | { | |
1351 | return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position ); | |
1352 | } | |
1353 | ||
e2bc1d69 | 1354 | OSStatus wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id ){ |
f49c76e5 | 1355 | return GetDataBrowserTableViewColumnProperty( m_controlRef, position, id ); |
e2bc1d69 KO |
1356 | } |
1357 | ||
1358 | OSStatus wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position ) | |
1359 | { | |
f49c76e5 | 1360 | DataBrowserTableViewColumnID id; |
e2bc1d69 KO |
1361 | GetColumnIDFromIndex( position, &id ); |
1362 | return RemoveDataBrowserTableViewColumn( m_controlRef, id ); | |
1363 | } | |
1364 | ||
6cce68ea SC |
1365 | OSStatus wxMacDataBrowserControl::AutoSizeColumns() |
1366 | { | |
1367 | return AutoSizeDataBrowserListViewColumns(m_controlRef); | |
1368 | } | |
1369 | ||
1370 | OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert ) | |
1371 | { | |
1372 | return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert ); | |
1373 | } | |
1374 | ||
1375 | OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) | |
1376 | { | |
1377 | return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle ); | |
1378 | } | |
1379 | ||
1380 | OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height) | |
1381 | { | |
1382 | return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height ); | |
1383 | } | |
1384 | ||
1385 | OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height) | |
1386 | { | |
1387 | return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height ); | |
1388 | } | |
1389 | ||
1390 | OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks) | |
1391 | { | |
1392 | return SetDataBrowserCallbacks( m_controlRef, callbacks ); | |
1393 | } | |
1394 | ||
88a7a4e1 | 1395 | OSStatus wxMacDataBrowserControl::UpdateItems( |
6cce68ea SC |
1396 | DataBrowserItemID container, |
1397 | UInt32 numItems, | |
1398 | const DataBrowserItemID *items, | |
1399 | DataBrowserPropertyID preSortProperty, | |
1400 | DataBrowserPropertyID propertyID ) const | |
1401 | { | |
1402 | return UpdateDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty, propertyID ); | |
1403 | } | |
1404 | ||
1405 | bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const | |
1406 | { | |
1407 | return IsDataBrowserItemSelected( m_controlRef, item ); | |
1408 | } | |
1409 | ||
1410 | OSStatus wxMacDataBrowserControl::AddItems( | |
1411 | DataBrowserItemID container, | |
1412 | UInt32 numItems, | |
1413 | const DataBrowserItemID *items, | |
1414 | DataBrowserPropertyID preSortProperty ) | |
1415 | { | |
1416 | return AddDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty ); | |
1417 | } | |
1418 | ||
1419 | OSStatus wxMacDataBrowserControl::RemoveItems( | |
1420 | DataBrowserItemID container, | |
1421 | UInt32 numItems, | |
1422 | const DataBrowserItemID *items, | |
1423 | DataBrowserPropertyID preSortProperty ) | |
1424 | { | |
1425 | return RemoveDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty ); | |
1426 | } | |
1427 | ||
1428 | OSStatus wxMacDataBrowserControl::RevealItem( | |
1429 | DataBrowserItemID item, | |
1430 | DataBrowserPropertyID propertyID, | |
1431 | DataBrowserRevealOptions options ) const | |
1432 | { | |
1433 | return RevealDataBrowserItem( m_controlRef, item, propertyID, options ); | |
1434 | } | |
1435 | ||
1436 | OSStatus wxMacDataBrowserControl::SetSelectedItems( | |
1437 | UInt32 numItems, | |
1438 | const DataBrowserItemID *items, | |
1439 | DataBrowserSetOption operation ) | |
1440 | { | |
1441 | return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation ); | |
1442 | } | |
1443 | ||
1444 | OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const | |
1445 | { | |
1446 | return GetDataBrowserSelectionAnchor( m_controlRef, first, last ); | |
1447 | } | |
1448 | ||
1449 | OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const | |
1450 | { | |
1451 | return GetDataBrowserTableViewItemID( m_controlRef, row, item ); | |
1452 | } | |
1453 | ||
1454 | OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const | |
1455 | { | |
1456 | return GetDataBrowserTableViewItemRow( m_controlRef, item, row ); | |
1457 | } | |
1458 | ||
88a7a4e1 | 1459 | OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height ) |
6cce68ea | 1460 | { |
88a7a4e1 | 1461 | return SetDataBrowserTableViewRowHeight( m_controlRef , height ); |
6cce68ea SC |
1462 | } |
1463 | ||
88a7a4e1 | 1464 | OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const |
6cce68ea | 1465 | { |
88a7a4e1 | 1466 | return GetDataBrowserTableViewRowHeight( m_controlRef, height ); |
6cce68ea | 1467 | } |
88a7a4e1 WS |
1468 | |
1469 | OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height) | |
6cce68ea SC |
1470 | { |
1471 | return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height ); | |
1472 | } | |
1473 | ||
88a7a4e1 | 1474 | OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const |
6cce68ea SC |
1475 | { |
1476 | return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height); | |
1477 | } | |
1478 | ||
88a7a4e1 | 1479 | OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const |
6cce68ea SC |
1480 | { |
1481 | return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width ); | |
1482 | } | |
1483 | ||
88a7a4e1 | 1484 | OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width ) |
6cce68ea SC |
1485 | { |
1486 | return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width ); | |
1487 | } | |
1488 | ||
88a7a4e1 | 1489 | OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const |
6cce68ea SC |
1490 | { |
1491 | return GetDataBrowserTableViewColumnWidth( m_controlRef , width ); | |
1492 | } | |
1493 | ||
88a7a4e1 | 1494 | OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width ) |
6cce68ea SC |
1495 | { |
1496 | return SetDataBrowserTableViewColumnWidth( m_controlRef , width ); | |
1497 | } | |
1498 | ||
88a7a4e1 | 1499 | OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const |
6cce68ea SC |
1500 | { |
1501 | return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns); | |
1502 | } | |
1503 | ||
88a7a4e1 | 1504 | OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column, |
e6c3d3e6 | 1505 | DataBrowserTableViewColumnIndex *position) const |
6cce68ea SC |
1506 | { |
1507 | return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position); | |
1508 | } | |
1509 | ||
e6c3d3e6 | 1510 | OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position) |
6cce68ea SC |
1511 | { |
1512 | return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position); | |
1513 | } | |
1514 | ||
88a7a4e1 | 1515 | OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const |
6cce68ea SC |
1516 | { |
1517 | return GetDataBrowserScrollPosition( m_controlRef , top , left ); | |
1518 | } | |
1519 | ||
88a7a4e1 | 1520 | OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left ) |
6cce68ea SC |
1521 | { |
1522 | return SetDataBrowserScrollPosition( m_controlRef , top , left ); | |
1523 | } | |
1524 | ||
88a7a4e1 | 1525 | OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const |
6cce68ea SC |
1526 | { |
1527 | return GetDataBrowserSortProperty( m_controlRef , column ); | |
1528 | } | |
1529 | ||
88a7a4e1 | 1530 | OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column ) |
6cce68ea SC |
1531 | { |
1532 | return SetDataBrowserSortProperty( m_controlRef , column ); | |
1533 | } | |
88a7a4e1 WS |
1534 | |
1535 | OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const | |
6cce68ea SC |
1536 | { |
1537 | return GetDataBrowserSortOrder( m_controlRef , order ); | |
1538 | } | |
1539 | ||
88a7a4e1 | 1540 | OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order ) |
6cce68ea SC |
1541 | { |
1542 | return SetDataBrowserSortOrder( m_controlRef , order ); | |
1543 | } | |
1544 | ||
88a7a4e1 WS |
1545 | OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property, |
1546 | DataBrowserPropertyFlags *flags ) const | |
6cce68ea SC |
1547 | { |
1548 | return GetDataBrowserPropertyFlags( m_controlRef , property , flags ); | |
1549 | } | |
1550 | ||
88a7a4e1 WS |
1551 | OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property, |
1552 | DataBrowserPropertyFlags flags ) | |
6cce68ea SC |
1553 | { |
1554 | return SetDataBrowserPropertyFlags( m_controlRef , property , flags ); | |
1555 | } | |
1556 | ||
88a7a4e1 WS |
1557 | OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property, |
1558 | DataBrowserListViewHeaderDesc *desc ) const | |
6cce68ea SC |
1559 | { |
1560 | return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc ); | |
1561 | } | |
1562 | ||
88a7a4e1 WS |
1563 | OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property, |
1564 | DataBrowserListViewHeaderDesc *desc ) | |
6cce68ea | 1565 | { |
88a7a4e1 | 1566 | return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc ); |
6cce68ea SC |
1567 | } |
1568 | ||
88a7a4e1 WS |
1569 | OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property , |
1570 | Boolean expandableRows ) | |
6cce68ea SC |
1571 | { |
1572 | return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows); | |
1573 | } | |
1574 | ||
1575 | // ============================================================================ | |
88a7a4e1 | 1576 | // Higher-level Databrowser |
6cce68ea SC |
1577 | // ============================================================================ |
1578 | // | |
1579 | // basing on data item objects | |
1580 | // | |
1581 | ||
1582 | wxMacDataItem::wxMacDataItem() | |
88a7a4e1 | 1583 | { |
e2bc1d69 | 1584 | m_data = NULL; |
f49c76e5 | 1585 | |
e2bc1d69 KO |
1586 | m_order = 0; |
1587 | m_colId = kTextColumnId; // for compat with existing wx*ListBox impls. | |
6cce68ea SC |
1588 | } |
1589 | ||
88a7a4e1 WS |
1590 | wxMacDataItem::~wxMacDataItem() |
1591 | { | |
6cce68ea | 1592 | } |
88a7a4e1 | 1593 | |
e2bc1d69 | 1594 | void wxMacDataItem::SetOrder( SInt32 order ) |
6cce68ea | 1595 | { |
e2bc1d69 KO |
1596 | m_order = order; |
1597 | } | |
1598 | ||
1599 | SInt32 wxMacDataItem::GetOrder() const | |
1600 | { | |
1601 | return m_order; | |
1602 | } | |
1603 | ||
1604 | void wxMacDataItem::SetData( void* data) | |
1605 | { | |
1606 | m_data = data; | |
1607 | } | |
1608 | ||
1609 | void* wxMacDataItem::GetData() const | |
1610 | { | |
1611 | return m_data; | |
1612 | } | |
1613 | ||
1614 | short wxMacDataItem::GetColumn() | |
1615 | { | |
1616 | return m_colId; | |
1617 | } | |
1618 | ||
1619 | void wxMacDataItem::SetColumn( short col ) | |
1620 | { | |
1621 | m_colId = col; | |
f49c76e5 | 1622 | } |
e2bc1d69 KO |
1623 | |
1624 | void wxMacDataItem::SetLabel( const wxString& str) | |
1625 | { | |
1626 | m_label = str; | |
1627 | m_cfLabel.Assign( str , wxLocale::GetSystemEncoding()); | |
6cce68ea SC |
1628 | } |
1629 | ||
e2bc1d69 KO |
1630 | const wxString& wxMacDataItem::GetLabel() const |
1631 | { | |
1632 | return m_label; | |
1633 | } | |
1634 | ||
89954433 | 1635 | bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *WXUNUSED(owner) , |
e2bc1d69 KO |
1636 | const wxMacDataItem* rhs, |
1637 | DataBrowserPropertyID sortProperty) const | |
1638 | { | |
bf9a1615 | 1639 | const wxMacDataItem* otherItem = wx_const_cast(wxMacDataItem*,rhs); |
e2bc1d69 | 1640 | bool retval = false; |
f49c76e5 | 1641 | |
67650ea0 | 1642 | if ( sortProperty == m_colId ){ |
e2bc1d69 KO |
1643 | retval = m_label.CmpNoCase( otherItem->m_label) < 0; |
1644 | } | |
f49c76e5 | 1645 | |
67650ea0 | 1646 | else if ( sortProperty == kNumericOrderColumnId ) |
e2bc1d69 KO |
1647 | retval = m_order < otherItem->m_order; |
1648 | ||
1649 | return retval; | |
1650 | } | |
1651 | ||
89954433 | 1652 | OSStatus wxMacDataItem::GetSetData( wxMacDataItemBrowserControl *WXUNUSED(owner) , |
6cce68ea SC |
1653 | DataBrowserPropertyID property, |
1654 | DataBrowserItemDataRef itemData, | |
88a7a4e1 | 1655 | bool changeValue ) |
6cce68ea | 1656 | { |
e2bc1d69 KO |
1657 | OSStatus err = errDataBrowserPropertyNotSupported; |
1658 | if ( !changeValue ) | |
1659 | { | |
1660 | if ( property == m_colId ){ | |
1661 | err = ::SetDataBrowserItemDataText( itemData, m_cfLabel ); | |
1662 | err = noErr; | |
1663 | } | |
1664 | else if ( property == kNumericOrderColumnId ){ | |
1665 | err = ::SetDataBrowserItemDataValue( itemData, m_order ); | |
1666 | err = noErr; | |
1667 | } | |
1668 | else{ | |
1669 | } | |
1670 | } | |
1671 | else | |
1672 | { | |
1673 | switch (property) | |
1674 | { | |
1675 | // no editable props here | |
1676 | default: | |
1677 | break; | |
1678 | } | |
1679 | } | |
1680 | ||
1681 | return err; | |
6cce68ea SC |
1682 | } |
1683 | ||
89954433 VZ |
1684 | void wxMacDataItem::Notification(wxMacDataItemBrowserControl *WXUNUSED(owner) , |
1685 | DataBrowserItemNotification WXUNUSED(message), | |
1686 | DataBrowserItemDataRef WXUNUSED(itemData) ) const | |
6cce68ea SC |
1687 | { |
1688 | } | |
1689 | ||
bf9a1615 | 1690 | IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl , wxMacDataBrowserControl ) |
6cce68ea | 1691 | |
88a7a4e1 | 1692 | wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) : |
6cce68ea | 1693 | wxMacDataBrowserControl( peer, pos, size, style ) |
88a7a4e1 | 1694 | { |
6cce68ea | 1695 | m_suppressSelection = false; |
e2bc1d69 KO |
1696 | m_sortOrder = SortOrder_None; |
1697 | m_clientDataItemsType = wxClientData_None; | |
1698 | } | |
1699 | ||
1700 | wxMacDataItem* wxMacDataItemBrowserControl::CreateItem() | |
1701 | { | |
1702 | return new wxMacDataItem(); | |
6cce68ea | 1703 | } |
88a7a4e1 WS |
1704 | |
1705 | wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser) | |
6cce68ea SC |
1706 | { |
1707 | m_former = browser->SuppressSelection(true); | |
1708 | m_browser = browser; | |
1709 | } | |
1710 | ||
1711 | wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor() | |
1712 | { | |
1713 | m_browser->SuppressSelection(m_former); | |
1714 | } | |
1715 | ||
1716 | bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress ) | |
1717 | { | |
1718 | bool former = m_suppressSelection; | |
1719 | m_suppressSelection = suppress; | |
1720 | ||
1721 | return former; | |
1722 | } | |
1723 | ||
88a7a4e1 WS |
1724 | Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID, |
1725 | DataBrowserItemID itemTwoID, | |
1726 | DataBrowserPropertyID sortProperty) | |
6cce68ea SC |
1727 | { |
1728 | wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID; | |
1729 | wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID; | |
1730 | return CompareItems( itemOne , itemTwo , sortProperty ); | |
1731 | } | |
1732 | ||
88a7a4e1 WS |
1733 | Boolean wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem* itemOne, |
1734 | const wxMacDataItem* itemTwo, | |
1735 | DataBrowserPropertyID sortProperty) | |
6cce68ea SC |
1736 | { |
1737 | Boolean retval = false; | |
1738 | if ( itemOne != NULL ) | |
1739 | retval = itemOne->IsLessThan( this , itemTwo , sortProperty); | |
1740 | return retval; | |
1741 | } | |
1742 | ||
1743 | OSStatus wxMacDataItemBrowserControl::GetSetItemData( | |
1744 | DataBrowserItemID itemID, | |
1745 | DataBrowserPropertyID property, | |
1746 | DataBrowserItemDataRef itemData, | |
88a7a4e1 | 1747 | Boolean changeValue ) |
6cce68ea SC |
1748 | { |
1749 | wxMacDataItem* item = (wxMacDataItem*) itemID; | |
1750 | return GetSetItemData(item, property, itemData , changeValue ); | |
1751 | } | |
1752 | ||
1753 | OSStatus wxMacDataItemBrowserControl::GetSetItemData( | |
1754 | wxMacDataItem* item, | |
1755 | DataBrowserPropertyID property, | |
1756 | DataBrowserItemDataRef itemData, | |
88a7a4e1 | 1757 | Boolean changeValue ) |
6cce68ea SC |
1758 | { |
1759 | OSStatus err = errDataBrowserPropertyNotSupported; | |
1760 | switch( property ) | |
1761 | { | |
1762 | case kDataBrowserContainerIsClosableProperty : | |
1763 | case kDataBrowserContainerIsSortableProperty : | |
1764 | case kDataBrowserContainerIsOpenableProperty : | |
1765 | // right now default behaviour on these | |
1766 | break; | |
1767 | default : | |
f49c76e5 | 1768 | |
e2bc1d69 | 1769 | if ( item != NULL ){ |
6cce68ea | 1770 | err = item->GetSetData( this, property , itemData , changeValue ); |
e2bc1d69 | 1771 | } |
6cce68ea | 1772 | break; |
88a7a4e1 | 1773 | |
6cce68ea SC |
1774 | } |
1775 | return err; | |
1776 | } | |
1777 | ||
1778 | void wxMacDataItemBrowserControl::ItemNotification( | |
1779 | DataBrowserItemID itemID, | |
1780 | DataBrowserItemNotification message, | |
88a7a4e1 | 1781 | DataBrowserItemDataRef itemData) |
6cce68ea | 1782 | { |
88a7a4e1 | 1783 | wxMacDataItem* item = (wxMacDataItem*) itemID; |
6cce68ea SC |
1784 | ItemNotification( item , message, itemData); |
1785 | } | |
1786 | ||
1787 | void wxMacDataItemBrowserControl::ItemNotification( | |
1788 | const wxMacDataItem* item, | |
1789 | DataBrowserItemNotification message, | |
88a7a4e1 | 1790 | DataBrowserItemDataRef itemData) |
6cce68ea SC |
1791 | { |
1792 | if (item != NULL) | |
1793 | item->Notification( this, message, itemData); | |
1794 | } | |
1795 | ||
88a7a4e1 WS |
1796 | unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container, |
1797 | bool recurse , DataBrowserItemState state) const | |
6cce68ea | 1798 | { |
e6c3d3e6 | 1799 | ItemCount numItems = 0; |
88a7a4e1 WS |
1800 | verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container, |
1801 | recurse, state, &numItems ) ); | |
6cce68ea SC |
1802 | return numItems; |
1803 | } | |
1804 | ||
f49c76e5 | 1805 | unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem* container, |
e2bc1d69 KO |
1806 | bool recurse ) const |
1807 | { | |
1808 | return GetItemCount( container, recurse, kDataBrowserItemIsSelected ); | |
1809 | ||
1810 | } | |
1811 | ||
88a7a4e1 WS |
1812 | void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container, |
1813 | bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const | |
6cce68ea SC |
1814 | { |
1815 | Handle handle = NewHandle(0); | |
88a7a4e1 WS |
1816 | verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container , |
1817 | recurse , state, handle) ); | |
6cce68ea SC |
1818 | |
1819 | int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID); | |
1820 | HLock( handle ); | |
1821 | wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle; | |
1822 | for ( int i = 0; i < itemCount; ++i) | |
1823 | { | |
1824 | items.Add(itemsArray[i]); | |
1825 | } | |
1826 | HUnlock( handle ); | |
1827 | DisposeHandle( handle ); | |
1828 | } | |
1829 | ||
1830 | unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const | |
1831 | { | |
1832 | DataBrowserTableViewRowIndex row; | |
1833 | OSStatus err = GetItemRow( (DataBrowserItemID) item , &row); | |
1834 | wxASSERT( err == noErr); | |
1835 | return row; | |
1836 | } | |
1837 | ||
1838 | wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const | |
1839 | { | |
1840 | DataBrowserItemID id; | |
1841 | OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id); | |
1842 | wxASSERT( err == noErr); | |
88a7a4e1 | 1843 | return (wxMacDataItem*) id; |
6cce68ea SC |
1844 | } |
1845 | ||
88a7a4e1 | 1846 | void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container, |
6cce68ea SC |
1847 | const wxMacDataItem *item , DataBrowserPropertyID property) const |
1848 | { | |
88a7a4e1 | 1849 | verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1, |
6cce68ea SC |
1850 | (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) ); |
1851 | } | |
1852 | ||
88a7a4e1 | 1853 | void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container, |
6cce68ea SC |
1854 | wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const |
1855 | { | |
1856 | unsigned int noItems = itemArray.GetCount(); | |
1857 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1858 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1859 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1860 | ||
88a7a4e1 | 1861 | verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems, |
6cce68ea SC |
1862 | items, kDataBrowserItemNoProperty /* notSorted */, property ) ); |
1863 | delete [] items; | |
1864 | } | |
1865 | ||
3ef4e126 | 1866 | void wxMacDataItemBrowserControl::InsertColumn(int colId, DataBrowserPropertyType colType, |
0e4124e7 | 1867 | const wxString& title, SInt16 just, int defaultWidth) |
e2bc1d69 KO |
1868 | { |
1869 | DataBrowserListViewColumnDesc columnDesc; | |
1870 | columnDesc.headerBtnDesc.titleOffset = 0; | |
1871 | columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; | |
1872 | ||
1873 | columnDesc.headerBtnDesc.btnFontStyle.flags = | |
1874 | kControlUseFontMask | kControlUseJustMask; | |
1875 | ||
f49c76e5 | 1876 | columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly; |
e2bc1d69 KO |
1877 | columnDesc.headerBtnDesc.btnFontStyle.just = just; |
1878 | columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; | |
1879 | columnDesc.headerBtnDesc.btnFontStyle.style = normal; | |
f49c76e5 | 1880 | |
e2bc1d69 KO |
1881 | // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is |
1882 | // defined for other modes? | |
1883 | wxFontEncoding enc; | |
1884 | if ( m_font.Ok() ) | |
1885 | enc = m_font.GetEncoding(); | |
1886 | else | |
1887 | enc = wxLocale::GetSystemEncoding(); | |
1888 | wxMacCFStringHolder cfTitle; | |
1889 | cfTitle.Assign( title, enc ); | |
f49c76e5 | 1890 | columnDesc.headerBtnDesc.titleString = cfTitle; |
0d2d29b1 KO |
1891 | |
1892 | columnDesc.headerBtnDesc.minimumWidth = 0; | |
1893 | columnDesc.headerBtnDesc.maximumWidth = 30000; | |
e2bc1d69 KO |
1894 | |
1895 | columnDesc.propertyDesc.propertyID = (kMinColumnId + colId); | |
1896 | columnDesc.propertyDesc.propertyType = colType; | |
f49c76e5 | 1897 | columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn; |
f49c76e5 | 1898 | columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; |
4e78e173 | 1899 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
67650ea0 | 1900 | columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton; |
e2bc1d69 KO |
1901 | #endif |
1902 | ||
1903 | verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); | |
0d2d29b1 KO |
1904 | |
1905 | if (defaultWidth > 0){ | |
1906 | SetColumnWidth(colId, defaultWidth); | |
1907 | } | |
1908 | ||
e2bc1d69 KO |
1909 | } |
1910 | ||
1911 | void wxMacDataItemBrowserControl::SetColumnWidth(int colId, int width) | |
1912 | { | |
1913 | DataBrowserPropertyID id; | |
1914 | GetColumnIDFromIndex(colId, &id); | |
1915 | verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id, width)); | |
1916 | } | |
1917 | ||
1918 | int wxMacDataItemBrowserControl::GetColumnWidth(int colId) | |
1919 | { | |
1920 | DataBrowserPropertyID id; | |
1921 | GetColumnIDFromIndex(colId, &id); | |
1922 | UInt16 result; | |
1923 | verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id, &result)); | |
1924 | return result; | |
1925 | } | |
1926 | ||
6cce68ea SC |
1927 | void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item) |
1928 | { | |
88a7a4e1 | 1929 | verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1, |
6cce68ea SC |
1930 | (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) ); |
1931 | } | |
1932 | ||
88a7a4e1 | 1933 | void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray ) |
6cce68ea SC |
1934 | { |
1935 | unsigned int noItems = itemArray.GetCount(); | |
1936 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1937 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1938 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1939 | ||
88a7a4e1 | 1940 | verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, noItems, |
6cce68ea SC |
1941 | (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) ); |
1942 | delete [] items; | |
1943 | } | |
1944 | ||
88a7a4e1 | 1945 | void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item) |
6cce68ea | 1946 | { |
88a7a4e1 | 1947 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1, |
e6c3d3e6 | 1948 | (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ); |
6cce68ea SC |
1949 | verify_noerr( err ); |
1950 | } | |
1951 | ||
88a7a4e1 | 1952 | void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray) |
6cce68ea SC |
1953 | { |
1954 | unsigned int noItems = itemArray.GetCount(); | |
1955 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1956 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1957 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1958 | ||
88a7a4e1 | 1959 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems, |
e6c3d3e6 | 1960 | (DataBrowserItemID*) items, kDataBrowserItemNoProperty ); |
6cce68ea SC |
1961 | verify_noerr( err ); |
1962 | delete [] items; | |
1963 | } | |
1964 | ||
88a7a4e1 | 1965 | void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container) |
6cce68ea SC |
1966 | { |
1967 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty ); | |
1968 | verify_noerr( err ); | |
1969 | } | |
1970 | ||
88a7a4e1 | 1971 | void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option) |
6cce68ea SC |
1972 | { |
1973 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option )); | |
1974 | } | |
1975 | ||
88a7a4e1 | 1976 | void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option) |
6cce68ea SC |
1977 | { |
1978 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option )); | |
1979 | } | |
1980 | ||
88a7a4e1 | 1981 | void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option) |
6cce68ea SC |
1982 | { |
1983 | unsigned int noItems = itemArray.GetCount(); | |
1984 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1985 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1986 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1987 | ||
1988 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option )); | |
1989 | delete [] items; | |
1990 | } | |
1991 | ||
1992 | Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const | |
1993 | { | |
1994 | return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item); | |
1995 | } | |
1996 | ||
88a7a4e1 | 1997 | void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options) |
6cce68ea SC |
1998 | { |
1999 | verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) ); | |
2000 | } | |
2001 | ||
88a7a4e1 | 2002 | void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const |
6cce68ea | 2003 | { |
88a7a4e1 | 2004 | verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) ); |
6cce68ea SC |
2005 | } |
2006 | ||
e2bc1d69 KO |
2007 | wxClientDataType wxMacDataItemBrowserControl::GetClientDataType() const |
2008 | { | |
2009 | return m_clientDataItemsType; | |
2010 | } | |
2011 | void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType) | |
2012 | { | |
2013 | m_clientDataItemsType = clientDataItemsType; | |
2014 | } | |
2015 | ||
2016 | unsigned int wxMacDataItemBrowserControl::MacGetCount() const | |
2017 | { | |
2018 | return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState); | |
2019 | } | |
2020 | ||
2021 | void wxMacDataItemBrowserControl::MacDelete( unsigned int n ) | |
2022 | { | |
2023 | wxMacDataItem* item = (wxMacDataItem*)GetItemFromLine( n ); | |
2024 | RemoveItem( wxMacDataBrowserRootContainer, item ); | |
2025 | } | |
2026 | ||
a236aa20 VZ |
2027 | void wxMacDataItemBrowserControl::MacInsert( unsigned int n, |
2028 | const wxArrayStringsAdapter& items, | |
2029 | int column ) | |
e2bc1d69 KO |
2030 | { |
2031 | size_t itemsCount = items.GetCount(); | |
2032 | if ( itemsCount == 0 ) | |
2033 | return; | |
2034 | ||
2035 | SInt32 frontLineOrder = 0; | |
2036 | ||
2037 | if ( m_sortOrder == SortOrder_None ) | |
2038 | { | |
2039 | // increase the order of the lines to be shifted | |
2040 | unsigned int lines = MacGetCount(); | |
2041 | for ( unsigned int i = n; i < lines; ++i) | |
2042 | { | |
2043 | wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i); | |
2044 | iter->SetOrder( iter->GetOrder() + itemsCount ); | |
2045 | } | |
2046 | if ( n > 0 ) | |
2047 | { | |
2048 | wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1); | |
2049 | frontLineOrder = iter->GetOrder(); | |
2050 | } | |
2051 | } | |
2052 | ||
2053 | wxArrayMacDataItemPtr ids; | |
2054 | ids.SetCount( itemsCount ); | |
2055 | ||
2056 | for ( unsigned int i = 0; i < itemsCount; ++i ) | |
2057 | { | |
2058 | wxMacDataItem* item = CreateItem(); | |
2059 | item->SetLabel( items[i]); | |
2060 | if ( column != -1 ) | |
2061 | item->SetColumn( kMinColumnId + column ); | |
f49c76e5 | 2062 | |
e2bc1d69 KO |
2063 | if ( m_sortOrder == SortOrder_None ) |
2064 | item->SetOrder( frontLineOrder + 1 + i ); | |
2065 | ||
2066 | ids[i] = item; | |
2067 | } | |
2068 | ||
2069 | AddItems( wxMacDataBrowserRootContainer, ids ); | |
2070 | } | |
2071 | ||
2072 | int wxMacDataItemBrowserControl::MacAppend( const wxString& text) | |
2073 | { | |
2074 | wxMacDataItem* item = CreateItem(); | |
2075 | item->SetLabel( text ); | |
2076 | if ( m_sortOrder == SortOrder_None ) | |
2077 | { | |
2078 | unsigned int lines = MacGetCount(); | |
2079 | if ( lines == 0 ) | |
2080 | item->SetOrder( 1 ); | |
2081 | else | |
2082 | { | |
2083 | wxMacDataItem* frontItem = (wxMacDataItem*) GetItemFromLine(lines-1); | |
2084 | item->SetOrder( frontItem->GetOrder() + 1 ); | |
2085 | } | |
2086 | } | |
2087 | AddItem( wxMacDataBrowserRootContainer, item ); | |
2088 | ||
2089 | return GetLineFromItem(item); | |
2090 | } | |
2091 | ||
2092 | void wxMacDataItemBrowserControl::MacClear() | |
2093 | { | |
2094 | wxMacDataItemBrowserSelectionSuppressor suppressor(this); | |
2095 | RemoveAllItems(wxMacDataBrowserRootContainer); | |
2096 | } | |
2097 | ||
2098 | void wxMacDataItemBrowserControl::MacDeselectAll() | |
2099 | { | |
2100 | wxMacDataItemBrowserSelectionSuppressor suppressor(this); | |
2101 | SetSelectedAllItems( kDataBrowserItemsRemove ); | |
2102 | } | |
2103 | ||
2104 | void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n, bool select, bool multi ) | |
2105 | { | |
2106 | wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n); | |
2107 | wxMacDataItemBrowserSelectionSuppressor suppressor(this); | |
2108 | ||
2109 | if ( IsItemSelected( item ) != select ) | |
2110 | { | |
2111 | if ( select ) | |
2112 | SetSelectedItem( item, multi ? kDataBrowserItemsAdd : kDataBrowserItemsAssign ); | |
2113 | else | |
2114 | SetSelectedItem( item, kDataBrowserItemsRemove ); | |
2115 | } | |
2116 | ||
2117 | MacScrollTo( n ); | |
2118 | } | |
2119 | ||
2120 | bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n ) const | |
2121 | { | |
2122 | wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n); | |
2123 | return IsItemSelected( item ); | |
2124 | } | |
2125 | ||
2126 | int wxMacDataItemBrowserControl::MacGetSelection() const | |
2127 | { | |
2128 | wxMacDataItemPtr first, last; | |
2129 | GetSelectionAnchor( &first, &last ); | |
2130 | ||
2131 | if ( first != NULL ) | |
2132 | { | |
2133 | return GetLineFromItem( first ); | |
2134 | } | |
2135 | ||
2136 | return -1; | |
2137 | } | |
2138 | ||
2139 | int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt& aSelections ) const | |
2140 | { | |
2141 | aSelections.Empty(); | |
2142 | wxArrayMacDataItemPtr selectedItems; | |
2143 | GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems); | |
2144 | ||
2145 | int count = selectedItems.GetCount(); | |
2146 | ||
2147 | for ( int i = 0; i < count; ++i) | |
2148 | { | |
2149 | aSelections.Add(GetLineFromItem(selectedItems[i])); | |
2150 | } | |
2151 | ||
2152 | return count; | |
2153 | } | |
2154 | ||
2155 | void wxMacDataItemBrowserControl::MacSetString( unsigned int n, const wxString& text ) | |
2156 | { | |
2157 | // as we don't store the strings we only have to issue a redraw | |
2158 | wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n); | |
2159 | item->SetLabel( text ); | |
2160 | UpdateItem( wxMacDataBrowserRootContainer, item , kTextColumnId ); | |
2161 | } | |
2162 | ||
2163 | wxString wxMacDataItemBrowserControl::MacGetString( unsigned int n ) const | |
2164 | { | |
2165 | wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); | |
2166 | return item->GetLabel(); | |
2167 | } | |
2168 | ||
2169 | void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n, void * data) | |
2170 | { | |
2171 | wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n); | |
2172 | item->SetData( data ); | |
2173 | // not displayed, therefore no Update infos to DataBrowser | |
2174 | } | |
2175 | ||
2176 | void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n) const | |
2177 | { | |
2178 | wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); | |
2179 | return item->GetData(); | |
2180 | } | |
2181 | ||
2182 | void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n ) | |
2183 | { | |
6239ee05 SC |
2184 | UInt32 top , left ; |
2185 | GetScrollPosition( &top , &left ) ; | |
2186 | wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); | |
2187 | ||
2188 | UInt16 height ; | |
2189 | GetRowHeight( (DataBrowserItemID) item , &height ) ; | |
2190 | SetScrollPosition( n * ((UInt32)height) , left ) ; | |
2191 | ||
2192 | RevealItem( item , kDataBrowserRevealWithoutSelecting ); | |
e2bc1d69 KO |
2193 | } |
2194 | ||
88a7a4e1 | 2195 | |
6cce68ea | 2196 | |
5ca0d812 SC |
2197 | // |
2198 | // Tab Control | |
2199 | // | |
9d8aca48 WS |
2200 | |
2201 | OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable ) | |
5ca0d812 | 2202 | { |
6cce68ea | 2203 | return ::SetTabEnabled( m_controlRef , tabNo , enable ); |
5ca0d812 | 2204 | } |
9d8aca48 | 2205 | |
30e77b5c SC |
2206 | // |
2207 | // Quartz Support | |
2208 | // | |
2209 | ||
2210 | #ifdef __WXMAC_OSX__ | |
2211 | // snippets from Sketch Sample from Apple : | |
2212 | ||
8638e69b DS |
2213 | #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc" |
2214 | ||
30e77b5c | 2215 | /* |
fb5246be | 2216 | This function locates, opens, and returns the profile reference for the calibrated |
30e77b5c SC |
2217 | Generic RGB color space. It is up to the caller to call CMCloseProfile when done |
2218 | with the profile reference this function returns. | |
2219 | */ | |
8638e69b | 2220 | CMProfileRef wxMacOpenGenericProfile() |
30e77b5c SC |
2221 | { |
2222 | static CMProfileRef cachedRGBProfileRef = NULL; | |
fb5246be | 2223 | |
30e77b5c SC |
2224 | // we only create the profile reference once |
2225 | if (cachedRGBProfileRef == NULL) | |
2226 | { | |
fb5246be WS |
2227 | CMProfileLocation loc; |
2228 | ||
2229 | loc.locType = cmPathBasedProfile; | |
2230 | strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr); | |
2231 | ||
2232 | verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) ); | |
30e77b5c SC |
2233 | } |
2234 | ||
8638e69b | 2235 | // clone the profile reference so that the caller has their own reference, not our cached one |
30e77b5c | 2236 | if (cachedRGBProfileRef) |
fb5246be | 2237 | CMCloneProfileRef(cachedRGBProfileRef); |
30e77b5c SC |
2238 | |
2239 | return cachedRGBProfileRef; | |
2240 | } | |
2241 | ||
2242 | /* | |
2243 | Return the generic RGB color space. This is a 'get' function and the caller should | |
2244 | not release the returned value unless the caller retains it first. Usually callers | |
2245 | of this routine will immediately use the returned colorspace with CoreGraphics | |
2246 | so they typically do not need to retain it themselves. | |
fb5246be | 2247 | |
30e77b5c SC |
2248 | This function creates the generic RGB color space once and hangs onto it so it can |
2249 | return it whenever this function is called. | |
2250 | */ | |
2251 | ||
2252 | CGColorSpaceRef wxMacGetGenericRGBColorSpace() | |
2253 | { | |
6cce68ea | 2254 | static wxMacCFRefHolder<CGColorSpaceRef> genericRGBColorSpace; |
fb5246be | 2255 | |
8638e69b DS |
2256 | if (genericRGBColorSpace == NULL) |
2257 | { | |
26a2f914 | 2258 | if ( UMAGetSystemVersion() >= 0x1040 ) |
fb5246be | 2259 | { |
6cce68ea | 2260 | genericRGBColorSpace.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) ); |
fb5246be | 2261 | } |
26a2f914 SC |
2262 | else |
2263 | { | |
2264 | CMProfileRef genericRGBProfile = wxMacOpenGenericProfile(); | |
8638e69b | 2265 | |
26a2f914 SC |
2266 | if (genericRGBProfile) |
2267 | { | |
6cce68ea | 2268 | genericRGBColorSpace.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile) ); |
8638e69b | 2269 | |
6cce68ea | 2270 | wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") ); |
8638e69b | 2271 | |
26a2f914 | 2272 | // we opened the profile so it is up to us to close it |
88a7a4e1 | 2273 | CMCloseProfile(genericRGBProfile); |
26a2f914 SC |
2274 | } |
2275 | } | |
8638e69b DS |
2276 | } |
2277 | ||
30e77b5c SC |
2278 | return genericRGBColorSpace; |
2279 | } | |
2280 | #endif | |
2281 | ||
e6c3d3e6 SC |
2282 | #ifndef __LP64__ |
2283 | ||
54ce9ebb JS |
2284 | wxMacPortSaver::wxMacPortSaver( GrafPtr port ) |
2285 | { | |
6cce68ea SC |
2286 | ::GetPort( &m_port ); |
2287 | ::SetPort( port ); | |
54ce9ebb JS |
2288 | } |
2289 | ||
2290 | wxMacPortSaver::~wxMacPortSaver() | |
2291 | { | |
6cce68ea | 2292 | ::SetPort( m_port ); |
54ce9ebb | 2293 | } |
e6c3d3e6 SC |
2294 | #endif |
2295 | ||
2296 | void wxMacGlobalToLocal( WindowRef window , Point*pt ) | |
2297 | { | |
f49c76e5 | 2298 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4 |
e6c3d3e6 | 2299 | HIPoint p = CGPointMake( pt->h, pt->v ); |
f49c76e5 WS |
2300 | HIViewRef contentView ; |
2301 | // TODO check toolbar offset | |
daca43d8 | 2302 | HIViewFindByID( HIViewGetRoot( window ), kHIViewWindowContentID , &contentView) ; |
f49c76e5 | 2303 | HIPointConvert( &p, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceView, contentView ); |
e6c3d3e6 SC |
2304 | pt->h = p.x; |
2305 | pt->v = p.y; | |
2306 | #else | |
2307 | QDGlobalToLocalPoint( GetWindowPort(window), pt ) ; | |
2308 | #endif | |
2309 | } | |
2310 | ||
2311 | void wxMacLocalToGlobal( WindowRef window , Point*pt ) | |
2312 | { | |
f49c76e5 | 2313 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4 |
e6c3d3e6 | 2314 | HIPoint p = CGPointMake( pt->h, pt->v ); |
f49c76e5 WS |
2315 | HIViewRef contentView ; |
2316 | // TODO check toolbar offset | |
daca43d8 SC |
2317 | HIViewFindByID( HIViewGetRoot( window ), kHIViewWindowContentID , &contentView) ; |
2318 | HIPointConvert( &p, kHICoordSpaceView, contentView, kHICoordSpace72DPIGlobal, NULL ); | |
e6c3d3e6 SC |
2319 | pt->h = p.x; |
2320 | pt->v = p.y; | |
2321 | #else | |
2322 | QDLocalToGlobalPoint( GetWindowPort(window), pt ) ; | |
2323 | #endif | |
2324 | } | |
54ce9ebb | 2325 | |
b6ed2b86 | 2326 | #endif // wxUSE_GUI |