#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"
#ifdef __VMS__
#pragma message disable nosimpint
#endif
-#include <Xm/Xm.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
#pragma message enable nosimpint
#endif
-#include "wx/motif/private.h"
+#include "wx/x11/private.h"
#include <string.h>
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);
delete wxTheColourDatabase;
wxTheColourDatabase = NULL;
-#if wxUSE_POSTSCRIPT
- /* Done using wxModule now
- wxInitializePrintSetupData(FALSE);
- delete wxThePrintPaperDatabase;
- wxThePrintPaperDatabase = NULL;
- */
-#endif
-
wxBitmap::CleanUpHandlers();
delete[] wxBuffer;
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;
}
* use an Xt-eventhandler.
*/
- XSelectInput(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()),
- XDefaultRootWindow(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())),
+ XSelectInput(wxGetDisplay(),
+ XDefaultRootWindow(wxGetDisplay()),
PropertyChangeMask);
XEvent event;
// 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())
{
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)
{
}
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);
}
}
// 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);
}
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)
// 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);
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)
{
{
// 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,
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;
}
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 );
}
// accessors for C modules
// ----------------------------------------------------------------------------
+#if 0
extern "C" XtAppContext wxGetAppContext()
{
return (XtAppContext)wxTheApp->GetAppContext();
}
+#endif
\ No newline at end of file