TGComboBox.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGComboBox.cxx 36649 2010-11-13 06:10:53Z brun $
00002 // Author: Fons Rademakers   13/01/98
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, 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     This source is based on Xclass95, a Win95-looking GUI toolkit.
00014     Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
00015 
00016     Xclass95 is free software; you can redistribute it and/or
00017     modify it under the terms of the GNU Library General Public
00018     License as published by the Free Software Foundation; either
00019     version 2 of the License, or (at your option) any later version.
00020 
00021 **************************************************************************/
00022 
00023 //////////////////////////////////////////////////////////////////////////
00024 //                                                                      //
00025 // TGComboBox, TGComboBoxPopup                                          //
00026 //                                                                      //
00027 // A combobox (also known as a drop down listbox) allows the selection  //
00028 // of one item out of a list of items. The selected item is visible in  //
00029 // a little window. To view the list of possible items one has to click //
00030 // on a button on the right of the little window. This will drop down   //
00031 // a listbox. After selecting an item from the listbox the box will     //
00032 // disappear and the newly selected item will be shown in the little    //
00033 // window.                                                              //
00034 //                                                                      //
00035 // The TGComboBox is user callable. The TGComboBoxPopup is a service    //
00036 // class of the combobox.                                               //
00037 //                                                                      //
00038 // Selecting an item in the combobox will generate the event:           //
00039 // kC_COMMAND, kCM_COMBOBOX, combobox id, item id.                      //
00040 //                                                                      //
00041 //////////////////////////////////////////////////////////////////////////
00042 
00043 #include "TGComboBox.h"
00044 #include "TGScrollBar.h"
00045 #include "TGPicture.h"
00046 #include "TGResourcePool.h"
00047 #include "Riostream.h"
00048 #include "TGTextEntry.h"
00049 
00050 
00051 
00052 ClassImp(TGComboBoxPopup)
00053 ClassImp(TGComboBox)
00054 
00055 ClassImp(TGLineStyleComboBox)
00056 ClassImp(TGLineWidthComboBox)
00057 ClassImp(TGFontTypeComboBox)
00058 
00059 //______________________________________________________________________________
00060 TGComboBoxPopup::TGComboBoxPopup(const TGWindow *p, UInt_t w, UInt_t h,
00061                                  UInt_t options, ULong_t back) :
00062    TGCompositeFrame (p, w, h, options, back), fListBox(0), fSelected(0)
00063 {
00064    // Create a combo box popup frame.
00065 
00066    SetWindowAttributes_t wattr;
00067 
00068    wattr.fMask = kWAOverrideRedirect | kWASaveUnder |
00069                  kWABorderPixel      | kWABorderWidth;
00070    wattr.fOverrideRedirect = kTRUE;
00071    wattr.fSaveUnder = kTRUE;
00072    wattr.fBorderPixel = fgBlackPixel;
00073    wattr.fBorderWidth = 1;
00074    gVirtualX->ChangeWindowAttributes(fId, &wattr);
00075 
00076    AddInput(kStructureNotifyMask);
00077    fEditDisabled = kEditDisable | kEditDisableGrab  | kEditDisableBtnEnable;
00078    SetWindowName();
00079 }
00080 
00081 //______________________________________________________________________________
00082 Bool_t TGComboBoxPopup::HandleButton(Event_t *event)
00083 {
00084    // Handle mouse button event in combo box popup.
00085 
00086    if (event->fType == kButtonPress && event->fCode == kButton1) {
00087       if ((fListBox != 0) && (fSelected != 0) && 
00088           fListBox->GetSelectedEntry() != fSelected) {
00089          // in the case the combo box popup is closed by clicking outside the 
00090          // list box, then select the previously selected entry
00091          fListBox->Select(fSelected->EntryId());
00092       }
00093       EndPopup();
00094    }
00095    return kTRUE;
00096 }
00097 
00098 //______________________________________________________________________________
00099 void TGComboBoxPopup::EndPopup()
00100 {
00101    // Ungrab pointer and unmap popup window.
00102 
00103    if (IsMapped()) {
00104       gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);
00105       UnmapWindow();
00106    }
00107 }
00108 
00109 //______________________________________________________________________________
00110 void TGComboBoxPopup::PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h)
00111 {
00112    // Popup combo box popup window at the specified place.
00113 
00114    Int_t  rx, ry;
00115    UInt_t rw, rh;
00116 
00117    // Parent is root window for the popup:
00118    gVirtualX->GetWindowSize(fParent->GetId(), rx, ry, rw, rh);
00119 
00120    if (x < 0) x = 0;
00121    if (x + fWidth > rw) x = rw - fWidth;
00122    if (y < 0) y = 0;
00123    if (y + fHeight > rh) y = rh - fHeight;
00124 
00125    // remember the current selected entry
00126    if (fListBox == 0) {
00127       // the listbox should be the first in the list
00128       TGFrameElement *el = (TGFrameElement *)fList->First();
00129       fListBox = dynamic_cast<TGListBox *>(el->fFrame);
00130    }
00131    fSelected = fListBox ? fListBox->GetSelectedEntry() : 0;
00132 
00133    MoveResize(x, y, w, h);
00134    MapSubwindows();
00135    Layout();
00136    MapRaised();
00137 
00138    gVirtualX->GrabPointer(fId, kButtonPressMask | kButtonReleaseMask |
00139                               kPointerMotionMask, kNone,
00140                               fClient->GetResourcePool()->GetGrabCursor());
00141 
00142    if (fClient->IsEditable()) {
00143       fClient->RegisterPopup(this);
00144    }
00145 
00146    fClient->WaitForUnmap(this);
00147    EndPopup();
00148 }
00149 
00150 
00151 //______________________________________________________________________________
00152 TGComboBox::TGComboBox(const TGWindow *p, Int_t id, UInt_t options,
00153                        ULong_t back) :
00154    TGCompositeFrame (p, 10, 10, options | kOwnBackground, back)
00155 {
00156    // Create a combo box widget.
00157 
00158    fWidgetId  = id;
00159    fMsgWindow = p;
00160    fTextEntry = 0;
00161 
00162    fSelEntry = new TGTextLBEntry(this, new TGString(""), 0);
00163    fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
00164 
00165    AddFrame(fSelEntry, fLhs = new TGLayoutHints(kLHintsLeft |
00166                                                 kLHintsExpandY | kLHintsExpandX));
00167    Init();
00168 }
00169 
00170 //______________________________________________________________________________
00171 TGComboBox::TGComboBox(const TGWindow *p, const char *text, Int_t id,
00172                        UInt_t options, ULong_t back) :
00173             TGCompositeFrame (p, 10, 10, options | kOwnBackground, back)
00174 {
00175    // Create an editable combo box widget.
00176 
00177    fWidgetId  = id;
00178    fMsgWindow = p;
00179    fSelEntry = 0;
00180 
00181    fTextEntry = new TGTextEntry(this, text, id);
00182    fTextEntry->SetFrameDrawn(kFALSE);
00183    fTextEntry->Connect("ReturnPressed()", "TGComboBox", this, "ReturnPressed()");
00184 
00185    AddFrame(fTextEntry, fLhs = new TGLayoutHints(kLHintsLeft |
00186                                                  kLHintsExpandY | kLHintsExpandX));
00187    Init();
00188 }
00189 
00190 //______________________________________________________________________________
00191 TGComboBox::~TGComboBox()
00192 {
00193    // Delete a combo box widget.
00194 
00195    fClient->FreePicture(fBpic);
00196 
00197    if (!MustCleanup()) {
00198       SafeDelete(fDDButton);
00199       SafeDelete(fSelEntry);
00200       SafeDelete(fTextEntry);
00201       SafeDelete(fLhs);
00202       SafeDelete(fLhb);
00203    }
00204 
00205    SafeDelete(fLhdd);
00206    SafeDelete(fListBox);
00207    if (fComboFrame) {
00208       fComboFrame->EndPopup();  // force popdown in case of Qt interface
00209       SafeDelete(fComboFrame);
00210    }
00211 }
00212 
00213 //______________________________________________________________________________
00214 void TGComboBox::Init()
00215 {
00216    // Initiate the internal classes of a combo box.
00217 
00218    fBpic = fClient->GetPicture("arrow_down.xpm");
00219 
00220    if (!fBpic)
00221       Error("TGComboBox", "arrow_down.xpm not found");
00222 
00223    fDDButton = new TGScrollBarElement(this, fBpic, kDefaultScrollBarWidth,
00224                                       kDefaultScrollBarWidth, kRaisedFrame);
00225 
00226    AddFrame(fDDButton, fLhb = new TGLayoutHints(kLHintsRight |
00227                                                 kLHintsExpandY));
00228 
00229    fComboFrame = new TGComboBoxPopup(fClient->GetDefaultRoot(), 100, 100, kVerticalFrame);
00230 
00231    fListBox = new TGListBox(fComboFrame, fWidgetId, kChildFrame);
00232 
00233    fListBox->Resize(100, 100);
00234    fListBox->Associate(this);
00235    fListBox->GetScrollBar()->GrabPointer(kFALSE); // combobox will do a pointergrab
00236 
00237    fComboFrame->AddFrame(fListBox, fLhdd = new TGLayoutHints(kLHintsExpandX |
00238                                                              kLHintsExpandY));
00239    fComboFrame->SetListBox(fListBox);
00240    fComboFrame->MapSubwindows();
00241    fComboFrame->Resize(fComboFrame->GetDefaultSize());
00242 
00243    gVirtualX->GrabButton(fId, kButton1, kAnyModifier, kButtonPressMask |
00244                          kButtonReleaseMask | kPointerMotionMask, kNone, kNone);
00245 
00246    // Drop down listbox of combo box should react to pointer motion
00247    // so it will be able to Activate() (i.e. highlight) the different
00248    // items when the mouse crosses.
00249    fListBox->GetContainer()->AddInput(kButtonPressMask | kButtonReleaseMask |
00250                                       kPointerMotionMask);
00251 
00252    fListBox->SetEditDisabled(kEditDisable);
00253    fListBox->GetContainer()->SetEditDisabled(kEditDisable);
00254    if (fSelEntry) fSelEntry->SetEditDisabled(kEditDisable | kEditDisableEvents | kEditDisableGrab);
00255    if (fTextEntry) fTextEntry->SetEditDisabled(kEditDisable | kEditDisableGrab | kEditDisableBtnEnable);
00256    fDDButton->SetEditDisabled(kEditDisable | kEditDisableGrab);
00257    fEditDisabled = kEditDisableLayout | kEditDisableBtnEnable | kEditDisableHeight;
00258 
00259    SetWindowName();
00260 }
00261 
00262 //______________________________________________________________________________
00263 void TGComboBox::DrawBorder()
00264 {
00265    // Draw border of combo box widget.
00266 
00267    switch (fOptions & (kSunkenFrame | kRaisedFrame | kDoubleBorder)) {
00268       case kSunkenFrame | kDoubleBorder:
00269          gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, fWidth-2, 0);
00270          gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, 0, fHeight-2);
00271          gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, fWidth-3, 1);
00272          gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, 1, fHeight-3);
00273 
00274          gVirtualX->DrawLine(fId, GetHilightGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
00275          gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
00276          gVirtualX->DrawLine(fId, GetBckgndGC()(),  1, fHeight-2, fWidth-2, fHeight-2);
00277          gVirtualX->DrawLine(fId, GetBckgndGC()(),  fWidth-2, 1, fWidth-2, fHeight-2);
00278          break;
00279 
00280       default:
00281          TGCompositeFrame::DrawBorder();
00282          break;
00283    }
00284 }
00285 
00286 //______________________________________________________________________________
00287 void TGComboBox::EnableTextInput(Bool_t on)
00288 {
00289    // Switch text input or readonly mode of combobox (not perfect yet).
00290 
00291    UInt_t w, h;
00292    const char *text = "";
00293    Pixel_t back = TGFrame::GetWhitePixel(); // default
00294 
00295    if (on) {
00296       if (fSelEntry) {
00297          back = fSelEntry->GetBackground();
00298          text = ((TGTextLBEntry*)fSelEntry)->GetText()->GetString();
00299          if (fTextEntry && fSelEntry->InheritsFrom(TGTextLBEntry::Class())) {
00300             fTextEntry->SetText(text);
00301          }
00302          RemoveFrame(fSelEntry);
00303          w = fSelEntry->GetWidth();
00304          h = fSelEntry->GetHeight();
00305          fSelEntry->DestroyWindow();
00306          delete fSelEntry;
00307          fSelEntry = 0;
00308       }
00309       if (!fTextEntry) {
00310          fTextEntry = new TGTextEntry(this, text, 0);
00311          fTextEntry->SetFrameDrawn(kFALSE);
00312          fTextEntry->Connect("ReturnPressed()", "TGComboBox", this, "ReturnPressed()");
00313          AddFrame(fTextEntry, fLhs);
00314          fTextEntry->SetEditDisabled(kEditDisable | kEditDisableGrab | kEditDisableBtnEnable);
00315       }
00316       fTextEntry->SetBackgroundColor(back);
00317       MapSubwindows();
00318       GetLayoutManager()->Layout();
00319    } else {
00320       if (fTextEntry) {
00321          back = fTextEntry->GetBackground();
00322          text = fTextEntry->GetText();
00323          RemoveFrame(fTextEntry);
00324          fTextEntry->DestroyWindow();
00325          w = fTextEntry->GetWidth();
00326          h = fTextEntry->GetHeight();
00327          delete fTextEntry;
00328          fTextEntry = 0;
00329       }
00330       if (!fSelEntry) {
00331          fSelEntry = new TGTextLBEntry(this, new TGString(text), 0);
00332          fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
00333          AddFrame(fSelEntry, fLhs);
00334          fSelEntry->SetEditDisabled(kEditDisable | kEditDisableGrab);
00335       }
00336       fSelEntry->SetBackgroundColor(back);
00337       MapSubwindows();
00338       GetLayoutManager()->Layout();
00339    }
00340 }
00341 
00342 //______________________________________________________________________________
00343 TGLBEntry *TGComboBox::FindEntry(const char *s) const
00344 {
00345    // Find entry by name.
00346 
00347    TGLBEntry *sel = 0;
00348    sel = fListBox->FindEntry(s);
00349    return sel;
00350 }
00351 
00352 //______________________________________________________________________________
00353 void TGComboBox::SetTopEntry(TGLBEntry *e, TGLayoutHints *lh)
00354 {
00355    // Set a new combo box value (normally update of text string in
00356    // fSelEntry is done via fSelEntry::Update()).
00357 
00358    if (!fSelEntry) return;
00359 
00360    RemoveFrame(fSelEntry);
00361    fSelEntry->DestroyWindow();
00362    delete fSelEntry;
00363    delete fLhs;
00364    fSelEntry = e;
00365    fLhs = lh;
00366    AddFrame(fSelEntry, fLhs);
00367    Layout();
00368 }
00369 
00370 //______________________________________________________________________________
00371 void TGComboBox::Select(Int_t id, Bool_t emit)
00372 {
00373    // Make the selected item visible in the combo box window
00374    // and emit signals according to the second parameter.
00375 
00376    if (id!=GetSelected()) {
00377       TGLBEntry *e;
00378       e = fListBox->Select(id);
00379       if (e) {
00380          if (fSelEntry) {
00381             fSelEntry->Update(e);
00382             Layout();
00383             if (emit) {
00384                Selected(fWidgetId, id);
00385                Selected(id);
00386             }
00387          }
00388       }
00389    }
00390 }
00391 
00392 //______________________________________________________________________________
00393 Bool_t TGComboBox::HandleButton(Event_t *event)
00394 {
00395    // Handle mouse button events in the combo box.
00396 
00397    if (!fDDButton || !fDDButton->IsEnabled()) return kFALSE;
00398 
00399    if (event->fType == kButtonPress) {
00400       Window_t child = (Window_t)event->fUser[0];  // fUser[0] = child window
00401 
00402       if (child == fDDButton->GetId() || (fSelEntry && child == fSelEntry->GetId())) {
00403          fDDButton->SetState(kButtonDown);
00404 
00405          if (fTextEntry && (child == fTextEntry->GetId())) {
00406             return fTextEntry->HandleButton(event);
00407          }
00408          int      ax, ay;
00409          Window_t wdummy;
00410          gVirtualX->TranslateCoordinates(fId, fComboFrame->GetParent()->GetId(),
00411                                          0, fHeight, ax, ay, wdummy);
00412          // Drop down listbox of combo box should react to pointer motion...
00413          fListBox->GetContainer()->AddInput(kPointerMotionMask);
00414          fComboFrame->PlacePopup(ax, ay, fWidth-2, fComboFrame->GetDefaultHeight());
00415          fDDButton->SetState(kButtonUp);
00416       } else if (fTextEntry) {
00417          return fTextEntry->HandleButton(event);
00418       }
00419    }
00420    return kTRUE;
00421 }
00422 
00423 //______________________________________________________________________________
00424 void TGComboBox::RemoveEntry(Int_t id)
00425 {
00426    // Remove entry. If id == -1, the currently selected entry is removed
00427 
00428    fListBox->RemoveEntry(id);
00429 
00430    if (id < 0) {
00431       if (fSelEntry) {
00432          ((TGTextLBEntry*)fSelEntry)->SetTitle("");
00433          fClient->NeedRedraw(fSelEntry);
00434       } else {
00435          fTextEntry->SetTitle("");
00436          fClient->NeedRedraw(fTextEntry);
00437       }
00438    }
00439    Resize();
00440 }
00441 
00442 //______________________________________________________________________________
00443 void TGComboBox::Layout()
00444 {
00445    // layout combobox
00446 
00447    TGCompositeFrame::Layout();
00448    UInt_t h = fListBox->GetNumberOfEntries()*fListBox->GetItemVsize();
00449 
00450    if (h && (h < 100)) {
00451       fListBox->Resize(fListBox->GetWidth(), h);
00452    }
00453 }
00454 
00455 //______________________________________________________________________________
00456 Bool_t TGComboBox::HandleDoubleClick(Event_t *event)
00457 {
00458    // Handle double click in text entry.
00459 
00460    return fTextEntry ? fTextEntry->HandleDoubleClick(event) : kTRUE;
00461 }
00462 
00463 //______________________________________________________________________________
00464 Bool_t TGComboBox::HandleMotion(Event_t *event)
00465 {
00466    // Handle pointer motion in text entry.
00467 
00468    return fTextEntry ? fTextEntry->HandleMotion(event) : kTRUE;
00469 }
00470 
00471 //______________________________________________________________________________
00472 Bool_t TGComboBox::HandleSelection(Event_t *event)
00473 {
00474    // Handle selection in text entry.
00475 
00476    return fTextEntry ? fTextEntry->HandleSelection(event) : kTRUE;
00477 }
00478 
00479 //______________________________________________________________________________
00480 Bool_t TGComboBox::HandleSelectionRequest(Event_t *event)
00481 {
00482    // Handle selection request in text entry.
00483 
00484    return fTextEntry ? fTextEntry->HandleSelectionRequest(event) : kTRUE;
00485 }
00486 
00487 //______________________________________________________________________________
00488 Bool_t TGComboBox::ProcessMessage(Long_t msg, Long_t, Long_t parm2)
00489 {
00490    // Process messages generated by the listbox and forward
00491    // messages to the combobox message handling window. Parm2 contains
00492    // the id of the selected listbox entry.
00493 
00494    TGLBEntry *e;
00495 
00496    switch (GET_MSG(msg)) {
00497       case kC_COMMAND:
00498          switch (GET_SUBMSG(msg)) {
00499             case kCM_LISTBOX:
00500                e = fListBox->GetSelectedEntry();
00501                if (fSelEntry) {
00502                   fSelEntry->Update(e);
00503                } else if (fTextEntry &&
00504                           e->InheritsFrom(TGTextLBEntry::Class())) {
00505                   TGTextLBEntry *te = (TGTextLBEntry*)e;
00506                   fTextEntry->SetText(te->GetText()->GetString());
00507                }
00508                GetLayoutManager()->Layout();
00509                fComboFrame->EndPopup();
00510                fDDButton->SetState(kButtonUp);
00511                SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_COMBOBOX),
00512                            fWidgetId, parm2);
00513                if (e->InheritsFrom(TGTextLBEntry::Class())) {
00514                   const char *text;
00515                   text = ((TGTextLBEntry*)e)->GetText()->GetString();
00516                   Selected(text);
00517                }
00518                Selected(fWidgetId, (Int_t)parm2);
00519                Selected((Int_t)parm2);
00520                fClient->NeedRedraw(this);
00521                break;
00522          }
00523          break;
00524 
00525       default:
00526          break;
00527    }
00528    return kTRUE;
00529 }
00530 
00531 //______________________________________________________________________________
00532 void TGComboBox::Selected(Int_t widgetId, Int_t id)
00533 {
00534    // Emit signal.
00535 
00536    Long_t args[2];
00537 
00538    args[0] = widgetId;
00539    args[1] = id;
00540 
00541    Emit("Selected(Int_t,Int_t)", args);
00542 }
00543 
00544 //______________________________________________________________________________
00545 void TGComboBox::SetEnabled(Bool_t on)
00546 {
00547    // Set state of combo box. If kTRUE=enabled, kFALSE=disabled.
00548 
00549    fDDButton->SetEnabled(on);
00550    if (on) {
00551       SetFlags(kWidgetIsEnabled);
00552       fSelEntry->SetBackgroundColor(GetBackground());
00553    } else {
00554       ClearFlags(kWidgetIsEnabled);
00555       fSelEntry->SetBackgroundColor(GetDefaultFrameBackground());
00556    }
00557    fClient->NeedRedraw(fSelEntry);
00558 }
00559 
00560 //______________________________________________________________________________
00561 void TGComboBox::ReturnPressed()
00562 {
00563    // Add new entry to combo box when return key pressed inside text entry
00564    // ReturnPressed signal is emitted.
00565 
00566    if (!fTextEntry) return;
00567 
00568    TGLBContainer *lbc = (TGLBContainer *)fListBox->GetContainer();
00569    TString text = fTextEntry->GetText();
00570 
00571    TIter next(lbc->GetList());
00572    TGFrameElement *el;
00573 
00574    Emit("ReturnPressed()");
00575 
00576    while ((el = (TGFrameElement *)next())) {
00577       TGTextLBEntry *lbe = (TGTextLBEntry *)el->fFrame;
00578       if (lbe->GetText()->GetString() == text) {
00579          return;
00580       }
00581    }
00582 
00583    Int_t nn = GetNumberOfEntries() + 1;
00584    AddEntry(text.Data(), nn);
00585    Select(nn);
00586 }
00587 
00588 //______________________________________________________________________________
00589 void TGComboBox::RemoveAll()
00590 {
00591    // Remove all entries from combo box.
00592 
00593    fListBox->RemoveAll();
00594 
00595    if (fSelEntry) {
00596       ((TGTextLBEntry*)fSelEntry)->SetTitle("");
00597       fClient->NeedRedraw(fSelEntry);
00598    } else {
00599       fTextEntry->SetTitle("");
00600       fClient->NeedRedraw(fTextEntry);
00601    }
00602 }
00603 
00604 //______________________________________________________________________________
00605 void TGComboBox::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
00606 {
00607    // Save a combo box widget as a C++ statement(s) on output stream out.
00608 
00609    if (fBackground != GetDefaultFrameBackground()) SaveUserColor(out, option);
00610 
00611    out << endl << "   // combo box" << endl;
00612    out << "   TGComboBox *";
00613 
00614    if (!fTextEntry) {
00615       out << GetName() << " = new TGComboBox(" << fParent->GetName() << "," << fWidgetId;
00616    } else {
00617       out << GetName() << " = new TGComboBox(" << fParent->GetName() << ",";
00618       out << '\"' <<  fTextEntry->GetText() << '\"' << "," <<fWidgetId;
00619    }
00620 
00621    if (fBackground == GetWhitePixel()) {
00622       if (GetOptions() == (kHorizontalFrame | kSunkenFrame | kDoubleBorder)) {
00623          out <<");" << endl;
00624       } else {
00625          out << "," << GetOptionString() << ");" << endl;
00626       }
00627    } else {
00628       out << "," << GetOptionString() << ",ucolor);" << endl;
00629    }
00630    if (option && strstr(option, "keep_names"))
00631       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00632 
00633    TGTextLBEntry *b;
00634    TGFrameElement *el;
00635    TGListBox *lb = GetListBox();
00636 
00637    TIter next(((TGLBContainer *)lb->GetContainer())->GetList());
00638 
00639    while ((el = (TGFrameElement *) next())) {
00640       b = (TGTextLBEntry *) el->fFrame;
00641       out << "   " << GetName() << "->AddEntry(";
00642       b->SavePrimitive(out, option);
00643       out <<  ");" << endl;
00644    }
00645 
00646    out << "   " << GetName() << "->Resize(" << GetWidth()  << ","
00647        << GetHeight() << ");" << endl;
00648    out << "   " << GetName() << "->Select(" << GetSelected() << ");" << endl;
00649 }
00650 
00651 //______________________________________________________________________________
00652 TGLineStyleComboBox::TGLineStyleComboBox(const TGWindow *p, Int_t id,
00653                                          UInt_t options, Pixel_t back)
00654    : TGComboBox(p, id, options, back)
00655 {
00656    // Create a line style combo box.
00657 
00658    SetTopEntry(new TGLineLBEntry(this, 0),
00659                new TGLayoutHints(kLHintsLeft | kLHintsExpandY | kLHintsExpandX));
00660    fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
00661 
00662    for (Int_t i = 1; i <= 10; i++)
00663       AddEntry(new TGLineLBEntry(GetListBox()->GetContainer(), i,
00664                TString::Format("%d",i), 0, i),
00665                new TGLayoutHints(kLHintsTop | kLHintsExpandX));
00666 
00667    Select(1, kFALSE);  // to have first entry selected
00668 
00669    SetWindowName();
00670 }
00671 
00672 //______________________________________________________________________________
00673 void TGLineStyleComboBox::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
00674 {
00675    // Save a line style combo box widget as a C++ statement(s).
00676 
00677    out << endl << "   // line style combo box" << endl;
00678    out << "   TGLineStyleComboBox *";
00679 
00680    out << GetName() << " = new TGLineStyleComboBox(" << fParent->GetName()
00681        << "," << fWidgetId << ");" << endl;
00682    if (option && strstr(option, "keep_names"))
00683       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00684    out << "   " << GetName() << "->Resize(" << GetWidth()  << ","
00685        << GetHeight() << ");" << endl;
00686    out << "   " << GetName() << "->Select(" << GetSelected() << ");" << endl;
00687 }
00688 
00689 //______________________________________________________________________________
00690 TGLineWidthComboBox::TGLineWidthComboBox(const TGWindow *p, Int_t id,
00691                                          UInt_t options, Pixel_t back, Bool_t none)
00692    : TGComboBox(p, id, options, back)
00693 {
00694    // Create a line width combo box.
00695    // If "none" is equal to kTRUE the first entry is "None".
00696 
00697    SetTopEntry(new TGLineLBEntry(this,0),
00698                new TGLayoutHints(kLHintsLeft | kLHintsExpandY | kLHintsExpandX));
00699    fSelEntry->ChangeOptions(fSelEntry->GetOptions() | kOwnBackground);
00700 
00701    if (none) {
00702       AddEntry(new TGLineLBEntry(GetListBox()->GetContainer(), 0, "None", 0, 0),
00703                new TGLayoutHints(kLHintsTop | kLHintsExpandX));
00704    }
00705 
00706    for (Int_t i = 1; i < 16; i++)
00707       AddEntry(new TGLineLBEntry(GetListBox()->GetContainer(), i,
00708                TString::Format("%d",i), i, 0),
00709                new TGLayoutHints(kLHintsTop | kLHintsExpandX));
00710    Select(1, kFALSE);  // to have first entry selected
00711    SetWindowName();
00712 }
00713 
00714 //______________________________________________________________________________
00715 void TGLineWidthComboBox::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
00716 {
00717    // Save a line width combo box widget as a C++ statement(s).
00718 
00719    out << endl << "   // line width combo box" << endl;
00720    out << "   TGLineWidthComboBox *";
00721 
00722    out << GetName() << " = new TGLineWidthComboBox(" << fParent->GetName()
00723        << "," << fWidgetId << ");" << endl;
00724    if (option && strstr(option, "keep_names"))
00725       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00726    out << "   " << GetName() << "->Resize(" << GetWidth()  << ","
00727        << GetHeight() << ");" << endl;
00728    out << "   " << GetName() << "->Select(" << GetSelected() << ");" << endl;
00729 }
00730 
00731 static const char *gFonts[][2] = {    //   unix name,     name
00732    { "",                                           ""                         }, //not used
00733    { "-*-times-medium-i-*-*-12-*-*-*-*-*-*-*",     "1. times italic"          },
00734    { "-*-times-bold-r-*-*-12-*-*-*-*-*-*-*",       "2. times bold"            },
00735    { "-*-times-bold-i-*-*-12-*-*-*-*-*-*-*",       "3. times bold italic"     },
00736    { "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*", "4. helvetica"             },
00737    { "-*-helvetica-medium-o-*-*-12-*-*-*-*-*-*-*", "5. helvetica italic"      },
00738    { "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*",   "6. helvetica bold"        },
00739    { "-*-helvetica-bold-o-*-*-12-*-*-*-*-*-*-*",   "7. helvetica bold italic" },
00740    { "-*-courier-medium-r-*-*-12-*-*-*-*-*-*-*",   "8. courier"               },
00741    { "-*-courier-medium-o-*-*-12-*-*-*-*-*-*-*",   "9. courier italic"        },
00742    { "-*-courier-bold-r-*-*-12-*-*-*-*-*-*-*",     "10. courier bold"         },
00743    { "-*-courier-bold-o-*-*-12-*-*-*-*-*-*-*",     "11. courier bold italic"  },
00744    { "-*-symbol-medium-r-*-*-12-*-*-*-*-*-*-*",    "12. symbol"               },
00745    { "-*-times-medium-r-*-*-12-*-*-*-*-*-*-*",     "13. times"                },
00746    { 0, 0}
00747 };
00748 
00749 //______________________________________________________________________________
00750 TGFontTypeComboBox::TGFontTypeComboBox(const TGWindow *p, Int_t id,
00751                                        UInt_t options, Pixel_t back) :
00752    TGComboBox(p, id, options, back)
00753 {
00754    // Create a text font combo box.
00755 
00756    Int_t noFonts = 0;
00757 
00758    for (Int_t i = 1; gFonts[i][0] != 0 && noFonts < kMaxFonts; i++) {
00759 
00760       fFonts[noFonts] = gVirtualX->LoadQueryFont(gFonts[i][0]);
00761 
00762       if (fFonts[noFonts] == 0)
00763          fFonts[noFonts] = TGTextLBEntry::GetDefaultFontStruct();
00764 
00765       GCValues_t gval;
00766       gval.fMask = kGCFont;
00767       gval.fFont = gVirtualX->GetFontHandle(fFonts[noFonts]);
00768 
00769       AddEntry(new TGTextLBEntry(GetListBox()->GetContainer(),
00770                new TGString(gFonts[i][1]), i,
00771                fClient->GetGC(&gval, kTRUE)->GetGC(), fFonts[noFonts]),
00772                new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX));
00773       noFonts++;
00774    }
00775 
00776    if (noFonts < kMaxFonts - 1)
00777       fFonts[noFonts] = 0;
00778 
00779    Select(1, kFALSE);  // to have first entry selected
00780    SetWindowName();
00781 }
00782 
00783 //______________________________________________________________________________
00784 TGFontTypeComboBox::~TGFontTypeComboBox()
00785 {
00786    // Text font combo box dtor.
00787 
00788    for (int i = 0; i < kMaxFonts && fFonts[i] != 0; i++) {
00789       if (fFonts[i] != TGTextLBEntry::GetDefaultFontStruct()) gVirtualX->DeleteFont(fFonts[i]);
00790    }
00791 }

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