Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGHtml.cxx
Go to the documentation of this file.
1// $Id: TGHtml.cxx,v 1.4 2007/05/07 15:19:07 brun Exp $
2// Author: Valeriy Onuchin 03/05/2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/**************************************************************************
13
14 HTML widget for xclass. Based on tkhtml 1.28
15 Copyright (C) 1997-2000 D. Richard Hipp <drh@acm.org>
16 Copyright (C) 2002-2003 Hector Peraza.
17
18 This library is free software; you can redistribute it and/or
19 modify it under the terms of the GNU Library General Public
20 License as published by the Free Software Foundation; either
21 version 2 of the License, or (at your option) any later version.
22
23 This library is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 Library General Public License for more details.
27
28 You should have received a copy of the GNU Library General Public
29 License along with this library; if not, write to the Free
30 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31
32**************************************************************************/
33
34#include <cctype>
35#include <cstdlib>
36#include <cstring>
37#include <iostream>
38
39#include "TGHtml.h"
40#include "THashTable.h"
41#include "TObjString.h"
42#include "TGIdleHandler.h"
43#include "TImage.h"
44#include "TTimer.h"
45#include "TGTextEntry.h"
46#include "TGText.h"
47#include "TGComboBox.h"
48#include "TGListBox.h"
49#include "TVirtualX.h"
50#include "strlcpy.h"
51#include "snprintf.h"
52
53//_____________________________________________________________________________
54//
55// TGHtml
56//
57// The ROOT HTML widget. A derivate of TGView.
58//_____________________________________________________________________________
59
61
62int HtmlTraceMask = 0; //HtmlTrace_Table1 | HtmlTrace_Table4;
63int HtmlDepth = 0;
64
65#define DEF_FRAME_BG_COLOR "#c0c0c0"
66#define DEF_FRAME_CURSOR ""
67#define DEF_BUTTON_FG "black"
68#define DEF_BUTTON_HIGHLIGHT_BG "#d9d9d9"
69#define DEF_BUTTON_HIGHLIGHT "black"
70
71
72////////////////////////////////////////////////////////////////////////////////
73/// HTML Widget constructor.
74
75TGHtml::TGHtml(const TGWindow *p, int w, int h, int id) : TGView(p, w, h, id)
76{
78
79 int i;
80
81 fExiting = 0;
82 fPFirst = 0;
83 fPLast = 0;
84 fNToken = 0;
85 fLastSized = 0;
86 fNextPlaced = 0;
87 fFirstBlock = 0;
88 fLastBlock = 0;
89 fFirstInput = 0;
90 fLastInput = 0;
91 fNInput = 0;
92 fNForm = 0;
93 fVarId = 0; // do we need this??
94 fInputIdx = 0;
95 fRadioIdx = 0;
96 fSelBegin.fI = 0;
97 fSelBegin.fP = 0;
98 fSelEnd.fI = 0;
99 fSelEnd.fP = 0;
100 fPSelStartBlock = 0;
101 fPSelEndBlock = 0;
104 fInsStatus = 0;
105 fInsTimer = 0;
106 fIns.fI = 0;
107 fIns.fP = 0;
108 fPInsBlock = 0;
109 fInsIndex = 0;
110 fZText = 0;
111 fNText = 0;
112 fNAlloc = 0;
113 fNComplete = 0;
114 fICol = 0;
115 fIPlaintext = 0;
116 fPScript = 0;
117 fIdle = 0;
118 fStyleStack = 0;
121 fAnchorFlags = 0;
122 fInDt = 0;
123 fInTr = 0;
124 fInTd = 0;
125 fAnchorStart = 0;
126 fFormStart = 0;
127 fFormElemStart = 0;
128 fFormElemLast = 0;
129 fLoEndPtr = 0;
130 fLoFormStart = 0;
131 fInnerList = 0;
133 fHighlightWidth = 0;
136 for (i = 0; i < N_FONT; ++i) fAFont[i] = 0;
137 memset(fFontValid, 0, sizeof(fFontValid));
138 for (i = 0; i < N_COLOR; ++i) {
139 fApColor[i] = 0;
140 fIDark[i] = 0;
141 fILight[i] = 0;
142 }
143 fFgColor = AllocColor("black");
144 fBgColor = AllocColor("white"); //AllocColor("#c0c0c0");
148
154
155 fBgImage = 0;
156
158 SetBackgroundPixmap(0); // force usage of solid color
159
160 fColorUsed = 0;
161
162 for (i = 0; i < N_CACHE_GC; ++i) {
163 fAGcCache[i].fIndex = 0;
164 fAGcCache[i].fColor = 0;
165 fAGcCache[i].fFont = 0;
166 fAGcCache[i].fGc = 0;
167 }
168 fLastGC = 0;
169 fSelEndIndex =0;
170 fSelStartIndex = 0;
171 fGcNextToFree = 0;
172 fImageList = 0;
173 fZBaseHref = 0;
174 fInnerList = 0;
175 fFormPadding = 5;
176 fOverrideFonts = 0;
177 fOverrideColors = 0;
178 fHasScript = 0;
179 fHasFrames = 0;
180 fAddEndTags = 0;
181 fTableBorderMin = 0;
182 fVarind = 0;
183 fIdind = 0;
184 fInParse = 0;
185 fZGoto = 0;
186 fExts = 0;
191 fRulePadding = 5;
192 fZBase = 0;
193 fZBaseHref = 0;
195 fMaxX = 0;
196 fMaxY = 0;
197
198 fXMargin = fYMargin = 0; //HTML_INDENT/4;
199
201
203 fDirtyRight = 0;
205 fDirtyBottom = 0;
206
207
210
211 fLastUri = 0;
212
215
216 fUidTable = new THashTable(100);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// HTML widget destructor.
221
223{
224 int i;
225
226 fExiting = 1;
227 HClear();
228 for (i = 0; i < N_FONT; i++) {
229 if (fAFont[i] != 0) fClient->FreeFont(fAFont[i]);
230 }
231 if (fInsTimer) delete fInsTimer;
232 if (fIdle) delete fIdle;
233
234 // TODO: should also free colors!
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Start background update.
239
241{
242 //GCValues_t gcv;
243 //unsigned int mask = GCTileStipXOrigin | GCTileStipYOrigin;
244//
245 //gcv.ts_x_origin = -fVvisible.fX;
246 //gcv.ts_y_origin = -fVisibleStart.fY;
247 //XChangeGC(GetDisplay(), _backGC, mask, &gcv);
248}
249
250////////////////////////////////////////////////////////////////////////////////
251/// Free system color.
252
254{
255 gVirtualX->FreeColor(gClient->GetDefaultColormap(), color->fPixel);
256 delete color;
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Allocate system color by name.
261
263{
264 ColorStruct_t *color = new ColorStruct_t;
265
266 color->fPixel = 0;
267 if (gVirtualX->ParseColor(fClient->GetDefaultColormap(), name, *color)) {
268 if (!gVirtualX->AllocColor(fClient->GetDefaultColormap(), *color)) {
269 // force allocation of pixel 0
270 gVirtualX->QueryColor(fClient->GetDefaultColormap(), *color);
271 gVirtualX->AllocColor(fClient->GetDefaultColormap(), *color);
272 }
273 }
274
275 return color;
276}
277
278////////////////////////////////////////////////////////////////////////////////
279/// Allocate system color by value.
280
282{
284 *c = *color;
285
286 if (!gVirtualX->AllocColor(gClient->GetDefaultColormap(), *c)) {
287 // force allocation of pixel 0
288 c->fPixel = 0;
289 gVirtualX->QueryColor(gClient->GetDefaultColormap(), *c);
290 gVirtualX->AllocColor(gClient->GetDefaultColormap(), *c);
291 }
292
293 return c;
294}
295
296////////////////////////////////////////////////////////////////////////////////
297/// Erase all HTML from this widget and clear the screen. This is
298/// typically done before loading a new document.
299
301{
302 HClear();
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Appends (or insert at the specified position) the given HTML text to the
310/// end of any HTML text that may have been inserted by prior calls to this
311/// command. Then it runs the tokenizer, parser and layout engine as far as
312/// possible with the text that is available. The display is updated
313/// appropriately.
314
315int TGHtml::ParseText(char *text, const char *index)
316{
317 SHtmlIndex_t iStart;
318 TGHtmlElement *savePtr=0;
319
320 iStart.fP = 0;
321 iStart.fI = 0;
322
324
325 if (index) {
326 int rc = GetIndex(index, &iStart.fP, &iStart.fI);
327 if (rc != 0) return kFALSE; // malformed index
328 if (iStart.fP) {
329 savePtr = iStart.fP->fPNext;
330 fPLast = iStart.fP;
331 iStart.fP->fPNext = 0;
332 }
333 }
334
336
337 if (fLoEndPtr) {
339 if (iStart.fP && savePtr) {
341 fPLast->fPNext = savePtr;
342 savePtr->fPPrev = fPLast;
346 } else if (fLoEndPtr->fPNext) {
348 }
349 } else if (fPFirst) {
352 fAnchorFlags = 0;
353 fInDt = 0;
354 fAnchorStart = 0;
355 fFormStart = 0;
356 fInnerList = 0;
357 fNInput = 0;
359 }
360#if 1
363#endif
364
367
368 return kTRUE;
369}
370
371////////////////////////////////////////////////////////////////////////////////
372/// Sets relief mode of html table.
373
375{
376 if (fTableRelief != relief) {
377 fTableRelief = relief;
378 fFlags |= RELAYOUT;
380 }
381}
382
383////////////////////////////////////////////////////////////////////////////////
384/// Sets relief mode of html rule.
385
386void TGHtml::SetRuleRelief(int relief)
387{
388 if (fRuleRelief != relief) {
389 fRuleRelief = relief;
390 fFlags |= RELAYOUT;
392 }
393}
394
395////////////////////////////////////////////////////////////////////////////////
396/// Set/reset html links underline.
397
399{
400 if (fUnderlineLinks != onoff) {
401 fUnderlineLinks = onoff;
402// fFlags |= RESIZE_ELEMENTS | RELAYOUT;
403// AddStyle(fPFirst);
404
405 TGHtmlElement *p;
407 for (p = fPFirst; p; p = p->fPNext) {
408 if (p->fType == Html_A) {
409 if (fAnchorStart) {
411 fAnchorStart = 0;
412 fAnchorFlags = 0;
413 }
414 const char *z = p->MarkupArg("href", 0);
415 if (z) {
416 style.fColor = GetLinkColor(z);
417 if (fUnderlineLinks) style.fFlags |= STY_Underline;
421 }
422 } else if (p->fType == Html_EndA) {
423 if (fAnchorStart) {
424 ((TGHtmlRef *)p)->fPOther = fAnchorStart;
426 fAnchorStart = 0;
427 fAnchorFlags = 0;
428 }
429 }
430 p->fStyle.fFlags &= ~STY_Underline;
431 p->fStyle.fFlags |= (style.fFlags & STY_Underline);
432 }
433
435 }
436}
437
438////////////////////////////////////////////////////////////////////////////////
439/// Sets base URI.
440
441void TGHtml::SetBaseUri(const char *uri)
442{
443 if (fZBase) delete[] fZBase;
444 fZBase = 0;
445 if (uri) fZBase = StrDup(uri);
446}
447
448////////////////////////////////////////////////////////////////////////////////
449/// Go to anchor position.
450
451int TGHtml::GotoAnchor(const char *name)
452{
453 const char *z;
454 TGHtmlElement *p;
455
456 for (p = fPFirst; p; p = p->fPNext) {
457 if (p->fType == Html_A) {
458 z = p->MarkupArg("name", 0);
459 if (z && strcmp(z, name) == 0) {
461 return kTRUE;
462 }
463 }
464 }
465
466 return kFALSE;
467}
468
469////////////////////////////////////////////////////////////////////////////////
470/// Given a string, this procedure returns a unique identifier for the
471/// string.
472///
473/// This procedure returns a pointer to a new char string corresponding to
474/// the "string" argument. The new string has a value identical to string
475/// (strcmp will return 0), but it's guaranteed that any other calls to this
476/// procedure with a string equal to "string" will return exactly the same
477/// result (i.e. can compare pointer *values* directly, without having to
478/// call strcmp on what they point to).
479
480const char *TGHtml::GetUid(const char *string)
481{
482 //int dummy;
483
484 TObjString *obj = 0;
485 obj = (TObjString*)fUidTable->FindObject(string);
486
487 if (!obj) {
488 obj = new TObjString(string);
489 fUidTable->Add(obj);
490 }
491
492 return (const char *)obj->GetName();
493}
494
495////////////////////////////////////////////////////////////////////////////////
496/// Computes virtual size of html area.
497
499{
501}
502
503////////////////////////////////////////////////////////////////////////////////
504/// Clear the cache of GCs
505
507{
508 int i;
509
510 for (i = 0; i < N_CACHE_GC; i++) {
511 if (fAGcCache[i].fIndex) {
512 gVirtualX->DeleteGC(fAGcCache[i].fGc);
513 fAGcCache[i].fIndex = 0;
514 }
515 }
516 fGcNextToFree = 0;
517}
518
519////////////////////////////////////////////////////////////////////////////////
520/// Reset the main layout context in the main widget. This happens
521/// before we redo the layout, or just before deleting the widget.
522
524{
526}
527
528////////////////////////////////////////////////////////////////////////////////
529/// This routine is invoked in order to redraw all or part of the HTML
530/// widget. This might happen because the display has changed, or in
531/// response to an expose event. In all cases, though, this routine
532/// is called by an idle handler.
533
535{
536 Pixmap_t pixmap; // The buffer on which to render HTML
537 int x, y, w, h; // Virtual canvas coordinates of area to draw
538 int hw; // highlight thickness
539 int clipwinH, clipwinW; // Width and height of the clipping window
540 TGHtmlBlock *pBlock; // For looping over blocks to be drawn
541 int redoSelection = 0; // kTRUE to recompute the selection
542
543 // Don't do anything if we are in the middle of a parse.
544
545 if (fInParse) {
546 fFlags &= ~REDRAW_PENDING;
547 return;
548 }
549
550 // Recompute the layout, if necessary or requested.
551 //
552 // Calling LayoutDoc() is tricky because LayoutDoc() may invoke one
553 // or more user-overriden methods, and these methods could, in theory,
554 // do nasty things. So we have to take precautions:
555 //
556 // * Do not remove the REDRAW_PENDING flag until after LayoutDoc()
557 // has been called, to prevent a recursive call to Redraw().
558
559 if ((fFlags & RESIZE_ELEMENTS) != 0 && (fFlags & STYLER_RUNNING) == 0) {
560 TGHtmlImage *pImage;
561 for (pImage = fImageList; pImage; pImage = pImage->fPNext) {
562 pImage->fPList = 0;
563 }
564 fLastSized = 0;
565 fFlags &= ~RESIZE_ELEMENTS;
566 fFlags |= RELAYOUT;
567 }
568
569 // We used to make a distinction between RELAYOUT and EXTEND_LAYOUT.
570 // RELAYOUT would be used when the widget was resized, but the
571 // less compute-intensive EXTEND_LAYOUT would be used when new
572 // text was appended.
573 //
574 // Unfortunately, EXTEND_LAYOUT has some problem that arise when
575 // tables are used. The quick fix is to make an EXTEND_LAYOUT do
576 // a complete RELAYOUT. Someday, we need to fix EXTEND_LAYOUT so
577 // that it works right...
578
579 if ((fFlags & (RELAYOUT | EXTEND_LAYOUT)) != 0
580 && (fFlags & STYLER_RUNNING) == 0) {
581 fNextPlaced = 0;
582 //fNInput = 0;
583 fVarId = 0;
584 fMaxX = 0;
585 fMaxY = 0;
587 fFirstBlock = 0;
588 fLastBlock = 0;
589 redoSelection = 1;
590 fFlags &= ~RELAYOUT;
592 }
593
594 if ((fFlags & EXTEND_LAYOUT) && fPFirst != 0) {
595 LayoutDoc();
596 fFlags &= ~EXTEND_LAYOUT;
597 FormBlocks();
598 MapControls();
599 if (redoSelection && fSelBegin.fP && fSelEnd.fP) {
601 UpdateInsert();
602 }
603 }
604 fFlags &= ~REDRAW_PENDING;
605
606 // No need to do any actual drawing if we aren't mapped
607
608//// if (!IsMapped()) return;
609
610 // Update the scrollbars.
611
612 if ((fFlags & (HSCROLL | VSCROLL)) != 0) {
614 fFlags &= ~(HSCROLL | VSCROLL);
615
616 if (fFlags & REDRAW_PENDING) return;
617 }
618
619 // Redraw the focus highlight, if requested
620 hw = fHighlightWidth;
621 if (fFlags & REDRAW_FOCUS) {
622 if (hw > 0) {
623#if 0
624 unsigned long color;
625
626 if (fFlags & GOT_FOCUS) {
627 color = highlightColorPtr;
628 } else {
629 color = highlightBgColorPtr;
630 }
631 _DrawFocusHighlight(color);
632#endif
633 }
634 fFlags &= ~REDRAW_FOCUS;
635 }
636
637 // If the styler is in a callback, abort further processing.
638 // TODO: check this!
639
640 if (fFlags & STYLER_RUNNING) {
641 goto earlyOut;
642 }
643
644 MapControls();
645
646 // Compute the virtual canvas coordinates corresponding to the
647 // dirty region of the clipping window.
648
649 clipwinW = fCanvas->GetWidth();
650 clipwinH = fCanvas->GetHeight();
651 if (fFlags & REDRAW_TEXT) {
652 w = clipwinW;
653 h = clipwinH;
654 x = fVisible.fX;
655 y = fVisible.fY;
656 fDirtyLeft = 0;
657 fDirtyTop = 0;
658 fFlags &= ~REDRAW_TEXT;
659 } else {
660 if (fDirtyLeft < 0) fDirtyLeft = 0;
661 if (fDirtyRight > clipwinW) fDirtyRight = clipwinW;
662 if (fDirtyTop < 0) fDirtyTop = 0;
663 if (fDirtyBottom > clipwinH) fDirtyBottom = clipwinH;
668 }
669
670 // Skip the rest of the drawing process if the area to be refreshed is
671 // less than zero
672 if (w > 0 && h > 0) {
673 GContext_t gcBg;
674 TGRectangle xrec;
675 // printf("Redraw %dx%d at %d,%d\n", w, h, x, y);
676
677 // Allocate and clear a pixmap upon which to draw
679 pixmap = gVirtualX->CreatePixmap(fCanvas->GetId(), w, h);
680 xrec.fX = 0;
681 xrec.fY = 0;
682 xrec.fW = w;
683 xrec.fH = h;
684#if 0
685
686//old-- XFillRectangles(GetDisplay(), pixmap, gcBg, &xrec, 1);
687//new-- if (fBgImage)
688// BGDraw(fVisible.fX, fVisible.fY, w, h, fBgImage);
689#else
690
693
694 gVirtualX->FillRectangle(pixmap, fWhiteGC.GetGC(), 0, 0, w, h);
695 UpdateBackgroundStart(); // back to original
696#endif
697
698 // Render all visible HTML onto the pixmap
699 for (pBlock = fFirstBlock; pBlock; pBlock = pBlock->fBNext) {
700 if (pBlock->fTop <= y+h && pBlock->fBottom >= y-10 &&
701 pBlock->fLeft <= x+w && pBlock->fRight >= x-10) {
702 BlockDraw(pBlock, pixmap, x, y, w, h, pixmap);
703 }
704 }
705
706 // Finally, copy the pixmap onto the window and delete the pixmap
707 gVirtualX->CopyArea(pixmap, fCanvas->GetId(),
708 gcBg, 0, 0, w, h, fDirtyLeft, fDirtyTop);
709 gVirtualX->Update(kFALSE);
710
711 gVirtualX->DeletePixmap(pixmap);
712// XFlush(GetDisplay());
713 }
714
715 // Redraw images, if requested
716 if (fFlags & REDRAW_IMAGES) {
717 TGHtmlImage *pImage;
718 TGHtmlImageMarkup *pElem;
719 int top, bottom, left, right; // Coordinates of the clipping window
720 int imageTop; // Top edge of image
721
722 top = fVisible.fY;
723 bottom = top + fCanvas->GetHeight();
724 left = fVisible.fX;
725 right = left + fCanvas->GetWidth();
726 for (pImage = fImageList; pImage; pImage = pImage->fPNext) {
727 for (pElem = pImage->fPList; pElem; pElem = pElem->fINext) {
728 if (pElem->fRedrawNeeded == 0) continue;
729 imageTop = pElem->fY - pElem->fAscent;
730 if (imageTop > bottom || imageTop + pElem->fH < top
731 || pElem->fX > right || pElem->fX + pElem->fW < left) continue;
732
733 DrawImage(pElem, fCanvas->GetId(), left, top, right, bottom);
734 }
735 }
737 }
738
739 // Set the dirty region to the empty set.
740earlyOut:
743 fDirtyBottom = 0;
744 fDirtyRight = 0;
745
746 return;
747}
748
749////////////////////////////////////////////////////////////////////////////////
750/// Make sure that a call to the Redraw() routine has been queued.
751
753{
754 if ((fFlags & REDRAW_PENDING) == 0 /*&& IsMapped()*/) {
755 if (!fIdle) fIdle = new TGIdleHandler(this);
757 }
758}
759
760////////////////////////////////////////////////////////////////////////////////
761/// Handles idle event.
762
764{
765 if (idle != fIdle) return kFALSE;
766 Redraw();
767 delete fIdle;
768 fIdle = NULL;
769 return kTRUE;
770}
771
772////////////////////////////////////////////////////////////////////////////////
773/// If any part of the screen needs to be redrawn, then call this routine
774/// with the values of a box (in window coordinates) that needs to be
775/// redrawn. This routine will schedule an idle handler to do the redraw.
776///
777/// The box coordinates are relative to the clipping window (fCanvas).
778
779void TGHtml::RedrawArea(int left, int top, int right, int bottom)
780{
781 if (bottom < 0) return;
782 if (top > (int)fCanvas->GetHeight()) return;
783 if (right < 0) return;
784 if (left > (int)fCanvas->GetWidth()) return;
785 if (fDirtyTop > top) fDirtyTop = top;
786 if (fDirtyLeft > left) fDirtyLeft = left;
787 if (fDirtyBottom < bottom) fDirtyBottom = bottom;
788 if (fDirtyRight < right) fDirtyRight = right;
790}
791
792////////////////////////////////////////////////////////////////////////////////
793/// Draw region defined by [x,y] [w,h].
794
796{
797 TGView::DrawRegion(x, y, w, h);
798
799#if 0
800 RedrawArea(x, y, x + w + 1, y + h + 1);
801#else
802 int left = x;
803 int top = y;
804 int right = x + w + 1;
805 int bottom = y + h + 1;
806 if (bottom < 0) return;
807 if (top > (int) fCanvas->GetHeight()) return;
808 if (right < 0) return;
809 if (left > (int)fCanvas->GetWidth()) return;
810 if (fDirtyTop > top) fDirtyTop = top;
811 if (fDirtyLeft > left) fDirtyLeft = left;
812 if (fDirtyBottom < bottom) fDirtyBottom = bottom;
813 if (fDirtyRight < right) fDirtyRight = right;
814
816 Redraw();
817#endif
818 return;
819}
820
821////////////////////////////////////////////////////////////////////////////////
822/// Layout html widget.
823
825{
826#if 0
828 Redraw(); //RedrawEverything();
829#else
830 fNextPlaced = 0;
831 //fNInput = 0;
832 fVarId = 0;
833 fMaxX = 0;
834 fMaxY = 0;
836 fFirstBlock = 0;
837 fLastBlock = 0;
838 if (fPFirst != 0) {
839 LayoutDoc();
840 FormBlocks();
841 MapControls();
842 if (fSelBegin.fP && fSelEnd.fP) {
844 UpdateInsert();
845 }
846 }
849#endif
850 return kTRUE;
851}
852
853////////////////////////////////////////////////////////////////////////////////
854/// Redraw the TGHtmlBlock given.
855
857{
858 if (p) {
860 p->fRight - fVisible.fX + 1, p->fBottom - fVisible.fY);
861 }
862}
863
864////////////////////////////////////////////////////////////////////////////////
865/// Call this routine to force the entire widget to be redrawn.
866
868{
871}
872
873////////////////////////////////////////////////////////////////////////////////
874/// Call this routine to cause all of the rendered HTML at the
875/// virtual canvas coordinate of Y and beyond to be redrawn.
876
878{
879 int clipHeight; // Height of the clipping window
880
881 clipHeight = fCanvas->GetHeight();
882 y -= fVisible.fY;
883 if (y < clipHeight) {
884 RedrawArea(0, y, LARGE_NUMBER, clipHeight);
885 }
886}
887
888////////////////////////////////////////////////////////////////////////////////
889/// Erase all data from the HTML widget. Bring it back to an empty screen.
890
892{
893 int i;
894 TGHtmlElement *p, *fPNext;
895
896 fXMargin = fYMargin = 0; //HTML_INDENT/4;
897
899 for (p = fPFirst; p; p = fPNext) {
900 fPNext = p->fPNext;
901 delete p;
902 }
903 fPFirst = 0;
904 fPLast = 0;
905 fNToken = 0;
906 if (fZText) delete[] fZText;
907 fZText = 0;
908 fNText = 0;
909 fNAlloc = 0;
910 fNComplete = 0;
911 fIPlaintext = 0;
912
913 for (i = 0; i < N_COLOR; ++i) {
914 if (fApColor[i] != 0) FreeColor(fApColor[i]);
915 fApColor[i] = 0;
916 fIDark[i] = 0;
917 fILight[i] = 0;
918 }
919
920 if (!fExiting) {
921 fFgColor = AllocColor("black");
922 fBgColor = AllocColor("white"); //AllocColor("#c0c0c0");
926
932
934 SetBackgroundPixmap(0); // use solid color
935 }
936
937 fColorUsed = 0;
938 while (fImageList) {
940 fImageList = p2->fPNext;
941 delete p2;
942 }
943
944 if (fBgImage) delete fBgImage;
945 fBgImage = 0;
946
947 while (fStyleStack) {
949 fStyleStack = p2->fPNext;
950 delete p2;
951 }
952 ClearGcCache();
954// if (fZBase) delete[] fZBase;
955// fZBase = 0;
956
957 if (fZBaseHref) delete [] fZBaseHref;
958 fZBaseHref = 0;
959 fLastSized = 0;
960 fNextPlaced = 0;
961 fFirstBlock = 0;
962 fLastBlock = 0;
963 fNInput = 0;
964 fNForm = 0;
965 fVarId = 0;
968 fAnchorFlags = 0;
969 fInDt = 0;
970 fAnchorStart = 0;
971 fFormStart = 0;
972 fInnerList = 0;
973 fMaxX = 0;
974 fMaxY = 0;
975#if 0 // in OXView::Clear()
976 fVisible = TGPosition(0, 0);
977 _virtualSize = TGDimension(0, 0);
978 ScrollTTGPosition(fVisible);
979#endif
980 fPInsBlock = 0;
981 fIns.fP = 0;
982 fSelBegin.fP = 0;
983 fSelEnd.fP = 0;
984 fPSelStartBlock = 0;
985 fPSelEndBlock = 0;
986 fHasScript = 0;
987 fHasFrames = 0;
988 fLastUri = 0;
989}
990
991////////////////////////////////////////////////////////////////////////////////
992/// Handle timer event.
993
995{
996 if (t == fInsTimer) {
997 if (fInsTimer) delete fInsTimer;
998 fInsTimer = NULL;
999 FlashCursor();
1000 return kTRUE;
1001 } else {
1002 TGHtmlImage *pImage;
1003 for (pImage = fImageList; pImage; pImage = pImage->fPNext) {
1004 if (pImage->fTimer == t) {
1005 AnimateImage(pImage);
1006 return kTRUE;
1007 }
1008 }
1009 }
1010 return kFALSE;
1011}
1012
1013////////////////////////////////////////////////////////////////////////////////
1014/// Flash the insertion cursor.
1015
1017{
1018 if (fPInsBlock == 0 || fInsOnTime <= 0 || fInsOffTime <= 0) return;
1020 if ((fFlags & GOT_FOCUS) == 0) {
1021 fInsStatus = 0;
1022 } else if (fInsStatus) {
1023 fInsTimer = new TTimer(this, fInsOffTime);
1024 fInsStatus = 0;
1025 } else {
1026 fInsTimer = new TTimer(this, fInsOnTime);
1027 fInsStatus = 1;
1028 }
1029}
1030
1031////////////////////////////////////////////////////////////////////////////////
1032/// Return a GC from the cache. As many as N_CACHE_GCs are kept valid
1033/// at any one time. They are replaced using an LRU algorithm.
1034///
1035/// A value of FONT_Any (-1) for the font means "don't care".
1036
1037GContext_t TGHtml::GetGC(int color, int font)
1038{
1039 int i, j;
1040 GcCache_t *p = fAGcCache;
1041 GCValues_t gcValues;
1042 TGFont *xfont;
1043
1044 // Check for an existing GC.
1045
1046 if (color < 0 || color >= N_COLOR) color = 0;
1047 if (font < FONT_Any || font >= N_FONT) font = FONT_Default;
1048
1049 for (i = 0; i < N_CACHE_GC; i++, p++) {
1050 if (p->fIndex == 0) continue;
1051 if ((font < 0 || p->fFont == font) && p->fColor == color) {
1052 if (p->fIndex > 1) {
1053 for (j = 0; j < N_CACHE_GC; j++) {
1054 if (fAGcCache[j].fIndex && fAGcCache[j].fIndex < p->fIndex ) {
1055 fAGcCache[j].fIndex++;
1056 }
1057 }
1058 p->fIndex = 1;
1059 }
1060 return fAGcCache[i].fGc;
1061 }
1062 }
1063
1064 // No GC matches. Find a place to allocate a new GC.
1065
1066 p = fAGcCache;
1067 for (i = 0; i < N_CACHE_GC; i++, p++) {
1068 if (p->fIndex == 0 || p->fIndex == N_CACHE_GC) break;
1069 }
1070 if (i >= N_CACHE_GC) { // No slot, so free one (round-robin)
1071 p = fAGcCache;
1072 for (i = 0; i < N_CACHE_GC && i < fGcNextToFree; ++i, ++p) {}
1074 gVirtualX->DeleteGC(p->fGc);
1075 }
1076 gcValues.fForeground = fApColor[color]->fPixel;
1077 gcValues.fGraphicsExposures = kTRUE;
1079
1080 if (font < 0) font = FONT_Default;
1081 xfont = GetFont(font);
1082
1083 if (xfont) {
1084 gcValues.fFont = xfont->GetFontHandle();
1085 gcValues.fMask |= kGCFont;
1086 }
1087
1088 p->fGc = gVirtualX->CreateGC(fId, &gcValues);
1089
1090 if (p->fIndex == 0) p->fIndex = N_CACHE_GC + 1;
1091 for (j = 0; j < N_CACHE_GC; j++) {
1092 if (fAGcCache[j].fIndex && fAGcCache[j].fIndex < p->fIndex) {
1093 fAGcCache[j].fIndex++;
1094 }
1095 }
1096 p->fIndex = 1;
1097 p->fFont = font;
1098 p->fColor = color;
1099
1100 return p->fGc;
1101}
1102
1103////////////////////////////////////////////////////////////////////////////////
1104/// Retrieve any valid GC. The font and color don't matter since the
1105/// GC will only be used for copying.
1106
1108{
1109 int i;
1110 GcCache_t *p = fAGcCache;
1111
1112 for (i = 0; i < N_CACHE_GC; i++, p++) {
1113 if (p->fIndex) return p->fGc;
1114 }
1115
1117}
1118
1119////////////////////////////////////////////////////////////////////////////////
1120/// Handle focus change event.
1121
1123{
1124 if (event->fType == kFocusIn) {
1127 UpdateInsert();
1128 } else { // FocusOut
1129 fFlags &= ~GOT_FOCUS;
1132 }
1133 return kTRUE;
1134}
1135
1136////////////////////////////////////////////////////////////////////////////////
1137/// This routine searchs for a hyperlink beneath the coordinates x,y
1138/// and returns a pointer to the HREF for that hyperlink. The text
1139/// is held in one of the markup argv[] fields of the <a> markup.
1140
1142{
1143 TGHtmlInput *p; // For looping over all controls
1144 int vx, vy, vw, vh; // Part of the virtual canvas that is visible
1145
1146 vx = fVisible.fX;
1147 vy = fVisible.fY;
1148 vw = fCanvas->GetWidth();
1149 vh = fCanvas->GetHeight();
1150 for (p = fFirstInput; p; p = p->fINext) {
1151 if (p->fFrame == 0) continue;
1152 if (p->fY < vy + vh && p->fY + p->fH > vy &&
1153 p->fX < vx + vw && p->fX + p->fW > vx) {
1154 if ((x > p->fX) && (y > p->fY) && (x < (p->fX + p->fW)) &&
1155 (y < (p->fY + p->fH)) ) {
1156 return p;
1157 }
1158 }
1159 }
1160 return 0;
1161}
1162
1163////////////////////////////////////////////////////////////////////////////////
1164/// Handle html input (button, checkbox, ...) event.
1165
1167{
1168 Window_t childdum;
1169 Event_t eventSt;
1170 eventSt.fType = event->fType;
1171 eventSt.fWindow = event->fWindow;
1172 eventSt.fTime = event->fTime;
1173 eventSt.fX = 2;
1174 eventSt.fY = 2;
1175 eventSt.fXRoot = event->fXRoot;
1176 eventSt.fYRoot = event->fYRoot;
1177 eventSt.fCode = event->fCode;
1178 eventSt.fState = event->fState;
1179 eventSt.fWidth = event->fWidth;
1180 eventSt.fHeight = event->fHeight;
1181 eventSt.fCount = event->fCount;
1182 eventSt.fSendEvent = event->fSendEvent;
1183 eventSt.fHandle = event->fHandle;
1184 eventSt.fFormat = event->fFormat;
1185 eventSt.fUser[0] = event->fUser[0];
1186 eventSt.fUser[1] = event->fUser[1];
1187 eventSt.fUser[2] = event->fUser[2];
1188 eventSt.fUser[3] = event->fUser[3];
1189 eventSt.fUser[4] = event->fUser[4];
1190 gVirtualX->TranslateCoordinates(GetId(), pr->fFrame->GetId(),
1191 event->fX, event->fY, eventSt.fX,
1192 eventSt.fY, childdum);
1193
1194 const char *name = pr->MarkupArg("name", 0);
1195 const char *val = pr->MarkupArg("value", 0);
1196 switch (pr->fItype) {
1197 case INPUT_TYPE_Submit:
1198 case INPUT_TYPE_Button: {
1199 TGButton *b = (TGButton *) pr->fFrame;
1200 Bool_t was = !b->IsDown();
1201 b->HandleButton(&eventSt);
1202 Bool_t now = !b->IsDown();
1203 if (!was && now) {
1204 if (pr->fItype == INPUT_TYPE_Submit)
1205 SubmitClicked(val); // emit SubmitClicked
1206 else
1207 ButtonClicked(name, val); // emit ButtonClicked
1208 }
1209 break;
1210 }
1211 case INPUT_TYPE_Radio: {
1212 TGRadioButton *rb = (TGRadioButton *) pr->fFrame;
1213 Bool_t was = !rb->IsDown();
1214 rb->HandleButton(&eventSt);
1215 Bool_t now = !rb->IsDown();
1216 if ((!was && now) || (was && !now)) {
1218 RadioChanged(name, val); // emit RadioChanged
1219 }
1220 break;
1221 }
1222 case INPUT_TYPE_Checkbox: {
1223 TGCheckButton *cb = (TGCheckButton *) pr->fFrame;
1224 Bool_t was = !cb->IsDown();
1225 cb->HandleButton(&eventSt);
1226 Bool_t now = !cb->IsDown();
1227 if ((!was && now) || (was && !now))
1228 CheckToggled(name, !now, val); // emit CheckToggled
1229 break;
1230 }
1231 case INPUT_TYPE_Text:
1232 case INPUT_TYPE_Password: {
1233 TGTextEntry *te = (TGTextEntry *) pr->fFrame;
1234 te->SetFocus();
1235 break;
1236 }
1237 case INPUT_TYPE_Select: {
1239 eventSt.fUser[0] = childdum;
1240 if (pr->fFrame->InheritsFrom("TGComboBox"))
1241 ((TGComboBox *)pr->fFrame)->HandleButton(&eventSt);
1242 else if (pr->fFrame->InheritsFrom("TGListBox"))
1243 ((TGListBox *)pr->fFrame)->HandleButton(&eventSt);
1244 InputSelected(name, val); // emit InputSelected
1246 break;
1247 }
1248 default:
1249 break;
1250 }
1251 return kTRUE;
1252}
1253
1254////////////////////////////////////////////////////////////////////////////////
1255/// Handle radio button event.
1256
1258{
1259 TGHtmlInput *pr;
1260 for (pr = fFirstInput; pr; pr = pr->fINext) {
1261 if ((pr->fPForm == p->fPForm) && (pr->fItype == INPUT_TYPE_Radio)) {
1262 if (pr != p) {
1263 if (strcmp(pr->MarkupArg("name", ""), p->MarkupArg("name", "")) == 0) {
1264 ((TGRadioButton *)pr->fFrame)->SetState(kButtonUp);
1265 }
1266 }
1267 }
1268 }
1269
1270 return kTRUE;
1271}
1272
1273////////////////////////////////////////////////////////////////////////////////
1274/// Emit ButtonClicked() signal.
1275
1276void TGHtml::ButtonClicked(const char *name, const char *val)
1277{
1278 Long_t args[2];
1279
1280 args[0] = (Long_t)name;
1281 args[1] = (Long_t)val;
1282
1283 Emit("ButtonClicked(char*,char*)", args);
1284}
1285
1286////////////////////////////////////////////////////////////////////////////////
1287/// Emit CheckToggled() signal.
1288
1289void TGHtml::CheckToggled(const char *name, Bool_t on, const char *val)
1290{
1291 Long_t args[3];
1292
1293 args[0] = (Long_t)name;
1294 args[1] = on;
1295 args[2] = (Long_t)val;
1296
1297 Emit("CheckToggled(char*,Bool_t,char*)", args);
1298}
1299
1300////////////////////////////////////////////////////////////////////////////////
1301/// Emit RadioChanged() signal.
1302
1303void TGHtml::RadioChanged(const char *name, const char *val)
1304{
1305 Long_t args[2];
1306
1307 args[0] = (Long_t)name;
1308 args[1] = (Long_t)val;
1309
1310 Emit("RadioChanged(char*,char*)", args);
1311}
1312
1313////////////////////////////////////////////////////////////////////////////////
1314/// Emit Selected() signal.
1315
1316void TGHtml::InputSelected(const char *name, const char *val)
1317{
1318 Long_t args[2];
1319
1320 args[0] = (Long_t)name;
1321 args[1] = (Long_t)val;
1322
1323 Emit("InputSelected(char*,char*)", args);
1324}
1325
1326////////////////////////////////////////////////////////////////////////////////
1327/// Emit SubmitClicked() signal.
1328
1329void TGHtml::SubmitClicked(const char *val)
1330{
1331 Emit("SubmitClicked(char*)", val);
1332}
1333
1334////////////////////////////////////////////////////////////////////////////////
1335/// Handle mouse button event.
1336
1338{
1339 int amount, ch;
1340
1341 ch = fCanvas->GetHeight();
1342 amount = fScrollVal.fY * TMath::Max(ch/6, 1);
1343
1344 int ix = event->fX + fVisible.fX;
1345 int iy = event->fY + fVisible.fY;
1346 TGHtmlInput *pr = GetInputElement(ix, iy);
1347 if (pr) {
1348 HandleHtmlInput(pr, event);
1349 }
1350 if ((event->fType == kButtonPress) && (event->fCode == kButton1)) {
1351 int x = event->fX + fVisible.fX;
1352 int y = event->fY + fVisible.fY;
1353 const char *uri = GetHref(x, y);
1354
1355#if 0 // insertion cursor test
1356 char ix[20];
1357 sprintf(ix, "begin");
1358 SetInsert(ix);
1359#endif
1360
1361 if (uri) {
1362 uri = ResolveUri(uri);
1363 if (uri) {
1364 MouseDown(uri);
1365 //!!delete[] uri;
1366 }
1367 }
1368 } else if (event->fCode == kButton4) {
1370 } else if (event->fCode == kButton5) {
1372 } else {
1373 return TGView::HandleButton(event);
1374 }
1375 return kTRUE;
1376}
1377
1378////////////////////////////////////////////////////////////////////////////////
1379/// handle mouse motion events
1380
1382{
1383 int x = event->fX + fVisible.fX;
1384 int y = event->fY + fVisible.fY;
1385 const char *uri = GetHref(x, y);
1386
1387 if (uri) {
1388 gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kHand));
1389 } else {
1390 gVirtualX->SetCursor(fId, gVirtualX->CreateCursor(kPointer));
1391 }
1392
1393 if (uri != fLastUri) {
1394 fLastUri = uri;
1395 if (uri) uri = ResolveUri(uri);
1396 MouseOver(uri);
1397 //!!if (uri) delete [] uri;
1398 }
1399
1400 return kTRUE;
1401}
1402
1403////////////////////////////////////////////////////////////////////////////////
1404/// The rendering and layout routines should call this routine in order to
1405/// get a font structure. The iFont parameter specifies which of the N_FONT
1406/// fonts should be obtained. The font is allocated if necessary.
1407
1409{
1410 TGFont *toFree = 0;
1411
1412 if (iFont < 0) iFont = 0;
1413 if (iFont >= N_FONT) { iFont = N_FONT - 1; CANT_HAPPEN; }
1414
1415 // If the font has previously been allocated, but the "fontValid" bitmap
1416 // shows it is no longer valid, then mark it for freeing later. We use
1417 // a policy of allocate-before-free because xclass' font cache operates
1418 // much more efficiently that way.
1419
1420 if (!FontIsValid(iFont) && fAFont[iFont] != 0) {
1421 toFree = fAFont[iFont];
1422 fAFont[iFont] = 0;
1423 }
1424
1425 // If we need to allocate a font, first construct the font name then
1426 // allocate it.
1427
1428 if (fAFont[iFont] == 0) {
1429 char name[200]; // Name of the font
1430 const char *familyStr = "";
1431 int iFamily;
1432 int iSize;
1433 int size;
1434
1435 iFamily = FontFamily(iFont) >> 3;
1436 iSize = FontSize(iFont) + 1;
1437
1438 switch (iFamily) {
1439//#define TIMES
1440#ifdef TIMES
1441 case 0: familyStr = "times -%d"; break;
1442 case 1: familyStr = "times -%d bold"; break;
1443 case 2: familyStr = "times -%d italic"; break;
1444 case 3: familyStr = "times -%d bold italic"; break;
1445 case 4: familyStr = "courier -%d"; break;
1446 case 5: familyStr = "courier -%d bold"; break;
1447 case 6: familyStr = "courier -%d italic"; break;
1448 case 7: familyStr = "courier -%d bold italic"; break;
1449 default: familyStr = "times -16"; CANT_HAPPEN;
1450#else
1451 case 0: familyStr = "helvetica -%d"; break;
1452 case 1: familyStr = "helvetica -%d bold"; break;
1453 case 2: familyStr = "helvetica -%d italic"; break;
1454 case 3: familyStr = "helvetica -%d bold italic"; break;
1455 case 4: familyStr = "courier -%d"; break;
1456 case 5: familyStr = "courier -%d bold"; break;
1457 case 6: familyStr = "courier -%d italic"; break;
1458 case 7: familyStr = "courier -%d bold italic"; break;
1459 default: familyStr = "helvetica -14"; CANT_HAPPEN;
1460#endif
1461 }
1462#if 0
1463 switch (iSize) {
1464 case 1: size = 6+finc/*8*/; break;
1465 case 2: size = 10+finc/*10*/; break;
1466 case 3: size = 12+finc/*12*/; break;
1467 case 4: size = 14+finc/*14*/; break;
1468 case 5: size = 20+finc/*16*/; break;
1469 case 6: size = 24+finc/*18*/; break;
1470 case 7: size = 30+finc/*24*/; break;
1471 default: size = 14+finc/*14*/; CANT_HAPPEN;
1472 }
1473#else
1474 switch (iSize) {
1475 case 1: size = 8; break;
1476 case 2: size = 10; break;
1477 case 3: size = 12; break;
1478 case 4: size = 14; break;
1479 case 5: size = 16; break;
1480 case 6: size = 18; break;
1481 case 7: size = 24; break;
1482 default: size = 14; CANT_HAPPEN;
1483 }
1484#endif
1485#ifdef TIMES
1486 if (iFamily < 4) size += 2;
1487#endif
1488
1489 snprintf(name, 199, familyStr, size);
1490
1491 // Get the named font
1492 fAFont[iFont] = fClient->GetFont(name);
1493
1494 if (fAFont[iFont] == 0) {
1495 fprintf(stderr, "TGHtml: could not get font \"%s\", trying fixed\n",
1496 name);
1497 fAFont[iFont] = fClient->GetFont("fixed");
1498 }
1499 if (fAFont[iFont] == 0 ){
1500 fprintf(stderr, "TGHtml: could not get font \"fixed\", trying "
1501 "\"helvetica -12\"\n");
1502 fAFont[iFont] = fClient->GetFont("helvetica -12");
1503 }
1504 FontSetValid(iFont);
1505 }
1506
1507 // Free the expired font, if any.
1508
1509 if (toFree) fClient->FreeFont(toFree);
1510
1511 return fAFont[iFont];
1512}
1513
1514////////////////////////////////////////////////////////////////////////////////
1515/// Only support rect and circles for now
1516
1517int TGHtml::InArea(TGHtmlMapArea *p, int left, int top, int x, int y)
1518{
1519 int *ip = p->fCoords;
1520 if (!ip) return 0;
1521
1522 if (p->fMType == HTML_MAP_RECT) {
1523 return ((left + ip[0]) <= x && (left + ip[2]) >= x &&
1524 (top + ip[1]) <= y && (top + ip[3]) >= y);
1525 } else if (p->fMType == HTML_MAP_CIRCLE) {
1526 int dx = left + ip[0] - x;
1527 int dy = top + ip[1] - y;
1528 return (dx * dx + dy * dy <= ip[2] * ip[2]);
1529 }
1530 return 0;
1531}
1532
1533////////////////////////////////////////////////////////////////////////////////
1534/// Returns html map element.
1535
1537{
1539 const char *z, *zb;
1540
1541 while (p) {
1542 if (p->fType == Html_MAP) {
1543 z = p->MarkupArg("name", 0);
1544 zb = p->MarkupArg("shape", 0);
1545 if (zb && *zb != 'r') return 0;
1546 if (z && !strcmp(z, name)) return p;
1547 }
1548 p = p->fPNext;
1549 }
1550 return 0;
1551}
1552
1553////////////////////////////////////////////////////////////////////////////////
1554/// Compute the squared distance between two colors
1555
1557{
1558 float x, y, z;
1559
1560 x = 0.30 * (pA->fRed - pB->fRed);
1561 y = 0.61 * (pA->fGreen - pB->fGreen);
1562 z = 0.11 * (pA->fBlue - pB->fBlue);
1563
1564 return x*x + y*y + z*z;
1565}
1566
1567////////////////////////////////////////////////////////////////////////////////
1568/// This routine returns an index between 0 and N_COLOR-1 which indicates
1569/// which ColorStruct_t structure in the fApColor[] array should be used to describe
1570/// the color specified by the given name.
1571
1572int TGHtml::GetColorByName(const char *zColor)
1573{
1574 ColorStruct_t *pNew;
1575 int iColor;
1576 const char *name; // unique!
1577 int i, n;
1578 char zAltColor[16];
1579
1580 // Netscape accepts color names that are just HEX values, without
1581 // the # up front. This isn't valid HTML, but we support it for
1582 // compatibility.
1583
1584 n = strlen(zColor);
1585 if (n == 6 || n == 3 || n == 9 || n == 12) {
1586 for (i = 0; i < n; i++) {
1587 if (!isxdigit(zColor[i])) break;
1588 }
1589 if (i == n) {
1590 snprintf(zAltColor, 15, "#%s", zColor);
1591 } else {
1592 strlcpy(zAltColor, zColor, sizeof(zAltColor));
1593 }
1594 name = GetUid(zAltColor);
1595 } else {
1596 name = GetUid(zColor);
1597 }
1598
1599 pNew = AllocColor(name);
1600 if (pNew == 0) {
1601 return 0; // Color 0 is always the default
1602 }
1603
1604 iColor = GetColorByValue(pNew);
1605 FreeColor(pNew);
1606
1607 return iColor;
1608}
1609
1610
1611// Macros used in the computation of appropriate shadow colors.
1612
1613#define MAX_COLOR 65535
1614#define MAX(A,B) ((A)<(B)?(B):(A))
1615#define MIN(A,B) ((A)<(B)?(A):(B))
1616
1617////////////////////////////////////////////////////////////////////////////////
1618/// Check to see if the given color is too dark to be easily distinguished
1619/// from black.
1620
1622{
1623 float x, y, z;
1624
1625 x = 0.50 * p->fRed;
1626 y = 1.00 * p->fGreen;
1627 z = 0.28 * p->fBlue;
1628 return (x*x + y*y + z*z) < (0.05 * MAX_COLOR * MAX_COLOR);
1629}
1630
1631////////////////////////////////////////////////////////////////////////////////
1632/// Given that the background color is iBgColor, figure out an
1633/// appropriate color for the dark part of a 3D shadow.
1634
1636{
1637 if (fIDark[iBgColor] == 0) {
1638 ColorStruct_t *pRef, val;
1639 val.fMask = kDoRed | kDoGreen | kDoBlue;
1640 val.fPixel = 0;
1641 pRef = fApColor[iBgColor];
1642 if (IsDarkColor(pRef)) {
1643 int t1, t2;
1644 t1 = (int) MIN(MAX_COLOR, pRef->fRed * 1.2);
1645 t2 = (pRef->fRed * 3 + MAX_COLOR) / 4;
1646 val.fRed = MAX(t1, t2);
1647 t1 = (int) MIN(MAX_COLOR, pRef->fGreen * 1.2);
1648 t2 = (pRef->fGreen * 3 + MAX_COLOR) / 4;
1649 val.fGreen = MAX(t1, t2);
1650 t1 = (int) MIN(MAX_COLOR, pRef->fBlue * 1.2);
1651 t2 = (pRef->fBlue * 3 + MAX_COLOR) / 4;
1652 val.fBlue = MAX(t1, t2);
1653 } else {
1654 val.fRed = (unsigned short) (pRef->fRed * 0.6);
1655 val.fGreen = (unsigned short) (pRef->fGreen * 0.6);
1656 val.fBlue = (unsigned short) (pRef->fBlue * 0.6);
1657 }
1658 fIDark[iBgColor] = GetColorByValue(&val) + 1;
1659 }
1660
1661 return fIDark[iBgColor] - 1;
1662}
1663
1664////////////////////////////////////////////////////////////////////////////////
1665/// Check to see if the given color is too light to be easily distinguished
1666/// from white.
1667
1669{
1670 return p->fGreen >= 0.85 * MAX_COLOR;
1671}
1672
1673////////////////////////////////////////////////////////////////////////////////
1674/// Given that the background color is iBgColor, figure out an
1675/// appropriate color for the bright part of the 3D shadow.
1676
1678{
1679 if (fILight[iBgColor] == 0) {
1680 ColorStruct_t *pRef, val;
1681 val.fMask = kDoRed | kDoGreen | kDoBlue;
1682 val.fPixel = 0;
1683 pRef = fApColor[iBgColor];
1684 if (IsLightColor(pRef)) {
1685 val.fRed = (unsigned short) (pRef->fRed * 0.9);
1686 val.fGreen = (unsigned short) (pRef->fGreen * 0.9);
1687 val.fBlue = (unsigned short) (pRef->fBlue * 0.9);
1688 } else {
1689 int t1, t2;
1690 t1 = (int) MIN(MAX_COLOR, pRef->fGreen * 1.4);
1691 t2 = (pRef->fGreen + MAX_COLOR) / 2;
1692 val.fGreen = MAX(t1, t2);
1693 t1 = (int) MIN(MAX_COLOR, pRef->fRed * 1.4);
1694 t2 = (pRef->fRed + MAX_COLOR) / 2;
1695 val.fRed = MAX(t1, t2);
1696 t1 = (int) MIN(MAX_COLOR, pRef->fBlue * 1.4);
1697 t2 = (pRef->fBlue + MAX_COLOR) / 2;
1698 val.fBlue = MAX(t1, t2);
1699 }
1700 fILight[iBgColor] = GetColorByValue(&val) + 1;
1701 }
1702
1703 return fILight[iBgColor] - 1;
1704}
1705
1706////////////////////////////////////////////////////////////////////////////////
1707/// Find a color integer for the color whose color components
1708/// are given by pRef.
1709
1711{
1712 int i;
1713 float dist;
1714 float closestDist;
1715 int closest;
1716 int r, g, b;
1717# define COLOR_MASK 0xf800
1718
1719 // Search for an exact match
1720 r = pRef->fRed & COLOR_MASK;
1721 g = pRef->fGreen & COLOR_MASK;
1722 b = pRef->fBlue & COLOR_MASK;
1723 for (i = 0; i < N_COLOR; i++) {
1724 ColorStruct_t *p = fApColor[i];
1725 if (p &&
1726 ((p->fRed & COLOR_MASK) == r) &&
1727 ((p->fGreen & COLOR_MASK) == g) &&
1728 ((p->fBlue & COLOR_MASK) == b)) {
1729 fColorUsed |= (1<<i);
1730 return i;
1731 }
1732 }
1733
1734 // No exact matches. Look for a completely unused slot
1735 for (i = N_PREDEFINED_COLOR; i < N_COLOR; i++) {
1736 if (fApColor[i] == 0) {
1737 fApColor[i] = AllocColorByValue(pRef);
1738 fColorUsed |= (1<<i);
1739 return i;
1740 }
1741 }
1742
1743 // No empty slots. Look for a slot that contains a color that
1744 // isn't currently in use.
1745 for (i = N_PREDEFINED_COLOR; i < N_COLOR; i++) {
1746 if (((fColorUsed >> i) & 1) == 0) {
1747 FreeColor(fApColor[i]);
1748 fApColor[i] = AllocColorByValue(pRef);
1749 fColorUsed |= (1<<i);
1750 return i;
1751 }
1752 }
1753
1754 // Ok, find the existing color that is closest to the color requested
1755 // and use it.
1756 closest = 0;
1757 closestDist = ColorDistance(pRef, fApColor[0]);
1758 for (i = 1; i < N_COLOR; i++) {
1759 dist = ColorDistance(pRef, fApColor[i]);
1760 if (dist < closestDist) {
1761 closestDist = dist;
1762 closest = i;
1763 }
1764 }
1765
1766 return closest;
1767}
1768
1769////////////////////////////////////////////////////////////////////////////////
1770/// This routine searchs for a hyperlink beneath the coordinates x,y
1771/// and returns a pointer to the HREF for that hyperlink. The text
1772/// is held in one of the markup argv[] fields of the <a> markup.
1773
1774const char *TGHtml::GetHref(int x, int y, const char **target)
1775{
1776 TGHtmlBlock *pBlock;
1777 TGHtmlElement *pElem;
1778
1779 for (pBlock = fFirstBlock; pBlock; pBlock = pBlock->fBNext) {
1780 if (pBlock->fTop > y || pBlock->fBottom < y ||
1781 pBlock->fLeft > x || pBlock->fRight < x) continue;
1782 pElem = pBlock->fPNext;
1783 if (pElem->fType == Html_IMG) {
1784 TGHtmlImageMarkup *image = (TGHtmlImageMarkup *) pElem;
1785 if (image->fPMap) {
1786 pElem = image->fPMap->fPNext;
1787 while (pElem && pElem->fType != Html_EndMAP) {
1788 if (pElem->fType == Html_AREA) {
1789 if (InArea((TGHtmlMapArea *) pElem, pBlock->fLeft, pBlock->fTop, x, y)) {
1790 if (target) *target = pElem->MarkupArg("target", 0);
1791 return pElem->MarkupArg("href", 0);
1792 }
1793 }
1794 pElem = pElem->fPNext;
1795 }
1796 continue;
1797 }
1798 }
1799 if ((pElem->fStyle.fFlags & STY_Anchor) == 0) continue;
1800 switch (pElem->fType) {
1801 case Html_Text:
1802 case Html_Space:
1803 case Html_IMG:
1804 while (pElem && pElem->fType != Html_A) pElem = pElem->fPPrev;
1805 if (pElem == 0 || pElem->fType != Html_A) break;
1806 if (target) *target = pElem->MarkupArg("target", 0);
1807 return pElem->MarkupArg("href", 0);
1808
1809 default:
1810 break;
1811 }
1812 }
1813
1814 return 0;
1815}
1816
1817////////////////////////////////////////////////////////////////////////////////
1818/// Return coordinates of item
1819
1820int TGHtml::ElementCoords(TGHtmlElement *p, int /*i*/, int pct, int *coords)
1821{
1822 TGHtmlBlock *pBlock;
1823
1824 while (p && p->fType != Html_Block) p = p->fPPrev;
1825 if (!p) return 1;
1826
1827 pBlock = (TGHtmlBlock *) p;
1828 if (pct) {
1829 TGHtmlElement *pEnd = fPLast;
1830 TGHtmlBlock *pb2;
1831 while (pEnd && pEnd->fType != Html_Block) pEnd = pEnd->fPPrev;
1832 pb2 = (TGHtmlBlock *) pEnd;
1833#define HGCo(dir) (pb2 && pb2->dir) ? pBlock->dir * 100 / pb2->dir : 0
1834 coords[0] = HGCo(fLeft);
1835 coords[1] = HGCo(fTop);
1836 coords[3] = HGCo(fRight);
1837 coords[4] = HGCo(fBottom);
1838 } else {
1839 coords[0] = pBlock->fLeft;
1840 coords[1] = pBlock->fTop;
1841 coords[2] = pBlock->fRight;
1842 coords[3] = pBlock->fBottom;
1843 }
1844 return 0;
1845}
1846
1847////////////////////////////////////////////////////////////////////////////////
1848/// Returns html element matching attribute name and value.
1849
1850TGHtmlElement *TGHtml::AttrElem(const char *name, char *value)
1851{
1852 TGHtmlElement *p;
1853 const char *z;
1854
1855 for (p = fPFirst; p; p = p->fPNext) {
1856 if (p->fType != Html_A) continue;
1857 z = p->MarkupArg(name, 0);
1858 if (z && (strcmp(z, value) == 0)) return p;
1859 }
1860 return 0;
1861}
1862
1863////////////////////////////////////////////////////////////////////////////////
1864/// Given the selection end-points in fSelBegin and fSelEnd, recompute
1865/// pSelBeginBlock and fPSelEndBlock, then call UpdateSelectionDisplay()
1866/// to update the display.
1867///
1868/// This routine should be called whenever the selection changes or
1869/// whenever the set of TGHtmlBlock structures change.
1870
1871void TGHtml::UpdateSelection(int forceUpdate)
1872{
1873 TGHtmlBlock *pBlock;
1874 int index;
1875 int needUpdate = forceUpdate;
1876 int temp;
1877
1878 if (fSelEnd.fP == 0) fSelBegin.fP = 0;
1879
1880 IndexToBlockIndex(fSelBegin, &pBlock, &index);
1881 if (needUpdate || pBlock != fPSelStartBlock) {
1882 needUpdate = 1;
1884 fPSelStartBlock = pBlock;
1885 fSelStartIndex = index;
1886 } else if (index != fSelStartIndex) {
1887 RedrawBlock(pBlock);
1888 fSelStartIndex = index;
1889 }
1890
1891 if (fSelBegin.fP == 0) fSelEnd.fP = 0;
1892
1893 IndexToBlockIndex(fSelEnd, &pBlock, &index);
1894 if (needUpdate || pBlock != fPSelEndBlock) {
1895 needUpdate = 1;
1897 fPSelEndBlock = pBlock;
1898 fSelEndIndex = index;
1899 } else if (index != fSelEndIndex) {
1900 RedrawBlock(pBlock);
1901 fSelEndIndex = index;
1902 }
1903
1906 temp = fSelStartIndex;
1908 fSelEndIndex = temp;
1909 }
1910
1911 if (needUpdate) {
1914 }
1915}
1916
1917////////////////////////////////////////////////////////////////////////////////
1918/// The fPSelStartBlock and fPSelEndBlock values have been changed.
1919/// This routine's job is to loop over all TGHtmlBlocks and either
1920/// set or clear the HTML_Selected bits in the .fFlags field
1921/// as appropriate. For every TGHtmlBlock where the bit changes,
1922/// mark that block for redrawing.
1923
1925{
1926 int selected = 0;
1927 SHtmlIndex_t tempIndex;
1928 TGHtmlBlock *pTempBlock;
1929 int temp;
1930 TGHtmlBlock *p;
1931
1932 for (p = fFirstBlock; p; p = p->fBNext) {
1933 if (p == fPSelStartBlock) {
1934 selected = 1;
1935 RedrawBlock(p);
1936 } else if (!selected && p == fPSelEndBlock) {
1937 selected = 1;
1938 tempIndex = fSelBegin;
1940 fSelEnd = tempIndex;
1941 pTempBlock = fPSelStartBlock;
1943 fPSelEndBlock = pTempBlock;
1944 temp = fSelStartIndex;
1946 fSelEndIndex = temp;
1947 RedrawBlock(p);
1948 }
1949 if (p->fFlags & HTML_Selected) {
1950 if (!selected) {
1951 p->fFlags &= ~HTML_Selected;
1952 RedrawBlock(p);
1953 }
1954 } else {
1955 if (selected) {
1956 p->fFlags |= HTML_Selected;
1957 RedrawBlock(p);
1958 }
1959 }
1960 if (p == fPSelEndBlock) {
1961 selected = 0;
1962 RedrawBlock(p);
1963 }
1964 }
1965}
1966
1967////////////////////////////////////////////////////////////////////////////////
1968/// Clear selection.
1969
1971{
1972 if (fExportSelection) {
1973 // clear selection
1974 fPSelStartBlock = 0;
1975 fPSelEndBlock = 0;
1976 fSelBegin.fP = 0;
1977 fSelEnd.fP = 0;
1979 }
1980}
1981
1982////////////////////////////////////////////////////////////////////////////////
1983/// Set selection.
1984
1985int TGHtml::SelectionSet(const char *startIx, const char *endIx)
1986{
1987 SHtmlIndex_t sBegin, sEnd;
1988 int bi, ei;
1989
1990 if (GetIndex(startIx, &sBegin.fP, &sBegin.fI)) {
1991 // malformed start index
1992 return kFALSE;
1993 }
1994
1995 if (GetIndex(endIx, &sEnd.fP, &sEnd.fI)) {
1996 // malformed end index
1997 return kFALSE;
1998 }
1999
2000 bi = TokenNumber(sBegin.fP);
2001 ei = TokenNumber(sEnd.fP);
2002
2003 if (!(sBegin.fP && sEnd.fP)) return kTRUE;
2004
2005 if (bi < ei || (bi == ei && sBegin.fI <= sEnd.fI)) {
2006 fSelBegin = sBegin;
2007 fSelEnd = sEnd;
2008 } else {
2009 fSelBegin = sEnd;
2010 fSelEnd = sBegin;
2011 }
2012
2013 UpdateSelection(0);
2014 if (fExportSelection) {
2015 // TODO:
2016 // get selection ownership ... fId, XA_PRIMARY
2017 // selection lost handler must directly call LostSelection()
2018 }
2019
2020 return kTRUE;
2021}
2022
2023////////////////////////////////////////////////////////////////////////////////
2024/// Recompute the position of the insertion cursor based on the
2025/// position in fIns.
2026
2028{
2031 if (fInsTimer == 0) {
2032 fInsStatus = 0;
2033 FlashCursor();
2034 }
2035}
2036
2037////////////////////////////////////////////////////////////////////////////////
2038/// Set the position of the insertion cursor.
2039
2040int TGHtml::SetInsert(const char *insIx)
2041{
2042 SHtmlIndex_t i;
2043
2044 if (!insIx) {
2046 fInsStatus = 0;
2047 fPInsBlock = 0;
2048 fIns.fP = 0;
2049 } else {
2050 if (GetIndex(insIx, &i.fP, &i.fI)) {
2051 // malformed index
2052 return kFALSE;
2053 }
2055 fIns = i;
2056 UpdateInsert();
2057 }
2058
2059 return kTRUE;
2060}
2061
2062////////////////////////////////////////////////////////////////////////////////
2063/// Save a html widget as a C++ statement(s) on output stream out.
2064
2065void TGHtml::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2066{
2067 out << " TGHtml *";
2068 out << GetName() << " = new TGHtml(" << fParent->GetName()
2069 << "," << GetWidth() << "," << GetHeight()
2070 << ");"<< std::endl;
2071 if (option && strstr(option, "keep_names"))
2072 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
2073
2075 out << " " << GetName() << "->ChangeBackground(" << fCanvas->GetBackground() << ");" << std::endl;
2076 }
2077
2078 TString fn;
2079 TGText txt(GetText());
2080 fn.Form("Html%s.htm", GetName()+5);
2081 txt.Save(fn.Data());
2082 out << " " << "FILE *f = fopen(\"" << fn.Data() << "\", \"r\");" << std::endl;
2083 out << " " << "if (f) {" << std::endl;
2084 out << " " << GetName() << "->Clear();" << std::endl;
2085 out << " " << GetName() << "->Layout();" << std::endl;
2086 out << " " << GetName() << "->SetBaseUri(\"\");" << std::endl;
2087 out << " " << "char *buf = (char *)calloc(4096, sizeof(char));" << std::endl;
2088 out << " " << "while (fgets(buf, 4096, f)) {" << std::endl;
2089 out << " " << GetName() << "->ParseText(buf);" << std::endl;
2090 out << " " << "}" << std::endl;
2091 out << " " << "free(buf);" << std::endl;
2092 out << " " << "fclose(f);" << std::endl;
2093 out << " " << "}" << std::endl;
2094 out << " " << GetName() << "->Layout();" << std::endl;
2095}
l unsigned short
@ kButtonPress
Definition GuiTypes.h:60
@ kFocusIn
Definition GuiTypes.h:61
const Mask_t kGCForeground
Definition GuiTypes.h:288
const Mask_t kFocusChangeMask
Definition GuiTypes.h:169
const Mask_t kButtonPressMask
Definition GuiTypes.h:161
const Mask_t kExposureMask
Definition GuiTypes.h:165
const Mask_t kDoRed
Definition GuiTypes.h:319
Handle_t Pixmap_t
Pixmap handle.
Definition GuiTypes.h:30
const Mask_t kGCFont
Definition GuiTypes.h:300
const Mask_t kPointerMotionMask
Definition GuiTypes.h:163
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:38
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:162
const Mask_t kGCGraphicsExposures
Definition GuiTypes.h:302
@ kHand
Definition GuiTypes.h:374
@ kPointer
Definition GuiTypes.h:375
const Mask_t kDoGreen
Definition GuiTypes.h:320
const Mask_t kDoBlue
Definition GuiTypes.h:321
@ kButton4
Definition GuiTypes.h:215
@ kButton5
Definition GuiTypes.h:215
@ kButton1
Definition GuiTypes.h:214
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
ROOT::R::TRInterface & r
Definition Object.C:4
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
#define h(i)
Definition RSha256.hxx:106
const Bool_t kFALSE
Definition RtypesCore.h:92
long Long_t
Definition RtypesCore.h:54
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:166
@ Html_AREA
@ Html_Block
@ Html_Space
@ Html_Text
@ Html_A
@ Html_IMG
@ Html_EndA
@ Html_EndMAP
@ Html_MAP
#define MAX_COLOR
Definition TGHtml.cxx:1613
#define HGCo(dir)
int HtmlDepth
Definition TGHtml.cxx:63
#define COLOR_MASK
int HtmlTraceMask
Definition TGHtml.cxx:62
#define STYLER_RUNNING
Definition TGHtml.h:1329
#define HTML_MAP_CIRCLE
Definition TGHtml.h:464
#define HTML_Selected
Definition TGHtml.h:276
#define INPUT_TYPE_Radio
Definition TGHtml.h:618
#define COLOR_Selection
Definition TGHtml.h:199
#define FONT_Default
Definition TGHtml.h:173
#define INPUT_TYPE_Button
Definition TGHtml.h:625
#define COLOR_Unvisited
Definition TGHtml.h:197
#define REDRAW_PENDING
Definition TGHtml.h:1320
#define REDRAW_FOCUS
Definition TGHtml.h:1326
#define DEF_HTML_EXPORT_SEL
Definition TGHtml.h:1352
#define DEF_HTML_INSERT_OFF_TIME
Definition TGHtml.h:1357
#define HTML_MAP_RECT
Definition TGHtml.h:463
#define FONT_Any
Definition TGHtml.h:172
#define FontSetValid(I)
Definition TGHtml.h:180
#define HTML_RELIEF_SUNKEN
Definition TGHtml.h:51
#define CANT_HAPPEN
Definition TGHtml.h:59
#define COLOR_Background
Definition TGHtml.h:200
#define INPUT_TYPE_Submit
Definition TGHtml.h:621
#define LARGE_NUMBER
Definition TGHtml.h:1345
#define GOT_FOCUS
Definition TGHtml.h:1321
#define HTML_RELIEF_RAISED
Definition TGHtml.h:52
#define RELAYOUT
Definition TGHtml.h:1324
#define N_PREDEFINED_COLOR
Definition TGHtml.h:201
#define DEF_HTML_INSERT_ON_TIME
Definition TGHtml.h:1358
#define STY_Anchor
Definition TGHtml.h:237
#define N_CACHE_GC
Definition TGHtml.h:818
#define REDRAW_IMAGES
Definition TGHtml.h:1331
#define INPUT_TYPE_Text
Definition TGHtml.h:622
#define ANIMATE_IMAGES
Definition TGHtml.h:1332
#define STY_Underline
Definition TGHtml.h:235
#define DEF_HTML_SELECTION_COLOR
Definition TGHtml.h:1362
#define N_COLOR
Definition TGHtml.h:194
#define FontFamily(X)
Definition TGHtml.h:171
#define N_FONT
Definition TGHtml.h:165
#define INPUT_TYPE_Password
Definition TGHtml.h:617
#define DEF_HTML_UNVISITED
Definition TGHtml.h:1364
#define RESIZE_ELEMENTS
Definition TGHtml.h:1325
#define FontSize(X)
Definition TGHtml.h:170
#define EXTEND_LAYOUT
Definition TGHtml.h:1328
#define COLOR_Normal
Definition TGHtml.h:196
#define VSCROLL
Definition TGHtml.h:1323
#define INPUT_TYPE_Checkbox
Definition TGHtml.h:613
#define INPUT_TYPE_Select
Definition TGHtml.h:620
#define REDRAW_TEXT
Definition TGHtml.h:1327
#define HSCROLL
Definition TGHtml.h:1322
#define ALIGN_None
Definition TGHtml.h:211
#define COLOR_Visited
Definition TGHtml.h:198
#define DEF_HTML_VISITED
Definition TGHtml.h:1365
#define FontIsValid(I)
Definition TGHtml.h:179
XFontStruct * id
Definition TGX11.cxx:109
char name[80]
Definition TGX11.cxx:110
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2510
#define gVirtualX
Definition TVirtualX.h:338
#define snprintf
Definition civetweb.c:1540
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event.
virtual Bool_t IsDown() const
Definition TGButton.h:312
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get a font from the font pool.
Definition TGClient.cxx:347
Colormap_t GetDefaultColormap() const
Definition TGClient.h:154
void FreeFont(const TGFont *font)
Free a font.
Definition TGClient.cxx:363
FontH_t GetFontHandle() const
Definition TGFont.h:192
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:324
void RemoveInput(UInt_t emask)
Remove events specified in emask from the events the frame should handle.
Definition TGFrame.cxx:333
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:694
UInt_t GetHeight() const
Definition TGFrame.h:249
virtual Pixel_t GetBackground() const
Definition TGFrame.h:216
UInt_t GetWidth() const
Definition TGFrame.h:248
GContext_t GetGC() const
Definition TGGC.h:50
void SetTileStipYOrigin(Int_t v)
Y offset for tile or stipple operations.
Definition TGGC.cxx:399
void SetTileStipXOrigin(Int_t v)
X offset for tile or stipple operations.
Definition TGGC.cxx:388
TGHtmlBlock * fBNext
Definition TGHtml.h:720
Html_u16_t fRight
Definition TGHtml.h:718
Html_u16_t fLeft
Definition TGHtml.h:718
int fBottom
Definition TGHtml.h:717
Html_u8_t fFlags
Definition TGHtml.h:265
Html_u8_t fType
Definition TGHtml.h:264
SHtmlStyle_t fStyle
Definition TGHtml.h:263
virtual const char * MarkupArg(const char *, const char *)
Definition TGHtml.h:254
TGHtmlElement * fPPrev
Definition TGHtml.h:262
TGHtmlElement * fPNext
Definition TGHtml.h:261
TGHtmlImageMarkup * fINext
Definition TGHtml.h:553
Html_16_t fAscent
Definition TGHtml.h:546
Html_u8_t fRedrawNeeded
Definition TGHtml.h:542
Html_32_t fY
Definition TGHtml.h:549
Html_16_t fW
Definition TGHtml.h:545
TGHtmlElement * fPMap
Definition TGHtml.h:552
Html_16_t fH
Definition TGHtml.h:544
Html_16_t fX
Definition TGHtml.h:548
TTimer * fTimer
Definition TGHtml.h:526
TGHtmlImageMarkup * fPList
Definition TGHtml.h:524
TGHtmlImage * fPNext
Definition TGHtml.h:523
Html_u16_t fW
Definition TGHtml.h:597
Html_u8_t fItype
Definition TGHtml.h:602
Html_u16_t fH
Definition TGHtml.h:597
TGFrame * fFrame
Definition TGHtml.h:590
Html_u16_t fX
Definition TGHtml.h:596
TGHtmlForm * fPForm
Definition TGHtml.h:588
TGHtmlInput * fINext
Definition TGHtml.h:589
Html_32_t fY
Definition TGHtml.h:595
void Reset()
Reset the layout context.
int * fCoords
Definition TGHtml.h:473
virtual const char * MarkupArg(const char *tag, const char *zDefault)
Lookup an argument in the given markup with the name given.
int GetLightShadowColor(int iBgColor)
Given that the background color is iBgColor, figure out an appropriate color for the bright part of t...
Definition TGHtml.cxx:1677
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a html widget as a C++ statement(s) on output stream out.
Definition TGHtml.cxx:2065
TGHtmlElement * GetMap(const char *name)
Returns html map element.
Definition TGHtml.cxx:1536
int IsDarkColor(ColorStruct_t *p)
Check to see if the given color is too dark to be easily distinguished from black.
Definition TGHtml.cxx:1621
int fAddEndTags
Definition TGHtml.h:1245
ColorStruct_t * fFgColor
Definition TGHtml.h:1229
void RedrawArea(int left, int top, int right, int bottom)
If any part of the screen needs to be redrawn, then call this routine with the values of a box (in wi...
Definition TGHtml.cxx:779
int fICol
Definition TGHtml.h:1173
int GotoAnchor(const char *name)
Go to anchor position.
Definition TGHtml.cxx:451
TGHtmlBlock * fLastBlock
Definition TGHtml.h:1136
int SetInsert(const char *insIx)
Set the position of the insertion cursor.
Definition TGHtml.cxx:2040
virtual ~TGHtml()
HTML widget destructor.
Definition TGHtml.cxx:222
virtual void RadioChanged(const char *name, const char *val)
Emit RadioChanged() signal.
Definition TGHtml.cxx:1303
TGHtmlElement * fLoEndPtr
Definition TGHtml.h:1200
SHtmlIndex_t fSelBegin
Definition TGHtml.h:1148
char * fZGoto
Definition TGHtml.h:1272
int fParaAlignment
Definition TGHtml.h:1189
TGHtmlBlock * fPSelStartBlock
Definition TGHtml.h:1150
int fIdind
Definition TGHtml.h:1270
int fRadioIdx
Definition TGHtml.h:1144
int fInputIdx
Definition TGHtml.h:1143
const char * fZBase
Definition TGHtml.h:1259
int fUnderlineLinks
Definition TGHtml.h:1242
int IsLightColor(ColorStruct_t *p)
Check to see if the given color is too light to be easily distinguished from white.
Definition TGHtml.cxx:1668
void TokenizerAppend(const char *text)
Append text to the tokenizer engine.
TGHtmlImage * fImageList
Definition TGHtml.h:1236
TGHtmlElement * fPFirst
Definition TGHtml.h:1128
void AddStyle(TGHtmlElement *p)
This routine adds information to the input texts that doesn't change when the display is resized or w...
int fNForm
Definition TGHtml.h:1140
virtual void MouseDown(const char *uri)
Definition TGHtml.h:1116
void ScheduleRedraw()
Make sure that a call to the Redraw() routine has been queued.
Definition TGHtml.cxx:752
void LostSelection()
Clear selection.
Definition TGHtml.cxx:1970
const char * fLastUri
Definition TGHtml.h:1278
int fNToken
Definition TGHtml.h:1130
const char * GetHref(int x, int y, const char **target=0)
This routine searchs for a hyperlink beneath the coordinates x,y and returns a pointer to the HREF fo...
Definition TGHtml.cxx:1774
virtual TGFont * GetFont(int iFont)
The rendering and layout routines should call this routine in order to get a font structure.
Definition TGHtml.cxx:1408
SHtmlIndex_t fIns
Definition TGHtml.h:1162
void UpdateInsert()
Recompute the position of the insertion cursor based on the position in fIns.
Definition TGHtml.cxx:2027
int fAnchorFlags
Definition TGHtml.h:1191
char fFontValid[(N_FONT+7)/8]
Definition TGHtml.h:1220
int fExiting
Definition TGHtml.h:1279
TGHtmlElement * fLastSized
Definition TGHtml.h:1132
void LayoutDoc()
Advance the layout as far as possible.
void BlockDraw(TGHtmlBlock *pBlock, Drawable_t wid, int left, int top, int width, int height, Pixmap_t pixmap)
Display a single HtmlBlock. This is where all the drawing happens.
void IndexToBlockIndex(SHtmlIndex_t sIndex, TGHtmlBlock **ppBlock, int *piIndex)
Convert an Element-based index into a Block-based index.
int fLastGC
Definition TGHtml.h:1235
int GetColorByName(const char *zColor)
This routine returns an index between 0 and N_COLOR-1 which indicates which ColorStruct_t structure i...
Definition TGHtml.cxx:1572
void DrawImage(TGHtmlImageMarkup *image, Drawable_t wid, int left, int top, int right, int bottom)
Draw all or part of an image.
TGHtmlInput * fFormElemLast
Definition TGHtml.h:1198
void AnimateImage(TGHtmlImage *image)
TGImage *img = image->image;.
TGHtmlBlock * fPInsBlock
Definition TGHtml.h:1163
virtual void InputSelected(const char *name, const char *val)
Emit Selected() signal.
Definition TGHtml.cxx:1316
virtual void CheckToggled(const char *name, Bool_t on, const char *val)
Emit CheckToggled() signal.
Definition TGHtml.cxx:1289
int SelectionSet(const char *startIx, const char *endIx)
Set selection.
Definition TGHtml.cxx:1985
virtual void Clear(Option_t *="")
Erase all HTML from this widget and clear the screen.
Definition TGHtml.cxx:300
void UpdateSelectionDisplay()
The fPSelStartBlock and fPSelEndBlock values have been changed.
Definition TGHtml.cxx:1924
TGHtmlBlock * fPSelEndBlock
Definition TGHtml.h:1154
ColorStruct_t * fSelectionColor
Definition TGHtml.h:1232
virtual Bool_t HandleFocusChange(Event_t *event)
Handle focus change event.
Definition TGHtml.cxx:1122
int fInsOffTime
Definition TGHtml.h:1159
void FormBlocks()
Add additional blocks to the block list in order to cover all elements on the element list.
TGFont * fAFont[N_FONT]
Definition TGHtml.h:1219
int fVarind
Definition TGHtml.h:1247
int fFlags
Definition TGHtml.h:1269
virtual void ButtonClicked(const char *name, const char *val)
Emit ButtonClicked() signal.
Definition TGHtml.cxx:1276
ColorStruct_t * fHighlightBgColorPtr
Definition TGHtml.h:1216
void SetRuleRelief(int relief)
Sets relief mode of html rule.
Definition TGHtml.cxx:386
virtual void UpdateBackgroundStart()
Start background update.
Definition TGHtml.cxx:240
int fInsOnTime
Definition TGHtml.h:1158
int fVarId
Definition TGHtml.h:1141
int fDirtyBottom
Definition TGHtml.h:1268
SHtmlStyleStack_t * fStyleStack
Definition TGHtml.h:1188
int ParseText(char *text, const char *index=0)
Appends (or insert at the specified position) the given HTML text to the end of any HTML text that ma...
Definition TGHtml.cxx:315
virtual Bool_t HandleTimer(TTimer *timer)
Handle timer event.
Definition TGHtml.cxx:994
ColorStruct_t * fNewLinkColor
Definition TGHtml.h:1230
TGHtmlListStart * fInnerList
Definition TGHtml.h:1199
int fIPlaintext
Definition TGHtml.h:1175
void RedrawText(int y)
Call this routine to cause all of the rendered HTML at the virtual canvas coordinate of Y and beyond ...
Definition TGHtml.cxx:877
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event.
Definition TGHtml.cxx:1337
int fOverrideColors
Definition TGHtml.h:1241
virtual void MouseOver(const char *uri)
Definition TGHtml.h:1115
Bool_t HandleRadioButton(TGHtmlInput *p)
Handle radio button event.
Definition TGHtml.cxx:1257
int fMaxY
Definition TGHtml.h:1262
Cursor_t fCursor
Definition TGHtml.h:1261
virtual Bool_t HandleMotion(Event_t *event)
handle mouse motion events
Definition TGHtml.cxx:1381
TGHtmlInput * GetInputElement(int x, int y)
This routine searchs for a hyperlink beneath the coordinates x,y and returns a pointer to the HREF fo...
Definition TGHtml.cxx:1141
char * fZText
Definition TGHtml.h:1168
int fInsIndex
Definition TGHtml.h:1164
int fILight[N_COLOR]
Definition TGHtml.h:1227
int fNInput
Definition TGHtml.h:1139
void UpdateSelection(int forceUpdate)
Given the selection end-points in fSelBegin and fSelEnd, recompute pSelBeginBlock and fPSelEndBlock,...
Definition TGHtml.cxx:1871
int fNAlloc
Definition TGHtml.h:1170
void SetBaseUri(const char *uri)
Sets base URI.
Definition TGHtml.cxx:441
int fDirtyRight
Definition TGHtml.h:1268
void DeleteControls()
Delete all input controls.
ColorStruct_t * AllocColorByValue(ColorStruct_t *color)
Allocate system color by value.
Definition TGHtml.cxx:281
virtual Bool_t HandleIdleEvent(TGIdleHandler *i)
Handles idle event.
Definition TGHtml.cxx:763
TGHtmlInput * fFirstInput
Definition TGHtml.h:1137
void SetTableRelief(int relief)
Sets relief mode of html table.
Definition TGHtml.cxx:374
ColorStruct_t * AllocColor(const char *name)
Allocate system color by name.
Definition TGHtml.cxx:262
void HClear()
Erase all data from the HTML widget. Bring it back to an empty screen.
Definition TGHtml.cxx:891
int fRowAlignment
Definition TGHtml.h:1190
THashTable * fUidTable
Definition TGHtml.h:1276
ColorStruct_t * fHighlightColorPtr
Definition TGHtml.h:1218
int fFormPadding
Definition TGHtml.h:1239
GContext_t GetAnyGC()
Retrieve any valid GC.
Definition TGHtml.cxx:1107
Html_16_t fSelStartIndex
Definition TGHtml.h:1151
virtual Bool_t ItemLayout()
Layout html widget.
Definition TGHtml.cxx:824
TGHtmlScript * fPScript
Definition TGHtml.h:1179
TGHtmlBlock * fFirstBlock
Definition TGHtml.h:1135
void RedrawBlock(TGHtmlBlock *p)
Redraw the TGHtmlBlock given.
Definition TGHtml.cxx:856
int fInTr
Definition TGHtml.h:1193
TGIdleHandler * fIdle
Definition TGHtml.h:1181
int fMaxX
Definition TGHtml.h:1262
const char * GetUid(const char *string)
Given a string, this procedure returns a unique identifier for the string.
Definition TGHtml.cxx:480
void Redraw()
This routine is invoked in order to redraw all or part of the HTML widget.
Definition TGHtml.cxx:534
int GetLinkColor(const char *zURL)
For the markup <a href=XXX>, find out if the URL has been visited before or not.
Html_16_t fSelEndIndex
Definition TGHtml.h:1153
TGHtmlAnchor * fAnchorStart
Definition TGHtml.h:1195
int GetColorByValue(ColorStruct_t *pRef)
Find a color integer for the color whose color components are given by pRef.
Definition TGHtml.cxx:1710
int fIDark[N_COLOR]
Definition TGHtml.h:1226
int fDirtyTop
Definition TGHtml.h:1265
int fHasFrames
Definition TGHtml.h:1244
Long_t fColorUsed
Definition TGHtml.h:1224
int fDirtyLeft
Definition TGHtml.h:1265
GcCache_t fAGcCache[N_CACHE_GC]
Definition TGHtml.h:1233
TTimer * fInsTimer
Definition TGHtml.h:1161
TGHtmlElement * fPLast
Definition TGHtml.h:1129
SHtmlStyle_t PopStyleStack(int tag)
Pop a rendering style off of the stack.
void FreeColor(ColorStruct_t *color)
Free system color.
Definition TGHtml.cxx:253
void ComputeVirtualSize()
Computes virtual size of html area.
Definition TGHtml.cxx:498
int TokenNumber(TGHtmlElement *p)
Return the token number for the given TGHtmlElement.
int fInTd
Definition TGHtml.h:1194
int fRulePadding
Definition TGHtml.h:1258
int fRuleRelief
Definition TGHtml.h:1257
TGHtmlElement * AttrElem(const char *name, char *value)
Returns html element matching attribute name and value.
Definition TGHtml.cxx:1850
int fGcNextToFree
Definition TGHtml.h:1234
GContext_t GetGC(int color, int font)
Return a GC from the cache.
Definition TGHtml.cxx:1037
virtual char * ResolveUri(const char *uri)
This function resolves the specified URI and returns the result in a newly allocated string.
int InArea(TGHtmlMapArea *p, int left, int top, int x, int y)
Only support rect and circles for now.
Definition TGHtml.cxx:1517
virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw region defined by [x,y] [w,h].
Definition TGHtml.cxx:795
void PushStyleStack(int tag, SHtmlStyle_t style)
Push a new rendering style onto the stack.
TGHtmlElement * fNextPlaced
Definition TGHtml.h:1133
int fOverrideFonts
Definition TGHtml.h:1240
TImage * fBgImage
Definition TGHtml.h:1237
int fNComplete
Definition TGHtml.h:1171
int fInDt
Definition TGHtml.h:1192
TGHtmlLayoutContext fLayoutContext
Definition TGHtml.h:1207
int fExportSelection
Definition TGHtml.h:1251
ColorStruct_t * fBgColor
Definition TGHtml.h:1228
void RedrawEverything()
Call this routine to force the entire widget to be redrawn.
Definition TGHtml.cxx:867
virtual void SubmitClicked(const char *val)
Emit SubmitClicked() signal.
Definition TGHtml.cxx:1329
void UnderlineLinks(int onoff)
Set/reset html links underline.
Definition TGHtml.cxx:398
int fHighlightWidth
Definition TGHtml.h:1211
SHtmlIndex_t fSelEnd
Definition TGHtml.h:1149
SHtmlStyle_t GetCurrentStyle()
Get the current rendering style.
int MapControls()
Map any control that should be visible according to the current scroll position.
const char * GetText() const
Definition TGHtml.h:961
void ClearGcCache()
Clear the cache of GCs.
Definition TGHtml.cxx:506
int GetIndex(const char *zIndex, TGHtmlElement **ppToken, int *pIndex)
This routine decodes a complete index specification.
ColorStruct_t * fOldLinkColor
Definition TGHtml.h:1231
TGHtmlForm * fLoFormStart
Definition TGHtml.h:1201
TGHtmlInput * fFormElemStart
Definition TGHtml.h:1197
ColorStruct_t * fApColor[N_COLOR]
Definition TGHtml.h:1223
int ElementCoords(TGHtmlElement *p, int i, int pct, int *coords)
Return coordinates of item.
Definition TGHtml.cxx:1820
int fHasScript
Definition TGHtml.h:1243
int fTableRelief
Definition TGHtml.h:1256
TGHtmlForm * fFormStart
Definition TGHtml.h:1196
float ColorDistance(ColorStruct_t *pA, ColorStruct_t *pB)
Compute the squared distance between two colors.
Definition TGHtml.cxx:1556
void FlashCursor()
Flash the insertion cursor.
Definition TGHtml.cxx:1016
int GetDarkShadowColor(int iBgColor)
Given that the background color is iBgColor, figure out an appropriate color for the dark part of a 3...
Definition TGHtml.cxx:1635
int fInsStatus
Definition TGHtml.h:1160
TGHtml(const TGWindow *p, int w, int h, int id=-1)
HTML Widget constructor.
Definition TGHtml.cxx:75
Bool_t HandleHtmlInput(TGHtmlInput *pr, Event_t *event)
Handle html input (button, checkbox, ...) event.
Definition TGHtml.cxx:1166
int fInParse
Definition TGHtml.h:1271
int fTableBorderMin
Definition TGHtml.h:1246
SHtmlExtensions_t * fExts
Definition TGHtml.h:1274
char * fZBaseHref
Definition TGHtml.h:1260
TGHtmlInput * fLastInput
Definition TGHtml.h:1138
void ResetLayoutContext()
Reset the main layout context in the main widget.
Definition TGHtml.cxx:523
int fNText
Definition TGHtml.h:1169
TGClient * fClient
Definition TGObject.h:37
Handle_t GetId() const
Definition TGObject.h:47
Handle_t fId
Definition TGObject.h:36
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event.
virtual Bool_t IsDown() const
Definition TGButton.h:371
virtual void SetAccelerated(Bool_t m=kTRUE)
virtual void SetFocus()
Set focus to this text entry.
Bool_t Save(const char *fn)
Save text buffer to file fn.
Definition TGText.cxx:610
TGHScrollBar * fHsb
Definition TGView.h:62
virtual Bool_t HandleButton(Event_t *event)
handle button
Definition TGView.cxx:235
TGDimension fVirtualSize
Definition TGView.h:54
TGVScrollBar * fVsb
Definition TGView.h:63
TGLongPosition fVisible
Definition TGView.h:51
UInt_t fXMargin
Definition TGView.h:59
virtual void SetBackgroundColor(Pixel_t)
Set background color of the canvas frame.
Definition TGView.cxx:579
TGLongPosition fScrollVal
Definition TGView.h:53
TGViewFrame * fCanvas
Definition TGView.h:61
virtual void DrawRegion(Int_t x, Int_t y, UInt_t width, UInt_t height)
Draw region.
Definition TGView.cxx:194
TGGC fWhiteGC
Definition TGView.h:65
virtual void ScrollToPosition(TGLongPosition newPos)
Scroll the canvas to pos.
Definition TGView.cxx:451
UInt_t fYMargin
Definition TGView.h:60
virtual void Clear(Option_t *="")
Clear view.
Definition TGView.cxx:159
virtual void SetBackgroundPixmap(Pixmap_t p)
Set backgound pixmap.
Definition TGView.cxx:589
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:335
const TGWindow * fParent
Definition TGWindow.h:36
@ kIsHtmlView
Definition TGWindow.h:70
THashTable implements a hash table to store TObject's.
Definition THashTable.h:35
void Add(TObject *obj)
Add object to the hash table.
TObject * FindObject(const char *name) const
Find object using its name.
Collectable string class.
Definition TObjString.h:28
const char * GetName() const
Returns name of object.
Definition TObjString.h:38
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:696
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2309
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
TText * text
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Definition TMathBase.h:212
ULong_t fPixel
color pixel value (index in color table)
Definition GuiTypes.h:311
UShort_t fRed
red component (0..65535)
Definition GuiTypes.h:312
UShort_t fGreen
green component (0..65535)
Definition GuiTypes.h:313
UShort_t fBlue
blue component (0..65535)
Definition GuiTypes.h:314
UShort_t fMask
mask telling which color components are valid
Definition GuiTypes.h:315
Event structure.
Definition GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:178
Int_t fXRoot
Definition GuiTypes.h:179
Bool_t fSendEvent
true if event came from SendEvent
Definition GuiTypes.h:184
Handle_t fHandle
general resource handle (used for atoms or windows)
Definition GuiTypes.h:185
Int_t fFormat
Next fields only used by kClientMessageEvent.
Definition GuiTypes.h:186
UInt_t fWidth
Definition GuiTypes.h:182
UInt_t fHeight
width and height of exposed area
Definition GuiTypes.h:182
Int_t fCount
if non-zero, at least this many more exposes
Definition GuiTypes.h:183
Window_t fWindow
window reported event is relative to
Definition GuiTypes.h:176
UInt_t fState
key or button mask
Definition GuiTypes.h:181
Int_t fYRoot
coordinates relative to root
Definition GuiTypes.h:179
Int_t fX
Definition GuiTypes.h:178
Long_t fUser[5]
5 longs can be used by client message events NOTE: only [0], [1] and [2] may be used.
Definition GuiTypes.h:187
Time_t fTime
time event event occurred in ms
Definition GuiTypes.h:177
UInt_t fCode
key or button code
Definition GuiTypes.h:180
Graphics context structure.
Definition GuiTypes.h:224
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:251
Bool_t fGraphicsExposures
boolean, should exposures be generated
Definition GuiTypes.h:244
ULong_t fForeground
foreground pixel
Definition GuiTypes.h:227
FontH_t fFont
default text font for text operations
Definition GuiTypes.h:242
Html_u8_t fIndex
Definition TGHtml.h:824
Html_u8_t fFont
Definition TGHtml.h:822
Html_u8_t fColor
Definition TGHtml.h:823
GContext_t fGc
Definition TGHtml.h:821
TGHtmlElement * fP
Definition TGHtml.h:832
SHtmlStyleStack_t * fPNext
Definition TGHtml.h:733
unsigned int fFlags
Definition TGHtml.h:150
TCanvas * style()
Definition style.C:1
#define MIN(x, y)
Definition sweep.c:95
#define MAX(x, y)
Definition sweep.c:94
auto * t1
Definition textangle.C:20