Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'QXEmbed (./kdelibs/kdeui/qxembed.h:34)
class QXEmbed : public QWidget
{
Q_OBJECT
public:
QXEmbed( QWidget *parent=0, const char *name=0, WFlags f = 0 );
~QXEmbed();
static void initialize();
void embed( WId w );
WId embeddedWinId() const;
static void embedClientIntoWindow( QWidget* client, WId window );
static bool processClientCmdline( QWidget* client, int& argc, char ** argv );
QSize sizeHint() const;
QSize minimumSizeHint() const;
QSizePolicy sizePolicy() const;
bool eventFilter( QObject *, QEvent * );
signals:
void embeddedWindowDestroyed();
protected:
bool event( QEvent * );
void keyPressEvent( QKeyEvent * );
void keyReleaseEvent( QKeyEvent * );
void focusInEvent( QFocusEvent * );
void focusOutEvent( QFocusEvent * );
void resizeEvent(QResizeEvent *);
void showEvent( QShowEvent * );
bool x11Event( XEvent* );
virtual void windowChanged( WId );
bool focusNextPrevChild( bool next );
private:
WId window;
QXEmbedData* d;
};
kdelibs'QXEmbed::initialize() (./kdelibs/kdeui/qxembed.cpp:317)
void QXEmbed::initialize()
{
static bool is_initialized = FALSE;
if ( is_initialized )
return;
xembed = XInternAtom( qt_xdisplay(), "_XEMBED", FALSE );
oldFilter = qt_set_x11_event_filter( qxembed_x11_event_filter );
focusMap = new QPtrDict<QGuardedPtr<QWidget> >;
focusMap->setAutoDelete( TRUE );
filter = new QXEmbedAppFilter;
is_initialized = TRUE;
}
/*!
\class QXEmbed qxembed.h
\brief The QXEmbed widget is a graphical socket that can embed an
external X-Window.
\extension XEmbed
A QXEmbed widget serves as an embedder that can manage one single
embedded X-window. These so-called client windows can be arbitrary
QWidgets.
There are two different ways of using QXembed, from the embedder's
or from the client's side. When using it from the embedder's side,
you already know the window identifier of the window that should be
embedded. Simply call embed() with this identifier as parameter.
Embedding from the client's side requires that the client knows the
window identifier of the respective embedder widget. Use either
embedClientIntoWindow() or the high-level wrapper
processClientCmdline().
If a window has been embedded succesfully, embeddedWinId() returns
its id.
Reimplement the change handler windowChanged() to catch embedding or
the destruction of embedded windows. In the latter case, the
embedder also emits a signal embeddedWindowDestroyed() for
convenience.
*/
/*!
Constructs a xembed widget.
The \e parent, \e name and \e f arguments are passed to the QFrame
constructor.
*/
kdelibs'QXEmbed::QXEmbed() (./kdelibs/kdeui/qxembed.cpp:372)
QXEmbed::QXEmbed(QWidget *parent, const char *name, WFlags f)
: QWidget(parent, name, f)
{
initialize();
window = 0;
setFocusPolicy(StrongFocus);
setKeyCompression( FALSE );
//trick to create extraData();
(void) topData();
// we are interested in SubstructureNotify
XSelectInput(qt_xdisplay(), winId(),
KeyPressMask | KeyReleaseMask |
ButtonPressMask | ButtonReleaseMask |
KeymapStateMask |
ButtonMotionMask |
PointerMotionMask | // may need this, too
EnterWindowMask | LeaveWindowMask |
FocusChangeMask |
ExposureMask |
StructureNotifyMask |
SubstructureRedirectMask |
SubstructureNotifyMask
);
topLevelWidget()->installEventFilter( this );
qApp->installEventFilter( this );
setAcceptDrops( TRUE );
}
/*!
Destructor. Cleans up the focus if necessary.
*/
kdelibs'QXEmbed::~QXEmbed() (./kdelibs/kdeui/qxembed.cpp:407)
QXEmbed::~QXEmbed()
{
if ( window != 0 ) {
XUnmapWindow(qt_xdisplay(), window );
XReparentWindow(qt_xdisplay(), window, qt_xrootwin(), 0, 0);
XEvent ev;
memset(&ev, 0, sizeof(ev));
ev.xclient.type = ClientMessage;
ev.xclient.window = window;
ev.xclient.message_type = qt_wm_protocols;
ev.xclient.format = 32;
ev.xclient.data.s[0] = qt_wm_delete_window;
XSendEvent(qt_xdisplay(), window, FALSE, NoEventMask, &ev);
}
window = 0;
}
/*!\reimp
*/
kdelibs'QXEmbed::resizeEvent() (./kdelibs/kdeui/qxembed.cpp:429)
void QXEmbed::resizeEvent(QResizeEvent*)
{
if (window != 0)
XResizeWindow(qt_xdisplay(), window, width(), height());
}
/*!\reimp
*/
kdelibs'QXEmbed::showEvent() (./kdelibs/kdeui/qxembed.cpp:437)
void QXEmbed::showEvent(QShowEvent*)
{
if (window != 0)
XMapRaised(qt_xdisplay(), window);
}
/*!\reimp
*/
kdelibs'QXEmbed::eventFilter() (./kdelibs/kdeui/qxembed.cpp:447)
bool QXEmbed::eventFilter( QObject *o, QEvent * e)
{
switch ( e->type() ) {
case QEvent::WindowActivate:
if ( o == topLevelWidget() )
send_xembed_message( window, XEMBED_WINDOW_ACTIVATE );
break;
case QEvent::WindowDeactivate:
if ( o == topLevelWidget() )
send_xembed_message( window, XEMBED_WINDOW_DEACTIVATE );
break;
default:
break;
}
return FALSE;
}
kdelibs'QXEmbed::event() (./kdelibs/kdeui/qxembed.cpp:466)
bool QXEmbed::event( QEvent * e)
{
return QWidget::event( e );
}
/*!\reimp
*/
kdelibs'QXEmbed::keyPressEvent() (./kdelibs/kdeui/qxembed.cpp:473)
void QXEmbed::keyPressEvent( QKeyEvent *)
{
if (!window)
return;
send_xembed_message( window, XEMBED_PROCESS_NEXT_EVENT );
last_key_event.window = window;
XSendEvent(qt_xdisplay(), window, FALSE, NoEventMask, (XEvent*)&last_key_event);
}
/*!\reimp
*/
kdelibs'QXEmbed::keyReleaseEvent() (./kdelibs/kdeui/qxembed.cpp:485)
void QXEmbed::keyReleaseEvent( QKeyEvent *)
{
if (!window)
return;
send_xembed_message( window, XEMBED_PROCESS_NEXT_EVENT );
last_key_event.window = window;
XSendEvent(qt_xdisplay(), window, FALSE, NoEventMask, (XEvent*)&last_key_event);
}
/*!\reimp
*/
kdelibs'QXEmbed::focusInEvent() (./kdelibs/kdeui/qxembed.cpp:496)
void QXEmbed::focusInEvent( QFocusEvent * e ){
if (!window)
return;
int detail = XEMBED_FOCUS_CURRENT;
if ( e->reason() == QFocusEvent::Tab )
detail = tabForward?XEMBED_FOCUS_FIRST:XEMBED_FOCUS_LAST;
send_xembed_message( window, XEMBED_FOCUS_IN, detail);
}
/*!\reimp
*/
kdelibs'QXEmbed::focusOutEvent() (./kdelibs/kdeui/qxembed.cpp:507)
void QXEmbed::focusOutEvent( QFocusEvent * ){
if (!window)
return;
send_xembed_message( window, XEMBED_FOCUS_OUT );
}
/*!
Embeds the window with the identifier \a w into this xembed widget.
This function is useful if the server knows about the client window
that should be embedded. Often it is vice versa: the client knows
about its target embedder. In that case, it is not necessary to call
embed(). Instead, the client will call the static function
embedClientIntoWindow().
\sa embeddedWinId()
*/
kdelibs'QXEmbed::embed() (./kdelibs/kdeui/qxembed.cpp:526)
void QXEmbed::embed(WId w)
{
if (!w)
return;
bool has_window = w == window;
window = w;
if ( !has_window )
XReparentWindow(qt_xdisplay(), w, winId(), 0, 0);
QApplication::syncX();
XResizeWindow(qt_xdisplay(), w, width(), height());
XMapRaised(qt_xdisplay(), window);
XAddToSaveSet( qt_xdisplay(), w );
extraData()->xDndProxy = w;
if ( parent() ) {
QEvent * layoutHint = new QEvent( QEvent::LayoutHint );
QApplication::postEvent( parent(), layoutHint );
}
windowChanged( window );
send_xembed_message( window, XEMBED_EMBEDDED_NOTIFY );
send_xembed_message( window, isActiveWindow() ? XEMBED_WINDOW_ACTIVATE : XEMBED_WINDOW_DEACTIVATE );
if ( hasFocus() )
send_xembed_message( window, XEMBED_FOCUS_IN );
}
/*!
Returns the window identifier of the embedded window, or 0 if no
window is embedded yet.
*/
kdelibs'QXEmbed::embeddedWinId() (./kdelibs/kdeui/qxembed.cpp:557)
WId QXEmbed::embeddedWinId() const
{
return window;
}
/*!\reimp
*/
kdelibs'QXEmbed::focusNextPrevChild() (./kdelibs/kdeui/qxembed.cpp:565)
bool QXEmbed::focusNextPrevChild( bool next )
{
if ( window )
return FALSE;
else
return QWidget::focusNextPrevChild( next );
}
/*!\reimp
*/
kdelibs'QXEmbed::x11Event() (./kdelibs/kdeui/qxembed.cpp:576)
bool QXEmbed::x11Event( XEvent* e)
{
switch ( e->type ) {
case DestroyNotify:
if ( e->xdestroywindow.window == window ) {
window = 0;
windowChanged( window );
emit embeddedWindowDestroyed();
}
break;
case ReparentNotify:
if ( window && e->xreparent.window == window &&
e->xreparent.parent != winId() ) {
// we lost the window
window = 0;
windowChanged( window );
} else if ( e->xreparent.parent == winId() ){
// we got a window
window = e->xreparent.window;
embed( window );
}
break;
case MapRequest:
if ( window && e->xmaprequest.window == window )
XMapRaised(qt_xdisplay(), window );
break;
case ClientMessage:
if ( e->xclient.format == 32 && e->xclient.message_type == xembed ) {
int message = e->xclient.data.l[1];
// int detail = e->xclient.data.l[2];
switch ( message ) {
case XEMBED_FOCUS_NEXT:
QWidget::focusNextPrevChild( TRUE );
break;
case XEMBED_FOCUS_PREV:
QWidget::focusNextPrevChild( FALSE );
break;
case XEMBED_REQUEST_FOCUS:
setFocus();
break;
default:
break;
}
}
default:
break;
}
return FALSE;
}
/*!
A change handler that indicates that the embedded window has been
changed. The window handle can also be retrieved with
embeddedWinId().
*/
kdelibs'QXEmbed::windowChanged() (./kdelibs/kdeui/qxembed.cpp:632)
void QXEmbed::windowChanged( WId )
{
}
/*!
A utility function for clients that embed theirselves. The widget \a
client will be embedded in the window that is passed as
\c -embed command line argument.
The function returns TRUE on sucess or FALSE if no such command line
parameter is specified.
\sa embedClientIntoWindow()
*/
kdelibs'QXEmbed::processClientCmdline() (./kdelibs/kdeui/qxembed.cpp:647)
bool QXEmbed::processClientCmdline( QWidget* client, int& argc, char ** argv )
{
int myargc = argc;
WId window = 0;
int i, j;
j = 1;
for ( i=1; i<myargc; i++ ) {
if ( argv[i] && *argv[i] != '-' ) {
argv[j++] = argv[i];
continue;
}
QCString arg = argv[i];
if ( strcmp(arg,"-embed") == 0 && i < myargc-1 ) {
QCString s = argv[++i];
window = s.toInt();
} else
argv[j++] = argv[i];
}
argc = j;
if ( window != 0 ) {
embedClientIntoWindow( client, window );
return TRUE;
}
return FALSE;
}
/*!
A function for clients that embed themselves. The widget \a
client will be embedded in the window \a window. The application has
to ensure that \a window is the handle of the window identifier of
an QXEmbed widget.
\sa processClientCmdline()
*/
kdelibs'QXEmbed::embedClientIntoWindow() (./kdelibs/kdeui/qxembed.cpp:685)
void QXEmbed::embedClientIntoWindow(QWidget* client, WId window)
{
initialize();
XReparentWindow(qt_xdisplay(), client->winId(), window, 0, 0);
((QXEmbed*)client)->topData()->embedded = TRUE;
((QXEmbed*)client)->topData()->parentWinId = window;
client->show();
}
/*!
Specifies that this widget can use additional space, and that it can
survive on less than sizeHint().
*/
kdelibs'QXEmbed::sizePolicy() (./kdelibs/kdeui/qxembed.cpp:701)
QSizePolicy QXEmbed::sizePolicy() const
{
return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
}
/*!
Returns a size sufficient for the embedded window
*/
kdelibs'QXEmbed::sizeHint() (./kdelibs/kdeui/qxembed.cpp:710)
QSize QXEmbed::sizeHint() const
{
return minimumSizeHint();
}
/*!
\fn void QXEmbed::embeddedWindowDestroyed()
This signal is emitted when the embedded window has been destroyed.
\sa embeddedWinId()
*/
/*!
Returns a size sufficient for one character, and scroll bars.
*/
kdelibs'QXEmbed::minimumSizeHint() (./kdelibs/kdeui/qxembed.cpp:727)
QSize QXEmbed::minimumSizeHint() const
{
int minw = 0;
int minh = 0;
if ( window ) {
XSizeHints size;
long msize;
if (XGetWMNormalHints(qt_xdisplay(), window, &size, &msize)
&& ( size.flags & PMinSize) ) {
minw = size.min_width;
minh = size.min_height;
}
}
return QSize( minw, minh );
}
// for KDE