~x2go/x2go/x2goclient_master

« back to all changes in this revision

Viewing changes to embedwidget.cpp

  • Committer: Reinhard Tartler
  • Author(s): Oleksander Schneyder
  • Date: 2011-01-27 20:43:11 UTC
  • Revision ID: git-v1:af42fa37d555c1031810a868db687f39c2f9e574
Imported x2goclient_3.01-16.tar.gz

Summary: Imported x2goclient_3.01-16.tar.gz
Keywords:

Imported x2goclient_3.01-16.tar.gz
into Git repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// C++ Implementation: embedwidget
3
 
//
4
 
// Description:
5
 
//
6
 
//
7
 
// Author: Oleksandr Shneyder <oleksandr.shneyder@obviously-nice.de>, (C) 2009
8
 
//
9
 
// Copyright: See COPYING file that comes with this distribution
10
 
//
11
 
//
12
 
#include "x2goclientconfig.h"
13
 
#ifndef Q_OS_DARWIN
14
 
 
15
 
#include <QTimer>
16
 
#include <QBoxLayout>
17
 
#include "x2gologdebug.h"
18
 
 
19
 
#include "embedwidget.h"
20
 
#include "onmainwindow.h"
21
 
 
22
 
 
23
 
 
24
 
#ifdef Q_OS_LINUX
25
 
// #include <QX11EmbedWidget>
26
 
#include <QX11EmbedContainer>
27
 
#include <QX11Info>
28
 
#include <X11/Xlib.h>
29
 
#include <X11/Xutil.h>
30
 
#endif
31
 
#ifdef Q_OS_WIN
32
 
#include "wapi.h"
33
 
#endif
34
 
 
35
 
EmbedWidget::EmbedWidget ()
36
 
{
37
 
        oldParentSize=QSize ( 0,0 );
38
 
        embedContainer=0;
39
 
#ifdef Q_OS_WIN
40
 
        oldParentPos=QPoint ( 0,0 );
41
 
#endif
42
 
        childId=0l;
43
 
}
44
 
 
45
 
 
46
 
EmbedWidget::~EmbedWidget()
47
 
{
48
 
}
49
 
 
50
 
void EmbedWidget::initWidgets()
51
 
{
52
 
#ifdef Q_OS_LINUX
53
 
/*      qx11embedWidget=new QX11EmbedWidget;
54
 
        mainLay=new QVBoxLayout ( qx11embedWidget );
55
 
        mainLay->setContentsMargins ( 0,0,0,0 );
56
 
        ( ( ONMainWindow* ) this )->setParent ( qx11embedWidget );
57
 
        
58
 
        mainLay->addWidget ( ( ONMainWindow* ) this );
59
 
 
60
 
        qx11embedWidget->connect ( qx11embedWidget,
61
 
                                   SIGNAL ( containerClosed () ),
62
 
                                   ( ONMainWindow* ) this,
63
 
                                   SLOT ( close() ) );*/
64
 
 
65
 
        embedContainer=new QX11EmbedContainer (
66
 
            ( ( ONMainWindow* ) this )->mainWidget() );
67
 
        ( ( ONMainWindow* ) this )->connect (
68
 
            embedContainer,
69
 
            SIGNAL ( clientClosed() ),
70
 
            ( ONMainWindow* ) this,
71
 
            SLOT ( slotDetachProxyWindow() ) );
72
 
 
73
 
        embedContainer->connect (
74
 
            embedContainer,
75
 
            SIGNAL ( clientClosed() ),
76
 
            embedContainer,
77
 
            SLOT ( hide() ) );
78
 
#endif
79
 
#ifdef Q_OS_WIN
80
 
        embedContainer=new QWidget (
81
 
            ( ( ONMainWindow* ) this )->mainWidget() );
82
 
#endif
83
 
        embedContainer->hide();
84
 
        ( ( ONMainWindow* ) this )->mainLayout()->addWidget (
85
 
            embedContainer );
86
 
}
87
 
 
88
 
 
89
 
/*void EmbedWidget::embedInto ( long winId )
90
 
{
91
 
        parentId=winId;
92
 
        oldParentSize=getWindowSize ( parentId );
93
 
#ifdef Q_OS_LINUX
94
 
        qx11embedWidget->embedInto ( winId );
95
 
        QTimer::singleShot ( 100, qx11embedWidget, SLOT ( show() ) );
96
 
        qx11embedWidget->move ( 0,0 );
97
 
        qx11embedWidget->resize ( oldParentSize );
98
 
        x2goDebug<<"embed  window id: "<<qx11embedWidget->winId();
99
 
        QString title;
100
 
        QTextStream ( &title ) <<"x2goembedded "<<winId;
101
 
        qx11embedWidget->setWindowTitle ( title );
102
 
#endif
103
 
#ifdef Q_OS_WIN
104
 
        wapiSetParent (
105
 
            ( HWND ) ( ( ONMainWindow* ) this )->winId(),
106
 
            ( HWND ) winId );
107
 
//      wapiHideFromTaskBar(( HWND ) ( ( ONMainWindow* ) this )->winId());
108
 
        QTimer::singleShot ( 50, ( ( ONMainWindow* ) this ), SLOT ( show() ) );
109
 
        QTimer::singleShot ( 100, ( ONMainWindow* ) this,
110
 
                             SLOT ( slotUpdateEmbed() ) );
111
 
#endif
112
 
        updateTimer = new QTimer ( ( ONMainWindow* ) this );
113
 
        ( ( ONMainWindow* ) this )->connect ( updateTimer, SIGNAL ( timeout() ),
114
 
                                              ( ONMainWindow* ) this,
115
 
                                              SLOT ( slotUpdateEmbed() ) );
116
 
        updateTimer->start ( 500 );
117
 
}
118
 
 
119
 
 
120
 
void EmbedWidget::slotUpdateEmbed()
121
 
{
122
 
        QSize sz=getWindowSize ( parentId );
123
 
        if ( sz!=oldParentSize )
124
 
        {
125
 
                oldParentSize=sz;
126
 
#ifdef Q_OS_LINUX
127
 
                qx11embedWidget->resize ( oldParentSize );
128
 
#endif
129
 
#ifdef Q_OS_WIN
130
 
                moveEmbed ( 0,0 );
131
 
                ( ( ONMainWindow* ) this )->resize ( oldParentSize );
132
 
#endif
133
 
        }
134
 
#ifdef Q_OS_WIN
135
 
        if ( sz==QSize ( 0,0 ) )
136
 
        {
137
 
                QRect rec;
138
 
                if ( !wapiClientRect ( ( HWND ) parentId,rec ) )
139
 
                {
140
 
                        //parent not exist, close x2goclient;
141
 
                        x2goDebug<<"slotUpdateEmbed: parent closed\n";
142
 
                        ( ( ONMainWindow* ) this )->close();
143
 
                }
144
 
        }
145
 
        if ( ( ( ONMainWindow* ) this )->pos() !=oldParentPos )
146
 
        {
147
 
                moveEmbed ( 0,0 );
148
 
                ( ( ONMainWindow* ) this )->resize ( oldParentSize );
149
 
        }
150
 
        if ( childId )
151
 
        {
152
 
                QRect rec;
153
 
                if ( !wapiWindowRect ( ( HWND ) childId,rec ) )
154
 
                {
155
 
                        x2goDebug<<"slotUpdateEmbed: child closed\n";
156
 
                        detachClient();
157
 
                        return;
158
 
                }
159
 
                if ( ( embedContainer->size() != oldContainerSize ) ||
160
 
                        ( rec.topLeft() !=oldChildPos ) )
161
 
                {
162
 
                        moveEmbedChild ( 0,0 );
163
 
                }
164
 
                wapiUpdateWindow ( ( HWND ) childId );
165
 
        }
166
 
//      wapiUpdateWindow ( ( HWND ) ( ( ONMainWindow* ) this )->winId() );
167
 
        ( ( ONMainWindow* ) this )->update();
168
 
#endif
169
 
}
170
 
*/
171
 
QSize EmbedWidget::getWindowSize ( long winId )
172
 
{
173
 
 
174
 
#ifdef Q_OS_LINUX
175
 
        XWindowAttributes atr;
176
 
        if ( XGetWindowAttributes ( QX11Info::display(),winId,&atr ) )
177
 
                return QSize ( atr.width,atr.height );
178
 
        return QSize ( 0,0 );
179
 
#endif
180
 
#ifdef Q_OS_WIN
181
 
        QRect rec;
182
 
        if ( wapiClientRect ( ( HWND ) winId,rec ) )
183
 
                return rec.size();
184
 
        else
185
 
                return QSize ( 0,0 );
186
 
#endif
187
 
}
188
 
 
189
 
#ifdef Q_OS_WIN
190
 
void EmbedWidget::moveEmbed ( int x, int y )
191
 
{
192
 
        int vBorder=0;
193
 
        int hBorder=0;
194
 
        int barHeight=0;
195
 
 
196
 
        if ( wapiGetBorders ( ( HWND ) ( ( ONMainWindow* ) this )->winId(),
197
 
                              vBorder, hBorder, barHeight ) )
198
 
        {
199
 
                oldParentPos.setX ( x-hBorder );
200
 
                oldParentPos.setY ( y-vBorder-barHeight );
201
 
                ( ( ONMainWindow* ) this )->move ( oldParentPos.x(),
202
 
                                                   oldParentPos.y() );
203
 
        }
204
 
}
205
 
 
206
 
void EmbedWidget::moveEmbedChild ( int x, int y )
207
 
{
208
 
        int vBorder=0;
209
 
        int hBorder=0;
210
 
        int barHeight=0;
211
 
        oldContainerSize=embedContainer->size();
212
 
 
213
 
        if ( wapiGetBorders ( ( HWND ) childId,
214
 
                              vBorder, hBorder, barHeight ) )
215
 
        {
216
 
 
217
 
                oldChildPos.setX ( x-hBorder );
218
 
                oldChildPos.setY ( y-vBorder-barHeight );
219
 
                wapiMoveWindow ( ( HWND ) childId,oldChildPos.x(),
220
 
                                 oldChildPos.y(),
221
 
                                 oldContainerSize.width() +2*hBorder,
222
 
                                 oldContainerSize.height() +2*vBorder+barHeight,
223
 
                                 false );
224
 
        }
225
 
}
226
 
#endif
227
 
 
228
 
 
229
 
#ifdef Q_OS_LINUX
230
 
long EmbedWidget::X11FindWindow ( QString text, long rootWin )
231
 
{
232
 
        Window    wParent;
233
 
        Window    wRoot;
234
 
        Window   *child_list;
235
 
        unsigned  nChildren;
236
 
        long proxyId=0;
237
 
        if ( !rootWin )
238
 
                rootWin= XDefaultRootWindow ( QX11Info::display() );
239
 
 
240
 
        if ( XQueryTree ( QX11Info::display(),rootWin,&wRoot,&wParent,
241
 
                          &child_list,&nChildren ) )
242
 
        {
243
 
                for ( uint i=0;i<nChildren;++i )
244
 
                {
245
 
                        char *wname;
246
 
                        if ( XFetchName ( QX11Info::display(),
247
 
                                          child_list[i],&wname ) )
248
 
                        {
249
 
                                QString title ( wname );
250
 
                                XFree ( wname );
251
 
                                if ( title==text )
252
 
                                {
253
 
                                        proxyId=child_list[i];
254
 
                                        break;
255
 
                                }
256
 
                        }
257
 
                        proxyId=X11FindWindow ( text, child_list[i] );
258
 
                        if ( proxyId )
259
 
                                break;
260
 
                }
261
 
                XFree ( child_list );
262
 
        }
263
 
        return proxyId;
264
 
}
265
 
#endif
266
 
 
267
 
long EmbedWidget::findWindow ( QString text )
268
 
{
269
 
#ifdef Q_OS_LINUX
270
 
        return X11FindWindow ( text );
271
 
#endif
272
 
#ifdef Q_OS_WIN
273
 
        return ( long ) wapiFindWindow ( 0,text.utf16() );
274
 
#endif
275
 
}
276
 
 
277
 
 
278
 
void EmbedWidget::embedWindow ( long wndId )
279
 
{
280
 
        childId=wndId;
281
 
        embedContainer->show();
282
 
#ifdef Q_OS_LINUX
283
 
        embedContainer->embedClient ( wndId );
284
 
#endif
285
 
#ifdef Q_OS_WIN
286
 
        wapiSetParent ( ( HWND ) childId,
287
 
                        ( HWND ) ( embedContainer->winId() ) );
288
 
        oldContainerSize=QSize ( 0,0 );
289
 
        oldChildPos=QPoint ( 0,0 );
290
 
//      slotUpdateEmbed();
291
 
#endif
292
 
}
293
 
 
294
 
 
295
 
void EmbedWidget::detachClient()
296
 
{
297
 
#ifdef Q_OS_LINUX
298
 
        if ( embedContainer )
299
 
        {
300
 
                embedContainer->discardClient();
301
 
        }
302
 
#endif
303
 
#ifdef Q_OS_WIN
304
 
        wapiSetParent ( ( HWND ) childId, ( HWND ) 0 );
305
 
        ( ( ONMainWindow* ) this )->slotDetachProxyWindow();
306
 
        if ( childId )
307
 
        {
308
 
                wapiMoveWindow ( ( HWND ) childId,0,0,
309
 
                                 oldContainerSize.width(),
310
 
                                 oldContainerSize.height(),true );
311
 
        }
312
 
#endif
313
 
        childId=0;
314
 
}
315
 
 
316
 
/*
317
 
void EmbedWidget::closeEmbedWidget()
318
 
{
319
 
#ifdef Q_OS_LINUX
320
 
        if ( qx11embedWidget )
321
 
        {
322
 
                qx11embedWidget->close();
323
 
                qx11embedWidget=0;
324
 
        }
325
 
#endif
326
 
}
327
 
*/
328
 
#endif //(Q_OS_DARWIN)