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