43 #include "RConfigure.h"
51 ClassImp(TGedPatternFrame);
52 ClassImp(TGedPatternSelector);
53 ClassImp(TGedPatternPopup);
54 ClassImp(TGedPatternSelect);
56 TGGC* TGedPatternFrame::fgGC = 0;
62 TGedPatternFrame::TGedPatternFrame(
const TGWindow *p, Style_t pattern,
63 int width,
int height)
64 : TGFrame(p, width, height, kOwnBackground)
67 gClient->GetColorByName(
"white", white);
68 SetBackgroundColor(white);
72 SetBackgroundColor(0);
76 AddInput(kButtonPressMask | kButtonReleaseMask);
79 snprintf(fTipText,
sizeof(fTipText),
"%d", pattern);
82 if (pattern != 0 && pattern != 1001)
83 fTip =
new TGToolTip(fClient->GetDefaultRoot(),
this, fTipText, 1000);
84 else if (pattern == 0)
85 fTip =
new TGToolTip(fClient->GetDefaultRoot(),
this,
"0 - hollow", 1000);
87 fTip =
new TGToolTip(fClient->GetDefaultRoot(),
this,
"1001 - solid", 1000);
89 AddInput(kEnterWindowMask | kLeaveWindowMask);
93 gcv.fMask = kGCLineStyle | kGCLineWidth | kGCFillStyle |
94 kGCForeground | kGCBackground;
95 gcv.fLineStyle = kLineSolid;
98 gcv.fBackground = white;
100 fgGC = gClient->GetGC(&gcv, kTRUE);
107 Bool_t TGedPatternFrame::HandleCrossing(Event_t *event)
110 if (event->fType == kEnterNotify)
121 Bool_t TGedPatternFrame::HandleButton(Event_t *event)
123 if (event->fType == kButtonPress) {
124 SendMessage(fMsgWindow, MK_MSG(kC_PATTERNSEL, kPAT_CLICK), event->fCode, fPattern);
126 SendMessage(fMsgWindow, MK_MSG(kC_PATTERNSEL, kPAT_SELCHANGED), event->fCode, fPattern);
135 void TGedPatternFrame::DrawBorder()
137 gVirtualX->DrawRectangle(fId, GetBckgndGC()(), 0, 0, fWidth, fHeight);
138 Draw3dRectangle(kDoubleBorder | kSunkenFrame, 0, 0, fWidth, fHeight);
144 void TGedPatternFrame::DoRedraw()
148 if (fPattern > 3000 && fPattern < 3026) {
149 SetFillStyle(fgGC, fPattern);
150 gVirtualX->FillRectangle(fId, fgGC->GetGC(), 0, 0, fWidth, fHeight);
161 void TGedPatternFrame::SetFillStyle(TGGC* gc, Style_t fstyle)
163 Int_t style = fstyle/1000;
164 Int_t fasi = fstyle%1000;
165 Int_t stn = (fasi >= 1 && fasi <=25) ? fasi : 2;
167 static Pixmap_t fillPattern = 0;
171 gc->SetFillStyle(kFillSolid);
176 gc->SetFillStyle(kFillStippled);
177 if (fillPattern != 0) {
178 gVirtualX->DeletePixmap(fillPattern);
181 fillPattern = gVirtualX->CreateBitmap(gClient->GetDefaultRoot()->GetId(),
182 (
const char*)gStipples[stn], 16, 16);
183 gc->SetStipple(fillPattern);
193 TGedPatternSelector::TGedPatternSelector(
const TGWindow *p) :
194 TGCompositeFrame(p, 124, 190)
196 SetLayoutManager(
new TGTileLayout(
this, 1));
199 for (i = 1; i <= 25; i++)
200 fCe[i-1] =
new TGedPatternFrame(
this, 3000 + i);
202 fCe[25] =
new TGedPatternFrame(
this, 0);
203 fCe[26] =
new TGedPatternFrame(
this, 1001);
205 for (i = 0; i < 27; i++)
206 AddFrame(fCe[i],
new TGLayoutHints(kLHintsNoHints));
215 TGedPatternSelector::~TGedPatternSelector()
223 void TGedPatternSelector::SetActive(Int_t newat)
225 if (fActive != newat) {
226 if ((fActive >= 0) && (fActive < 27)) {
227 fCe[fActive]->SetActive(kFALSE);
230 if ((fActive >= 0) && (fActive < 27)) {
231 fCe[fActive]->SetActive(kTRUE);
239 Bool_t TGedPatternSelector::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
241 switch (GET_MSG(msg)) {
243 switch (GET_SUBMSG(msg)) {
244 case kPAT_SELCHANGED:
247 SendMessage(fMsgWindow, MK_MSG(kC_PATTERNSEL,
248 kPAT_SELCHANGED), parm1, parm2);
268 TGedPopup::TGedPopup(
const TGWindow *p,
const TGWindow *m, UInt_t w, UInt_t h,
269 UInt_t options, Pixel_t back)
270 : TGCompositeFrame(p, w, h, options, back)
273 SetWindowAttributes_t wattr;
275 wattr.fMask = kWAOverrideRedirect | kWASaveUnder ;
276 wattr.fOverrideRedirect = kTRUE;
277 wattr.fSaveUnder = kTRUE;
278 gVirtualX->ChangeWindowAttributes(fId, &wattr);
280 AddInput(kStructureNotifyMask);
286 void TGedPopup::EndPopup()
288 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
295 void TGedPopup::PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h)
301 gVirtualX->GetWindowSize(fParent->GetId(), rx, ry, rw, rh);
303 if (gVirtualX->InheritsFrom(
"TGWin32")) {
304 if ((x > 0) && ((x + abs(rx) + (Int_t)fWidth) > (Int_t)rw))
305 x = rw - abs(rx) - fWidth;
306 if ((y > 0) && (y + abs(ry) + (Int_t)fHeight > (Int_t)rh))
310 if (x + fWidth > rw) x = rw - fWidth;
312 if (y + fHeight > rh) y = rh - fHeight;
315 MoveResize(x, y, w, h);
320 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
321 kPointerMotionMask, kNone,
322 fClient->GetResourcePool()->GetGrabCursor());
323 gClient->WaitForUnmap(
this);
330 Bool_t TGedPopup::HandleButton(Event_t *event)
332 if ((event->fX < 0) || (event->fX >= (Int_t) fWidth) ||
333 (event->fY < 0) || (event->fY >= (Int_t) fHeight)) {
335 if (event->fType == kButtonRelease) EndPopup();
338 TGFrame *f = GetFrameFromPoint(event->fX, event->fY);
339 if (f && f !=
this) {
340 TranslateCoordinates(f, event->fX, event->fY, event->fX, event->fY);
341 f->HandleButton(event);
350 Bool_t TGedPopup::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
352 switch (GET_MSG(msg)) {
354 switch (GET_SUBMSG(msg)) {
357 SendMessage(fMsgWindow, MK_MSG(kC_POPUP, kPOP_HIDE),
371 TGedPatternPopup::TGedPatternPopup(
const TGWindow *p,
const TGWindow *m, Style_t pattern)
372 : TGedPopup(p, m, 10, 10, kDoubleBorder | kRaisedFrame | kOwnBackground,
373 GetDefaultFrameBackground())
375 fCurrentPattern = pattern;
377 TGedPatternSelector *ps =
new TGedPatternSelector(
this);
378 AddFrame(ps,
new TGLayoutHints(kLHintsCenterX, 1, 1, 1, 1));
381 Resize(ps->GetDefaultWidth() + 6, ps->GetDefaultHeight());
387 TGedPatternPopup::~TGedPatternPopup()
395 Bool_t TGedPatternPopup::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
397 switch (GET_MSG(msg)) {
399 switch (GET_SUBMSG(msg)) {
400 case kPAT_SELCHANGED:
401 SendMessage(fMsgWindow, MK_MSG(kC_PATTERNSEL, kPAT_SELCHANGED),
417 TGedSelect::TGedSelect(
const TGWindow *p, Int_t
id)
418 : TGCheckButton(p,
"", id)
423 gcv.fMask = kGCLineStyle | kGCLineWidth | kGCFillStyle |
424 kGCForeground | kGCBackground;
425 gcv.fLineStyle = kLineSolid;
429 gClient->GetColorByName(
"white", white);
430 gcv.fBackground = white;
432 fDrawGC = gClient->GetGC(&gcv, kTRUE);
436 AddInput(kButtonPressMask | kButtonReleaseMask);
442 TGedSelect::~TGedSelect()
446 fClient->FreeGC(fDrawGC);
452 Bool_t TGedSelect::HandleButton(Event_t *event)
454 TGFrame::HandleButton(event);
456 if (!IsEnabled())
return kTRUE;
458 if (event->fCode != kButton1)
return kFALSE;
460 if ((event->fType == kButtonPress) && HasFocus()) WantFocus();
462 if (event->fType == kButtonPress) {
463 if (fState != kButtonDown) {
465 SetState(kButtonDown);
468 if (fState != kButtonUp) {
473 gVirtualX->TranslateCoordinates(fId, gClient->GetDefaultRoot()->GetId(),
474 0, fHeight, ax, ay, wdummy);
476 gVirtualX->SetWMTransientHint(fPopup->GetId(), GetId());
478 fPopup->PlacePopup(ax, ay, fPopup->GetDefaultWidth(),
479 fPopup->GetDefaultHeight());
489 void TGedSelect::Enable()
491 SetFlags(kWidgetIsEnabled);
492 fClient->NeedRedraw(
this);
498 void TGedSelect::Disable()
500 ClearFlags(kWidgetIsEnabled);
501 fClient->NeedRedraw(
this);
507 void TGedSelect::DoRedraw()
512 TGButton::DoRedraw();
517 x = fWidth - 6 - fBorderWidth - 6;
518 y = fBorderWidth + 1;
519 h = fHeight - fBorderWidth - 1;
521 if (fState == kButtonDown) { ++x; ++y; }
523 gVirtualX->DrawLine(fId, GetShadowGC()(), x, y, x, h - 2);
524 gVirtualX->DrawLine(fId, GetHilightGC()(), x + 1, y, x + 1, h - 1);
525 gVirtualX->DrawLine(fId, GetHilightGC()(), x, h - 1, x + 1, h - 1);
529 x = fWidth - 6 - fBorderWidth - 2;
530 y = (fHeight - 4) / 2 + 1;
532 if (fState == kButtonDown) { ++x; ++y; }
534 DrawTriangle(GetBlackGC()(), x, y);
539 x = fWidth - 6 - fBorderWidth - 6;
540 y = fBorderWidth + 1;
541 h = fHeight - fBorderWidth - 1;
543 gVirtualX->DrawLine(fId, GetShadowGC()(), x, y, x, h - 2);
544 gVirtualX->DrawLine(fId, GetHilightGC()(), x + 1, y, x + 1, h - 1);
545 gVirtualX->DrawLine(fId, GetHilightGC()(), x, h - 1, x + 1, h - 1);
549 x = fWidth - 6 - fBorderWidth - 2;
550 y = (fHeight - 4) / 2 + 1;
552 DrawTriangle(GetHilightGC()(), x + 1, y + 1);
553 DrawTriangle(GetShadowGC()(), x, y);
560 void TGedSelect::DrawTriangle(GContext_t gc, Int_t x, Int_t y)
567 points[1].fX = x + 6;
569 points[2].fX = x + 3;
570 points[2].fY = y + 3;
574 points[1].fX = x + 5;
576 points[2].fX = x + 2;
577 points[2].fY = y + 3;
580 gVirtualX->FillPolygon(fId, gc, points, 3);
587 TGedPatternSelect::TGedPatternSelect(
const TGWindow *p, Style_t pattern, Int_t
id)
591 SetPopup(
new TGedPatternPopup(gClient->GetDefaultRoot(),
this, fPattern));
592 SetPattern(fPattern);
598 Bool_t TGedPatternSelect::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
600 if (GET_MSG(msg) == kC_PATTERNSEL && GET_SUBMSG(msg) == kPAT_SELCHANGED)
603 parm1 = (Long_t)fWidgetId;
604 SendMessage(fMsgWindow, MK_MSG(kC_PATTERNSEL, kPAT_SELCHANGED),
613 void TGedPatternSelect::DoRedraw()
615 TGedSelect::DoRedraw();
622 x = fBorderWidth + 2;
623 y = fBorderWidth + 2;
624 h = fHeight - (fBorderWidth * 2) - 4;
626 if (fState == kButtonDown) { ++x; ++y; }
629 TGedPatternFrame::SetFillStyle(fDrawGC, 1001);
632 gClient->GetColorByName(
"white", white);
633 fDrawGC->SetForeground(white);
634 gVirtualX->FillRectangle(fId, fDrawGC->GetGC(), x + 1, y + 1, w - 1, h - 1);
637 fDrawGC->SetForeground(0);
638 TGedPatternFrame::SetFillStyle(fDrawGC, fPattern);
639 gVirtualX->FillRectangle(fId, fDrawGC->GetGC(), x + 1, y + 1, w - 1, h - 1);
642 gVirtualX->DrawRectangle(fId, GetShadowGC()(), x + 1, y + 1, w - 1, h - 1);
644 gVirtualX->DrawRectangle(fId, GetShadowGC()(), x, y, w - 1, h - 1);
646 TGedPatternFrame::SetFillStyle(fDrawGC, 1001);
649 gClient->GetColorByName(
"white", white);
650 fDrawGC->SetForeground(white);
651 gVirtualX->FillRectangle(fId, fDrawGC->GetGC(), x + 1, y + 1, w - 2, h - 2);
654 fDrawGC->SetForeground(0);
655 TGedPatternFrame::SetFillStyle(fDrawGC, fPattern);
656 gVirtualX->FillRectangle(fId, fDrawGC->GetGC(), x + 1, y + 1, w - 2, h - 2);
661 x = fBorderWidth + 2;
662 y = fBorderWidth + 2;
664 h = fHeight - (fBorderWidth * 2) - 4;
665 Draw3dRectangle(kSunkenFrame, x, y, w, h);
672 void TGedPatternSelect::SetPattern(Style_t pattern, Bool_t emit)
675 gClient->NeedRedraw(
this);
677 PatternSelected(fPattern);
683 void TGedPatternSelect::SavePrimitive(std::ostream &out, Option_t * )
685 out <<
" TGedPatternSelect *";
686 out << GetName() <<
" = new TGedPatternSelect(" << fParent->GetName()
687 <<
"," << fPattern <<
"," << WidgetId() <<
");" << std::endl;