53 #include "RConfigure.h"
58 ClassImp(TGColorFrame);
59 ClassImp(TG16ColorSelector);
60 ClassImp(TGColorPopup);
61 ClassImp(TGColorSelect);
68 TGColorFrame::TGColorFrame(
const TGWindow *p, ULong_t color, Int_t ) :
69 TGFrame(p, 20, 20, kOwnBackground, color)
71 SetBackgroundColor(color);
73 fPixel = fColor = color;
75 AddInput(kButtonPressMask | kButtonReleaseMask);
79 fGrayGC = GetShadowGC()();
80 fEditDisabled = kEditDisable;
86 Bool_t TGColorFrame::HandleButton(Event_t *event)
88 if (event->fType == kButtonPress) {
89 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_CLICK), event->fCode, fColor);
91 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_SELCHANGED), event->fCode, fColor);
100 void TGColorFrame::DrawBorder()
102 gVirtualX->DrawRectangle(fId, GetBckgndGC()(), 0, 0, fWidth - 1, fHeight - 1);
103 Draw3dRectangle(kDoubleBorder | kSunkenFrame, 1, 1, fWidth - 2, fHeight - 2);
110 TG16ColorSelector::TG16ColorSelector(
const TGWindow *p) :
111 TGCompositeFrame(p, 10, 10)
113 SetLayoutManager(
new TGMatrixLayout(
this, 4, 4, 1, 1));
115 fCe[0] =
new TGColorFrame(
this, TColor::Number2Pixel(0), 0);
116 fCe[1] =
new TGColorFrame(
this, TColor::Number2Pixel(1), 1);
117 fCe[2] =
new TGColorFrame(
this, TColor::Number2Pixel(2), 2);
118 fCe[3] =
new TGColorFrame(
this, TColor::Number2Pixel(3), 3);
119 fCe[4] =
new TGColorFrame(
this, TColor::Number2Pixel(4), 4);
120 fCe[5] =
new TGColorFrame(
this, TColor::Number2Pixel(5), 5);
121 fCe[6] =
new TGColorFrame(
this, TColor::Number2Pixel(6), 6);
122 fCe[7] =
new TGColorFrame(
this, TColor::Number2Pixel(7), 7);
123 fCe[8] =
new TGColorFrame(
this, TColor::Number2Pixel(8), 8);
124 fCe[9] =
new TGColorFrame(
this, TColor::Number2Pixel(9), 9);
125 fCe[10] =
new TGColorFrame(
this, TColor::Number2Pixel(30), 10);
126 fCe[11] =
new TGColorFrame(
this, TColor::Number2Pixel(38), 11);
127 fCe[12] =
new TGColorFrame(
this, TColor::Number2Pixel(41), 12);
128 fCe[13] =
new TGColorFrame(
this, TColor::Number2Pixel(42), 13);
129 fCe[14] =
new TGColorFrame(
this, TColor::Number2Pixel(50), 14);
130 fCe[15] =
new TGColorFrame(
this, TColor::Number2Pixel(51), 15);
132 for (Int_t i = 0; i < 16; i++)
133 AddFrame(fCe[i],
new TGLayoutHints(kLHintsCenterX | kLHintsCenterY));
138 SetEditDisabled(kEditDisable);
144 TG16ColorSelector::~TG16ColorSelector()
152 void TG16ColorSelector::SetActive(Int_t newat)
154 if (fActive != newat) {
155 if ((fActive >= 0) && (fActive < 16)) {
156 fCe[fActive]->SetActive(kFALSE);
159 if ((fActive >= 0) && (fActive < 16)) {
160 fCe[fActive]->SetActive(kTRUE);
168 Bool_t TG16ColorSelector::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
170 switch (GET_MSG(msg)) {
172 switch (GET_SUBMSG(msg)) {
173 case kCOL_SELCHANGED:
176 SendMessage(fMsgWindow,
177 MK_MSG(kC_COLORSEL, kCOL_SELCHANGED),
201 TGColorPopup::TGColorPopup(
const TGWindow *p,
const TGWindow *m, ULong_t color) :
202 TGCompositeFrame(p, 10, 10, kDoubleBorder | kRaisedFrame | kOwnBackground,
203 GetDefaultFrameBackground())
206 fCurrentColor = color;
208 SetWindowAttributes_t wattr;
210 wattr.fMask = kWAOverrideRedirect;
211 wattr.fOverrideRedirect = kTRUE;
213 gVirtualX->ChangeWindowAttributes(fId, &wattr);
215 AddInput(kStructureNotifyMask);
218 fLaunchDialog = kFALSE;
220 TG16ColorSelector *cs =
new TG16ColorSelector(
this);
221 AddFrame(cs,
new TGLayoutHints(kLHintsCenterX, 1, 1, 1, 1));
222 AddFrame(
new TGHorizontal3DLine(
this),
223 new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 2, 2, 2, 2));
224 TGTextButton *other =
new TGTextButton(
this,
"Other...", 102);
225 other->SetToolTipText(
"Popups up Color Selector");
226 other->Associate(
this);
227 AddFrame(other,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 2, 2, 2, 2));
231 Resize(cs->GetDefaultWidth() + 6, cs->GetDefaultHeight() +
232 other->GetDefaultHeight());
233 SetEditDisabled(kEditDisable);
239 TGColorPopup::~TGColorPopup()
247 void TGColorPopup::EndPopup()
249 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
256 void TGColorPopup::PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h)
262 gVirtualX->GetWindowSize(fParent->GetId(), rx, ry, rw, rh);
264 if (gVirtualX->InheritsFrom(
"TGWin32")) {
265 if ((x > 0) && ((x + abs(rx) + (Int_t)fWidth) > (Int_t)rw))
266 x = rw - abs(rx) - fWidth;
267 if ((y > 0) && (y + abs(ry) + (Int_t)fHeight > (Int_t)rh))
271 if (x + fWidth > rw) x = rw - fWidth;
273 if (y + fHeight > rh) y = rh - fHeight;
276 MoveResize(x, y, w, h);
281 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
282 kPointerMotionMask, kNone,
283 fClient->GetResourcePool()->GetGrabCursor());
285 fLaunchDialog = kFALSE;
287 gClient->WaitForUnmap(
this);
292 ULong_t color = fCurrentColor;
294 new TGColorDialog(gClient->GetDefaultRoot(),
this, &retc, &color);
297 fCurrentColor = color;
298 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_SELCHANGED),
308 Bool_t TGColorPopup::HandleButton(Event_t *event)
310 if (event->fX < 0 || event->fX >= (Int_t) fWidth ||
311 event->fY < 0 || event->fY >= (Int_t) fHeight) {
312 if (event->fType == kButtonRelease)
315 TGFrame *f = GetFrameFromPoint(event->fX, event->fY);
316 if (f && f !=
this) {
317 TranslateCoordinates(f, event->fX, event->fY, event->fX, event->fY);
318 f->HandleButton(event);
327 Bool_t TGColorPopup::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
329 switch (GET_MSG(msg)) {
331 switch (GET_SUBMSG(msg)) {
332 case kCOL_SELCHANGED:
333 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_SELCHANGED),
344 switch (GET_SUBMSG(msg)) {
347 fLaunchDialog = kTRUE;
360 void TGColorPopup::PreviewColor(Pixel_t color)
362 if (fClient->IsEditable())
return;
364 fCurrentColor = color;
365 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_SELCHANGED), -1, color);
371 void TGColorPopup::PreviewAlphaColor(ULong_t color)
373 if (fClient->IsEditable())
return;
375 TColor *tcolor = (TColor *)color;
376 fCurrentColor = tcolor->GetPixel();
377 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_SELCHANGED), 0, (ULong_t)tcolor);
386 TGColorSelect::TGColorSelect(
const TGWindow *p, ULong_t color, Int_t
id) :
387 TGCheckButton(p,
"", id)
389 if (!p && fClient->IsEditable() && !color) {
390 color = TColor::Number2Pixel(6);
395 fDrawGC = *fClient->GetResourcePool()->GetFrameGC();
399 AddInput(kButtonPressMask | kButtonReleaseMask);
402 fEditDisabled = kEditDisable;
408 TGColorSelect::~TGColorSelect()
416 Bool_t TGColorSelect::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
418 switch (GET_MSG(msg)) {
420 switch (GET_SUBMSG(msg)) {
421 case kCOL_SELCHANGED:
424 SetAlphaColor((ULong_t)parm2);
425 parm1 = (Long_t)fWidgetId;
426 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_SELCHANGED),
431 parm1 = (Long_t)fWidgetId;
432 SendMessage(fMsgWindow, MK_MSG(kC_COLORSEL, kCOL_SELCHANGED),
449 Bool_t TGColorSelect::HandleButton(Event_t *event)
451 TGFrame::HandleButton(event);
452 if (!IsEnabled())
return kTRUE;
454 if (event->fCode != kButton1)
return kFALSE;
456 if ((event->fType == kButtonPress) && HasFocus())
459 if (event->fType == kButtonPress) {
463 if (fState != kButtonDown) {
465 SetState(kButtonDown);
468 if (fState != kButtonUp) {
472 if ((fPressPos.fX != fX) || (fPressPos.fY != fY)) {
479 fColorPopup =
new TGColorPopup(gClient->GetDefaultRoot(),
this, fColor);
481 gVirtualX->TranslateCoordinates(fId, gClient->GetDefaultRoot()->GetId(),
482 0, fHeight, ax, ay, wdummy);
485 gVirtualX->SetWMTransientHint(fColorPopup->GetId(), GetId());
487 fColorPopup->PlacePopup(ax, ay, fColorPopup->GetDefaultWidth(),
488 fColorPopup->GetDefaultHeight());
498 void TGColorSelect::Enable(Bool_t on)
501 SetFlags(kWidgetIsEnabled);
503 ClearFlags(kWidgetIsEnabled);
505 fClient->NeedRedraw(
this);
511 void TGColorSelect::Disable()
513 ClearFlags(kWidgetIsEnabled);
514 fClient->NeedRedraw(
this);
520 void TGColorSelect::DoRedraw()
525 TGButton::DoRedraw();
531 x = fBorderWidth + 2;
532 y = fBorderWidth + 2;
534 h = fHeight - (fBorderWidth * 2) - 4;
536 if (fState == kButtonDown) { ++x; ++y; }
543 gVirtualX->FillRectangle(fId, fDrawGC(), x + 1, y + 1, w - 1, h - 1);
544 gVirtualX->DrawRectangle(fId, GetShadowGC()(), x + 1, y + 1, w - 1, h - 1);
546 gVirtualX->DrawRectangle(fId, GetShadowGC()(), x, y, w - 1, h - 1);
547 gVirtualX->FillRectangle(fId, fDrawGC(), x + 1, y + 1, w - 2, h - 2);
552 x = fWidth - 6 - fBorderWidth - 6;
553 y = fBorderWidth + 1;
554 h = fHeight - fBorderWidth - 1;
556 if (fState == kButtonDown) { ++x; ++y; }
558 gVirtualX->DrawLine(fId, GetShadowGC()(), x, y, x, h - 2);
559 gVirtualX->DrawLine(fId, GetHilightGC()(), x + 1, y, x + 1, h - 1);
560 gVirtualX->DrawLine(fId, GetHilightGC()(), x, h - 1, x + 1, h - 1);
564 x = fWidth - 6 - fBorderWidth - 2;
565 y = (fHeight - 4) / 2 + 1;
567 if (fState == kButtonDown) { ++x; ++y; }
569 DrawTriangle(GetBlackGC()(), x, y);
575 x = fBorderWidth + 2;
576 y = fBorderWidth + 2;
578 h = fHeight - (fBorderWidth * 2) - 4;
580 Draw3dRectangle(kSunkenFrame, x, y, w, h);
584 x = fWidth - 6 - fBorderWidth - 6;
585 y = fBorderWidth + 1;
586 h = fHeight - fBorderWidth - 1;
588 gVirtualX->DrawLine(fId, GetShadowGC()(), x, y, x, h - 2);
589 gVirtualX->DrawLine(fId, GetHilightGC()(), x + 1, y, x + 1, h - 1);
590 gVirtualX->DrawLine(fId, GetHilightGC()(), x, h - 1, x + 1, h - 1);
594 x = fWidth - 6 - fBorderWidth - 2;
595 y = (fHeight - 4) / 2 + 1;
597 DrawTriangle(GetHilightGC()(), x + 1, y + 1);
598 DrawTriangle(GetShadowGC()(), x, y);
605 void TGColorSelect::DrawTriangle(GContext_t gc, Int_t x, Int_t y)
615 points[1].fX = x + 6;
617 points[2].fX = x + 3;
618 points[2].fY = y + 3;
622 points[1].fX = x + 5;
624 points[2].fX = x + 2;
625 points[2].fY = y + 3;
628 gVirtualX->FillPolygon(fId, gc, points, 3);
634 void TGColorSelect::SetColor(ULong_t color, Bool_t emit)
637 fDrawGC.SetForeground(color);
638 gClient->NeedRedraw(
this);
640 ColorSelected(fColor);
646 void TGColorSelect::SetAlphaColor(ULong_t color, Bool_t emit)
649 AlphaColorSelected(color);
657 void TGColorSelect::SavePrimitive(std::ostream &out, Option_t *option )
661 TString cvar = TString::Format(
"ColPar%d",nn);
663 ULong_t color = GetColor();
664 const char *colorname = TColor::PixelAsHexString(color);
665 gClient->GetColorByName(colorname, color);
667 out << std::endl <<
" // color select widget" << std::endl;
668 out <<
" ULong_t " << cvar.Data() <<
";" << std::endl;
669 out <<
" gClient->GetColorByName(" << quote << colorname << quote
670 <<
", " << cvar.Data() <<
");" << std::endl;
672 out <<
" TGColorSelect *";
673 out << GetName() <<
" = new TGColorSelect(" << fParent->GetName()
674 <<
", " << cvar.Data() <<
", " << WidgetId() <<
");" << std::endl;
677 if (option && strstr(option,
"keep_names"))
678 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
681 out <<
" " << GetName() <<
"->Disable();" << std::endl;