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"
75 #include "wx/statusbr.h"
81 #include "wx/msw/wince/time.h"
85 #include "wx/mac/private.h"
87 #include "InternetConfig.h"
91 #if !defined(__MWERKS__) && !defined(__WXWINCE__)
92 #include <sys/types.h>
96 #if defined(__WXMSW__)
97 #include "wx/msw/private.h"
98 #include "wx/msw/registry.h"
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 // ============================================================================
109 // ============================================================================
111 #if WXWIN_COMPATIBILITY_2_4
114 copystring (const wxChar
*s
)
116 if (s
== NULL
) s
= wxEmptyString
;
117 size_t len
= wxStrlen (s
) + 1;
119 wxChar
*news
= new wxChar
[len
];
120 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
125 #endif // WXWIN_COMPATIBILITY_2_4
127 // ----------------------------------------------------------------------------
128 // String <-> Number conversions (deprecated)
129 // ----------------------------------------------------------------------------
131 #if WXWIN_COMPATIBILITY_2_4
133 WXDLLIMPEXP_DATA_BASE(const wxChar
*) wxFloatToStringStr
= wxT("%.2f");
134 WXDLLIMPEXP_DATA_BASE(const wxChar
*) wxDoubleToStringStr
= wxT("%.2f");
137 StringToFloat (const wxChar
*s
, float *number
)
139 if (s
&& *s
&& number
)
140 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
144 StringToDouble (const wxChar
*s
, double *number
)
146 if (s
&& *s
&& number
)
147 *number
= wxStrtod (s
, (wxChar
**) NULL
);
151 FloatToString (float number
, const wxChar
*fmt
)
153 static wxChar buf
[256];
155 wxSprintf (buf
, fmt
, number
);
160 DoubleToString (double number
, const wxChar
*fmt
)
162 static wxChar buf
[256];
164 wxSprintf (buf
, fmt
, number
);
169 StringToInt (const wxChar
*s
, int *number
)
171 if (s
&& *s
&& number
)
172 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
176 StringToLong (const wxChar
*s
, long *number
)
178 if (s
&& *s
&& number
)
179 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
183 IntToString (int number
)
185 static wxChar buf
[20];
187 wxSprintf (buf
, wxT("%d"), number
);
192 LongToString (long number
)
194 static wxChar buf
[20];
196 wxSprintf (buf
, wxT("%ld"), number
);
200 #endif // WXWIN_COMPATIBILITY_2_4
202 // Array used in DecToHex conversion routine.
203 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
205 // Convert 2-digit hex number to decimal
206 int wxHexToDec(const wxString
& buf
)
208 int firstDigit
, secondDigit
;
210 if (buf
.GetChar(0) >= wxT('A'))
211 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
213 firstDigit
= buf
.GetChar(0) - wxT('0');
215 if (buf
.GetChar(1) >= wxT('A'))
216 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
218 secondDigit
= buf
.GetChar(1) - wxT('0');
220 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
223 // Convert decimal integer to 2-character hex string
224 void wxDecToHex(int dec
, wxChar
*buf
)
226 int firstDigit
= (int)(dec
/16.0);
227 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
228 buf
[0] = hexArray
[firstDigit
];
229 buf
[1] = hexArray
[secondDigit
];
233 // Convert decimal integer to 2-character hex string
234 wxString
wxDecToHex(int dec
)
237 wxDecToHex(dec
, buf
);
238 return wxString(buf
);
241 // ----------------------------------------------------------------------------
243 // ----------------------------------------------------------------------------
245 // Return the current date/time
250 wxDateTime now
= wxDateTime::Now();
253 return wxEmptyString
;
256 time_t now
= time((time_t *) NULL
);
257 char *date
= ctime(&now
);
259 return wxString::FromAscii(date
);
263 void wxUsleep(unsigned long milliseconds
)
265 wxMilliSleep(milliseconds
);
268 const wxChar
*wxGetInstallPrefix()
272 if ( wxGetEnv(wxT("WXPREFIX"), &prefix
) )
273 return prefix
.c_str();
275 #ifdef wxINSTALL_PREFIX
276 return wxT(wxINSTALL_PREFIX
);
278 return wxEmptyString
;
282 wxString
wxGetDataDir()
284 wxString dir
= wxGetInstallPrefix();
285 dir
<< wxFILE_SEP_PATH
<< wxT("share") << wxFILE_SEP_PATH
<< wxT("wx");
289 int wxGetOsVersion(int *verMaj
, int *verMin
)
291 // we want this function to work even if there is no wxApp
292 wxConsoleAppTraits traitsConsole
;
293 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
295 traits
= &traitsConsole
;
297 wxToolkitInfo
& info
= traits
->GetToolkitInfo();
299 *verMaj
= info
.versionMajor
;
301 *verMin
= info
.versionMinor
;
306 * Class to make it easier to specify platform-dependent values
309 wxArrayInt
* wxPlatform::sm_customPlatforms
= NULL
;
311 void wxPlatform::Copy(const wxPlatform
& platform
)
313 m_longValue
= platform
.m_longValue
;
314 m_doubleValue
= platform
.m_doubleValue
;
315 m_stringValue
= platform
.m_stringValue
;
318 wxPlatform
wxPlatform::If(int platform
, long value
)
321 return wxPlatform(value
);
326 wxPlatform
wxPlatform::IfNot(int platform
, long value
)
329 return wxPlatform(value
);
334 wxPlatform
& wxPlatform::ElseIf(int platform
, long value
)
341 wxPlatform
& wxPlatform::ElseIfNot(int platform
, long value
)
348 wxPlatform
wxPlatform::If(int platform
, double value
)
351 return wxPlatform(value
);
356 wxPlatform
wxPlatform::IfNot(int platform
, double value
)
359 return wxPlatform(value
);
364 wxPlatform
& wxPlatform::ElseIf(int platform
, double value
)
367 m_doubleValue
= value
;
371 wxPlatform
& wxPlatform::ElseIfNot(int platform
, double value
)
374 m_doubleValue
= value
;
378 wxPlatform
wxPlatform::If(int platform
, const wxString
& value
)
381 return wxPlatform(value
);
386 wxPlatform
wxPlatform::IfNot(int platform
, const wxString
& value
)
389 return wxPlatform(value
);
394 wxPlatform
& wxPlatform::ElseIf(int platform
, const wxString
& value
)
397 m_stringValue
= value
;
401 wxPlatform
& wxPlatform::ElseIfNot(int platform
, const wxString
& value
)
404 m_stringValue
= value
;
408 wxPlatform
& wxPlatform::Else(long value
)
414 wxPlatform
& wxPlatform::Else(double value
)
416 m_doubleValue
= value
;
420 wxPlatform
& wxPlatform::Else(const wxString
& value
)
422 m_stringValue
= value
;
426 void wxPlatform::AddPlatform(int platform
)
428 if (!sm_customPlatforms
)
429 sm_customPlatforms
= new wxArrayInt
;
430 sm_customPlatforms
->Add(platform
);
433 void wxPlatform::ClearPlatforms()
435 delete sm_customPlatforms
;
436 sm_customPlatforms
= NULL
;
439 /// Function for testing current platform
441 bool wxPlatform::Is(int platform
)
444 if (platform
== wxMSW
)
448 if (platform
== wxWinCE
)
451 #if defined(__WXWINCE__) && defined(__POCKETPC__)
452 if (platform
== wxWinPocketPC
)
455 #if defined(__WXWINCE__) && defined(__SMARTPHONE__)
456 if (platform
== wxWinSmartPhone
)
460 if (platform
== wxGTK
)
464 if (platform
== wxMac
)
468 if (platform
== wxX11
)
472 if (platform
== wxUnix
)
476 if (platform
== wxMGL
)
480 if (platform
== wxOS2
)
484 if (platform
== wxCocoa
)
488 if (sm_customPlatforms
&& sm_customPlatforms
->Index(platform
) != wxNOT_FOUND
)
494 // ----------------------------------------------------------------------------
495 // network and user id functions
496 // ----------------------------------------------------------------------------
498 // Get Full RFC822 style email address
499 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
501 wxString email
= wxGetEmailAddress();
505 wxStrncpy(address
, email
, maxSize
- 1);
506 address
[maxSize
- 1] = wxT('\0');
511 wxString
wxGetEmailAddress()
515 wxString host
= wxGetFullHostName();
518 wxString user
= wxGetUserId();
521 email
<< user
<< wxT('@') << host
;
528 wxString
wxGetUserId()
530 static const int maxLoginLen
= 256; // FIXME arbitrary number
533 bool ok
= wxGetUserId(wxStringBuffer(buf
, maxLoginLen
), maxLoginLen
);
541 wxString
wxGetUserName()
543 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
546 bool ok
= wxGetUserName(wxStringBuffer(buf
, maxUserNameLen
), maxUserNameLen
);
554 wxString
wxGetHostName()
556 static const size_t hostnameSize
= 257;
559 bool ok
= wxGetHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
567 wxString
wxGetFullHostName()
569 static const size_t hostnameSize
= 257;
572 bool ok
= wxGetFullHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
580 wxString
wxGetHomeDir()
590 wxString
wxGetCurrentDir()
597 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
602 if ( errno
!= ERANGE
)
604 wxLogSysError(_T("Failed to get current directory"));
606 return wxEmptyString
;
610 // buffer was too small, retry with a larger one
622 // ----------------------------------------------------------------------------
624 // ----------------------------------------------------------------------------
626 // wxDoExecuteWithCapture() helper: reads an entire stream into one array
628 // returns true if ok, false if error
630 static bool ReadAll(wxInputStream
*is
, wxArrayString
& output
)
632 wxCHECK_MSG( is
, false, _T("NULL stream in wxExecute()?") );
634 // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
637 wxTextInputStream
tis(*is
);
642 wxString line
= tis
.ReadLine();
658 #endif // wxUSE_STREAMS
660 // this is a private function because it hasn't a clean interface: the first
661 // array is passed by reference, the second by pointer - instead we have 2
662 // public versions of wxExecute() below
663 static long wxDoExecuteWithCapture(const wxString
& command
,
664 wxArrayString
& output
,
665 wxArrayString
* error
,
668 // create a wxProcess which will capture the output
669 wxProcess
*process
= new wxProcess
;
672 long rc
= wxExecute(command
, wxEXEC_SYNC
| flags
, process
);
677 if ( !ReadAll(process
->GetInputStream(), output
) )
682 if ( !ReadAll(process
->GetErrorStream(), *error
) )
690 #endif // wxUSE_STREAMS/!wxUSE_STREAMS
697 long wxExecute(const wxString
& command
, wxArrayString
& output
, int flags
)
699 return wxDoExecuteWithCapture(command
, output
, NULL
, flags
);
702 long wxExecute(const wxString
& command
,
703 wxArrayString
& output
,
704 wxArrayString
& error
,
707 return wxDoExecuteWithCapture(command
, output
, &error
, flags
);
710 // ----------------------------------------------------------------------------
711 // Launch default browser
712 // ----------------------------------------------------------------------------
714 bool wxLaunchDefaultBrowser(const wxString
& urlOrig
, int flags
)
718 // set the scheme of url to http if it does not have one
719 wxString
url(urlOrig
);
720 if ( !wxURI(url
).HasScheme() )
721 url
.Prepend(wxT("http://"));
723 #if defined(__WXMSW__)
726 if ( flags
& wxBROWSER_NEW_WINDOW
)
728 // ShellExecuteEx() opens the URL in an existing window by default so
729 // we can't use it if we need a new window
730 wxRegKey
key(wxRegKey::HKCR
, url
.BeforeFirst(':') + _T("\\shell\\open"));
733 wxRegKey
keyDDE(key
, wxT("DDEExec"));
734 if ( keyDDE
.Exists() )
736 const wxString ddeTopic
= wxRegKey(keyDDE
, wxT("topic"));
738 // we only know the syntax of WWW_OpenURL DDE request for IE,
739 // optimistically assume that all other browsers are compatible
742 bool ok
= ddeTopic
== wxT("WWW_OpenURL");
745 ddeCmd
= keyDDE
.QueryDefaultValue();
746 ok
= !ddeCmd
.empty();
751 // for WWW_OpenURL, the index of the window to open the URL
752 // in is -1 (meaning "current") by default, replace it with
753 // 0 which means "new" (see KB article 160957)
754 ok
= ddeCmd
.Replace(wxT("-1"), wxT("0"),
755 false /* only first occurence */) == 1;
760 // and also replace the parameters: the topic should
761 // contain a placeholder for the URL
762 ok
= ddeCmd
.Replace(wxT("%1"), url
, false) == 1;
767 // try to send it the DDE request now but ignore the errors
770 const wxString ddeServer
= wxRegKey(keyDDE
, wxT("application"));
771 if ( wxExecuteDDE(ddeServer
, ddeTopic
, ddeCmd
) )
774 // this is not necessarily an error: maybe browser is
775 // simply not running, but no matter, in any case we're
776 // going to launch it using ShellExecuteEx() below now and
777 // we shouldn't try to open a new window if we open a new
785 WinStruct
<SHELLEXECUTEINFO
> sei
;
786 sei
.lpFile
= url
.c_str();
787 sei
.lpVerb
= _T("open");
788 sei
.nShow
= SW_SHOWNORMAL
;
790 ::ShellExecuteEx(&sei
);
792 const int nResult
= (int) sei
.hInstApp
;
794 // Firefox returns file not found for some reason, so make an exception
796 if ( nResult
> 32 || nResult
== SE_ERR_FNF
)
799 // Log something if SE_ERR_FNF happens
800 if ( nResult
== SE_ERR_FNF
)
801 wxLogDebug(wxT("SE_ERR_FNF from ShellExecute -- maybe FireFox?"));
802 #endif // __WXDEBUG__
805 #elif defined(__WXMAC__)
811 err
= ICStart(&inst
, 'STKA'); // put your app creator code here
815 err
= ICFindConfigFile(inst
, 0, NULL
);
819 ConstStr255Param hint
= 0;
821 endSel
= url
.length();
822 err
= ICLaunchURL(inst
, hint
, url
.fn_str(), endSel
, &startSel
, &endSel
);
824 wxLogDebug(wxT("ICLaunchURL error %d"), (int) err
);
831 wxLogDebug(wxT("ICStart error %d"), (int) err
);
839 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(_T("html"));
843 ft
->GetMimeType(&mt
);
845 ok
= ft
->GetOpenCommand(&cmd
, wxFileType::MessageParameters(url
));
849 if ( !ok
|| cmd
.empty() )
851 // fallback to checking for the BROWSER environment variable
852 cmd
= wxGetenv(wxT("BROWSER"));
854 cmd
<< _T(' ') << url
;
857 ok
= ( !cmd
.empty() && wxExecute(cmd
) );
861 // no file type for HTML extension
862 wxLogError(_T("No default application configured for HTML files."));
864 #endif // !wxUSE_MIMETYPE && !__WXMSW__
866 wxLogSysError(_T("Failed to open URL \"%s\" in default browser."),
872 // ----------------------------------------------------------------------------
873 // wxApp::Yield() wrappers for backwards compatibility
874 // ----------------------------------------------------------------------------
878 return wxTheApp
&& wxTheApp
->Yield();
881 bool wxYieldIfNeeded()
883 return wxTheApp
&& wxTheApp
->Yield(true);
888 // ============================================================================
889 // GUI-only functions from now on
890 // ============================================================================
895 static long wxCurrentId
= 100;
899 // skip the part of IDs space that contains hard-coded values:
900 if (wxCurrentId
== wxID_LOWEST
)
901 wxCurrentId
= wxID_HIGHEST
+ 1;
903 return wxCurrentId
++;
907 wxGetCurrentId(void) { return wxCurrentId
; }
910 wxRegisterId (long id
)
912 if (id
>= wxCurrentId
)
913 wxCurrentId
= id
+ 1;
918 // ----------------------------------------------------------------------------
919 // Menu accelerators related functions
920 // ----------------------------------------------------------------------------
922 wxChar
*wxStripMenuCodes(const wxChar
*in
, wxChar
*out
)
924 wxString s
= wxMenuItem::GetLabelFromText(in
);
927 // go smash their buffer if it's not big enough - I love char * params
928 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
932 // MYcopystring - for easier search...
933 out
= new wxChar
[s
.length() + 1];
934 wxStrcpy(out
, s
.c_str());
940 wxString
wxStripMenuCodes(const wxString
& in
)
944 size_t len
= in
.length();
947 for ( size_t n
= 0; n
< len
; n
++ )
952 // skip it, it is used to introduce the accel char (or to quote
953 // itself in which case it should still be skipped): note that it
954 // can't be the last character of the string
957 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
961 // use the next char instead
965 else if ( ch
== _T('\t') )
967 // everything after TAB is accel string, exit the loop
977 #endif // wxUSE_MENUS
979 // ----------------------------------------------------------------------------
980 // Window search functions
981 // ----------------------------------------------------------------------------
984 * If parent is non-NULL, look through children for a label or title
985 * matching the specified string. If NULL, look through all top-level windows.
990 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
992 return wxWindow::FindWindowByLabel( title
, parent
);
997 * If parent is non-NULL, look through children for a name
998 * matching the specified string. If NULL, look through all top-level windows.
1003 wxFindWindowByName (const wxString
& name
, wxWindow
* parent
)
1005 return wxWindow::FindWindowByName( name
, parent
);
1008 // Returns menu item id or wxNOT_FOUND if none.
1010 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
1013 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
1015 return menuBar
->FindMenuItem (menuString
, itemString
);
1016 #endif // wxUSE_MENUS
1021 // Try to find the deepest child that contains 'pt'.
1022 // We go backwards, to try to allow for controls that are spacially
1023 // within other controls, but are still siblings (e.g. buttons within
1024 // static boxes). Static boxes are likely to be created _before_ controls
1025 // that sit inside them.
1026 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
1028 if (!win
->IsShown())
1031 // Hack for wxNotebook case: at least in wxGTK, all pages
1032 // claim to be shown, so we must only deal with the selected one.
1034 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
1036 wxNotebook
* nb
= (wxNotebook
*) win
;
1037 int sel
= nb
->GetSelection();
1040 wxWindow
* child
= nb
->GetPage(sel
);
1041 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
1048 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetLast();
1051 wxWindow
* child
= node
->GetData();
1052 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
1055 node
= node
->GetPrevious();
1058 wxPoint pos
= win
->GetPosition();
1059 wxSize sz
= win
->GetSize();
1060 if ( !win
->IsTopLevel() && win
->GetParent() )
1062 pos
= win
->GetParent()->ClientToScreen(pos
);
1065 wxRect
rect(pos
, sz
);
1066 if (rect
.Inside(pt
))
1072 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
1074 // Go backwards through the list since windows
1075 // on top are likely to have been appended most
1077 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetLast();
1080 wxWindow
* win
= node
->GetData();
1081 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
1084 node
= node
->GetPrevious();
1089 // ----------------------------------------------------------------------------
1091 // ----------------------------------------------------------------------------
1094 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
1095 * since otherwise the generic code may be pulled in unnecessarily.
1100 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
1101 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
1103 long decorated_style
= style
;
1105 if ( ( style
& ( wxICON_EXCLAMATION
| wxICON_HAND
| wxICON_INFORMATION
| wxICON_QUESTION
) ) == 0 )
1107 decorated_style
|= ( style
& wxYES
) ? wxICON_QUESTION
: wxICON_INFORMATION
;
1110 wxMessageDialog
dialog(parent
, message
, caption
, decorated_style
);
1112 int ans
= dialog
.ShowModal();
1125 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
1130 #endif // wxUSE_MSGDLG
1134 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
1135 const wxString
& defaultValue
, wxWindow
*parent
,
1136 wxCoord x
, wxCoord y
, bool centre
)
1139 long style
= wxTextEntryDialogStyle
;
1146 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, style
, wxPoint(x
, y
));
1148 if (dialog
.ShowModal() == wxID_OK
)
1150 str
= dialog
.GetValue();
1156 wxString
wxGetPasswordFromUser(const wxString
& message
,
1157 const wxString
& caption
,
1158 const wxString
& defaultValue
,
1160 wxCoord x
, wxCoord y
, bool centre
)
1163 long style
= wxTextEntryDialogStyle
;
1170 wxPasswordEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
1171 style
, wxPoint(x
, y
));
1172 if ( dialog
.ShowModal() == wxID_OK
)
1174 str
= dialog
.GetValue();
1180 #endif // wxUSE_TEXTDLG
1184 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
, const wxString
& caption
)
1187 data
.SetChooseFull(true);
1190 data
.SetColour((wxColour
&)colInit
); // const_cast
1194 wxColourDialog
dialog(parent
, &data
);
1195 if (!caption
.empty())
1196 dialog
.SetTitle(caption
);
1197 if ( dialog
.ShowModal() == wxID_OK
)
1199 colRet
= dialog
.GetColourData().GetColour();
1201 //else: leave it invalid
1206 #endif // wxUSE_COLOURDLG
1210 wxFont
wxGetFontFromUser(wxWindow
*parent
, const wxFont
& fontInit
, const wxString
& caption
)
1213 if ( fontInit
.Ok() )
1215 data
.SetInitialFont(fontInit
);
1219 wxFontDialog
dialog(parent
, data
);
1220 if (!caption
.empty())
1221 dialog
.SetTitle(caption
);
1222 if ( dialog
.ShowModal() == wxID_OK
)
1224 fontRet
= dialog
.GetFontData().GetChosenFont();
1226 //else: leave it invalid
1231 #endif // wxUSE_FONTDLG
1233 // ----------------------------------------------------------------------------
1234 // wxSafeYield and supporting functions
1235 // ----------------------------------------------------------------------------
1237 void wxEnableTopLevelWindows(bool enable
)
1239 wxWindowList::compatibility_iterator node
;
1240 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1241 node
->GetData()->Enable(enable
);
1244 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1246 // remember the top level windows which were already disabled, so that we
1247 // don't reenable them later
1248 m_winDisabled
= NULL
;
1250 wxWindowList::compatibility_iterator node
;
1251 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1253 wxWindow
*winTop
= node
->GetData();
1254 if ( winTop
== winToSkip
)
1257 // we don't need to disable the hidden or already disabled windows
1258 if ( winTop
->IsEnabled() && winTop
->IsShown() )
1264 if ( !m_winDisabled
)
1266 m_winDisabled
= new wxWindowList
;
1269 m_winDisabled
->Append(winTop
);
1274 wxWindowDisabler::~wxWindowDisabler()
1276 wxWindowList::compatibility_iterator node
;
1277 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1279 wxWindow
*winTop
= node
->GetData();
1280 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1284 //else: had been already disabled, don't reenable
1287 delete m_winDisabled
;
1290 // Yield to other apps/messages and disable user input to all windows except
1292 bool wxSafeYield(wxWindow
*win
, bool onlyIfNeeded
)
1294 wxWindowDisabler
wd(win
);
1298 rc
= wxYieldIfNeeded();
1305 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1306 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1309 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1311 return true; // detectable auto-repeat is the only mode MSW supports