ROOT logo
// @(#)root/gui:$Id$
// Author: Fons Rademakers   1/7/2000

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGTextView
#define ROOT_TGTextView


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGTextView                                                           //
//                                                                      //
// A TGTextView is a text viewer widget. It is a specialization of      //
// TGView. It uses the TGText class (which contains all text            //
// manipulation code, i.e. loading a file in memory, changing,          //
// removing lines, etc.). Use a TGTextView to view non-editable text.   //
// For supported messages see TGView.                                   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TGView
#include "TGView.h"
#endif
#ifndef ROOT_TGText
#include "TGText.h"
#endif

class TViewTimer;

class TGTextView : public TGView {

protected:
   TGText         *fText;         // text buffer
   TGText         *fClipText;     // clipboard text buffer
   FontStruct_t    fFont;         // text font
   Int_t           fMaxAscent;    // maximum ascent in font
   Int_t           fMaxDescent;   // maximum descent in font
   Int_t           fMaxWidth;     // maximum width of character in font
   TGGC            fNormGC;       // graphics context for drawing text
   TGGC            fSelGC;        // graphics context for drawing marked text
   TGGC            fSelbackGC;    // graphics context for drawing marked background
   Bool_t          fMarkedFromX;  // true if text is marked from x
   Bool_t          fMarkedFromY;  // true if text is marker from y
   Bool_t          fIsMarked;     // true if text is marked/selected
   Bool_t          fIsMarking;    // true if in marking mode
   Bool_t          fIsSaved;      // true is content is saved
   Bool_t          fReadOnly;     // text cannot be editted
   TGLongPosition  fMarkedStart;  // start position of marked text
   TGLongPosition  fMarkedEnd;    // end position of marked text
   TViewTimer     *fScrollTimer;  // scrollbar timer
   Atom_t         *fDNDTypeList;  // handles DND types

   static const TGFont *fgDefaultFont;
   static TGGC         *fgDefaultGC;
   static TGGC         *fgDefaultSelectedGC;
   static const TGGC   *fgDefaultSelectedBackgroundGC;

   void Init(Pixel_t bg);
   virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h);
   virtual void Mark(Long_t xPos, Long_t yPos);
   virtual void UnMark();
   virtual void Copy(TObject &) const { MayNotUse("Copy(TObject &)"); }
   virtual void HLayout();
   virtual void VLayout();

   static FontStruct_t  GetDefaultFontStruct();
   static const TGGC   &GetDefaultGC();
   static const TGGC   &GetDefaultSelectedGC();
   static const TGGC   &GetDefaultSelectedBackgroundGC();

private:
   TGTextView(const TGTextView&);
   TGTextView& operator=(const TGTextView&);

public:
   TGTextView(const TGWindow *parent = 0, UInt_t w = 1, UInt_t h = 1, Int_t id = -1,
              UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
   TGTextView(const TGWindow *parent, UInt_t w, UInt_t h, TGText *text,
              Int_t id = -1, UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());
   TGTextView(const TGWindow *parent, UInt_t w, UInt_t h, const char *string,
              Int_t id = -1, UInt_t sboptions = 0, Pixel_t back = GetWhitePixel());

   virtual ~TGTextView();

   virtual Bool_t IsSaved() { fIsSaved = fText->IsSaved(); return fIsSaved;}
   virtual Long_t ToObjXCoord(Long_t xCoord, Long_t line);
   virtual Long_t ToObjYCoord(Long_t yCoord);
   virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line);
   virtual Long_t ToScrYCoord(Long_t yCoord);
   virtual void   AdjustWidth();
   virtual Bool_t LoadFile(const char *fname, long startpos = 0, long length = -1);
   virtual Bool_t LoadBuffer(const char *txtbuf);
   virtual void   Clear(Option_t * = "");
   virtual Bool_t Copy();
   virtual Bool_t SelectAll();
   virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive);
   virtual void   SetFont(FontStruct_t font);
   virtual Long_t ReturnHeighestColHeight() { return fText->RowCount()*fScrollVal.fY; }
   virtual Long_t ReturnLongestLineWidth();
   virtual Long_t ReturnLineLength(Long_t line) { return fText->GetLineLength(line); }
   virtual Long_t ReturnLongestLine() { return fText->GetLongestLine(); }
   virtual Long_t ReturnLineCount() { return fText->RowCount(); }

   virtual void   SetSBRange(Int_t direction);
   virtual void   SetHsbPosition(Long_t newPos);
   virtual void   SetVsbPosition(Long_t newPos);
   virtual void   ShowBottom();
   virtual void   ShowTop();

   virtual void   SavePrimitive(ostream &out, Option_t * = "");
   virtual void   SetText(TGText *text);
   virtual void   AddText(TGText *text);
   virtual void   AddLine(const char *string);
   virtual void   AddLineFast(const char *string);
   virtual void   Update();
   virtual void   Layout();

   virtual void   SetBackground(Pixel_t p);
   virtual void   SetSelectBack(Pixel_t p);
   virtual void   SetSelectFore(Pixel_t p);
   virtual void   SetForegroundColor(Pixel_t);

   TGText        *GetText() const { return fText; }

   virtual void   SetReadOnly(Bool_t on = kTRUE) { fReadOnly = on; } //*TOGGLE* *GETTER=IsReadOnly
   Bool_t IsReadOnly() const { return fReadOnly; }
   Bool_t IsMarked() const { return fIsMarked; }

   virtual Bool_t HandleDNDDrop(TDNDData *data);
   virtual Atom_t HandleDNDPosition(Int_t x, Int_t y, Atom_t action,
                                    Int_t xroot, Int_t yroot);
   virtual Atom_t HandleDNDEnter(Atom_t * typelist);
   virtual Bool_t HandleDNDLeave();

   virtual Bool_t HandleButton(Event_t *event);
   virtual Bool_t HandleDoubleClick(Event_t *event);
   virtual Bool_t HandleSelectionClear(Event_t *event);
   virtual Bool_t HandleSelectionRequest(Event_t *event);
   virtual Bool_t HandleMotion(Event_t *event);
   virtual Bool_t HandleTimer(TTimer *t);
   virtual Bool_t HandleCrossing(Event_t *event);

   virtual void DataChanged() { Emit("DataChanged()"); }  //*SIGNAL*
   virtual void DataDropped(const char *fname) { Emit("DataDropped(char *)", fname); }  //*SIGNAL*
   virtual void Marked(Bool_t mark) { Emit("Marked(Bool_t)", mark); } // *SIGNAL*
   virtual void Clicked(const char *word) { Emit("Clicked(char *)", word); }  //*SIGNAL*
   virtual void DoubleClicked(const char *word) { Emit("DoubleClicked(char *)", word); }  //*SIGNAL*

   ClassDef(TGTextView,0)  // Non-editable text viewer widget
};


class TViewTimer : public TTimer {
private:
   TGView   *fView;

   TViewTimer(const TViewTimer&);             // not implemented
   TViewTimer& operator=(const TViewTimer&);  // not implemented

public:
   TViewTimer(TGView *t, Long_t ms) : TTimer(ms, kTRUE), fView(t) { }
   Bool_t Notify();
};


#endif
 TGTextView.h:1
 TGTextView.h:2
 TGTextView.h:3
 TGTextView.h:4
 TGTextView.h:5
 TGTextView.h:6
 TGTextView.h:7
 TGTextView.h:8
 TGTextView.h:9
 TGTextView.h:10
 TGTextView.h:11
 TGTextView.h:12
 TGTextView.h:13
 TGTextView.h:14
 TGTextView.h:15
 TGTextView.h:16
 TGTextView.h:17
 TGTextView.h:18
 TGTextView.h:19
 TGTextView.h:20
 TGTextView.h:21
 TGTextView.h:22
 TGTextView.h:23
 TGTextView.h:24
 TGTextView.h:25
 TGTextView.h:26
 TGTextView.h:27
 TGTextView.h:28
 TGTextView.h:29
 TGTextView.h:30
 TGTextView.h:31
 TGTextView.h:32
 TGTextView.h:33
 TGTextView.h:34
 TGTextView.h:35
 TGTextView.h:36
 TGTextView.h:37
 TGTextView.h:38
 TGTextView.h:39
 TGTextView.h:40
 TGTextView.h:41
 TGTextView.h:42
 TGTextView.h:43
 TGTextView.h:44
 TGTextView.h:45
 TGTextView.h:46
 TGTextView.h:47
 TGTextView.h:48
 TGTextView.h:49
 TGTextView.h:50
 TGTextView.h:51
 TGTextView.h:52
 TGTextView.h:53
 TGTextView.h:54
 TGTextView.h:55
 TGTextView.h:56
 TGTextView.h:57
 TGTextView.h:58
 TGTextView.h:59
 TGTextView.h:60
 TGTextView.h:61
 TGTextView.h:62
 TGTextView.h:63
 TGTextView.h:64
 TGTextView.h:65
 TGTextView.h:66
 TGTextView.h:67
 TGTextView.h:68
 TGTextView.h:69
 TGTextView.h:70
 TGTextView.h:71
 TGTextView.h:72
 TGTextView.h:73
 TGTextView.h:74
 TGTextView.h:75
 TGTextView.h:76
 TGTextView.h:77
 TGTextView.h:78
 TGTextView.h:79
 TGTextView.h:80
 TGTextView.h:81
 TGTextView.h:82
 TGTextView.h:83
 TGTextView.h:84
 TGTextView.h:85
 TGTextView.h:86
 TGTextView.h:87
 TGTextView.h:88
 TGTextView.h:89
 TGTextView.h:90
 TGTextView.h:91
 TGTextView.h:92
 TGTextView.h:93
 TGTextView.h:94
 TGTextView.h:95
 TGTextView.h:96
 TGTextView.h:97
 TGTextView.h:98
 TGTextView.h:99
 TGTextView.h:100
 TGTextView.h:101
 TGTextView.h:102
 TGTextView.h:103
 TGTextView.h:104
 TGTextView.h:105
 TGTextView.h:106
 TGTextView.h:107
 TGTextView.h:108
 TGTextView.h:109
 TGTextView.h:110
 TGTextView.h:111
 TGTextView.h:112
 TGTextView.h:113
 TGTextView.h:114
 TGTextView.h:115
 TGTextView.h:116
 TGTextView.h:117
 TGTextView.h:118
 TGTextView.h:119
 TGTextView.h:120
 TGTextView.h:121
 TGTextView.h:122
 TGTextView.h:123
 TGTextView.h:124
 TGTextView.h:125
 TGTextView.h:126
 TGTextView.h:127
 TGTextView.h:128
 TGTextView.h:129
 TGTextView.h:130
 TGTextView.h:131
 TGTextView.h:132
 TGTextView.h:133
 TGTextView.h:134
 TGTextView.h:135
 TGTextView.h:136
 TGTextView.h:137
 TGTextView.h:138
 TGTextView.h:139
 TGTextView.h:140
 TGTextView.h:141
 TGTextView.h:142
 TGTextView.h:143
 TGTextView.h:144
 TGTextView.h:145
 TGTextView.h:146
 TGTextView.h:147
 TGTextView.h:148
 TGTextView.h:149
 TGTextView.h:150
 TGTextView.h:151
 TGTextView.h:152
 TGTextView.h:153
 TGTextView.h:154
 TGTextView.h:155
 TGTextView.h:156
 TGTextView.h:157
 TGTextView.h:158
 TGTextView.h:159
 TGTextView.h:160
 TGTextView.h:161
 TGTextView.h:162
 TGTextView.h:163
 TGTextView.h:164
 TGTextView.h:165
 TGTextView.h:166
 TGTextView.h:167
 TGTextView.h:168
 TGTextView.h:169
 TGTextView.h:170
 TGTextView.h:171
 TGTextView.h:172
 TGTextView.h:173