50 #include "RConfigure.h"
54 ClassImp(TGViewFrame);
59 TGViewFrame::TGViewFrame(TGView *v, UInt_t w, UInt_t h, UInt_t options,
61 TGCompositeFrame(v, w, h, options | kOwnBackground, back)
65 SetBackgroundColor(back);
67 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
68 kButtonPressMask | kButtonReleaseMask |
69 kButtonMotionMask, kNone, kNone);
71 AddInput(kKeyPressMask | kEnterWindowMask | kLeaveWindowMask |
74 SetWindowAttributes_t wattr;
75 wattr.fMask = kWAWinGravity | kWABitGravity;
76 wattr.fBitGravity = 1;
77 wattr.fWinGravity = 1;
78 gVirtualX->ChangeWindowAttributes(fId, &wattr);
81 fEditDisabled = kEditDisableGrab | kEditDisableKeyEnable | kEditDisableBtnEnable;
91 TGView::TGView(
const TGWindow *p, UInt_t w, UInt_t h, Int_t
id,
92 UInt_t xMargin, UInt_t yMargin, UInt_t options,
93 UInt_t sboptions, ULong_t back)
94 : TGCompositeFrame(p, w, h, options, GetDefaultFrameBackground())
98 fWidgetFlags = kWidgetWantFocus;
104 fExposedRegion.Empty();
106 fClipboard = fClient->GetResourcePool()->GetClipboard();
108 fCanvas =
new TGViewFrame(
this, 10, 10, kChildFrame | kOwnBackground, back);
111 if (!(sboptions & kNoHSB)) {
112 fHsb =
new TGHScrollBar(
this, 10, 10, kChildFrame);
114 fHsb->Associate(
this);
119 if (!(sboptions & kNoVSB)) {
120 fVsb =
new TGVScrollBar(
this, 10, 10, kChildFrame);
122 fVsb->Associate(
this);
127 fWhiteGC.SetGraphicsExposures(kTRUE);
128 fWhiteGC.SetBackground(back);
132 fVsb->SetEditDisabled(kEditDisableGrab | kEditDisableBtnEnable);
135 fHsb->SetEditDisabled(kEditDisableGrab | kEditDisableBtnEnable);
138 fEditDisabled = kEditDisableLayout;
141 delete fLayoutManager;
150 if (!MustCleanup()) {
160 void TGView::Clear(Option_t *)
164 fMousePos.fX = fMousePos.fY = -1;
165 fVisible.fX = fVisible.fY = 0;
166 UpdateBackgroundStart();
167 fVirtualSize = TGDimension(0, 0);
169 gVirtualX->ClearArea(fCanvas->GetId(), 0, 0,
170 fCanvas->GetWidth(), fCanvas->GetHeight());
177 void TGView::SetVisibleStart(Int_t newTop, Int_t direction)
179 if (direction == kHorizontal) {
180 if (newTop / fScrollVal.fX == fVisible.fX / fScrollVal.fX) {
183 ScrollCanvas(newTop, kHorizontal);
185 if (newTop / fScrollVal.fY == fVisible.fY / fScrollVal.fY) {
188 ScrollCanvas(newTop, kVertical);
195 void TGView::DrawRegion(Int_t, Int_t, UInt_t, UInt_t)
203 void TGView::UpdateRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
208 w = x + w > fCanvas->GetWidth() ? fCanvas->GetWidth() - x : w;
209 h = y + h > fCanvas->GetHeight() ? fCanvas->GetHeight() - y : h;
211 if (fExposedRegion.IsEmpty()) {
212 fExposedRegion.fX = x;
213 fExposedRegion.fY = y;
214 fExposedRegion.fW = w;
215 fExposedRegion.fH = h;
217 TGRectangle r(x, y, w, h);
218 fExposedRegion.Merge(r);
221 fClient->NeedRedraw(
this);
227 void TGView::UpdateBackgroundStart()
229 fWhiteGC.SetTileStipXOrigin(-fVisible.fX);
230 fWhiteGC.SetTileStipYOrigin(-fVisible.fY);
236 Bool_t TGView::HandleButton(Event_t *event)
238 if (event->fType == kButtonPress) {
241 ch = fCanvas->GetHeight();
243 if (fScrollVal.fY == 1) {
244 amount = fScrollVal.fY * TMath::Max(ch/6, 1);
246 amount = fScrollVal.fY * 5;
249 if (event->fState & kKeyShiftMask) {
250 amount = fScrollVal.fY;
251 }
else if (event->fState & kKeyControlMask) {
252 amount = ch - TMath::Max(ch / 20, 1);
255 if (event->fCode == kButton4) {
258 }
else if (event->fCode == kButton5) {
269 void TGView::DoRedraw()
273 if (!fExposedRegion.IsEmpty()) {
274 DrawRegion(fExposedRegion.fX, fExposedRegion.fY,
275 fExposedRegion.fW, fExposedRegion.fH);
276 fExposedRegion.Empty();
283 Bool_t TGView::HandleExpose(Event_t *event)
285 if (event->fWindow == fCanvas->GetId()) {
287 TGPosition pos(event->fX, event->fY);
288 TGDimension dim(event->fWidth, event->fHeight);
289 TGRectangle rect(pos, dim);
291 if (fExposedRegion.IsEmpty()) {
292 fExposedRegion = rect;
294 if (((!rect.fX && !fExposedRegion.fY) ||
295 (!rect.fY && !fExposedRegion.fX)) &&
296 ((rect.fX >= (int)fExposedRegion.fW) ||
297 (rect.fY >= (int)fExposedRegion.fH))) {
298 DrawRegion(rect.fX, rect.fY, rect.fW, rect.fY);
300 fExposedRegion.Merge(rect);
304 fClient->NeedRedraw(
this);
306 return TGCompositeFrame::HandleExpose(event);
315 Bool_t TGView::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
317 switch(GET_MSG(msg)) {
319 switch(GET_SUBMSG(msg)) {
320 case kSB_SLIDERTRACK:
322 SetVisibleStart(Int_t(parm1 * fScrollVal.fX), kHorizontal);
328 switch(GET_SUBMSG(msg)) {
329 case kSB_SLIDERTRACK:
331 SetVisibleStart(Int_t(parm1 * fScrollVal.fY), kVertical);
345 void TGView::Layout()
347 Bool_t need_vsb, need_hsb;
350 need_vsb = need_hsb = kFALSE;
353 cw = fWidth - (fBorderWidth << 1) - fXMargin - 1;
354 ch = fHeight - (fBorderWidth << 1) - fYMargin - 1;
356 fCanvas->SetWidth(cw);
357 fCanvas->SetHeight(ch);
360 if ((Int_t)fVirtualSize.fWidth > cw) {
363 if (fVsb) ch -= fVsb->GetDefaultWidth();
365 fCanvas->SetHeight(ch);
370 if ((Int_t)fVirtualSize.fHeight > ch) {
373 if (fHsb) cw -= fHsb->GetDefaultHeight();
375 fCanvas->SetWidth(cw);
382 if ((Int_t)fVirtualSize.fWidth > cw) {
385 if (fVsb) ch -= fVsb->GetDefaultWidth();
387 fCanvas->SetHeight(ch);
394 fHsb->MoveResize(fBorderWidth + fXMargin, ch + fBorderWidth + fYMargin,
395 cw, fHsb->GetDefaultHeight());
399 fHsb->SetPosition(0);
405 fVsb->MoveResize(cw + fBorderWidth + fXMargin, fBorderWidth + fYMargin,
406 fVsb->GetDefaultWidth(), ch);
410 fVsb->SetPosition(0);
413 fCanvas->MoveResize(fBorderWidth + fXMargin, fBorderWidth + fYMargin, cw, ch);
416 fHsb->SetRange(fVirtualSize.fWidth / fScrollVal.fX, fCanvas->GetWidth() / fScrollVal.fX);
420 fVsb->SetRange(fVirtualSize.fHeight / fScrollVal.fY, fCanvas->GetHeight() / fScrollVal.fY);
427 void TGView::DrawBorder()
429 switch (fOptions & (kSunkenFrame | kRaisedFrame | kDoubleBorder)) {
430 case kSunkenFrame | kDoubleBorder:
431 if (gClient->GetStyle() < 2) {
432 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, fWidth-2, 0);
433 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, 0, fHeight-2);
434 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, fWidth-3, 1);
435 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, 1, fHeight-3);
437 gVirtualX->DrawLine(fId, GetHilightGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
438 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
439 gVirtualX->DrawLine(fId, GetBckgndGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
440 gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-2, 1, fWidth-2, fHeight-2);
444 TGFrame::DrawBorder();
452 void TGView::ScrollToPosition(TGLongPosition pos)
454 if (pos.fX < 0) pos.fX = 0;
455 if (pos.fY < 0) pos.fY = 0;
456 if (pos.fX != fHsb->GetPosition()) fHsb->SetPosition(pos.fX / fScrollVal.fX);
457 if (pos.fY != fVsb->GetPosition()) fVsb->SetPosition(pos.fY / fScrollVal.fY);
463 void TGView::ScrollCanvas(Int_t new_top, Int_t direction)
466 Int_t xsrc, ysrc, xdest, ydest, cpyheight, cpywidth;
472 if (direction == kVertical) {
473 if (new_top == fVisible.fY) {
477 points[0].fX = points[3].fX = 0;
478 points[1].fX = points[2].fX = fCanvas->GetWidth();
481 if (new_top < fVisible.fY) {
483 ydest = Int_t(fVisible.fY - new_top);
485 if (ydest > (Int_t)fCanvas->GetHeight()) {
486 ydest = fCanvas->GetHeight();
489 points[1].fY = points[0].fY = 0;
490 points[3].fY = points[2].fY = ydest;
493 ysrc = Int_t(new_top - fVisible.fY);
495 if (ysrc > (Int_t)fCanvas->GetHeight()) {
496 ysrc = fCanvas->GetHeight();
498 points[1].fY = points[0].fY = fCanvas->GetHeight()-ysrc;
499 points[3].fY = points[2].fY = fCanvas->GetHeight();
501 fVisible.fY = new_top;
503 if (fVisible.fY < 0) {
507 if (new_top == fVisible.fX) {
511 points[0].fY = points[1].fY = 0;
512 points[2].fY = points[3].fY = fCanvas->GetHeight();
516 if (new_top < fVisible.fX) {
518 xdest = Int_t(fVisible.fX - new_top);
521 xdest = fCanvas->GetWidth();
523 points[0].fX = points[3].fX = 0;
524 points[1].fX = points[2].fX = xdest ;
527 xsrc = Int_t(new_top - fVisible.fX);
529 if (xsrc > (Int_t)fCanvas->GetWidth()) {
530 xsrc = fCanvas->GetWidth();
532 points[0].fX = points[3].fX = fCanvas->GetWidth()-xsrc;
533 points[1].fX = points[2].fX = fCanvas->GetWidth();
535 fVisible.fX = new_top;
536 if (fVisible.fX < 0) {
541 UpdateBackgroundStart();
546 DrawRegion(0, 0, GetWidth(), GetHeight());
549 gVirtualX->CopyArea(fCanvas->GetId(), fCanvas->GetId(), fWhiteGC(),
550 xsrc, ysrc, fCanvas->GetWidth()-cpywidth,
551 fCanvas->GetHeight()-cpyheight, xdest, ydest);
553 UInt_t xdiff = points[2].fX - points[0].fX;
554 UInt_t ydiff = points[2].fY - points[0].fY;
562 DrawRegion(points[0].fX, points[0].fY, xdiff, ydiff);
569 void TGView::ChangeBackground(Pixel_t col)
571 fCanvas->SetBackgroundColor(col);
572 fWhiteGC.SetBackground(col);
573 fWhiteGC.SetForeground(col);
574 DrawRegion(0, 0, fCanvas->GetWidth(), fCanvas->GetHeight());
580 void TGView::SetBackgroundColor(Pixel_t col)
582 fCanvas->SetBackgroundColor(col);
583 fWhiteGC.SetBackground(col);
584 fWhiteGC.SetForeground(col);
590 void TGView::SetBackgroundPixmap(Pixmap_t p)
592 fCanvas->SetBackgroundPixmap(p);