TGedMarkerSelect.cxx

Go to the documentation of this file.
00001 // @(#)root/ged:$Id: TGedMarkerSelect.cxx 20935 2007-11-20 17:39:33Z rdm $
00002 // Author: Marek Biskup, Ilka Antcheva   22/07/03
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 
00013 //////////////////////////////////////////////////////////////////////////
00014 //                                                                      //
00015 // TGedMarkerSelect, TGedMarkerPopup                                    //
00016 //                                                                      //
00017 // The TGedMarkerPopup is a popup containing buttons to                 //
00018 // select marker style.                                                 //
00019 //                                                                      //
00020 // The TGedMarkerSelect widget is a button showing selected marker      //
00021 // and a little down arrow. When clicked on the arrow the               //
00022 // TGedMarkerPopup pops up.                                             //
00023 //                                                                      //
00024 // Selecting a marker in this widget will generate the event:           //
00025 // kC_MARKERSEL, kMAR_SELCHANGED, widget id, style.                     //
00026 //                                                                      //
00027 // and the signal:                                                      //
00028 // MarkerSelected(Style_t marker)                                      //
00029 //                                                                      //
00030 //////////////////////////////////////////////////////////////////////////
00031 
00032 #include "TGedMarkerSelect.h"
00033 #include "TGPicture.h"
00034 #include "TGToolTip.h"
00035 #include "TGButton.h"
00036 #include "Riostream.h"
00037 
00038 ClassImp(TGedMarkerSelect)
00039 ClassImp(TGedMarkerPopup)
00040 
00041 struct MarkerDescription_t {
00042    const char* fFilename;  // xpm file name
00043    const char* fName;      // type number for tooltip
00044    Int_t       fNumber;    // marker type number
00045 };
00046 
00047 static MarkerDescription_t  gMarkers[] = {
00048 
00049    {"marker1.xpm", "1", 1},
00050    {"marker6.xpm", "6", 6},
00051    {"marker7.xpm", "7", 7},
00052    {"marker2.xpm", "2", 2},
00053    {"marker3.xpm", "3", 3},
00054    {"marker4.xpm", "4", 4},
00055    {"marker5.xpm", "5", 5},
00056    {"marker20.xpm", "20", 20},
00057    {"marker21.xpm", "21", 21},
00058    {"marker22.xpm", "22", 22},
00059    {"marker23.xpm", "23", 23},
00060    {"marker24.xpm", "24", 24},
00061    {"marker25.xpm", "25", 25},
00062    {"marker26.xpm", "26", 26},
00063    {"marker27.xpm", "27", 27},
00064    {"marker28.xpm", "28", 28},
00065    {"marker29.xpm", "29", 29},
00066    {"marker30.xpm", "30", 30},
00067    {0, 0, 0},
00068 };
00069 
00070 static MarkerDescription_t* GetMarkerByNumber(Int_t number)
00071 {
00072    for (Int_t i = 0; gMarkers[i].fFilename != 0; i++) {
00073       if (gMarkers[i].fNumber == number)
00074          return &gMarkers[i];
00075    }
00076    return 0;
00077 }
00078 
00079 //______________________________________________________________________________
00080 TGedMarkerPopup::TGedMarkerPopup(const TGWindow *p, const TGWindow *m, Style_t markerStyle)
00081    : TGedPopup(p, m, 30, 30, kDoubleBorder | kRaisedFrame | kOwnBackground,
00082                GetDefaultFrameBackground())
00083 {
00084    // Create marker popup window.
00085 
00086    TGButton *b;
00087    fCurrentStyle = markerStyle;
00088 
00089    Pixel_t white;
00090    gClient->GetColorByName("white", white); // white background
00091    SetBackgroundColor(white);
00092 
00093    SetLayoutManager(new TGTileLayout(this, 1));
00094 
00095    for (int i = 0; gMarkers[i].fFilename != 0; i++) {
00096       AddFrame(b = new TGPictureButton(this, gMarkers[i].fFilename,
00097                gMarkers[i].fNumber, TGButton::GetDefaultGC()(), kSunkenFrame),
00098                new TGLayoutHints(kLHintsLeft, 14, 14, 14, 14));
00099       b->SetToolTipText(gMarkers[i].fName);
00100    }
00101 
00102    Resize(65, 94);
00103    MapSubwindows();
00104 }
00105 
00106 //______________________________________________________________________________
00107 TGedMarkerPopup::~TGedMarkerPopup()
00108 {
00109    // Destructor.
00110 
00111    TGFrameElement *el;
00112    TIter next(GetList());
00113    while ((el = (TGFrameElement *)next())) {
00114       if (el->fFrame->InheritsFrom(TGPictureButton::Class()))
00115          fClient->FreePicture(((TGPictureButton *)el->fFrame)->GetPicture());
00116    }
00117    Cleanup();
00118 }
00119 
00120 //______________________________________________________________________________
00121 Bool_t TGedMarkerPopup::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
00122 {
00123    // Process messages generated by the marker popup window.
00124 
00125    if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON) {
00126       SendMessage(fMsgWindow, MK_MSG(kC_MARKERSEL, kMAR_SELCHANGED), 0, parm1);
00127       EndPopup();
00128    }
00129 
00130    if (parm2) {
00131       // no warning
00132    }
00133 
00134    return kTRUE;
00135 }
00136 
00137 //______________________________________________________________________________
00138 TGedMarkerSelect::TGedMarkerSelect(const TGWindow *p, Style_t markerStyle, Int_t id)
00139    : TGedSelect(p, id)
00140 {
00141    // Create and show marker popup window.
00142 
00143    fPicture = 0;
00144    SetPopup(new TGedMarkerPopup(gClient->GetDefaultRoot(), this, markerStyle));
00145    SetMarkerStyle(markerStyle);
00146 
00147 }
00148 
00149 //_____________________________________________________________________________
00150 Bool_t TGedMarkerSelect::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
00151 {
00152    // Process messages according to the user input.
00153 
00154    if (GET_MSG(msg) == kC_MARKERSEL && GET_SUBMSG(msg) == kMAR_SELCHANGED) {
00155       SetMarkerStyle(parm2);
00156       parm1 = (Long_t)fWidgetId;
00157       SendMessage(fMsgWindow, MK_MSG(kC_MARKERSEL, kMAR_SELCHANGED),
00158                   parm1, parm2);
00159    }
00160 
00161    return kTRUE;
00162 }
00163 
00164 //_____________________________________________________________________________
00165 void TGedMarkerSelect::DoRedraw()
00166 {
00167    // Draw selected marker type as current one.
00168 
00169    TGedSelect::DoRedraw();
00170 
00171    Int_t  x, y;
00172    UInt_t w, h;
00173 
00174    if (IsEnabled()) {
00175       // pattern rectangle
00176 
00177       x = fBorderWidth + 2;
00178       y = fBorderWidth + 2;  // 1;
00179       h = fHeight - (fBorderWidth * 2) - 4;  // -3;  // 14
00180       w = h;
00181       if (fState == kButtonDown) {
00182          ++x; ++y;
00183       }
00184       gVirtualX->DrawRectangle(fId, GetShadowGC()(), x, y, w - 1, h - 1);
00185 
00186       if (fPicture != 0) fPicture->Draw(fId, fDrawGC->GetGC(), x + 1, y + 1);
00187    } else { // sunken rectangle
00188       x = fBorderWidth + 2;
00189       y = fBorderWidth + 2;  // 1;
00190       w = 42;
00191       h = fHeight - (fBorderWidth * 2) - 4;  // 3;
00192       Draw3dRectangle(kSunkenFrame, x, y, w, h);
00193    }
00194 }
00195 
00196 //_____________________________________________________________________________
00197 void TGedMarkerSelect::SetMarkerStyle(Style_t markerStyle)
00198 {
00199    // Set marker.
00200 
00201    fMarkerStyle = markerStyle;
00202    gClient->NeedRedraw(this);
00203 
00204    if (fPicture) {
00205       gClient->FreePicture(fPicture);
00206       fPicture = 0;
00207    }
00208 
00209    MarkerDescription_t *md = GetMarkerByNumber(fMarkerStyle);
00210 
00211    if (md)  fPicture = gClient->GetPicture(md->fFilename);
00212 
00213    MarkerSelected(fMarkerStyle);
00214 }
00215 
00216 //______________________________________________________________________________
00217 void TGedMarkerSelect::SavePrimitive(ostream &out, Option_t * /*= ""*/)
00218 {
00219    // Save the pattern select widget as a C++ statement(s) on output stream out
00220 
00221    out <<"   TGedMarkerSelect *";
00222    out << GetName() << " = new TGedMarkerSelect(" << fParent->GetName()
00223        << "," << fMarkerStyle << "," << WidgetId() << ");" << endl;
00224 }

Generated on Tue Jul 5 14:19:46 2011 for ROOT_528-00b_version by  doxygen 1.5.1