]>
git.saurik.com Git - wxWidgets.git/blob - src/common/utilscmn.cpp
488be4bec8a6a292ba88c0b6ed4852c0f23a32e9
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     Miscellaneous utility functions and classes 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) 1998 Julian Smart 
   9 // Licence:     wxWindows license 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  21     #pragma implementation "utils.h" 
  24 // For compilers that support precompilation, includes "wx.h". 
  25 #include "wx/wxprec.h" 
  33     #include "wx/string.h" 
  40         #include "wx/window.h" 
  43         #include "wx/msgdlg.h" 
  44         #include "wx/textdlg.h" 
  45         #include "wx/textctrl.h"    // for wxTE_PASSWORD 
  47             #include "wx/menuitem.h" 
  54 #include "wx/process.h" 
  55 #include "wx/txtstrm.h" 
  63 #if !defined(__WATCOMC__) 
  64     #if !(defined(_MSC_VER) && (_MSC_VER > 800)) 
  70     #include "wx/colordlg.h" 
  71     #include "wx/fontdlg.h" 
  72     #include "wx/notebook.h" 
  74     #include "wx/statusbr.h" 
  75     #include "wx/toolbar.h" 
  81     #include <sys/types.h> 
  90     #include "wx/msw/private.h" 
  93 // ---------------------------------------------------------------------------- 
  95 // ---------------------------------------------------------------------------- 
  98     static wxWindow 
*wxFindWindowByLabel1(const wxString
& title
, wxWindow 
*parent
); 
  99     static wxWindow 
*wxFindWindowByName1 (const wxString
& title
, wxWindow 
*parent
); 
 102 // ============================================================================ 
 104 // ============================================================================ 
 106 // ---------------------------------------------------------------------------- 
 108 // ---------------------------------------------------------------------------- 
 110 #if defined(__WXMAC__) && !defined(__DARWIN__) 
 111 int strcasecmp(const char *str_1
, const char *str_2
) 
 113   register char c1
, c2
; 
 115     c1 
= tolower(*str_1
++); 
 116     c2 
= tolower(*str_2
++); 
 117   } while ( c1 
&& (c1 
== c2
) ); 
 122 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
) 
 125   register char c1
, c2
; 
 128     c1 
= tolower(*str_1
++); 
 129     c2 
= tolower(*str_2
++); 
 139 #endif // __WXMAC__ && !__DARWIN__ 
 141 #if defined( __VMS__ ) && ( __VMS_VER < 70000000 ) 
 142 // we have no strI functions under VMS, therefore I have implemented 
 143 // an inefficient but portable version: convert copies of strings to lowercase 
 144 // and then use the normal comparison 
 145 static void myLowerString(char *s
) 
 148     if(isalpha(*s
)) *s 
= (char)tolower(*s
); 
 153 int strcasecmp(const char *str_1
, const char *str_2
) 
 155   char *temp1 
= new char[strlen(str_1
)+1]; 
 156   char *temp2 
= new char[strlen(str_2
)+1]; 
 159   myLowerString(temp1
); 
 160   myLowerString(temp2
); 
 162   int result 
= wxStrcmp(temp1
,temp2
); 
 169 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
) 
 171   char *temp1 
= new char[strlen(str_1
)+1]; 
 172   char *temp2 
= new char[strlen(str_2
)+1]; 
 175   myLowerString(temp1
); 
 176   myLowerString(temp2
); 
 178   int result 
= strncmp(temp1
,temp2
,maxchar
); 
 186 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__) 
 190 #define strcasecmp stricmp 
 191 #define strncasecmp strnicmp 
 193 #define strcasecmp _stricmp 
 194 #define strncasecmp _strnicmp 
 201 #define strcasecmp stricmp 
 202 #define strncasecmp strnicmp 
 205 // This declaration is missing in SunOS! 
 206 // (Yes, I know it is NOT ANSI-C but its in BSD libc) 
 207 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__) 
 210   int strcasecmp (const char *, const char *); 
 211   int strncasecmp (const char *, const char *, size_t); 
 214 #endif  /* __WXMSW__ */ 
 217 #define strcasecmp stricmp 
 218 #define strncasecmp strnicmp 
 222 #define strcasecmp stricmp 
 223 #define strncasecmp strnicmp 
 227 copystring (const wxChar 
*s
) 
 229   if (s 
== NULL
) s 
= wxT(""); 
 230   size_t len 
= wxStrlen (s
) + 1; 
 232   wxChar 
*news 
= new wxChar
[len
]; 
 233   memcpy (news
, s
, len 
* sizeof(wxChar
));    // Should be the fastest 
 239 static long wxCurrentId 
= 100; 
 244   return wxCurrentId
++; 
 248 wxGetCurrentId(void) { return wxCurrentId
; } 
 251 wxRegisterId (long id
) 
 253   if (id 
>= wxCurrentId
) 
 254     wxCurrentId 
= id 
+ 1; 
 258 StringToFloat (const wxChar 
*s
, float *number
) 
 260   if (s 
&& *s 
&& number
) 
 261     *number 
= (float) wxStrtod (s
, (wxChar 
**) NULL
); 
 265 StringToDouble (const wxChar 
*s
, double *number
) 
 267   if (s 
&& *s 
&& number
) 
 268     *number 
= wxStrtod (s
, (wxChar 
**) NULL
); 
 272 FloatToString (float number
, const wxChar 
*fmt
) 
 274   static wxChar buf
[256]; 
 276   wxSprintf (buf
, fmt
, number
); 
 281 DoubleToString (double number
, const wxChar 
*fmt
) 
 283   static wxChar buf
[256]; 
 285   wxSprintf (buf
, fmt
, number
); 
 290 StringToInt (const wxChar 
*s
, int *number
) 
 292   if (s 
&& *s 
&& number
) 
 293     *number 
= (int) wxStrtol (s
, (wxChar 
**) NULL
, 10); 
 297 StringToLong (const wxChar 
*s
, long *number
) 
 299   if (s 
&& *s 
&& number
) 
 300     *number 
= wxStrtol (s
, (wxChar 
**) NULL
, 10); 
 304 IntToString (int number
) 
 306   static wxChar buf
[20]; 
 308   wxSprintf (buf
, wxT("%d"), number
); 
 313 LongToString (long number
) 
 315   static wxChar buf
[20]; 
 317   wxSprintf (buf
, wxT("%ld"), number
); 
 321 // Array used in DecToHex conversion routine. 
 322 static wxChar hexArray
[] = wxT("0123456789ABCDEF"); 
 324 // Convert 2-digit hex number to decimal 
 325 int wxHexToDec(const wxString
& buf
) 
 327   int firstDigit
, secondDigit
; 
 329   if (buf
.GetChar(0) >= wxT('A')) 
 330     firstDigit 
= buf
.GetChar(0) - wxT('A') + 10; 
 332     firstDigit 
= buf
.GetChar(0) - wxT('0'); 
 334   if (buf
.GetChar(1) >= wxT('A')) 
 335     secondDigit 
= buf
.GetChar(1) - wxT('A') + 10; 
 337     secondDigit 
= buf
.GetChar(1) - wxT('0'); 
 339   return (firstDigit 
& 0xF) * 16 + (secondDigit 
& 0xF ); 
 342 // Convert decimal integer to 2-character hex string 
 343 void wxDecToHex(int dec
, wxChar 
*buf
) 
 345   int firstDigit 
= (int)(dec
/16.0); 
 346   int secondDigit 
= (int)(dec 
- (firstDigit
*16.0)); 
 347   buf
[0] = hexArray
[firstDigit
]; 
 348   buf
[1] = hexArray
[secondDigit
]; 
 352 // Convert decimal integer to 2-character hex string 
 353 wxString 
wxDecToHex(int dec
) 
 356     wxDecToHex(dec
, buf
); 
 357     return wxString(buf
); 
 360 // Match a string INDEPENDENT OF CASE 
 362 StringMatch (const char *str1
, const char *str2
, bool subString
, bool exact
) 
 364   if (str1 
== NULL 
|| str2 
== NULL
) 
 371       int len1 
= strlen (str1
); 
 372       int len2 
= strlen (str2
); 
 375       // Search for str1 in str2 
 376       // Slow .... but acceptable for short strings 
 377       for (i 
= 0; i 
<= len2 
- len1
; i
++) 
 379           if (strncasecmp (str1
, str2 
+ i
, len1
) == 0) 
 385       if (strcasecmp (str1
, str2
) == 0) 
 390       int len1 
= strlen (str1
); 
 391       int len2 
= strlen (str2
); 
 393       if (strncasecmp (str1
, str2
, wxMin (len1
, len2
)) == 0) 
 400 // Return the current date/time 
 404   time_t now 
= time((time_t *) NULL
); 
 405   char *date 
= ctime(&now
); 
 407   return wxString(date
); 
 414 // ---------------------------------------------------------------------------- 
 415 // Menu accelerators related functions 
 416 // ---------------------------------------------------------------------------- 
 418 wxChar 
*wxStripMenuCodes(const wxChar 
*in
, wxChar 
*out
) 
 420     wxString s 
= wxMenuItem::GetLabelFromText(in
); 
 423         // go smash their buffer if it's not big enough - I love char * params 
 424         memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
)); 
 434 wxString 
wxStripMenuCodes(const wxString
& in
) 
 438     size_t len 
= in
.length(); 
 441     for ( size_t n 
= 0; n 
< len
; n
++ ) 
 446             // skip it, it is used to introduce the accel char (or to quote 
 447             // itself in which case it should still be skipped): note that it 
 448             // can't be the last character of the string 
 451                 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str()); 
 455                 // use the next char instead 
 459         else if ( ch 
== _T('\t') ) 
 461             // everything after TAB is accel string, exit the loop 
 471 #endif // wxUSE_MENUS 
 473 // ---------------------------------------------------------------------------- 
 474 // Window search functions 
 475 // ---------------------------------------------------------------------------- 
 478  * If parent is non-NULL, look through children for a label or title 
 479  * matching the specified string. If NULL, look through all top-level windows. 
 484 wxFindWindowByLabel (const wxString
& title
, wxWindow 
* parent
) 
 488         return wxFindWindowByLabel1(title
, parent
); 
 492         for ( wxWindowList::Node 
* node 
= wxTopLevelWindows
.GetFirst(); 
 494               node 
= node
->GetNext() ) 
 496             wxWindow 
*win 
= node
->GetData(); 
 497             wxWindow 
*retwin 
= wxFindWindowByLabel1 (title
, win
); 
 503     return (wxWindow 
*) NULL
; 
 508 wxFindWindowByLabel1 (const wxString
& title
, wxWindow 
* parent
) 
 512         if (parent
->GetLabel() == title
) 
 518         for ( wxWindowList::Node 
* node 
= parent
->GetChildren().GetFirst(); 
 520               node 
= node
->GetNext() ) 
 522             wxWindow 
*win 
= (wxWindow 
*)node
->GetData(); 
 523             wxWindow 
*retwin 
= wxFindWindowByLabel1 (title
, win
); 
 530     return (wxWindow 
*) NULL
;                        // Not found 
 534  * If parent is non-NULL, look through children for a name 
 535  * matching the specified string. If NULL, look through all top-level windows. 
 540 wxFindWindowByName (const wxString
& title
, wxWindow 
* parent
) 
 544         return wxFindWindowByName1 (title
, parent
); 
 548         for ( wxWindowList::Node 
* node 
= wxTopLevelWindows
.GetFirst(); 
 550               node 
= node
->GetNext() ) 
 552             wxWindow 
*win 
= node
->GetData(); 
 553             wxWindow 
*retwin 
= wxFindWindowByName1 (title
, win
); 
 560     // Failed? Try by label instead. 
 561     return wxFindWindowByLabel(title
, parent
); 
 566 wxFindWindowByName1 (const wxString
& title
, wxWindow 
* parent
) 
 570             if ( parent
->GetName() == title 
) 
 576       for (wxNode 
* node 
= parent
->GetChildren().First (); node
; node 
= node
->Next ()) 
 578           wxWindow 
*win 
= (wxWindow 
*) node
->Data (); 
 579           wxWindow 
*retwin 
= wxFindWindowByName1 (title
, win
); 
 586   return (wxWindow 
*) NULL
;                        // Not found 
 590 // Returns menu item id or -1 if none. 
 592 wxFindMenuItemId (wxFrame 
* frame
, const wxString
& menuString
, const wxString
& itemString
) 
 595   wxMenuBar 
*menuBar 
= frame
->GetMenuBar (); 
 597       return menuBar
->FindMenuItem (menuString
, itemString
); 
 598 #endif // wxUSE_MENUS 
 603 // Try to find the deepest child that contains 'pt'. 
 604 // We go backwards, to try to allow for controls that are spacially 
 605 // within other controls, but are still siblings (e.g. buttons within 
 606 // static boxes). Static boxes are likely to be created _before_ controls 
 607 // that sit inside them. 
 608 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
) 
 613     // Hack for wxNotebook case: at least in wxGTK, all pages 
 614     // claim to be shown, so we must only deal with the selected one. 
 616     if (win
->IsKindOf(CLASSINFO(wxNotebook
))) 
 618       wxNotebook
* nb 
= (wxNotebook
*) win
; 
 619       int sel 
= nb
->GetSelection(); 
 622         wxWindow
* child 
= nb
->GetPage(sel
); 
 623         wxWindow
* foundWin 
= wxFindWindowAtPoint(child
, pt
); 
 632     else if (win->IsKindOf(CLASSINFO(wxFrame))) 
 634       // Pseudo-children that may not be mentioned in the child list 
 635       wxWindowList extraChildren; 
 636       wxFrame* frame = (wxFrame*) win; 
 637       if (frame->GetStatusBar()) 
 638         extraChildren.Append(frame->GetStatusBar()); 
 639       if (frame->GetToolBar()) 
 640         extraChildren.Append(frame->GetToolBar()); 
 642       wxNode* node = extraChildren.First(); 
 645           wxWindow* child = (wxWindow*) node->Data(); 
 646           wxWindow* foundWin = wxFindWindowAtPoint(child, pt); 
 654     wxNode
* node 
= win
->GetChildren().Last(); 
 657         wxWindow
* child 
= (wxWindow
*) node
->Data(); 
 658         wxWindow
* foundWin 
= wxFindWindowAtPoint(child
, pt
); 
 661         node 
= node
->Previous(); 
 664     wxPoint pos 
= win
->GetPosition(); 
 665     wxSize sz 
= win
->GetSize(); 
 666     if (win
->GetParent()) 
 668         pos 
= win
->GetParent()->ClientToScreen(pos
); 
 671     wxRect 
rect(pos
, sz
); 
 678 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
) 
 680     // Go backwards through the list since windows 
 681     // on top are likely to have been appended most 
 683     wxNode
* node 
= wxTopLevelWindows
.Last(); 
 686         wxWindow
* win 
= (wxWindow
*) node
->Data(); 
 687         wxWindow
* found 
= wxFindWindowAtPoint(win
, pt
); 
 690         node 
= node
->Previous(); 
 698 On Fri, 21 Jul 1995, Paul Craven wrote: 
 700 > Is there a way to find the path of running program's executable? I can get 
 701 > my home directory, and the current directory, but I don't know how to get the 
 702 > executable directory. 
 705 The code below (warty as it is), does what you want on most Unix, 
 706 DOS, and Mac platforms (it's from the ALS Prolog main). 
 708 || Ken Bowen      Applied Logic Systems, Inc.         PO Box 180, 
 709 ||====            Voice:  +1 (617)965-9191            Newton Centre, 
 710 ||                FAX:    +1 (617)965-1636            MA  02159  USA 
 711                   Email:  ken@als.com        WWW: http://www.als.com 
 712 ------------------------------------------------------------------------ 
 715 // This code is commented out but it may be integrated with wxWin at 
 716 // a later date, after testing. Thanks Ken! 
 719 /*--------------------------------------------------------------------* 
 720  | whereami is given a filename f in the form:  whereami(argv[0]) 
 721  | It returns the directory in which the executable file (containing 
 722  | this code [main.c] ) may be found.  A dot will be returned to indicate 
 723  | the current directory. 
 724  *--------------------------------------------------------------------*/ 
 730     register char *cutoff 
= NULL
;        /* stifle -Wall */ 
 737      * See if the file is accessible either through the current directory 
 738      * or through an absolute path. 
 741     if (access(name
, R_OK
) == 0) { 
 743         /*-------------------------------------------------------------* 
 744          * The file was accessible without any other work.  But the current 
 745          * working directory might change on us, so if it was accessible 
 746          * through the cwd, then we should get it for later accesses. 
 747          *-------------------------------------------------------------*/ 
 750         if (!absolute_pathname(name
)) { 
 751 #if defined(__DOS__) || defined(__WIN32__) 
 757             if (*(name 
+ 1) == ':') { 
 758                 if (*name 
>= 'a' && *name 
<= 'z') 
 759                     drive 
= (int) (*name 
- 'a' + 1); 
 761                     drive 
= (int) (*name 
- 'A' + 1); 
 763                 *newrbuf
++ = *(name 
+ 1); 
 764                 *newrbuf
++ = DIR_SEPARATOR
; 
 768                 *newrbuf
++ = DIR_SEPARATOR
; 
 770             if (getcwd(newrbuf
, drive
) == 0) {        /* } */ 
 772             if (getcwd(newrbuf
, 1024) == 0) {        /* } */ 
 776             if (getwd(imagedir
) == 0) {                /* } */ 
 777 #else  /* !HAVE_GETWD */ 
 778             if (getcwd(imagedir
, 1024) == 0) { 
 779 #endif /* !HAVE_GETWD */ 
 781                 fatal_error(FE_GETCWD
, 0); 
 783             for (; *t
; t
++)        /* Set t to end of buffer */ 
 785             if (*(t 
- 1) == DIR_SEPARATOR
)        /* leave slash if already 
 790                 cutoff 
= t
;        /* otherwise put one in */ 
 791                 *t
++ = DIR_SEPARATOR
; 
 794 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__)) 
 796                 (*t
++ = DIR_SEPARATOR
); 
 799         /*-------------------------------------------------------------* 
 800          * Copy the rest of the string and set the cutoff if it was not 
 801          * already set.  If the first character of name is a slash, cutoff 
 802          * is not presently set but will be on the first iteration of the 
 804          *-------------------------------------------------------------*/ 
 806         for ((*name 
== DIR_SEPARATOR 
? (s 
= name
+1) : (s 
= name
));;) { 
 807             if (*s 
== DIR_SEPARATOR
) 
 816         /*-------------------------------------------------------------* 
 817          * Get the path list from the environment.  If the path list is 
 818          * inaccessible for any reason, leave with fatal error. 
 819          *-------------------------------------------------------------*/ 
 822         if ((s 
= getenv("Commands")) == (char *) 0) 
 824         if ((s 
= getenv("PATH")) == (char *) 0) 
 826             fatal_error(FE_PATH
, 0); 
 829          * Copy path list into ebuf and set the source pointer to the 
 830          * beginning of this buffer. 
 838             while (*s 
&& *s 
!= PATH_SEPARATOR
) 
 840             if (t 
> imagedir 
&& *(t 
- 1) == DIR_SEPARATOR
) 
 841                 ;                /* do nothing -- slash already is in place */ 
 843                 *t
++ = DIR_SEPARATOR
;        /* put in the slash */ 
 844             cutoff 
= t 
- 1;        /* set cutoff */ 
 846             if (access(imagedir
, R_OK
) == 0) 
 850                 s
++;                /* advance source pointer */ 
 852                 fatal_error(FE_INFND
, 0); 
 857     /*-------------------------------------------------------------* 
 858      | At this point the full pathname should exist in imagedir and 
 859      | cutoff should be set to the final slash.  We must now determine 
 860      | whether the file name is a symbolic link or not and chase it down 
 861      | if it is.  Note that we reuse ebuf for getting the link. 
 862      *-------------------------------------------------------------*/ 
 865     while ((cc 
= readlink(imagedir
, ebuf
, 512)) != -1) { 
 868         if (*s 
== DIR_SEPARATOR
) { 
 875             if (*s 
== DIR_SEPARATOR
) 
 876                 cutoff 
= t
;        /* mark the last slash seen */ 
 877             if (!(*t
++ = *s
++))        /* copy the character */ 
 882 #endif /* HAVE_SYMLINK */ 
 884     strcpy(imagename
, cutoff 
+ 1);        /* keep the image name */ 
 885     *(cutoff 
+ 1) = 0;                /* chop off the filename part */ 
 892 // ---------------------------------------------------------------------------- 
 894 // ---------------------------------------------------------------------------- 
 897  * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp 
 898  * since otherwise the generic code may be pulled in unnecessarily. 
 903 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
, 
 904                  wxWindow 
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) ) 
 906     wxMessageDialog 
dialog(parent
, message
, caption
, style
); 
 908     int ans 
= dialog
.ShowModal(); 
 921     wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") ); 
 926 #endif // wxUSE_MSGDLG 
 930 wxString 
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
, 
 931                         const wxString
& defaultValue
, wxWindow 
*parent
, 
 932                         int x
, int y
, bool WXUNUSED(centre
) ) 
 935     wxTextEntryDialog 
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
)); 
 936     if (dialog
.ShowModal() == wxID_OK
) 
 938         str 
= dialog
.GetValue(); 
 944 wxString 
wxGetPasswordFromUser(const wxString
& message
, 
 945                                const wxString
& caption
, 
 946                                const wxString
& defaultValue
, 
 950     wxTextEntryDialog 
dialog(parent
, message
, caption
, defaultValue
, 
 951                              wxOK 
| wxCANCEL 
| wxTE_PASSWORD
); 
 952     if ( dialog
.ShowModal() == wxID_OK 
) 
 954         str 
= dialog
.GetValue(); 
 960 #endif // wxUSE_TEXTDLG 
 964 wxColour 
wxGetColourFromUser(wxWindow 
*parent
, const wxColour
& colInit
) 
 967     data
.SetChooseFull(TRUE
); 
 970         data
.SetColour((wxColour 
&)colInit
); // const_cast 
 974     wxColourDialog 
dialog(parent
, &data
); 
 975     if ( dialog
.ShowModal() == wxID_OK 
) 
 977         colRet 
= dialog
.GetColourData().GetColour(); 
 979     //else: leave it invalid 
 984 #endif // wxUSE_COLOURDLG 
 988 wxFont 
wxGetFontFromUser(wxWindow 
*parent
, const wxFont
& fontInit
) 
 993         data
.SetInitialFont(fontInit
); 
 997     wxFontDialog 
dialog(parent
, &data
); 
 998     if ( dialog
.ShowModal() == wxID_OK 
) 
1000         fontRet 
= dialog
.GetFontData().GetChosenFont(); 
1002     //else: leave it invalid 
1007 #endif // wxUSE_FONTDLG 
1008 // ---------------------------------------------------------------------------- 
1009 // missing C RTL functions (FIXME shouldn't be here at all) 
1010 // ---------------------------------------------------------------------------- 
1013 #if __MSL__ < 0x7000 
1014 char *strdup(const char *s
) 
1016         return strcpy( (char*) malloc( strlen( s 
) + 1 ) , s 
) ; 
1019 int isascii( int c 
) 
1021         return ( c 
>= 0 && c 
< 128 ) ; 
1023 #endif // __MWERKS__ 
1025 // ---------------------------------------------------------------------------- 
1026 // wxSafeYield and supporting functions 
1027 // ---------------------------------------------------------------------------- 
1029 void wxEnableTopLevelWindows(bool enable
) 
1031     wxWindowList::Node 
*node
; 
1032     for ( node 
= wxTopLevelWindows
.GetFirst(); node
; node 
= node
->GetNext() ) 
1033         node
->GetData()->Enable(enable
); 
1036 wxWindowDisabler::wxWindowDisabler(wxWindow 
*winToSkip
) 
1038     // remember the top level windows which were already disabled, so that we 
1039     // don't reenable them later 
1040     m_winDisabled 
= NULL
; 
1042     wxWindowList::Node 
*node
; 
1043     for ( node 
= wxTopLevelWindows
.GetFirst(); node
; node 
= node
->GetNext() ) 
1045         wxWindow 
*winTop 
= node
->GetData(); 
1046         if ( winTop 
== winToSkip 
) 
1049         if ( winTop
->IsEnabled() ) 
1055             if ( !m_winDisabled 
) 
1057                 m_winDisabled 
= new wxWindowList
; 
1060             m_winDisabled
->Append(winTop
); 
1065 wxWindowDisabler::~wxWindowDisabler() 
1067     wxWindowList::Node 
*node
; 
1068     for ( node 
= wxTopLevelWindows
.GetFirst(); node
; node 
= node
->GetNext() ) 
1070         wxWindow 
*winTop 
= node
->GetData(); 
1071         if ( !m_winDisabled 
|| !m_winDisabled
->Find(winTop
) ) 
1075         //else: had been already disabled, don't reenable 
1078     delete m_winDisabled
; 
1081 // Yield to other apps/messages and disable user input to all windows except 
1083 bool wxSafeYield(wxWindow 
*win
) 
1085     wxWindowDisabler 
wd(win
); 
1087     bool rc 
= wxYield(); 
1092 // ---------------------------------------------------------------------------- 
1094 // ---------------------------------------------------------------------------- 
1096 // Don't synthesize KeyUp events holding down a key and producing KeyDown 
1097 // events with autorepeat. On by default and always on in wxMSW. wxGTK version 
1100 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) ) 
1102     return TRUE
;    // detectable auto-repeat is the only mode MSW supports 
1108 const wxChar 
*wxGetInstallPrefix() 
1112     if ( wxGetEnv(wxT("WX_PREFIX"), &prefix
) ) 
1113         return prefix
.c_str(); 
1115 #ifdef wxINSTALL_PREFIX 
1116     return wxT(wxINSTALL_PREFIX
); 
1122 wxString 
wxGetDataDir() 
1124     wxString format 
= wxGetInstallPrefix(); 
1125     format 
<<  wxFILE_SEP_PATH
 
1126            << wxT("share") << wxFILE_SEP_PATH
 
1127            << wxT("wx") << wxFILE_SEP_PATH
 
1130     dir
.Printf(format
.c_str(), wxMAJOR_VERSION
, wxMINOR_VERSION
); 
1135 // ---------------------------------------------------------------------------- 
1136 // network and user id functions 
1137 // ---------------------------------------------------------------------------- 
1139 // Get Full RFC822 style email address 
1140 bool wxGetEmailAddress(wxChar 
*address
, int maxSize
) 
1142     wxString email 
= wxGetEmailAddress(); 
1146     wxStrncpy(address
, email
, maxSize 
- 1); 
1147     address
[maxSize 
- 1] = wxT('\0'); 
1152 wxString 
wxGetEmailAddress() 
1156     wxString host 
= wxGetFullHostName(); 
1159         wxString user 
= wxGetUserId(); 
1162             email 
<< user 
<< wxT('@') << host
; 
1169 wxString 
wxGetUserId() 
1171     static const int maxLoginLen 
= 256; // FIXME arbitrary number 
1174     bool ok 
= wxGetUserId(buf
.GetWriteBuf(maxLoginLen
), maxLoginLen
); 
1175     buf
.UngetWriteBuf(); 
1183 wxString 
wxGetUserName() 
1185     static const int maxUserNameLen 
= 1024; // FIXME arbitrary number 
1188     bool ok 
= wxGetUserName(buf
.GetWriteBuf(maxUserNameLen
), maxUserNameLen
); 
1189     buf
.UngetWriteBuf(); 
1197 wxString 
wxGetHostName() 
1199     static const size_t hostnameSize 
= 257; 
1202     bool ok 
= wxGetHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
); 
1204     buf
.UngetWriteBuf(); 
1212 wxString 
wxGetFullHostName() 
1214     static const size_t hostnameSize 
= 257; 
1217     bool ok 
= wxGetFullHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
); 
1219     buf
.UngetWriteBuf(); 
1227 wxString 
wxGetHomeDir() 
1230     wxGetHomeDir(&home
); 
1237 wxString 
wxGetCurrentDir() 
1244         ok 
= getcwd(dir
.GetWriteBuf(len 
+ 1), len
) != NULL
; 
1245         dir
.UngetWriteBuf(); 
1249             if ( errno 
!= ERANGE 
) 
1251                 wxLogSysError(_T("Failed to get current directory")); 
1253                 return wxEmptyString
; 
1257                 // buffer was too small, retry with a larger one 
1269 // ---------------------------------------------------------------------------- 
1271 // ---------------------------------------------------------------------------- 
1273 // this is a private function because it hasn't a clean interface: the first 
1274 // array is passed by reference, the second by pointer - instead we have 2 
1275 // public versions of wxExecute() below 
1276 static long wxDoExecuteWithCapture(const wxString
& command
, 
1277                                    wxArrayString
& output
, 
1278                                    wxArrayString
* error
) 
1281     wxFAIL_MSG("Sorry, this version of wxExecute not implemented on WIN16."); 
1285     // create a wxProcess which will capture the output 
1286     wxProcess 
*process 
= new wxProcess
; 
1287     process
->Redirect(); 
1289     long rc 
= wxExecute(command
, TRUE 
/* sync */, process
); 
1294         wxInputStream
* is 
= process
->GetInputStream(); 
1295         wxCHECK_MSG( is
, -1, _T("if wxExecute() succeded, stream can't be NULL") ); 
1296         wxTextInputStream 
tis(*is
); 
1298         wxTextInputStream 
*tes 
= NULL
; 
1299         wxInputStream 
*es 
= NULL
; 
1302             es 
= process
->GetErrorStream(); 
1304             wxCHECK_MSG( es
, -1, _T("stderr can't be NULL") ); 
1306             tes 
= new wxTextInputStream(*es
); 
1314             if ( !is
->Eof() && is
->IsOk() ) 
1316                 wxString line 
= tis
.ReadLine(); 
1317                 if ( is
->LastError() ) 
1325             if ( error 
&& !es
->Eof() && es
->IsOk() ) 
1327                 wxString line 
= tes
->ReadLine(); 
1328                 if ( es
->LastError() ) 
1340 #endif // wxUSE_STREAMS 
1345 #endif // IO redirection supoprted 
1348 long wxExecute(const wxString
& command
, wxArrayString
& output
) 
1350     return wxDoExecuteWithCapture(command
, output
, NULL
); 
1353 long wxExecute(const wxString
& command
, 
1354                wxArrayString
& output
, 
1355                wxArrayString
& error
) 
1357     return wxDoExecuteWithCapture(command
, output
, &error
); 
1360 // ---------------------------------------------------------------------------- 
1361 // wxApp::Yield() wrappers for backwards compatibility 
1362 // ---------------------------------------------------------------------------- 
1367     return wxTheApp 
&& wxTheApp
->Yield(); 
1373 bool wxYieldIfNeeded() 
1376     return wxTheApp 
&& wxTheApp
->Yield(TRUE
);