ROOT logo
// @(#)root/ged:$Id: TGedMarkerSelect.cxx 20935 2007-11-20 17:39:33Z rdm $
// Author: Marek Biskup, Ilka Antcheva   22/07/03

/*************************************************************************
 * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGedMarkerSelect, TGedMarkerPopup                                    //
//                                                                      //
// The TGedMarkerPopup is a popup containing buttons to                 //
// select marker style.                                                 //
//                                                                      //
// The TGedMarkerSelect widget is a button showing selected marker      //
// and a little down arrow. When clicked on the arrow the               //
// TGedMarkerPopup pops up.                                             //
//                                                                      //
// Selecting a marker in this widget will generate the event:           //
// kC_MARKERSEL, kMAR_SELCHANGED, widget id, style.                     //
//                                                                      //
// and the signal:                                                      //
// MarkerSelected(Style_t marker)                                      //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TGedMarkerSelect.h"
#include "TGPicture.h"
#include "TGToolTip.h"
#include "TGButton.h"
#include "Riostream.h"

ClassImp(TGedMarkerSelect)
ClassImp(TGedMarkerPopup)

struct MarkerDescription_t {
   const char* fFilename;  // xpm file name
   const char* fName;      // type number for tooltip
   Int_t       fNumber;    // marker type number
};

static MarkerDescription_t  gMarkers[] = {

   {"marker1.xpm", "1", 1},
   {"marker6.xpm", "6", 6},
   {"marker7.xpm", "7", 7},
   {"marker2.xpm", "2", 2},
   {"marker3.xpm", "3", 3},
   {"marker4.xpm", "4", 4},
   {"marker5.xpm", "5", 5},
   {"marker20.xpm", "20", 20},
   {"marker21.xpm", "21", 21},
   {"marker22.xpm", "22", 22},
   {"marker23.xpm", "23", 23},
   {"marker24.xpm", "24", 24},
   {"marker25.xpm", "25", 25},
   {"marker26.xpm", "26", 26},
   {"marker27.xpm", "27", 27},
   {"marker28.xpm", "28", 28},
   {"marker29.xpm", "29", 29},
   {"marker30.xpm", "30", 30},
   {0, 0, 0},
};

static MarkerDescription_t* GetMarkerByNumber(Int_t number)
{
   for (Int_t i = 0; gMarkers[i].fFilename != 0; i++) {
      if (gMarkers[i].fNumber == number)
         return &gMarkers[i];
   }
   return 0;
}

//______________________________________________________________________________
TGedMarkerPopup::TGedMarkerPopup(const TGWindow *p, const TGWindow *m, Style_t markerStyle)
   : TGedPopup(p, m, 30, 30, kDoubleBorder | kRaisedFrame | kOwnBackground,
               GetDefaultFrameBackground())
{
   // Create marker popup window.

   TGButton *b;
   fCurrentStyle = markerStyle;

   Pixel_t white;
   gClient->GetColorByName("white", white); // white background
   SetBackgroundColor(white);

   SetLayoutManager(new TGTileLayout(this, 1));

   for (int i = 0; gMarkers[i].fFilename != 0; i++) {
      AddFrame(b = new TGPictureButton(this, gMarkers[i].fFilename,
               gMarkers[i].fNumber, TGButton::GetDefaultGC()(), kSunkenFrame),
               new TGLayoutHints(kLHintsLeft, 14, 14, 14, 14));
      b->SetToolTipText(gMarkers[i].fName);
   }

   Resize(65, 94);
   MapSubwindows();
}

//______________________________________________________________________________
TGedMarkerPopup::~TGedMarkerPopup()
{
   // Destructor.

   TGFrameElement *el;
   TIter next(GetList());
   while ((el = (TGFrameElement *)next())) {
      if (el->fFrame->InheritsFrom(TGPictureButton::Class()))
         fClient->FreePicture(((TGPictureButton *)el->fFrame)->GetPicture());
   }
   Cleanup();
}

//______________________________________________________________________________
Bool_t TGedMarkerPopup::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
{
   // Process messages generated by the marker popup window.

   if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON) {
      SendMessage(fMsgWindow, MK_MSG(kC_MARKERSEL, kMAR_SELCHANGED), 0, parm1);
      EndPopup();
   }

   if (parm2) {
      // no warning
   }

   return kTRUE;
}

//______________________________________________________________________________
TGedMarkerSelect::TGedMarkerSelect(const TGWindow *p, Style_t markerStyle, Int_t id)
   : TGedSelect(p, id)
{
   // Create and show marker popup window.

   fPicture = 0;
   SetPopup(new TGedMarkerPopup(gClient->GetDefaultRoot(), this, markerStyle));
   SetMarkerStyle(markerStyle);

}

//_____________________________________________________________________________
Bool_t TGedMarkerSelect::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
{
   // Process messages according to the user input.

   if (GET_MSG(msg) == kC_MARKERSEL && GET_SUBMSG(msg) == kMAR_SELCHANGED) {
      SetMarkerStyle(parm2);
      parm1 = (Long_t)fWidgetId;
      SendMessage(fMsgWindow, MK_MSG(kC_MARKERSEL, kMAR_SELCHANGED),
                  parm1, parm2);
   }

   return kTRUE;
}

//_____________________________________________________________________________
void TGedMarkerSelect::DoRedraw()
{
   // Draw selected marker type as current one.

   TGedSelect::DoRedraw();

   Int_t  x, y;
   UInt_t w, h;

   if (IsEnabled()) {
      // pattern rectangle

      x = fBorderWidth + 2;
      y = fBorderWidth + 2;  // 1;
      h = fHeight - (fBorderWidth * 2) - 4;  // -3;  // 14
      w = h;
      if (fState == kButtonDown) {
         ++x; ++y;
      }
      gVirtualX->DrawRectangle(fId, GetShadowGC()(), x, y, w - 1, h - 1);

      if (fPicture != 0) fPicture->Draw(fId, fDrawGC->GetGC(), x + 1, y + 1);
   } else { // sunken rectangle
      x = fBorderWidth + 2;
      y = fBorderWidth + 2;  // 1;
      w = 42;
      h = fHeight - (fBorderWidth * 2) - 4;  // 3;
      Draw3dRectangle(kSunkenFrame, x, y, w, h);
   }
}

//_____________________________________________________________________________
void TGedMarkerSelect::SetMarkerStyle(Style_t markerStyle)
{
   // Set marker.

   fMarkerStyle = markerStyle;
   gClient->NeedRedraw(this);

   if (fPicture) {
      gClient->FreePicture(fPicture);
      fPicture = 0;
   }

   MarkerDescription_t *md = GetMarkerByNumber(fMarkerStyle);

   if (md)  fPicture = gClient->GetPicture(md->fFilename);

   MarkerSelected(fMarkerStyle);
}

//______________________________________________________________________________
void TGedMarkerSelect::SavePrimitive(ostream &out, Option_t * /*= ""*/)
{
   // Save the pattern select widget as a C++ statement(s) on output stream out

   out <<"   TGedMarkerSelect *";
   out << GetName() << " = new TGedMarkerSelect(" << fParent->GetName()
       << "," << fMarkerStyle << "," << WidgetId() << ");" << endl;
}
 TGedMarkerSelect.cxx:1
 TGedMarkerSelect.cxx:2
 TGedMarkerSelect.cxx:3
 TGedMarkerSelect.cxx:4
 TGedMarkerSelect.cxx:5
 TGedMarkerSelect.cxx:6
 TGedMarkerSelect.cxx:7
 TGedMarkerSelect.cxx:8
 TGedMarkerSelect.cxx:9
 TGedMarkerSelect.cxx:10
 TGedMarkerSelect.cxx:11
 TGedMarkerSelect.cxx:12
 TGedMarkerSelect.cxx:13
 TGedMarkerSelect.cxx:14
 TGedMarkerSelect.cxx:15
 TGedMarkerSelect.cxx:16
 TGedMarkerSelect.cxx:17
 TGedMarkerSelect.cxx:18
 TGedMarkerSelect.cxx:19
 TGedMarkerSelect.cxx:20
 TGedMarkerSelect.cxx:21
 TGedMarkerSelect.cxx:22
 TGedMarkerSelect.cxx:23
 TGedMarkerSelect.cxx:24
 TGedMarkerSelect.cxx:25
 TGedMarkerSelect.cxx:26
 TGedMarkerSelect.cxx:27
 TGedMarkerSelect.cxx:28
 TGedMarkerSelect.cxx:29
 TGedMarkerSelect.cxx:30
 TGedMarkerSelect.cxx:31
 TGedMarkerSelect.cxx:32
 TGedMarkerSelect.cxx:33
 TGedMarkerSelect.cxx:34
 TGedMarkerSelect.cxx:35
 TGedMarkerSelect.cxx:36
 TGedMarkerSelect.cxx:37
 TGedMarkerSelect.cxx:38
 TGedMarkerSelect.cxx:39
 TGedMarkerSelect.cxx:40
 TGedMarkerSelect.cxx:41
 TGedMarkerSelect.cxx:42
 TGedMarkerSelect.cxx:43
 TGedMarkerSelect.cxx:44
 TGedMarkerSelect.cxx:45
 TGedMarkerSelect.cxx:46
 TGedMarkerSelect.cxx:47
 TGedMarkerSelect.cxx:48
 TGedMarkerSelect.cxx:49
 TGedMarkerSelect.cxx:50
 TGedMarkerSelect.cxx:51
 TGedMarkerSelect.cxx:52
 TGedMarkerSelect.cxx:53
 TGedMarkerSelect.cxx:54
 TGedMarkerSelect.cxx:55
 TGedMarkerSelect.cxx:56
 TGedMarkerSelect.cxx:57
 TGedMarkerSelect.cxx:58
 TGedMarkerSelect.cxx:59
 TGedMarkerSelect.cxx:60
 TGedMarkerSelect.cxx:61
 TGedMarkerSelect.cxx:62
 TGedMarkerSelect.cxx:63
 TGedMarkerSelect.cxx:64
 TGedMarkerSelect.cxx:65
 TGedMarkerSelect.cxx:66
 TGedMarkerSelect.cxx:67
 TGedMarkerSelect.cxx:68
 TGedMarkerSelect.cxx:69
 TGedMarkerSelect.cxx:70
 TGedMarkerSelect.cxx:71
 TGedMarkerSelect.cxx:72
 TGedMarkerSelect.cxx:73
 TGedMarkerSelect.cxx:74
 TGedMarkerSelect.cxx:75
 TGedMarkerSelect.cxx:76
 TGedMarkerSelect.cxx:77
 TGedMarkerSelect.cxx:78
 TGedMarkerSelect.cxx:79
 TGedMarkerSelect.cxx:80
 TGedMarkerSelect.cxx:81
 TGedMarkerSelect.cxx:82
 TGedMarkerSelect.cxx:83
 TGedMarkerSelect.cxx:84
 TGedMarkerSelect.cxx:85
 TGedMarkerSelect.cxx:86
 TGedMarkerSelect.cxx:87
 TGedMarkerSelect.cxx:88
 TGedMarkerSelect.cxx:89
 TGedMarkerSelect.cxx:90
 TGedMarkerSelect.cxx:91
 TGedMarkerSelect.cxx:92
 TGedMarkerSelect.cxx:93
 TGedMarkerSelect.cxx:94
 TGedMarkerSelect.cxx:95
 TGedMarkerSelect.cxx:96
 TGedMarkerSelect.cxx:97
 TGedMarkerSelect.cxx:98
 TGedMarkerSelect.cxx:99
 TGedMarkerSelect.cxx:100
 TGedMarkerSelect.cxx:101
 TGedMarkerSelect.cxx:102
 TGedMarkerSelect.cxx:103
 TGedMarkerSelect.cxx:104
 TGedMarkerSelect.cxx:105
 TGedMarkerSelect.cxx:106
 TGedMarkerSelect.cxx:107
 TGedMarkerSelect.cxx:108
 TGedMarkerSelect.cxx:109
 TGedMarkerSelect.cxx:110
 TGedMarkerSelect.cxx:111
 TGedMarkerSelect.cxx:112
 TGedMarkerSelect.cxx:113
 TGedMarkerSelect.cxx:114
 TGedMarkerSelect.cxx:115
 TGedMarkerSelect.cxx:116
 TGedMarkerSelect.cxx:117
 TGedMarkerSelect.cxx:118
 TGedMarkerSelect.cxx:119
 TGedMarkerSelect.cxx:120
 TGedMarkerSelect.cxx:121
 TGedMarkerSelect.cxx:122
 TGedMarkerSelect.cxx:123
 TGedMarkerSelect.cxx:124
 TGedMarkerSelect.cxx:125
 TGedMarkerSelect.cxx:126
 TGedMarkerSelect.cxx:127
 TGedMarkerSelect.cxx:128
 TGedMarkerSelect.cxx:129
 TGedMarkerSelect.cxx:130
 TGedMarkerSelect.cxx:131
 TGedMarkerSelect.cxx:132
 TGedMarkerSelect.cxx:133
 TGedMarkerSelect.cxx:134
 TGedMarkerSelect.cxx:135
 TGedMarkerSelect.cxx:136
 TGedMarkerSelect.cxx:137
 TGedMarkerSelect.cxx:138
 TGedMarkerSelect.cxx:139
 TGedMarkerSelect.cxx:140
 TGedMarkerSelect.cxx:141
 TGedMarkerSelect.cxx:142
 TGedMarkerSelect.cxx:143
 TGedMarkerSelect.cxx:144
 TGedMarkerSelect.cxx:145
 TGedMarkerSelect.cxx:146
 TGedMarkerSelect.cxx:147
 TGedMarkerSelect.cxx:148
 TGedMarkerSelect.cxx:149
 TGedMarkerSelect.cxx:150
 TGedMarkerSelect.cxx:151
 TGedMarkerSelect.cxx:152
 TGedMarkerSelect.cxx:153
 TGedMarkerSelect.cxx:154
 TGedMarkerSelect.cxx:155
 TGedMarkerSelect.cxx:156
 TGedMarkerSelect.cxx:157
 TGedMarkerSelect.cxx:158
 TGedMarkerSelect.cxx:159
 TGedMarkerSelect.cxx:160
 TGedMarkerSelect.cxx:161
 TGedMarkerSelect.cxx:162
 TGedMarkerSelect.cxx:163
 TGedMarkerSelect.cxx:164
 TGedMarkerSelect.cxx:165
 TGedMarkerSelect.cxx:166
 TGedMarkerSelect.cxx:167
 TGedMarkerSelect.cxx:168
 TGedMarkerSelect.cxx:169
 TGedMarkerSelect.cxx:170
 TGedMarkerSelect.cxx:171
 TGedMarkerSelect.cxx:172
 TGedMarkerSelect.cxx:173
 TGedMarkerSelect.cxx:174
 TGedMarkerSelect.cxx:175
 TGedMarkerSelect.cxx:176
 TGedMarkerSelect.cxx:177
 TGedMarkerSelect.cxx:178
 TGedMarkerSelect.cxx:179
 TGedMarkerSelect.cxx:180
 TGedMarkerSelect.cxx:181
 TGedMarkerSelect.cxx:182
 TGedMarkerSelect.cxx:183
 TGedMarkerSelect.cxx:184
 TGedMarkerSelect.cxx:185
 TGedMarkerSelect.cxx:186
 TGedMarkerSelect.cxx:187
 TGedMarkerSelect.cxx:188
 TGedMarkerSelect.cxx:189
 TGedMarkerSelect.cxx:190
 TGedMarkerSelect.cxx:191
 TGedMarkerSelect.cxx:192
 TGedMarkerSelect.cxx:193
 TGedMarkerSelect.cxx:194
 TGedMarkerSelect.cxx:195
 TGedMarkerSelect.cxx:196
 TGedMarkerSelect.cxx:197
 TGedMarkerSelect.cxx:198
 TGedMarkerSelect.cxx:199
 TGedMarkerSelect.cxx:200
 TGedMarkerSelect.cxx:201
 TGedMarkerSelect.cxx:202
 TGedMarkerSelect.cxx:203
 TGedMarkerSelect.cxx:204
 TGedMarkerSelect.cxx:205
 TGedMarkerSelect.cxx:206
 TGedMarkerSelect.cxx:207
 TGedMarkerSelect.cxx:208
 TGedMarkerSelect.cxx:209
 TGedMarkerSelect.cxx:210
 TGedMarkerSelect.cxx:211
 TGedMarkerSelect.cxx:212
 TGedMarkerSelect.cxx:213
 TGedMarkerSelect.cxx:214
 TGedMarkerSelect.cxx:215
 TGedMarkerSelect.cxx:216
 TGedMarkerSelect.cxx:217
 TGedMarkerSelect.cxx:218
 TGedMarkerSelect.cxx:219
 TGedMarkerSelect.cxx:220
 TGedMarkerSelect.cxx:221
 TGedMarkerSelect.cxx:222
 TGedMarkerSelect.cxx:223
 TGedMarkerSelect.cxx:224