00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "tqrootwindow.h"
00017
00018 #include <iostream.h>
00019
00020 #include "TVirtualX.h"
00021 #include "TSystem.h"
00022 #include "GuiTypes.h"
00023
00024 #include "qevent.h"
00025 #include "qpainter.h"
00026
00027 using namespace std;
00028
00029 #include "lockguard.h"
00030
00032 TQRootFrame::TQRootFrame(Window_t wid)
00033 :TGCompositeFrame(gClient,wid,new TGMainFrame(gClient->GetDefaultRoot(),100,100))
00034 {
00035
00036
00037 }
00038
00039 TQRootFrame::~TQRootFrame()
00040 {
00041 delete fParent;
00042 }
00043
00044 Bool_t TQRootFrame::HandleEvent(Event_t *event)
00045 {
00046
00047
00048 return TGCompositeFrame::HandleEvent(event);
00049 }
00050
00051
00052 void TQRootFrame::CloseWindow()
00053 {
00054 UnmapWindow();
00055 }
00056
00057
00059
00060
00061 TQRootWindow::TQRootWindow( QWidget *parent, const char *name)
00062 : QWidget( parent, name)
00063 {
00064
00065 setUpdatesEnabled( true );
00066 setMouseTracking(true);
00067
00068
00069 setFocusPolicy( TabFocus );
00070 setCursor( Qt::crossCursor );
00071
00072
00073 fiWinid=gVirtualX->AddWindow(winId(),145,600);
00074
00075
00076 gSystem->Sleep(60);
00077
00078 Window_t handle=gVirtualX->GetWindowID(fiWinid);
00079
00080 fxRootwindow=new TQRootFrame(handle);
00081 fxRootwindow->Resize();
00082 if ( parent ) parent->installEventFilter( this );
00083
00084
00085 }
00086
00087
00088 void TQRootWindow::AddSubFrame(TGFrame* f, TGLayoutHints* l)
00089 {
00090
00091 fxRootwindow->AddFrame(f,l);
00092 fxRootwindow->MapWindow();
00093 fxRootwindow->MapSubwindows();
00094 fxRootwindow->Resize();
00095 polish();
00096 update();
00097 show();
00098 }
00099
00100 void TQRootWindow::SetEditable(bool on)
00101 {
00102 fxRootwindow->SetEditable(on);
00103 }
00104
00105 Event_t* TQRootWindow::MapQMouseEvent(QMouseEvent *e)
00106 {
00107 if(e==0) return 0;
00108 Event_t* rev= new Event_t;
00109
00110 rev->fX=e->x();
00111 rev->fY=e->y();
00112 rev->fXRoot= e->globalX();
00113 rev->fYRoot= e->globalY();
00114
00115
00116 if(e->type() == QEvent::MouseButtonPress) rev->fType = kButtonPress;
00117 else if(e->type() == QEvent::MouseButtonRelease) rev->fType = kButtonRelease;
00118 else if(e->type() == QEvent::MouseButtonDblClick) rev->fType = kButtonDoubleClick;
00119 else if(e->type() == QEvent::MouseMove) rev->fType = kMotionNotify;
00120 else if(e->type() == QEvent::KeyPress) rev->fType = kGKeyPress;
00121 else if(e->type() == QEvent::KeyRelease) rev->fType = kKeyRelease;
00122 else rev->fType = kOtherEvent;
00123
00124
00125 rev->fState=0;
00126 if(e->state() & LeftButton)
00127 rev->fState |= kButton1Mask;
00128 if(e->state() & RightButton)
00129 rev->fState |= kButton3Mask;
00130 if(e->state() & MidButton)
00131 rev->fState |= kButton2Mask;
00132 if(e->state() & MouseButtonMask)
00133 rev->fState |= kButton1Mask;
00134 if(e->state() & ShiftButton)
00135 rev->fState |= kKeyShiftMask;
00136 if(e->state() & ControlButton)
00137 rev->fState |= kKeyControlMask;
00138 if(e->state() & AltButton)
00139 rev->fState |= kKeyMod1Mask;
00140 if(e->state() & MetaButton)
00141 rev->fState |= kKeyMod1Mask;
00142
00143
00144
00145
00146
00147 rev->fCode = NoButton;
00148 if(e->button() & LeftButton)
00149 rev->fCode |= kButton1Mask;
00150 if(e->button() & RightButton)
00151 rev->fCode |= kButton3Mask;
00152 if(e->button() & MidButton)
00153 rev->fCode |= kButton2Mask;
00154
00155 rev->fUser[0]=0;
00156 rev->fWindow = gVirtualX->GetWindowID(fiWinid);
00157 rev->fSendEvent = 0;
00158 rev->fTime = 0;
00159
00160
00161
00162 return rev;
00163 }
00164
00165
00166
00167 void TQRootWindow::paintEvent( QPaintEvent * )
00168 {
00169
00170
00171 if(fxRootwindow){
00172
00173
00174
00175
00176
00177 fxRootwindow->Resize(width(),height());
00178 }
00179 }
00180
00181
00182 bool TQRootWindow ::eventFilter( QObject *o, QEvent *e )
00183 {
00184
00185
00186
00187 QMouseEvent* me=dynamic_cast<QMouseEvent*>(e);
00188 if(me)
00189 {
00190
00191 Event_t* roote=MapQMouseEvent(me);
00192 if(fxRootwindow) fxRootwindow->HandleEvent(roote);
00193 delete roote;
00194 return FALSE;
00195 }
00196
00197
00198 if ( e->type() == QEvent::Close) {
00199 delete fxRootwindow;
00200 fxRootwindow=0;
00201 return FALSE;
00202 }
00203
00204
00205 return QWidget::eventFilter( o, e );
00206 }
00207
00208
00209
00210 void TQRootWindow::closeEvent( QCloseEvent * e){
00211
00212 delete fxRootwindow;
00213 fxRootwindow=0;
00214 e->accept();
00215 return;
00216 }
00217
00218
00219
00220 TQRootWindow::~TQRootWindow()
00221 {
00222 delete fxRootwindow;
00223 fxRootwindow=0;
00224 }
00225
00226 TGCompositeFrame* TQRootWindow::GetRootFrame()
00227 {
00228 return fxRootwindow;
00229 }
00230
00231
00232