63 TGSlider::TGSlider(
const TGWindow *p, UInt_t w, UInt_t h, UInt_t type, Int_t
id,
64 UInt_t options, ULong_t back)
65 : TGFrame(p, w, h, options, back)
69 fWidgetFlags = kWidgetWantFocus | kWidgetIsEnabled;
83 void TGSlider::CreateDisabledPicture()
85 if (!fSliderPic)
return;
87 TImage *img = TImage::Create();
89 TImage *img2 = TImage::Create();
94 TString back = gEnv->GetValue(
"Gui.BackgroundColor",
"#c0c0c0");
95 img2->FillRectangle(back.Data(), 0, 0, fSliderPic->GetWidth(),
96 fSliderPic->GetHeight());
97 img->SetImage(fSliderPic->GetPicture(), fSliderPic->GetMask());
98 Pixmap_t mask = img->GetMask();
99 img2->Merge(img,
"overlay");
101 TString name =
"disbl_";
102 name += fSliderPic->GetName();
103 fDisabledPic = fClient->GetPicturePool()->GetPicture(name.Data(),
104 img2->GetPixmap(), mask);
112 void TGSlider::SetState(Bool_t state)
115 SetFlags(kWidgetIsEnabled);
117 ClearFlags(kWidgetIsEnabled);
119 fClient->NeedRedraw(
this);
125 TGVSlider::TGVSlider(
const TGWindow *p, UInt_t h, UInt_t type, Int_t
id,
126 UInt_t options, ULong_t back) :
127 TGSlider(p, kSliderWidth, h, type, id, options, back)
129 if ((fType & kSlider1))
130 fSliderPic = fClient->GetPicture(
"slider1h.xpm");
132 fSliderPic = fClient->GetPicture(
"slider2h.xpm");
135 Error(
"TGVSlider",
"slider?h.xpm not found");
137 CreateDisabledPicture();
139 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
140 kButtonPressMask | kButtonReleaseMask |
141 kPointerMotionMask, kNone, kNone);
143 AddInput(kStructureNotifyMask);
145 fPos = h/2; fVmin = 0; fVmax = h; fYp = 0;
146 fEditDisabled = kEditDisableWidth;
148 if (!p && fClient->IsEditable()) {
149 Resize(GetDefaultWidth(), 100);
156 TGVSlider::~TGVSlider()
158 if (fSliderPic) fClient->FreePicture(fSliderPic);
159 if (fDisabledPic) fClient->FreePicture(fDisabledPic);
165 void TGVSlider::DoRedraw()
168 gVirtualX->ClearWindow(fId);
170 GContext_t drawGC = IsEnabled() ? GetBlackGC()() : GetShadowGC()();
172 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth/2, 8, fWidth/2-1, 8);
173 gVirtualX->DrawLine(fId, GetShadowGC()(), fWidth/2-1, 8, fWidth/2-1, fHeight-9);
174 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth/2+1, 8, fWidth/2+1, fHeight-8);
175 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth/2+1, fHeight-8, fWidth/2, fHeight-8);
176 gVirtualX->DrawLine(fId, drawGC, fWidth/2, 9, fWidth/2, fHeight-9);
179 if (fScale == 1) fScale++;
180 if (fScale * 2 > (
int)fHeight) fScale = 0;
181 if (fScale > 0 && !(fType & kScaleNo)) {
182 int lines = ((int)fHeight-16) / fScale;
183 int remain = ((int)fHeight-16) % fScale;
184 if (lines < 1) lines = 1;
185 for (
int i = 0; i <= lines; i++) {
186 int y = i * fScale + (i * remain) / lines;
187 gVirtualX->DrawLine(fId, drawGC, fWidth/2+8, y+7, fWidth/2+10, y+7);
188 if ((fType & kSlider2) && (fType & kScaleBoth))
189 gVirtualX->DrawLine(fId, drawGC, fWidth/2-9, y+7, fWidth/2-11, y+7);
192 if (fPos < fVmin) fPos = fVmin;
193 if (fPos > fVmax) fPos = fVmax;
196 fRelPos = (((int)fHeight-16) * (fPos - fVmin)) / (fVmax - fVmin) + 8;
197 const TGPicture *pic = fSliderPic;
199 if (!fDisabledPic) CreateDisabledPicture();
200 pic = fDisabledPic ? fDisabledPic : fSliderPic;
202 if (pic) pic->Draw(fId, GetBckgndGC()(), fWidth/2-7, fRelPos-6);
208 Bool_t TGVSlider::HandleButton(Event_t *event)
210 if (!IsEnabled())
return kTRUE;
211 if (event->fCode == kButton4 || event->fCode == kButton5) {
213 int m = (fVmax - fVmin) / (fWidth-16);
214 if (event->fCode == kButton4)
215 fPos -= ((m) ? m : 1);
216 else if (event->fCode == kButton5)
217 fPos += ((m) ? m : 1);
218 if (fPos > fVmax) fPos = fVmax;
219 if (fPos < fVmin) fPos = fVmin;
220 SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_POS),
222 fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POS),
224 if (fPos != oldPos) {
225 PositionChanged(fPos);
226 fClient->NeedRedraw(
this);
230 if (event->fType == kButtonPress) {
232 if (event->fX < (Int_t)fWidth/2-7 || event->fX > (Int_t)fWidth/2+7) {
236 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
237 kPointerMotionMask, kNone, kNone,
240 if (event->fY >= fRelPos - 7 && event->fY <= fRelPos + 7) {
243 fYp =
event->fY - (fRelPos-7);
244 SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_PRESS), fWidgetId, 0);
245 fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_PRESS), fWidgetId, 0);
248 if (event->fCode == kButton1) {
250 int m = (fVmax - fVmin) / (fHeight-16);
251 if (event->fY < fRelPos) {
252 fPos -= ((m) ? m : 1);
254 if (event->fY > fRelPos) {
255 fPos += ((m) ? m : 1);
257 }
else if (event->fCode == kButton2) {
259 fPos = ((fVmax - fVmin) * event->fY) / (fHeight-16) + fVmin;
261 if (fPos > fVmax) fPos = fVmax;
262 if (fPos < fVmin) fPos = fVmin;
263 SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_POS),
265 fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_POS),
267 PositionChanged(fPos);
269 fClient->NeedRedraw(
this);
274 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
276 SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_RELEASE), fWidgetId, 0);
277 fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_RELEASE), fWidgetId, 0);
286 Bool_t TGVSlider::HandleMotion(Event_t *event)
290 fPos = ((fVmax - fVmin) * (event->fY - fYp)) / ((
int)fHeight-16) + fVmin;
291 if (fPos > fVmax) fPos = fVmax;
292 if (fPos < fVmin) fPos = fVmin;
296 fClient->NeedRedraw(
this);
297 SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_POS),
299 fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_POS),
301 PositionChanged(fPos);
310 Bool_t TGVSlider::HandleConfigureNotify(Event_t* event)
312 TGFrame::HandleConfigureNotify(event);
313 fClient->NeedRedraw(
this);
320 TGHSlider::TGHSlider(
const TGWindow *p, UInt_t w, UInt_t type, Int_t
id,
321 UInt_t options, ULong_t back) :
322 TGSlider(p, w, kSliderHeight, type, id, options, back)
324 if ((fType & kSlider1))
325 fSliderPic = fClient->GetPicture(
"slider1v.xpm");
327 fSliderPic = fClient->GetPicture(
"slider2v.xpm");
330 Error(
"TGHSlider",
"slider?v.xpm not found");
332 CreateDisabledPicture();
334 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
335 kButtonPressMask | kButtonReleaseMask |
336 kPointerMotionMask, kNone, kNone);
338 AddInput(kStructureNotifyMask);
340 fPos = w/2; fVmin = 0; fVmax = w; fXp = 0;
341 fEditDisabled = kEditDisableHeight;
343 if (!p && fClient->IsEditable()) {
344 Resize(100, GetDefaultHeight());
351 TGHSlider::~TGHSlider()
353 if (fSliderPic) fClient->FreePicture(fSliderPic);
354 if (fDisabledPic) fClient->FreePicture(fDisabledPic);
360 void TGHSlider::DoRedraw()
363 gVirtualX->ClearWindow(fId);
365 GContext_t drawGC = IsEnabled() ? GetBlackGC()() : GetShadowGC()();
367 gVirtualX->DrawLine(fId, GetShadowGC()(), 8, fHeight/2, 8, fHeight/2-1);
368 gVirtualX->DrawLine(fId, GetShadowGC()(), 8, fHeight/2-1, fWidth-9, fHeight/2-1);
369 gVirtualX->DrawLine(fId, GetHilightGC()(), 8, fHeight/2+1, fWidth-8, fHeight/2+1);
370 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-8, fHeight/2+1, fWidth-8, fHeight/2);
371 gVirtualX->DrawLine(fId, drawGC, 9, fHeight/2, fWidth-9, fHeight/2);
373 if (fScale == 1) fScale++;
374 if (fScale * 2 > (
int)fWidth) fScale = 0;
375 if (fScale > 0 && !(fType & kScaleNo)) {
376 int lines = ((int)fWidth-16) / fScale;
377 int remain = ((int)fWidth-16) % fScale;
378 if (lines < 1) lines = 1;
379 for (
int i = 0; i <= lines; i++) {
380 int x = i * fScale + (i * remain) / lines;
381 gVirtualX->DrawLine(fId, drawGC, x+7, fHeight/2+8, x+7, fHeight/2+10);
382 if ((fType & kSlider2) && (fType & kScaleBoth))
383 gVirtualX->DrawLine(fId, drawGC, x+7, fHeight/2-9, x+7, fHeight/2-11);
386 if (fPos < fVmin) fPos = fVmin;
387 if (fPos > fVmax) fPos = fVmax;
390 fRelPos = (((int)fWidth-16) * (fPos - fVmin)) / (fVmax - fVmin) + 8;
391 const TGPicture *pic = fSliderPic;
393 if (!fDisabledPic) CreateDisabledPicture();
394 pic = fDisabledPic ? fDisabledPic : fSliderPic;
396 if (pic) pic->Draw(fId, GetBckgndGC()(), fRelPos-6, fHeight/2-7);
402 Bool_t TGHSlider::HandleButton(Event_t *event)
404 if (!IsEnabled())
return kTRUE;
405 if (event->fCode == kButton4 || event->fCode == kButton5) {
407 int m = (fVmax - fVmin) / (fWidth-16);
408 if (event->fCode == kButton4)
409 fPos += ((m) ? m : 1);
410 else if (event->fCode == kButton5)
411 fPos -= ((m) ? m : 1);
412 if (fPos > fVmax) fPos = fVmax;
413 if (fPos < fVmin) fPos = fVmin;
414 SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_POS),
416 fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POS),
418 if (fPos != oldPos) {
419 PositionChanged(fPos);
420 fClient->NeedRedraw(
this);
424 if (event->fType == kButtonPress) {
426 if (event->fY < (Int_t)fHeight/2-7 || event->fY > (Int_t)fHeight/2+7) {
429 if (event->fX >= fRelPos - 7 && event->fX <= fRelPos + 7) {
432 fXp =
event->fX - (fRelPos-7);
433 SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_PRESS), fWidgetId, 0);
434 fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_PRESS), fWidgetId, 0);
437 if (event->fCode == kButton1) {
438 int m = (fVmax - fVmin) / (fWidth-16);
439 if (event->fX < fRelPos) {
440 fPos -= ((m) ? m : 1);
442 if (event->fX > fRelPos) {
443 fPos += ((m) ? m : 1);
445 }
else if (event->fCode == kButton2) {
446 fPos = ((fVmax - fVmin) * event->fX) / (fWidth-16) + fVmin;
448 if (fPos > fVmax) fPos = fVmax;
449 if (fPos < fVmin) fPos = fVmin;
450 SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_POS),
452 fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POS),
454 PositionChanged(fPos);
456 fClient->NeedRedraw(
this);
459 gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask | kPointerMotionMask,
460 kNone, kNone, kTRUE, kFALSE);
464 gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
466 SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_RELEASE), fWidgetId, 0);
467 fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_RELEASE), fWidgetId, 0);
476 Bool_t TGHSlider::HandleMotion(Event_t *event)
480 fPos = ((fVmax - fVmin) * (event->fX - fXp)) / ((
int)fWidth-16) + fVmin;
481 if (fPos > fVmax) fPos = fVmax;
482 if (fPos < fVmin) fPos = fVmin;
486 fClient->NeedRedraw(
this);
487 SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_POS),
489 fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POS),
491 PositionChanged(fPos);
500 Bool_t TGHSlider::HandleConfigureNotify(Event_t* event)
502 TGFrame::HandleConfigureNotify(event);
503 fClient->NeedRedraw(
this);
510 TString TGSlider::GetTypeString()
const
515 if (fType & kSlider1) {
516 if (stype.Length() == 0) stype =
"kSlider1";
517 else stype +=
" | kSlider1";
519 if (fType & kSlider2) {
520 if (stype.Length() == 0) stype =
"kSlider2";
521 else stype +=
" | kSlider2";
523 if (fType & kScaleNo) {
524 if (stype.Length() == 0) stype =
"kScaleNo";
525 else stype +=
" | kScaleNo";
527 if (fType & kScaleDownRight) {
528 if (stype.Length() == 0) stype =
"kScaleDownRight";
529 else stype +=
" | kScaleDownRight";
531 if (fType & kScaleBoth) {
532 if (stype.Length() == 0) stype =
"kScaleBoth";
533 else stype +=
" | kScaleBoth";
542 void TGHSlider::SavePrimitive(std::ostream &out, Option_t *option )
544 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
546 out <<
" TGHSlider *";
547 out << GetName() <<
" = new TGHSlider(" << fParent->GetName()
548 <<
"," << GetWidth() <<
",";
549 out << GetTypeString() <<
"," << WidgetId();
551 if (fBackground == GetDefaultFrameBackground()) {
553 out <<
");" << std::endl;
555 out <<
"," << GetOptionString() <<
");" << std::endl;
558 out <<
"," << GetOptionString() <<
",ucolor);" << std::endl;
560 if (option && strstr(option,
"keep_names"))
561 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
563 if (fVmin != 0 || fVmax != (Int_t)fWidth)
564 out <<
" " << GetName() <<
"->SetRange(" << fVmin <<
"," << fVmax <<
");" << std::endl;
566 if (fPos != (Int_t)fWidth/2)
567 out <<
" " << GetName() <<
"->SetPosition(" << GetPosition() <<
");" << std::endl;
570 out <<
" " << GetName() <<
"->SetScale(" << fScale <<
");" << std::endl;
573 out <<
" " << GetName() <<
"->SetState(kFALSE);" << std::endl;
579 void TGVSlider::SavePrimitive(std::ostream &out, Option_t *option )
581 if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
584 out << GetName() <<
" = new TGVSlider("<< fParent->GetName()
585 <<
"," << GetHeight() <<
",";
586 out << GetTypeString() <<
"," << WidgetId();
588 if (fBackground == GetDefaultFrameBackground()) {
591 out <<
");" << std::endl;
593 out <<
"," << GetOptionString() <<
");" << std::endl;
596 out <<
"," << GetOptionString() <<
",ucolor);" << std::endl;
598 if (option && strstr(option,
"keep_names"))
599 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
601 if (fVmin != 0 || fVmax != (Int_t)fHeight)
602 out <<
" " << GetName() <<
"->SetRange(" << fVmin <<
"," << fVmax <<
");" << std::endl;
604 if (fPos != (Int_t)fHeight/2)
605 out <<
" " << GetName() <<
"->SetPosition(" << GetPosition() <<
");" << std::endl;
608 out <<
" " << GetName() <<
"->SetScale(" << fScale <<
");" << std::endl;
611 out <<
" " << GetName() <<
"->SetState(kFALSE);" << std::endl;