00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "TGSplitter.h"
00023 #include "TGPicture.h"
00024 #include "Riostream.h"
00025
00026
00027 ClassImp(TGSplitter)
00028 ClassImp(TGVSplitter)
00029 ClassImp(TGHSplitter)
00030 ClassImp(TGVFileSplitter)
00031
00032
00033
00034 TGSplitter::TGSplitter(const TGWindow *p, UInt_t w, UInt_t h,
00035 UInt_t options, ULong_t back) :
00036 TGFrame(p, w, h, options, back),
00037 fDragging (kFALSE),
00038 fExternalHandler (kFALSE),
00039 fSplitterPic (0)
00040 {
00041
00042
00043 fSplitCursor = kNone;
00044 fEditDisabled = kTRUE;
00045 }
00046
00047
00048 void TGSplitter::DragStarted()
00049 {
00050
00051
00052 Emit("DragStarted()");
00053 }
00054
00055
00056 void TGSplitter::Moved(Int_t delta)
00057 {
00058
00059
00060 Emit("Moved(Int_t)", delta);
00061 }
00062
00063
00064 TGVSplitter::TGVSplitter(const TGWindow *p, UInt_t w, UInt_t h,
00065 UInt_t options, ULong_t back) : TGSplitter(p, w, h, options, back)
00066 {
00067
00068
00069 fSplitCursor = kNone;
00070 fSplitterPic = fClient->GetPicture("splitterv.xpm");
00071 fFrameHeight = h;
00072 fFrameWidth = w;
00073 fLeft = kTRUE;
00074 fMax = fMin = 0;
00075 fStartX = 0;
00076
00077 if (!fSplitterPic)
00078 Error("TGVSplitter", "splitterv.xpm not found");
00079
00080 if (p && !p->InheritsFrom(TGCompositeFrame::Class())) {
00081 Error("TGVSplitter", "parent must inherit from a TGCompositeFrame");
00082 return;
00083 }
00084 if (p && !(((TGCompositeFrame*)p)->GetOptions() & kHorizontalFrame)) {
00085 Error("TGVSplitter", "parent must have a horizontal layout manager");
00086 return;
00087 }
00088
00089 fSplitCursor = gVirtualX->CreateCursor(kArrowHor);
00090 fFrame = 0;
00091
00092 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
00093 kButtonPressMask | kButtonReleaseMask |
00094 kPointerMotionMask, kNone, kNone);
00095
00096 AddInput(kEnterWindowMask | kLeaveWindowMask);
00097 }
00098
00099
00100 TGVSplitter::TGVSplitter(const TGWindow *p, UInt_t w, UInt_t h, Bool_t external) :
00101 TGSplitter(p, w, h, kChildFrame, GetDefaultFrameBackground())
00102 {
00103
00104
00105 fExternalHandler = external;
00106
00107 fSplitCursor = kNone;
00108 fSplitterPic = fClient->GetPicture("splitterv.xpm");
00109
00110 if (!fSplitterPic)
00111 Error("TGVSplitter", "splitterv.xpm not found");
00112
00113 fSplitCursor = gVirtualX->CreateCursor(kArrowHor);
00114 fFrame = 0;
00115 fFrameHeight = h;
00116 fFrameWidth = w;
00117 fLeft = kTRUE;
00118 fMax = fMin = 0;
00119 fStartX = 0;
00120
00121 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
00122 kButtonPressMask | kButtonReleaseMask |
00123 kPointerMotionMask, kNone, kNone);
00124
00125 AddInput(kEnterWindowMask | kLeaveWindowMask);
00126 }
00127
00128
00129 TGVSplitter::~TGVSplitter()
00130 {
00131
00132
00133 if (fSplitterPic) fClient->FreePicture(fSplitterPic);
00134 }
00135
00136
00137 void TGVSplitter::SetFrame(TGFrame *frame, Bool_t left)
00138 {
00139
00140
00141
00142 fFrame = frame;
00143 fLeft = left;
00144
00145 if (!fExternalHandler && !(fFrame->GetOptions() & kFixedWidth))
00146 Error("SetFrame", "resize frame must have kFixedWidth option set");
00147 }
00148
00149
00150 Bool_t TGVSplitter::HandleButton(Event_t *event)
00151 {
00152
00153
00154 if (fSplitCursor == kNone) return kTRUE;
00155
00156 if (!fExternalHandler && !fFrame) {
00157 Error("HandleButton", "frame to be resized not set");
00158 return kTRUE;
00159 }
00160
00161 if (event->fType == kButtonPress) {
00162 fStartX = event->fXRoot;
00163 fDragging = kTRUE;
00164
00165 if (fExternalHandler) {
00166 fMin = 0;
00167 fMax = 99999;
00168 DragStarted();
00169 } else {
00170 Int_t x, y;
00171 gVirtualX->GetWindowSize(fFrame->GetId(), x, y, fFrameWidth, fFrameHeight);
00172
00173
00174 Int_t xroot, yroot;
00175 UInt_t w, h;
00176 Window_t wdum;
00177 gVirtualX->GetWindowSize(fParent->GetId(), x, y, w, h);
00178 gVirtualX->TranslateCoordinates(fParent->GetParent()->GetId(),
00179 fClient->GetDefaultRoot()->GetId(),
00180 x, y, xroot, yroot, wdum);
00181 fMin = xroot;
00182 fMax = xroot + w - 2;
00183 }
00184
00185
00186 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
00187 kPointerMotionMask, kNone, fSplitCursor,
00188 kTRUE, kFALSE);
00189 } else {
00190 fDragging = kFALSE;
00191 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
00192 }
00193 return kTRUE;
00194 }
00195
00196
00197 Bool_t TGVSplitter::HandleMotion(Event_t *event)
00198 {
00199
00200
00201 if (fDragging) {
00202 Int_t xr = event->fXRoot;
00203 if (xr > fMax) xr = fMax;
00204 if (xr < fMin) xr = fMin;
00205 Int_t delta = xr - fStartX;
00206 if (fExternalHandler) {
00207 if (delta != 0) {
00208 Moved(delta);
00209 fStartX = xr;
00210 }
00211 } else {
00212 Int_t w = (Int_t) fFrameWidth;
00213 if (fLeft)
00214 w += delta;
00215 else
00216 w -= delta;
00217 if (w < 0) w = 0;
00218 fStartX = xr;
00219
00220 if (delta != 0) {
00221 fFrameWidth = w;
00222 fFrame->Resize(fFrameWidth, fFrameHeight);
00223
00224 TGCompositeFrame *p = (TGCompositeFrame *) GetParent();
00225 p->Layout();
00226 }
00227 }
00228 }
00229 return kTRUE;
00230 }
00231
00232
00233 Bool_t TGVSplitter::HandleCrossing(Event_t *event)
00234 {
00235
00236
00237 if (event->fType == kEnterNotify)
00238 gVirtualX->SetCursor(fId, fSplitCursor);
00239 else
00240 gVirtualX->SetCursor(fId, kNone);
00241
00242 return kTRUE;
00243 }
00244
00245
00246 void TGVSplitter::DrawBorder()
00247 {
00248
00249
00250 if (fSplitterPic) {
00251 Int_t posx = (fWidth/2)-(fSplitterPic->GetWidth()/2);
00252 Int_t posy = (fHeight/2)-(fSplitterPic->GetHeight()/2);
00253 fSplitterPic->Draw(fId, GetBckgndGC()(), posx, posy);
00254 }
00255 }
00256
00257
00258
00259 TGHSplitter::TGHSplitter(const TGWindow *p, UInt_t w, UInt_t h,
00260 UInt_t options, ULong_t back) : TGSplitter(p, w, h, options, back)
00261 {
00262
00263
00264 fSplitCursor = kNone;
00265
00266 fSplitterPic = fClient->GetPicture("splitterh.xpm");
00267
00268 if (!fSplitterPic)
00269 Error("TGHSplitter", "splitterh.xpm not found");
00270
00271 if (p && !p->InheritsFrom(TGCompositeFrame::Class())) {
00272 Error("TGHSplitter", "parent must inherit from a TGCompositeFrame");
00273 return;
00274 }
00275 if (p && !(((TGCompositeFrame*)p)->GetOptions() & kVerticalFrame)) {
00276 Error("TGHSplitter", "parent must have a vertical layout manager");
00277 return;
00278 }
00279
00280 fSplitCursor = gVirtualX->CreateCursor(kArrowVer);
00281 fFrame = 0;
00282 fFrameHeight = h;
00283 fFrameWidth = w;
00284 fAbove = kTRUE;
00285 fMax = fMin = 0;
00286 fStartY = 0;
00287
00288 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
00289 kButtonPressMask | kButtonReleaseMask |
00290 kPointerMotionMask, kNone, kNone);
00291
00292 AddInput(kEnterWindowMask | kLeaveWindowMask);
00293 }
00294
00295
00296 TGHSplitter::TGHSplitter(const TGWindow *p, UInt_t w, UInt_t h, Bool_t external) :
00297 TGSplitter(p, w, h, kChildFrame, GetDefaultFrameBackground())
00298 {
00299
00300
00301 fExternalHandler = external;
00302
00303 fSplitCursor = kNone;
00304
00305 fSplitterPic = fClient->GetPicture("splitterh.xpm");
00306
00307 if (!fSplitterPic)
00308 Error("TGHSplitter", "splitterh.xpm not found");
00309
00310 fSplitCursor = gVirtualX->CreateCursor(kArrowVer);
00311 fFrame = 0;
00312 fFrameHeight = h;
00313 fFrameWidth = w;
00314 fAbove = kTRUE;
00315 fMax = fMin = 0;
00316 fStartY = 0;
00317
00318 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
00319 kButtonPressMask | kButtonReleaseMask |
00320 kPointerMotionMask, kNone, kNone);
00321
00322 AddInput(kEnterWindowMask | kLeaveWindowMask);
00323 }
00324
00325
00326 TGHSplitter::~TGHSplitter()
00327 {
00328
00329
00330 if (fSplitterPic) fClient->FreePicture(fSplitterPic);
00331 }
00332
00333
00334 void TGHSplitter::SetFrame(TGFrame *frame, Bool_t above)
00335 {
00336
00337
00338
00339 fFrame = frame;
00340 fAbove = above;
00341
00342 if (!fExternalHandler && !(fFrame->GetOptions() & kFixedHeight))
00343 Error("SetFrame", "resize frame must have kFixedHeight option set");
00344 }
00345
00346
00347 Bool_t TGHSplitter::HandleButton(Event_t *event)
00348 {
00349
00350
00351 if (fSplitCursor == kNone) return kTRUE;
00352
00353 if (!fExternalHandler && !fFrame) {
00354 Error("HandleButton", "frame to be resized not set");
00355 return kTRUE;
00356 }
00357
00358 if (event->fType == kButtonPress) {
00359 fStartY = event->fYRoot;
00360 fDragging = kTRUE;
00361
00362 if (fExternalHandler) {
00363 fMin = 0;
00364 fMax = 99999;
00365 DragStarted();
00366 } else {
00367 Int_t x, y;
00368 gVirtualX->GetWindowSize(fFrame->GetId(), x, y, fFrameWidth, fFrameHeight);
00369
00370
00371 Int_t xroot, yroot;
00372 UInt_t w, h;
00373 Window_t wdum;
00374 gVirtualX->GetWindowSize(fParent->GetId(), x, y, w, h);
00375 gVirtualX->TranslateCoordinates(fParent->GetParent()->GetId(),
00376 fClient->GetDefaultRoot()->GetId(),
00377 x, y, xroot, yroot, wdum);
00378 fMin = yroot;
00379 fMax = yroot + h - 2;
00380 }
00381
00382
00383 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
00384 kPointerMotionMask, kNone, fSplitCursor,
00385 kTRUE, kFALSE);
00386 } else {
00387 fDragging = kFALSE;
00388 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
00389 }
00390 return kTRUE;
00391 }
00392
00393
00394 Bool_t TGHSplitter::HandleMotion(Event_t *event)
00395 {
00396
00397
00398 if (fDragging) {
00399 Int_t yr = event->fYRoot;
00400 if (yr > fMax) yr = fMax;
00401 if (yr < fMin) yr = fMin;
00402 Int_t delta = yr - fStartY;
00403 if (fExternalHandler) {
00404 if (delta != 0) {
00405 Moved(delta);
00406 fStartY = yr;
00407 }
00408 } else {
00409 Int_t h = (Int_t) fFrameHeight;
00410 if (fAbove)
00411 h += delta;
00412 else
00413 h -= delta;
00414 if (h < 0) h = 0;
00415 fStartY = yr;
00416
00417 if (delta != 0) {
00418 fFrameHeight = h;
00419 fFrame->Resize(fFrameWidth, fFrameHeight);
00420
00421 TGCompositeFrame *p = (TGCompositeFrame *) GetParent();
00422 p->Layout();
00423 }
00424 }
00425 }
00426 return kTRUE;
00427 }
00428
00429
00430 Bool_t TGHSplitter::HandleCrossing(Event_t *event)
00431 {
00432
00433
00434 if (event->fType == kEnterNotify)
00435 gVirtualX->SetCursor(fId, fSplitCursor);
00436 else
00437 gVirtualX->SetCursor(fId, kNone);
00438
00439 return kTRUE;
00440 }
00441
00442
00443 void TGHSplitter::DrawBorder()
00444 {
00445
00446
00447 if (fSplitterPic) {
00448 Int_t posx = (fWidth/2)-(fSplitterPic->GetWidth()/2);
00449 Int_t posy = (fHeight/2)-(fSplitterPic->GetHeight()/2);
00450 fSplitterPic->Draw(fId, GetBckgndGC()(), posx, posy);
00451 }
00452 }
00453
00454
00455 TGVFileSplitter::TGVFileSplitter(const TGWindow *p, UInt_t w, UInt_t h,
00456 UInt_t options, Pixel_t back):
00457 TGVSplitter(p, w, h, options, back)
00458 {
00459
00460
00461
00462
00463 }
00464
00465
00466 TGVFileSplitter::~TGVFileSplitter()
00467 {
00468
00469 }
00470
00471
00472 Bool_t TGVFileSplitter::HandleMotion(Event_t *event)
00473 {
00474
00475
00476 fMin = 30;
00477
00478 if (fDragging) {
00479 Int_t xr = event->fXRoot;
00480 if (xr > fMax) xr = fMax;
00481 if (xr < fMin) xr = fMin;
00482 Int_t delta = xr - fStartX;
00483 Int_t w = (Int_t) fFrameWidth;
00484 if (fLeft)
00485 w += delta;
00486 else
00487 w -= delta;
00488
00489 if (w < 0) w = 0;
00490 fStartX = xr;
00491
00492 if (delta != 0) {
00493 delta = w - fFrameWidth;
00494 fFrameWidth = w;
00495
00496 TGCompositeFrame *p = (TGCompositeFrame *) GetParent();
00497 p->Resize( p->GetWidth() + delta, p->GetHeight() );
00498
00499 fFrame->Resize(fFrameWidth, fFrameHeight);
00500
00501 p->Layout();
00502 LayoutHeader((TGFrame *)fFrame);
00503 }
00504 }
00505 return kTRUE;
00506 }
00507
00508
00509 Bool_t TGVFileSplitter::HandleButton(Event_t *event)
00510 {
00511
00512
00513 if ( event->fType == kButtonPress) {
00514 ButtonPressed();
00515 } else if ( event->fType == kButtonRelease) {
00516 LayoutHeader(0);
00517 LayoutListView();
00518 ButtonReleased();
00519 } else if ( event->fType == kButtonDoubleClick ) {
00520 DoubleClicked(this);
00521 }
00522 return TGVSplitter::HandleButton(event);
00523 }
00524
00525
00526 void TGVFileSplitter::LayoutHeader(TGFrame *f)
00527 {
00528
00529
00530 Emit("LayoutHeader(TGFrame*)", (Long_t)f);
00531 }
00532
00533
00534 void TGVFileSplitter::LayoutListView()
00535 {
00536
00537
00538 Emit("LayoutListView()");
00539 }
00540
00541
00542 void TGVFileSplitter::ButtonPressed()
00543 {
00544
00545
00546 Emit("ButtonPressed()");
00547 }
00548
00549
00550 void TGVFileSplitter::ButtonReleased()
00551 {
00552
00553
00554 Emit("ButtonReleased()");
00555 }
00556
00557
00558 void TGVFileSplitter::DoubleClicked(TGVFileSplitter* splitter)
00559 {
00560
00561
00562 Emit("DoubleClicked(TGVFileSplitter*)", (Long_t) splitter);
00563 }
00564
00565
00566 Bool_t TGVFileSplitter::HandleDoubleClick(Event_t *)
00567 {
00568
00569
00570 DoubleClicked(this);
00571 return kTRUE;
00572 }
00573
00574
00575 void TGVSplitter::SavePrimitive(ostream &out, Option_t *option )
00576 {
00577
00578
00579 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
00580
00581 out << " TGVSplitter *";
00582 out << GetName() <<" = new TGVSplitter("<< fParent->GetName()
00583 << "," << GetWidth() << "," << GetHeight();
00584
00585 if (fBackground == GetDefaultFrameBackground()) {
00586 if (!GetOptions()) {
00587 out <<");" << endl;
00588 } else {
00589 out << "," << GetOptionString() <<");" << endl;
00590 }
00591 } else {
00592 out << "," << GetOptionString() << ",ucolor);" << endl;
00593 }
00594 if (option && strstr(option, "keep_names"))
00595 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00596
00597
00598
00599
00600 if (GetLeft()) {
00601 out << " " << GetName() << "->SetFrame(" << GetFrame()->GetName();
00602 if (GetLeft()) out << ",kTRUE);" << endl;
00603 else out << ",kFALSE);"<< endl;
00604 }
00605 }
00606
00607
00608 void TGHSplitter::SavePrimitive(ostream &out, Option_t *option )
00609 {
00610
00611
00612 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
00613
00614 out << " TGHSplitter *";
00615 out << GetName() <<" = new TGHSplitter("<< fParent->GetName()
00616 << "," << GetWidth() << "," << GetHeight();
00617
00618 if (fBackground == GetDefaultFrameBackground()) {
00619 if (!GetOptions()) {
00620 out <<");" << endl;
00621 } else {
00622 out << "," << GetOptionString() <<");" << endl;
00623 }
00624 } else {
00625 out << "," << GetOptionString() << ",ucolor);" << endl;
00626 }
00627 if (option && strstr(option, "keep_names"))
00628 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00629
00630
00631
00632
00633 if (GetAbove()) {
00634 out << " " << GetName() << "->SetFrame(" << GetFrame()->GetName();
00635 if (GetAbove()) out << ",kTRUE);" << endl;
00636 else out << ",kFALSE);"<< endl;
00637 }
00638 }
00639
00640
00641 void TGVFileSplitter::SavePrimitive(ostream &out, Option_t *option )
00642 {
00643
00644
00645 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
00646
00647 out << " TGVFileSplitter *";
00648 out << GetName() <<" = new TGVFileSplitter("<< fParent->GetName()
00649 << "," << GetWidth() << "," << GetHeight();
00650
00651 if (fBackground == GetDefaultFrameBackground()) {
00652 if (!GetOptions()) {
00653 out <<");" << endl;
00654 } else {
00655 out << "," << GetOptionString() <<");" << endl;
00656 }
00657 } else {
00658 out << "," << GetOptionString() << ",ucolor);" << endl;
00659 }
00660 if (option && strstr(option, "keep_names"))
00661 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00662
00663 out << " " << GetName() << "->SetFrame(" << GetFrame()->GetName();
00664 if (GetLeft()) out << ",kTRUE);" << endl;
00665 else out << ",kFALSE);"<< endl;
00666 }
00667