TGFontDialog.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGFontDialog.cxx 34656 2010-07-29 14:08:32Z bellenot $
00002 // Author: Bertrand Bellenot + Fons Rademakers + Valeriy Onuchin  23/04/03
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, 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 #include "TGFontDialog.h"
00024 #include "TString.h"
00025 #include "TError.h"
00026 #include "TGColorSelect.h"
00027 #include "TGButton.h"
00028 #include "TGLabel.h"
00029 #include "TGListBox.h"
00030 #include "TGComboBox.h"
00031 #include <stdlib.h>
00032 
00033 
00034 
00035 enum EFontDialog {
00036    kFDLG_OK          = 1,
00037    kFDLG_CANCEL,
00038 
00039    kFDLG_FONTNAMES   = 21,
00040    kFDLG_FONTSIZES,
00041    kFDLG_FONTSTYLES,
00042    kFDLG_FONTALIGNS,
00043 
00044    kFDLG_COLORSEL    = 31
00045 };
00046 
00047 static const char *gFDLG_DEFAULTSAMPLE = "AaBbCcYyZz 1234567890";
00048 
00049 
00050 static const char *gFontSizes[] = {
00051     "8",  "9", "10", "11", "12", "13", "14", "16",
00052    "18", "20", "22", "24", "26", "28", "30", "32",
00053    "34", "36", "48", "72", 0
00054 };
00055 
00056 static const char *gFontStyles[] = {
00057    "Normal", "Bold", "Italic", "Bold Italic", 0
00058 };
00059 
00060 static TString gFontStylesReal[4];
00061 
00062 
00063 static const char *gAlignTypes[] = {
00064     "top left", "top center", "top right",
00065     "middle left", "middle center", "middle right",
00066     "bottom left", "bottom center", "bottom right",
00067     0
00068 };
00069 
00070 static const Int_t gAlignValues[] = {
00071     kTextTop     | kTextLeft,
00072     kTextTop     | kTextCenterX,
00073     kTextTop     | kTextRight,
00074     kTextCenterY | kTextLeft,
00075     kTextCenterY | kTextCenterX,
00076     kTextCenterY | kTextRight,
00077     kTextBottom  | kTextLeft,
00078     kTextBottom  | kTextCenterX,
00079     kTextBottom  | kTextRight,
00080     0
00081 };
00082 
00083 /*
00084 static const char *gFontList[] = {
00085    "Arial",
00086    "Comic Sans MS",
00087    "Courier New",
00088    "Georgia",
00089    "Impact",
00090    "Monotype",
00091    "Symbol",
00092    "Times New Roman",
00093    "Trebuchet MS",
00094    "Verdana",
00095    "Webdings",
00096    "Wingdings",
00097    0,
00098 };
00099 
00100 static const char *gFontList2[] = {
00101    "FreeSans",
00102    "FreeSerif",
00103    "FreeMono",
00104    "OpenSymbol",
00105    0
00106 };
00107 */
00108 
00109 //_____________________________________________________________________________
00110 //
00111 // TGFontDialog
00112 //
00113 // Font selection dialog, allowing to select one in the list of available fonts
00114 // in the system.
00115 //_____________________________________________________________________________
00116 
00117 ClassImp(TGFontDialog)
00118 
00119 //________________________________________________________________________________
00120 TGFontDialog::TGFontDialog(const TGWindow *p, const TGWindow *t,
00121                            FontProp_t *fontProp, const TString &sample,
00122                            char **fontList, Bool_t wait) :
00123               TGTransientFrame(p, t, 100, 100)
00124 {
00125    // Create font dialog. When closed via OK button fontProp is set to
00126    // the newly selected font. If closed via Cancel button or WM close box
00127    // fontProp->fName == "".
00128 
00129    TGLabel *lbl;
00130    TGHorizontalFrame *hf, *hf2;
00131    TGVerticalFrame *vf;
00132    Int_t i, w;
00133    UInt_t width = 0, height = 0;
00134 
00135    fSampleTextGC = 0;
00136    fLabelFont    = 0;
00137    fSample       = 0;
00138    fHitOK        = kFALSE;
00139    fWaitFor      = wait;
00140    fInitFont     = 0;
00141    fInitColor    = 0;
00142    fInitAlign    = 0;
00143 
00144    if (!fontProp) {
00145       Error("TGFontDialog", "fontProp argument may not be 0");
00146       return;
00147    }
00148    SetCleanup(kDeepCleanup);
00149 
00150    TGLayoutHints *lh1 = new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
00151    TGLayoutHints *lh2 = new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 0, 2, 2);
00152 
00153    fFontProp = fontProp;
00154    if (fontProp->fName == "") {
00155       fName      = fontList ? fontList[0] : "Arial";
00156       fItalic    = kFALSE;
00157       fBold      = kFALSE;
00158       fSize      = 12;
00159       fTextAlign = gAlignValues[6];   //kTextBottom  | kTextLeft
00160       fTextColor = TGFrame::GetBlackPixel();
00161    } else {
00162       fName      = fontProp->fName;
00163       fItalic    = fontProp->fItalic;
00164       fBold      = fontProp->fBold;
00165       fSize      = fontProp->fSize;
00166       fTextAlign = fontProp->fAlign;
00167       fTextColor = fontProp->fColor;
00168    }
00169 
00170    hf = new TGHorizontalFrame(this, 10, 10);
00171    AddFrame(hf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));
00172 
00173    //--------------------- font names listbox
00174 
00175    vf = new TGVerticalFrame(hf, 10, 10);
00176 
00177    lbl = new TGLabel(vf, new TGString("Font:"));
00178    vf->AddFrame(lbl, lh2);
00179 
00180    fFontNames = new TGListBox(vf, kFDLG_FONTNAMES);
00181    fFontNames->Resize(120, fFontNames->GetDefaultHeight());
00182 
00183    if (gVirtualX->InheritsFrom("TGX11")) {
00184       fFontNames->Connect("Selected(char*)", "TGFontDialog", this, "UpdateStyleSize(char*)");
00185    }
00186    fFontNames->Associate(this);
00187    vf->AddFrame(fFontNames,  new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00188 
00189    hf->AddFrame(vf, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY,
00190                                       0, 10, 2, 2));
00191 
00192    //--------------------- font styles listbox
00193 
00194    vf = new TGVerticalFrame(hf, 10, 10);
00195 
00196    lbl = new TGLabel(vf, new TGString("Style:"));
00197    vf->AddFrame(lbl, lh2);
00198 
00199    fFontStyles = new TGListBox(vf, kFDLG_FONTSTYLES);
00200    fFontStyles->Resize(80, fFontStyles->GetDefaultHeight());
00201    fFontStyles->Associate(this);
00202    vf->AddFrame(fFontStyles, lh1);
00203 
00204    hf->AddFrame(vf, new TGLayoutHints(kLHintsLeft | kLHintsExpandY,
00205                                       0, 10, 2, 2));
00206 
00207    //--------------------- font sizes listbox
00208 
00209    vf = new TGVerticalFrame(hf, 10, 10);
00210 
00211    lbl = new TGLabel(vf, new TGString("Size:"));
00212    vf->AddFrame(lbl, lh2);
00213 
00214    fFontSizes = new TGListBox(vf, kFDLG_FONTSIZES);
00215    fFontSizes->Resize(50, fFontSizes->GetDefaultHeight());
00216    fFontSizes->Associate(this);
00217    vf->AddFrame(fFontSizes, lh1);
00218 
00219    hf->AddFrame(vf, new TGLayoutHints(kLHintsLeft | kLHintsExpandY,
00220                                       0, 0, 2, 2));
00221 
00222    //--------------------- Text align and color
00223 
00224    vf = new TGVerticalFrame(hf, 10, 10, kFixedWidth);
00225 
00226    lbl = new TGLabel(vf, new TGString("Text Align :"));
00227    vf->AddFrame(lbl, new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5));
00228 
00229    fTextAligns = new TGComboBox(vf, kFDLG_FONTALIGNS);
00230    fTextAligns->Associate(this);
00231    vf->AddFrame(fTextAligns, new TGLayoutHints(kLHintsCenterX | kLHintsTop |
00232                                                kLHintsExpandX, 5, 5, 0, 5));
00233 
00234    fTextAligns->Resize(110,20);
00235 
00236    vf->Layout();
00237    vf->Resize(120,vf->GetDefaultHeight());
00238 
00239    w = hf->GetDefaultWidth();
00240 
00241    hf2 = new TGHorizontalFrame(vf, 10, 10);
00242    vf->AddFrame(hf2, new TGLayoutHints(kLHintsNormal, 0, 0, 5, 5));
00243 
00244    lbl = new TGLabel(hf2, new TGString("Text Color"));
00245    hf2->AddFrame(lbl, new TGLayoutHints(kLHintsLeft, 5, 5, 20, 5));
00246 
00247    fColorSelect = new TGColorSelect(hf2, fTextColor, kFDLG_COLORSEL);
00248    fColorSelect->Associate(this);
00249 
00250    hf2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsRight | kLHintsTop, 5, 5, 20, 5));
00251 
00252    vf->Resize(vf->GetDefaultSize());
00253 
00254    hf->AddFrame(vf, new TGLayoutHints(kLHintsLeft | kLHintsExpandY | kLHintsTop,
00255                                       10, 0, lbl->GetDefaultHeight()+6, 0));
00256 
00257    //--------------------- initialize controls
00258 
00259    Resize(GetDefaultSize());
00260 
00261    Int_t cnt = 0;
00262    Bool_t own = kFALSE;
00263 
00264    if (!fontList) {
00265       fontList = gVirtualX->ListFonts("-*-*-*-*", 10000, cnt);
00266       own = kTRUE;
00267    }
00268 
00269    Build(fontList, cnt);
00270 
00271    for (i = 0; gAlignTypes[i] != 0; ++i) {
00272       fTextAligns->AddEntry(new TGString(gAlignTypes[i]), i);
00273    }
00274 
00275    for (i = 0; gAlignValues[i] != 0; ++i) {
00276       if (gAlignValues[i] == fTextAlign) {
00277          fTextAligns->Select(i);
00278       }
00279    }
00280 
00281    //--------------------- sample box
00282 
00283    hf = new TGHorizontalFrame(this, 10, 10);
00284    AddFrame(hf, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 5, 5, 5, 5));
00285 
00286    TGGroupFrame *gf = new TGGroupFrame(hf, new TGString("Sample"), kFixedSize);
00287    hf->AddFrame(gf, new TGLayoutHints(kLHintsNormal, 3, 3, 3, 3));
00288 
00289    TGCompositeFrame *cf = new TGCompositeFrame(gf, 200, 100, kSunkenFrame);
00290    gf->AddFrame(cf, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY |
00291                                       kLHintsExpandX | kLHintsExpandY,
00292                                       1, 1, 3, 1));
00293 
00294    if (sample == "")
00295       fSampleText = gFDLG_DEFAULTSAMPLE;
00296    else
00297       fSampleText = sample;
00298 
00299    for (i = 0; gFontSizes[i] != 0; ++i) {
00300       if (fSize == atoi(gFontSizes[i])) {
00301          fFontSizes->Select(i);
00302          break;
00303       }
00304    }
00305 
00306    if ((fBold == kFALSE) && (fItalic == kFALSE))
00307       fFontStyles->Select(0);
00308    if ((fBold == kTRUE) && (fItalic == kFALSE))
00309       fFontStyles->Select(1);
00310    if ((fBold == kFALSE) && (fItalic == kTRUE))
00311       fFontStyles->Select(2);
00312    if ((fBold == kTRUE) && (fItalic == kTRUE))
00313       fFontStyles->Select(3);
00314 
00315    GetFontName();   //sets fLName and other data members
00316 
00317    GCValues_t gcval;
00318    gcval.fMask = kGCForeground | kGCFont;
00319    gcval.fForeground = fTextColor;
00320    gcval.fFont = fLabelFont->GetFontHandle();
00321    fSampleTextGC = fClient->GetGC(&gcval, kTRUE);
00322    fSample = new TGLabel(cf, fSampleText); //, (*fSampleTextGC)(), (*fLabelFont)());
00323    fSample->SetTextJustify(gAlignValues[fTextAligns->GetSelected()]);
00324    cf->AddFrame(fSample, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY |
00325                                            kLHintsExpandX | kLHintsExpandY,
00326                                            1, 1, 1, 1));
00327    cf->Layout();
00328    if (own) gVirtualX->FreeFontNames(fontList);
00329 
00330    gf->Resize(w, 80);
00331 
00332    //--------------------- OK and Cancel buttons
00333 
00334    vf = new TGVerticalFrame(hf, 10, 10, kFixedWidth);
00335 
00336    TGTextButton *ok = new TGTextButton(vf, new TGHotString("&OK"), kFDLG_OK);
00337    ok->Associate(this);
00338    vf->AddFrame(ok, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 20, 5));
00339 
00340    TGTextButton *cancel = new TGTextButton(vf, new TGHotString("&Cancel"), kFDLG_CANCEL);
00341    cancel->Associate(this);
00342    vf->AddFrame(cancel, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5));
00343 
00344    vf->Resize(cancel->GetDefaultWidth()+70, vf->GetDefaultHeight());
00345 
00346    hf->AddFrame(vf, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 5, 5, 5, 5));
00347    SetEditDisabled(kEditDisable);
00348 
00349    fInitAlign = fTextAlign;
00350    fInitColor = fTextColor;
00351    fInitFont = fLabelFont;
00352 
00353    fFontNames->GetScrollBar()->SetPosition(fFontNames->GetSelected()-3);
00354    fFontSizes->GetScrollBar()->SetPosition(fFontSizes->GetSelected()-3);
00355    fFontSizes->Layout();
00356    fFontNames->Layout();
00357 
00358    SetWindowName("Font Selection");
00359    SetIconName("Font Selection");
00360    SetClassHints("FontDialog", "FontDialog");
00361 
00362    SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
00363                               kMWMDecorMinimize | kMWMDecorMenu,
00364                kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize |
00365                               kMWMFuncMinimize,
00366                kMWMInputModeless);
00367 
00368    //---- set minimum size to the dialog box
00369    width  = GetDefaultWidth();
00370    height = GetDefaultHeight();
00371    MapSubwindows();
00372    Resize(width, height);
00373 
00374    //---- position the dialog relative to the parent's window
00375    CenterOnParent();
00376 
00377    // set minimum size
00378    SetWMSize(width, height);
00379    SetWMSizeHints(width, height, 10000, 10000, 0, 0);
00380 
00381    if (fWaitFor) {
00382       MapWindow();
00383       fClient->WaitForUnmap(this);
00384       DeleteWindow();
00385    }
00386 }
00387 
00388 //________________________________________________________________________________
00389 TGFontDialog::~TGFontDialog()
00390 {
00391    // Delete all widgets.
00392 
00393    //fClient->FreeFont(fLabelFont);
00394    fClient->FreeGC(fSampleTextGC);
00395 }
00396 
00397 //________________________________________________________________________________
00398 void TGFontDialog::CloseWindow()
00399 {
00400    // Called when window is closed via window manager.
00401 
00402    if (fWaitFor) {
00403       UnmapWindow();
00404       return;
00405    }
00406 
00407    if (!fHitOK) {
00408       fFontProp->fName = "";
00409 
00410       if (fInitFont) {
00411          SetFont(fInitFont);
00412          FontSelected((char*)fInitFont->GetName());
00413       }
00414       if (fInitColor) {
00415          SetColor(fInitColor);
00416          ColorSelected(fInitColor);
00417       }
00418 
00419       if (fInitAlign) {
00420          SetAlign(fInitAlign);
00421          AlignSelected(fInitAlign);
00422       }
00423    }
00424    fFontNames->Select(0);
00425    fFontStyles->Select(0);
00426    fFontSizes->Select(0);
00427 
00428    // don't call DeleteWindow() here since that will cause access
00429    // to the deleted dialog in the WaitFor() method (see ctor)
00430    UnmapWindow();
00431 }
00432 
00433 //________________________________________________________________________________
00434 Bool_t TGFontDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
00435 {
00436    // Handle dialog events.
00437 
00438    switch (GET_MSG(msg)) {
00439       case kC_COMMAND:
00440          switch (GET_SUBMSG(msg)) {
00441             case kCM_BUTTON:
00442                switch (parm1) {
00443 
00444                   case kFDLG_OK:
00445                      fHitOK             = kTRUE;
00446                      fFontProp->fName   = fName;
00447                      fFontProp->fItalic = fItalic;
00448                      fFontProp->fBold   = fBold;
00449                      fFontProp->fSize   = fSize;
00450                      fFontProp->fColor  = fTextColor;
00451                      fFontProp->fAlign  = fTextAlign;
00452                      CloseWindow();
00453                      break;
00454                   case kFDLG_CANCEL:
00455                      fHitOK = kFALSE;
00456                      CloseWindow();
00457                      break;
00458                }
00459                break;
00460 
00461             case kCM_LISTBOX:
00462                GetFontName();
00463                break;
00464 
00465             case kCM_COMBOBOX:
00466                GetFontName();
00467                break;
00468 
00469             default:
00470                break;
00471          }
00472          break;
00473 
00474       case kC_COLORSEL:
00475          switch (GET_SUBMSG(msg)) {
00476 
00477             case kCOL_SELCHANGED:
00478                {
00479                   if (parm2 != (Int_t)fTextColor) {
00480                      fTextColor = parm2;
00481                      GetFontName();
00482                   }
00483                }
00484                break;
00485 
00486             default:
00487                break;
00488          }
00489          break;
00490 
00491       default:
00492          break;
00493    }
00494    return kTRUE;
00495 }
00496 
00497 //________________________________________________________________________________
00498 Bool_t TGFontDialog::Build(char **fontList, Int_t cnt)
00499 {
00500    // Build font dialog.
00501 
00502    TString family;
00503    TString font;
00504 
00505    Int_t  i;
00506    fNumberOfFonts = 1;
00507    Int_t n1, n2;
00508 
00509    for (i = 0; i < cnt; i++) {
00510       font = fontList[i];
00511       n1 = font.Index("-", 1);
00512       n2 = font.Index("-", n1+1);
00513       family = font(n1+1, n2-n1-1);
00514 
00515       if ((family.Length() == 0) || (family.BeginsWith("@"))) {
00516          continue;
00517       }
00518 
00519       if (!fFontNames->FindEntry(family.Data())) {
00520          fFontNames->AddEntry(family.Data(), fNumberOfFonts++);
00521       }
00522    }
00523 
00524    fFontNames->SortByName();
00525 
00526    TGTextLBEntry *le = (TGTextLBEntry*)fFontNames->FindEntry(fName.Data());
00527 
00528    if (le) {
00529       fFontNames->Select(le->EntryId());
00530    }
00531 
00532    UpdateStyleSize(fName.Data());
00533 
00534    return kTRUE;
00535 }
00536 
00537 //________________________________________________________________________________
00538 void TGFontDialog::UpdateStyleSize(const char *family)
00539 {
00540    // Build font style and size list boxes
00541 
00542    if (!family) {
00543       return;
00544    }
00545 
00546    TString font = family;
00547    Bool_t styles[4] = { kFALSE, kFALSE, kFALSE, kFALSE };
00548    Int_t cnt = 0;
00549    Int_t i = 0;
00550 
00551    TString fname;
00552    char **fontList = 0;
00553 
00554    fname = TString::Format("-*-%s-*-*", family);
00555    fontList = gVirtualX->ListFonts(fname.Data(), 1000, cnt);
00556 
00557    fFontSizes->RemoveEntries(0, 1000);
00558    fFontSizes->Layout();
00559 
00560    fFontStyles->RemoveEntries(0, 100);
00561    fFontStyles->Layout();
00562 
00563    if (!cnt || !fontList) {
00564       return;
00565    }
00566 
00567    TString style1;
00568    TString style2;
00569    TString sz;
00570    TString name;
00571    Int_t n1, n2;
00572    Bool_t x11 = gVirtualX->InheritsFrom("TGX11");
00573    Bool_t all_sizes = !x11;
00574    Bool_t all_styles = !x11;
00575    int szn = 0;
00576 
00577    fFontSizes->AddEntry("12", szn++);
00578 
00579    for (i = 0; i < cnt; i++) {
00580       name = fontList[i];
00581       n1 = name.Index(family);
00582 
00583       if (n1 == kNPOS) {
00584          break;
00585       }
00586       n1 += font.Length() + 1;
00587       n2 = name.Index("-", n1);
00588       if (n2 == kNPOS) {
00589          break;
00590       }
00591 
00592       style1 = name(n1, n2 - n1);
00593 
00594       n1 = n2 + 1;
00595       n2 = name.Index("-", n1);
00596       if (n2 == kNPOS) {
00597          break;
00598       }
00599       style2 = name(n1, n2 - n1);
00600 
00601       if ((style1 == "normal") || (style1 == "medium")) {
00602          if (style2 == "r") {
00603             styles[0]  = kTRUE;
00604             gFontStylesReal[0] = style1 + "-" + style2;
00605          } else if (style2 == "i") {
00606             styles[2]  = kTRUE;
00607             gFontStylesReal[2] = style1 + "-" + style2;
00608          } else if (style2 == "o") {
00609             styles[2]  = kTRUE;
00610             gFontStylesReal[2] = style1 + "-" + style2;
00611          }
00612       } else if (style1 == "bold") {
00613          if (style2 == "r") {
00614             styles[1]  = kTRUE;
00615             gFontStylesReal[1] = style1 + "-" + style2;
00616          } else if (style2 == "i") {
00617             styles[3]  = kTRUE;
00618             gFontStylesReal[3] = style1 + "-" + style2;
00619          } else if (style2 == "o") {
00620             styles[3]  = kTRUE;
00621             gFontStylesReal[3] = style1 + "-" + style2;
00622          }
00623       } else if (style1 == "(null)") {
00624          styles[0]  = kTRUE;
00625          gFontStylesReal[0] = "normal-r";
00626          styles[1]  = kTRUE;
00627          gFontStylesReal[1] = "bold-r";
00628          styles[2]  = kTRUE;
00629          gFontStylesReal[2] = "normal-i";
00630          styles[3]  = kTRUE;
00631          gFontStylesReal[3] = "bold-i";
00632       }
00633 
00634       n1++;
00635       n2 = name.Index("-", n1);
00636       n1 = n2 + 1;
00637       n2 = name.Index("-", n1);
00638       n1 = n2 + 1;
00639 
00640       if (n2 != kNPOS) {
00641          n1 = n2 + 2;
00642          n2 = name.Index("-", n1);
00643          sz = name(n1, n2 - n1);
00644          if (!sz.IsDigit()) {
00645             continue;
00646          }
00647 
00648          all_sizes = (sz == "0") && !x11;
00649          if (!all_sizes) {
00650             sz.Strip();
00651             if (sz.Length() == 1) {
00652                sz = " " + sz;
00653             }
00654             if (!fFontSizes->FindEntry(sz.Data())) {
00655                fFontSizes->AddEntry(sz.Data(), szn++);
00656             }
00657          }
00658       }
00659    }
00660    gVirtualX->FreeFontNames(fontList);
00661 
00662    Bool_t nostyles = kTRUE;
00663    for (i = 0; gFontStyles[i] != 0; ++i) {
00664       if (all_styles || styles[i]) {
00665          nostyles = kFALSE;
00666          fFontStyles->AddEntry(new TGString(gFontStyles[i]), i);
00667       }
00668    }
00669 
00670    if (nostyles && x11) {
00671       fFontStyles->AddEntry(new TGString(gFontStyles[0]), 0);
00672       fBold = kFALSE;
00673       fItalic = kFALSE;
00674    }
00675 
00676    if (!fBold) {
00677       if (!fItalic) {
00678          fFontStyles->Select(0);
00679       } else {
00680          fFontStyles->Select(2);
00681       }
00682    } else {
00683       if (!fItalic) {
00684          fFontStyles->Select(1);
00685       } else {
00686          fFontStyles->Select(3);
00687       }
00688    }
00689 
00690 //   if (nostyles) {
00691 //      fFontNames->RemoveEntry(fFontNames->FindEntry(family)->EntryId());
00692 //   }
00693 
00694    fFontStyles->MapSubwindows();
00695    fFontStyles->Layout();
00696 //
00697 
00698    sz = TString::Format("%d", fSize);
00699    if (sz.Length() == 1) {
00700       sz = " " + sz;
00701    }
00702 
00703    for (i = 0; gFontSizes[i] != 0; ++i) {
00704       if (all_sizes && !fFontSizes->FindEntry(gFontSizes[i])) {
00705          fFontSizes->AddEntry(new TGString(gFontSizes[i]), i);
00706       }
00707       if (sz == gFontSizes[i]) {
00708          fFontSizes->Select(i);
00709       }
00710    }
00711 
00712    fFontSizes->SortByName();
00713    fFontSizes->MapSubwindows();
00714    fFontSizes->Layout();
00715 }
00716 
00717 //________________________________________________________________________________
00718 void TGFontDialog::GetFontName()
00719 {
00720    // Sets fLName and other data members.
00721 
00722    TGTextLBEntry *e;
00723    const char *size, *name;
00724    Int_t sel;
00725    Int_t sav = gErrorIgnoreLevel;
00726    gErrorIgnoreLevel = kFatal;
00727 
00728    TString oldName = fName;
00729    e = (TGTextLBEntry *) fFontNames->GetSelectedEntry();
00730 
00731    if (!e) {
00732       fFontNames->Select(1);
00733       e = (TGTextLBEntry *) fFontNames->GetSelectedEntry();
00734    }
00735    name = e ? e->GetText()->GetString() : "";
00736    fName = name;
00737 
00738    e = (TGTextLBEntry *) fFontSizes->GetSelectedEntry();
00739    size = e ? e->GetText()->GetString() : "0";
00740    fSize = atoi(size);
00741 
00742    sel = fFontStyles->GetSelected();
00743    if (sel < 0) sel = 0;
00744 
00745    switch(sel) {
00746       case 0:
00747          fItalic = kFALSE;
00748          fBold   = kFALSE;
00749          break;
00750       case 1:
00751          fItalic = kFALSE;
00752          fBold   = kTRUE;
00753          break;
00754       case 2:
00755          fItalic = kTRUE;
00756          fBold   = kFALSE;
00757          break;
00758       case 3:
00759          fItalic = kTRUE;
00760          fBold   = kTRUE;
00761          break;
00762       default:
00763          fItalic = kFALSE;
00764          fBold   = kFALSE;
00765          break;
00766    }
00767 
00768    const char *rgstry = "*";
00769 
00770    if ((fName == "Symbol") || (fName == "Webdings") || (fName == "Wingdings")) {
00771       rgstry = "microsoft";
00772    }
00773 
00774    TString oldFont = fLName;
00775    fLName = TString::Format("-*-%s-%s-*-*-%s-*-*-*-*-*-%s-*", name, 
00776                             gFontStylesReal[sel].Data(), size, rgstry);
00777 
00778    if (oldFont != fLName) {
00779       if (fLabelFont) {
00780          //fClient->FreeFont(fLabelFont);
00781          fLabelFont = fClient->GetFont(fLName, kFALSE);
00782 
00783          if (!fLabelFont) {
00784             fLabelFont = fClient->GetFont("fixed");
00785          }
00786       } else {
00787          fLabelFont = fClient->GetFont("fixed");
00788       }
00789 
00790       if (!fLabelFont) {
00791          // should not happen
00792          fLName = oldFont;
00793          goto out;
00794       }
00795 
00796       if (fSample) {
00797          fSample->SetTextFont(fLabelFont);
00798       }
00799    }
00800 
00801 out:
00802    Int_t oldAlign = fTextAlign;
00803 
00804    Int_t idx = fTextAligns->GetSelected();
00805    fTextAlign = gAlignValues[idx >= 0 ? idx : 6];
00806 
00807    if (fSample) {
00808       if (fTextAlign != oldAlign) {
00809          fSample->SetTextJustify(fTextAlign);
00810          AlignSelected(fTextAlign);
00811       }
00812       fSample->SetTextColor(fTextColor);
00813       fColorSelect->SetColor(fTextColor, kFALSE);
00814       ColorSelected(fTextColor);
00815    }
00816    FontSelected((char*)fLName.Data());
00817    fClient->NeedRedraw(this);
00818    gErrorIgnoreLevel = sav;
00819 }
00820 
00821 //________________________________________________________________________________
00822 void TGFontDialog::SetFont(TGFont *font)
00823 {
00824    // Set font
00825 
00826    if (!font) {
00827       return;
00828    }
00829    TString name = font->GetName();
00830 
00831    if (name.Index("-", 1) == kNPOS) {
00832       return;
00833    }
00834 
00835    if (fSample) {
00836       fLabelFont = font;
00837       fSample->SetTextFont(fLabelFont);
00838    }
00839    fInitFont = font;
00840 
00841    TString style1;
00842    TString style2;
00843    TString sz;
00844 
00845    TString family;
00846    Int_t n1, n2;
00847 
00848    n1 = name.Index("-", 1);
00849    n2 = name.Index("-", n1 + 1);
00850    n1++;
00851    family = name(n1, n2 - n1);
00852 
00853    TGTextLBEntry *le = (TGTextLBEntry*)fFontNames->FindEntry(family.Data());
00854 
00855    if (le) {
00856       fFontNames->Select(le->EntryId());
00857    }
00858 
00859    n1 = n2 + 1;
00860    n2 = name.Index("-", n1);
00861 
00862    style1 = name(n1, n2 - n1);
00863 
00864    n1 = n2 + 1;
00865    n2 = name.Index("-", n1);
00866    if (n2 == kNPOS) {
00867       return;
00868    }
00869    style2 = name(n1, n2 - n1);
00870 
00871    if ((style1 == "normal") || (style1 == "medium")) {
00872       if (style2 == "r") {
00873          fFontStyles->Select(0);
00874       } else if (style2 == "i") {
00875          fFontStyles->Select(2);
00876       } else if (style2 == "o") {
00877          fFontStyles->Select(2);
00878       }
00879    } else if (style1 == "bold") {
00880       if (style2 == "r") {
00881          fFontStyles->Select(1);
00882       } else if (style2 == "i") {
00883          fFontStyles->Select(3);
00884       } else if (style2 == "o") {
00885          fFontStyles->Select(3);
00886       }
00887    }
00888    n1++;
00889    n2 = name.Index("-", n1);
00890    n1 = n2 + 1;
00891    n2 = name.Index("-", n1);
00892    n1 = n2 + 1;
00893    n2 = name.Index("-", n1);
00894    n1 = n2 + 1;
00895    if (n2 != kNPOS) {
00896       n1 = n2 + 1;
00897       n2 = name.Index("-", n1);
00898       sz = name(n1, n2 - n1);
00899 
00900       le = (TGTextLBEntry*)fFontSizes->FindEntry(sz.Data());
00901       if (le) {
00902          fFontSizes->Select(le->EntryId());
00903       }
00904    }
00905 }
00906 
00907 //________________________________________________________________________________
00908 void TGFontDialog::SetColor(Pixel_t color)
00909 {
00910    // Set color
00911 
00912    if (fSample) {
00913       fTextColor = color;
00914       fSample->SetTextColor(fTextColor);
00915    }
00916    fColorSelect->SetColor(color, kFALSE);
00917    fClient->NeedRedraw(fColorSelect);
00918    fInitColor = color;
00919 }
00920 
00921 //________________________________________________________________________________
00922 void TGFontDialog::SetAlign(Int_t align)
00923 {
00924    // Set align
00925 
00926    if (fSample) {
00927       fTextAlign = align;
00928       fSample->SetTextJustify(fTextAlign);
00929    }
00930 
00931    for (int i = 0; gAlignValues[i] != 0; ++i) {
00932       if (gAlignValues[i] == align) {
00933          fTextAligns->Select(i);
00934       }
00935    }
00936    fInitAlign = align;
00937    fClient->NeedRedraw(fTextAligns);
00938 }
00939 
00940 //________________________________________________________________________________
00941 void TGFontDialog::EnableAlign(Bool_t on)
00942 {
00943    // Enable/disable align combobox
00944 
00945    fTextAligns->SetEnabled(on);
00946 }

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