Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGSlider.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 14/01/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 /**************************************************************************
12 
13  This source is based on Xclass95, a Win95-looking GUI toolkit.
14  Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15 
16  Xclass95 is free software; you can redistribute it and/or
17  modify it under the terms of the GNU Library General Public
18  License as published by the Free Software Foundation; either
19  version 2 of the License, or (at your option) any later version.
20 
21 **************************************************************************/
22 
23 //////////////////////////////////////////////////////////////////////////
24 // //
25 // TGSlider, TGVSlider and TGHSlider //
26 // //
27 // Slider widgets allow easy selection of a range. //
28 // Sliders can be either horizontal or vertical oriented and there is //
29 // a choice of two different slider types and three different types //
30 // of tick marks. //
31 // //
32 // TGSlider is an abstract base class. Use the concrete TGVSlider and //
33 // TGHSlider. //
34 // //
35 // Dragging the slider will generate the event: //
36 // kC_VSLIDER, kSL_POS, slider id, position (for vertical slider) //
37 // kC_HSLIDER, kSL_POS, slider id, position (for horizontal slider) //
38 // //
39 // Pressing the mouse will generate the event: //
40 // kC_VSLIDER, kSL_PRESS, slider id, 0 (for vertical slider) //
41 // kC_HSLIDER, kSL_PRESS, slider id, 0 (for horizontal slider) //
42 // //
43 // Releasing the mouse will generate the event: //
44 // kC_VSLIDER, kSL_RELEASE, slider id, 0 (for vertical slider) //
45 // kC_HSLIDER, kSL_RELEASE, slider id, 0 (for horizontal slider) //
46 // //
47 //////////////////////////////////////////////////////////////////////////
48 
49 #include "TGSlider.h"
50 #include "TGPicture.h"
51 #include "TImage.h"
52 #include "TEnv.h"
53 #include "Riostream.h"
54 
55 ClassImp(TGSlider);
56 ClassImp(TGVSlider);
57 ClassImp(TGHSlider);
58 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Slider constructor.
62 
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)
66 {
67  fDisabledPic = 0;
68  fWidgetId = id;
69  fWidgetFlags = kWidgetWantFocus | kWidgetIsEnabled;
70  fMsgWindow = p;
71 
72  fType = type;
73  fScale = 10;
74  fDragging = kFALSE;
75  fPos = fRelPos = 0;
76  fVmax = fVmin = 0;
77  fSliderPic = 0;
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Creates disabled picture.
82 
83 void TGSlider::CreateDisabledPicture()
84 {
85  if (!fSliderPic) return;
86 
87  TImage *img = TImage::Create();
88  if (!img) return;
89  TImage *img2 = TImage::Create();
90  if (!img2) {
91  if (img) delete img;
92  return;
93  }
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");
100 
101  TString name = "disbl_";
102  name += fSliderPic->GetName();
103  fDisabledPic = fClient->GetPicturePool()->GetPicture(name.Data(),
104  img2->GetPixmap(), mask);
105  delete img;
106  delete img2;
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// Set state of widget. If kTRUE=enabled, kFALSE=disabled.
111 
112 void TGSlider::SetState(Bool_t state)
113 {
114  if (state) {
115  SetFlags(kWidgetIsEnabled);
116  } else {
117  ClearFlags(kWidgetIsEnabled);
118  }
119  fClient->NeedRedraw(this);
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Create a vertical slider widget.
124 
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)
128 {
129  if ((fType & kSlider1))
130  fSliderPic = fClient->GetPicture("slider1h.xpm");
131  else
132  fSliderPic = fClient->GetPicture("slider2h.xpm");
133 
134  if (!fSliderPic)
135  Error("TGVSlider", "slider?h.xpm not found");
136 
137  CreateDisabledPicture();
138 
139  gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
140  kButtonPressMask | kButtonReleaseMask |
141  kPointerMotionMask, kNone, kNone);
142 
143  AddInput(kStructureNotifyMask);
144  // set initial values
145  fPos = h/2; fVmin = 0; fVmax = h; fYp = 0;
146  fEditDisabled = kEditDisableWidth;
147 
148  if (!p && fClient->IsEditable()) {
149  Resize(GetDefaultWidth(), 100);
150  }
151 }
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// Delete vertical slider widget.
155 
156 TGVSlider::~TGVSlider()
157 {
158  if (fSliderPic) fClient->FreePicture(fSliderPic);
159  if (fDisabledPic) fClient->FreePicture(fDisabledPic);
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Redraw vertical slider widget.
164 
165 void TGVSlider::DoRedraw()
166 {
167  // cleanup the drawable
168  gVirtualX->ClearWindow(fId);
169 
170  GContext_t drawGC = IsEnabled() ? GetBlackGC()() : GetShadowGC()();
171 
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);
177 
178  // check scale
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);
190  }
191  }
192  if (fPos < fVmin) fPos = fVmin;
193  if (fPos > fVmax) fPos = fVmax;
194 
195  // calc slider-picture position
196  fRelPos = (((int)fHeight-16) * (fPos - fVmin)) / (fVmax - fVmin) + 8;
197  const TGPicture *pic = fSliderPic;
198  if (!IsEnabled()) {
199  if (!fDisabledPic) CreateDisabledPicture();
200  pic = fDisabledPic ? fDisabledPic : fSliderPic;
201  }
202  if (pic) pic->Draw(fId, GetBckgndGC()(), fWidth/2-7, fRelPos-6);
203 }
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Handle mouse button event in vertical slider.
207 
208 Bool_t TGVSlider::HandleButton(Event_t *event)
209 {
210  if (!IsEnabled()) return kTRUE;
211  if (event->fCode == kButton4 || event->fCode == kButton5) {
212  Int_t oldPos = fPos;
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),
221  fWidgetId, fPos);
222  fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POS),
223  fWidgetId, fPos);
224  if (fPos != oldPos) {
225  PositionChanged(fPos);
226  fClient->NeedRedraw(this);
227  }
228  return kTRUE;
229  }
230  if (event->fType == kButtonPress) {
231  // constrain to the slider width
232  if (event->fX < (Int_t)fWidth/2-7 || event->fX > (Int_t)fWidth/2+7) {
233  return kTRUE;
234  }
235  // last argument kFALSE forces all specified events to this window
236  gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
237  kPointerMotionMask, kNone, kNone,
238  kTRUE, kFALSE);
239 
240  if (event->fY >= fRelPos - 7 && event->fY <= fRelPos + 7) {
241  // slider selected
242  fDragging = kTRUE;
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);
246  Pressed();
247  } else {
248  if (event->fCode == kButton1) {
249  // scroll up or down
250  int m = (fVmax - fVmin) / (fHeight-16);
251  if (event->fY < fRelPos) {
252  fPos -= ((m) ? m : 1);
253  }
254  if (event->fY > fRelPos) {
255  fPos += ((m) ? m : 1);
256  }
257  } else if (event->fCode == kButton2) {
258  // set absolute position
259  fPos = ((fVmax - fVmin) * event->fY) / (fHeight-16) + fVmin;
260  }
261  if (fPos > fVmax) fPos = fVmax;
262  if (fPos < fVmin) fPos = fVmin;
263  SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_POS),
264  fWidgetId, fPos);
265  fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_POS),
266  fWidgetId, fPos);
267  PositionChanged(fPos);
268  }
269  fClient->NeedRedraw(this);
270 
271  } else {
272  // ButtonRelease
273  fDragging = kFALSE;
274  gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
275 
276  SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_RELEASE), fWidgetId, 0);
277  fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_RELEASE), fWidgetId, 0);
278  Released();
279  }
280  return kTRUE;
281 }
282 
283 ////////////////////////////////////////////////////////////////////////////////
284 /// Handle mouse motion event in vertical slider.
285 
286 Bool_t TGVSlider::HandleMotion(Event_t *event)
287 {
288  if (fDragging) {
289  int old = fPos;
290  fPos = ((fVmax - fVmin) * (event->fY - fYp)) / ((int)fHeight-16) + fVmin;
291  if (fPos > fVmax) fPos = fVmax;
292  if (fPos < fVmin) fPos = fVmin;
293 
294  // check if position changed
295  if (old != fPos) {
296  fClient->NeedRedraw(this);
297  SendMessage(fMsgWindow, MK_MSG(kC_VSLIDER, kSL_POS),
298  fWidgetId, fPos);
299  fClient->ProcessLine(fCommand, MK_MSG(kC_VSLIDER, kSL_POS),
300  fWidgetId, fPos);
301  PositionChanged(fPos);
302  }
303  }
304  return kTRUE;
305 }
306 
307 ////////////////////////////////////////////////////////////////////////////////
308 /// Handles resize events for this widget.
309 
310 Bool_t TGVSlider::HandleConfigureNotify(Event_t* event)
311 {
312  TGFrame::HandleConfigureNotify(event);
313  fClient->NeedRedraw(this);
314  return kTRUE;
315 }
316 
317 ////////////////////////////////////////////////////////////////////////////////
318 /// Create horizontal slider widget.
319 
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)
323 {
324  if ((fType & kSlider1))
325  fSliderPic = fClient->GetPicture("slider1v.xpm");
326  else
327  fSliderPic = fClient->GetPicture("slider2v.xpm");
328 
329  if (!fSliderPic)
330  Error("TGHSlider", "slider?v.xpm not found");
331 
332  CreateDisabledPicture();
333 
334  gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
335  kButtonPressMask | kButtonReleaseMask |
336  kPointerMotionMask, kNone, kNone);
337 
338  AddInput(kStructureNotifyMask);
339  // set initial values
340  fPos = w/2; fVmin = 0; fVmax = w; fXp = 0;
341  fEditDisabled = kEditDisableHeight;
342 
343  if (!p && fClient->IsEditable()) {
344  Resize(100, GetDefaultHeight());
345  }
346 }
347 
348 ////////////////////////////////////////////////////////////////////////////////
349 /// Delete a horizontal slider widget.
350 
351 TGHSlider::~TGHSlider()
352 {
353  if (fSliderPic) fClient->FreePicture(fSliderPic);
354  if (fDisabledPic) fClient->FreePicture(fDisabledPic);
355 }
356 
357 ////////////////////////////////////////////////////////////////////////////////
358 /// Redraw horizontal slider widget.
359 
360 void TGHSlider::DoRedraw()
361 {
362  // cleanup drawable
363  gVirtualX->ClearWindow(fId);
364 
365  GContext_t drawGC = IsEnabled() ? GetBlackGC()() : GetShadowGC()();
366 
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);
372 
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);
384  }
385  }
386  if (fPos < fVmin) fPos = fVmin;
387  if (fPos > fVmax) fPos = fVmax;
388 
389  // calc slider-picture position
390  fRelPos = (((int)fWidth-16) * (fPos - fVmin)) / (fVmax - fVmin) + 8;
391  const TGPicture *pic = fSliderPic;
392  if (!IsEnabled()) {
393  if (!fDisabledPic) CreateDisabledPicture();
394  pic = fDisabledPic ? fDisabledPic : fSliderPic;
395  }
396  if (pic) pic->Draw(fId, GetBckgndGC()(), fRelPos-6, fHeight/2-7);
397 }
398 
399 ////////////////////////////////////////////////////////////////////////////////
400 /// Handle mouse button event in horizontal slider widget.
401 
402 Bool_t TGHSlider::HandleButton(Event_t *event)
403 {
404  if (!IsEnabled()) return kTRUE;
405  if (event->fCode == kButton4 || event->fCode == kButton5) {
406  Int_t oldPos = fPos;
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),
415  fWidgetId, fPos);
416  fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POS),
417  fWidgetId, fPos);
418  if (fPos != oldPos) {
419  PositionChanged(fPos);
420  fClient->NeedRedraw(this);
421  }
422  return kTRUE;
423  }
424  if (event->fType == kButtonPress) {
425  // constrain to the slider height
426  if (event->fY < (Int_t)fHeight/2-7 || event->fY > (Int_t)fHeight/2+7) {
427  return kTRUE;
428  }
429  if (event->fX >= fRelPos - 7 && event->fX <= fRelPos + 7) {
430  // slider selected
431  fDragging = kTRUE;
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);
435  Pressed();
436  } else {
437  if (event->fCode == kButton1) {
438  int m = (fVmax - fVmin) / (fWidth-16);
439  if (event->fX < fRelPos) {
440  fPos -= ((m) ? m : 1);
441  }
442  if (event->fX > fRelPos) {
443  fPos += ((m) ? m : 1);
444  }
445  } else if (event->fCode == kButton2) {
446  fPos = ((fVmax - fVmin) * event->fX) / (fWidth-16) + fVmin;
447  }
448  if (fPos > fVmax) fPos = fVmax;
449  if (fPos < fVmin) fPos = fVmin;
450  SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_POS),
451  fWidgetId, fPos);
452  fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POS),
453  fWidgetId, fPos);
454  PositionChanged(fPos);
455  }
456  fClient->NeedRedraw(this);
457 
458  // last argument kFALSE forces all specified events to this window
459  gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask | kPointerMotionMask,
460  kNone, kNone, kTRUE, kFALSE);
461  } else {
462  // ButtonRelease
463  fDragging = kFALSE;
464  gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
465 
466  SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_RELEASE), fWidgetId, 0);
467  fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_RELEASE), fWidgetId, 0);
468  Released();
469  }
470  return kTRUE;
471 }
472 
473 ////////////////////////////////////////////////////////////////////////////////
474 /// Handle mouse motion event in horizontal slide widget.
475 
476 Bool_t TGHSlider::HandleMotion(Event_t *event)
477 {
478  if (fDragging) {
479  int old = fPos;
480  fPos = ((fVmax - fVmin) * (event->fX - fXp)) / ((int)fWidth-16) + fVmin;
481  if (fPos > fVmax) fPos = fVmax;
482  if (fPos < fVmin) fPos = fVmin;
483 
484  // check if position changed
485  if (old != fPos) {
486  fClient->NeedRedraw(this);
487  SendMessage(fMsgWindow, MK_MSG(kC_HSLIDER, kSL_POS),
488  fWidgetId, fPos);
489  fClient->ProcessLine(fCommand, MK_MSG(kC_HSLIDER, kSL_POS),
490  fWidgetId, fPos);
491  PositionChanged(fPos);
492  }
493  }
494  return kTRUE;
495 }
496 
497 ////////////////////////////////////////////////////////////////////////////////
498 /// Handles resize events for this widget.
499 
500 Bool_t TGHSlider::HandleConfigureNotify(Event_t* event)
501 {
502  TGFrame::HandleConfigureNotify(event);
503  fClient->NeedRedraw(this);
504  return kTRUE;
505 }
506 
507 ////////////////////////////////////////////////////////////////////////////////
508 /// Returns the slider type as a string - used in SavePrimitive().
509 
510 TString TGSlider::GetTypeString() const
511 {
512  TString stype;
513 
514  if (fType) {
515  if (fType & kSlider1) {
516  if (stype.Length() == 0) stype = "kSlider1";
517  else stype += " | kSlider1";
518  }
519  if (fType & kSlider2) {
520  if (stype.Length() == 0) stype = "kSlider2";
521  else stype += " | kSlider2";
522  }
523  if (fType & kScaleNo) {
524  if (stype.Length() == 0) stype = "kScaleNo";
525  else stype += " | kScaleNo";
526  }
527  if (fType & kScaleDownRight) {
528  if (stype.Length() == 0) stype = "kScaleDownRight";
529  else stype += " | kScaleDownRight";
530  }
531  if (fType & kScaleBoth) {
532  if (stype.Length() == 0) stype = "kScaleBoth";
533  else stype += " | kScaleBoth";
534  }
535  }
536  return stype;
537 }
538 
539 ////////////////////////////////////////////////////////////////////////////////
540 /// Save an horizontal slider as a C++ statement(s) on output stream out.
541 
542 void TGHSlider::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
543 {
544  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
545 
546  out <<" TGHSlider *";
547  out << GetName() << " = new TGHSlider(" << fParent->GetName()
548  << "," << GetWidth() << ",";
549  out << GetTypeString() << "," << WidgetId();
550 
551  if (fBackground == GetDefaultFrameBackground()) {
552  if (!GetOptions()) {
553  out <<");" << std::endl;
554  } else {
555  out << "," << GetOptionString() <<");" << std::endl;
556  }
557  } else {
558  out << "," << GetOptionString() << ",ucolor);" << std::endl;
559  }
560  if (option && strstr(option, "keep_names"))
561  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
562 
563  if (fVmin != 0 || fVmax != (Int_t)fWidth)
564  out << " " << GetName() <<"->SetRange(" << fVmin << "," << fVmax << ");" << std::endl;
565 
566  if (fPos != (Int_t)fWidth/2)
567  out << " " << GetName() <<"->SetPosition(" << GetPosition() << ");" << std::endl;
568 
569  if (fScale != 10)
570  out << " " << GetName() <<"->SetScale(" << fScale << ");" << std::endl;
571 
572  if (!IsEnabled())
573  out << " " << GetName() <<"->SetState(kFALSE);" << std::endl;
574 }
575 
576 ////////////////////////////////////////////////////////////////////////////////
577 /// Save an horizontal slider as a C++ statement(s) on output stream out.
578 
579 void TGVSlider::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
580 {
581  if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
582 
583  out<<" TGVSlider *";
584  out << GetName() <<" = new TGVSlider("<< fParent->GetName()
585  << "," << GetHeight() << ",";
586  out << GetTypeString() << "," << WidgetId();
587 
588  if (fBackground == GetDefaultFrameBackground()) {
589 
590  if (!GetOptions()) {
591  out <<");" << std::endl;
592  } else {
593  out << "," << GetOptionString() <<");" << std::endl;
594  }
595  } else {
596  out << "," << GetOptionString() << ",ucolor);" << std::endl;
597  }
598  if (option && strstr(option, "keep_names"))
599  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
600 
601  if (fVmin != 0 || fVmax != (Int_t)fHeight)
602  out << " " << GetName() <<"->SetRange(" << fVmin << "," << fVmax << ");" << std::endl;
603 
604  if (fPos != (Int_t)fHeight/2)
605  out << " " << GetName() <<"->SetPosition(" << GetPosition() << ");" << std::endl;
606 
607  if (fScale != 10)
608  out << " " << GetName() <<"->SetScale(" << fScale << ");" << std::endl;
609 
610  if (!IsEnabled())
611  out << " " << GetName() <<"->SetState(kFALSE);" << std::endl;
612 }