Logo ROOT  
Reference Guide
TGTextEdit.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Fons Rademakers 3/7/2000
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
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 This source is based on Xclass95, a Win95-looking GUI toolkit.
14 Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15
16 Xclass95 is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Library General Public
18 License as published by the Free Software Foundation; either
19 version 2 of the License, or (at your option) any later version.
20
21**************************************************************************/
22
23//////////////////////////////////////////////////////////////////////////
24// //
25// TGTextEdit //
26// //
27// A TGTextEdit is a specialization of TGTextView. It provides the //
28// text edit functionality to the static text viewing widget. //
29// For the messages supported by this widget see the TGView class. //
30// //
31//////////////////////////////////////////////////////////////////////////
32
33#include "TGTextEdit.h"
34#include "TGTextEditDialogs.h"
35#include "TGResourcePool.h"
36#include "TSystem.h"
37#include "TMath.h"
38#include "TTimer.h"
39#include "TGMenu.h"
40#include "TGMsgBox.h"
41#include "TGFileDialog.h"
42#include "TGScrollBar.h"
43#include "KeySymbols.h"
44#include "Riostream.h"
45#include "RConfigure.h"
46#include "TVirtualX.h"
47
48
49static const char *gFiletypes[] = { "All files", "*",
50 "Text files", "*.txt",
51 "ROOT macros", "*.C",
52 0, 0 };
53static char *gPrinter = nullptr;
54static char *gPrintCommand = nullptr;
55
56
59
60
61///////////////////////////////////////////////////////////////////////////////
62class TGTextEditHist : public TList {
63
64public:
65 TGTextEditHist() {}
66 virtual ~TGTextEditHist() { Delete(); }
67
68 Bool_t Notify() { //
69 TObject *obj = Last();
70 if (!obj) return kFALSE;
71
72 obj->Notify(); // execute undo action
73 RemoveLast();
74 delete obj;
75 return kTRUE;
76 }
77};
78
79///////////////////////////////////////////////////////////////////////////////
80class TGTextEditCommand : public TObject {
81protected:
82 TGTextEdit *fEdit;
83 TGLongPosition fPos;
84
85public:
86 TGTextEditCommand(TGTextEdit *te) : fEdit(te) {
87 fPos = fEdit->GetCurrentPos();
88 fEdit->GetHistory()->Add(this);
89 }
90 void SetPos(TGLongPosition pos) { fPos = pos; }
91};
92
93///////////////////////////////////////////////////////////////////////////////
94class TInsCharCom : public TGTextEditCommand {
95
96public:
97 TInsCharCom(TGTextEdit *te, char ch) : TGTextEditCommand(te) {
98 fEdit->InsChar(ch);
99 }
100 Bool_t Notify() { //
101 fEdit->SetCurrent(fPos);
102 fEdit->NextChar();
103 fEdit->DelChar();
104 return kTRUE;
105 }
106};
107
108///////////////////////////////////////////////////////////////////////////////
109class TDelCharCom : public TGTextEditCommand {
110
111private:
112 char fChar;
113
114public:
115 TDelCharCom(TGTextEdit *te) : TGTextEditCommand(te) {
116 fPos.fX--;
117 fChar = fEdit->GetText()->GetChar(fPos);
118 fEdit->DelChar();
119 }
120 Bool_t Notify() { //
121 if (fChar > 0) {
122 fEdit->SetCurrent(fPos);
123 fEdit->InsChar(fChar);
124 } else {
125 fPos.fY--;
126 fEdit->BreakLine();
127 }
128 return kTRUE;
129 }
130};
131
132///////////////////////////////////////////////////////////////////////////////
133class TBreakLineCom : public TGTextEditCommand {
134
135public:
136 TBreakLineCom(TGTextEdit *te) : TGTextEditCommand(te) {
137 fEdit->BreakLine();
138 fPos.fX = 0;
139 fPos.fY++;
140 }
141
142 Bool_t Notify() { //
143 fEdit->SetCurrent(fPos);
144 fEdit->DelChar();
145 return kTRUE;
146 }
147};
148
149///////////////////////////////////////////////////////////////////////////////
150class TInsTextCom : public TGTextEditCommand {
151private:
152 TGLongPosition fEndPos;
153
154public:
155 char fChar;
156
157 TInsTextCom(TGTextEdit *te) : TGTextEditCommand(te), fChar(0) {
158 }
159
160 void SetEndPos(TGLongPosition end) {
161 fEndPos = end;
162 }
163
164 Bool_t Notify() { //
165 fEdit->GetText()->DelText(fPos, fEndPos);
166
167 if (fChar > 0) {
168 fEdit->GetText()->InsChar(fPos, fChar);
169 } else if (fPos.fY != fEndPos.fY) {
170 fEdit->GetText()->BreakLine(fPos);
171 }
172 fEdit->SetCurrent(fPos);
173 fEdit->Update();
174 return kTRUE;
175 }
176};
177
178///////////////////////////////////////////////////////////////////////////////
179class TDelTextCom : public TGTextEditCommand {
180
181private:
182 TGText *fText;
183 TGLongPosition fEndPos;
184 Bool_t fBreakLine;
185
186public:
187 TDelTextCom(TGTextEdit *te, TGText *txt) : TGTextEditCommand(te) {
188 fText = new TGText(txt);
189 fBreakLine = kFALSE;
190 }
191 TDelTextCom(const TDelTextCom &dtc) : TGTextEditCommand(dtc) {
192 fText = new TGText(dtc.fText);
193 fBreakLine = dtc.fBreakLine;
194 }
195 virtual ~TDelTextCom() { delete fText; }
196
197 TDelTextCom &operator=(const TDelTextCom &dtc) {
198 if (this != &dtc) {
199 if (fText) delete fText;
200 fText = new TGText(dtc.fText);
201 fBreakLine = dtc.fBreakLine;
202 }
203 return *this;
204 }
205
206 void SetEndPos(TGLongPosition end) {
207 fEndPos = end;
208 }
209
210 void SetBreakLine(Bool_t on) { fBreakLine = on; }
211
212 Bool_t Notify() { //
213 TGLongPosition start_src, end_src;
214 start_src.fX = start_src.fY = 0;
215 end_src.fY = fText->RowCount() - 1;
216 end_src.fX = fText->GetLineLength(end_src.fY) - 1;
217
218 fEdit->GetText()->InsText(fPos, fText, start_src, end_src);
219
220 if (fBreakLine) {
221 fEndPos.fY++;
222 fEdit->GetText()->BreakLine(fEndPos);
223 fEndPos.fX = fEdit->GetText()->GetLineLength(fEndPos.fY);
224 } else {
225 fEndPos.fX++;
226 }
227
228 fEdit->SetCurrent(fEndPos);
229 fEdit->Update();
230 return kTRUE;
231 }
232};
233
234
236
237
238////////////////////////////////////////////////////////////////////////////////
239/// Create a text edit widget.
240
242 UInt_t sboptions, ULong_t back) :
243 TGTextView(parent, w, h, id, sboptions, back)
244{
245 Init();
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Create a text edit widget. Initialize it with the specified text buffer.
250
252 Int_t id, UInt_t sboptions, ULong_t back) :
253 TGTextView(parent, w, h, text, id, sboptions, back)
254{
255 Init();
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Create a text edit widget. Initialize it with the specified string.
260
262 const char *string, Int_t id, UInt_t sboptions,
263 ULong_t back) :
264 TGTextView(parent, w, h, string, id, sboptions, back)
265{
266 Init();
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// Cleanup text edit widget.
271
273{
276 }
277 delete fCurBlink;
278 delete fMenu;
279 delete fHistory;
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Initiliaze a text edit widget.
284
286{
289 fCursorState = 1;
290 fCurrent.fY = fCurrent.fX = 0;
292 fCurBlink = 0;
293 fSearch = 0;
296
298
299 // create popup menu with default editor actions
301 fMenu->AddEntry("New", kM_FILE_NEW);
302 fMenu->AddEntry("Open...", kM_FILE_OPEN);
304 fMenu->AddEntry("Close", kM_FILE_CLOSE);
305 fMenu->AddEntry("Save", kM_FILE_SAVE);
306 fMenu->AddEntry("Save As...", kM_FILE_SAVEAS);
308 fMenu->AddEntry("Print...", kM_FILE_PRINT);
310 fMenu->AddEntry("Cut", kM_EDIT_CUT);
311 fMenu->AddEntry("Copy", kM_EDIT_COPY);
312 fMenu->AddEntry("Paste", kM_EDIT_PASTE);
313 fMenu->AddEntry("Select All", kM_EDIT_SELECTALL);
315 fMenu->AddEntry("Find...", kM_SEARCH_FIND);
316 fMenu->AddEntry("Find Again", kM_SEARCH_FINDAGAIN);
317 fMenu->AddEntry("Goto...", kM_SEARCH_GOTO);
318
319 fMenu->Associate(this);
320
321 fHistory = new TGTextEditHist();
322}
323
324////////////////////////////////////////////////////////////////////////////////
325/// Enable/disable menu items in function of what is possible.
326
328{
329 if (fText->RowCount() == 1 && fText->GetLineLength(0) <= 0) {
338 } else {
347 }
348
349 if (IsSaved())
351 else
353
354 if (fIsMarked) {
357 } else {
360 }
361}
362
363////////////////////////////////////////////////////////////////////////////////
364/// Return width of longest line in widget.
365
367{
369 linewidth += 3*fScrollVal.fX;
370 return linewidth;
371}
372
373////////////////////////////////////////////////////////////////////////////////
374/// Clear text edit widget.
375
377{
378 fCursorState = 1;
379 fCurrent.fY = fCurrent.fX = 0;
381}
382
383////////////////////////////////////////////////////////////////////////////////
384/// Save file. If filename==0 ask user via dialog for a filename, if in
385/// addition saveas==kTRUE always ask for new filename. Returns
386/// kTRUE if file was correctly saved, kFALSE otherwise.
387
388Bool_t TGTextEdit::SaveFile(const char *filename, Bool_t saveas)
389{
390 if (!filename) {
391 Bool_t untitled = !strlen(fText->GetFileName()) ? kTRUE : kFALSE;
392 if (untitled || saveas) {
393 static TString dir(".");
394 static Bool_t overwr = kFALSE;
395 TGFileInfo fi;
397 fi.SetIniDir(dir);
398 fi.fOverwrite = overwr;
399 new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
400 overwr = fi.fOverwrite;
401 if (fi.fFilename && strlen(fi.fFilename)) {
402 dir = fi.fIniDir;
403 return fText->Save(fi.fFilename);
404 }
405 return kFALSE;
406 }
407 return fText->Save(fText->GetFileName());
408 }
409
410 return fText->Save(filename);
411}
412
413////////////////////////////////////////////////////////////////////////////////
414/// Copy text.
415
417{
418 if (!fIsMarked || ((fMarkedStart.fX == fMarkedEnd.fX) &&
420 return kFALSE;
421 }
422
424
426 del = del || (!fMarkedEnd.fX && (fCurrent.fY != fMarkedEnd.fY));
427 del = del && fClipText->AsString().Length() > 0;
428
429 if (del) {
430 TGLongPosition pos;
431 pos.fY = fClipText->RowCount();
432 pos.fX = 0;
433 fClipText->InsText(pos, 0);
434 }
435
436 return kTRUE;
437}
438
439////////////////////////////////////////////////////////////////////////////////
440/// Cut text.
441
443{
444 if (!Copy()) {
445 return kFALSE;
446 }
447 Delete();
448
449 return kTRUE;
450}
451
452////////////////////////////////////////////////////////////////////////////////
453/// Paste text into widget.
454
456{
457 if (fReadOnly) {
458 return kFALSE;
459 }
460
461 if (fIsMarked) {
462 TString sav = fClipText->AsString();
464 Delete();
465 fClipText->Clear();
466 fClipText->LoadBuffer(sav.Data());
467 }
468
469 gVirtualX->ConvertPrimarySelection(fId, fClipboard, 0);
470
471 return kTRUE;
472}
473
474////////////////////////////////////////////////////////////////////////////////
475/// Send current buffer to printer.
476
478{
479 TString msg;
480
481 msg.Form("%s -P%s\n", gPrintCommand, gPrinter);
482 FILE *p = gSystem->OpenPipe(msg.Data(), "w");
483 if (p) {
484 char *buf1, *buf2;
485 Long_t len;
486 ULong_t i = 0;
487 TGLongPosition pos;
488
489 pos.fX = pos.fY = 0;
490 while (pos.fY < fText->RowCount()) {
491 len = fText->GetLineLength(pos.fY);
492 if (len < 0) len = 0;
493 buf1 = fText->GetLine(pos, len);
494 buf2 = new char[len + 2];
495 strncpy(buf2, buf1, (UInt_t)len);
496 buf2[len] = '\n';
497 buf2[len+1] = '\0';
498 while (buf2[i] != '\0') {
499 if (buf2[i] == '\t') {
500 ULong_t j = i+1;
501 while (buf2[j] == 16)
502 j++;
503 // coverity[secure_coding]
504 strcpy(buf2+i+1, buf2+j);
505 }
506 i++;
507 }
508 fwrite(buf2, sizeof(char), strlen(buf2)+1, p);
509
510 delete [] buf1;
511 delete [] buf2;
512 pos.fY++;
513 }
514 gSystem->ClosePipe(p);
515
516 Bool_t untitled = !strlen(fText->GetFileName()) ? kTRUE : kFALSE;
517 msg.Form("Printed: %s\nLines: %ld\nUsing: %s -P%s",
518 untitled ? "Untitled" : fText->GetFileName(),
520 new TGMsgBox(fClient->GetDefaultRoot(), this, "Editor", msg.Data(),
522 } else {
523 msg.Form("Could not execute: %s -P%s\n", gPrintCommand, gPrinter);
524 new TGMsgBox(fClient->GetDefaultRoot(), this, "Editor", msg.Data(),
526 }
527}
528
529////////////////////////////////////////////////////////////////////////////////
530/// Delete selection.
531
533{
534 if (!fIsMarked || fReadOnly) {
535 return;
536 }
537
538 if (fMarkedStart.fX == fMarkedEnd.fX &&
541
542 if (fCurrent.fY == fText->RowCount()-1 && fCurrent.fX == len) {
543 gVirtualX->Bell(0);
544 return;
545 }
546
547 new TDelCharCom(this);
548 return;
549 }
550
551 TGLongPosition pos, endPos;
552 Bool_t delast = kFALSE;
553
554 endPos.fX = fMarkedEnd.fX - 1;
555 endPos.fY = fMarkedEnd.fY;
556
557 if (endPos.fX == -1) {
558 pos = fCurrent;
559 if (endPos.fY > 0) {
560 SetCurrent(endPos);
561 DelChar();
562 endPos.fY--;
563 SetCurrent(pos);
564 }
565 endPos.fX = fText->GetLineLength(endPos.fY);
566 if (endPos.fX < 0) {
567 endPos.fX = 0;
568 }
569 delast = kTRUE;
570 }
571
572 // delete command for undo
573 TDelTextCom *dcom = new TDelTextCom(this, fClipText);
574 dcom->SetPos(fMarkedStart);
575 dcom->SetEndPos(endPos);
576
577 if (delast || ((fText->GetLineLength(endPos.fY) == endPos.fX+1) &&
578 (fClipText->RowCount() > 1))) {
579 TGLongPosition p = endPos;
580
581 p.fY--;
582 if (!delast) p.fX++;
583 dcom->SetEndPos(p);
584 dcom->SetBreakLine(kTRUE);
585 }
586
587 fText->DelText(fMarkedStart, endPos);
588
589 pos.fY = ToObjYCoord(fVisible.fY);
590
591 if (fMarkedStart.fY < pos.fY) {
592 pos.fY = fMarkedStart.fY;
593 }
594 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
595 if (fMarkedStart.fX < pos.fX) {
596 pos.fX = fMarkedStart.fX;
597 }
598
601 th = th < 0 ? 0 : th;
602 ys = ys < 0 ? 0 : ys;
603
604 // clear
605 if ((th < 0) || (th < (Int_t)fCanvas->GetHeight())) {
606 gVirtualX->ClearArea(fCanvas->GetId(), 0, ys,
607 fCanvas->GetWidth(), fCanvas->GetHeight() - ys);
608 }
609
611
617
619 UnMark();
620
621 // only to make sure that IsSaved() returns true in case everything has
622 // been deleted
623 if (fText->RowCount() == 1 && fText->GetLineLength(0) == 0) {
624 delete fText;
625 fText = new TGText();
626 fText->Clear();
627 }
628}
629
630////////////////////////////////////////////////////////////////////////////////
631/// Search for string in the specified direction. If direction is true
632/// the search will be in forward direction.
633
634Bool_t TGTextEdit::Search(const char *string, Bool_t direction,
635 Bool_t caseSensitive)
636{
637 if (!IsMapped()) return kFALSE;
638
643 }
644
645 TGLongPosition pos;
646 if (!fText->Search(&pos, fCurrent, string, direction, caseSensitive)) {
647 fCurrent.fX = 1;
648 fCurrent.fY = 1;
649
650 if (!fText->Search(&pos, fCurrent, string, direction, caseSensitive)) { //try again
651 TString msg;
652 msg.Form("Couldn't find \"%s\"", string);
653 gVirtualX->Bell(20);
654 new TGMsgBox(fClient->GetDefaultRoot(), fCanvas, "TextEdit",
655 msg.Data(), kMBIconExclamation, kMBOk, 0);
656 return kFALSE;
657 }
658 return kTRUE;
659 }
660 UnMark();
663 fMarkedStart.fX = pos.fX;
664 fMarkedEnd.fX = fMarkedStart.fX + strlen(string);
665
666 if (direction) {
668 } else {
670 }
671
672 pos.fY = ToObjYCoord(fVisible.fY);
673 if (fCurrent.fY < pos.fY ||
675 pos.fY = fMarkedStart.fY;
676 }
677 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
678
679 if (fCurrent.fX < pos.fX ||
681 pos.fX = fMarkedStart.fX;
682 }
683
686
689
690 return kTRUE;
691}
692
693////////////////////////////////////////////////////////////////////////////////
694/// Replace text starting at textPos.
695
696Bool_t TGTextEdit::Replace(TGLongPosition textPos, const char *oldText,
697 const char *newText, Bool_t direction, Bool_t caseSensitive)
698{
699 TGLongPosition pos;
700 if (!fText->Replace(textPos, oldText, newText, direction, caseSensitive)) {
701 return kFALSE;
702 }
703 UnMark();
705 fMarkedStart.fY = fMarkedEnd.fY = textPos.fY;
706 fMarkedStart.fX = textPos.fX;
707 fMarkedEnd.fX = fMarkedStart.fX + strlen(newText);
708
709 if (direction) {
711 } else {
713 }
714
715 pos.fY = ToObjYCoord(fVisible.fY);
716 if (fCurrent.fY < pos.fY ||
718 pos.fY = fMarkedStart.fY;
719 }
720 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
721 if (fCurrent.fX < pos.fX ||
723 pos.fX = fMarkedStart.fX;
724 }
725
728
731
732 return kTRUE;
733}
734
735////////////////////////////////////////////////////////////////////////////////
736/// Goto the specified line.
737
739{
740 if (line < 0)
741 line = 0;
742 if (line >= fText->RowCount())
743 line = fText->RowCount() - 1;
744 if (column < 0)
745 column = 0;
746 if (column > fText->GetLineLength(line))
747 column = fText->GetLineLength(line);
748
749 TGLongPosition gotopos, pos;
750 gotopos.fY = line;
751 gotopos.fX = column;
752 SetCurrent(gotopos);
753
754 pos.fY = ToObjYCoord(fVisible.fY);
755 if (fCurrent.fY < pos.fY ||
757 pos.fY = gotopos.fY;
758
761
762 UnMark();
765 fMarkedStart.fX = 0;
767
768 return kTRUE;
769}
770
771////////////////////////////////////////////////////////////////////////////////
772/// Sets the mode how characters are entered.
773
775{
776 if (fInsertMode == mode) return;
777
778 fInsertMode = mode;
779}
780
781////////////////////////////////////////////////////////////////////////////////
782/// If cursor if on, turn it off.
783
785{
786 if (fCursorState == 1) {
787 DrawCursor(2);
788 }
789 fCursorState = 2;
790}
791
792////////////////////////////////////////////////////////////////////////////////
793/// Turn cursor on.
794
796{
797 DrawCursor(1);
798 fCursorState = 1;
799
800 if (fCurBlink) {
801 fCurBlink->Reset();
802 }
803}
804
805////////////////////////////////////////////////////////////////////////////////
806/// Make the specified position the current position.
807
809{
810 CursorOff();
811
812 fCurrent.fY = new_coord.fY;
813 fCurrent.fX = new_coord.fX;
814
815 CursorOn();
816
818 DataChanged();
819}
820
821////////////////////////////////////////////////////////////////////////////////
822/// Draw cursor. If mode = 1 draw cursor, if mode = 2 erase cursor.
823
825{
826 char count = -1;
827 char cursor = ' ';
829 return;
830 }
831
836 if (fCurrent.fY < fText->RowCount()) {
837 count = fText->GetChar(fCurrent);
838 }
839 if (count == -1 || count == '\t') {
840 cursor = ' ';
841 } else {
842 cursor = count;
843 }
844
845 if (mode == 2) {
846 if (fIsMarked && count != -1) {
855 // back ground fillrectangle
856 gVirtualX->FillRectangle(fCanvas->GetId(), fSelbackGC(),
862 if (count != -1)
864 Int_t(ToScrYCoord(fCurrent.fY+1) - fMaxDescent), &cursor, 1);
865 } else {
866 gVirtualX->ClearArea(fCanvas->GetId(),
872 if (count != -1)
874 Int_t(ToScrYCoord(fCurrent.fY+1) - fMaxDescent), &cursor, 1);
875 }
876 } else {
877 gVirtualX->ClearArea(fCanvas->GetId(),
884 Int_t(ToScrYCoord(fCurrent.fY+1) - fMaxDescent), &cursor, 1);
885 }
886 } else {
887 if (mode == 1) {
888 gVirtualX->FillRectangle(fCanvas->GetId(), fCursor1GC,
891 2,
893 }
894 }
895 }
896}
897
898////////////////////////////////////////////////////////////////////////////////
899/// Adjust current position.
900
902{
903 TGLongPosition pos;
904 pos.fY = fCurrent.fY;
905 pos.fX = fCurrent.fX;
906
907 if (pos.fY < ToObjYCoord(fVisible.fY)) {
908 pos.fY = ToObjYCoord(fVisible.fY);
909 } else if (ToScrYCoord(pos.fY+1) >= (Int_t) fCanvas->GetHeight()) {
911 }
912 if (pos.fX < ToObjXCoord(fVisible.fX, pos.fY)) {
913 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
914 } else if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t) fCanvas->GetWidth()) {
915 pos.fX = ToObjXCoord(fVisible.fX + fCanvas->GetWidth(), pos.fY)-1;
916 }
917 if (pos.fY != fCurrent.fY || pos.fX != fCurrent.fX) {
918 SetCurrent(pos);
919 }
920}
921
922////////////////////////////////////////////////////////////////////////////////
923/// Handle timer cursor blink timer.
924
926{
927 if (t != fCurBlink) {
929 return kTRUE;
930 }
931
932 if (fCursorState == 1) {
933 fCursorState = 2;
934 } else {
935 fCursorState = 1;
936 }
937
939
940 return kTRUE;
941}
942
943////////////////////////////////////////////////////////////////////////////////
944/// Handle selection notify event.
945
947{
948 TString data;
949 Int_t nchar;
950
951 gVirtualX->GetPasteBuffer((Window_t)event->fUser[0], (Atom_t)event->fUser[3],
952 data, nchar, kFALSE);
953
954 if (!nchar) return kTRUE;
955
956 delete fClipText;
957
958 fClipText = new TGText;
959 fClipText->LoadBuffer(data.Data());
960
961 TGLongPosition start_src, end_src, pos;
962
963 pos.fX = pos.fY = 0;
964 start_src.fY = start_src.fX = 0;
965 end_src.fY = fClipText->RowCount()-1;
966 end_src.fX = fClipText->GetLineLength(end_src.fY)-1;
967
968 if (end_src.fX < 0) {
969 end_src.fX = 0;
970 }
971
972 // undo command
973 TInsTextCom *icom = new TInsTextCom(this);
974 icom->fChar = fText->GetChar(fCurrent);
975 fText->InsText(fCurrent, fClipText, start_src, end_src);
976
978
979 fExposedRegion.fX = 0;
981
982 pos.fY = fCurrent.fY + fClipText->RowCount()-1;
984
985 if (start_src.fY == end_src.fY) {
986 pos.fX = pos.fX + fCurrent.fX;
987 }
988
989 icom->SetEndPos(pos);
990
991 // calculate exposed region
994
995 SetCurrent(pos);
996
997 if (ToScrYCoord(pos.fY) >= (Int_t)fCanvas->GetHeight()) {
998 pos.fY = ToScrYCoord(pos.fY) + fVisible.fY - fCanvas->GetHeight()/2;
1001 } else {
1002 pos.fY = fVisible.fY;
1003 }
1004 if (ToScrXCoord(pos.fX, fCurrent.fY) >= (Int_t) fCanvas->GetWidth()) {
1005 pos.fX = ToScrXCoord(pos.fX, fCurrent.fY) + fVisible.fX + fCanvas->GetWidth()/2;
1006 } else if (ToScrXCoord(pos.fX, fCurrent.fY < 0) && pos.fX != 0) {
1007 if (fVisible.fX - (Int_t)fCanvas->GetWidth()/2 > 0) {
1008 pos.fX = fVisible.fX - fCanvas->GetWidth()/2;
1009 } else {
1010 pos.fX = 0;
1011 }
1012 } else {
1013 pos.fX = fVisible.fX;
1014 }
1015
1020
1021 fClient->NeedRedraw(this);
1022
1023 return kTRUE;
1024}
1025
1028
1029////////////////////////////////////////////////////////////////////////////////
1030/// Handle mouse button event in text edit widget.
1031
1033{
1034 if (event->fWindow != fCanvas->GetId()) {
1035 return kFALSE;
1036 }
1037
1038 TGLongPosition pos;
1039
1041
1042 if (event->fType == kButtonPress) {
1043 SetFocus();
1044 //Update();
1045
1046 if (event->fCode == kButton1 || event->fCode == kButton2) {
1047 pos.fY = ToObjYCoord(fVisible.fY + event->fY);
1048 if (pos.fY >= fText->RowCount()) {
1049 pos.fY = fText->RowCount()-1;
1050 }
1051 pos.fX = ToObjXCoord(fVisible.fX+event->fX, pos.fY);
1052 if (pos.fX >= fText->GetLineLength(pos.fY)) {
1053 pos.fX = fText->GetLineLength(pos.fY);
1054 }
1055 while (fText->GetChar(pos) == 16) {
1056 pos.fX++;
1057 }
1058
1059 SetCurrent(pos);
1060
1062 char *word = line->GetWord(pos.fX);
1063 Clicked((const char*)word); // emit signal
1064 delete [] word;
1065 }
1066 if (event->fCode == kButton2) {
1067 if (gVirtualX->GetPrimarySelectionOwner() != kNone) {
1068 gVirtualX->ConvertPrimarySelection(fId, fClipboard, event->fTime);
1069 Update();
1070 return kTRUE;
1071 }
1072 }
1073 if (event->fCode == kButton3) {
1074 // do not handle during guibuilding
1075 if (fClient->IsEditable() || !fEnableMenu) {
1076 return kTRUE;
1077 }
1078 SetMenuState();
1079 fMenu->PlaceMenu(event->fXRoot, event->fYRoot, kTRUE, kTRUE);
1080 }
1081 gDbl_clk = kFALSE;
1082 gTrpl_clk = kFALSE;
1083 }
1084
1085 return kTRUE;
1086}
1087
1088////////////////////////////////////////////////////////////////////////////////
1089/// Handle double click event.
1090
1092{
1093 if (event->fWindow != fCanvas->GetId()) {
1094 return kFALSE;
1095 }
1096
1097 if (event->fCode != kButton1) {
1098 return kFALSE;
1099 }
1100 if (!fText->GetCurrentLine()->GetText()) {// empty line
1101 return kFALSE;
1102 }
1103
1104 SetFocus();
1105 TGLongPosition pos;
1106 pos.fY = ToObjYCoord(fVisible.fY + event->fY);
1107
1108 if (gDbl_clk && (event->fTime - fgLastClick < 350)) { // triple click
1109 fgLastClick = event->fTime;
1110 gDbl_clk = kFALSE;
1111 gTrpl_clk = kTRUE;
1112 fMarkedStart.fY = fMarkedEnd.fY = pos.fY;
1113 fIsMarked = kTRUE;
1114 fMarkedStart.fX = 0;
1115 fMarkedEnd.fX = strlen(fText->GetCurrentLine()->GetText());
1116 Marked(kTRUE);
1119 return kTRUE;
1120 }
1121
1122 if (gTrpl_clk && (event->fTime - fgLastClick < 350)) { // 4 click
1123 fgLastClick = event->fTime;
1124 gTrpl_clk = kFALSE;
1125 fIsMarked = kTRUE;
1126 fMarkedStart.fY = 0;
1127 fMarkedStart.fX = 0;
1128 fMarkedEnd.fY = fText->RowCount()-1;
1130 if (fMarkedEnd.fX < 0) {
1131 fMarkedEnd.fX = 0;
1132 }
1134 return kTRUE;
1135 }
1136
1137 gDbl_clk = kTRUE;
1138 gTrpl_clk = kFALSE;
1139
1140 if (pos.fY >= fText->RowCount()) {
1141 pos.fY = fText->RowCount() - 1;
1142 }
1143 pos.fX = ToObjXCoord(fVisible.fX + event->fX, pos.fY);
1144
1145 if (pos.fX >= fText->GetLineLength(pos.fY)) {
1146 pos.fX = fText->GetLineLength(pos.fY);
1147 }
1148 while (fText->GetChar(pos) == 16) {
1149 pos.fX++;
1150 }
1151
1152 SetCurrent(pos);
1153
1154 fMarkedStart.fY = fMarkedEnd.fY = pos.fY;
1155 char *line = fText->GetCurrentLine()->GetText();
1157 Int_t start = pos.fX;
1158 Int_t end = pos.fX;
1159 Int_t i = pos.fX;
1160
1161 if (line[i] == ' ' || line[i] == '\t') {
1162 while (start >= 0) {
1163 if (line[start] == ' ' || line[start] == '\t') --start;
1164 else break;
1165 }
1166 ++start;
1167 while (end < (Int_t)len) {
1168 if (line[end] == ' ' || line[end] == '\t') ++end;
1169 else break;
1170 }
1171 } else if (isalnum(line[i])) {
1172 while (start >= 0) {
1173 if (isalnum(line[start])) --start;
1174 else break;
1175 }
1176 ++start;
1177 while (end < (Int_t)len) {
1178 if (isalnum(line[end])) ++end;
1179 else break;
1180 }
1181 } else {
1182 while (start >= 0) {
1183 if (isalnum(line[start]) || line[start] == ' ' || line[start] == '\t') {
1184 break;
1185 } else {
1186 --start;
1187 }
1188 }
1189 ++start;
1190 while (end < (Int_t)len) {
1191 if (isalnum(line[end]) || line[end] == ' ' || line[end] == '\t') {
1192 break;
1193 } else {
1194 ++end;
1195 }
1196 }
1197 }
1198
1199 fMarkedStart.fX = start;
1200 fIsMarked = kTRUE;
1201 fMarkedEnd.fX = end;
1202 Marked(kTRUE);
1203
1204 len = end - start; //length
1205 char *word = new char[len + 1];
1206 word[len] = '\0';
1207 strncpy(word, line+start, (UInt_t)len);
1208 DoubleClicked((const char *)word); // emit signal
1209
1210 delete [] word;
1211// delete [] line;
1212
1215
1216 return kTRUE;
1217}
1218
1219////////////////////////////////////////////////////////////////////////////////
1220/// Handle mouse motion event in text edit widget.
1221
1223{
1224 TGLongPosition pos;
1225 if (event->fWindow != fCanvas->GetId()) {
1226 return kTRUE;
1227 }
1228
1229 if (fScrolling == -1) {
1230 pos.fY = ToObjYCoord(fVisible.fY+event->fY);
1231 if (pos.fY >= fText->RowCount()) {
1232 pos.fY = fText->RowCount()-1;
1233 }
1234 pos.fX = ToObjXCoord(fVisible.fX+event->fX, pos.fY);
1235 if (pos.fX > fText->GetLineLength(pos.fY)) {
1236 pos.fX = fText->GetLineLength(pos.fY);
1237 }
1238 if (fText->GetChar(pos) == 16) {
1239 if (pos.fX < fCurrent.fX) {
1240 pos.fX = fCurrent.fX;
1241 }
1242 if (pos.fX > fCurrent.fX) {
1243 do {
1244 pos.fX++;
1245 } while (fText->GetChar(pos) == 16);
1246 }
1247 }
1248 event->fY = (Int_t)ToScrYCoord(pos.fY);
1249 event->fX = (Int_t)ToScrXCoord(pos.fX, pos.fY);
1250 if (pos.fY != fCurrent.fY || pos.fX != fCurrent.fX) {
1252 SetCurrent(pos);
1253 }
1254 }
1255 return kTRUE;
1256}
1257
1258////////////////////////////////////////////////////////////////////////////////
1259/// The key press event handler converts a key press to some line editor
1260/// action.
1261
1263{
1264 Bool_t mark_ok = kFALSE;
1265 char input[10];
1266 Int_t n;
1267 UInt_t keysym;
1268
1269 if (event->fType == kGKeyPress) {
1270 gVirtualX->LookupString(event, input, sizeof(input), keysym);
1271 n = strlen(input);
1272
1273 AdjustPos();
1274
1275 switch ((EKeySym)keysym) { // ignore these keys
1276 case kKey_Shift:
1277 case kKey_Control:
1278 case kKey_Meta:
1279 case kKey_Alt:
1280 case kKey_CapsLock:
1281 case kKey_NumLock:
1282 case kKey_ScrollLock:
1283 return kTRUE;
1284 default:
1285 break;
1286 }
1287 if (event->fState & kKeyControlMask) { // Cntrl key modifier pressed
1288 switch((EKeySym)keysym & ~0x20) { // treat upper and lower the same
1289 case kKey_A:
1290 SelectAll();
1291 return kTRUE;
1292 case kKey_B:
1293 mark_ok = kTRUE;
1294 PrevChar();
1295 break;
1296 case kKey_C:
1297 Copy();
1298 return kTRUE;
1299 case kKey_D:
1300 if (fIsMarked) {
1301 Cut();
1302 } else {
1304 if (fCurrent.fY == fText->RowCount()-1 && fCurrent.fX == len) {
1305 gVirtualX->Bell(0);
1306 return kTRUE;
1307 }
1308 NextChar();
1309 new TDelCharCom(this);
1310 }
1311 break;
1312 case kKey_E:
1313 mark_ok = kTRUE;
1314 End();
1315 break;
1316 case kKey_H:
1317 if (fCurrent.fX || fCurrent.fY) new TDelCharCom(this);
1318 else gVirtualX->Bell(0);
1319 break;
1320 case kKey_K:
1321 End();
1322 fIsMarked = kTRUE;
1324 Cut();
1325 break;
1326 case kKey_U:
1327 Home();
1328 UnMark();
1331 End();
1332 fIsMarked = kTRUE;
1334 Cut();
1335 break;
1336 case kKey_V:
1337 case kKey_Y:
1338 Paste();
1339 return kTRUE;
1340 case kKey_X:
1341 Cut();
1342 return kTRUE;
1343 case kKey_Z:
1344 fHistory->Notify(); // undo action
1345 return kTRUE;
1346 case kKey_F:
1347 Search(kFALSE);
1348 return kTRUE;
1349 case kKey_L:
1350 {
1351 Long_t ret = fCurrent.fY+1;
1352 new TGGotoDialog(fClient->GetDefaultRoot(), this, 400, 150, &ret);
1353 if (ret > -1) {
1354 ret--; // user specifies lines starting at 1
1355 Goto(ret);
1356 }
1357 return kTRUE;
1358 }
1359 case kKey_Home:
1360 {
1361 TGLongPosition pos;
1362 pos.fY = 0;
1363 pos.fX = 0;
1364 SetHsbPosition(0);
1365 SetVsbPosition(0);
1366 SetCurrent(pos);
1367 }
1368 break;
1369 case kKey_End:
1370 {
1371 TGLongPosition pos;
1372 pos.fY = fText->RowCount()-1;
1373 pos.fX = fText->GetLineLength(pos.fY);
1374 if (fVsb && fVsb->IsMapped())
1376 SetCurrent(pos);
1377 }
1378 break;
1379 default:
1380 return kTRUE;
1381 }
1382 }
1383 if (n && keysym >= 32 && keysym < 127 && // printable keys
1384 !(event->fState & kKeyControlMask) &&
1385 (EKeySym)keysym != kKey_Delete &&
1386 (EKeySym)keysym != kKey_Backspace) {
1387
1388 if (fIsMarked) {
1389 Cut();
1390 }
1391 new TInsCharCom(this, input[0]);
1392
1393 } else {
1394
1395 switch ((EKeySym)keysym) {
1396 case kKey_F3:
1397 // typically FindAgain action
1399 kTRUE);
1400 SetMenuState();
1404 FindAgain();
1405 }
1406 break;
1407 case kKey_Delete:
1408 if (fIsMarked) {
1409 Cut();
1410 } else {
1412 if (fCurrent.fY == fText->RowCount()-1 && fCurrent.fX == len) {
1413 gVirtualX->Bell(0);
1414 return kTRUE;
1415 }
1416 NextChar();
1417 new TDelCharCom(this);
1418 }
1419 break;
1420 case kKey_Return:
1421 case kKey_Enter:
1422 new TBreakLineCom(this);
1423 break;
1424 case kKey_Tab:
1425 new TInsCharCom(this, '\t');
1426 break;
1427 case kKey_Backspace:
1428 if (fIsMarked) {
1429 Cut();
1430 } else {
1431 if (fCurrent.fX || fCurrent.fY) {
1432 new TDelCharCom(this);
1433 } else {
1434 gVirtualX->Bell(0);
1435 }
1436 }
1437 break;
1438 case kKey_Left:
1439 mark_ok = kTRUE;
1440 PrevChar();
1441 break;
1442 case kKey_Right:
1443 mark_ok = kTRUE;
1444 NextChar();
1445 break;
1446 case kKey_Up:
1447 mark_ok = kTRUE;
1448 LineUp();
1449 break;
1450 case kKey_Down:
1451 mark_ok = kTRUE;
1452 LineDown();
1453 break;
1454 case kKey_PageUp:
1455 mark_ok = kTRUE;
1456 ScreenUp();
1457 break;
1458 case kKey_PageDown:
1459 mark_ok = kTRUE;
1460 ScreenDown();
1461 break;
1462 case kKey_Home:
1463 mark_ok = kTRUE;
1464 Home();
1465 break;
1466 case kKey_End:
1467 mark_ok = kTRUE;
1468 End();
1469 break;
1470 case kKey_Insert: // switch on/off insert mode
1472 break;
1473 default:
1474 break;
1475 }
1476 }
1477 if ((event->fState & kKeyShiftMask) && mark_ok) {
1478 fIsMarked = kTRUE;
1480 Copy();
1482 kTRUE);
1483 Marked(kTRUE);
1484 } else {
1485 UnMark();
1487 fWidgetId, kFALSE);
1490 }
1491 }
1492 return kTRUE;
1493}
1494
1495////////////////////////////////////////////////////////////////////////////////
1496/// Handle mouse crossing event.
1497
1499{
1500 if (event->fWindow != fCanvas->GetId()) {
1501 return kTRUE;
1502 }
1503 if (gVirtualX->GetInputFocus() != fCanvas->GetId()) {
1504 if (event->fType == kEnterNotify) {
1505 if (!fCurBlink) {
1506 fCurBlink = new TViewTimer(this, 500);
1507 }
1508 fCurBlink->Reset();
1510 } else {
1511 if (fCurBlink) fCurBlink->Remove();
1512 if (!fEnableCursorWithoutFocus && (fCursorState == 1)) {
1513 DrawCursor(2);
1514 fCursorState = 2;
1515 } else if (fCursorState == 2) {
1516 DrawCursor(1);
1517 fCursorState = 1;
1518 }
1519 }
1520 }
1521
1523
1524 return kTRUE;
1525}
1526
1527////////////////////////////////////////////////////////////////////////////////
1528/// Handle focus change event in text edit widget.
1529
1531{
1532 if (event->fWindow != fCanvas->GetId()) {
1533 return kTRUE;
1534 }
1535
1536 // check this when porting to Win32
1537 if ((event->fCode == kNotifyNormal) && (event->fState != kNotifyPointer)) {
1538 if (event->fType == kFocusIn) {
1539 if (!fCurBlink) {
1540 fCurBlink = new TViewTimer(this, 500);
1541 }
1542 fCurBlink->Reset();
1544 } else {
1545 if (fCurBlink) fCurBlink->Remove();
1546 if (fCursorState == 2) {
1547 DrawCursor(1);
1548 fCursorState = 1;
1549 }
1550 }
1551 fClient->NeedRedraw(this);
1552 }
1553 return kTRUE;
1554}
1555
1556////////////////////////////////////////////////////////////////////////////////
1557/// Invokes search dialog.
1558
1560{
1561 static TGSearchType *srch = 0;
1562 Int_t ret = 0;
1563
1564 if (!srch) srch = new TGSearchType;
1565 srch->fClose = close;
1566
1567 if (!close) {
1570 fCanvas, 400, 150, srch, &ret);
1571 }
1572 TGSearchDialog::SearchDialog()->Connect("TextEntered(char *)", "TGTextEdit",
1573 this, "Search(char *,Bool_t,Bool_t)");
1575 } else {
1576 new TGSearchDialog(fClient->GetDefaultRoot(), fCanvas, 400, 150, srch, &ret);
1577 if (ret) {
1578 Search(srch->fBuffer);
1579 }
1580 }
1581}
1582
1583////////////////////////////////////////////////////////////////////////////////
1584/// Process context menu messages.
1585
1587{
1588 TString msg2;
1589 TGTextView::ProcessMessage(msg, parm1, parm2);
1590
1591 switch(GET_MSG(msg)) {
1592 case kC_COMMAND:
1593 switch(GET_SUBMSG(msg)) {
1594 case kCM_MENU:
1595 switch (parm1) {
1596 case kM_FILE_NEW:
1597 case kM_FILE_CLOSE:
1598 case kM_FILE_OPEN:
1599 if (!IsSaved()) {
1600 Int_t retval;
1601 Bool_t untitled = !strlen(fText->GetFileName()) ? kTRUE : kFALSE;
1602
1603 msg2.Form("Save \"%s\"?",
1604 untitled ? "Untitled" : fText->GetFileName());
1605 new TGMsgBox(fClient->GetDefaultRoot(), this, "Editor",
1606 msg2.Data(), kMBIconExclamation,
1607 kMBYes | kMBNo | kMBCancel, &retval);
1608
1609 if (retval == kMBCancel)
1610 return kTRUE;
1611 if (retval == kMBYes)
1612 if (!SaveFile(0))
1613 return kTRUE;
1614 }
1615 Clear();
1616 if (parm1 == kM_FILE_CLOSE) {
1618 fWidgetId, 0);
1619 Closed();
1620 }
1621 if (parm1 == kM_FILE_OPEN) {
1622 TGFileInfo fi;
1624 new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen, &fi);
1625 if (fi.fFilename && strlen(fi.fFilename)) {
1626 LoadFile(fi.fFilename);
1628 fWidgetId, 0);
1629 Opened();
1630 }
1631 }
1632 break;
1633 case kM_FILE_SAVE:
1634 if (SaveFile(0)) {
1636 fWidgetId, 0);
1637 Saved();
1638 }
1639 break;
1640 case kM_FILE_SAVEAS:
1641 if (SaveFile(0, kTRUE)) {
1643 fWidgetId, 0);
1644 SavedAs();
1645 }
1646 break;
1647 case kM_FILE_PRINT:
1648 {
1649 Int_t ret = 0;
1650 if (!gPrinter) {
1651 gPrinter = StrDup("892_2_cor"); // use gEnv
1652 gPrintCommand = StrDup("xprint");
1653 }
1654 new TGPrintDialog(fClient->GetDefaultRoot(), this, 400, 150,
1655 &gPrinter, &gPrintCommand, &ret);
1656 if (ret)
1657 Print();
1658 }
1659 break;
1660 case kM_EDIT_CUT:
1661 Cut();
1662 break;
1663 case kM_EDIT_COPY:
1664 Copy();
1665 break;
1666 case kM_EDIT_PASTE:
1667 Paste();
1668 break;
1669 case kM_EDIT_SELECTALL:
1670 SelectAll();
1671 break;
1672 case kM_SEARCH_FIND:
1673 {
1674 Search(kFALSE);
1675 }
1676 break;
1678 if (!fSearch) {
1680 kM_SEARCH_FIND, 0);
1681 return kTRUE;
1682 }
1685 msg2.Form("Couldn't find \"%s\"", fSearch->fBuffer);
1686 new TGMsgBox(fClient->GetDefaultRoot(), this, "Editor",
1687 msg2.Data(), kMBIconExclamation, kMBOk, 0);
1688 }
1689 break;
1690 case kM_SEARCH_GOTO:
1691 {
1692 Long_t ret = fCurrent.fY+1;
1693 new TGGotoDialog(fClient->GetDefaultRoot(), this, 400, 150, &ret);
1694 if (ret > -1) {
1695 ret--; // user specifies lines starting at 1
1696 Goto(ret);
1697 }
1698 }
1699 break;
1700 default:
1701 printf("No action implemented for menu id %ld\n", parm1);
1702 break;
1703 }
1704 default:
1705 break;
1706 }
1707 break;
1708
1709 default:
1710 break;
1711 }
1712 return kTRUE;
1713}
1714
1715////////////////////////////////////////////////////////////////////////////////
1716/// Insert a character in the text edit widget.
1717
1718void TGTextEdit::InsChar(char character)
1719{
1720 if (fReadOnly) return;
1721
1722 char *charstring = 0;
1723 TGLongPosition pos;
1724
1725 if (character == '\t') {
1726 pos.fX = fCurrent.fX;
1727 pos.fY = fCurrent.fY;
1728 fText->InsChar(pos, '\t');
1729 pos.fX++;
1730 while (pos.fX & 0x7) {
1731 pos.fX++;
1732 }
1733 fText->ReTab(pos.fY);
1735 UInt_t(ToScrYCoord(pos.fY+1) - ToScrYCoord(pos.fY)));
1737 if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
1738 if (pos.fX != fText->GetLineLength(fCurrent.fY)) {
1740 } else {
1742 }
1743 }
1744 SetCurrent(pos);
1745 return;
1746 } else {
1747 if (fInsertMode == kReplace) {
1748 fCurrent.fX++;
1749 new TDelCharCom(this);
1750 }
1751 fText->InsChar(fCurrent, character);
1752 pos.fX = fCurrent.fX + 1;
1753 pos.fY = fCurrent.fY;
1754 charstring = new char[2];
1755 charstring[1] = '\0';
1756 charstring[0] = character;
1757 }
1759 if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
1760 if (pos.fX != fText->GetLineLength(fCurrent.fY)) {
1762 } else {
1763 SetHsbPosition(fVisible.fX/fScrollVal.fX+strlen(charstring));
1764 }
1765 if (!fHsb)
1766 gVirtualX->DrawString(fCanvas->GetId(), fNormGC(),
1769 charstring, strlen(charstring));
1770 } else {
1771#ifdef R__HAS_COCOA
1772 //I would use const, but some members of TGTextLine are non-const.
1773 if (TGTextLine *currentLine = fText->GetCurrentLine()) {
1774 const ULong_t lineStart = ToObjXCoord(fVisible.fX, fCurrent.fY);
1775 if (lineStart < currentLine->GetLineLength()) {
1776 const char *textToRender = currentLine->GetText(lineStart, currentLine->GetLineLength() - lineStart);
1777 //The next two lines can throw and textToRender will leak, but ROOT does not care about such things. :(
1778 gVirtualX->ClearArea(fCanvas->GetId(), Int_t(ToScrXCoord(0, fCurrent.fY)),
1779 Int_t(ToScrYCoord(fCurrent.fY)), UInt_t(ToScrXCoord(currentLine->GetLineLength(), fCurrent.fY)),
1781 gVirtualX->DrawString(fCanvas->GetId(), fNormGC(), Int_t(ToScrXCoord(0, fCurrent.fY)),
1783 textToRender, -1);
1784 delete [] textToRender;
1785 }
1786 }
1787#else
1788 gVirtualX->CopyArea(fCanvas->GetId(), fCanvas->GetId(), fNormGC(),
1794 gVirtualX->ClearArea(fCanvas->GetId(),
1797 UInt_t(ToScrXCoord(fCurrent.fX+strlen(charstring), fCurrent.fY) -
1800 gVirtualX->DrawString(fCanvas->GetId(), fNormGC(),
1803 charstring, strlen(charstring));
1804 fCursorState = 2; // the ClearArea effectively turned off the cursor
1805#endif
1806 }
1807 delete [] charstring;
1808 SetCurrent(pos);
1809}
1810
1811////////////////////////////////////////////////////////////////////////////////
1812/// Delete a character from the text edit widget.
1813
1815{
1816 if (fReadOnly) {
1817 return;
1818 }
1819
1820 char *buffer;
1821 TGLongPosition pos, pos2;
1822 Long_t len;
1823
1824 pos.fY = fCurrent.fY;
1825 pos.fX = fCurrent.fX;
1826 UInt_t h = 0;
1827
1828 if (fCurrent.fX > 0) {
1829 Int_t y = (Int_t)ToScrYCoord(pos.fY);
1830 h = UInt_t(ToScrYCoord(pos.fY+2) - y);
1831 if (!y) h = h << 1;
1832
1833 pos.fX--;
1834 if (fText->GetChar(pos) == 16) {
1835 do {
1836 pos.fX++;
1837 fText->DelChar(pos);
1838 pos.fX -= 2;
1839 } while (fText->GetChar(pos) != '\t');
1840
1841 pos.fX++;
1842 fText->DelChar(pos);
1843 pos.fX--;
1844 fText->ReTab(pos.fY);
1845 UpdateRegion(0, y, fCanvas->GetWidth(), h);
1846 } else {
1847 pos.fX = fCurrent.fX;
1848 fText->DelChar(pos);
1849 pos.fX = fCurrent.fX - 1;
1850 }
1851 if (ToScrXCoord(fCurrent.fX-1, fCurrent.fY) < 0) {
1853 }
1855 UpdateRegion(0, y, fCanvas->GetWidth(), h);
1856 } else {
1857 if (fCurrent.fY > 0) {
1859 if (len > 0) {
1860 buffer = fText->GetLine(fCurrent, len);
1861 pos.fY--;
1862 pos.fX = fText->GetLineLength(fCurrent.fY-1);
1863 fText->InsText(pos, buffer);
1864 pos.fY++;
1865 delete [] buffer;
1866 } else {
1867 pos.fX = fText->GetLineLength(fCurrent.fY-1);
1868 }
1869
1870 pos2.fY = ToScrYCoord(fCurrent.fY+1);
1871 pos.fY = fCurrent.fY - 1;
1873 len = fText->GetLineLength(fCurrent.fY-1);
1874
1875 if (ToScrXCoord(pos.fX, fCurrent.fY-1) >= (Int_t)fCanvas->GetWidth()) {
1877 }
1878
1879#ifdef R__HAS_COCOA
1881#else
1883 gVirtualX->CopyArea(fCanvas->GetId(), fCanvas->GetId(), fNormGC(), 0,
1884 Int_t(pos2.fY), fWidth, h, 0, (Int_t)ToScrYCoord(fCurrent.fY));
1885 if (ToScrYCoord(pos.fY) < 0) {
1887 }
1889#endif
1892 }
1893 }
1894
1895 SetCurrent(pos);
1896}
1897
1898////////////////////////////////////////////////////////////////////////////////
1899/// Break a line.
1900
1902{
1903 if (fReadOnly) return;
1904
1905 TGLongPosition pos;
1907 if (ToScrYCoord(fCurrent.fY+2) <= (Int_t)fCanvas->GetHeight()) {
1908#ifdef R__HAS_COCOA
1910#else
1911 gVirtualX->CopyArea(fCanvas->GetId(), fCanvas->GetId(), fNormGC(), 0,
1915 0, (Int_t)ToScrYCoord(fCurrent.fY+2));
1918#endif
1919 if (fVisible.fX != 0) {
1920 SetHsbPosition(0);
1921 }
1924 } else {
1930 }
1931 pos.fY = fCurrent.fY+1;
1932 pos.fX = 0;
1933 SetCurrent(pos);
1934}
1935
1936////////////////////////////////////////////////////////////////////////////////
1937/// Scroll the canvas to new_top in the kVertical or kHorizontal direction.
1938
1939void TGTextEdit::ScrollCanvas(Int_t new_top, Int_t direction)
1940{
1941 CursorOff();
1942
1943 TGTextView::ScrollCanvas(new_top, direction);
1944
1945 CursorOn();
1946}
1947
1948////////////////////////////////////////////////////////////////////////////////
1949/// Redraw the text edit widget.
1950
1952{
1953 CursorOff();
1954
1955 TGTextView::DrawRegion(x, y, width, height);
1956
1957 CursorOn();
1958}
1959
1960////////////////////////////////////////////////////////////////////////////////
1961/// Go to the previous character.
1962
1964{
1965 if (fCurrent.fY == 0 && fCurrent.fX == 0) {
1966 gVirtualX->Bell(0);
1967 return;
1968 }
1969
1970 TGLongPosition pos;
1971 Long_t len;
1972
1973 pos.fY = fCurrent.fY;
1974 pos.fX = fCurrent.fX;
1975 if (fCurrent.fX > 0) {
1976 pos.fX--;
1977 while (fText->GetChar(pos) == 16) {
1978 pos.fX--;
1979 }
1980
1981 if (ToScrXCoord(pos.fX, pos.fY) < 0) {
1982 if (fVisible.fX-(Int_t)fCanvas->GetWidth()/2 >= 0) {
1984 } else {
1985 SetHsbPosition(0);
1986 }
1987 }
1988 } else {
1989 if (fCurrent.fY > 0) {
1990 pos.fY = fCurrent.fY - 1;
1991 len = fText->GetLineLength(pos.fY);
1992 if (ToScrYCoord(fCurrent.fY) <= 0) {
1994 }
1995 if (ToScrXCoord(len, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
1998 }
1999 pos.fX = len;
2000 }
2001 }
2002 SetCurrent(pos);
2003}
2004
2005////////////////////////////////////////////////////////////////////////////////
2006/// Go to next character.
2007
2009{
2011
2012 if (fCurrent.fY == fText->RowCount()-1 && fCurrent.fX == len) {
2013 gVirtualX->Bell(0);
2014 return;
2015 }
2016
2017 TGLongPosition pos;
2018 pos.fY = fCurrent.fY;
2019 if (fCurrent.fX < len) {
2020 if (fText->GetChar(fCurrent) == '\t') {
2021 pos.fX = fCurrent.fX + 8 - (fCurrent.fX & 0x7);
2022 } else {
2023 pos.fX = fCurrent.fX + 1;
2024 }
2025
2026 if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
2028 }
2029 } else {
2030 if (fCurrent.fY < fText->RowCount()-1) {
2031 pos.fY = fCurrent.fY + 1;
2032 if (ToScrYCoord(pos.fY+1) >= (Int_t)fCanvas->GetHeight()) {
2034 }
2035 SetHsbPosition(0);
2036 pos.fX = 0;
2037 }
2038 }
2039 SetCurrent(pos);
2040}
2041
2042////////////////////////////////////////////////////////////////////////////////
2043/// Make current position first line in window by scrolling up.
2044
2046{
2047 TGLongPosition pos;
2048 Long_t len;
2049 if (fCurrent.fY > 0) {
2050 pos.fY = fCurrent.fY - 1;
2051 if (ToScrYCoord(fCurrent.fY) <= 0) {
2053 }
2054 len = fText->GetLineLength(fCurrent.fY-1);
2055 if (fCurrent.fX > len) {
2056 if (ToScrXCoord(len, pos.fY) <= 0) {
2057 if (ToScrXCoord(len, pos.fY) < 0) {
2058 SetHsbPosition(ToScrXCoord(len, pos.fY)+
2060 } else {
2061 SetHsbPosition(0);
2062 }
2063 }
2064 pos.fX = len;
2065 } else {
2067 }
2068
2069 while (fText->GetChar(pos) == 16) {
2070 pos.fX++;
2071 }
2072 SetCurrent(pos);
2073 }
2074}
2075
2076////////////////////////////////////////////////////////////////////////////////
2077/// Move one line down.
2078
2080{
2081 TGLongPosition pos;
2082 Long_t len;
2083 if (fCurrent.fY < fText->RowCount()-1) {
2084 len = fText->GetLineLength(fCurrent.fY+1);
2085 pos.fY = fCurrent.fY + 1;
2086 if (ToScrYCoord(pos.fY+1) > (Int_t)fCanvas->GetHeight()) {
2088 }
2089 if (fCurrent.fX > len) {
2090 if (ToScrXCoord(len, pos.fY) <= 0) {
2091 if (ToScrXCoord(len, pos.fY) < 0) {
2093 } else {
2094 SetHsbPosition(0);
2095 }
2096 }
2097 pos.fX = len;
2098 } else {
2100 }
2101
2102 while (fText->GetChar(pos) == 16) {
2103 pos.fX++;
2104 }
2105 SetCurrent(pos);
2106 }
2107}
2108
2109////////////////////////////////////////////////////////////////////////////////
2110/// Move one screen up.
2111
2113{
2114 TGLongPosition pos;
2115 pos.fX = fCurrent.fX;
2117 if (fVisible.fY - (Int_t)fCanvas->GetHeight() >= 0) { // +1
2119 } else {
2120 pos.fY = 0;
2121 SetVsbPosition(0);
2122 }
2123 while (fText->GetChar(pos) == 16) {
2124 pos.fX++;
2125 }
2126 SetCurrent(pos);
2127}
2128
2129////////////////////////////////////////////////////////////////////////////////
2130/// Move one screen down.
2131
2133{
2134 TGLongPosition pos;
2135 pos.fX = fCurrent.fX;
2137 Long_t count = fText->RowCount()-1;
2138 if ((Int_t)fCanvas->GetHeight() < ToScrYCoord(count)) {
2140 } else {
2141 pos.fY = count;
2142 }
2143 while (fText->GetChar(pos) == 16) {
2144 pos.fX++;
2145 }
2146 SetCurrent(pos);
2147}
2148
2149////////////////////////////////////////////////////////////////////////////////
2150/// Move to beginning of line.
2151
2153{
2154 TGLongPosition pos;
2155 pos.fY = fCurrent.fY;
2156 pos.fX = 0;
2157 SetHsbPosition(0);
2158 SetCurrent(pos);
2159}
2160
2161////////////////////////////////////////////////////////////////////////////////
2162/// Move to end of line.
2163
2165{
2166 TGLongPosition pos;
2167 pos.fY = fCurrent.fY;
2168 pos.fX = fText->GetLineLength(pos.fY);
2169 if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
2171 }
2172 SetCurrent(pos);
2173}
2174
2175////////////////////////////////////////////////////////////////////////////////
2176/// Return selection graphics context for text cursor.
2177
2179{
2180 if (!fgCursor0GC) {
2183 }
2184 return *fgCursor0GC;
2185}
2186
2187////////////////////////////////////////////////////////////////////////////////
2188/// Return default graphics context for text cursor.
2189
2191{
2192 if (!fgCursor1GC) {
2193 fgCursor1GC = new TGGC(GetDefaultGC());
2195 }
2196 return *fgCursor1GC;
2197}
2198
2199////////////////////////////////////////////////////////////////////////////////
2200/// Save a text edit widget as a C++ statement(s) on output stream out
2201
2202void TGTextEdit::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2203{
2204 char quote = '"';
2205 out << " TGTextEdit *";
2206 out << GetName() << " = new TGTextEdit(" << fParent->GetName()
2207 << "," << GetWidth() << "," << GetHeight()
2208 << ");"<< std::endl;
2209 if (option && strstr(option, "keep_names"))
2210 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
2211
2212 if (IsReadOnly()) {
2213 out << " " << GetName() << "->SetReadOnly(kTRUE);" << std::endl;
2214 }
2215
2216 if (!IsMenuEnabled()) {
2217 out << " " << GetName() << "->EnableMenu(kFALSE);" << std::endl;
2218 }
2219
2221 out << " " << GetName() << "->ChangeBackground(" << fCanvas->GetBackground() << ");" << std::endl;
2222 }
2223
2224 TGText *txt = GetText();
2225 Bool_t fromfile = strlen(txt->GetFileName()) ? kTRUE : kFALSE;
2226 TString fn;
2227
2228 if (fromfile) {
2229 const char *filename = txt->GetFileName();
2230 fn = gSystem->UnixPathName(filename);
2232 } else {
2233 fn = TString::Format("Txt%s", GetName()+5);
2234 txt->Save(fn.Data());
2235 }
2236 out << " " << GetName() << "->LoadFile(" << quote << fn.Data() << quote << ");" << std::endl;
2237}
@ kGKeyPress
Definition: GuiTypes.h:59
@ kButtonPress
Definition: GuiTypes.h:59
@ kFocusIn
Definition: GuiTypes.h:60
@ kEnterNotify
Definition: GuiTypes.h:60
@ kNotifyNormal
Definition: GuiTypes.h:218
@ kNotifyPointer
Definition: GuiTypes.h:219
@ kGXxor
Definition: GuiTypes.h:73
@ kGXand
Definition: GuiTypes.h:68
const Mask_t kKeyShiftMask
Definition: GuiTypes.h:194
Handle_t Atom_t
Definition: GuiTypes.h:36
const Handle_t kNone
Definition: GuiTypes.h:87
const Mask_t kKeyControlMask
Definition: GuiTypes.h:196
@ kButton2
Definition: GuiTypes.h:213
@ kButton3
Definition: GuiTypes.h:213
@ kButton1
Definition: GuiTypes.h:213
Handle_t Window_t
Definition: GuiTypes.h:28
EKeySym
Definition: KeySymbols.h:25
@ kKey_Right
Definition: KeySymbols.h:42
@ kKey_Down
Definition: KeySymbols.h:43
@ kKey_Meta
Definition: KeySymbols.h:51
@ kKey_Y
Definition: KeySymbols.h:150
@ kKey_B
Definition: KeySymbols.h:127
@ kKey_PageDown
Definition: KeySymbols.h:47
@ kKey_F
Definition: KeySymbols.h:131
@ kKey_L
Definition: KeySymbols.h:137
@ kKey_CapsLock
Definition: KeySymbols.h:53
@ kKey_Up
Definition: KeySymbols.h:41
@ kKey_Return
Definition: KeySymbols.h:30
@ kKey_Alt
Definition: KeySymbols.h:52
@ kKey_C
Definition: KeySymbols.h:128
@ kKey_ScrollLock
Definition: KeySymbols.h:55
@ kKey_Delete
Definition: KeySymbols.h:33
@ kKey_A
Definition: KeySymbols.h:126
@ kKey_F3
Definition: KeySymbols.h:59
@ kKey_Left
Definition: KeySymbols.h:40
@ kKey_Shift
Definition: KeySymbols.h:49
@ kKey_E
Definition: KeySymbols.h:130
@ kKey_Backspace
Definition: KeySymbols.h:29
@ kKey_Z
Definition: KeySymbols.h:151
@ kKey_D
Definition: KeySymbols.h:129
@ kKey_X
Definition: KeySymbols.h:149
@ kKey_Home
Definition: KeySymbols.h:38
@ kKey_U
Definition: KeySymbols.h:146
@ kKey_Insert
Definition: KeySymbols.h:32
@ kKey_Enter
Definition: KeySymbols.h:31
@ kKey_Control
Definition: KeySymbols.h:50
@ kKey_Tab
Definition: KeySymbols.h:27
@ kKey_H
Definition: KeySymbols.h:133
@ kKey_End
Definition: KeySymbols.h:39
@ kKey_NumLock
Definition: KeySymbols.h:54
@ kKey_PageUp
Definition: KeySymbols.h:45
@ kKey_K
Definition: KeySymbols.h:136
@ kKey_V
Definition: KeySymbols.h:147
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:43
unsigned int UInt_t
Definition: RtypesCore.h:44
const Bool_t kFALSE
Definition: RtypesCore.h:90
unsigned long ULong_t
Definition: RtypesCore.h:53
long Long_t
Definition: RtypesCore.h:52
bool Bool_t
Definition: RtypesCore.h:61
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
@ kFDOpen
Definition: TGFileDialog.h:38
@ kFDSave
Definition: TGFileDialog.h:39
@ kMBNo
Definition: TGMsgBox.h:43
@ kMBYes
Definition: TGMsgBox.h:42
@ kMBCancel
Definition: TGMsgBox.h:48
@ kMBOk
Definition: TGMsgBox.h:44
@ kMBIconExclamation
Definition: TGMsgBox.h:35
@ kMBIconAsterisk
Definition: TGMsgBox.h:36
static Bool_t gDbl_clk
static Bool_t gTrpl_clk
static const char * gFiletypes[]
Definition: TGTextEdit.cxx:49
static char * gPrinter
Definition: TGTextEdit.cxx:53
static char * gPrintCommand
Definition: TGTextEdit.cxx:54
XFontStruct * id
Definition: TGX11.cxx:108
R__EXTERN void * gTQSender
Definition: TQObject.h:44
Binding & operator=(OUT(*fun)(void))
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2490
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
#define gVirtualX
Definition: TVirtualX.h:338
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
Int_t GET_MSG(Long_t val)
@ kC_TEXTVIEW
@ kTXT_OPEN
@ kCM_MENU
@ kTXT_SAVE
@ kTXT_CLOSE
@ kTXT_ISMARKED
@ kTXT_DATACHANGE
@ kC_COMMAND
@ kTXT_F3
Int_t GET_SUBMSG(Long_t val)
virtual Bool_t Notify()
'Notify' all objects in this collection.
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:234
Bool_t IsEditable() const
Definition: TGClient.h:98
const TGResourcePool * GetResourcePool() const
Definition: TGClient.h:133
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:372
char * fFilename
Definition: TGFileDialog.h:61
const char ** fFileTypes
Definition: TGFileDialog.h:63
char * fIniDir
Definition: TGFileDialog.h:62
Bool_t fOverwrite
Definition: TGFileDialog.h:65
void SetIniDir(const char *inidir)
Set directory name.
virtual void MapRaised()
map raised
Definition: TGFrame.h:230
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:629
static Time_t fgLastClick
Definition: TGFrame.h:135
UInt_t fWidth
Definition: TGFrame.h:112
UInt_t GetHeight() const
Definition: TGFrame.h:250
virtual Pixel_t GetBackground() const
Definition: TGFrame.h:217
static Pixel_t fgWhitePixel
Definition: TGFrame.h:128
UInt_t GetWidth() const
Definition: TGFrame.h:249
Definition: TGGC.h:31
void SetFunction(EGraphicsFunction v)
Set graphics context drawing function.
Definition: TGGC.cxx:254
TGClient * fClient
Definition: TGObject.h:37
Handle_t GetId() const
Definition: TGObject.h:47
Handle_t fId
Definition: TGObject.h:36
virtual void AddEntry(TGHotString *s, Int_t id, void *ud=0, const TGPicture *p=0, TGMenuEntry *before=0)
Add a menu entry.
Definition: TGMenu.cxx:988
virtual void AddSeparator(TGMenuEntry *before=0)
Add a menu separator to the menu.
Definition: TGMenu.cxx:1058
virtual void DisableEntry(Int_t id)
Disable entry (disabled entries appear in a sunken relieve).
Definition: TGMenu.cxx:1722
virtual void EnableEntry(Int_t id)
Enable entry. By default entries are enabled.
Definition: TGMenu.cxx:1703
virtual void Associate(const TGWindow *w)
Definition: TGMenu.h:219
virtual void PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode, Bool_t grab_pointer)
Popup a popup menu.
Definition: TGMenu.cxx:1239
virtual Bool_t IsEntryEnabled(Int_t id)
Return true if menu entry is enabled.
Definition: TGMenu.cxx:1734
Cursor_t GetTextCursor() const
virtual TGSearchType * GetType() const
static TGSearchDialog *& SearchDialog()
Return global search dialog.
TGLongPosition fCurrent
Definition: TGTextEdit.h:53
TGTextEditHist * fHistory
Definition: TGTextEdit.h:56
GContext_t fCursor1GC
Definition: TGTextEdit.h:48
virtual void Closed()
Definition: TGTextEdit.h:136
virtual Bool_t HandleFocusChange(Event_t *event)
Handle focus change event in text edit widget.
virtual Bool_t Goto(Long_t line, Long_t column=0)
Goto the specified line.
Definition: TGTextEdit.cxx:738
virtual Bool_t HandleDoubleClick(Event_t *event)
Handle double click event.
static TGGC * fgCursor0GC
Definition: TGTextEdit.h:60
static const TGGC & GetCursor1GC()
Return default graphics context for text cursor.
@ kM_SEARCH_GOTO
Definition: TGTextEdit.h:43
@ kM_FILE_SAVEAS
Definition: TGTextEdit.h:41
@ kM_SEARCH_FINDAGAIN
Definition: TGTextEdit.h:43
@ kM_FILE_PRINT
Definition: TGTextEdit.h:42
@ kM_EDIT_SELECTALL
Definition: TGTextEdit.h:42
@ kM_FILE_OPEN
Definition: TGTextEdit.h:41
@ kM_FILE_SAVE
Definition: TGTextEdit.h:41
@ kM_EDIT_COPY
Definition: TGTextEdit.h:42
@ kM_SEARCH_FIND
Definition: TGTextEdit.h:43
@ kM_FILE_CLOSE
Definition: TGTextEdit.h:41
@ kM_EDIT_PASTE
Definition: TGTextEdit.h:42
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process context menu messages.
virtual void Saved()
Definition: TGTextEdit.h:138
virtual Bool_t Replace(TGLongPosition pos, const char *oldText, const char *newText, Bool_t direction, Bool_t caseSensitive)
Replace text starting at textPos.
Definition: TGTextEdit.cxx:696
virtual void DrawCursor(Int_t mode)
Draw cursor. If mode = 1 draw cursor, if mode = 2 erase cursor.
Definition: TGTextEdit.cxx:824
virtual Bool_t Copy()
Copy text.
Definition: TGTextEdit.cxx:416
TList * GetHistory() const
Definition: TGTextEdit.h:113
virtual void AdjustPos()
Adjust current position.
Definition: TGTextEdit.cxx:901
virtual Bool_t SaveFile(const char *fname, Bool_t saveas=kFALSE)
Save file.
Definition: TGTextEdit.cxx:388
EInsertMode GetInsertMode() const
Definition: TGTextEdit.h:109
virtual void DrawRegion(Int_t x, Int_t y, UInt_t width, UInt_t height)
Redraw the text edit widget.
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
virtual void SetMenuState()
Enable/disable menu items in function of what is possible.
Definition: TGTextEdit.cxx:327
virtual Bool_t Cut()
Cut text.
Definition: TGTextEdit.cxx:442
Bool_t fEnableMenu
Definition: TGTextEdit.h:55
TGLongPosition GetCurrentPos() const
Definition: TGTextEdit.h:122
virtual Long_t ReturnLongestLineWidth()
Return width of longest line in widget.
Definition: TGTextEdit.cxx:366
virtual void Print(Option_t *="") const
Send current buffer to printer.
Definition: TGTextEdit.cxx:477
virtual void DelChar()
Delete a character from the text edit widget.
virtual Bool_t HandleSelection(Event_t *event)
Handle selection notify event.
Definition: TGTextEdit.cxx:946
GContext_t fCursor0GC
Definition: TGTextEdit.h:47
virtual Bool_t HandleKey(Event_t *event)
The key press event handler converts a key press to some line editor action.
virtual void SavedAs()
Definition: TGTextEdit.h:139
virtual void LineDown()
Move one line down.
virtual void Clear(Option_t *="")
Clear text edit widget.
Definition: TGTextEdit.cxx:376
virtual void ScreenDown()
Move one screen down.
virtual void Delete(Option_t *="")
Delete selection.
Definition: TGTextEdit.cxx:532
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a text edit widget as a C++ statement(s) on output stream out.
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in text edit widget.
virtual void LineUp()
Make current position first line in window by scrolling up.
EInsertMode fInsertMode
Definition: TGTextEdit.h:54
virtual void CursorOn()
Turn cursor on.
Definition: TGTextEdit.cxx:795
virtual void SetCurrent(TGLongPosition new_coord)
Make the specified position the current position.
Definition: TGTextEdit.cxx:808
virtual void NextChar()
Go to next character.
virtual void ScreenUp()
Move one screen up.
virtual void BreakLine()
Break a line.
virtual ~TGTextEdit()
Cleanup text edit widget.
Definition: TGTextEdit.cxx:272
TGTextEdit(const TGTextEdit &)
virtual void FindAgain()
Definition: TGTextEdit.h:135
virtual void InsChar(char character)
Insert a character in the text edit widget.
virtual void SetInsertMode(EInsertMode mode=kInsert)
Sets the mode how characters are entered.
Definition: TGTextEdit.cxx:774
virtual void CursorOff()
If cursor if on, turn it off.
Definition: TGTextEdit.cxx:784
virtual Bool_t Search(const char *string, Bool_t direction=kTRUE, Bool_t caseSensitive=kFALSE)
Search for string in the specified direction.
Definition: TGTextEdit.cxx:634
Int_t fCursorState
Definition: TGTextEdit.h:49
TGSearchType * fSearch
Definition: TGTextEdit.h:52
virtual void Opened()
Definition: TGTextEdit.h:137
virtual void PrevChar()
Go to the previous character.
virtual Bool_t Paste()
Paste text into widget.
Definition: TGTextEdit.cxx:455
virtual Bool_t IsMenuEnabled() const
Definition: TGTextEdit.h:112
virtual void SetFocus()
Definition: TGTextEdit.h:119
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in text edit widget.
TGPopupMenu * fMenu
Definition: TGTextEdit.h:51
virtual void ScrollCanvas(Int_t newTop, Int_t direction)
Scroll the canvas to new_top in the kVertical or kHorizontal direction.
Bool_t fEnableCursorWithoutFocus
Definition: TGTextEdit.h:57
virtual void Home()
Move to beginning of line.
static TGGC * fgCursor1GC
Definition: TGTextEdit.h:61
TViewTimer * fCurBlink
Definition: TGTextEdit.h:50
virtual void End()
Move to end of line.
void Init()
Initiliaze a text edit widget.
Definition: TGTextEdit.cxx:285
static const TGGC & GetCursor0GC()
Return selection graphics context for text cursor.
virtual Bool_t HandleTimer(TTimer *t)
Handle timer cursor blink timer.
Definition: TGTextEdit.cxx:925
ULong_t GetLineLength()
Definition: TGText.h:51
char * GetText(ULong_t pos, ULong_t length)
Get length characters from line starting at pos.
Definition: TGText.cxx:183
Int_t fMaxDescent
Definition: TGTextView.h:40
virtual void Update()
update the whole window of text view
Definition: TGTextView.cxx:261
TGGC fNormGC
Definition: TGTextView.h:42
Bool_t fReadOnly
Definition: TGTextView.h:50
TGText * fText
Definition: TGTextView.h:36
virtual void UnMark()
Clear marked region.
virtual Bool_t IsSaved()
Definition: TGTextView.h:88
virtual Long_t ToObjXCoord(Long_t xCoord, Long_t line)
Convert x screen coordinate to column in specified line.
Definition: TGTextView.cxx:391
virtual void SetHsbPosition(Long_t newPos)
Set position of horizontal scrollbar.
virtual Bool_t LoadFile(const char *fname, long startpos=0, long length=-1)
Load a file in the text view widget.
Definition: TGTextView.cxx:453
virtual void Mark(Long_t xPos, Long_t yPos)
Mark a text region from xPos to yPos.
virtual Long_t ToScrYCoord(Long_t yCoord)
Convert line number to screen coordinate.
Definition: TGTextView.cxx:345
virtual Long_t ReturnLongestLineWidth()
Return width of longest line.
Definition: TGTextView.cxx:271
TGText * fClipText
Definition: TGTextView.h:37
static const TGGC & GetDefaultSelectedGC()
Return selection graphics context in use.
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in the text editor widget.
Definition: TGTextView.cxx:909
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Bool_t fIsMarked
Definition: TGTextView.h:47
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
Definition: TGTextView.cxx:673
virtual void Clicked(const char *word)
Definition: TGTextView.h:149
TGGC fSelbackGC
Definition: TGTextView.h:44
TGGC fSelGC
Definition: TGTextView.h:43
virtual Bool_t SelectAll()
Select all text in the viewer.
Definition: TGTextView.cxx:516
TGText * GetText() const
Definition: TGTextView.h:126
virtual void SetVsbPosition(Long_t newPos)
Set position of vertical scrollbar.
TGLongPosition fMarkedEnd
Definition: TGTextView.h:52
virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw lines in exposed region.
Definition: TGTextView.cxx:538
virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line)
Convert column number in specified line to screen coordinate.
Definition: TGTextView.cxx:359
virtual void Clear(Option_t *="")
Clear text view widget.
Definition: TGTextView.cxx:429
virtual void Marked(Bool_t mark)
Definition: TGTextView.h:148
virtual void DataChanged()
Definition: TGTextView.h:146
Bool_t IsReadOnly() const
Definition: TGTextView.h:129
virtual Bool_t Copy()
Copy selected text to clipboard.
Definition: TGTextView.cxx:485
virtual void DoubleClicked(const char *word)
Definition: TGTextView.h:150
virtual Bool_t HandleTimer(TTimer *t)
Handle scroll timer.
Definition: TGTextView.cxx:718
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in text editor.
Definition: TGTextView.cxx:823
virtual void SetSBRange(Int_t direction)
Set the range for the kVertical or kHorizontal scrollbar.
TGLongPosition fMarkedStart
Definition: TGTextView.h:51
virtual Long_t ToObjYCoord(Long_t yCoord)
Convert y screen coordinate to line number.
Definition: TGTextView.cxx:383
Definition: TGText.h:67
Bool_t InsChar(TGLongPosition pos, char c)
Insert character c at the specified position pos.
Definition: TGText.cxx:706
void ReTab(Long_t row)
Redo all tabs in a line. Needed after a new tab is inserted.
Definition: TGText.cxx:1086
Long_t RowCount() const
Definition: TGText.h:116
Bool_t DelText(TGLongPosition start, TGLongPosition end)
Delete text between start and end positions.
Definition: TGText.cxx:735
Bool_t Search(TGLongPosition *foundPos, TGLongPosition start, const char *searchString, Bool_t direction, Bool_t caseSensitive)
Search for string searchString starting at the specified position going in forward (direction = true)...
Definition: TGText.cxx:1142
Bool_t DelLine(ULong_t pos)
Delete specified row. Returns false if row does not exist.
Definition: TGText.cxx:963
Bool_t Save(const char *fn)
Save text buffer to file fn.
Definition: TGText.cxx:609
Bool_t Replace(TGLongPosition start, const char *oldText, const char *newText, Bool_t direction, Bool_t caseSensitive)
Replace oldText by newText. Returns false if nothing replaced.
Definition: TGText.cxx:1196
Bool_t DelChar(TGLongPosition pos)
Delete character at specified position pos.
Definition: TGText.cxx:690
Bool_t BreakLine(TGLongPosition pos)
Break line at position pos. Returns false if pos is not valid.
Definition: TGText.cxx:1007
Bool_t InsText(TGLongPosition pos, const char *buf)
Insert single line at specified position.
Definition: TGText.cxx:887
char * GetLine(TGLongPosition pos, ULong_t length)
Return string at position pos.
Definition: TGText.cxx:996
char GetChar(TGLongPosition pos)
Get character a position pos. If charcater not valid return -1.
Definition: TGText.cxx:722
Bool_t LoadBuffer(const char *txtbuf)
Load a 0 terminated buffer. Lines will be split at ' '.
Definition: TGText.cxx:512
void Clear()
Clear text buffer.
Definition: TGText.cxx:405
TGTextLine * GetCurrentLine() const
Definition: TGText.h:112
const char * GetFileName() const
Definition: TGText.h:98
Long_t GetLineLength(Long_t row)
Get length of specified line. Returns -1 if row does not exist.
Definition: TGText.cxx:1042
TString AsString()
Returns content as ROOT string.
Definition: TGText.cxx:1237
Atom_t fClipboard
Definition: TGView.h:59
TGHScrollBar * fHsb
Definition: TGView.h:63
TGVScrollBar * fVsb
Definition: TGView.h:64
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process scrollbar messages.
Definition: TGView.cxx:314
TGLongPosition fVisible
Definition: TGView.h:52
Int_t fScrolling
Definition: TGView.h:58
TGLongPosition fScrollVal
Definition: TGView.h:54
TGViewFrame * fCanvas
Definition: TGView.h:62
virtual void UpdateRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
update a part of view
Definition: TGView.cxx:202
virtual void ScrollCanvas(Int_t newTop, Int_t direction)
Scroll the canvas to new_top in the kVertical or kHorizontal direction.
Definition: TGView.cxx:462
TGRectangle fExposedRegion
Definition: TGView.h:56
@ kHorizontal
Definition: TGView.h:49
@ kVertical
Definition: TGView.h:49
Int_t fWidgetId
Definition: TGWidget.h:58
const TGWindow * fMsgWindow
Definition: TGWidget.h:60
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:326
const TGWindow * fParent
Definition: TGWindow.h:36
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
Definition: TGWindow.cxx:285
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual void RemoveLast()
Remove the last object of the list.
Definition: TList.cxx:908
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:692
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:469
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition: TObject.cxx:506
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:866
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
Definition: TQObject.cxx:1024
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
const char * Data() const
Definition: TString.h:364
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2311
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2289
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1269
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
Definition: TSystem.cxx:660
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition: TSystem.cxx:1058
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition: TSystem.cxx:469
virtual int ClosePipe(FILE *pipe)
Close the pipe.
Definition: TSystem.cxx:669
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
void Reset()
Reset the timer.
Definition: TTimer.cxx:157
void Remove()
Definition: TTimer.h:85
TText * text
TLine * line
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
EGEventType fType
Definition: GuiTypes.h:174
Int_t fY
Definition: GuiTypes.h:177
Int_t fXRoot
Definition: GuiTypes.h:178
Window_t fWindow
Definition: GuiTypes.h:175
UInt_t fState
Definition: GuiTypes.h:180
Int_t fYRoot
Definition: GuiTypes.h:178
Int_t fX
Definition: GuiTypes.h:177
Long_t fUser[5]
Definition: GuiTypes.h:186
Time_t fTime
Definition: GuiTypes.h:176
UInt_t fCode
Definition: GuiTypes.h:179