qnp.cpp

来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 2,022 行 · 第 1/4 页

CPP
2,022
字号
		focussedWidget->leaveInstance();		focussedWidget = 0;	    }	    removeXtEventFilters(Dangerous);	}    }    *cont = FALSE;}// Relacement for Qt function - add Xt stuff for top-level widgetsWindow qt_XCreateWindow( const QWidget* qw, Display *display, Window parent,			 int x, int y, uint w, uint h,			 int borderwidth, int depth,			 uint windowclass, Visual *visual,			 ulong valuemask, XSetWindowAttributes *attributes ){    // ### This isA will not work - we are still in QWidget's constructor.    if ( qw->isTopLevel() && !qw->isA("QNPWidget") ) {	// ### not sure it is good to use name() and className().	bool cmap = valuemask & CWColormap;	Widget xtw = XtVaAppCreateShell( qw->name(), qw->className(),	    applicationShellWidgetClass, display,	    XtNx, x, XtNy, y, XtNwidth, w, XtNheight, h,	    XtNborderWidth, borderwidth, XtNdepth, depth,	    XtNvisual, visual,	    cmap ? XtNcolormap : 0, cmap ? attributes->colormap : 0,	    0, 0 );	// Ensure it has a window, and get it.	XtSetMappedWhenManaged( xtw, FALSE );	XtRealizeWidget( xtw );	Window xw = XtWindow( xtw );	// Set the attributes (directly)	XChangeWindowAttributes( display, xw, valuemask, attributes );	// Inform us on enter/leave	XtAddEventHandler( xtw, EnterWindowMask, TRUE, enter_event_handler, 0 );	XtAddEventHandler( xtw, LeaveWindowMask, TRUE, leave_event_handler, 0 );	// Return Xt's window for the widget	return xw;    } else {	Window window = XCreateWindow( display, parent, x, y, w, h, borderwidth, depth,			      windowclass, visual, valuemask, attributes );	return window;    }}// Relacement for Qt function - add Xt stuff for top-level widgetsWindow qt_XCreateSimpleWindow( const QWidget* qw, Display *display, Window parent,			       int x, int y, uint w, uint h, int borderwidth,			       ulong border, ulong background ){    // ### This isA will not work - we are still in QWidget's constructor.    Window window;    if ( qw->isTopLevel() && !qw->isA("QNPWidget") ) {	XSetWindowAttributes attributes;	attributes.border_pixel = border;	attributes.background_pixel = background;	window = qt_XCreateWindow (	    qw, display, parent, x, y, w, h, borderwidth,	    CopyFromParent, CopyFromParent, CopyFromParent,	    CWBackPixel | CWBorderPixel, &attributes );    } else {	window = XCreateSimpleWindow( display, parent, x, y, w, h, borderwidth,				    border, background );    }    return window;}// Relacement for Qt function - add Xt stuff for top-level widgetsvoid qt_XDestroyWindow( const QWidget* qw, Display *display, Window window ){    if ( qw->isTopLevel() && !qw->isA("QNPWidget") ) {	Widget xtw = XtWindowToWidget( display, window );	if ( xtw ) {	    XtRemoveEventHandler(xtw, LeaveWindowMask, TRUE, leave_event_handler, 0);	    XtRemoveEventHandler(xtw, EnterWindowMask, TRUE, enter_event_handler, 0);	    XtDestroyWidget( xtw );	} else {	    XDestroyWindow( display, window );	}    } else {	XDestroyWindow( display, window );    }}#endif#ifdef Q_WS_WINBOOL   WINAPI   DllMain (HANDLE hInst,			ULONG ul_reason_for_call,			LPVOID lpReserved){    switch ( ul_reason_for_call ) {	case DLL_PROCESS_ATTACH:	case DLL_THREAD_ATTACH:	    WinMain( (HINSTANCE)hInst, 0, "", SW_SHOW );	    break;	case DLL_PROCESS_DETACH:	case DLL_THREAD_DETACH:	    break;    }    return TRUE;}int main(int argc, char** argv){    return 0;}#endif/*!  \class QNPWidget qnp.h  \brief The QNPWidget class provides a QWidget that is a Web-browser plugin window.  \extension NSPlugin  Derive from QNPWidget to create a widget that can be used as a  Browser plugin window, or create one and add child widgets.  Instances of QNPWidget may only be created  when QNPInstance::newWindow() is called by the browser.  A common way to develop a plugin widget is to develop it as a stand-alone  application window, then make it a \e child of a plugin widget to use  it as a browser plugin.  The technique is:\codeclass MyPluginWindow : public QNPWidget {    QWidget* child;public:    MyPluginWindow()    {	// Some widget that is normally used as a top-level widget	child = new MyIndependentlyDevelopedWidget();	// Use the background color of the web page	child->setBackgroundColor( backgroundColor() );	// Fill the plugin widget	child->setGeometry( 0, 0, width(), height() );    }    void resizeEvent(QResizeEvent*)    {	// Fill the plugin widget	child->resize(size());    }};\endcode  The default implementation is an empty window.*//*!  Creates a QNPWidget.*/QNPWidget::QNPWidget() :    pi(next_pi){    if (!next_pi) {	qFatal("QNPWidget must only be created within call to newWindow");    }    next_pi->widget = this;    next_pi = 0;    setWindow(TRUE);    piApp->addQNPWidget(this);#ifdef Q_WS_WIN    // Communicator and explorer give us an unshown    // widget.  Navigator gives us a shown one.    QWidget::show();#endif}/*!  Destroys the window.  This will be called by the plugin binding code  when the window is no longer required.  The Web-browser will delete windows  when they leave the page.  The bindings will change the QWidget::winId()  of the window when the window is resized, but this should not affect  normal widget behavior.*/QNPWidget::~QNPWidget(){    piApp->removeQNPWidget(this);}/*!  Called when the mouse enters the plugin window.  Does nothing by  default.*/void QNPWidget::enterInstance(){}/*!  Called when the mouse leaves the plugin window.  Does nothing by  default.*/void QNPWidget::leaveInstance(){}/*!  Returns the instance for which this widget is the window.*/QNPInstance* QNPWidget::instance(){    return pi->instance;}class QFixableWidget : public QWidget {public:    void fix()    {	QRect g = geometry();	QColor bg = backgroundColor();	bool mt = hasMouseTracking();	bool hascurs = testWFlags( WState_OwnCursor );	QCursor curs = cursor();	clearWState( WState_Created );	clearWState( WState_Visible );	create( 0, TRUE, FALSE );	setGeometry(g);	setBackgroundColor( bg );	setMouseTracking( mt );	if ( hascurs ) {	    setCursor( curs );	}    }};staticvoid createNewWindowsForAllChildren(QWidget* parent, int indent=0){    QObjectList* list = parent->queryList("QWidget", 0, FALSE, FALSE);    if ( list ) {	QObjectListIt it( *list );	QFixableWidget* c;	while ( (c = (QFixableWidget*)it.current()) ) {	    bool vis = c->isVisible();	    // Fix children first, so propagation can work	    createNewWindowsForAllChildren(c,indent+1);	    c->fix();	    if ( vis ) 		c->show(); // Now that all children are valid.			    	    ++it;	}	delete list;    }}/*!    \internal  For internal use only.  If \a delold parameter is passed to the create() function.*/void QNPWidget::setWindow(bool delold){    saveWId = winId(); // ### Don't need this anymore    create((WId)pi->window, FALSE, delold);   if ( delold ) {      // Make sure they get a show()      clearWState( WState_Visible );   }#ifdef Q_WS_X11    Widget w = XtWindowToWidget (qt_xdisplay(), pi->window);    XtAddEventHandler(w, EnterWindowMask, FALSE, enter_event_handler, pi);    XtAddEventHandler(w, LeaveWindowMask, FALSE, leave_event_handler, pi);    Pixmap bgpm=0;    XColor col;    XtVaGetValues(w,	XtNbackground, &col.pixel,	XtNbackgroundPixmap, &bgpm,	0, 0);    XQueryColor(qt_xdisplay(), x11Colormap(), &col);    setBackgroundColor(QColor(col.red >> 8, col.green >> 8, col.blue >> 8));    if (bgpm) {	// ### Need an under-the-hood function here, or we have to	// ### rewrite lots of code from QPixmap::convertToImage().	// ### Doesn't matter yet, because Netscape doesn't ever set	// ### the background image of the window it gives us.    }#endif    createNewWindowsForAllChildren(this);    setGeometry( pi->x, pi->y, pi->width, pi->height );}/*!  For internal use only.  \internal*/void QNPWidget::unsetWindow(){#ifdef Q_WS_X11    WId wi = winId();    Widget w = XtWindowToWidget (qt_xdisplay(), wi);    if ( w ) {	XtRemoveEventHandler(w, LeaveWindowMask, FALSE, leave_event_handler, pi);	XtRemoveEventHandler(w, EnterWindowMask, FALSE, enter_event_handler, pi);    }    destroy( FALSE, FALSE ); // Xt has already destroyed all the windows#endif#ifdef Q_WS_WIN    // Nothing special    destroy( FALSE, TRUE ); // Browser will the window, but not the subwindows#endif}/*!  \class QNPInstance qnp.h  \brief The QNPInstance class provides a QObject that is a Web-browser plugin.  \extension NSPlugin  Deriving from QNPInstance creates an object that represents a single  \c{<EMBED>} tag in an HTML document.  The QNPInstance is responsible for creating an appropriate window if  required (not all plugins have windows), and for interacting with the  input/output facilities intrinsic to plugins.  Note that there is \e{absolutely no guarantee} regarding the order in  which functions are called.  Sometimes the browser will call newWindow()  first, at other times, newStreamCreated() will be called first (assuming the  \c{<EMBED>} tag has a SRC parameter).  \e{None of Qt's GUI functionality} may be used until after the first call  to newWindow().  This includes any use of QPaintDevice (ie. QPixmap,  QWidget, and all subclasses), QApplication, anything related to  QPainter (QBrush, etc.), fonts, QMovie, QToolTip, etc.  Useful  classes which specifically \e can be used are QImage, QFile,  and QBuffer.  By structuring your plugin so that  the task of the QNPInstance is to gather data, while  the task of the QNPWidget is to provide a graphical interface to that data,  this restriction can easily be accommodated.*//*! \enum QNPInstance::InstanceMode  This enum type provides Qt-style names for three #defines in  npapi.h:  \value Embed - corresponds to NP_EMBED  \value Full - corresponds to NP_FULL  \value Background - corresponds to NP_BACKGROUND*//*! \enum QNPInstance::Reason    \value ReasonDone    \value ReasonBreak    \value ReasonError    \value ReasonUnknown*//*! \enum QNPInstance::StreamMode    \value Normal    \value Seek    \value AsFile    \value AsFileOnly*//*!  Creates a QNPInstance.  Can only be called from within a derived class created  within QNPlugin::newInstance().*/QNPInstance::QNPInstance() :    pi(next_pi){    if (!next_pi) {	qFatal("QNPInstance must only be created within call to newInstance");    }    next_pi->instance = this;    next_pi = 0;}/*!  Called when the plugin instance is about to disappear.*/QNPInstance::~QNPInstance(){}/*!  Called at most once, at some time after the QNPInstance is created.  If the plugin requires a window, this function should return a derived  class of QNPWidget that provides the required interface.*/QNPWidget* QNPInstance::newWindow(){    // No window by default    next_pi = 0;    return 0;}/*!  Returns the plugin window created by newWindow(), if any.*/QNPWidget* QNPInstance::widget(){    return pi->widget;}/*!  \fn bool QNPInstance::newStreamCreated(QNPStream*, StreamMode& smode)  This function is called when a new stream has been created.  The instance should return TRUE if it accepts the processing  of the stream.  If the instance requires the stream as a file,  it should set \a smode to AsFileOnly, in which case the data  will be delivered some time later to the streamAsFile() function.  Otherwise, the data will be delivered in chunks to the write()  function which must consume at least as much data as was returned  by the most recent call to writeReady().  Note that the AsFileOnly method is not supported by Netscape 2.0  and MSIE 3.0.*/bool QNPInstance::newStreamCreated(QNPStream*, StreamMode&){    return FALSE;}/*!  Called when a stream is delivered as a single file called \a fname  rather than as chunks.  This may be simpler for a plugin to deal  with, but precludes any incremental behavior.  Note that the AsFileOnly method is not supported by Netscape 2.0  and MSIE 3.0.  \sa newStreamCreated(), newStream()*/void QNPInstance::streamAsFile(QNPStream*, const char*){}/*!  Called when a stream is destroyed.  At this point, the stream may  be complete() and okay().  If it is not okay(), then an error has  occurred.  If it is okay(), but not complete(), then the user has  cancelled the transmission - do not give an error message in this case.*/void QNPInstance::streamDestroyed(QNPStream*){}/*!    Returns the minimum amount of data the instance is  willing to receive from the given stream.  The default returns a very large value.*/int QNPInstance::writeReady(QNPStream*){    // Yes, we can handle any amount of data at once.    return 0X0FFFFFFF;}/*!  \fn int QNPInstance::write(QNPStream*, int offset, int len, void* buffer)  Called when incoming data is available for processing by the instance.  The instance \e must consume at least the amount that it returned in  the most recent call to writeReady(), but it may consume up to the  amount given by \a len.  \a buffer is the data available for consumption.  The \a offset argument is merely an informational  value indicating the total amount of data that has been consumed  in prior calls.  This function should return the amount of data actually consumed.*/int QNPInstance::write(QNPStream*, int, int len, void*){    // Yes, we processed it all... into the bit bucket.    return len;}/*!  Requests that the \a url be retrieved and sent to the named  \a window.  See Netscape's JavaScript documentation for an explanation

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?