1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/utilscmn.cpp
3 // Purpose: Miscellaneous utility functions and classes
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/string.h"
35 #include "wx/window.h"
38 #include "wx/msgdlg.h"
39 #include "wx/textdlg.h"
40 #include "wx/textctrl.h" // for wxTE_PASSWORD
42 #include "wx/menuitem.h"
48 #include "wx/apptrait.h"
50 #include "wx/process.h"
51 #include "wx/txtstrm.h"
53 #include "wx/mimetype.h"
54 #include "wx/config.h"
56 #if defined(__WXWINCE__) && wxUSE_DATETIME
57 #include "wx/datetime.h"
65 #if !wxONLY_WATCOM_EARLIER_THAN(1,4)
66 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
72 #include "wx/colordlg.h"
73 #include "wx/fontdlg.h"
74 #include "wx/notebook.h"
76 #include "wx/statusbr.h"
82 #include "wx/msw/wince/time.h"
86 #include "wx/mac/private.h"
88 #include "InternetConfig.h"
92 #if !defined(__MWERKS__) && !defined(__WXWINCE__)
93 #include <sys/types.h>
97 #if defined(__WXMSW__)
98 #include "wx/msw/private.h"
99 #include "wx/msw/registry.h"
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
108 // ============================================================================
110 // ============================================================================
112 #if WXWIN_COMPATIBILITY_2_4
115 copystring (const wxChar
*s
)
117 if (s
== NULL
) s
= wxEmptyString
;
118 size_t len
= wxStrlen (s
) + 1;
120 wxChar
*news
= new wxChar
[len
];
121 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
126 #endif // WXWIN_COMPATIBILITY_2_4
128 // ----------------------------------------------------------------------------
129 // String <-> Number conversions (deprecated)
130 // ----------------------------------------------------------------------------
132 #if WXWIN_COMPATIBILITY_2_4
134 WXDLLIMPEXP_DATA_BASE(const wxChar
*) wxFloatToStringStr
= wxT("%.2f");
135 WXDLLIMPEXP_DATA_BASE(const wxChar
*) wxDoubleToStringStr
= wxT("%.2f");
138 StringToFloat (const wxChar
*s
, float *number
)
140 if (s
&& *s
&& number
)
141 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
145 StringToDouble (const wxChar
*s
, double *number
)
147 if (s
&& *s
&& number
)
148 *number
= wxStrtod (s
, (wxChar
**) NULL
);
152 FloatToString (float number
, const wxChar
*fmt
)
154 static wxChar buf
[256];
156 wxSprintf (buf
, fmt
, number
);
161 DoubleToString (double number
, const wxChar
*fmt
)
163 static wxChar buf
[256];
165 wxSprintf (buf
, fmt
, number
);
170 StringToInt (const wxChar
*s
, int *number
)
172 if (s
&& *s
&& number
)
173 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
177 StringToLong (const wxChar
*s
, long *number
)
179 if (s
&& *s
&& number
)
180 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
184 IntToString (int number
)
186 static wxChar buf
[20];
188 wxSprintf (buf
, wxT("%d"), number
);
193 LongToString (long number
)
195 static wxChar buf
[20];
197 wxSprintf (buf
, wxT("%ld"), number
);
201 #endif // WXWIN_COMPATIBILITY_2_4
203 // Array used in DecToHex conversion routine.
204 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
206 // Convert 2-digit hex number to decimal
207 int wxHexToDec(const wxString
& buf
)
209 int firstDigit
, secondDigit
;
211 if (buf
.GetChar(0) >= wxT('A'))
212 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
214 firstDigit
= buf
.GetChar(0) - wxT('0');
216 if (buf
.GetChar(1) >= wxT('A'))
217 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
219 secondDigit
= buf
.GetChar(1) - wxT('0');
221 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
224 // Convert decimal integer to 2-character hex string
225 void wxDecToHex(int dec
, wxChar
*buf
)
227 int firstDigit
= (int)(dec
/16.0);
228 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
229 buf
[0] = hexArray
[firstDigit
];
230 buf
[1] = hexArray
[secondDigit
];
234 // Convert decimal integer to 2-character hex string
235 wxString
wxDecToHex(int dec
)
238 wxDecToHex(dec
, buf
);
239 return wxString(buf
);
242 // ----------------------------------------------------------------------------
244 // ----------------------------------------------------------------------------
246 // Return the current date/time
251 wxDateTime now
= wxDateTime
::Now();
254 return wxEmptyString
;
257 time_t now
= time((time_t *) NULL
);
258 char *date
= ctime(&now
);
260 return wxString
::FromAscii(date
);
264 void wxUsleep(unsigned long milliseconds
)
266 wxMilliSleep(milliseconds
);
269 const wxChar
*wxGetInstallPrefix()
273 if ( wxGetEnv(wxT("WXPREFIX"), &prefix
) )
274 return prefix
.c_str();
276 #ifdef wxINSTALL_PREFIX
277 return wxT(wxINSTALL_PREFIX
);
279 return wxEmptyString
;
283 wxString
wxGetDataDir()
285 wxString dir
= wxGetInstallPrefix();
286 dir
<< wxFILE_SEP_PATH
<< wxT("share") << wxFILE_SEP_PATH
<< wxT("wx");
290 int wxGetOsVersion(int *verMaj
, int *verMin
)
292 // we want this function to work even if there is no wxApp
293 wxConsoleAppTraits traitsConsole
;
294 wxAppTraits
*traits
= wxTheApp ? wxTheApp
->GetTraits() : NULL
;
296 traits
= &traitsConsole
;
298 wxToolkitInfo
& info
= traits
->GetToolkitInfo();
300 *verMaj
= info
.versionMajor
;
302 *verMin
= info
.versionMinor
;
307 * Class to make it easier to specify platform-dependent values
310 wxArrayInt
* wxPlatform
::sm_customPlatforms
= NULL
;
312 wxPlatform
& wxPlatform
::Is(int platform
, long value
)
314 if (wxPlatformIs(platform
))
319 wxPlatform
& wxPlatform
::IsNot(int platform
, long value
)
321 if (!wxPlatformIs(platform
))
326 wxPlatform
& wxPlatform
::Is(int platform
, double value
)
328 if (wxPlatformIs(platform
))
329 m_doubleValue
= value
;
333 wxPlatform
& wxPlatform
::IsNot(int platform
, double value
)
335 if (!wxPlatformIs(platform
))
336 m_doubleValue
= value
;
340 wxPlatform
& wxPlatform
::Is(int platform
, const wxString
& value
)
342 if (wxPlatformIs(platform
))
343 m_stringValue
= value
;
347 wxPlatform
& wxPlatform
::IsNot(int platform
, const wxString
& value
)
349 if (!wxPlatformIs(platform
))
350 m_stringValue
= value
;
354 wxPlatform
& wxPlatform
::Default(long value
)
360 wxPlatform
& wxPlatform
::Default(double value
)
362 m_doubleValue
= value
;
366 wxPlatform
& wxPlatform
::Default(const wxString
& value
)
368 m_stringValue
= value
;
372 void wxPlatform
::AddPlatform(int platform
)
374 if (!sm_customPlatforms
)
375 sm_customPlatforms
= new wxArrayInt
;
376 sm_customPlatforms
->Add(platform
);
379 void wxPlatform
::ClearPlatforms()
381 delete sm_customPlatforms
;
382 sm_customPlatforms
= NULL
;
385 /// Function for testing current platform
387 bool wxPlatform
::PlatformIs(int platform
)
390 if (platform
== wxMSW
)
394 if (platform
== wxWinCE
)
397 #if defined(__WXWINCE__) && defined(__POCKETPC__)
398 if (platform
== wxWinPocketPC
)
401 #if defined(__WXWINCE__) && defined(__SMARTPHONE__)
402 if (platform
== wxWinSmartphone
)
406 if (platform
== wxGTK
)
410 if (platform
== wxMac
)
414 if (platform
== wxX11
)
418 if (platform
== wxUnix
)
422 if (platform
== wxMGL
)
426 if (platform
== wxOS2
)
430 if (platform
== wxCocoa
)
434 if (sm_customPlatforms
&& sm_customPlatforms
->Index(platform
) != wxNOT_FOUND
)
440 // ----------------------------------------------------------------------------
441 // network and user id functions
442 // ----------------------------------------------------------------------------
444 // Get Full RFC822 style email address
445 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
447 wxString email
= wxGetEmailAddress();
451 wxStrncpy(address
, email
, maxSize
- 1);
452 address
[maxSize
- 1] = wxT('\0');
457 wxString
wxGetEmailAddress()
461 wxString host
= wxGetFullHostName();
464 wxString user
= wxGetUserId();
467 email
<< user
<< wxT('@') << host
;
474 wxString
wxGetUserId()
476 static const int maxLoginLen
= 256; // FIXME arbitrary number
479 bool ok
= wxGetUserId(wxStringBuffer(buf
, maxLoginLen
), maxLoginLen
);
487 wxString
wxGetUserName()
489 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
492 bool ok
= wxGetUserName(wxStringBuffer(buf
, maxUserNameLen
), maxUserNameLen
);
500 wxString
wxGetHostName()
502 static const size_t hostnameSize
= 257;
505 bool ok
= wxGetHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
513 wxString
wxGetFullHostName()
515 static const size_t hostnameSize
= 257;
518 bool ok
= wxGetFullHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
526 wxString
wxGetHomeDir()
536 wxString
wxGetCurrentDir()
543 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
548 if ( errno
!= ERANGE
)
550 wxLogSysError(_T("Failed to get current directory"));
552 return wxEmptyString
;
556 // buffer was too small, retry with a larger one
568 // ----------------------------------------------------------------------------
570 // ----------------------------------------------------------------------------
572 // wxDoExecuteWithCapture() helper: reads an entire stream into one array
574 // returns true if ok, false if error
576 static bool ReadAll(wxInputStream
*is
, wxArrayString
& output
)
578 wxCHECK_MSG( is
, false, _T("NULL stream in wxExecute()?") );
580 // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
583 wxTextInputStream
tis(*is
);
588 wxString line
= tis
.ReadLine();
604 #endif // wxUSE_STREAMS
606 // this is a private function because it hasn't a clean interface: the first
607 // array is passed by reference, the second by pointer - instead we have 2
608 // public versions of wxExecute() below
609 static long wxDoExecuteWithCapture(const wxString
& command
,
610 wxArrayString
& output
,
611 wxArrayString
* error
,
614 // create a wxProcess which will capture the output
615 wxProcess
*process
= new wxProcess
;
618 long rc
= wxExecute(command
, wxEXEC_SYNC
| flags
, process
);
623 if ( !ReadAll(process
->GetInputStream(), output
) )
628 if ( !ReadAll(process
->GetErrorStream(), *error
) )
636 #endif // wxUSE_STREAMS/!wxUSE_STREAMS
643 long wxExecute(const wxString
& command
, wxArrayString
& output
, int flags
)
645 return wxDoExecuteWithCapture(command
, output
, NULL
, flags
);
648 long wxExecute(const wxString
& command
,
649 wxArrayString
& output
,
650 wxArrayString
& error
,
653 return wxDoExecuteWithCapture(command
, output
, &error
, flags
);
656 // ----------------------------------------------------------------------------
657 // Launch default browser
658 // ----------------------------------------------------------------------------
660 bool wxLaunchDefaultBrowser(const wxString
& urlOrig
, int flags
)
664 // set the scheme of url to http if it does not have one
665 wxString
url(urlOrig
);
666 if ( !wxURI(url
).HasScheme() )
667 url
.Prepend(wxT("http://"));
669 #if defined(__WXMSW__)
672 if ( flags
& wxBROWSER_NEW_WINDOW
)
674 // ShellExecuteEx() opens the URL in an existing window by default so
675 // we can't use it if we need a new window
676 wxRegKey
key(wxRegKey
::HKCR
, url
.BeforeFirst(':') + _T("\\shell\\open"));
679 wxRegKey
keyDDE(key
, wxT("DDEExec"));
680 if ( keyDDE
.Exists() )
682 const wxString ddeTopic
= wxRegKey(keyDDE
, wxT("topic"));
684 // we only know the syntax of WWW_OpenURL DDE request for IE,
685 // optimistically assume that all other browsers are compatible
688 bool ok
= ddeTopic
== wxT("WWW_OpenURL");
691 ddeCmd
= keyDDE
.QueryDefaultValue();
692 ok
= !ddeCmd
.empty();
697 // for WWW_OpenURL, the index of the window to open the URL
698 // in is -1 (meaning "current") by default, replace it with
699 // 0 which means "new" (see KB article 160957)
700 ok
= ddeCmd
.Replace(wxT("-1"), wxT("0"),
701 false /* only first occurence */) == 1;
706 // and also replace the parameters: the topic should
707 // contain a placeholder for the URL
708 ok
= ddeCmd
.Replace(wxT("%1"), url
, false) == 1;
713 // try to send it the DDE request now but ignore the errors
716 const wxString ddeServer
= wxRegKey(keyDDE
, wxT("application"));
717 if ( wxExecuteDDE(ddeServer
, ddeTopic
, ddeCmd
) )
720 // this is not necessarily an error: maybe browser is
721 // simply not running, but no matter, in any case we're
722 // going to launch it using ShellExecuteEx() below now and
723 // we shouldn't try to open a new window if we open a new
731 WinStruct
<SHELLEXECUTEINFO
> sei
;
732 sei
.lpFile
= url
.c_str();
733 sei
.lpVerb
= _T("open");
734 sei
.nShow
= SW_SHOWNORMAL
;
736 ::ShellExecuteEx(&sei
);
738 const int nResult
= (int) sei
.hInstApp
;
740 // Firefox returns file not found for some reason, so make an exception
742 if ( nResult
> 32 || nResult
== SE_ERR_FNF
)
745 // Log something if SE_ERR_FNF happens
746 if ( nResult
== SE_ERR_FNF
)
747 wxLogDebug(wxT("SE_ERR_FNF from ShellExecute -- maybe FireFox?"));
748 #endif // __WXDEBUG__
751 #elif defined(__WXMAC__)
757 err
= ICStart(&inst
, 'STKA'); // put your app creator code here
761 err
= ICFindConfigFile(inst
, 0, NULL
);
765 ConstStr255Param hint
= 0;
767 endSel
= url
.Length();
768 err
= ICLaunchURL(inst
, hint
, url
.fn_str(), endSel
, &startSel
, &endSel
);
770 wxLogDebug(wxT("ICLaunchURL error %d"), (int) err
);
777 wxLogDebug(wxT("ICStart error %d"), (int) err
);
785 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(_T("html"));
789 ft
->GetMimeType(&mt
);
791 ok
= ft
->GetOpenCommand(&cmd
, wxFileType
::MessageParameters(url
));
795 if ( !ok
|| cmd
.empty() )
797 // fallback to checking for the BROWSER environment variable
798 cmd
= wxGetenv(wxT("BROWSER"));
800 cmd
<< _T(' ') << url
;
803 ok
= ( !cmd
.empty() && wxExecute(cmd
) );
807 // no file type for HTML extension
808 wxLogError(_T("No default application configured for HTML files."));
810 #endif // !wxUSE_MIMETYPE && !__WXMSW__
812 wxLogSysError(_T("Failed to open URL \"%s\" in default browser."),
818 // ----------------------------------------------------------------------------
819 // wxApp::Yield() wrappers for backwards compatibility
820 // ----------------------------------------------------------------------------
824 return wxTheApp
&& wxTheApp
->Yield();
827 bool wxYieldIfNeeded()
829 return wxTheApp
&& wxTheApp
->Yield(true);
834 // ============================================================================
835 // GUI-only functions from now on
836 // ============================================================================
841 static long wxCurrentId
= 100;
845 // skip the part of IDs space that contains hard-coded values:
846 if (wxCurrentId
== wxID_LOWEST
)
847 wxCurrentId
= wxID_HIGHEST
+ 1;
849 return wxCurrentId
++;
853 wxGetCurrentId(void) { return wxCurrentId
; }
856 wxRegisterId (long id
)
858 if (id
>= wxCurrentId
)
859 wxCurrentId
= id
+ 1;
864 // ----------------------------------------------------------------------------
865 // Menu accelerators related functions
866 // ----------------------------------------------------------------------------
868 wxChar
*wxStripMenuCodes(const wxChar
*in
, wxChar
*out
)
870 wxString s
= wxMenuItem
::GetLabelFromText(in
);
873 // go smash their buffer if it's not big enough - I love char * params
874 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
878 // MYcopystring - for easier search...
879 out
= new wxChar
[s
.length() + 1];
880 wxStrcpy(out
, s
.c_str());
886 wxString
wxStripMenuCodes(const wxString
& in
)
890 size_t len
= in
.length();
893 for ( size_t n
= 0; n
< len
; n
++ )
898 // skip it, it is used to introduce the accel char (or to quote
899 // itself in which case it should still be skipped): note that it
900 // can't be the last character of the string
903 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
907 // use the next char instead
911 else if ( ch
== _T('\t') )
913 // everything after TAB is accel string, exit the loop
923 #endif // wxUSE_MENUS
925 // ----------------------------------------------------------------------------
926 // Window search functions
927 // ----------------------------------------------------------------------------
930 * If parent is non-NULL, look through children for a label or title
931 * matching the specified string. If NULL, look through all top-level windows.
936 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
938 return wxWindow
::FindWindowByLabel( title
, parent
);
943 * If parent is non-NULL, look through children for a name
944 * matching the specified string. If NULL, look through all top-level windows.
949 wxFindWindowByName (const wxString
& name
, wxWindow
* parent
)
951 return wxWindow
::FindWindowByName( name
, parent
);
954 // Returns menu item id or wxNOT_FOUND if none.
956 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
959 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
961 return menuBar
->FindMenuItem (menuString
, itemString
);
962 #endif // wxUSE_MENUS
967 // Try to find the deepest child that contains 'pt'.
968 // We go backwards, to try to allow for controls that are spacially
969 // within other controls, but are still siblings (e.g. buttons within
970 // static boxes). Static boxes are likely to be created _before_ controls
971 // that sit inside them.
972 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
977 // Hack for wxNotebook case: at least in wxGTK, all pages
978 // claim to be shown, so we must only deal with the selected one.
980 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
982 wxNotebook
* nb
= (wxNotebook
*) win
;
983 int sel
= nb
->GetSelection();
986 wxWindow
* child
= nb
->GetPage(sel
);
987 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
994 wxWindowList
::compatibility_iterator node
= win
->GetChildren().GetLast();
997 wxWindow
* child
= node
->GetData();
998 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
1001 node
= node
->GetPrevious();
1004 wxPoint pos
= win
->GetPosition();
1005 wxSize sz
= win
->GetSize();
1006 if (win
->GetParent())
1008 pos
= win
->GetParent()->ClientToScreen(pos
);
1011 wxRect
rect(pos
, sz
);
1012 if (rect
.Inside(pt
))
1018 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
1020 // Go backwards through the list since windows
1021 // on top are likely to have been appended most
1023 wxWindowList
::compatibility_iterator node
= wxTopLevelWindows
.GetLast();
1026 wxWindow
* win
= node
->GetData();
1027 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
1030 node
= node
->GetPrevious();
1035 // ----------------------------------------------------------------------------
1037 // ----------------------------------------------------------------------------
1040 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
1041 * since otherwise the generic code may be pulled in unnecessarily.
1046 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
1047 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
1049 long decorated_style
= style
;
1051 if ( ( style
& ( wxICON_EXCLAMATION
| wxICON_HAND
| wxICON_INFORMATION
| wxICON_QUESTION
) ) == 0 )
1053 decorated_style
|= ( style
& wxYES
) ? wxICON_QUESTION
: wxICON_INFORMATION
;
1056 wxMessageDialog
dialog(parent
, message
, caption
, decorated_style
);
1058 int ans
= dialog
.ShowModal();
1071 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
1076 #endif // wxUSE_MSGDLG
1080 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
1081 const wxString
& defaultValue
, wxWindow
*parent
,
1082 wxCoord x
, wxCoord y
, bool centre
)
1085 long style
= wxTextEntryDialogStyle
;
1092 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, style
, wxPoint(x
, y
));
1094 if (dialog
.ShowModal() == wxID_OK
)
1096 str
= dialog
.GetValue();
1102 wxString
wxGetPasswordFromUser(const wxString
& message
,
1103 const wxString
& caption
,
1104 const wxString
& defaultValue
,
1106 wxCoord x
, wxCoord y
, bool centre
)
1109 long style
= wxTextEntryDialogStyle
;
1116 wxPasswordEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
1117 style
, wxPoint(x
, y
));
1118 if ( dialog
.ShowModal() == wxID_OK
)
1120 str
= dialog
.GetValue();
1126 #endif // wxUSE_TEXTDLG
1130 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
, const wxString
& caption
)
1133 data
.SetChooseFull(true);
1136 data
.SetColour((wxColour
&)colInit
); // const_cast
1140 wxColourDialog
dialog(parent
, &data
);
1141 if (!caption
.IsEmpty())
1142 dialog
.SetTitle(caption
);
1143 if ( dialog
.ShowModal() == wxID_OK
)
1145 colRet
= dialog
.GetColourData().GetColour();
1147 //else: leave it invalid
1152 #endif // wxUSE_COLOURDLG
1156 wxFont
wxGetFontFromUser(wxWindow
*parent
, const wxFont
& fontInit
, const wxString
& caption
)
1159 if ( fontInit
.Ok() )
1161 data
.SetInitialFont(fontInit
);
1165 wxFontDialog
dialog(parent
, data
);
1166 if (!caption
.IsEmpty())
1167 dialog
.SetTitle(caption
);
1168 if ( dialog
.ShowModal() == wxID_OK
)
1170 fontRet
= dialog
.GetFontData().GetChosenFont();
1172 //else: leave it invalid
1177 #endif // wxUSE_FONTDLG
1179 // ----------------------------------------------------------------------------
1180 // wxSafeYield and supporting functions
1181 // ----------------------------------------------------------------------------
1183 void wxEnableTopLevelWindows(bool enable
)
1185 wxWindowList
::compatibility_iterator node
;
1186 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1187 node
->GetData()->Enable(enable
);
1190 wxWindowDisabler
::wxWindowDisabler(wxWindow
*winToSkip
)
1192 // remember the top level windows which were already disabled, so that we
1193 // don't reenable them later
1194 m_winDisabled
= NULL
;
1196 wxWindowList
::compatibility_iterator node
;
1197 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1199 wxWindow
*winTop
= node
->GetData();
1200 if ( winTop
== winToSkip
)
1203 // we don't need to disable the hidden or already disabled windows
1204 if ( winTop
->IsEnabled() && winTop
->IsShown() )
1210 if ( !m_winDisabled
)
1212 m_winDisabled
= new wxWindowList
;
1215 m_winDisabled
->Append(winTop
);
1220 wxWindowDisabler
::~wxWindowDisabler()
1222 wxWindowList
::compatibility_iterator node
;
1223 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1225 wxWindow
*winTop
= node
->GetData();
1226 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1230 //else: had been already disabled, don't reenable
1233 delete m_winDisabled
;
1236 // Yield to other apps/messages and disable user input to all windows except
1238 bool wxSafeYield(wxWindow
*win
, bool onlyIfNeeded
)
1240 wxWindowDisabler
wd(win
);
1244 rc
= wxYieldIfNeeded();
1251 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1252 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1255 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1257 return true; // detectable auto-repeat is the only mode MSW supports