- /*-------------------------------------------------------------*
- * Copy the rest of the string and set the cutoff if it was not
- * already set. If the first character of name is a slash, cutoff
- * is not presently set but will be on the first iteration of the
- * loop below.
- *-------------------------------------------------------------*/
-
- for ((*name == DIR_SEPARATOR ? (s = name+1) : (s = name));;) {
- if (*s == DIR_SEPARATOR)
- cutoff = t;
- if (!(*t++ = *s++))
- break;
- }
-
- }
- else {
-
- /*-------------------------------------------------------------*
- * Get the path list from the environment. If the path list is
- * inaccessible for any reason, leave with fatal error.
- *-------------------------------------------------------------*/
-
-#ifdef __MAC__
- if ((s = getenv("Commands")) == (char *) 0)
-#else
- if ((s = getenv("PATH")) == (char *) 0)
-#endif
- fatal_error(FE_PATH, 0);
-
- /*
- * Copy path list into ebuf and set the source pointer to the
- * beginning of this buffer.
- */
-
- strcpy(ebuf, s);
- s = ebuf;
-
- for (;;) {
- t = imagedir;
- while (*s && *s != PATH_SEPARATOR)
- *t++ = *s++;
- if (t > imagedir && *(t - 1) == DIR_SEPARATOR)
- ; /* do nothing -- slash already is in place */
- else
- *t++ = DIR_SEPARATOR; /* put in the slash */
- cutoff = t - 1; /* set cutoff */
- strcpy(t, name);
- if (access(imagedir, R_OK) == 0)
- break;
-
- if (*s)
- s++; /* advance source pointer */
- else
- fatal_error(FE_INFND, 0);
- }
-
- }
-
- /*-------------------------------------------------------------*
- | At this point the full pathname should exist in imagedir and
- | cutoff should be set to the final slash. We must now determine
- | whether the file name is a symbolic link or not and chase it down
- | if it is. Note that we reuse ebuf for getting the link.
- *-------------------------------------------------------------*/
-
-#ifdef HAVE_SYMLINK
- while ((cc = readlink(imagedir, ebuf, 512)) != -1) {
- ebuf[cc] = 0;
- s = ebuf;
- if (*s == DIR_SEPARATOR) {
- t = imagedir;
- }
- else {
- t = cutoff + 1;
- }
- for (;;) {
- if (*s == DIR_SEPARATOR)
- cutoff = t; /* mark the last slash seen */
- if (!(*t++ = *s++)) /* copy the character */
- break;
- }
- }
-
-#endif /* HAVE_SYMLINK */
-
- strcpy(imagename, cutoff + 1); /* keep the image name */
- *(cutoff + 1) = 0; /* chop off the filename part */
-}
-
-#endif
-
-#if wxUSE_GUI
-
-// ----------------------------------------------------------------------------
-// GUI helpers
-// ----------------------------------------------------------------------------
-
-/*
- * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
- * since otherwise the generic code may be pulled in unnecessarily.
- */
-
-#if wxUSE_MSGDLG
-
-int wxMessageBox(const wxString& message, const wxString& caption, long style,
- wxWindow *parent, int WXUNUSED(x), int WXUNUSED(y) )
-{
- wxMessageDialog dialog(parent, message, caption, style);
-
- int ans = dialog.ShowModal();
- switch ( ans )
- {
- case wxID_OK:
- return wxOK;
- case wxID_YES:
- return wxYES;
- case wxID_NO:
- return wxNO;
- case wxID_CANCEL:
- return wxCANCEL;
- }
-
- wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
-
- return wxCANCEL;
-}
-
-#endif // wxUSE_MSGDLG
-
-#if wxUSE_TEXTDLG
-
-wxString wxGetTextFromUser(const wxString& message, const wxString& caption,
- const wxString& defaultValue, wxWindow *parent,
- int x, int y, bool WXUNUSED(centre) )
-{
- wxString str;
- wxTextEntryDialog dialog(parent, message, caption, defaultValue, wxOK|wxCANCEL, wxPoint(x, y));
- if (dialog.ShowModal() == wxID_OK)
- {
- str = dialog.GetValue();
- }
-
- return str;
-}
-
-wxString wxGetPasswordFromUser(const wxString& message,
- const wxString& caption,
- const wxString& defaultValue,
- wxWindow *parent)
-{
- wxString str;
- wxTextEntryDialog dialog(parent, message, caption, defaultValue,
- wxOK | wxCANCEL | wxTE_PASSWORD);
- if ( dialog.ShowModal() == wxID_OK )
- {
- str = dialog.GetValue();
- }
-
- return str;
-}
-
-#endif // wxUSE_TEXTDLG
-
-#if wxUSE_COLOURDLG
-
-wxColour wxGetColourFromUser(wxWindow *parent, const wxColour& colInit)
-{
- wxColourData data;
- data.SetChooseFull(TRUE);
- if ( colInit.Ok() )
- {
- data.SetColour((wxColour &)colInit); // const_cast
- }
-
- wxColour colRet;
- wxColourDialog dialog(parent, &data);
- if ( dialog.ShowModal() == wxID_OK )
- {
- colRet = dialog.GetColourData().GetColour();
- }
- //else: leave it invalid
-
- return colRet;
-}
-
-#endif // wxUSE_COLOURDLG
-
-#if wxUSE_FONTDLG
-
-wxFont wxGetFontFromUser(wxWindow *parent, const wxFont& fontInit)
-{
- wxFontData data;
- if ( fontInit.Ok() )
- {
- data.SetInitialFont(fontInit);
- }
-
- wxFont fontRet;
- wxFontDialog dialog(parent, data);
- if ( dialog.ShowModal() == wxID_OK )
- {
- fontRet = dialog.GetFontData().GetChosenFont();
- }
- //else: leave it invalid
-
- return fontRet;
-}
-
-#endif // wxUSE_FONTDLG
-// ----------------------------------------------------------------------------
-// missing C RTL functions (FIXME shouldn't be here at all)
-// ----------------------------------------------------------------------------
-
-#ifdef __MWERKS__
-#if __MSL__ < 0x7000
-char *strdup(const char *s)
-{
- return strcpy( (char*) malloc( strlen( s ) + 1 ) , s ) ;
-}
-#endif
-int isascii( int c )
-{
- return ( c >= 0 && c < 128 ) ;
-}
-#endif // __MWERKS__
-
-// ----------------------------------------------------------------------------
-// wxSafeYield and supporting functions
-// ----------------------------------------------------------------------------
-
-void wxEnableTopLevelWindows(bool enable)
-{
- wxWindowList::Node *node;
- for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
- node->GetData()->Enable(enable);
-}
-
-wxWindowDisabler::wxWindowDisabler(wxWindow *winToSkip)
-{
- // remember the top level windows which were already disabled, so that we
- // don't reenable them later
- m_winDisabled = NULL;
-
- wxWindowList::Node *node;
- for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
- {
- wxWindow *winTop = node->GetData();
- if ( winTop == winToSkip )
- continue;
-
- if ( winTop->IsEnabled() )
- {
- winTop->Disable();
- }
- else
- {
- if ( !m_winDisabled )
- {
- m_winDisabled = new wxWindowList;
- }
-
- m_winDisabled->Append(winTop);
- }
- }
-}
-
-wxWindowDisabler::~wxWindowDisabler()
-{
- wxWindowList::Node *node;
- for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
- {
- wxWindow *winTop = node->GetData();
- if ( !m_winDisabled || !m_winDisabled->Find(winTop) )
- {
- winTop->Enable();
- }
- //else: had been already disabled, don't reenable
- }
-
- delete m_winDisabled;
-}
-
-// Yield to other apps/messages and disable user input to all windows except
-// the given one
-bool wxSafeYield(wxWindow *win, bool onlyIfNeeded)
-{
- wxWindowDisabler wd(win);
-
- bool rc;
- if (onlyIfNeeded)
- rc = wxYieldIfNeeded();
- else
- rc = wxYield();
-
- return rc;
-}
-
-// ----------------------------------------------------------------------------
-// misc functions
-// ----------------------------------------------------------------------------
-
-// Don't synthesize KeyUp events holding down a key and producing KeyDown
-// events with autorepeat. On by default and always on in wxMSW. wxGTK version
-// in utilsgtk.cpp.
-#ifndef __WXGTK__
-bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
-{
- return TRUE; // detectable auto-repeat is the only mode MSW supports
-}
-#endif // !wxGTK
-
-#endif // wxUSE_GUI
-
-const wxChar *wxGetInstallPrefix()
-{
- wxString prefix;
-
- if ( wxGetEnv(wxT("WXPREFIX"), &prefix) )
- return prefix.c_str();
-
-#ifdef wxINSTALL_PREFIX
- return wxT(wxINSTALL_PREFIX);
-#else
- return wxT("");
-#endif
-}
-
-wxString wxGetDataDir()
-{
- wxString format = wxGetInstallPrefix();
- format << wxFILE_SEP_PATH
- << wxT("share") << wxFILE_SEP_PATH
- << wxT("wx") << wxFILE_SEP_PATH
- << wxT("%i.%i");
- wxString dir;
- dir.Printf(format.c_str(), wxMAJOR_VERSION, wxMINOR_VERSION);
- return dir;
-}