X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b5f62a0b2db198609b45dec622a018dae37008e..e2a5251d0109a1be6b9ce5c818d89f56ebfaeae1:/src/motif/utils.cpp?ds=sidebyside diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp index 179a3a43d6..56c48759cb 100644 --- a/src/motif/utils.cpp +++ b/src/motif/utils.cpp @@ -25,7 +25,8 @@ #include "wx/app.h" #include "wx/msgdlg.h" #include "wx/cursor.h" -#include "wx/window.h" // for wxTopLevelWindows +#include "wx/dcmemory.h" +#include "wx/bitmap.h" #include #include @@ -37,7 +38,6 @@ #include #include #include -// #include #include #if (defined(__SUNCC__) || defined(__CLCC__)) @@ -50,14 +50,8 @@ #include "wx/unix/execute.h" -#ifdef __WXMOTIF__ #include #include "wx/motif/private.h" -#endif - -#ifdef __WXX11__ -#include "wx/x11/private.h" -#endif #if wxUSE_RESOURCES #include "X11/Xresource.h" @@ -81,7 +75,9 @@ #define DEFAULT_XRESOURCE_DIR "/usr/lib/X11/app-defaults" #endif +#if wxUSE_RESOURCES static char *GetIniFile (char *dest, const char *filename); +#endif // ============================================================================ // implementation @@ -98,7 +94,6 @@ void wxFlushEvents() XSync (display, FALSE); -#ifdef __WXMOTIF__ // XtAppPending returns availability of events AND timers/inputs, which // are processed via callbacks, so XtAppNextEvent will not return if // there are no events. So added '& XtIMXEvent' - Sergey. @@ -108,18 +103,13 @@ void wxFlushEvents() // Jan Lessner: works better when events are non-X events XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMXEvent); } -#endif -#ifdef __WXX11__ - // TODO for X11 - // ?? -#endif } +#if 0 // Check whether this window wants to process messages, e.g. Stop button // in long calculations. bool wxCheckForInterrupt(wxWindow *wnd) { -#ifdef __WXMOTIF__ wxCHECK_MSG( wnd, FALSE, "NULL window in wxCheckForInterrupt" ); Display *dpy=(Display*) wnd->GetXDisplay(); @@ -146,16 +136,13 @@ bool wxCheckForInterrupt(wxWindow *wnd) } return hadEvents; -#else - wxASSERT_MSG(FALSE, "wxCheckForInterrupt not yet implemented."); - return FALSE; -#endif } +#endif // ---------------------------------------------------------------------------- // wxExecute stuff // ---------------------------------------------------------------------------- -#ifdef __WXMOTIF__ + static void xt_notify_end_process(XtPointer data, int *WXUNUSED(fid), XtInputId *id) { @@ -168,11 +155,9 @@ static void xt_notify_end_process(XtPointer data, int *WXUNUSED(fid), XtRemoveInput(*id); } -#endif int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) { -#ifdef __WXMOTIF__ XtInputId id = XtAppAddInput((XtAppContext) wxTheApp->GetAppContext(), fd, (XtPointer *) XtInputReadMask, @@ -180,11 +165,6 @@ int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) (XtPointer) proc_data); return (int)id; -#endif -#ifdef __WXX11__ - // TODO - return 0; -#endif } // ---------------------------------------------------------------------------- @@ -200,7 +180,6 @@ void wxBell() int wxGetOsVersion(int *majorVsn, int *minorVsn) { -#ifdef __WXMOTIF__ // FIXME TODO // This code is WRONG!! Does NOT return the // Motif version of the libs but the X protocol @@ -212,20 +191,14 @@ int wxGetOsVersion(int *majorVsn, int *minorVsn) *minorVsn = ProtocolRevision (display); return wxMOTIF_X; -#endif -#ifdef __WXX11__ - if (majorVsn) - *majorVsn = 0; - if (minorVsn) - *minorVsn = 0; - return wxX11; -#endif } // ---------------------------------------------------------------------------- // Reading and writing resources (eg WIN.INI, .Xdefaults) // ---------------------------------------------------------------------------- +#if wxUSE_RESOURCES + // Read $HOME for what it says is home, if not // read $USER or $LOGNAME for user name else determine // the Real User, then determine the Real home dir. @@ -256,8 +229,6 @@ static char * GetIniFile (char *dest, const char *filename) return dest; } -#if wxUSE_RESOURCES - static char *GetResourcePath(char *buf, const char *name, bool create = FALSE) { if (create && wxFileExists (name) ) { @@ -271,7 +242,7 @@ static char *GetResourcePath(char *buf, const char *name, bool create = FALSE) // Put in standard place for resource files if not absolute strcpy (buf, DEFAULT_XRESOURCE_DIR); strcat (buf, "/"); - strcat (buf, (const char*) wxFileNameFromPath (name)); + strcat (buf, wxFileNameFromPath (name).c_str()); } if (create) { @@ -333,9 +304,9 @@ bool wxWriteResource(const wxString& section, const wxString& entry, const wxStr } char resName[300]; - strcpy (resName, (const char*) section); + strcpy (resName, section.c_str()); strcat (resName, "."); - strcat (resName, (const char*) entry); + strcat (resName, entry.c_str()); XrmPutStringResource (&database, resName, value); return TRUE; @@ -479,7 +450,7 @@ void wxXMergeDatabases (wxApp * theApp, Display * display) wxString classname = theApp->GetClassName(); char name[256]; (void) strcpy (name, "/usr/lib/X11/app-defaults/"); - (void) strcat (name, (const char*) classname); + (void) strcat (name, classname.c_str()); /* Get application defaults file, if any */ applicationDB = XrmGetFileDatabase (name); @@ -644,16 +615,11 @@ WXDisplay *wxGetDisplay() { if (gs_currentDisplay) return gs_currentDisplay; -#ifdef __WXMOTIF__ if (wxTheApp && wxTheApp->GetTopLevelWidget()) return XtDisplay ((Widget) wxTheApp->GetTopLevelWidget()); else if (wxTheApp) return wxTheApp->GetInitialDisplay(); return NULL; -#endif -#ifdef __WXX11__ - return wxApp::GetDisplay(); -#endif } bool wxSetDisplay(const wxString& display_name) @@ -668,13 +634,12 @@ bool wxSetDisplay(const wxString& display_name) } else { -#ifdef __WXMOTIF__ Cardinal argc = 0; Display *display = XtOpenDisplay((XtAppContext) wxTheApp->GetAppContext(), - (const char*) display_name, - (const char*) wxTheApp->GetAppName(), - (const char*) wxTheApp->GetClassName(), + display_name.c_str(), + wxTheApp->GetAppName().c_str(), + wxTheApp->GetClassName().c_str(), NULL, #if XtSpecificationRelease < 5 0, &argc, @@ -690,18 +655,6 @@ bool wxSetDisplay(const wxString& display_name) } else return FALSE; -#endif -#ifdef __WXX11__ - Display* display = XOpenDisplay((char*) display_name.c_str()); - - if (display) - { - gs_currentDisplay = (WXDisplay*) display; - return TRUE; - } - else - return FALSE; -#endif } } @@ -1101,7 +1054,6 @@ wxString wxGetXEventName(XEvent& event) } #endif -#ifdef __WXMOTIF__ // ---------------------------------------------------------------------------- // accelerators // ---------------------------------------------------------------------------- @@ -1206,9 +1158,6 @@ XmString wxFindAcceleratorText (const char *s) } -// These functions duplicate those in wxWindow, but are needed -// for use outside of wxWindow (e.g. wxMenu, wxMenuBar). - // Change a widget's foreground and background colours. void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) @@ -1245,8 +1194,17 @@ void wxDoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, boo NULL); } +extern void wxDoChangeFont(WXWidget widget, wxFont& font) +{ + // Lesstif 0.87 hangs here, but 0.93 does not +#if !wxCHECK_LESSTIF() || wxCHECK_LESSTIF_VERSION( 0, 93 ) + Widget w = (Widget)widget; + XtVaSetValues( w, + wxFont::GetFontTag(), font.GetFontType( XtDisplay(w) ), + NULL ); #endif - // __WXMOTIF__ + +} bool wxWindowIsVisible(Window win) { @@ -1255,3 +1213,53 @@ bool wxWindowIsVisible(Window win) return (wa.map_state == IsViewable); } + +wxString wxXmStringToString( const XmString& xmString ) +{ + char *txt; + if( XmStringGetLtoR( xmString, XmSTRING_DEFAULT_CHARSET, &txt ) ) + { + wxString str(txt); + XtFree (txt); + return str; + } + + return wxEmptyString; +} + +XmString wxStringToXmString( const wxString& str ) +{ + return XmStringCreateLtoR((char *)str.c_str(), XmSTRING_DEFAULT_CHARSET); +} + +XmString wxStringToXmString( const char* str ) +{ + return XmStringCreateLtoR((char *)str, XmSTRING_DEFAULT_CHARSET); +} + +// ---------------------------------------------------------------------------- +// wxBitmap utility functions +// ---------------------------------------------------------------------------- + +// Creates a bitmap with transparent areas drawn in +// the given colour. +wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, wxColour& colour) +{ + wxBitmap newBitmap(bitmap.GetWidth(), + bitmap.GetHeight(), + bitmap.GetDepth()); + wxMemoryDC destDC; + wxMemoryDC srcDC; + + srcDC.SelectObject(bitmap); + destDC.SelectObject(newBitmap); + + wxBrush brush(colour, wxSOLID); + // destDC.SetOptimization(FALSE); + destDC.SetBackground(brush); + destDC.Clear(); + destDC.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), + &srcDC, 0, 0, wxCOPY, TRUE); + + return newBitmap; +}