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 // Array used in DecToHex conversion routine.
113 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
115 // Convert 2-digit hex number to decimal
116 int wxHexToDec(const wxString
& buf
)
118 int firstDigit
, secondDigit
;
120 if (buf
.GetChar(0) >= wxT('A'))
121 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
123 firstDigit
= buf
.GetChar(0) - wxT('0');
125 if (buf
.GetChar(1) >= wxT('A'))
126 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
128 secondDigit
= buf
.GetChar(1) - wxT('0');
130 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
133 // Convert decimal integer to 2-character hex string
134 void wxDecToHex(int dec
, wxChar
*buf
)
136 int firstDigit
= (int)(dec
/16.0);
137 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
138 buf
[0] = hexArray
[firstDigit
];
139 buf
[1] = hexArray
[secondDigit
];
143 // Convert decimal integer to 2-character hex string
144 wxString
wxDecToHex(int dec
)
147 wxDecToHex(dec
, buf
);
148 return wxString(buf
);
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 // Return the current date/time
160 wxDateTime now
= wxDateTime::Now();
163 return wxEmptyString
;
166 time_t now
= time((time_t *) NULL
);
167 char *date
= ctime(&now
);
169 return wxString::FromAscii(date
);
173 void wxUsleep(unsigned long milliseconds
)
175 wxMilliSleep(milliseconds
);
178 const wxChar
*wxGetInstallPrefix()
182 if ( wxGetEnv(wxT("WXPREFIX"), &prefix
) )
183 return prefix
.c_str();
185 #ifdef wxINSTALL_PREFIX
186 return wxT(wxINSTALL_PREFIX
);
188 return wxEmptyString
;
192 wxString
wxGetDataDir()
194 wxString dir
= wxGetInstallPrefix();
195 dir
<< wxFILE_SEP_PATH
<< wxT("share") << wxFILE_SEP_PATH
<< wxT("wx");
199 bool wxIsPlatformLittleEndian()
201 // Are we little or big endian? This method is from Harbison & Steele.
205 char c
[sizeof(long)];
214 * Class to make it easier to specify platform-dependent values
217 wxArrayInt
* wxPlatform::sm_customPlatforms
= NULL
;
219 void wxPlatform::Copy(const wxPlatform
& platform
)
221 m_longValue
= platform
.m_longValue
;
222 m_doubleValue
= platform
.m_doubleValue
;
223 m_stringValue
= platform
.m_stringValue
;
226 wxPlatform
wxPlatform::If(int platform
, long value
)
229 return wxPlatform(value
);
234 wxPlatform
wxPlatform::IfNot(int platform
, long value
)
237 return wxPlatform(value
);
242 wxPlatform
& wxPlatform::ElseIf(int platform
, long value
)
249 wxPlatform
& wxPlatform::ElseIfNot(int platform
, long value
)
256 wxPlatform
wxPlatform::If(int platform
, double value
)
259 return wxPlatform(value
);
264 wxPlatform
wxPlatform::IfNot(int platform
, double value
)
267 return wxPlatform(value
);
272 wxPlatform
& wxPlatform::ElseIf(int platform
, double value
)
275 m_doubleValue
= value
;
279 wxPlatform
& wxPlatform::ElseIfNot(int platform
, double value
)
282 m_doubleValue
= value
;
286 wxPlatform
wxPlatform::If(int platform
, const wxString
& value
)
289 return wxPlatform(value
);
294 wxPlatform
wxPlatform::IfNot(int platform
, const wxString
& value
)
297 return wxPlatform(value
);
302 wxPlatform
& wxPlatform::ElseIf(int platform
, const wxString
& value
)
305 m_stringValue
= value
;
309 wxPlatform
& wxPlatform::ElseIfNot(int platform
, const wxString
& value
)
312 m_stringValue
= value
;
316 wxPlatform
& wxPlatform::Else(long value
)
322 wxPlatform
& wxPlatform::Else(double value
)
324 m_doubleValue
= value
;
328 wxPlatform
& wxPlatform::Else(const wxString
& value
)
330 m_stringValue
= value
;
334 void wxPlatform::AddPlatform(int platform
)
336 if (!sm_customPlatforms
)
337 sm_customPlatforms
= new wxArrayInt
;
338 sm_customPlatforms
->Add(platform
);
341 void wxPlatform::ClearPlatforms()
343 delete sm_customPlatforms
;
344 sm_customPlatforms
= NULL
;
347 /// Function for testing current platform
349 bool wxPlatform::Is(int platform
)
352 if (platform
== wxOS_WINDOWS
)
356 if (platform
== wxOS_WINDOWS_CE
)
362 // FIXME: wxWinPocketPC and wxWinSmartPhone are unknown symbols
364 #if defined(__WXWINCE__) && defined(__POCKETPC__)
365 if (platform
== wxWinPocketPC
)
368 #if defined(__WXWINCE__) && defined(__SMARTPHONE__)
369 if (platform
== wxWinSmartPhone
)
376 if (platform
== wxPORT_GTK
)
380 if (platform
== wxPORT_MAC
)
384 if (platform
== wxPORT_X11
)
388 if (platform
== wxOS_UNIX
)
392 if (platform
== wxPORT_MGL
)
396 if (platform
== wxOS_OS2
)
400 if (platform
== wxPORT_PM
)
404 if (platform
== wxPORT_MAC
)
408 if (sm_customPlatforms
&& sm_customPlatforms
->Index(platform
) != wxNOT_FOUND
)
414 // ----------------------------------------------------------------------------
415 // network and user id functions
416 // ----------------------------------------------------------------------------
418 // Get Full RFC822 style email address
419 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
421 wxString email
= wxGetEmailAddress();
425 wxStrncpy(address
, email
, maxSize
- 1);
426 address
[maxSize
- 1] = wxT('\0');
431 wxString
wxGetEmailAddress()
435 wxString host
= wxGetFullHostName();
438 wxString user
= wxGetUserId();
441 email
<< user
<< wxT('@') << host
;
448 wxString
wxGetUserId()
450 static const int maxLoginLen
= 256; // FIXME arbitrary number
453 bool ok
= wxGetUserId(wxStringBuffer(buf
, maxLoginLen
), maxLoginLen
);
461 wxString
wxGetUserName()
463 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
466 bool ok
= wxGetUserName(wxStringBuffer(buf
, maxUserNameLen
), maxUserNameLen
);
474 wxString
wxGetHostName()
476 static const size_t hostnameSize
= 257;
479 bool ok
= wxGetHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
487 wxString
wxGetFullHostName()
489 static const size_t hostnameSize
= 257;
492 bool ok
= wxGetFullHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
500 wxString
wxGetHomeDir()
510 wxString
wxGetCurrentDir()
517 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
522 if ( errno
!= ERANGE
)
524 wxLogSysError(_T("Failed to get current directory"));
526 return wxEmptyString
;
530 // buffer was too small, retry with a larger one
542 // ----------------------------------------------------------------------------
544 // ----------------------------------------------------------------------------
546 // wxDoExecuteWithCapture() helper: reads an entire stream into one array
548 // returns true if ok, false if error
550 static bool ReadAll(wxInputStream
*is
, wxArrayString
& output
)
552 wxCHECK_MSG( is
, false, _T("NULL stream in wxExecute()?") );
554 // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
557 wxTextInputStream
tis(*is
);
561 wxString line
= tis
.ReadLine();
563 // check for EOF before other errors as it's not really an error
566 // add the last, possibly incomplete, line
572 // any other error is fatal
581 #endif // wxUSE_STREAMS
583 // this is a private function because it hasn't a clean interface: the first
584 // array is passed by reference, the second by pointer - instead we have 2
585 // public versions of wxExecute() below
586 static long wxDoExecuteWithCapture(const wxString
& command
,
587 wxArrayString
& output
,
588 wxArrayString
* error
,
591 // create a wxProcess which will capture the output
592 wxProcess
*process
= new wxProcess
;
595 long rc
= wxExecute(command
, wxEXEC_SYNC
| flags
, process
);
600 if ( !ReadAll(process
->GetInputStream(), output
) )
605 if ( !ReadAll(process
->GetErrorStream(), *error
) )
613 #endif // wxUSE_STREAMS/!wxUSE_STREAMS
620 long wxExecute(const wxString
& command
, wxArrayString
& output
, int flags
)
622 return wxDoExecuteWithCapture(command
, output
, NULL
, flags
);
625 long wxExecute(const wxString
& command
,
626 wxArrayString
& output
,
627 wxArrayString
& error
,
630 return wxDoExecuteWithCapture(command
, output
, &error
, flags
);
633 // ----------------------------------------------------------------------------
634 // wxApp::Yield() wrappers for backwards compatibility
635 // ----------------------------------------------------------------------------
639 return wxTheApp
&& wxTheApp
->Yield();
642 bool wxYieldIfNeeded()
644 return wxTheApp
&& wxTheApp
->Yield(true);
648 static long wxCurrentId
= 100;
652 // skip the part of IDs space that contains hard-coded values:
653 if (wxCurrentId
== wxID_LOWEST
)
654 wxCurrentId
= wxID_HIGHEST
+ 1;
656 return wxCurrentId
++;
660 wxGetCurrentId(void) { return wxCurrentId
; }
663 wxRegisterId (long id
)
665 if (id
>= wxCurrentId
)
666 wxCurrentId
= id
+ 1;
671 // ============================================================================
672 // GUI-only functions from now on
673 // ============================================================================
677 // ----------------------------------------------------------------------------
678 // Launch default browser
679 // ----------------------------------------------------------------------------
682 // Private method in Objective-C++ source file.
683 bool wxCocoaLaunchDefaultBrowser(const wxString
& url
, int flags
);
686 bool wxLaunchDefaultBrowser(const wxString
& urlOrig
, int flags
)
690 // set the scheme of url to http if it does not have one
691 // RR: This doesn't work if the url is just a local path
692 wxString
url(urlOrig
);
694 if ( !uri
.HasScheme() )
696 if (wxFileExists(urlOrig
))
697 url
.Prepend( wxT("file://") );
699 url
.Prepend(wxT("http://"));
703 #if defined(__WXMSW__)
706 if ( flags
& wxBROWSER_NEW_WINDOW
)
708 // ShellExecuteEx() opens the URL in an existing window by default so
709 // we can't use it if we need a new window
710 wxRegKey
key(wxRegKey::HKCR
, uri
.GetScheme() + _T("\\shell\\open"));
713 // try default browser, it must be registered at least for http URLs
714 key
.SetName(wxRegKey::HKCR
, _T("http\\shell\\open"));
719 wxRegKey
keyDDE(key
, wxT("DDEExec"));
720 if ( keyDDE
.Exists() )
722 const wxString ddeTopic
= wxRegKey(keyDDE
, wxT("topic"));
724 // we only know the syntax of WWW_OpenURL DDE request for IE,
725 // optimistically assume that all other browsers are compatible
728 bool ok
= ddeTopic
== wxT("WWW_OpenURL");
731 ddeCmd
= keyDDE
.QueryDefaultValue();
732 ok
= !ddeCmd
.empty();
737 // for WWW_OpenURL, the index of the window to open the URL
738 // in is -1 (meaning "current") by default, replace it with
739 // 0 which means "new" (see KB article 160957)
740 ok
= ddeCmd
.Replace(wxT("-1"), wxT("0"),
741 false /* only first occurence */) == 1;
746 // and also replace the parameters: the topic should
747 // contain a placeholder for the URL
748 ok
= ddeCmd
.Replace(wxT("%1"), url
, false) == 1;
753 // try to send it the DDE request now but ignore the errors
756 const wxString ddeServer
= wxRegKey(keyDDE
, wxT("application"));
757 if ( wxExecuteDDE(ddeServer
, ddeTopic
, ddeCmd
) )
760 // this is not necessarily an error: maybe browser is
761 // simply not running, but no matter, in any case we're
762 // going to launch it using ShellExecuteEx() below now and
763 // we shouldn't try to open a new window if we open a new
771 WinStruct
<SHELLEXECUTEINFO
> sei
;
772 sei
.lpFile
= url
.c_str();
773 sei
.lpVerb
= _T("open");
774 sei
.nShow
= SW_SHOWNORMAL
;
776 ::ShellExecuteEx(&sei
);
778 const int nResult
= (int) sei
.hInstApp
;
780 // Firefox returns file not found for some reason, so make an exception
782 if ( nResult
> 32 || nResult
== SE_ERR_FNF
)
785 // Log something if SE_ERR_FNF happens
786 if ( nResult
== SE_ERR_FNF
)
787 wxLogDebug(wxT("SE_ERR_FNF from ShellExecute -- maybe FireFox?"));
788 #endif // __WXDEBUG__
791 #elif defined(__WXCOCOA__)
792 // NOTE: We need to call the real implementation from src/cocoa/utils.mm
793 // because the code must use Objective-C features.
794 return wxCocoaLaunchDefaultBrowser(url
, flags
);
795 #elif defined(__WXMAC__)
801 err
= ICStart(&inst
, 'STKA'); // put your app creator code here
805 err
= ICFindConfigFile(inst
, 0, NULL
);
809 ConstStr255Param hint
= 0;
811 endSel
= url
.length();
812 err
= ICLaunchURL(inst
, hint
, url
.fn_str(), endSel
, &startSel
, &endSel
);
814 wxLogDebug(wxT("ICLaunchURL error %d"), (int) err
);
821 wxLogDebug(wxT("ICStart error %d"), (int) err
);
825 // (non-Mac, non-MSW)
829 wxString desktop
= wxTheApp
->GetTraits()->GetDesktopEnvironment();
831 // GNOME and KDE desktops have some applications which should be always installed
832 // together with their main parts, which give us the
833 if (desktop
== wxT("GNOME"))
835 wxArrayString errors
;
836 wxArrayString output
;
838 // gconf will tell us the path of the application to use as browser
839 long res
= wxExecute( wxT("gconftool-2 --get /desktop/gnome/applications/browser/exec"),
840 output
, errors
, wxEXEC_NODISABLE
);
841 if (res
>= 0 && errors
.GetCount() == 0)
843 wxString cmd
= output
[0];
844 cmd
<< _T(' ') << url
;
849 else if (desktop
== wxT("KDE"))
851 // kfmclient directly opens the given URL
852 if (wxExecute(wxT("kfmclient openURL ") + url
))
861 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(_T("html"));
865 ft
->GetMimeType(&mt
);
867 ok
= ft
->GetOpenCommand(&cmd
, wxFileType::MessageParameters(url
));
870 #endif // wxUSE_MIMETYPE
872 if ( !ok
|| cmd
.empty() )
874 // fallback to checking for the BROWSER environment variable
875 cmd
= wxGetenv(wxT("BROWSER"));
877 cmd
<< _T(' ') << url
;
880 ok
= ( !cmd
.empty() && wxExecute(cmd
) );
884 // no file type for HTML extension
885 wxLogError(_T("No default application configured for HTML files."));
887 #endif // !wxUSE_MIMETYPE && !__WXMSW__
889 wxLogSysError(_T("Failed to open URL \"%s\" in default browser."),
895 // ----------------------------------------------------------------------------
896 // Menu accelerators related functions
897 // ----------------------------------------------------------------------------
899 wxChar
*wxStripMenuCodes(const wxChar
*in
, wxChar
*out
)
902 wxString s
= wxMenuItem::GetLabelFromText(in
);
905 wxString s
= wxStripMenuCodes(str
);
906 #endif // wxUSE_MENUS
909 // go smash their buffer if it's not big enough - I love char * params
910 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
914 out
= new wxChar
[s
.length() + 1];
915 wxStrcpy(out
, s
.c_str());
921 wxString
wxStripMenuCodes(const wxString
& in
, int flags
)
923 wxASSERT_MSG( flags
, _T("this is useless to call without any flags") );
927 size_t len
= in
.length();
930 for ( size_t n
= 0; n
< len
; n
++ )
933 if ( (flags
& wxStrip_Mnemonics
) && ch
== _T('&') )
935 // skip it, it is used to introduce the accel char (or to quote
936 // itself in which case it should still be skipped): note that it
937 // can't be the last character of the string
940 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
944 // use the next char instead
948 else if ( (flags
& wxStrip_Accel
) && ch
== _T('\t') )
950 // everything after TAB is accel string, exit the loop
960 // ----------------------------------------------------------------------------
961 // Window search functions
962 // ----------------------------------------------------------------------------
965 * If parent is non-NULL, look through children for a label or title
966 * matching the specified string. If NULL, look through all top-level windows.
971 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
973 return wxWindow::FindWindowByLabel( title
, parent
);
978 * If parent is non-NULL, look through children for a name
979 * matching the specified string. If NULL, look through all top-level windows.
984 wxFindWindowByName (const wxString
& name
, wxWindow
* parent
)
986 return wxWindow::FindWindowByName( name
, parent
);
989 // Returns menu item id or wxNOT_FOUND if none.
991 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
994 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
996 return menuBar
->FindMenuItem (menuString
, itemString
);
997 #endif // wxUSE_MENUS
1002 // Try to find the deepest child that contains 'pt'.
1003 // We go backwards, to try to allow for controls that are spacially
1004 // within other controls, but are still siblings (e.g. buttons within
1005 // static boxes). Static boxes are likely to be created _before_ controls
1006 // that sit inside them.
1007 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
1009 if (!win
->IsShown())
1012 // Hack for wxNotebook case: at least in wxGTK, all pages
1013 // claim to be shown, so we must only deal with the selected one.
1015 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
1017 wxNotebook
* nb
= (wxNotebook
*) win
;
1018 int sel
= nb
->GetSelection();
1021 wxWindow
* child
= nb
->GetPage(sel
);
1022 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
1029 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetLast();
1032 wxWindow
* child
= node
->GetData();
1033 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
1036 node
= node
->GetPrevious();
1039 wxPoint pos
= win
->GetPosition();
1040 wxSize sz
= win
->GetSize();
1041 if ( !win
->IsTopLevel() && win
->GetParent() )
1043 pos
= win
->GetParent()->ClientToScreen(pos
);
1046 wxRect
rect(pos
, sz
);
1047 if (rect
.Contains(pt
))
1053 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
1055 // Go backwards through the list since windows
1056 // on top are likely to have been appended most
1058 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetLast();
1061 wxWindow
* win
= node
->GetData();
1062 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
1065 node
= node
->GetPrevious();
1070 // ----------------------------------------------------------------------------
1072 // ----------------------------------------------------------------------------
1075 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
1076 * since otherwise the generic code may be pulled in unnecessarily.
1081 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
1082 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
1084 long decorated_style
= style
;
1086 if ( ( style
& ( wxICON_EXCLAMATION
| wxICON_HAND
| wxICON_INFORMATION
| wxICON_QUESTION
) ) == 0 )
1088 decorated_style
|= ( style
& wxYES
) ? wxICON_QUESTION
: wxICON_INFORMATION
;
1091 wxMessageDialog
dialog(parent
, message
, caption
, decorated_style
);
1093 int ans
= dialog
.ShowModal();
1106 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
1111 #endif // wxUSE_MSGDLG
1115 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
1116 const wxString
& defaultValue
, wxWindow
*parent
,
1117 wxCoord x
, wxCoord y
, bool centre
)
1120 long style
= wxTextEntryDialogStyle
;
1127 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, style
, wxPoint(x
, y
));
1129 if (dialog
.ShowModal() == wxID_OK
)
1131 str
= dialog
.GetValue();
1137 wxString
wxGetPasswordFromUser(const wxString
& message
,
1138 const wxString
& caption
,
1139 const wxString
& defaultValue
,
1141 wxCoord x
, wxCoord y
, bool centre
)
1144 long style
= wxTextEntryDialogStyle
;
1151 wxPasswordEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
1152 style
, wxPoint(x
, y
));
1153 if ( dialog
.ShowModal() == wxID_OK
)
1155 str
= dialog
.GetValue();
1161 #endif // wxUSE_TEXTDLG
1165 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
, const wxString
& caption
)
1168 data
.SetChooseFull(true);
1171 data
.SetColour((wxColour
&)colInit
); // const_cast
1175 wxColourDialog
dialog(parent
, &data
);
1176 if (!caption
.empty())
1177 dialog
.SetTitle(caption
);
1178 if ( dialog
.ShowModal() == wxID_OK
)
1180 colRet
= dialog
.GetColourData().GetColour();
1182 //else: leave it invalid
1187 #endif // wxUSE_COLOURDLG
1191 wxFont
wxGetFontFromUser(wxWindow
*parent
, const wxFont
& fontInit
, const wxString
& caption
)
1194 if ( fontInit
.Ok() )
1196 data
.SetInitialFont(fontInit
);
1200 wxFontDialog
dialog(parent
, data
);
1201 if (!caption
.empty())
1202 dialog
.SetTitle(caption
);
1203 if ( dialog
.ShowModal() == wxID_OK
)
1205 fontRet
= dialog
.GetFontData().GetChosenFont();
1207 //else: leave it invalid
1212 #endif // wxUSE_FONTDLG
1214 // ----------------------------------------------------------------------------
1215 // wxSafeYield and supporting functions
1216 // ----------------------------------------------------------------------------
1218 void wxEnableTopLevelWindows(bool enable
)
1220 wxWindowList::compatibility_iterator node
;
1221 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1222 node
->GetData()->Enable(enable
);
1225 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1227 // remember the top level windows which were already disabled, so that we
1228 // don't reenable them later
1229 m_winDisabled
= NULL
;
1231 wxWindowList::compatibility_iterator node
;
1232 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1234 wxWindow
*winTop
= node
->GetData();
1235 if ( winTop
== winToSkip
)
1238 // we don't need to disable the hidden or already disabled windows
1239 if ( winTop
->IsEnabled() && winTop
->IsShown() )
1245 if ( !m_winDisabled
)
1247 m_winDisabled
= new wxWindowList
;
1250 m_winDisabled
->Append(winTop
);
1255 wxWindowDisabler::~wxWindowDisabler()
1257 wxWindowList::compatibility_iterator node
;
1258 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1260 wxWindow
*winTop
= node
->GetData();
1261 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1265 //else: had been already disabled, don't reenable
1268 delete m_winDisabled
;
1271 // Yield to other apps/messages and disable user input to all windows except
1273 bool wxSafeYield(wxWindow
*win
, bool onlyIfNeeded
)
1275 wxWindowDisabler
wd(win
);
1279 rc
= wxYieldIfNeeded();
1286 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1287 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1290 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1292 return true; // detectable auto-repeat is the only mode MSW supports