00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "TAttTextEditor.h"
00028 #include "TGedEditor.h"
00029 #include "TGColorSelect.h"
00030 #include "TGComboBox.h"
00031 #include "TColor.h"
00032 #include "TPaveLabel.h"
00033 #include "TVirtualPad.h"
00034
00035 ClassImp(TAttTextEditor)
00036
00037 enum ETextWid {
00038 kCOLOR,
00039 kFONT_SIZE,
00040 kFONT_STYLE,
00041 kFONT_ALIGN
00042 };
00043
00044
00045 TAttTextEditor::TAttTextEditor(const TGWindow *p, Int_t width,
00046 Int_t height, UInt_t options, Pixel_t back)
00047 : TGedFrame(p, width, height, options | kVerticalFrame, back)
00048 {
00049
00050 fPriority = 3;
00051
00052 fAttText = 0;
00053
00054 MakeTitle("Text");
00055
00056 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00057 fColorSelect = new TGColorSelect(f2, 0, kCOLOR);
00058 f2->AddFrame(fColorSelect, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
00059 fColorSelect->Associate(this);
00060 fSizeCombo = BuildFontSizeComboBox(f2, kFONT_SIZE);
00061 f2->AddFrame(fSizeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
00062 fSizeCombo->Resize(91, 20);
00063 fSizeCombo->Associate(this);
00064 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
00065 fTypeCombo = new TGFontTypeComboBox(this, kFONT_STYLE);
00066 fTypeCombo->Resize(137, 20);
00067 AddFrame(fTypeCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
00068 fAlignCombo = BuildTextAlignComboBox(this, kFONT_ALIGN);
00069 fAlignCombo->Resize(137, 20);
00070 AddFrame(fAlignCombo, new TGLayoutHints(kLHintsLeft, 3, 1, 1, 1));
00071 }
00072
00073
00074 TAttTextEditor::~TAttTextEditor()
00075 {
00076
00077 }
00078
00079
00080 void TAttTextEditor::SetModel(TObject* obj)
00081 {
00082
00083
00084 TAttText *atttext = dynamic_cast<TAttText *>(obj);
00085 if (!atttext) return;
00086
00087 fAttText = atttext;
00088 fAvoidSignal = kTRUE;
00089
00090 fTypeCombo->Select(fAttText->GetTextFont() / 10);
00091
00092 Float_t s = fAttText->GetTextSize();
00093 Float_t dy;
00094
00095 if (obj->InheritsFrom(TPaveLabel::Class())) {
00096 TBox *pl = (TBox*)obj;
00097 dy = s * (pl->GetY2() - pl->GetY1());
00098 }
00099 else
00100 dy = s * (fGedEditor->GetPad()->GetY2() - fGedEditor->GetPad()->GetY1());
00101
00102 Int_t size = fGedEditor->GetPad()->YtoPixel(0.0) - fGedEditor->GetPad()->YtoPixel(dy);
00103 if (size > 50) size = 50;
00104 if (size < 0) size = 0;
00105 fSizeCombo->Select(size, kFALSE);
00106
00107 fAlignCombo->Select(fAttText->GetTextAlign(), kFALSE);
00108
00109 Color_t c = fAttText->GetTextColor();
00110 Pixel_t p = TColor::Number2Pixel(c);
00111 fColorSelect->SetColor(p, kFALSE);
00112
00113 fAvoidSignal = kFALSE;
00114 }
00115
00116
00117 Bool_t TAttTextEditor::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
00118 {
00119
00120
00121 if(!fGedEditor || !fGedEditor->GetModel()) return kTRUE;
00122
00123 Bool_t b = kFALSE;
00124
00125 if (GET_MSG(msg) == kC_COLORSEL && GET_SUBMSG(msg) == kCOL_SELCHANGED) {
00126 fAttText->SetTextColor(TColor::GetColor(parm2));
00127 b = kTRUE;
00128
00129 }
00130
00131 if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_COMBOBOX) {
00132
00133 if (parm1 == kFONT_SIZE) {
00134 TVirtualPad* pad = fGedEditor->GetPad();
00135 Float_t dy = pad->AbsPixeltoY(0) - pad->AbsPixeltoY(parm2);
00136 Float_t textSize;
00137
00138 if (fGedEditor->GetModel()->InheritsFrom(TPaveLabel::Class())) {
00139 TBox *pl = (TBox*)fGedEditor->GetModel();
00140 textSize = dy/(pl->GetY2() - pl->GetY1());
00141 }
00142 else
00143 textSize = dy/(pad->GetY2() - pad->GetY1());
00144
00145 fAttText->SetTextSize(textSize);
00146 b = kTRUE;
00147 } else if (parm1 == kFONT_STYLE) {
00148 Int_t fontPrec = fAttText->GetTextFont()%10;
00149 fAttText->SetTextFont(parm2 * 10 + fontPrec);
00150 b = kTRUE;
00151 } else if (parm1 == kFONT_ALIGN) {
00152 fAttText->SetTextAlign(parm2);
00153 b = kTRUE;
00154 }
00155 }
00156
00157 if (b && !fAvoidSignal) Update();
00158
00159 return kTRUE;
00160 }
00161
00162
00163 TGComboBox* TAttTextEditor::BuildFontSizeComboBox(TGFrame* parent, Int_t id)
00164 {
00165
00166
00167 char a[100];
00168 TGComboBox *c = new TGComboBox(parent, id);
00169
00170 c->AddEntry("Default", 0);
00171 for (int i = 1; i <= 50; i++) {
00172 snprintf(a, 99, "%d", i);
00173 c->AddEntry(a, i);
00174 }
00175
00176 return c;
00177 }
00178
00179
00180 TGComboBox* TAttTextEditor::BuildTextAlignComboBox(TGFrame* parent, Int_t id)
00181 {
00182
00183
00184 TGComboBox *c = new TGComboBox(parent, id);
00185
00186 c->AddEntry("11 Bottom, Left", 11);
00187 c->AddEntry("21 Bottom, Middle", 21);
00188 c->AddEntry("31 Bottom, Right", 31);
00189 c->AddEntry("12 Middle, Left", 12);
00190 c->AddEntry("22 Middle, Middle", 22);
00191 c->AddEntry("32 Middle, Right", 32);
00192 c->AddEntry("13 Top, Left", 13);
00193 c->AddEntry("23 Top, Middle", 23);
00194 c->AddEntry("33 Top, Right", 33);
00195
00196 return c;
00197 }