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
This commit is contained in:
Julian Smart
2002-02-14 11:07:26 +00:00
parent 318fa6983d
commit 45ff6421e6
17 changed files with 86 additions and 73 deletions

View File

@@ -57,7 +57,10 @@ class WXDLLEXPORT wxPoint;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Useful buffer (FIXME VZ: To be removed!!!) // 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; WXDLLEXPORT_DATA(extern wxChar*) wxBuffer;
#endif
// Make a copy of this string using 'new' // Make a copy of this string using 'new'
WXDLLEXPORT wxChar* copystring(const wxChar *s); WXDLLEXPORT wxChar* copystring(const wxChar *s);

View File

@@ -69,5 +69,10 @@ void wxXColorToHSV(wxHSV *hsv,XColor *xcolor);
void wxAllocNearestColor(Display *display,Colormap colormap,XColor *xcolor); void wxAllocNearestColor(Display *display,Colormap colormap,XColor *xcolor);
void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor); void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor);
// For debugging
#ifdef __WXDEBUG__
wxString wxGetXEventName(XEvent& event);
#endif
#endif #endif
// _WX_PRIVX_H_ // _WX_PRIVX_H_

View File

@@ -142,8 +142,6 @@
#define _MAXPATHLEN 1024 #define _MAXPATHLEN 1024
#endif #endif
extern wxChar *wxBuffer;
#ifdef __WXMAC__ #ifdef __WXMAC__
# include "MoreFiles.h" # include "MoreFiles.h"
# include "MoreFilesExtras.h" # include "MoreFilesExtras.h"

View File

@@ -564,8 +564,6 @@ void wxApp::DeletePendingObjects()
bool wxApp::Initialize() bool wxApp::Initialize()
{ {
wxBuffer = new wxChar[BUFSIZ + 512];
wxClassInfo::InitializeClasses(); wxClassInfo::InitializeClasses();
#if wxUSE_INTL #if wxUSE_INTL
@@ -613,9 +611,6 @@ void wxApp::CleanUp()
delete wxTheApp; delete wxTheApp;
wxTheApp = (wxApp*) NULL; wxTheApp = (wxApp*) NULL;
delete[] wxBuffer;
wxBuffer = NULL;
wxClassInfo::CleanUpClasses(); wxClassInfo::CleanUpClasses();
#if wxUSE_THREADS #if wxUSE_THREADS

View File

@@ -25,9 +25,6 @@
#define _MAXPATHLEN 500 #define _MAXPATHLEN 500
/* Useful buffer, initialized in wxCommonInit */
wxChar *wxBuffer = (wxChar *) NULL;
/* Windows List */ /* Windows List */
wxWindowList wxTopLevelWindows; wxWindowList wxTopLevelWindows;

View File

@@ -564,8 +564,6 @@ void wxApp::DeletePendingObjects()
bool wxApp::Initialize() bool wxApp::Initialize()
{ {
wxBuffer = new wxChar[BUFSIZ + 512];
wxClassInfo::InitializeClasses(); wxClassInfo::InitializeClasses();
#if wxUSE_INTL #if wxUSE_INTL
@@ -613,9 +611,6 @@ void wxApp::CleanUp()
delete wxTheApp; delete wxTheApp;
wxTheApp = (wxApp*) NULL; wxTheApp = (wxApp*) NULL;
delete[] wxBuffer;
wxBuffer = NULL;
wxClassInfo::CleanUpClasses(); wxClassInfo::CleanUpClasses();
#if wxUSE_THREADS #if wxUSE_THREADS

View File

@@ -25,9 +25,6 @@
#define _MAXPATHLEN 500 #define _MAXPATHLEN 500
/* Useful buffer, initialized in wxCommonInit */
wxChar *wxBuffer = (wxChar *) NULL;
/* Windows List */ /* Windows List */
wxWindowList wxTopLevelWindows; wxWindowList wxTopLevelWindows;

View File

@@ -412,8 +412,6 @@ bool wxApp::Initialize()
if ( MGL_init(".", NULL) == 0 ) if ( MGL_init(".", NULL) == 0 )
return FALSE; return FALSE;
wxBuffer = new wxChar[BUFSIZ + 512];
wxClassInfo::InitializeClasses(); wxClassInfo::InitializeClasses();
#if wxUSE_INTL #if wxUSE_INTL
@@ -497,8 +495,6 @@ void wxApp::CleanUp()
delete wxTheFontsManager; delete wxTheFontsManager;
wxTheFontsManager = (wxFontsManager*) NULL; wxTheFontsManager = (wxFontsManager*) NULL;
delete[] wxBuffer;
// check for memory leaks // check for memory leaks
#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
if (wxDebugContext::CountObjectsLeft(TRUE) > 0) if (wxDebugContext::CountObjectsLeft(TRUE) > 0)

View File

@@ -32,9 +32,6 @@
#define _MAXPATHLEN 500 #define _MAXPATHLEN 500
/* Useful buffer, initialized in wxCommonInit */
wxChar *wxBuffer = (wxChar *) NULL;
/* Windows List */ /* Windows List */
wxWindowList wxTopLevelWindows; wxWindowList wxTopLevelWindows;

View File

@@ -60,7 +60,6 @@
#include <string.h> #include <string.h>
extern char *wxBuffer;
extern wxList wxPendingDelete; extern wxList wxPendingDelete;
wxApp *wxTheApp = NULL; wxApp *wxTheApp = NULL;
@@ -89,8 +88,6 @@ long wxApp::sm_lastMessageTime = 0;
bool wxApp::Initialize() bool wxApp::Initialize()
{ {
wxBuffer = new char[BUFSIZ + 512];
wxClassInfo::InitializeClasses(); wxClassInfo::InitializeClasses();
// GL: I'm annoyed ... I don't know where to put this and I don't want to // 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(); wxBitmap::CleanUpHandlers();
delete[] wxBuffer;
wxBuffer = NULL;
wxClassInfo::CleanUpClasses(); wxClassInfo::CleanUpClasses();
delete wxTheApp; delete wxTheApp;

View File

@@ -68,14 +68,13 @@ void wxControl::SetLabel(const wxString& label)
if (!widget) if (!widget)
return; return;
wxStripMenuCodes((char*) (const char*) label, wxBuffer); wxString buf(wxStripMenuCodes());
wxXmString label_str(buf);
XmString text = XmStringCreateSimple (wxBuffer);
XtVaSetValues (widget, XtVaSetValues (widget,
XmNlabelString, text, XmNlabelString, label_str,
XmNlabelType, XmSTRING, XmNlabelType, XmSTRING,
NULL); NULL);
XmStringFree (text);
} }
wxString wxControl::GetLabel() const wxString wxControl::GetLabel() const

View File

@@ -18,9 +18,6 @@
#define _MAXPATHLEN 500 #define _MAXPATHLEN 500
// Useful buffer, initialized in CommonInit
char *wxBuffer = NULL;
// Windows List // Windows List
wxWindowList wxTopLevelWindows; wxWindowList wxTopLevelWindows;

View File

@@ -526,8 +526,6 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM
else else
{ {
char mnem = wxFindMnemonic (title); char mnem = wxFindMnemonic (title);
wxStripMenuCodes ((char*) (const char*) title, wxBuffer);
menu = XmCreatePulldownMenu ((Widget) parent, "pulldown", args, 2); menu = XmCreatePulldownMenu ((Widget) parent, "pulldown", args, 2);
wxString title2(wxStripMenuCodes(title)); wxString title2(wxStripMenuCodes(title));

View File

@@ -2147,12 +2147,13 @@ static void wxCanvasInputEvent(Widget drawingArea,
case KeyPress: case KeyPress:
{ {
KeySym keySym; KeySym keySym;
static char buf[100];
#if 0 #if 0
XComposeStatus compose; XComposeStatus compose;
(void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose); (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, &compose);
#endif // 0 #endif // 0
(void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL); (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, NULL);
int id = wxCharCodeXToWX (keySym); int id = wxCharCodeXToWX (keySym);
wxEventType eventType = wxEVT_CHAR; wxEventType eventType = wxEVT_CHAR;
@@ -2200,8 +2201,9 @@ static void wxCanvasInputEvent(Widget drawingArea,
} }
case KeyRelease: case KeyRelease:
{ {
static char buf[100];
KeySym keySym; KeySym keySym;
(void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, NULL); (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, NULL);
int id = wxCharCodeXToWX (keySym); int id = wxCharCodeXToWX (keySym);
wxKeyEvent event (wxEVT_KEY_UP); wxKeyEvent event (wxEVT_KEY_UP);

View File

@@ -29,6 +29,7 @@
#include "wx/log.h" #include "wx/log.h"
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/evtloop.h" #include "wx/evtloop.h"
#include "wx/cmdline.h"
#if wxUSE_THREADS #if wxUSE_THREADS
#include "wx/thread.h" #include "wx/thread.h"
@@ -53,7 +54,6 @@
#include <string.h> #include <string.h>
extern char *wxBuffer;
extern wxList wxPendingDelete; extern wxList wxPendingDelete;
wxApp *wxTheApp = NULL; wxApp *wxTheApp = NULL;
@@ -66,6 +66,14 @@ BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
EVT_IDLE(wxApp::OnIdle) EVT_IDLE(wxApp::OnIdle)
END_EVENT_TABLE() 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__ #ifdef __WXDEBUG__
typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *); typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *);
@@ -83,8 +91,6 @@ WXDisplay *wxApp::ms_display = NULL;
bool wxApp::Initialize() bool wxApp::Initialize()
{ {
wxBuffer = new char[BUFSIZ + 512];
wxClassInfo::InitializeClasses(); wxClassInfo::InitializeClasses();
// GL: I'm annoyed ... I don't know where to put this and I don't want to // 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; delete wxTheApp;
wxTheApp = NULL; wxTheApp = NULL;
delete[] wxBuffer;
wxBuffer = NULL;
wxClassInfo::CleanUpClasses(); wxClassInfo::CleanUpClasses();
#if wxUSE_THREADS #if wxUSE_THREADS
@@ -161,6 +164,11 @@ void wxApp::CleanUp()
delete wxLog::SetActiveTarget(NULL); 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! // NB: argc and argv may be changed here, pass by reference!
int wxEntryStart( int& argc, char *argv[] ) int wxEntryStart( int& argc, char *argv[] )
{ {
@@ -169,6 +177,13 @@ int wxEntryStart( int& argc, char *argv[] )
gs_pfnXErrorHandler = XSetErrorHandler( wxXErrorHandler ); gs_pfnXErrorHandler = XSetErrorHandler( wxXErrorHandler );
#endif // __WXDEBUG__ #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); Display* xdisplay = XOpenDisplay(NULL);
if (!xdisplay) if (!xdisplay)
@@ -236,8 +251,18 @@ int wxEntry( int argc, char *argv[] )
wxTheApp->SetClassName(wxFileNameFromPath(argv[0])); wxTheApp->SetClassName(wxFileNameFromPath(argv[0]));
wxTheApp->SetAppName(wxFileNameFromPath(argv[0])); wxTheApp->SetAppName(wxFileNameFromPath(argv[0]));
wxTheApp->argc = argc; // The command line may have been changed
wxTheApp->argv = argv; // 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; int retValue;
retValue = wxEntryInitGui(); retValue = wxEntryInitGui();
@@ -339,7 +364,7 @@ void wxApp::ProcessXEvent(WXEvent* _event)
win = wxGetWindowFromTable(window); win = wxGetWindowFromTable(window);
if (!win) if (!win)
return; return;
switch (event->type) switch (event->type)
{ {
@@ -498,6 +523,10 @@ void wxApp::ProcessXEvent(WXEvent* _event)
} }
default: default:
{ {
#ifdef __WXDEBUG__
//wxString eventName = wxGetXEventName(XEvent& event);
//wxLogDebug(wxT("Event %s not handled"), eventName.c_str());
#endif
break; break;
} }
} }
@@ -775,13 +804,3 @@ void wxApp::OnAssert(const wxChar *file, int line, const wxChar *msg)
#endif #endif
} }
// ----------------------------------------------------------------------------
// accessors for C modules
// ----------------------------------------------------------------------------
#if 0
extern "C" XtAppContext wxGetAppContext()
{
return (XtAppContext)wxTheApp->GetAppContext();
}
#endif

View File

@@ -18,9 +18,6 @@
#define _MAXPATHLEN 500 #define _MAXPATHLEN 500
// Useful buffer, initialized in CommonInit
char *wxBuffer = NULL;
// Windows List // Windows List
wxWindowList wxTopLevelWindows; wxWindowList wxTopLevelWindows;

View File

@@ -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__ #ifdef __WXMOTIF__
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// accelerators // accelerators
@@ -1115,7 +1138,8 @@ char * wxFindAccelerator (const char *s)
*/ */
wxBuffer[0] = '\0'; static char buf[256];
buf[0] = '\0';
char *tmp = copystring (s); char *tmp = copystring (s);
s = tmp; s = tmp;
char *p = tmp; char *p = tmp;
@@ -1127,23 +1151,23 @@ char * wxFindAccelerator (const char *s)
if (*p) if (*p)
{ {
*p = '\0'; *p = '\0';
if (wxBuffer[0]) if (buf[0])
strcat (wxBuffer, " "); strcat (buf, " ");
if (strcmp (s, "Alt")) if (strcmp (s, "Alt"))
strcat (wxBuffer, s); strcat (buf, s);
else else
strcat (wxBuffer, "Meta"); strcat (buf, "Meta");
s = p++; s = p++;
} }
else else
{ {
strcat (wxBuffer, "<Key>"); strcat (buf, "<Key>");
strcat (wxBuffer, s); strcat (buf, s);
break; break;
} }
} }
delete[]tmp; delete[]tmp;
return wxBuffer; return buf;
#endif #endif
} }