First stabs at stripping out Xt/Motif code

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14017 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2002-02-05 18:13:03 +00:00
parent eddf46fea7
commit 7eaac9f513
3 changed files with 102 additions and 135 deletions

View File

@@ -72,8 +72,6 @@ public:
// Returns TRUE if more idle time is requested. // Returns TRUE if more idle time is requested.
bool SendIdleEvents(wxWindow* win); bool SendIdleEvents(wxWindow* win);
// Motif implementation.
// Processes an X event. // Processes an X event.
virtual void ProcessXEvent(WXEvent* event); virtual void ProcessXEvent(WXEvent* event);
@@ -97,9 +95,7 @@ public:
void DeletePendingObjects(); void DeletePendingObjects();
bool ProcessIdle(); bool ProcessIdle();
// Motif-specific WXWindow GetTopLevelWidget() const { return m_topLevelWidget; }
WXAppContext GetAppContext() const { return m_appContext; }
WXWidget GetTopLevelWidget() const { return m_topLevelWidget; }
WXColormap GetMainColormap(WXDisplay* display); WXColormap GetMainColormap(WXDisplay* display);
WXDisplay* GetInitialDisplay() const { return m_initialDisplay; } WXDisplay* GetInitialDisplay() const { return m_initialDisplay; }
long GetMaxRequestSize() const { return m_maxRequestSize; } long GetMaxRequestSize() const { return m_maxRequestSize; }
@@ -114,9 +110,7 @@ public:
protected: protected:
bool m_keepGoing; bool m_keepGoing;
// Motif-specific WXWindow m_topLevelWidget;
WXAppContext m_appContext;
WXWidget m_topLevelWidget;
WXColormap m_mainColormap; WXColormap m_mainColormap;
WXDisplay* m_initialDisplay; WXDisplay* m_initialDisplay;
long m_maxRequestSize; long m_maxRequestSize;

View File

@@ -13,11 +13,6 @@
#pragma implementation "app.h" #pragma implementation "app.h"
#endif #endif
#ifdef __VMS
#define XtParent XTPARENT
#define XtDisplay XTDISPLAY
#endif
#include "wx/frame.h" #include "wx/frame.h"
#include "wx/app.h" #include "wx/app.h"
#include "wx/utils.h" #include "wx/utils.h"
@@ -47,7 +42,6 @@
#ifdef __VMS__ #ifdef __VMS__
#pragma message disable nosimpint #pragma message disable nosimpint
#endif #endif
#include <Xm/Xm.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xresource.h> #include <X11/Xresource.h>
@@ -56,7 +50,7 @@
#pragma message enable nosimpint #pragma message enable nosimpint
#endif #endif
#include "wx/motif/private.h" #include "wx/x11/private.h"
#include <string.h> #include <string.h>
@@ -109,15 +103,6 @@ bool wxApp::Initialize()
wxInitializeResourceSystem(); wxInitializeResourceSystem();
#endif #endif
// For PostScript printing
#if wxUSE_POSTSCRIPT
/* Done using wxModule now
wxInitializePrintSetupData();
wxThePrintPaperDatabase = new wxPrintPaperDatabase;
wxThePrintPaperDatabase->CreateDatabase();
*/
#endif
wxBitmap::InitStandardHandlers(); wxBitmap::InitStandardHandlers();
wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER); wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
@@ -148,14 +133,6 @@ void wxApp::CleanUp()
delete wxTheColourDatabase; delete wxTheColourDatabase;
wxTheColourDatabase = NULL; wxTheColourDatabase = NULL;
#if wxUSE_POSTSCRIPT
/* Done using wxModule now
wxInitializePrintSetupData(FALSE);
delete wxThePrintPaperDatabase;
wxThePrintPaperDatabase = NULL;
*/
#endif
wxBitmap::CleanUpHandlers(); wxBitmap::CleanUpHandlers();
delete[] wxBuffer; delete[] wxBuffer;
@@ -278,10 +255,8 @@ wxApp::wxApp()
argc = 0; argc = 0;
argv = NULL; argv = NULL;
m_exitOnFrameDelete = TRUE; m_exitOnFrameDelete = TRUE;
m_mainColormap = (WXColormap) NULL; m_mainColormap = (WXColormap) NULL;
m_appContext = (WXAppContext) NULL; m_topLevelWidget = (WXWindow) NULL;
m_topLevelWidget = (WXWidget) NULL;
m_maxRequestSize = 0; m_maxRequestSize = 0;
m_initialDisplay = (WXDisplay*) 0; m_initialDisplay = (WXDisplay*) 0;
} }
@@ -305,8 +280,8 @@ int wxApp::MainLoop()
* use an Xt-eventhandler. * use an Xt-eventhandler.
*/ */
XSelectInput(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), XSelectInput(wxGetDisplay(),
XDefaultRootWindow(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())), XDefaultRootWindow(wxGetDisplay()),
PropertyChangeMask); PropertyChangeMask);
XEvent event; XEvent event;
@@ -314,11 +289,11 @@ int wxApp::MainLoop()
// Use this flag to allow breaking the loop via wxApp::ExitMainLoop() // Use this flag to allow breaking the loop via wxApp::ExitMainLoop()
while (m_keepGoing) while (m_keepGoing)
{ {
XtAppNextEvent( (XtAppContext) wxTheApp->GetAppContext(), &event); XNextEvent(wxGetDisplay(), & event);
ProcessXEvent((WXEvent*) & event); ProcessXEvent((WXEvent*) & event);
if (XtAppPending( (XtAppContext) wxTheApp->GetAppContext() ) == 0) if (XtPending(wxGetDisplay()) == 0)
{ {
if (!ProcessIdle()) if (!ProcessIdle())
{ {
@@ -341,52 +316,51 @@ int wxApp::MainLoop()
void wxApp::ProcessXEvent(WXEvent* _event) void wxApp::ProcessXEvent(WXEvent* _event)
{ {
XEvent* event = (XEvent*) _event; XEvent* event = (XEvent*) _event;
if (event->type == KeyPress) if (event->type == KeyPress)
{ {
#if 0 // def __WXDEBUG__ if (CheckForAccelerator(_event))
Widget widget = XtWindowToWidget(event->xany.display, event->xany.window); {
wxLogDebug("Got key press event for 0x%08x (parent = 0x%08x)",
widget, XtParent(widget));
#endif // DEBUG
if (CheckForAccelerator(_event))
{
// Do nothing! We intercepted and processed the event as an // Do nothing! We intercepted and processed the event as an
// accelerator. // accelerator.
return; return;
} }
#if 1 #if 1
// It seemed before that this hack was redundant and // It seemed before that this hack was redundant and
// key down events were being generated by wxCanvasInputEvent. // key down events were being generated by wxCanvasInputEvent.
// But no longer - why ??? // But no longer - why ???
// //
else if (CheckForKeyDown(_event)) else if (CheckForKeyDown(_event))
{ {
// We intercepted and processed the key down event // We intercepted and processed the key down event
return; return;
} }
#endif #endif
else else
{ {
XtDispatchEvent(event); // TODO for X11 implementation -- the equivalent of XtDispatchEvent.
return; // Presumably, we need to form the wxEvents and
} // and send them to the appropriate windows.
// XtDispatchEvent(event);
return;
}
} }
else if (event->type == KeyRelease) else if (event->type == KeyRelease)
{ {
// TODO: work out why we still need this ! -michael // TODO: work out why we still need this ! -michael
// //
if (CheckForKeyUp(_event)) if (CheckForKeyUp(_event))
{ {
// We intercepted and processed the key up event // We intercepted and processed the key up event
return; return;
} }
else else
{ {
XtDispatchEvent(event); // TODO: The X equivalent of XtDispatchEvent
return; // (see above)
} // XtDispatchEvent(event);
return;
}
} }
else if (event->type == PropertyNotify) else if (event->type == PropertyNotify)
{ {
@@ -395,27 +369,29 @@ void wxApp::ProcessXEvent(WXEvent* _event)
} }
else if (event->type == ResizeRequest) else if (event->type == ResizeRequest)
{ {
/* Terry Gitnick <terryg@scientech.com> - 1/21/98 /* Terry Gitnick <terryg@scientech.com> - 1/21/98
* If resize event, don't resize until the last resize event for this * If resize event, don't resize until the last resize event for this
* window is recieved. Prevents flicker as windows are resized. * window is recieved. Prevents flicker as windows are resized.
*/ */
Display *disp = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()); Display *disp = wxGetDisplay();
Window win = event->xany.window; Window win = event->xany.window;
XEvent report; XEvent report;
// to avoid flicker // to avoid flicker
report = * event; report = * event;
while( XCheckTypedWindowEvent (disp, win, ResizeRequest, &report)); while( XCheckTypedWindowEvent (disp, win, ResizeRequest, &report));
// TODO: when implementing refresh optimization, we can use // TODO: when implementing refresh optimization, we can use
// XtAddExposureToRegion to expand the window's paint region. // XtAddExposureToRegion to expand the window's paint region.
XtDispatchEvent(event); // TODO: generate resize event
// XtDispatchEvent(event);
} }
else else
{ {
XtDispatchEvent(event); // TODO: generate all other events
// XtDispatchEvent(event);
} }
} }
@@ -437,20 +413,16 @@ void wxApp::ExitMainLoop()
// Is a message/event pending? // Is a message/event pending?
bool wxApp::Pending() bool wxApp::Pending()
{ {
XFlush(XtDisplay( (Widget) wxTheApp->GetTopLevelWidget() )); XFlush(wxGetDisplay());
// Fix by Doug from STI, to prevent a stall if non-X event return (XPending(wxGetDisplay()) > 0);
// is found.
return ((XtAppPending( (XtAppContext) GetAppContext() ) & XtIMXEvent) != 0) ;
} }
// Dispatch a message. // Dispatch a message.
void wxApp::Dispatch() void wxApp::Dispatch()
{ {
// XtAppProcessEvent( (XtAppContext) wxTheApp->GetAppContext(), XtIMAll);
XEvent event; XEvent event;
XtAppNextEvent((XtAppContext) GetAppContext(), &event); XNextEvent(wxGetDisplay(), & event);
ProcessXEvent((WXEvent*) & event); ProcessXEvent((WXEvent*) & event);
} }
@@ -459,7 +431,8 @@ void wxApp::Dispatch()
void wxApp::HandlePropertyChange(WXEvent *event) void wxApp::HandlePropertyChange(WXEvent *event)
{ {
// by default do nothing special // by default do nothing special
XtDispatchEvent((XEvent*) event); /* let Motif do the work */ // TODO: what to do for X11
// XtDispatchEvent((XEvent*) event); /* let Motif do the work */
} }
void wxApp::OnIdle(wxIdleEvent& event) void wxApp::OnIdle(wxIdleEvent& event)
@@ -570,39 +543,28 @@ void wxApp::DeletePendingObjects()
// Create an application context // Create an application context
bool wxApp::OnInitGui() bool wxApp::OnInitGui()
{ {
XtToolkitInitialize() ; // TODO: parse argv and get display to pass to XOpenDisplay
wxTheApp->m_appContext = (WXAppContext) XtCreateApplicationContext() ; Display* dpy = XOpenDisplay(NULL);
Display *dpy = XtOpenDisplay((XtAppContext) wxTheApp->m_appContext,(String)NULL,NULL, m_initialDisplay = (WXDisplay*) dpy;
(const char*) wxTheApp->GetClassName(), NULL, 0,
# if XtSpecificationRelease < 5
(Cardinal*) &argc,
# else
&argc,
# endif
argv);
if (!dpy) { if (!dpy) {
wxString className(wxTheApp->GetClassName()); wxString className(wxTheApp->GetClassName());
wxLogError(_("wxWindows could not open display for '%s': exiting."), wxLogError(_("wxWindows could not open display for '%s': exiting."),
(const char*) className); (const char*) className);
exit(-1); exit(-1);
} }
m_initialDisplay = (WXDisplay*) dpy;
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
// install the X error handler // install the X error handler
gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler); gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler);
#endif // __WXDEBUG__ #endif // __WXDEBUG__
// Do we need to create the top-level window initially?
#if 0
wxTheApp->m_topLevelWidget = (WXWidget) XtAppCreateShell((String)NULL, (const char*) wxTheApp->GetClassName(), wxTheApp->m_topLevelWidget = (WXWidget) XtAppCreateShell((String)NULL, (const char*) wxTheApp->GetClassName(),
applicationShellWidgetClass,dpy, applicationShellWidgetClass,dpy,
NULL,0) ; NULL,0) ;
#endif
// Add general resize proc
XtActionsRec rec;
rec.string = "resize";
rec.proc = (XtActionProc)wxWidgetResizeProc;
XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1);
GetMainColormap(dpy); GetMainColormap(dpy);
m_maxRequestSize = XMaxRequestSize((Display*) dpy); m_maxRequestSize = XMaxRequestSize((Display*) dpy);
@@ -626,6 +588,17 @@ WXColormap wxApp::GetMainColormap(WXDisplay* display)
return (WXColormap) c; return (WXColormap) c;
} }
static Window XGetParent(Window window)
{
Window parent, root = 0;
unsigned int noChildren = 0;
if (XQueryTree(wxGetDisplay(), window, & root, & parent,
NULL, & noChildren))
return parent;
else
return (Window) 0;
}
// Returns TRUE if an accelerator has been processed // Returns TRUE if an accelerator has been processed
bool wxApp::CheckForAccelerator(WXEvent* event) bool wxApp::CheckForAccelerator(WXEvent* event)
{ {
@@ -634,18 +607,18 @@ bool wxApp::CheckForAccelerator(WXEvent* event)
{ {
// Find a wxWindow for this window // Find a wxWindow for this window
// TODO: should get display for the window, not the current display // TODO: should get display for the window, not the current display
Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), xEvent->xany.window); Window window = xEvent->xany.window;
wxWindow* win = NULL; wxWindow* win = NULL;
// Find the first wxWindow that corresponds to this event window // Find the first wxWindow that corresponds to this event window
while (widget && !(win = wxGetWindowFromTable(widget))) while (window && !(win = wxGetWindowFromTable(window)))
widget = XtParent(widget); window = XGetParent(window);
if (!widget || !win) if (!window || !win)
return FALSE; return FALSE;
wxKeyEvent keyEvent(wxEVT_CHAR); wxKeyEvent keyEvent(wxEVT_CHAR);
wxTranslateKeyEvent(keyEvent, win, (Widget) 0, xEvent); wxTranslateKeyEvent(keyEvent, win, (Window) 0, xEvent);
// Now we have a wxKeyEvent and we have a wxWindow. // Now we have a wxKeyEvent and we have a wxWindow.
// Go up the hierarchy until we find a matching accelerator, // Go up the hierarchy until we find a matching accelerator,
@@ -666,23 +639,22 @@ bool wxApp::CheckForKeyDown(WXEvent* event)
XEvent* xEvent = (XEvent*) event; XEvent* xEvent = (XEvent*) event;
if (xEvent->xany.type == KeyPress) if (xEvent->xany.type == KeyPress)
{ {
Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), Window window = xEvent->xany.window;
xEvent->xany.window); wxWindow* win = NULL;
wxWindow* win = NULL;
// Find the first wxWindow that corresponds to this event window
// Find the first wxWindow that corresponds to this event window while (window && !(win = wxGetWindowFromTable(window)))
while (widget && !(win = wxGetWindowFromTable(widget))) window = XGetParent(window);
widget = XtParent(widget);
if (!window || !win)
if (!widget || !win)
return FALSE; return FALSE;
wxKeyEvent keyEvent(wxEVT_KEY_DOWN); wxKeyEvent keyEvent(wxEVT_KEY_DOWN);
wxTranslateKeyEvent(keyEvent, win, (Widget) 0, xEvent); wxTranslateKeyEvent(keyEvent, win, (Window) 0, xEvent);
return win->ProcessEvent( keyEvent ); return win->ProcessEvent( keyEvent );
} }
return FALSE; return FALSE;
} }
@@ -691,20 +663,19 @@ bool wxApp::CheckForKeyUp(WXEvent* event)
XEvent* xEvent = (XEvent*) event; XEvent* xEvent = (XEvent*) event;
if (xEvent->xany.type == KeyRelease) if (xEvent->xany.type == KeyRelease)
{ {
Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), Window window = xEvent->xany.window;
xEvent->xany.window);
wxWindow* win = NULL; wxWindow* win = NULL;
// Find the first wxWindow that corresponds to this event window // Find the first wxWindow that corresponds to this event window
while (widget && !(win = wxGetWindowFromTable(widget))) while (window && !(win = wxGetWindowFromTable(window)))
widget = XtParent(widget); window = XGetParent(window);
if (!widget || !win) if (!window || !win)
return FALSE; return FALSE;
wxKeyEvent keyEvent(wxEVT_KEY_UP); wxKeyEvent keyEvent(wxEVT_KEY_UP);
wxTranslateKeyEvent(keyEvent, win, (Widget) 0, xEvent); wxTranslateKeyEvent(keyEvent, win, (Window) 0, xEvent);
return win->ProcessEvent( keyEvent ); return win->ProcessEvent( keyEvent );
} }
@@ -790,7 +761,9 @@ wxApp::GetStdIcon(int which) const
// accessors for C modules // accessors for C modules
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if 0
extern "C" XtAppContext wxGetAppContext() extern "C" XtAppContext wxGetAppContext()
{ {
return (XtAppContext)wxTheApp->GetAppContext(); return (XtAppContext)wxTheApp->GetAppContext();
} }
#endif

View File

@@ -2745,7 +2745,7 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget,
return FALSE; return FALSE;
} }
bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget WXUNUSED(widget), XEvent *xevent) bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Window WXUNUSED(win), XEvent *xevent)
{ {
switch (xevent->xany.type) switch (xevent->xany.type)
{ {