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.
bool SendIdleEvents(wxWindow* win);
// Motif implementation.
// Processes an X event.
virtual void ProcessXEvent(WXEvent* event);
@ -97,9 +95,7 @@ public:
void DeletePendingObjects();
bool ProcessIdle();
// Motif-specific
WXAppContext GetAppContext() const { return m_appContext; }
WXWidget GetTopLevelWidget() const { return m_topLevelWidget; }
WXWindow GetTopLevelWidget() const { return m_topLevelWidget; }
WXColormap GetMainColormap(WXDisplay* display);
WXDisplay* GetInitialDisplay() const { return m_initialDisplay; }
long GetMaxRequestSize() const { return m_maxRequestSize; }
@ -114,9 +110,7 @@ public:
protected:
bool m_keepGoing;
// Motif-specific
WXAppContext m_appContext;
WXWidget m_topLevelWidget;
WXWindow m_topLevelWidget;
WXColormap m_mainColormap;
WXDisplay* m_initialDisplay;
long m_maxRequestSize;

View File

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

View File

@ -2745,7 +2745,7 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget,
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)
{