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" 
  34 // defined in unix/utilsunx.cpp for Mac OS X 
  36 // get full hostname (with domain name if possible) 
  37 bool wxGetFullHostName(wxChar 
*buf
, int maxSize
) 
  39     return wxGetHostName(buf
, maxSize
); 
  42 // Get hostname only (without domain name) 
  43 bool wxGetHostName(char *buf
, int maxSize
) 
  45         // Gets Chooser name of user by examining a System resource. 
  47         const short kComputerNameID 
= -16413; 
  49         short oldResFile 
= CurResFile() ; 
  51         StringHandle chooserName 
= (StringHandle
)::GetString(kComputerNameID
); 
  52         UseResFile(oldResFile
); 
  54         if (chooserName 
&& *chooserName
) 
  56           int length 
= (*chooserName
)[0] ; 
  57           if ( length 
+ 1 > maxSize 
) 
  59             length 
= maxSize 
- 1 ; 
  61           strncpy( buf 
, (char*) &(*chooserName
)[1] , length 
) ; 
  70 // Get user ID e.g. jacs 
  71 bool wxGetUserId(char *buf
, int maxSize
) 
  73   return wxGetUserName( buf 
, maxSize 
) ; 
  76 const wxChar
* wxGetHomeDir(wxString 
*pstr
) 
  78         *pstr 
= wxMacFindFolder(  (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder 
) ; 
  79         return pstr
->c_str() ; 
  82 // Get user name e.g. AUTHOR 
  83 bool wxGetUserName(char *buf
, int maxSize
) 
  85         // Gets Chooser name of user by examining a System resource. 
  87         const short kChooserNameID 
= -16096; 
  89         short oldResFile 
= CurResFile() ; 
  91         StringHandle chooserName 
= (StringHandle
)::GetString(kChooserNameID
); 
  92         UseResFile(oldResFile
); 
  94         if (chooserName 
&& *chooserName
) 
  96           int length 
= (*chooserName
)[0] ; 
  97           if ( length 
+ 1 > maxSize 
) 
  99             length 
= maxSize 
- 1 ; 
 101           strncpy( buf 
, (char*) &(*chooserName
)[1] , length 
) ; 
 110 int wxKill(long pid
, wxSignal sig
) 
 117 // Execute a program in an Interactive Shell 
 119 bool wxShell(const wxString
& command
) 
 125 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) 
 126 long wxGetFreeMemory() 
 131 void wxUsleep(unsigned long milliseconds
) 
 133                 clock_t start 
= clock() ; 
 137                 } while( clock() - start 
< milliseconds 
/ CLOCKS_PER_SEC 
) ; 
 140 void wxSleep(int nSecs
) 
 142     wxUsleep(1000*nSecs
); 
 145 // Consume all events until no more left 
 150 // Output a debug message, in a system dependent fashion. 
 151 void wxDebugMsg(const char *fmt 
...) 
 154   static char buffer
[512]; 
 156   if (!wxTheApp
->GetWantDebugOutput()) 
 161   vsprintf(buffer
,fmt
,ap
) ; 
 162   strcat(buffer
,";g") ; 
 164   DebugStr((unsigned char*) buffer
) ; 
 169 // Non-fatal error: pop up message box and (possibly) continue 
 170 void wxError(const wxString
& msg
, const wxString
& title
) 
 172   wxSprintf(wxBuffer
, wxT("%s\nContinue?"), WXSTRINGCAST msg
); 
 173   if (wxMessageBox(wxBuffer
, title
, wxYES_NO
) == wxID_NO 
) 
 177 // Fatal error: pop up message box and abort 
 178 void wxFatalError(const wxString
& msg
, const wxString
& title
) 
 180   wxSprintf(wxBuffer
, wxT("%s: %s"), WXSTRINGCAST title
, WXSTRINGCAST msg
); 
 181   wxMessageBox(wxBuffer
); 
 184 #endif // !__DARWIN__ 
 192 int wxGetOsVersion(int *majorVsn
, int *minorVsn
) 
 195   Gestalt(gestaltSystemVersion
, &theSystem
) ; 
 196   *minorVsn 
= (theSystem 
& 0xFF ) ; 
 197   *majorVsn 
= (theSystem 
>> 8 ) ; // are there x-platform conventions ? 
 201 // Reading and writing resources (eg WIN.INI, .Xdefaults) 
 203 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
) 
 209 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
) 
 212   sprintf(buf
, "%.4f", value
); 
 213   return wxWriteResource(section
, entry
, buf
, file
); 
 216 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
) 
 219   sprintf(buf
, "%ld", value
); 
 220   return wxWriteResource(section
, entry
, buf
, file
); 
 223 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
) 
 226   sprintf(buf
, "%d", value
); 
 227   return wxWriteResource(section
, entry
, buf
, file
); 
 230 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
) 
 236 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
) 
 239   bool succ 
= wxGetResource(section
, entry
, (char **)&s
, file
); 
 242     *value 
= (float)strtod(s
, NULL
); 
 249 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
) 
 252   bool succ 
= wxGetResource(section
, entry
, (char **)&s
, file
); 
 255     *value 
= strtol(s
, NULL
, 10); 
 262 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
) 
 265   bool succ 
= wxGetResource(section
, entry
, (char **)&s
, file
); 
 268     *value 
= (int)strtol(s
, NULL
, 10); 
 274 #endif // wxUSE_RESOURCES 
 276 int wxBusyCursorCount 
= 0; 
 277 extern CursHandle       gMacCurrentCursor 
; 
 278 CursHandle                      gMacStoredActiveCursor 
= NULL 
; 
 280 // Set the cursor to the busy cursor for all windows 
 281 void wxBeginBusyCursor(wxCursor 
*cursor
) 
 283   wxBusyCursorCount 
++; 
 284   if (wxBusyCursorCount 
== 1) 
 286         gMacStoredActiveCursor 
= gMacCurrentCursor 
; 
 287                 ::SetCursor( *::GetCursor( watchCursor 
) ) ; 
 295 // Restore cursor to normal 
 296 void wxEndBusyCursor() 
 298   if (wxBusyCursorCount 
== 0) 
 301   wxBusyCursorCount 
--; 
 302   if (wxBusyCursorCount 
== 0) 
 304     if ( gMacStoredActiveCursor 
) 
 305         ::SetCursor( *gMacStoredActiveCursor 
) ; 
 309         ::SetCursor( GetQDGlobalsArrow( &MacArrow 
) ) ; 
 311         gMacStoredActiveCursor 
= NULL 
; 
 315 // TRUE if we're between the above two calls 
 318   return (wxBusyCursorCount 
> 0); 
 322 wxString 
wxMacFindFolder( short                                         vol
, 
 324                                                                  Boolean                                createFolder
) 
 330         if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
) 
 333                 if ( FSMakeFSSpec( vRefNum 
, dirID 
, "\p" , &file 
) == noErr 
) 
 335                         strDir 
= wxMacFSSpec2MacFilename( &file 
) + ":" ; 
 343 char *wxGetUserHome (const wxString
& user
) 
 350 bool wxGetDiskSpace(const wxString
& path
, wxLongLong 
*pTotal
, wxLongLong 
*pFree
) 
 360     int pos 
= p
.Find(':') ; 
 361     if ( pos 
!= wxNOT_FOUND 
) { 
 370     wxMacStringToPascal( p  
, volumeName 
) ; 
 371     OSErr err 
= XGetVolumeInfoNoName( volumeName 
, 0 , &pb 
) ; 
 372     if ( err 
== noErr 
) { 
 374         (*pTotal
) = wxLongLong( pb
.ioVTotalBytes 
) ; 
 377         (*pFree
) = wxLongLong( pb
.ioVFreeBytes 
) ; 
 381     return err 
== noErr 
; 
 384 // Check whether this window wants to process messages, e.g. Stop button 
 385 // in long calculations. 
 386 bool wxCheckForInterrupt(wxWindow 
*wnd
) 
 392 void wxGetMousePosition( int* x
, int* y 
) 
 397     LocalToGlobal( &pt 
) ; 
 402 // Return TRUE if we have a colour display 
 403 bool wxColourDisplay() 
 408 // Returns depth of screen 
 412         SetRect(&globRect
, -32760, -32760, 32760, 32760); 
 413         GDHandle        theMaxDevice
; 
 416         theMaxDevice 
= GetMaxDevice(&globRect
); 
 417         if (theMaxDevice 
!= nil
) 
 418                 theDepth 
= (**(**theMaxDevice
).gdPMap
).pixelSize
; 
 423 // Get size of display 
 424 void wxDisplaySize(int *width
, int *height
) 
 427         GetQDGlobalsScreenBits( &screenBits 
); 
 429     *width 
= screenBits
.bounds
.right 
- screenBits
.bounds
.left  
; 
 430     *height 
= screenBits
.bounds
.bottom 
- screenBits
.bounds
.top 
; 
 433         GetThemeMenuBarHeight( &mheight 
) ; 
 436      *height 
-= LMGetMBarHeight() ; 
 440 void wxDisplaySizeMM(int *width
, int *height
) 
 442    wxDisplaySize(width
, height
); 
 445 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
) 
 447     // This is supposed to return desktop dimensions minus any window 
 448     // manager panels, menus, taskbars, etc.  If there is a way to do that 
 449     // for this platform please fix this function, otherwise it defaults 
 450     // to the entire desktop. 
 453     wxDisplaySize(width
, height
); 
 456 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
) 
 458     return wxGenericFindWindowAtPoint(pt
);