39 ClassImp(TGHotString);
44 TGString::TGString(
const TGString *s) : TString(s->Data())
51 void TGString::Draw(Drawable_t
id, GContext_t gc, Int_t x, Int_t y)
53 gVirtualX->DrawString(
id, gc, x, y, Data(), Length());
60 void TGString::DrawWrapped(Drawable_t
id, GContext_t gc,
61 Int_t x, Int_t y, UInt_t w, FontStruct_t font)
63 const char *p = Data();
65 const char *chunk = p;
66 int tw, th, len = Length();
68 tw = gVirtualX->TextWidth(font, p, len);
70 gVirtualX->DrawString(
id, gc, x, y, p, len);
74 int max_ascent, max_descent;
75 gVirtualX->GetFontProperties(font, max_ascent, max_descent);
76 th = max_ascent + max_descent + 1;
81 if (chunk) gVirtualX->DrawString(
id, gc, x, y, chunk, strlen(chunk));
84 tw = gVirtualX->TextWidth(font, chunk, p-chunk);
90 gVirtualX->DrawString(
id, gc, x, y, chunk, prev-chunk-1);
102 Int_t TGString::GetLines(FontStruct_t font, UInt_t w)
104 const char *p = Data();
105 const char *prev = p;
106 const char *chunk = p;
107 int tw, nlines, len = Length();
111 tw = gVirtualX->TextWidth(font, p, len);
112 if (tw <= (
int)w)
return nlines;
117 tw = gVirtualX->TextWidth(font, chunk, p-chunk);
135 TGHotString::TGHotString(
const char *s) : TGString()
145 char *dup = StrDup(s);
148 for (p = dup; *p; p++) {
152 for (
char *tmp = p; *tmp; tmp++)
157 fHotPos = (p - dup) + 1;
158 fHotChar = tolower(p[1]);
159 for (; *p; p++) p[0] = p[1];
170 void TGHotString::Draw(Drawable_t
id, GContext_t gc, Int_t x, Int_t y)
172 gVirtualX->DrawString(
id, gc, x, y, Data(), Length());
174 DrawHotChar(
id, gc, x, y);
181 void TGHotString::DrawWrapped(Drawable_t
id, GContext_t gc,
182 Int_t x, Int_t y, UInt_t w, FontStruct_t font)
184 const char *p = Data();
185 const char *prev = p;
186 const char *chunk = p;
187 int tw, th, len = Length();
189 tw = gVirtualX->TextWidth(font, p, len);
191 gVirtualX->DrawString(
id, gc, x, y, p, len);
192 DrawHotChar(
id, gc, x, y);
196 int max_ascent, max_descent;
197 gVirtualX->GetFontProperties(font, max_ascent, max_descent);
198 th = max_ascent + max_descent + 1;
205 gVirtualX->DrawString(
id, gc, x, y, chunk, strlen(chunk));
206 if (fHotPos > pcnt && fHotPos <= pcnt+(
int)strlen(chunk))
207 DrawHotChar(
id, gc, x, y);
211 tw = gVirtualX->TextWidth(font, chunk, p-chunk);
217 gVirtualX->DrawString(
id, gc, x, y, chunk, prev-chunk-1);
218 if (fHotPos > pcnt && fHotPos <= pcnt+prev-chunk-1)
219 DrawHotChar(
id, gc, x, y);
232 void TGHotString::DrawHotChar(Drawable_t
id, GContext_t gc, Int_t x, Int_t y)
238 font = gVirtualX->GetGCFont(gc);
240 fOff1 = gVirtualX->TextWidth(font, Data(), fHotPos-1);
241 fOff2 = gVirtualX->TextWidth(font, Data(), fHotPos) - 1;
244 gcval.fMask = kGCFont;
245 gVirtualX->GetGCValues(gc, gcval);
246 font = gVirtualX->GetFontStruct(gcval.fFont);
248 fOff1 = gVirtualX->TextWidth(font, Data(), fHotPos-1);
249 fOff2 = gVirtualX->TextWidth(font, Data(), fHotPos) - 1;
251 gVirtualX->FreeFontStruct(font);
255 gVirtualX->DrawLine(
id, gc, x+fOff1, y+1, x+fOff2, y+1);