47 static const char *gFDLG_DEFAULTSAMPLE = 
"AaBbCcYyZz 1234567890";
 
   50 static const char *gFontSizes[] = {
 
   51     "8",  
"9", 
"10", 
"11", 
"12", 
"13", 
"14", 
"16",
 
   52    "18", 
"20", 
"22", 
"24", 
"26", 
"28", 
"30", 
"32",
 
   53    "34", 
"36", 
"48", 
"72", 0
 
   56 static const char *gFontStyles[] = {
 
   57    "Normal", 
"Bold", 
"Italic", 
"Bold Italic", 0
 
   60 static TString gFontStylesReal[4];
 
   63 static const char *gAlignTypes[] = {
 
   64     "top left", 
"top center", 
"top right",
 
   65     "middle left", 
"middle center", 
"middle right",
 
   66     "bottom left", 
"bottom center", 
"bottom right",
 
   70 static const Int_t gAlignValues[] = {
 
   72     kTextTop     | kTextCenterX,
 
   73     kTextTop     | kTextRight,
 
   74     kTextCenterY | kTextLeft,
 
   75     kTextCenterY | kTextCenterX,
 
   76     kTextCenterY | kTextRight,
 
   77     kTextBottom  | kTextLeft,
 
   78     kTextBottom  | kTextCenterX,
 
   79     kTextBottom  | kTextRight,
 
  117 ClassImp(TGFontDialog);
 
  124 TGFontDialog::TGFontDialog(
const TGWindow *p, 
const TGWindow *t,
 
  125                            FontProp_t *fontProp, 
const TString &sample,
 
  126                            char **fontList, Bool_t wait) :
 
  127    TGTransientFrame(p, t, 100, 100), fFontNames(0), fFontSizes(0), fFontStyles(0),
 
  128    fTextAligns(0), fColorSelect(0), fFontProp(0), fItalic(0), fBold(0), fSize(0),
 
  129    fTextAlign(0), fTextColor(0), fNumberOfFonts(0)
 
  132    TGHorizontalFrame *hf, *hf2;
 
  135    UInt_t width = 0, height = 0;
 
  147       Error(
"TGFontDialog", 
"fontProp argument may not be 0");
 
  150    SetCleanup(kDeepCleanup);
 
  152    TGLayoutHints *lh1 = 
new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
 
  153    TGLayoutHints *lh2 = 
new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 0, 2, 2);
 
  155    fFontProp = fontProp;
 
  156    if (fontProp->fName == 
"") {
 
  157       fName      = fontList ? fontList[0] : 
"Arial";
 
  161       fTextAlign = gAlignValues[6];   
 
  162       fTextColor = TGFrame::GetBlackPixel();
 
  164       fName      = fontProp->fName;
 
  165       fItalic    = fontProp->fItalic;
 
  166       fBold      = fontProp->fBold;
 
  167       fSize      = fontProp->fSize;
 
  168       fTextAlign = fontProp->fAlign;
 
  169       fTextColor = fontProp->fColor;
 
  172    hf = 
new TGHorizontalFrame(
this, 10, 10);
 
  173    AddFrame(hf, 
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));
 
  177    vf = 
new TGVerticalFrame(hf, 10, 10);
 
  179    lbl = 
new TGLabel(vf, 
new TGString(
"Font:"));
 
  180    vf->AddFrame(lbl, lh2);
 
  182    fFontNames = 
new TGListBox(vf, kFDLG_FONTNAMES);
 
  183    fFontNames->Resize(120, fFontNames->GetDefaultHeight());
 
  185    if (gVirtualX->InheritsFrom(
"TGX11") || gVirtualX->InheritsFrom(
"TGCocoa")) {
 
  186       fFontNames->Connect(
"Selected(char*)", 
"TGFontDialog", 
this, 
"UpdateStyleSize(char*)");
 
  189    fFontNames->Associate(
this);
 
  190    vf->AddFrame(fFontNames,  
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
 
  192    hf->AddFrame(vf, 
new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY,
 
  197    vf = 
new TGVerticalFrame(hf, 10, 10);
 
  199    lbl = 
new TGLabel(vf, 
new TGString(
"Style:"));
 
  200    vf->AddFrame(lbl, lh2);
 
  202    fFontStyles = 
new TGListBox(vf, kFDLG_FONTSTYLES);
 
  203    fFontStyles->Resize(80, fFontStyles->GetDefaultHeight());
 
  204    fFontStyles->Associate(
this);
 
  205    vf->AddFrame(fFontStyles, lh1);
 
  207    hf->AddFrame(vf, 
new TGLayoutHints(kLHintsLeft | kLHintsExpandY,
 
  212    vf = 
new TGVerticalFrame(hf, 10, 10);
 
  214    lbl = 
new TGLabel(vf, 
new TGString(
"Size:"));
 
  215    vf->AddFrame(lbl, lh2);
 
  217    fFontSizes = 
new TGListBox(vf, kFDLG_FONTSIZES);
 
  218    fFontSizes->Resize(50, fFontSizes->GetDefaultHeight());
 
  219    fFontSizes->Associate(
this);
 
  220    vf->AddFrame(fFontSizes, lh1);
 
  222    hf->AddFrame(vf, 
new TGLayoutHints(kLHintsLeft | kLHintsExpandY,
 
  227    vf = 
new TGVerticalFrame(hf, 10, 10);
 
  229    lbl = 
new TGLabel(vf, 
new TGString(
"Text Align :"));
 
  230    vf->AddFrame(lbl, 
new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5));
 
  232    fTextAligns = 
new TGComboBox(vf, kFDLG_FONTALIGNS);
 
  233    fTextAligns->Associate(
this);
 
  234    vf->AddFrame(fTextAligns, 
new TGLayoutHints(kLHintsCenterX | kLHintsTop |
 
  235                                                kLHintsExpandX, 5, 5, 0, 5));
 
  237    fTextAligns->Resize(110, 20);
 
  240    vf->Resize(vf->GetDefaultSize());
 
  242    w = hf->GetDefaultWidth();
 
  244    hf2 = 
new TGHorizontalFrame(vf, 10, 10);
 
  245    vf->AddFrame(hf2, 
new TGLayoutHints(kLHintsNormal, 0, 0, 5, 5));
 
  247    lbl = 
new TGLabel(hf2, 
new TGString(
"Text Color"));
 
  248    hf2->AddFrame(lbl, 
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5, 5, 20, 5));
 
  250    fColorSelect = 
new TGColorSelect(hf2, fTextColor, kFDLG_COLORSEL);
 
  251    fColorSelect->Associate(
this);
 
  253    hf2->AddFrame(fColorSelect, 
new TGLayoutHints(kLHintsRight | kLHintsCenterY, 5, 5, 20, 5));
 
  255    vf->Resize(vf->GetDefaultSize());
 
  257    hf->AddFrame(vf, 
new TGLayoutHints(kLHintsLeft | kLHintsExpandY | kLHintsTop,
 
  258                                       10, 0, lbl->GetDefaultHeight()+6, 0));
 
  262    Resize(GetDefaultSize());
 
  268       fontList = gVirtualX->ListFonts(
"-*-*-*-*", 10000, cnt);
 
  272    Build(fontList, cnt);
 
  274    for (i = 0; gAlignTypes[i] != 0; ++i) {
 
  275       fTextAligns->AddEntry(
new TGString(gAlignTypes[i]), i);
 
  278    for (i = 0; gAlignValues[i] != 0; ++i) {
 
  279       if (gAlignValues[i] == fTextAlign) {
 
  280          fTextAligns->Select(i);
 
  284    TGLBEntry *entry = fTextAligns->FindEntry(
"bottom center");
 
  286       fTextAligns->Resize(entry->GetWidth() + 20, entry->GetHeight() > 20 ?
 
  287                           entry->GetHeight() : 20);
 
  290    vf->Resize(vf->GetDefaultSize());
 
  294    hf = 
new TGHorizontalFrame(
this, 10, 10);
 
  295    AddFrame(hf, 
new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 5, 5, 5, 5));
 
  297    TGGroupFrame *gf = 
new TGGroupFrame(hf, 
new TGString(
"Sample"));
 
  298    hf->AddFrame(gf, 
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3));
 
  300    TGCompositeFrame *cf = 
new TGCompositeFrame(gf, 200, 100, kSunkenFrame);
 
  301    gf->AddFrame(cf, 
new TGLayoutHints(kLHintsCenterX | kLHintsCenterY |
 
  302                                       kLHintsExpandX | kLHintsExpandY,
 
  306       fSampleText = gFDLG_DEFAULTSAMPLE;
 
  308       fSampleText = sample;
 
  310    for (i = 0; gFontSizes[i] != 0; ++i) {
 
  311       if (fSize == atoi(gFontSizes[i])) {
 
  312          fFontSizes->Select(i);
 
  317    if ((fBold == kFALSE) && (fItalic == kFALSE))
 
  318       fFontStyles->Select(0);
 
  319    if ((fBold == kTRUE) && (fItalic == kFALSE))
 
  320       fFontStyles->Select(1);
 
  321    if ((fBold == kFALSE) && (fItalic == kTRUE))
 
  322       fFontStyles->Select(2);
 
  323    if ((fBold == kTRUE) && (fItalic == kTRUE))
 
  324       fFontStyles->Select(3);
 
  329    gcval.fMask = kGCForeground | kGCFont;
 
  330    gcval.fForeground = fTextColor;
 
  331    gcval.fFont = fLabelFont->GetFontHandle();
 
  332    fSampleTextGC = fClient->GetGC(&gcval, kTRUE);
 
  333    fSample = 
new TGLabel(cf, fSampleText); 
 
  334    fSample->SetTextJustify(gAlignValues[fTextAligns->GetSelected()]);
 
  335    cf->AddFrame(fSample, 
new TGLayoutHints(kLHintsCenterX | kLHintsCenterY |
 
  336                                            kLHintsExpandX | kLHintsExpandY,
 
  339    if (own) gVirtualX->FreeFontNames(fontList);
 
  345    vf = 
new TGVerticalFrame(hf, 10, 10, kFixedWidth);
 
  347    TGTextButton *ok = 
new TGTextButton(vf, 
new TGHotString(
"&OK"), kFDLG_OK);
 
  349    vf->AddFrame(ok, 
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 20, 5));
 
  351    TGTextButton *cancel = 
new TGTextButton(vf, 
new TGHotString(
"&Cancel"), kFDLG_CANCEL);
 
  352    cancel->Associate(
this);
 
  353    vf->AddFrame(cancel, 
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5));
 
  355    vf->Resize(cancel->GetDefaultWidth()+70, vf->GetDefaultHeight());
 
  357    hf->AddFrame(vf, 
new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
 
  358    SetEditDisabled(kEditDisable);
 
  360    fInitAlign = fTextAlign;
 
  361    fInitColor = fTextColor;
 
  362    fInitFont = fLabelFont;
 
  364    fFontNames->GetScrollBar()->SetPosition(fFontNames->GetSelected()-3);
 
  365    fFontSizes->GetScrollBar()->SetPosition(fFontSizes->GetSelected()-3);
 
  366    fFontSizes->Layout();
 
  367    fFontNames->Layout();
 
  369    SetWindowName(
"Font Selection");
 
  370    SetIconName(
"Font Selection");
 
  371    SetClassHints(
"ROOT", 
"FontDialog");
 
  373    SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
 
  374                               kMWMDecorMinimize | kMWMDecorMenu,
 
  375                kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize |
 
  380    width  = GetDefaultWidth();
 
  381    height = GetDefaultHeight();
 
  383    Resize(width, height);
 
  389    SetWMSize(width, height);
 
  390    SetWMSizeHints(width, height, 10000, 10000, 0, 0);
 
  394       fClient->WaitForUnmap(
this);
 
  402 TGFontDialog::~TGFontDialog()
 
  405    fClient->FreeGC(fSampleTextGC);
 
  411 void TGFontDialog::CloseWindow()
 
  419       fFontProp->fName = 
"";
 
  423          FontSelected((
char*)fInitFont->GetName());
 
  426          SetColor(fInitColor);
 
  427          ColorSelected(fInitColor);
 
  431          SetAlign(fInitAlign);
 
  432          AlignSelected(fInitAlign);
 
  435    fFontNames->Select(0);
 
  436    fFontStyles->Select(0);
 
  437    fFontSizes->Select(0);
 
  447 Bool_t TGFontDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
 
  449    switch (GET_MSG(msg)) {
 
  451          switch (GET_SUBMSG(msg)) {
 
  457                      fFontProp->fName   = fName;
 
  458                      fFontProp->fItalic = fItalic;
 
  459                      fFontProp->fBold   = fBold;
 
  460                      fFontProp->fSize   = fSize;
 
  461                      fFontProp->fColor  = fTextColor;
 
  462                      fFontProp->fAlign  = fTextAlign;
 
  486          switch (GET_SUBMSG(msg)) {
 
  488             case kCOL_SELCHANGED:
 
  490                   if (parm2 != (Int_t)fTextColor) {
 
  511 Bool_t TGFontDialog::Build(
char **fontList, Int_t cnt)
 
  520    for (i = 0; i < cnt; i++) {
 
  522       n1 = font.Index(
"-", 1);
 
  523       n2 = font.Index(
"-", n1+1);
 
  524       family = font(n1+1, n2-n1-1);
 
  526       if ((family.Length() == 0) || (family.BeginsWith(
"@"))) {
 
  530       if (!fFontNames->FindEntry(family.Data())) {
 
  531          fFontNames->AddEntry(family.Data(), fNumberOfFonts++);
 
  535    fFontNames->SortByName();
 
  537    TGTextLBEntry *le = (TGTextLBEntry*)fFontNames->FindEntry(fName.Data());
 
  540       fFontNames->Select(le->EntryId());
 
  543    UpdateStyleSize(fName.Data());
 
  551 void TGFontDialog::UpdateStyleSize(
const char *family)
 
  557    TString font = family;
 
  558    Bool_t styles[4] = { kFALSE, kFALSE, kFALSE, kFALSE };
 
  565    fname = TString::Format(
"-*-%s-*-*", family);
 
  566    fontList = gVirtualX->ListFonts(fname.Data(), 1000, cnt);
 
  568    fFontSizes->RemoveEntries(0, 1000);
 
  569    fFontSizes->Layout();
 
  571    fFontStyles->RemoveEntries(0, 100);
 
  572    fFontStyles->Layout();
 
  574    if (!cnt || !fontList) {
 
  583    Bool_t x11 = gVirtualX->InheritsFrom(
"TGX11");
 
  584    Bool_t all_sizes = !x11;
 
  585    Bool_t all_styles = !x11;
 
  588    if (gVirtualX->InheritsFrom(
"TGCocoa")) {
 
  595    fFontSizes->AddEntry(
"12", szn++);
 
  597    for (i = 0; i < cnt; i++) {
 
  599       n1 = name.Index(family);
 
  604       n1 += font.Length() + 1;
 
  605       n2 = name.Index(
"-", n1);
 
  610       style1 = name(n1, n2 - n1);
 
  613       n2 = name.Index(
"-", n1);
 
  617       style2 = name(n1, n2 - n1);
 
  619       if ((style1 == 
"normal") || (style1 == 
"medium")) {
 
  622             gFontStylesReal[0] = style1 + 
"-" + style2;
 
  623          } 
else if (style2 == 
"i") {
 
  625             gFontStylesReal[2] = style1 + 
"-" + style2;
 
  626          } 
else if (style2 == 
"o") {
 
  628             gFontStylesReal[2] = style1 + 
"-" + style2;
 
  630       } 
else if (style1 == 
"bold") {
 
  633             gFontStylesReal[1] = style1 + 
"-" + style2;
 
  634          } 
else if (style2 == 
"i") {
 
  636             gFontStylesReal[3] = style1 + 
"-" + style2;
 
  637          } 
else if (style2 == 
"o") {
 
  639             gFontStylesReal[3] = style1 + 
"-" + style2;
 
  641       } 
else if (style1 == 
"(null)") {
 
  643          gFontStylesReal[0] = 
"normal-r";
 
  645          gFontStylesReal[1] = 
"bold-r";
 
  647          gFontStylesReal[2] = 
"normal-i";
 
  649          gFontStylesReal[3] = 
"bold-i";
 
  653       n2 = name.Index(
"-", n1);
 
  655       n2 = name.Index(
"-", n1);
 
  660          n2 = name.Index(
"-", n1);
 
  661          sz = name(n1, n2 - n1);
 
  666          all_sizes = (sz == 
"0") && !x11;
 
  669             if (sz.Length() == 1) {
 
  672             if (!fFontSizes->FindEntry(sz.Data())) {
 
  673                fFontSizes->AddEntry(sz.Data(), szn++);
 
  678    gVirtualX->FreeFontNames(fontList);
 
  680    Bool_t nostyles = kTRUE;
 
  681    for (i = 0; gFontStyles[i] != 0; ++i) {
 
  682       if (all_styles || styles[i]) {
 
  684          fFontStyles->AddEntry(
new TGString(gFontStyles[i]), i);
 
  688    if (nostyles && x11) {
 
  689       fFontStyles->AddEntry(
new TGString(gFontStyles[0]), 0);
 
  696          fFontStyles->Select(0);
 
  698          fFontStyles->Select(2);
 
  702          fFontStyles->Select(1);
 
  704          fFontStyles->Select(3);
 
  712    fFontStyles->MapSubwindows();
 
  713    fFontStyles->Layout();
 
  716    sz = TString::Format(
"%d", fSize);
 
  717    if (sz.Length() == 1) {
 
  721    for (i = 0; gFontSizes[i] != 0; ++i) {
 
  722       if (all_sizes && !fFontSizes->FindEntry(gFontSizes[i])) {
 
  723          fFontSizes->AddEntry(
new TGString(gFontSizes[i]), i);
 
  725       if (sz == gFontSizes[i]) {
 
  726          fFontSizes->Select(i);
 
  730    fFontSizes->SortByName();
 
  731    fFontSizes->MapSubwindows();
 
  732    fFontSizes->Layout();
 
  738 void TGFontDialog::GetFontName()
 
  741    const char *size, *name;
 
  743    Int_t sav = gErrorIgnoreLevel;
 
  744    gErrorIgnoreLevel = kFatal;
 
  746    TString oldName = fName;
 
  747    e = (TGTextLBEntry *) fFontNames->GetSelectedEntry();
 
  750       fFontNames->Select(1);
 
  751       e = (TGTextLBEntry *) fFontNames->GetSelectedEntry();
 
  753    name = e ? e->GetText()->GetString() : 
"";
 
  756    e = (TGTextLBEntry *) fFontSizes->GetSelectedEntry();
 
  757    size = e ? e->GetText()->GetString() : 
"0";
 
  760    sel = fFontStyles->GetSelected();
 
  761    if (sel < 0) sel = 0;
 
  786    const char *rgstry = 
"*";
 
  788    if ((fName == 
"Symbol") || (fName == 
"Webdings") || (fName == 
"Wingdings")) {
 
  789       rgstry = 
"microsoft";
 
  792    TString oldFont = fLName;
 
  793    fLName = TString::Format(
"-*-%s-%s-*-*-%s-*-*-*-*-*-%s-*", name,
 
  794                             gFontStylesReal[sel].Data(), size, rgstry);
 
  796    if (oldFont != fLName) {
 
  799          fLabelFont = fClient->GetFont(fLName, kFALSE);
 
  802             fLabelFont = fClient->GetFont(
"fixed");
 
  805          fLabelFont = fClient->GetFont(
"fixed");
 
  813          fSample->SetTextFont(fLabelFont);
 
  817    Int_t oldAlign = fTextAlign;
 
  819    Int_t idx = fTextAligns->GetSelected();
 
  820    fTextAlign = gAlignValues[idx >= 0 ? idx : 6];
 
  823       if (fTextAlign != oldAlign) {
 
  824          fSample->SetTextJustify(fTextAlign);
 
  825          AlignSelected(fTextAlign);
 
  827       fSample->SetTextColor(fTextColor);
 
  828       fColorSelect->SetColor(fTextColor, kFALSE);
 
  829       ColorSelected(fTextColor);
 
  831    FontSelected((
char*)fLName.Data());
 
  832    fClient->NeedRedraw(
this);
 
  833    gErrorIgnoreLevel = sav;
 
  839 void TGFontDialog::SetFont(TGFont *font)
 
  844    TString name = font->GetName();
 
  846    if (name.Index(
"-", 1) == kNPOS) {
 
  852       fSample->SetTextFont(fLabelFont);
 
  863    n1 = name.Index(
"-", 1);
 
  864    n2 = name.Index(
"-", n1 + 1);
 
  866    family = name(n1, n2 - n1);
 
  868    TGTextLBEntry *le = (TGTextLBEntry*)fFontNames->FindEntry(family.Data());
 
  871       fFontNames->Select(le->EntryId());
 
  875    n2 = name.Index(
"-", n1);
 
  877    style1 = name(n1, n2 - n1);
 
  880    n2 = name.Index(
"-", n1);
 
  884    style2 = name(n1, n2 - n1);
 
  886    if ((style1 == 
"normal") || (style1 == 
"medium")) {
 
  888          fFontStyles->Select(0);
 
  889       } 
else if (style2 == 
"i") {
 
  890          fFontStyles->Select(2);
 
  891       } 
else if (style2 == 
"o") {
 
  892          fFontStyles->Select(2);
 
  894    } 
else if (style1 == 
"bold") {
 
  896          fFontStyles->Select(1);
 
  897       } 
else if (style2 == 
"i") {
 
  898          fFontStyles->Select(3);
 
  899       } 
else if (style2 == 
"o") {
 
  900          fFontStyles->Select(3);
 
  904    n2 = name.Index(
"-", n1);
 
  906    n2 = name.Index(
"-", n1);
 
  908    n2 = name.Index(
"-", n1);
 
  912       n2 = name.Index(
"-", n1);
 
  913       sz = name(n1, n2 - n1);
 
  915       le = (TGTextLBEntry*)fFontSizes->FindEntry(sz.Data());
 
  917          fFontSizes->Select(le->EntryId());
 
  925 void TGFontDialog::SetColor(Pixel_t color)
 
  929       fSample->SetTextColor(fTextColor);
 
  931    fColorSelect->SetColor(color, kFALSE);
 
  932    fClient->NeedRedraw(fColorSelect);
 
  939 void TGFontDialog::SetAlign(Int_t align)
 
  943       fSample->SetTextJustify(fTextAlign);
 
  946    for (
int i = 0; gAlignValues[i] != 0; ++i) {
 
  947       if (gAlignValues[i] == align) {
 
  948          fTextAligns->Select(i);
 
  952    fClient->NeedRedraw(fTextAligns);
 
  958 void TGFontDialog::EnableAlign(Bool_t on)
 
  960    fTextAligns->SetEnabled(on);