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"
99 #include <shellapi.h> // needed for SHELLEXECUTEINFO
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 void wxPlatform::Copy(const wxPlatform
& platform
)
314 m_longValue
= platform
.m_longValue
;
315 m_doubleValue
= platform
.m_doubleValue
;
316 m_stringValue
= platform
.m_stringValue
;
319 wxPlatform
wxPlatform::If(int platform
, long value
)
322 return wxPlatform(value
);
327 wxPlatform
wxPlatform::IfNot(int platform
, long value
)
330 return wxPlatform(value
);
335 wxPlatform
& wxPlatform::ElseIf(int platform
, long value
)
342 wxPlatform
& wxPlatform::ElseIfNot(int platform
, long value
)
349 wxPlatform
wxPlatform::If(int platform
, double value
)
352 return wxPlatform(value
);
357 wxPlatform
wxPlatform::IfNot(int platform
, double value
)
360 return wxPlatform(value
);
365 wxPlatform
& wxPlatform::ElseIf(int platform
, double value
)
368 m_doubleValue
= value
;
372 wxPlatform
& wxPlatform::ElseIfNot(int platform
, double value
)
375 m_doubleValue
= value
;
379 wxPlatform
wxPlatform::If(int platform
, const wxString
& value
)
382 return wxPlatform(value
);
387 wxPlatform
wxPlatform::IfNot(int platform
, const wxString
& value
)
390 return wxPlatform(value
);
395 wxPlatform
& wxPlatform::ElseIf(int platform
, const wxString
& value
)
398 m_stringValue
= value
;
402 wxPlatform
& wxPlatform::ElseIfNot(int platform
, const wxString
& value
)
405 m_stringValue
= value
;
409 wxPlatform
& wxPlatform::Else(long value
)
415 wxPlatform
& wxPlatform::Else(double value
)
417 m_doubleValue
= value
;
421 wxPlatform
& wxPlatform::Else(const wxString
& value
)
423 m_stringValue
= value
;
427 void wxPlatform::AddPlatform(int platform
)
429 if (!sm_customPlatforms
)
430 sm_customPlatforms
= new wxArrayInt
;
431 sm_customPlatforms
->Add(platform
);
434 void wxPlatform::ClearPlatforms()
436 delete sm_customPlatforms
;
437 sm_customPlatforms
= NULL
;
440 /// Function for testing current platform
442 bool wxPlatform::Is(int platform
)
445 if (platform
== wxMSW
)
449 if (platform
== wxWinCE
)
452 #if defined(__WXWINCE__) && defined(__POCKETPC__)
453 if (platform
== wxWinPocketPC
)
456 #if defined(__WXWINCE__) && defined(__SMARTPHONE__)
457 if (platform
== wxWinSmartPhone
)
461 if (platform
== wxGTK
)
465 if (platform
== wxMac
)
469 if (platform
== wxX11
)
473 if (platform
== wxUnix
)
477 if (platform
== wxMGL
)
481 if (platform
== wxOS2
)
485 if (platform
== wxCocoa
)
489 if (sm_customPlatforms
&& sm_customPlatforms
->Index(platform
) != wxNOT_FOUND
)
495 // ----------------------------------------------------------------------------
496 // network and user id functions
497 // ----------------------------------------------------------------------------
499 // Get Full RFC822 style email address
500 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
502 wxString email
= wxGetEmailAddress();
506 wxStrncpy(address
, email
, maxSize
- 1);
507 address
[maxSize
- 1] = wxT('\0');
512 wxString
wxGetEmailAddress()
516 wxString host
= wxGetFullHostName();
519 wxString user
= wxGetUserId();
522 email
<< user
<< wxT('@') << host
;
529 wxString
wxGetUserId()
531 static const int maxLoginLen
= 256; // FIXME arbitrary number
534 bool ok
= wxGetUserId(wxStringBuffer(buf
, maxLoginLen
), maxLoginLen
);
542 wxString
wxGetUserName()
544 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
547 bool ok
= wxGetUserName(wxStringBuffer(buf
, maxUserNameLen
), maxUserNameLen
);
555 wxString
wxGetHostName()
557 static const size_t hostnameSize
= 257;
560 bool ok
= wxGetHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
568 wxString
wxGetFullHostName()
570 static const size_t hostnameSize
= 257;
573 bool ok
= wxGetFullHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
581 wxString
wxGetHomeDir()
591 wxString
wxGetCurrentDir()
598 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
603 if ( errno
!= ERANGE
)
605 wxLogSysError(_T("Failed to get current directory"));
607 return wxEmptyString
;
611 // buffer was too small, retry with a larger one
623 // ----------------------------------------------------------------------------
625 // ----------------------------------------------------------------------------
627 // wxDoExecuteWithCapture() helper: reads an entire stream into one array
629 // returns true if ok, false if error
631 static bool ReadAll(wxInputStream
*is
, wxArrayString
& output
)
633 wxCHECK_MSG( is
, false, _T("NULL stream in wxExecute()?") );
635 // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
638 wxTextInputStream
tis(*is
);
643 wxString line
= tis
.ReadLine();
659 #endif // wxUSE_STREAMS
661 // this is a private function because it hasn't a clean interface: the first
662 // array is passed by reference, the second by pointer - instead we have 2
663 // public versions of wxExecute() below
664 static long wxDoExecuteWithCapture(const wxString
& command
,
665 wxArrayString
& output
,
666 wxArrayString
* error
,
669 // create a wxProcess which will capture the output
670 wxProcess
*process
= new wxProcess
;
673 long rc
= wxExecute(command
, wxEXEC_SYNC
| flags
, process
);
678 if ( !ReadAll(process
->GetInputStream(), output
) )
683 if ( !ReadAll(process
->GetErrorStream(), *error
) )
691 #endif // wxUSE_STREAMS/!wxUSE_STREAMS
698 long wxExecute(const wxString
& command
, wxArrayString
& output
, int flags
)
700 return wxDoExecuteWithCapture(command
, output
, NULL
, flags
);
703 long wxExecute(const wxString
& command
,
704 wxArrayString
& output
,
705 wxArrayString
& error
,
708 return wxDoExecuteWithCapture(command
, output
, &error
, flags
);
711 // ----------------------------------------------------------------------------
712 // Launch default browser
713 // ----------------------------------------------------------------------------
715 bool wxLaunchDefaultBrowser(const wxString
& urlOrig
, int flags
)
719 // set the scheme of url to http if it does not have one
720 wxString
url(urlOrig
);
721 if ( !wxURI(url
).HasScheme() )
722 url
.Prepend(wxT("http://"));
724 #if defined(__WXMSW__)
727 if ( flags
& wxBROWSER_NEW_WINDOW
)
729 // ShellExecuteEx() opens the URL in an existing window by default so
730 // we can't use it if we need a new window
731 wxRegKey
key(wxRegKey::HKCR
, url
.BeforeFirst(':') + _T("\\shell\\open"));
734 wxRegKey
keyDDE(key
, wxT("DDEExec"));
735 if ( keyDDE
.Exists() )
737 const wxString ddeTopic
= wxRegKey(keyDDE
, wxT("topic"));
739 // we only know the syntax of WWW_OpenURL DDE request for IE,
740 // optimistically assume that all other browsers are compatible
743 bool ok
= ddeTopic
== wxT("WWW_OpenURL");
746 ddeCmd
= keyDDE
.QueryDefaultValue();
747 ok
= !ddeCmd
.empty();
752 // for WWW_OpenURL, the index of the window to open the URL
753 // in is -1 (meaning "current") by default, replace it with
754 // 0 which means "new" (see KB article 160957)
755 ok
= ddeCmd
.Replace(wxT("-1"), wxT("0"),
756 false /* only first occurence */) == 1;
761 // and also replace the parameters: the topic should
762 // contain a placeholder for the URL
763 ok
= ddeCmd
.Replace(wxT("%1"), url
, false) == 1;
768 // try to send it the DDE request now but ignore the errors
771 const wxString ddeServer
= wxRegKey(keyDDE
, wxT("application"));
772 if ( wxExecuteDDE(ddeServer
, ddeTopic
, ddeCmd
) )
775 // this is not necessarily an error: maybe browser is
776 // simply not running, but no matter, in any case we're
777 // going to launch it using ShellExecuteEx() below now and
778 // we shouldn't try to open a new window if we open a new
786 WinStruct
<SHELLEXECUTEINFO
> sei
;
787 sei
.lpFile
= url
.c_str();
788 sei
.lpVerb
= _T("open");
789 sei
.nShow
= SW_SHOWNORMAL
;
791 ::ShellExecuteEx(&sei
);
793 const int nResult
= (int) sei
.hInstApp
;
795 // Firefox returns file not found for some reason, so make an exception
797 if ( nResult
> 32 || nResult
== SE_ERR_FNF
)
800 // Log something if SE_ERR_FNF happens
801 if ( nResult
== SE_ERR_FNF
)
802 wxLogDebug(wxT("SE_ERR_FNF from ShellExecute -- maybe FireFox?"));
803 #endif // __WXDEBUG__
806 #elif defined(__WXMAC__)
812 err
= ICStart(&inst
, 'STKA'); // put your app creator code here
816 err
= ICFindConfigFile(inst
, 0, NULL
);
820 ConstStr255Param hint
= 0;
822 endSel
= url
.length();
823 err
= ICLaunchURL(inst
, hint
, url
.fn_str(), endSel
, &startSel
, &endSel
);
825 wxLogDebug(wxT("ICLaunchURL error %d"), (int) err
);
832 wxLogDebug(wxT("ICStart error %d"), (int) err
);
840 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(_T("html"));
844 ft
->GetMimeType(&mt
);
846 ok
= ft
->GetOpenCommand(&cmd
, wxFileType::MessageParameters(url
));
850 if ( !ok
|| cmd
.empty() )
852 // fallback to checking for the BROWSER environment variable
853 cmd
= wxGetenv(wxT("BROWSER"));
855 cmd
<< _T(' ') << url
;
858 ok
= ( !cmd
.empty() && wxExecute(cmd
) );
862 // no file type for HTML extension
863 wxLogError(_T("No default application configured for HTML files."));
865 #endif // !wxUSE_MIMETYPE && !__WXMSW__
867 wxLogSysError(_T("Failed to open URL \"%s\" in default browser."),
873 // ----------------------------------------------------------------------------
874 // wxApp::Yield() wrappers for backwards compatibility
875 // ----------------------------------------------------------------------------
879 return wxTheApp
&& wxTheApp
->Yield();
882 bool wxYieldIfNeeded()
884 return wxTheApp
&& wxTheApp
->Yield(true);
889 // ============================================================================
890 // GUI-only functions from now on
891 // ============================================================================
896 static long wxCurrentId
= 100;
900 // skip the part of IDs space that contains hard-coded values:
901 if (wxCurrentId
== wxID_LOWEST
)
902 wxCurrentId
= wxID_HIGHEST
+ 1;
904 return wxCurrentId
++;
908 wxGetCurrentId(void) { return wxCurrentId
; }
911 wxRegisterId (long id
)
913 if (id
>= wxCurrentId
)
914 wxCurrentId
= id
+ 1;
917 // ----------------------------------------------------------------------------
918 // Menu accelerators related functions
919 // ----------------------------------------------------------------------------
921 wxChar
*wxStripMenuCodes(const wxChar
*in
, wxChar
*out
)
924 wxString s
= wxMenuItem::GetLabelFromText(in
);
927 wxString s
= wxStripMenuCodes(str
);
928 #endif // wxUSE_MENUS
931 // go smash their buffer if it's not big enough - I love char * params
932 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
936 // MYcopystring - for easier search...
937 out
= new wxChar
[s
.length() + 1];
938 wxStrcpy(out
, s
.c_str());
944 wxString
wxStripMenuCodes(const wxString
& in
, int flags
)
946 wxASSERT_MSG( flags
, _T("this is useless to call without any flags") );
950 size_t len
= in
.length();
953 for ( size_t n
= 0; n
< len
; n
++ )
956 if ( (flags
& wxStrip_Mnemonics
) && ch
== _T('&') )
958 // skip it, it is used to introduce the accel char (or to quote
959 // itself in which case it should still be skipped): note that it
960 // can't be the last character of the string
963 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
967 // use the next char instead
971 else if ( (flags
& wxStrip_Accel
) && ch
== _T('\t') )
973 // everything after TAB is accel string, exit the loop
983 // ----------------------------------------------------------------------------
984 // Window search functions
985 // ----------------------------------------------------------------------------
988 * If parent is non-NULL, look through children for a label or title
989 * matching the specified string. If NULL, look through all top-level windows.
994 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
996 return wxWindow::FindWindowByLabel( title
, parent
);
1001 * If parent is non-NULL, look through children for a name
1002 * matching the specified string. If NULL, look through all top-level windows.
1007 wxFindWindowByName (const wxString
& name
, wxWindow
* parent
)
1009 return wxWindow::FindWindowByName( name
, parent
);
1012 // Returns menu item id or wxNOT_FOUND if none.
1014 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
1017 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
1019 return menuBar
->FindMenuItem (menuString
, itemString
);
1020 #endif // wxUSE_MENUS
1025 // Try to find the deepest child that contains 'pt'.
1026 // We go backwards, to try to allow for controls that are spacially
1027 // within other controls, but are still siblings (e.g. buttons within
1028 // static boxes). Static boxes are likely to be created _before_ controls
1029 // that sit inside them.
1030 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
1032 if (!win
->IsShown())
1035 // Hack for wxNotebook case: at least in wxGTK, all pages
1036 // claim to be shown, so we must only deal with the selected one.
1038 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
1040 wxNotebook
* nb
= (wxNotebook
*) win
;
1041 int sel
= nb
->GetSelection();
1044 wxWindow
* child
= nb
->GetPage(sel
);
1045 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
1052 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetLast();
1055 wxWindow
* child
= node
->GetData();
1056 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
1059 node
= node
->GetPrevious();
1062 wxPoint pos
= win
->GetPosition();
1063 wxSize sz
= win
->GetSize();
1064 if ( !win
->IsTopLevel() && win
->GetParent() )
1066 pos
= win
->GetParent()->ClientToScreen(pos
);
1069 wxRect
rect(pos
, sz
);
1070 if (rect
.Inside(pt
))
1076 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
1078 // Go backwards through the list since windows
1079 // on top are likely to have been appended most
1081 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetLast();
1084 wxWindow
* win
= node
->GetData();
1085 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
1088 node
= node
->GetPrevious();
1093 // ----------------------------------------------------------------------------
1095 // ----------------------------------------------------------------------------
1098 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
1099 * since otherwise the generic code may be pulled in unnecessarily.
1104 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
1105 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
1107 long decorated_style
= style
;
1109 if ( ( style
& ( wxICON_EXCLAMATION
| wxICON_HAND
| wxICON_INFORMATION
| wxICON_QUESTION
) ) == 0 )
1111 decorated_style
|= ( style
& wxYES
) ? wxICON_QUESTION
: wxICON_INFORMATION
;
1114 wxMessageDialog
dialog(parent
, message
, caption
, decorated_style
);
1116 int ans
= dialog
.ShowModal();
1129 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
1134 #endif // wxUSE_MSGDLG
1138 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
1139 const wxString
& defaultValue
, wxWindow
*parent
,
1140 wxCoord x
, wxCoord y
, bool centre
)
1143 long style
= wxTextEntryDialogStyle
;
1150 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, style
, wxPoint(x
, y
));
1152 if (dialog
.ShowModal() == wxID_OK
)
1154 str
= dialog
.GetValue();
1160 wxString
wxGetPasswordFromUser(const wxString
& message
,
1161 const wxString
& caption
,
1162 const wxString
& defaultValue
,
1164 wxCoord x
, wxCoord y
, bool centre
)
1167 long style
= wxTextEntryDialogStyle
;
1174 wxPasswordEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
1175 style
, wxPoint(x
, y
));
1176 if ( dialog
.ShowModal() == wxID_OK
)
1178 str
= dialog
.GetValue();
1184 #endif // wxUSE_TEXTDLG
1188 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
, const wxString
& caption
)
1191 data
.SetChooseFull(true);
1194 data
.SetColour((wxColour
&)colInit
); // const_cast
1198 wxColourDialog
dialog(parent
, &data
);
1199 if (!caption
.empty())
1200 dialog
.SetTitle(caption
);
1201 if ( dialog
.ShowModal() == wxID_OK
)
1203 colRet
= dialog
.GetColourData().GetColour();
1205 //else: leave it invalid
1210 #endif // wxUSE_COLOURDLG
1214 wxFont
wxGetFontFromUser(wxWindow
*parent
, const wxFont
& fontInit
, const wxString
& caption
)
1217 if ( fontInit
.Ok() )
1219 data
.SetInitialFont(fontInit
);
1223 wxFontDialog
dialog(parent
, data
);
1224 if (!caption
.empty())
1225 dialog
.SetTitle(caption
);
1226 if ( dialog
.ShowModal() == wxID_OK
)
1228 fontRet
= dialog
.GetFontData().GetChosenFont();
1230 //else: leave it invalid
1235 #endif // wxUSE_FONTDLG
1237 // ----------------------------------------------------------------------------
1238 // wxSafeYield and supporting functions
1239 // ----------------------------------------------------------------------------
1241 void wxEnableTopLevelWindows(bool enable
)
1243 wxWindowList::compatibility_iterator node
;
1244 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1245 node
->GetData()->Enable(enable
);
1248 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1250 // remember the top level windows which were already disabled, so that we
1251 // don't reenable them later
1252 m_winDisabled
= NULL
;
1254 wxWindowList::compatibility_iterator node
;
1255 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1257 wxWindow
*winTop
= node
->GetData();
1258 if ( winTop
== winToSkip
)
1261 // we don't need to disable the hidden or already disabled windows
1262 if ( winTop
->IsEnabled() && winTop
->IsShown() )
1268 if ( !m_winDisabled
)
1270 m_winDisabled
= new wxWindowList
;
1273 m_winDisabled
->Append(winTop
);
1278 wxWindowDisabler::~wxWindowDisabler()
1280 wxWindowList::compatibility_iterator node
;
1281 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1283 wxWindow
*winTop
= node
->GetData();
1284 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1288 //else: had been already disabled, don't reenable
1291 delete m_winDisabled
;
1294 // Yield to other apps/messages and disable user input to all windows except
1296 bool wxSafeYield(wxWindow
*win
, bool onlyIfNeeded
)
1298 wxWindowDisabler
wd(win
);
1302 rc
= wxYieldIfNeeded();
1309 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1310 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1313 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1315 return true; // detectable auto-repeat is the only mode MSW supports