X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dd12575372f29ff5f44cffca2540fcc6ca3c799e..47e59154157bb013ce255a4efa7a615574c974f7:/src/motif/utils.cpp diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp index 6f80f461de..84bc1a6d9a 100644 --- a/src/motif/utils.cpp +++ b/src/motif/utils.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: utils.cpp +// Name: src/motif/utils.cpp // Purpose: Various utilities // Author: Julian Smart // Modified by: @@ -24,12 +24,15 @@ #define XtDisplay XTDISPLAY #endif -#include "wx/setup.h" #include "wx/utils.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/dcmemory.h" + #include "wx/bitmap.h" +#endif + #include "wx/apptrait.h" -#include "wx/app.h" -#include "wx/dcmemory.h" -#include "wx/bitmap.h" #include "wx/evtloop.h" #include @@ -89,7 +92,7 @@ void wxFlushEvents(WXDisplay* wxdisplay) Display *display = (Display*)wxdisplay; wxEventLoop evtLoop; - XSync (display, FALSE); + XSync (display, False); while (evtLoop.Pending()) { @@ -140,27 +143,18 @@ void wxBell() } #endif -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { - static wxToolkitInfo info; + // XmVERSION and XmREVISION are defined in Xm/Xm.h + if ( verMaj ) + *verMaj = XmVERSION; + if ( verMin ) + *verMin = XmREVISION; - info.shortName = _T("motif"); - info.name = _T("wxMotif"); -#ifdef __WXUNIVERSAL__ - info.shortName << _T("univ"); - info.name << _T("/wxUniversal"); -#endif - // FIXME TODO - // This code is WRONG!! Does NOT return the - // Motif version of the libs but the X protocol - // version! - Display *display = wxGlobalDisplay(); - info.versionMajor = ProtocolVersion (display); - info.versionMinor = ProtocolRevision (display); - info.os = wxMOTIF_X; - return info; + return wxPORT_MOTIF; } + // ---------------------------------------------------------------------------- // Reading and writing resources (eg WIN.INI, .Xdefaults) // ---------------------------------------------------------------------------- @@ -177,7 +171,7 @@ static char * GetIniFile (char *dest, const char *filename) { strcpy(dest, filename); } - else if ((home = wxGetUserHome("")) != NULL) + else if ((home = wxGetUserHome()) != NULL) { strcpy(dest, home); if (dest[strlen(dest) - 1] != '/') @@ -197,7 +191,7 @@ static char * GetIniFile (char *dest, const char *filename) return dest; } -static char *GetResourcePath(char *buf, const char *name, bool create = FALSE) +static char *GetResourcePath(char *buf, const char *name, bool create = false) { if (create && wxFileExists (name) ) { strcpy(buf, name); @@ -240,7 +234,7 @@ wxFlushResources (void) { const char *file = node->GetKeyString(); // If file doesn't exist, create it first. - (void)GetResourcePath(nameBuffer, file, TRUE); + (void)GetResourcePath(nameBuffer, file, true); XrmDatabase database = (XrmDatabase) node->Data (); XrmPutFileDatabase (database, nameBuffer); @@ -277,7 +271,7 @@ bool wxWriteResource(const wxString& section, const wxString& entry, const wxStr strcat (resName, entry.c_str()); XrmPutStringResource (&database, resName, value); - return TRUE; + return true; } bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file) @@ -311,7 +305,7 @@ bool wxGetResource(const wxString& section, const wxString& entry, char **value, XrmDatabase database; - if (file != "") + if (!file.empty()) { char buffer[500]; @@ -354,9 +348,9 @@ bool wxGetResource(const wxString& section, const wxString& entry, char **value, *value = new char[xvalue.size + 1]; strncpy (*value, xvalue.addr, (int) xvalue.size); - return TRUE; + return true; } - return FALSE; + return false; } bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file) @@ -367,9 +361,9 @@ bool wxGetResource(const wxString& section, const wxString& entry, float *value, { *value = (float)strtod(s, NULL); delete[] s; - return TRUE; + return true; } - else return FALSE; + else return false; } bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file) @@ -380,9 +374,9 @@ bool wxGetResource(const wxString& section, const wxString& entry, long *value, { *value = strtol(s, NULL, 10); delete[] s; - return TRUE; + return true; } - else return FALSE; + else return false; } bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file) @@ -394,18 +388,18 @@ bool wxGetResource(const wxString& section, const wxString& entry, int *value, c // Handle True, False here // True, Yes, Enables, Set or Activated if (*s == 'T' || *s == 'Y' || *s == 'E' || *s == 'S' || *s == 'A') - *value = TRUE; + *value = true; // False, No, Disabled, Reset, Cleared, Deactivated else if (*s == 'F' || *s == 'N' || *s == 'D' || *s == 'R' || *s == 'C') - *value = FALSE; + *value = false; // Handle as Integer else *value = (int) strtol (s, NULL, 10); delete[] s; - return TRUE; + return true; } else - return FALSE; + return false; } void wxXMergeDatabases (wxApp * theApp, Display * display) @@ -451,7 +445,7 @@ void wxXMergeDatabases (wxApp * theApp, Display * display) environment = GetIniFile (filename, NULL); len = strlen (environment); wxString hostname = wxGetHostName(); - if ( !!hostname ) + if ( !hostname.empty() ) strncat(environment, hostname, 1024 - len); } homeDB = XrmGetFileDatabase (environment); @@ -492,7 +486,7 @@ wxSetDefaultResources (const Widget w, const char **resourceSpec, const char *na { #if (XlibSpecificationRelease>=5) XrmDatabase db = XtDatabase (dpy); - XrmCombineDatabase (rdb, &db, FALSE); + XrmCombineDatabase (rdb, &db, False); #else XrmMergeDatabases (dpy->db, &rdb); dpy->db = rdb; @@ -526,9 +520,9 @@ void wxGetMousePosition( int* x, int* y ) *x = xev.x_root; *y = xev.y_root; #endif -}; +} -// Return TRUE if we have a colour display +// Return true if we have a colour display bool wxColourDisplay() { return wxDisplayDepth() > 1; @@ -592,11 +586,11 @@ bool wxSetDisplay(const wxString& display_name) { gs_displayName = display_name; - if ( display_name.IsEmpty() ) + if ( display_name.empty() ) { gs_currentDisplay = NULL; - return TRUE; + return true; } else { @@ -617,10 +611,10 @@ bool wxSetDisplay(const wxString& display_name) if (display) { gs_currentDisplay = (WXDisplay*) display; - return TRUE; + return true; } else - return FALSE; + return false; } } @@ -664,9 +658,9 @@ void wxHSVToXColor(wxHSV *hsv,XColor *rgb) case 4: r = t, g = p, b = v; break; case 5: r = v, g = p, b = q; break; } - rgb->red = r << 8; - rgb->green = g << 8; - rgb->blue = b << 8; + rgb->red = (unsigned short)(r << 8); + rgb->green = (unsigned short)(g << 8); + rgb->blue = (unsigned short)(b << 8); } void wxXColorToHSV(wxHSV *hsv,XColor *rgb) @@ -757,22 +751,22 @@ wxString wxGetXEventName(XEvent& event) return str; #else int type = event.xany.type; - static char* event_name[] = { - "", "unknown(-)", // 0-1 - "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease", // 2-5 - "MotionNotify", "EnterNotify", "LeaveNotify", "FocusIn", // 6-9 - "FocusOut", "KeymapNotify", "Expose", "GraphicsExpose", // 10-13 - "NoExpose", "VisibilityNotify", "CreateNotify", // 14-16 - "DestroyNotify", "UnmapNotify", "MapNotify", "MapRequest",// 17-20 - "ReparentNotify", "ConfigureNotify", "ConfigureRequest", // 21-23 - "GravityNotify", "ResizeRequest", "CirculateNotify", // 24-26 - "CirculateRequest", "PropertyNotify", "SelectionClear", // 27-29 - "SelectionRequest", "SelectionNotify", "ColormapNotify", // 30-32 - "ClientMessage", "MappingNotify", // 33-34 - "unknown(+)"}; // 35 - type = wxMin(35, type); type = wxMax(1, type); - wxString str(event_name[type]); - return str; + static char* event_name[] = { + wxMOTIF_STR(""), wxMOTIF_STR("unknown(-)"), // 0-1 + wxMOTIF_STR("KeyPress"), wxMOTIF_STR("KeyRelease"), wxMOTIF_STR("ButtonPress"), wxMOTIF_STR("ButtonRelease"), // 2-5 + wxMOTIF_STR("MotionNotify"), wxMOTIF_STR("EnterNotify"), wxMOTIF_STR("LeaveNotify"), wxMOTIF_STR("FocusIn"), // 6-9 + wxMOTIF_STR("FocusOut"), wxMOTIF_STR("KeymapNotify"), wxMOTIF_STR("Expose"), wxMOTIF_STR("GraphicsExpose"), // 10-13 + wxMOTIF_STR("NoExpose"), wxMOTIF_STR("VisibilityNotify"), wxMOTIF_STR("CreateNotify"), // 14-16 + wxMOTIF_STR("DestroyNotify"), wxMOTIF_STR("UnmapNotify"), wxMOTIF_STR("MapNotify"), wxMOTIF_STR("MapRequest"),// 17-20 + wxMOTIF_STR("ReparentNotify"), wxMOTIF_STR("ConfigureNotify"), wxMOTIF_STR("ConfigureRequest"), // 21-23 + wxMOTIF_STR("GravityNotify"), wxMOTIF_STR("ResizeRequest"), wxMOTIF_STR("CirculateNotify"), // 24-26 + wxMOTIF_STR("CirculateRequest"), wxMOTIF_STR("PropertyNotify"), wxMOTIF_STR("SelectionClear"), // 27-29 + wxMOTIF_STR("SelectionRequest"), wxMOTIF_STR("SelectionNotify"), wxMOTIF_STR("ColormapNotify"), // 30-32 + wxMOTIF_STR("ClientMessage"), wxMOTIF_STR("MappingNotify"), // 33-34 + wxMOTIF_STR("unknown(+)")}; // 35 + type = wxMin(35, type); type = wxMax(1, type); + wxString str(event_name[type]); + return str; #endif } #endif @@ -808,6 +802,7 @@ char wxFindMnemonic (const char *s) char* wxFindAccelerator( const char *s ) { #if 1 + wxUnusedVar(s); // VZ: this function returns incorrect keysym which completely breaks kbd // handling return NULL; @@ -875,6 +870,7 @@ char* wxFindAccelerator( const char *s ) XmString wxFindAcceleratorText (const char *s) { #if 1 + wxUnusedVar(s); // VZ: this function returns incorrect keysym which completely breaks kbd // handling return NULL; @@ -905,7 +901,7 @@ void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) NULL); } -void wxDoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour) +void wxDoChangeBackgroundColour(WXWidget widget, const wxColour& backgroundColour, bool changeArmColour) { wxComputeColours (XtDisplay((Widget) widget), & backgroundColour, (wxColour*) NULL); @@ -923,14 +919,17 @@ void wxDoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, boo NULL); } -extern void wxDoChangeFont(WXWidget widget, wxFont& font) +extern void wxDoChangeFont(WXWidget widget, const wxFont& font) { - // Lesstif 0.87 hangs here, but 0.93 does not -#if !wxCHECK_LESSTIF() || wxCHECK_LESSTIF_VERSION( 0, 93 ) + // Lesstif 0.87 hangs here, but 0.93 does not; MBN: sometimes it does +#if !wxCHECK_LESSTIF() // || wxCHECK_LESSTIF_VERSION( 0, 93 ) Widget w = (Widget)widget; XtVaSetValues( w, - wxFont::GetFontTag(), font.GetFontType( XtDisplay(w) ), + wxFont::GetFontTag(), font.GetFontTypeC( XtDisplay(w) ), NULL ); +#else + wxUnusedVar(widget); + wxUnusedVar(font); #endif } @@ -964,7 +963,7 @@ XmString wxStringToXmString( const char* str ) // Creates a bitmap with transparent areas drawn in // the given colour. -wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, wxColour& colour) +wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, const wxColour& colour) { wxBitmap newBitmap(bitmap.GetWidth(), bitmap.GetHeight(), @@ -976,11 +975,10 @@ wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, wxColour& colour) 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); + &srcDC, 0, 0, wxCOPY, true); return newBitmap; }