⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qnp.cpp

📁 qt-embedded-2.3.8.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	    if ( focussedWidget ) {		focussedWidget->enterInstance();		qt_np_leave_cb = PluginSDK_QApplication::removeXtEventFiltersIfOutsideQNPWidget;	    }	}	// Post the event	*cont = qt_event_handler(event);    } else {	*cont = FALSE;    }}// Called when a top-level widget (which has an Xt widget's window) is left.staticvoid leave_event_handler(Widget, XtPointer, XEvent*, Boolean* cont){    if (piApp) {	if ( !QApplication::activePopupWidget()	  && !QApplication::activeModalWidget() )	{	    if ( focussedWidget ) {		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 _WS_WIN_BOOL   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 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.*//*! \enum QNPWidget::InstanceMode  This enum type provides C++-friendly names for three #defines in  npapi.h: <ul>  <li> \c Embed - corresponds to NP_EMBED  <li> \c Full - corresponds to NP_FULL  <li> \c Background - corresponds to NP_BACKGROUND  </ul>*//*!  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 _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.  Default does nothing.*/void QNPWidget::enterInstance(){}/*!  Called when the mouse leaves the plugin window.  Default does nothing.*/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;    }}/*!  For internal use only.*/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 _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.*/void QNPWidget::unsetWindow(){#ifdef _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 _WS_WIN_    // Nothing special    destroy( FALSE, TRUE ); // Browser will the window, but not the subwindows#endif}/*!  \class QNPInstance qnp.h  \brief a QObject that is a Web-browser plugin  \extension NSPlugin  Deriving from QNPInstance creates an object that represents a single  &lt;EMBED&gt; 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 <em>absolutely no garrantee</em> as to the order in  which functions are called.  Sometimes the browser will call setWindow()  first, at other times, newStreamCreated() will be called first (assuming the  &lt;EMBED&gt; tag has a SRC parameter).  <em>No GUI functionality</em> of Qt may be used until the first call  to setWindow().  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 <em>can</em> 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 be easily accommodated.*//*!  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 at 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 MS-Explorer 3.0.*/bool QNPInstance::newStreamCreated(QNPStream*, StreamMode&){    return FALSE;}/*!  Called when a stream is delivered as a single file rather than  as chunks.  This may be simpler for a plugin to deal with, but  precludes any incremental behavior.  \sa newStreamCreated(), newStream()  Note that the AsFileOnly method is not supported by Netscape 2.0  and MS-Explorer 3.0.*/void QNPInstance::streamAsFile(QNPStream*, const char*){}/*!  Called when a stream is destroyed.  At this this, 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*){}/*!  Called to inquire 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

⌨️ 快捷键说明

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