1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Various utilities
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // Note: this is done in utilscmn.cpp now.
14 // #pragma implementation
15 // #pragma implementation "utils.h"
21 #include "wx/mac/uma.h"
31 // defined in unix/utilsunx.cpp for Mac OS X
33 // get full hostname (with domain name if possible)
34 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
36 return wxGetHostName(buf
, maxSize
);
39 // Get hostname only (without domain name)
40 bool wxGetHostName(char *buf
, int maxSize
)
46 // Get user ID e.g. jacs
47 bool wxGetUserId(char *buf
, int maxSize
)
53 const wxChar
* wxGetHomeDir(wxString
*pstr
)
55 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
56 return pstr
->c_str() ;
61 // Get user name e.g. AUTHOR
62 bool wxGetUserName(char *buf
, int maxSize
)
68 int wxKill(long pid
, int sig
)
75 // Execute a program in an Interactive Shell
77 bool wxShell(const wxString
& command
)
83 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
84 long wxGetFreeMemory()
90 void wxSleep(int nSecs
)
95 // Consume all events until no more left
100 // Output a debug message, in a system dependent fashion.
101 void wxDebugMsg(const char *fmt
...)
104 static char buffer
[512];
106 if (!wxTheApp
->GetWantDebugOutput())
111 // wvsprintf(buffer,fmt,ap) ;
112 // TODO: output buffer
117 // Non-fatal error: pop up message box and (possibly) continue
118 void wxError(const wxString
& msg
, const wxString
& title
)
124 // Fatal error: pop up message box and abort
125 void wxFatalError(const wxString
& msg
, const wxString
& title
)
137 int wxGetOsVersion(int *majorVsn
, int *minorVsn
)
143 // Reading and writing resources (eg WIN.INI, .Xdefaults)
145 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
151 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
154 sprintf(buf
, "%.4f", value
);
155 return wxWriteResource(section
, entry
, buf
, file
);
158 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
161 sprintf(buf
, "%ld", value
);
162 return wxWriteResource(section
, entry
, buf
, file
);
165 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
168 sprintf(buf
, "%d", value
);
169 return wxWriteResource(section
, entry
, buf
, file
);
172 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
178 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
181 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
184 *value
= (float)strtod(s
, NULL
);
191 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
194 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
197 *value
= strtol(s
, NULL
, 10);
204 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
207 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
210 *value
= (int)strtol(s
, NULL
, 10);
216 #endif // wxUSE_RESOURCES
218 int wxBusyCursorCount
= 0;
219 extern CursHandle gMacCurrentCursor
;
220 CursHandle gMacStoredActiveCursor
= NULL
;
222 // Set the cursor to the busy cursor for all windows
223 void wxBeginBusyCursor(wxCursor
*cursor
)
225 wxBusyCursorCount
++;
226 if (wxBusyCursorCount
== 1)
228 gMacStoredActiveCursor
= gMacCurrentCursor
;
229 ::SetCursor( *::GetCursor( watchCursor
) ) ;
237 // Restore cursor to normal
238 void wxEndBusyCursor()
240 if (wxBusyCursorCount
== 0)
243 wxBusyCursorCount
--;
244 if (wxBusyCursorCount
== 0)
246 if ( gMacStoredActiveCursor
)
247 ::SetCursor( *gMacStoredActiveCursor
) ;
251 ::SetCursor( GetQDGlobalsArrow( &MacArrow
) ) ;
253 gMacStoredActiveCursor
= NULL
;
257 // TRUE if we're between the above two calls
260 return (wxBusyCursorCount
> 0);
263 wxString
wxMacFindFolder( short vol
,
265 Boolean createFolder
)
271 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
274 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
276 strDir
= wxMacFSSpec2UnixFilename( &file
) + "/" ;
283 char *wxGetUserHome (const wxString
& user
)
290 // Check whether this window wants to process messages, e.g. Stop button
291 // in long calculations.
292 bool wxCheckForInterrupt(wxWindow
*wnd
)
298 void wxGetMousePosition( int* x
, int* y
)
303 LocalToGlobal( &pt
) ;
308 // Return TRUE if we have a colour display
309 bool wxColourDisplay()
314 // Returns depth of screen
318 SetRect(&globRect
, -32760, -32760, 32760, 32760);
319 GDHandle theMaxDevice
;
322 theMaxDevice
= GetMaxDevice(&globRect
);
323 if (theMaxDevice
!= nil
)
324 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
329 // Get size of display
330 void wxDisplaySize(int *width
, int *height
)
333 GetQDGlobalsScreenBits( &screenBits
);
335 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
336 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
339 GetThemeMenuBarHeight( &mheight
) ;
342 *height
-= LMGetMBarHeight() ;
346 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
348 return wxGenericFindWindowAtPoint(pt
);