From 45ff6421e6d0327584bb85aeb5bda8be48b6ca5e Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 14 Feb 2002 11:07:26 +0000 Subject: [PATCH] Removed wxBuffer from several ports; added function to get XEvent name; started on commandline parsing for wxX11 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14197 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/utils.h | 3 +++ include/wx/x11/privx.h | 5 ++++ src/common/filefn.cpp | 2 -- src/gtk/app.cpp | 5 ---- src/gtk/data.cpp | 3 --- src/gtk1/app.cpp | 5 ---- src/gtk1/data.cpp | 3 --- src/mgl/app.cpp | 4 --- src/mgl/data.cpp | 3 --- src/motif/app.cpp | 6 ----- src/motif/control.cpp | 7 +++--- src/motif/data.cpp | 3 --- src/motif/menu.cpp | 2 -- src/motif/window.cpp | 8 +++--- src/x11/app.cpp | 57 ++++++++++++++++++++++++++++-------------- src/x11/data.cpp | 3 --- src/x11/utils.cpp | 40 +++++++++++++++++++++++------ 17 files changed, 86 insertions(+), 73 deletions(-) diff --git a/include/wx/utils.h b/include/wx/utils.h index f3cb1257fb..fd8f12f022 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -57,7 +57,10 @@ class WXDLLEXPORT wxPoint; // ---------------------------------------------------------------------------- // Useful buffer (FIXME VZ: To be removed!!!) +// Now only needed in Mac and MSW ports +#if !defined(__WXMOTIF__) && !defined(__WXGTK__) && !defined(__WXX11__) && !defined(__WXMGL__) WXDLLEXPORT_DATA(extern wxChar*) wxBuffer; +#endif // Make a copy of this string using 'new' WXDLLEXPORT wxChar* copystring(const wxChar *s); diff --git a/include/wx/x11/privx.h b/include/wx/x11/privx.h index 36f597fd9d..a55f980277 100644 --- a/include/wx/x11/privx.h +++ b/include/wx/x11/privx.h @@ -69,5 +69,10 @@ void wxXColorToHSV(wxHSV *hsv,XColor *xcolor); void wxAllocNearestColor(Display *display,Colormap colormap,XColor *xcolor); void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor); +// For debugging +#ifdef __WXDEBUG__ +wxString wxGetXEventName(XEvent& event); +#endif + #endif // _WX_PRIVX_H_ diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 583c0711b3..786381d64b 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -142,8 +142,6 @@ #define _MAXPATHLEN 1024 #endif -extern wxChar *wxBuffer; - #ifdef __WXMAC__ # include "MoreFiles.h" # include "MoreFilesExtras.h" diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index b25fce3b1c..65710bb24d 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -564,8 +564,6 @@ void wxApp::DeletePendingObjects() bool wxApp::Initialize() { - wxBuffer = new wxChar[BUFSIZ + 512]; - wxClassInfo::InitializeClasses(); #if wxUSE_INTL @@ -613,9 +611,6 @@ void wxApp::CleanUp() delete wxTheApp; wxTheApp = (wxApp*) NULL; - delete[] wxBuffer; - wxBuffer = NULL; - wxClassInfo::CleanUpClasses(); #if wxUSE_THREADS diff --git a/src/gtk/data.cpp b/src/gtk/data.cpp index dc6b6523a8..ba8a0ba0e5 100644 --- a/src/gtk/data.cpp +++ b/src/gtk/data.cpp @@ -25,9 +25,6 @@ #define _MAXPATHLEN 500 -/* Useful buffer, initialized in wxCommonInit */ -wxChar *wxBuffer = (wxChar *) NULL; - /* Windows List */ wxWindowList wxTopLevelWindows; diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp index b25fce3b1c..65710bb24d 100644 --- a/src/gtk1/app.cpp +++ b/src/gtk1/app.cpp @@ -564,8 +564,6 @@ void wxApp::DeletePendingObjects() bool wxApp::Initialize() { - wxBuffer = new wxChar[BUFSIZ + 512]; - wxClassInfo::InitializeClasses(); #if wxUSE_INTL @@ -613,9 +611,6 @@ void wxApp::CleanUp() delete wxTheApp; wxTheApp = (wxApp*) NULL; - delete[] wxBuffer; - wxBuffer = NULL; - wxClassInfo::CleanUpClasses(); #if wxUSE_THREADS diff --git a/src/gtk1/data.cpp b/src/gtk1/data.cpp index dc6b6523a8..ba8a0ba0e5 100644 --- a/src/gtk1/data.cpp +++ b/src/gtk1/data.cpp @@ -25,9 +25,6 @@ #define _MAXPATHLEN 500 -/* Useful buffer, initialized in wxCommonInit */ -wxChar *wxBuffer = (wxChar *) NULL; - /* Windows List */ wxWindowList wxTopLevelWindows; diff --git a/src/mgl/app.cpp b/src/mgl/app.cpp index da9471e4dc..f4790cbc7a 100644 --- a/src/mgl/app.cpp +++ b/src/mgl/app.cpp @@ -412,8 +412,6 @@ bool wxApp::Initialize() if ( MGL_init(".", NULL) == 0 ) return FALSE; - wxBuffer = new wxChar[BUFSIZ + 512]; - wxClassInfo::InitializeClasses(); #if wxUSE_INTL @@ -497,8 +495,6 @@ void wxApp::CleanUp() delete wxTheFontsManager; wxTheFontsManager = (wxFontsManager*) NULL; - delete[] wxBuffer; - // check for memory leaks #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT if (wxDebugContext::CountObjectsLeft(TRUE) > 0) diff --git a/src/mgl/data.cpp b/src/mgl/data.cpp index 6a99ec80ee..b6c280dc17 100644 --- a/src/mgl/data.cpp +++ b/src/mgl/data.cpp @@ -32,9 +32,6 @@ #define _MAXPATHLEN 500 -/* Useful buffer, initialized in wxCommonInit */ -wxChar *wxBuffer = (wxChar *) NULL; - /* Windows List */ wxWindowList wxTopLevelWindows; diff --git a/src/motif/app.cpp b/src/motif/app.cpp index 8b019fdf6e..9a09d850b4 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -60,7 +60,6 @@ #include -extern char *wxBuffer; extern wxList wxPendingDelete; wxApp *wxTheApp = NULL; @@ -89,8 +88,6 @@ long wxApp::sm_lastMessageTime = 0; bool wxApp::Initialize() { - wxBuffer = new char[BUFSIZ + 512]; - wxClassInfo::InitializeClasses(); // GL: I'm annoyed ... I don't know where to put this and I don't want to @@ -158,9 +155,6 @@ void wxApp::CleanUp() wxBitmap::CleanUpHandlers(); - delete[] wxBuffer; - wxBuffer = NULL; - wxClassInfo::CleanUpClasses(); delete wxTheApp; diff --git a/src/motif/control.cpp b/src/motif/control.cpp index 894198a0a1..0a5e6377f1 100644 --- a/src/motif/control.cpp +++ b/src/motif/control.cpp @@ -68,14 +68,13 @@ void wxControl::SetLabel(const wxString& label) if (!widget) return; - wxStripMenuCodes((char*) (const char*) label, wxBuffer); + wxString buf(wxStripMenuCodes()); + wxXmString label_str(buf); - XmString text = XmStringCreateSimple (wxBuffer); XtVaSetValues (widget, - XmNlabelString, text, + XmNlabelString, label_str, XmNlabelType, XmSTRING, NULL); - XmStringFree (text); } wxString wxControl::GetLabel() const diff --git a/src/motif/data.cpp b/src/motif/data.cpp index eb1c8e0713..0387862c7b 100644 --- a/src/motif/data.cpp +++ b/src/motif/data.cpp @@ -18,9 +18,6 @@ #define _MAXPATHLEN 500 -// Useful buffer, initialized in CommonInit -char *wxBuffer = NULL; - // Windows List wxWindowList wxTopLevelWindows; diff --git a/src/motif/menu.cpp b/src/motif/menu.cpp index 84410f4f5f..c5d3232ead 100644 --- a/src/motif/menu.cpp +++ b/src/motif/menu.cpp @@ -526,8 +526,6 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM else { char mnem = wxFindMnemonic (title); - wxStripMenuCodes ((char*) (const char*) title, wxBuffer); - menu = XmCreatePulldownMenu ((Widget) parent, "pulldown", args, 2); wxString title2(wxStripMenuCodes(title)); diff --git a/src/motif/window.cpp b/src/motif/window.cpp index d0a7035d95..cbdac0a7ce 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -2147,12 +2147,13 @@ static void wxCanvasInputEvent(Widget drawingArea, case KeyPress: { KeySym keySym; + static char buf[100]; #if 0 XComposeStatus compose; - (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose); + (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, &compose); #endif // 0 - (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL); + (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, NULL); int id = wxCharCodeXToWX (keySym); wxEventType eventType = wxEVT_CHAR; @@ -2200,8 +2201,9 @@ static void wxCanvasInputEvent(Widget drawingArea, } case KeyRelease: { + static char buf[100]; KeySym keySym; - (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL); + (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, NULL); int id = wxCharCodeXToWX (keySym); wxKeyEvent event (wxEVT_KEY_UP); diff --git a/src/x11/app.cpp b/src/x11/app.cpp index 62cb336b78..a4d0c28487 100644 --- a/src/x11/app.cpp +++ b/src/x11/app.cpp @@ -29,6 +29,7 @@ #include "wx/log.h" #include "wx/intl.h" #include "wx/evtloop.h" +#include "wx/cmdline.h" #if wxUSE_THREADS #include "wx/thread.h" @@ -53,7 +54,6 @@ #include -extern char *wxBuffer; extern wxList wxPendingDelete; wxApp *wxTheApp = NULL; @@ -66,6 +66,14 @@ BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) EVT_IDLE(wxApp::OnIdle) END_EVENT_TABLE() +static const wxCmdLineEntryDesc g_cmdLineDesc[] = +{ + { wxCMD_LINE_SWITCH, "sync", "sync", "synchronize the display" }, + { wxCMD_LINE_OPTION, "display", "display", "use the given display", wxCMD_LINE_VAL_STRING }, + + { wxCMD_LINE_NONE } +}; + #ifdef __WXDEBUG__ typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *); @@ -83,8 +91,6 @@ WXDisplay *wxApp::ms_display = NULL; bool wxApp::Initialize() { - wxBuffer = new char[BUFSIZ + 512]; - wxClassInfo::InitializeClasses(); // GL: I'm annoyed ... I don't know where to put this and I don't want to @@ -132,9 +138,6 @@ void wxApp::CleanUp() delete wxTheApp; wxTheApp = NULL; - delete[] wxBuffer; - wxBuffer = NULL; - wxClassInfo::CleanUpClasses(); #if wxUSE_THREADS @@ -161,6 +164,11 @@ void wxApp::CleanUp() delete wxLog::SetActiveTarget(NULL); } +// This is set within wxEntryStart -- too early on +// to put these in wxTheApp +static int g_newArgc = 0; +static wxChar** g_newArgv = NULL; + // NB: argc and argv may be changed here, pass by reference! int wxEntryStart( int& argc, char *argv[] ) { @@ -169,6 +177,13 @@ int wxEntryStart( int& argc, char *argv[] ) gs_pfnXErrorHandler = XSetErrorHandler( wxXErrorHandler ); #endif // __WXDEBUG__ + /// TODO +#if 0 + // Parse the arguments. Is it OK to use the command line + // parser before calling Initialize? + wxCmdLineParser cmdLine(argv, argv); +#endif + Display* xdisplay = XOpenDisplay(NULL); if (!xdisplay) @@ -236,8 +251,18 @@ int wxEntry( int argc, char *argv[] ) wxTheApp->SetClassName(wxFileNameFromPath(argv[0])); wxTheApp->SetAppName(wxFileNameFromPath(argv[0])); - wxTheApp->argc = argc; - wxTheApp->argv = argv; + // The command line may have been changed + // by stripping out -display etc. + if (g_newArgc > 0) + { + wxTheApp->argc = g_newArgc; + wxTheApp->argv = g_newArgv; + } + else + { + wxTheApp->argc = argc; + wxTheApp->argv = argv; + } int retValue; retValue = wxEntryInitGui(); @@ -339,7 +364,7 @@ void wxApp::ProcessXEvent(WXEvent* _event) win = wxGetWindowFromTable(window); if (!win) - return; + return; switch (event->type) { @@ -498,6 +523,10 @@ void wxApp::ProcessXEvent(WXEvent* _event) } default: { +#ifdef __WXDEBUG__ + //wxString eventName = wxGetXEventName(XEvent& event); + //wxLogDebug(wxT("Event %s not handled"), eventName.c_str()); +#endif break; } } @@ -775,13 +804,3 @@ void wxApp::OnAssert(const wxChar *file, int line, const wxChar *msg) #endif } -// ---------------------------------------------------------------------------- -// accessors for C modules -// ---------------------------------------------------------------------------- - -#if 0 -extern "C" XtAppContext wxGetAppContext() -{ - return (XtAppContext)wxTheApp->GetAppContext(); -} -#endif diff --git a/src/x11/data.cpp b/src/x11/data.cpp index eb1c8e0713..0387862c7b 100644 --- a/src/x11/data.cpp +++ b/src/x11/data.cpp @@ -18,9 +18,6 @@ #define _MAXPATHLEN 500 -// Useful buffer, initialized in CommonInit -char *wxBuffer = NULL; - // Windows List wxWindowList wxTopLevelWindows; diff --git a/src/x11/utils.cpp b/src/x11/utils.cpp index ea472dcc6e..7d6e1f93ba 100644 --- a/src/x11/utils.cpp +++ b/src/x11/utils.cpp @@ -1062,6 +1062,29 @@ void wxAllocColor(Display *d,Colormap cmp,XColor *xc) } } +#ifdef __WXDEBUG__ +wxString wxGetXEventName(XEvent& event) +{ + 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; + } +#endif + #ifdef __WXMOTIF__ // ---------------------------------------------------------------------------- // accelerators @@ -1115,7 +1138,8 @@ char * wxFindAccelerator (const char *s) */ - wxBuffer[0] = '\0'; + static char buf[256]; + buf[0] = '\0'; char *tmp = copystring (s); s = tmp; char *p = tmp; @@ -1127,23 +1151,23 @@ char * wxFindAccelerator (const char *s) if (*p) { *p = '\0'; - if (wxBuffer[0]) - strcat (wxBuffer, " "); + if (buf[0]) + strcat (buf, " "); if (strcmp (s, "Alt")) - strcat (wxBuffer, s); + strcat (buf, s); else - strcat (wxBuffer, "Meta"); + strcat (buf, "Meta"); s = p++; } else { - strcat (wxBuffer, ""); - strcat (wxBuffer, s); + strcat (buf, ""); + strcat (buf, s); break; } } delete[]tmp; - return wxBuffer; + return buf; #endif } -- 2.45.2