📄 qxt.cpp
字号:
/****************************************************************************** $Id: qt/extensions/xt/src/qxt.cpp 2.3.0 edited 2001-01-26 $**** Implementation of Qt extension classes for Xt/Motif support.**** Created : 980107**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of the Qt GUI Toolkit.**** This file may be distributed under the terms of the Q Public License** as defined by Trolltech AS of Norway and appearing in the file** LICENSE.QPL included in the packaging of this file.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses may use this file in accordance with the Qt Commercial License** Agreement provided with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for** information about Qt Commercial License Agreements.** See http://www.trolltech.com/qpl/ for QPL licensing information.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include <qapplication.h>#include <qwidget.h>#include <qobjcoll.h>#include <qwidcoll.h>#include "qxt.h"#include <stdio.h>#include <string.h>#include <time.h>#include <limits.h>#include <X11/Xlib.h>#include <X11/Intrinsic.h>#include <X11/IntrinsicP.h> // for XtCreateWindow#include <X11/Shell.h>#include <X11/StringDefs.h>#include <X11/Xutil.h>#include <X11/Xos.h>const int XKeyPress = KeyPress;const int XKeyRelease = KeyRelease;#undef KeyPress#undef KeyReleaseextern Atom qt_wm_state;//#define HAVE_MOTIF#ifdef HAVE_MOTIF#include <Xm/Xm.h>#endiftypedef void (*SameAsXtTimerCallbackProc)(void*,void*);typedef void (*IntervalSetter)(int);typedef void (*ForeignEventProc)(XEvent*);extern XtEventDispatchProc qt_np_cascade_event_handler[LASTEvent]; // defined in qnpsupport.cppvoid qt_reset_color_avail(); // defined in qcolor_x11.cppint qt_activate_timers(); // defined in qapplication_x11.cpptimeval *qt_wait_timer(); // defined in qapplication_x11.cppvoid qt_x11SendPostedEvents(); // defined in qapplication_x11.cppint qt_event_handler( XEvent* event ); // defined in qnpsupport.cppextern int qt_np_count; // defined in qnpsupport.cppvoid qt_np_timeout( void* p, void* id ); // defined in qnpsupport.cppvoid qt_np_add_timeoutcb( SameAsXtTimerCallbackProc cb ); // defined in qnpsupport.cppvoid qt_np_remove_timeoutcb( SameAsXtTimerCallbackProc cb ); // defined in qnpsupport.cppvoid qt_np_add_timer_setter( IntervalSetter is ); // defined in qnpsupport.cppvoid qt_np_remove_timer_setter( IntervalSetter is ); // defined in qnpsupport.cppextern XtIntervalId qt_np_timerid; // defined in qnpsupport.cppextern void (*qt_np_leave_cb) (XLeaveWindowEvent*); // defined in qnpsupport.cppvoid qt_np_add_event_proc( ForeignEventProc fep ); // defined in qnpsupport.cppvoid qt_np_remove_event_proc( ForeignEventProc fep ); // defined in qnpsupport.cpptypedef struct { int empty;} QWidgetClassPart;typedef struct _QWidgetClassRec { CoreClassPart core_class; QWidgetClassPart qwidget_class;} QWidgetClassRec;//static QWidgetClassRec qwidgetClassRec;typedef struct { /* resources */ /* (none) */ /* private state */ QXtWidget* qxtwidget;} QWidgetPart;typedef struct _QWidgetRec { CorePart core; QWidgetPart qwidget;} QWidgetRec;staticvoid reparentChildrenOf(QWidget* parent){ if ( !parent->children() ) return; // nothing to do for ( QObjectListIt it( *parent->children() ); it.current(); ++it ) { if ( it.current()->isWidgetType() ) { QWidget* widget = (QWidget*)it.current(); XReparentWindow( qt_xdisplay(), widget->winId(), parent->winId(), widget->x(), widget->y() ); if ( widget->isVisible() ) XMapWindow( qt_xdisplay(), widget->winId() ); } }}void qwidget_realize( Widget widget, XtValueMask* mask, XSetWindowAttributes* attributes ){ widgetClassRec.core_class.realize(widget, mask, attributes); QXtWidget* qxtw = ((QWidgetRec*)widget)->qwidget.qxtwidget; if (XtWindow(widget) != qxtw->winId()) { qxtw->create(XtWindow(widget), FALSE, FALSE); reparentChildrenOf(qxtw); } qxtw->show(); XMapWindow( qt_xdisplay(), qxtw->winId() );}staticQWidgetClassRec qwidgetClassRec = { { /* core fields */ /* superclass */ (WidgetClass) &widgetClassRec, /* class_name */ (char*)"QWidget", /* widget_size */ sizeof(QWidgetRec), /* class_initialize */ 0, /* class_part_initialize */ 0, /* class_inited */ FALSE, /* initialize */ 0, /* initialize_hook */ 0, /* realize */ qwidget_realize, /* actions */ 0, /* num_actions */ 0, /* resources */ 0, /* num_resources */ 0, /* xrm_class */ NULLQUARK, /* compress_motion */ TRUE, /* compress_exposure */ TRUE, /* compress_enterleave */ TRUE, /* visible_interest */ FALSE, /* destroy */ 0, /* resize */ XtInheritResize, /* expose */ XtInheritExpose, /* set_values */ 0, /* set_values_hook */ 0, /* set_values_almost */ XtInheritSetValuesAlmost, /* get_values_hook */ 0, /* accept_focus */ XtInheritAcceptFocus, /* version */ XtVersion, /* callback_private */ 0, /* tm_table */ XtInheritTranslations, /* query_geometry */ XtInheritQueryGeometry, /* display_accelerator */ XtInheritDisplayAccelerator, /* extension */ 0 }, { /* qwidget fields */ /* empty */ 0 }};static WidgetClass qWidgetClass = (WidgetClass)&qwidgetClassRec;static bool filters_installed = FALSE;static QXtApplication* qxtapp = 0;static XtAppContext appcon;staticBoolean qt_event_handler_wrapper( XEvent* event ){ return (Boolean)qt_event_handler( event );}staticvoid installXtEventFilters(){ if (filters_installed) return; // Get Xt out of our face - install filter on every event type for (int et=2; et < LASTEvent; et++) { qt_np_cascade_event_handler[et] = XtSetEventDispatcher( qt_xdisplay(), et, qt_event_handler_wrapper ); } filters_installed = TRUE;}staticvoid removeXtEventFilters(){ if (!filters_installed) return; // We aren't needed any more... slink back into the shadows. for (int et=2; et < LASTEvent; et++) { XtSetEventDispatcher( qt_xdisplay(), et, qt_np_cascade_event_handler[et] ); } filters_installed = FALSE;}// When we are in an event loop of QApplication rather than the browser's// event loop (eg. for a modal dialog), we still send events to Xt.staticvoid np_event_proc( XEvent* e ){ Widget xtw = XtWindowToWidget( e->xany.display, e->xany.window ); if ( xtw && qApp->loopLevel() > 0 ) { // Allow Xt to process the event qt_np_cascade_event_handler[e->type]( e ); }}static void np_set_timer( int interval ){ // Ensure we only have one timeout in progress - QApplication is // computing the one amount of time we need to wait. if ( qt_np_timerid ) { XtRemoveTimeOut( qt_np_timerid ); } qt_np_timerid = XtAppAddTimeOut(appcon, interval, (XtTimerCallbackProc)qt_np_timeout, 0);}static void np_do_timers( void*, void* ){ qt_np_timerid = 0; // It's us, and we just expired, that's why we are here. qt_activate_timers(); timeval *tm = qt_wait_timer(); if (tm) { int interval = QMIN(tm->tv_sec,INT_MAX/1000)*1000 + tm->tv_usec/1000; np_set_timer( interval ); } qxtapp->sendPostedEvents();}/*! \class QXtApplication qxt.h \brief Allows mixing of Xt/Motif and Qt widgets. \extension Xt/Motif The QXtApplication and QXtWidget classes allow old Xt or Motif widgets to be used in new Qt applications. They also allow Qt widgets to be used in primarily Xt/Motif applications. The facility is intended to aid migration from Xt/Motif to the more comfortable Qt system.*/static bool my_xt;/*! Constructs a QApplication and initializes the Xt toolkit. The \a appclass, \a options, \a num_options, and \a resources arguments are passed on to XtAppSetFallbackResources and XtDisplayInitialize. Use this constructor when writing a new Qt application which needs to use some existing Xt/Motif widgets.*/QXtApplication::QXtApplication(int& argc, char** argv, const char* appclass, XrmOptionDescRec *options, int num_options, const char** resources) : QApplication(argc, argv){ my_xt = TRUE; XtToolkitInitialize(); appcon = XtCreateApplicationContext(); if (resources) XtAppSetFallbackResources(appcon, (char**)resources);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -