Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/** \class TGTextEdit
25 \ingroup guiwidgets
26
27A TGTextEdit is a specialization of TGTextView. It provides the
28text edit functionality to the static text viewing widget.
29For the messages supported by this widget see the TGView class.
30
31*/
32
33
34#include "TGTextEdit.h"
35#include "TGTextEditDialogs.h"
36#include "TGResourcePool.h"
37#include "TSystem.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 "RConfigure.h"
45#include "TVirtualX.h"
46
47#include <iostream>
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:
66 virtual ~TGTextEditHist() { Delete(); }
67
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:
84
85public:
88 fEdit->GetHistory()->Add(this);
89 }
90 void SetPos(TGLongPosition pos) { fPos = pos; }
91};
92
93///////////////////////////////////////////////////////////////////////////////
95
96public:
98 fEdit->InsChar(ch);
99 }
102 fEdit->NextChar();
103 fEdit->DelChar();
104 return kTRUE;
105 }
106};
107
108///////////////////////////////////////////////////////////////////////////////
110
111private:
112 char fChar;
113
114public:
116 fPos.fX--;
118 fEdit->DelChar();
119 }
121 if (fChar > 0) {
124 } else {
125 fPos.fY--;
126 fEdit->BreakLine();
127 }
128 return kTRUE;
129 }
130};
131
132///////////////////////////////////////////////////////////////////////////////
134
135public:
137 fEdit->BreakLine();
138 fPos.fX = 0;
139 fPos.fY++;
140 }
141
144 fEdit->DelChar();
145 return kTRUE;
146 }
147};
148
149///////////////////////////////////////////////////////////////////////////////
151private:
153
154public:
155 char fChar;
156
158 }
159
161 fEndPos = end;
162 }
163
166
167 if (fChar > 0) {
169 } else if (fPos.fY != fEndPos.fY) {
171 }
173 fEdit->Update();
174 return kTRUE;
175 }
176};
177
178///////////////////////////////////////////////////////////////////////////////
180
181private:
185
186public:
188 fText = new TGText(txt);
190 }
192 fText = new TGText(dtc.fText);
194 }
195 virtual ~TDelTextCom() { delete fText; }
196
198 if (this != &dtc) {
199 if (fText) delete fText;
200 fText = new TGText(dtc.fText);
202 }
203 return *this;
204 }
205
207 fEndPos = end;
208 }
209
210 void SetBreakLine(Bool_t on) { fBreakLine = on; }
211
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++;
224 } else {
225 fEndPos.fX++;
226 }
227
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/// Initialize 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 %zd\n", (size_t)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
1874 if (ToScrXCoord(pos.fX, fCurrent.fY-1) >= (Int_t)fCanvas->GetWidth()) {
1876 }
1877
1878#ifdef R__HAS_COCOA
1880#else
1882 gVirtualX->CopyArea(fCanvas->GetId(), fCanvas->GetId(), fNormGC(), 0,
1883 Int_t(pos2.fY), fWidth, h, 0, (Int_t)ToScrYCoord(fCurrent.fY));
1884 if (ToScrYCoord(pos.fY) < 0) {
1886 }
1888#endif
1891 }
1892 }
1893
1894 SetCurrent(pos);
1895}
1896
1897////////////////////////////////////////////////////////////////////////////////
1898/// Break a line.
1899
1901{
1902 if (fReadOnly) return;
1903
1904 TGLongPosition pos;
1906 if (ToScrYCoord(fCurrent.fY+2) <= (Int_t)fCanvas->GetHeight()) {
1907#ifdef R__HAS_COCOA
1909#else
1910 gVirtualX->CopyArea(fCanvas->GetId(), fCanvas->GetId(), fNormGC(), 0,
1914 0, (Int_t)ToScrYCoord(fCurrent.fY+2));
1917#endif
1918 if (fVisible.fX != 0) {
1919 SetHsbPosition(0);
1920 }
1923 } else {
1929 }
1930 pos.fY = fCurrent.fY+1;
1931 pos.fX = 0;
1932 SetCurrent(pos);
1933}
1934
1935////////////////////////////////////////////////////////////////////////////////
1936/// Scroll the canvas to new_top in the kVertical or kHorizontal direction.
1937
1938void TGTextEdit::ScrollCanvas(Int_t new_top, Int_t direction)
1939{
1940 CursorOff();
1941
1942 TGTextView::ScrollCanvas(new_top, direction);
1943
1944 CursorOn();
1945}
1946
1947////////////////////////////////////////////////////////////////////////////////
1948/// Redraw the text edit widget.
1949
1951{
1952 CursorOff();
1953
1954 TGTextView::DrawRegion(x, y, width, height);
1955
1956 CursorOn();
1957}
1958
1959////////////////////////////////////////////////////////////////////////////////
1960/// Go to the previous character.
1961
1963{
1964 if (fCurrent.fY == 0 && fCurrent.fX == 0) {
1965 gVirtualX->Bell(0);
1966 return;
1967 }
1968
1969 TGLongPosition pos;
1970 Long_t len;
1971
1972 pos.fY = fCurrent.fY;
1973 pos.fX = fCurrent.fX;
1974 if (fCurrent.fX > 0) {
1975 pos.fX--;
1976 while (fText->GetChar(pos) == 16) {
1977 pos.fX--;
1978 }
1979
1980 if (ToScrXCoord(pos.fX, pos.fY) < 0) {
1981 if (fVisible.fX-(Int_t)fCanvas->GetWidth()/2 >= 0) {
1983 } else {
1984 SetHsbPosition(0);
1985 }
1986 }
1987 } else {
1988 if (fCurrent.fY > 0) {
1989 pos.fY = fCurrent.fY - 1;
1990 len = fText->GetLineLength(pos.fY);
1991 if (ToScrYCoord(fCurrent.fY) <= 0) {
1993 }
1994 if (ToScrXCoord(len, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
1997 }
1998 pos.fX = len;
1999 }
2000 }
2001 SetCurrent(pos);
2002}
2003
2004////////////////////////////////////////////////////////////////////////////////
2005/// Go to next character.
2006
2008{
2010
2011 if (fCurrent.fY == fText->RowCount()-1 && fCurrent.fX == len) {
2012 gVirtualX->Bell(0);
2013 return;
2014 }
2015
2016 TGLongPosition pos;
2017 pos.fY = fCurrent.fY;
2018 if (fCurrent.fX < len) {
2019 if (fText->GetChar(fCurrent) == '\t') {
2020 pos.fX = fCurrent.fX + 8 - (fCurrent.fX & 0x7);
2021 } else {
2022 pos.fX = fCurrent.fX + 1;
2023 }
2024
2025 if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
2027 }
2028 } else {
2029 if (fCurrent.fY < fText->RowCount()-1) {
2030 pos.fY = fCurrent.fY + 1;
2031 if (ToScrYCoord(pos.fY+1) >= (Int_t)fCanvas->GetHeight()) {
2033 }
2034 SetHsbPosition(0);
2035 pos.fX = 0;
2036 }
2037 }
2038 SetCurrent(pos);
2039}
2040
2041////////////////////////////////////////////////////////////////////////////////
2042/// Make current position first line in window by scrolling up.
2043
2045{
2046 TGLongPosition pos;
2047 Long_t len;
2048 if (fCurrent.fY > 0) {
2049 pos.fY = fCurrent.fY - 1;
2050 if (ToScrYCoord(fCurrent.fY) <= 0) {
2052 }
2053 len = fText->GetLineLength(fCurrent.fY-1);
2054 if (fCurrent.fX > len) {
2055 if (ToScrXCoord(len, pos.fY) <= 0) {
2056 if (ToScrXCoord(len, pos.fY) < 0) {
2057 SetHsbPosition(ToScrXCoord(len, pos.fY)+
2059 } else {
2060 SetHsbPosition(0);
2061 }
2062 }
2063 pos.fX = len;
2064 } else {
2066 }
2067
2068 while (fText->GetChar(pos) == 16) {
2069 pos.fX++;
2070 }
2071 SetCurrent(pos);
2072 }
2073}
2074
2075////////////////////////////////////////////////////////////////////////////////
2076/// Move one line down.
2077
2079{
2080 TGLongPosition pos;
2081 Long_t len;
2082 if (fCurrent.fY < fText->RowCount()-1) {
2083 len = fText->GetLineLength(fCurrent.fY+1);
2084 pos.fY = fCurrent.fY + 1;
2085 if (ToScrYCoord(pos.fY+1) > (Int_t)fCanvas->GetHeight()) {
2087 }
2088 if (fCurrent.fX > len) {
2089 if (ToScrXCoord(len, pos.fY) <= 0) {
2090 if (ToScrXCoord(len, pos.fY) < 0) {
2092 } else {
2093 SetHsbPosition(0);
2094 }
2095 }
2096 pos.fX = len;
2097 } else {
2099 }
2100
2101 while (fText->GetChar(pos) == 16) {
2102 pos.fX++;
2103 }
2104 SetCurrent(pos);
2105 }
2106}
2107
2108////////////////////////////////////////////////////////////////////////////////
2109/// Move one screen up.
2110
2112{
2113 TGLongPosition pos;
2114 pos.fX = fCurrent.fX;
2116 if (fVisible.fY - (Int_t)fCanvas->GetHeight() >= 0) { // +1
2118 } else {
2119 pos.fY = 0;
2120 SetVsbPosition(0);
2121 }
2122 while (fText->GetChar(pos) == 16) {
2123 pos.fX++;
2124 }
2125 SetCurrent(pos);
2126}
2127
2128////////////////////////////////////////////////////////////////////////////////
2129/// Move one screen down.
2130
2132{
2133 TGLongPosition pos;
2134 pos.fX = fCurrent.fX;
2136 Long_t count = fText->RowCount()-1;
2137 if ((Int_t)fCanvas->GetHeight() < ToScrYCoord(count)) {
2139 } else {
2140 pos.fY = count;
2141 }
2142 while (fText->GetChar(pos) == 16) {
2143 pos.fX++;
2144 }
2145 SetCurrent(pos);
2146}
2147
2148////////////////////////////////////////////////////////////////////////////////
2149/// Move to beginning of line.
2150
2152{
2153 TGLongPosition pos;
2154 pos.fY = fCurrent.fY;
2155 pos.fX = 0;
2156 SetHsbPosition(0);
2157 SetCurrent(pos);
2158}
2159
2160////////////////////////////////////////////////////////////////////////////////
2161/// Move to end of line.
2162
2164{
2165 TGLongPosition pos;
2166 pos.fY = fCurrent.fY;
2167 pos.fX = fText->GetLineLength(pos.fY);
2168 if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
2170 }
2171 SetCurrent(pos);
2172}
2173
2174////////////////////////////////////////////////////////////////////////////////
2175/// Return selection graphics context for text cursor.
2176
2178{
2179 if (!fgCursor0GC) {
2182 }
2183 return *fgCursor0GC;
2184}
2185
2186////////////////////////////////////////////////////////////////////////////////
2187/// Return default graphics context for text cursor.
2188
2190{
2191 if (!fgCursor1GC) {
2192 fgCursor1GC = new TGGC(GetDefaultGC());
2194 }
2195 return *fgCursor1GC;
2196}
2197
2198////////////////////////////////////////////////////////////////////////////////
2199/// Save a text edit widget as a C++ statement(s) on output stream out
2200
2201void TGTextEdit::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2202{
2203 char quote = '"';
2204 out << " TGTextEdit *";
2205 out << GetName() << " = new TGTextEdit(" << fParent->GetName()
2206 << "," << GetWidth() << "," << GetHeight()
2207 << ");"<< std::endl;
2208 if (option && strstr(option, "keep_names"))
2209 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
2210
2211 if (IsReadOnly()) {
2212 out << " " << GetName() << "->SetReadOnly(kTRUE);" << std::endl;
2213 }
2214
2215 if (!IsMenuEnabled()) {
2216 out << " " << GetName() << "->EnableMenu(kFALSE);" << std::endl;
2217 }
2218
2220 out << " " << GetName() << "->ChangeBackground(" << fCanvas->GetBackground() << ");" << std::endl;
2221 }
2222
2223 TGText *txt = GetText();
2224 Bool_t fromfile = strlen(txt->GetFileName()) ? kTRUE : kFALSE;
2225 TString fn;
2226
2227 if (fromfile) {
2228 const char *filename = txt->GetFileName();
2229 fn = gSystem->UnixPathName(filename);
2231 } else {
2232 fn = TString::Format("Txt%s", GetName()+5);
2233 txt->Save(fn.Data());
2234 }
2235 out << " " << GetName() << "->LoadFile(" << quote << fn.Data() << quote << ");" << std::endl;
2236}
@ kGKeyPress
Definition GuiTypes.h:60
@ kButtonPress
Definition GuiTypes.h:60
@ kFocusIn
Definition GuiTypes.h:61
@ kEnterNotify
Definition GuiTypes.h:61
@ kNotifyNormal
Definition GuiTypes.h:219
@ kNotifyPointer
Definition GuiTypes.h:220
@ kGXxor
src XOR dst
Definition GuiTypes.h:74
@ kGXand
src AND dst
Definition GuiTypes.h:69
const Mask_t kKeyShiftMask
Definition GuiTypes.h:195
Handle_t Atom_t
WM token.
Definition GuiTypes.h:37
const Handle_t kNone
Definition GuiTypes.h:88
const Mask_t kKeyControlMask
Definition GuiTypes.h:197
@ kButton2
Definition GuiTypes.h:214
@ kButton3
Definition GuiTypes.h:214
@ kButton1
Definition GuiTypes.h:214
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
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:45
long Longptr_t
Definition RtypesCore.h:82
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:101
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
bool Bool_t
Definition RtypesCore.h:63
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
include TDocParser_001 C image html pict1_TDocParser_001 png width
@ kFDOpen
@ kFDSave
@ kMBNo
Definition TGMsgBox.h:32
@ kMBYes
Definition TGMsgBox.h:31
@ kMBCancel
Definition TGMsgBox.h:37
@ kMBOk
Definition TGMsgBox.h:33
@ kMBIconExclamation
Definition TGMsgBox.h:24
@ kMBIconAsterisk
Definition TGMsgBox.h:25
static Bool_t gDbl_clk
static Bool_t gTrpl_clk
static const char * gFiletypes[]
static char * gPrinter
static char * gPrintCommand
XFontStruct * id
Definition TGX11.cxx:109
R__EXTERN void * gTQSender
Definition TQObject.h:46
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2515
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
#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)
Bool_t Notify()
This method must be overridden to handle object notification.
TBreakLineCom(TGTextEdit *te)
TDelCharCom(TGTextEdit *te)
Bool_t Notify()
This method must be overridden to handle object notification.
void SetEndPos(TGLongPosition end)
Bool_t fBreakLine
TGLongPosition fEndPos
TGText * fText
TDelTextCom(TGTextEdit *te, TGText *txt)
void SetBreakLine(Bool_t on)
TDelTextCom & operator=(const TDelTextCom &dtc)
virtual ~TDelTextCom()
TDelTextCom(const TDelTextCom &dtc)
Bool_t Notify()
This method must be overridden to handle object notification.
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition TGClient.cxx:234
Bool_t IsEditable() const
Definition TGClient.h:89
const TGResourcePool * GetResourcePool() const
Definition TGClient.h:124
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:372
This class creates a file selection dialog.
char * fFilename
selected file name
const char ** fFileTypes
file types used to filter selectable files
char * fIniDir
on input: initial directory, on output: new directory
Bool_t fOverwrite
if true overwrite the file with existing name on save
void SetIniDir(const char *inidir)
Set directory name.
virtual void MapRaised()
map raised
Definition TGFrame.h:205
virtual Bool_t ProcessMessage(Longptr_t, Longptr_t, Longptr_t)
Definition TGFrame.h:183
static Time_t fgLastClick
Definition TGFrame.h:110
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:645
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:225
virtual Pixel_t GetBackground() const
Definition TGFrame.h:192
static Pixel_t fgWhitePixel
Definition TGFrame.h:103
UInt_t GetWidth() const
Definition TGFrame.h:224
Encapsulate a graphics context used in the low level graphics.
Definition TGGC.h:22
void SetFunction(EGraphicsFunction v)
Set graphics context drawing function.
Definition TGGC.cxx:256
Long_t fX
x position
Definition TGDimension.h:56
Long_t fY
y position
Definition TGDimension.h:57
TGClient * fClient
Connection to display server.
Definition TGObject.h:27
Handle_t GetId() const
Definition TGObject.h:37
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:26
This class creates a popup menu object.
Definition TGMenu.h:110
virtual void DisableEntry(Int_t id)
Disable entry (disabled entries appear in a sunken relieve).
Definition TGMenu.cxx:1724
virtual void EnableEntry(Int_t id)
Enable entry. By default entries are enabled.
Definition TGMenu.cxx:1705
virtual void Associate(const TGWindow *w)
Definition TGMenu.h:206
virtual void AddSeparator(TGMenuEntry *before=nullptr)
Add a menu separator to the menu.
Definition TGMenu.cxx:1060
virtual void AddEntry(TGHotString *s, Int_t id, void *ud=nullptr, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
Add a menu entry.
Definition TGMenu.cxx:990
virtual void PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode, Bool_t grab_pointer)
Popup a popup menu.
Definition TGMenu.cxx:1241
virtual Bool_t IsEntryEnabled(Int_t id)
Return true if menu entry is enabled.
Definition TGMenu.cxx:1736
UInt_t fH
height
Definition TGDimension.h:94
UInt_t fW
width
Definition TGDimension.h:93
Int_t fX
x position
Definition TGDimension.h:91
Int_t fY
y position
Definition TGDimension.h:92
Cursor_t GetTextCursor() const
virtual TGSearchType * GetType() const
static TGSearchDialog *& SearchDialog()
Return global search dialog.
void SetPos(TGLongPosition pos)
TGLongPosition fPos
TGTextEdit * fEdit
TGTextEditCommand(TGTextEdit *te)
Bool_t Notify()
'Notify' all objects in this collection.
virtual ~TGTextEditHist()
A TGTextEdit is a specialization of TGTextView.
Definition TGTextEdit.h:22
TGLongPosition fCurrent
current cursor position
Definition TGTextEdit.h:43
TGTextEditHist * fHistory
undo manager
Definition TGTextEdit.h:46
@ kM_SEARCH_FINDAGAIN
Definition TGTextEdit.h:33
@ kM_EDIT_SELECTALL
Definition TGTextEdit.h:32
GContext_t fCursor1GC
graphics context for drawing cursor
Definition TGTextEdit.h:38
virtual void Closed()
Definition TGTextEdit.h:126
virtual Bool_t HandleFocusChange(Event_t *event)
Handle focus change event in text edit widget.
TGTextEdit(const TGTextEdit &)=delete
virtual Bool_t Goto(Long_t line, Long_t column=0)
Goto the specified line.
virtual Bool_t HandleDoubleClick(Event_t *event)
Handle double click event.
static TGGC * fgCursor0GC
Definition TGTextEdit.h:50
static const TGGC & GetCursor1GC()
Return default graphics context for text cursor.
virtual void Saved()
Definition TGTextEdit.h:128
virtual Bool_t Replace(TGLongPosition pos, const char *oldText, const char *newText, Bool_t direction, Bool_t caseSensitive)
Replace text starting at textPos.
virtual void DrawCursor(Int_t mode)
Draw cursor. If mode = 1 draw cursor, if mode = 2 erase cursor.
virtual Bool_t Copy()
Copy text.
TList * GetHistory() const
Definition TGTextEdit.h:103
virtual void AdjustPos()
Adjust current position.
virtual Bool_t SaveFile(const char *fname, Bool_t saveas=kFALSE)
Save file.
EInsertMode GetInsertMode() const
Definition TGTextEdit.h:99
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.
virtual Bool_t Cut()
Cut text.
Bool_t fEnableMenu
enable context menu with editor actions
Definition TGTextEdit.h:45
TGLongPosition GetCurrentPos() const
Definition TGTextEdit.h:112
virtual Long_t ReturnLongestLineWidth()
Return width of longest line in widget.
virtual void Print(Option_t *="") const
Send current buffer to printer.
virtual void DelChar()
Delete a character from the text edit widget.
virtual Bool_t HandleSelection(Event_t *event)
Handle selection notify event.
GContext_t fCursor0GC
graphics context for erasing cursor
Definition TGTextEdit.h:37
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:129
virtual void LineDown()
Move one line down.
virtual void Clear(Option_t *="")
Clear text edit widget.
virtual void ScreenDown()
Move one screen down.
virtual void Delete(Option_t *="")
Delete selection.
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
OPTION={GetMethod="GetInsertMode";SetMethod="SetInsertMode";Items=(kInsert="&Insert",...
Definition TGTextEdit.h:44
virtual void CursorOn()
Turn cursor on.
virtual void SetCurrent(TGLongPosition new_coord)
Make the specified position the current position.
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.
virtual void FindAgain()
Definition TGTextEdit.h:125
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.
virtual void CursorOff()
If cursor if on, turn it off.
virtual Bool_t Search(const char *string, Bool_t direction=kTRUE, Bool_t caseSensitive=kFALSE)
Search for string in the specified direction.
Int_t fCursorState
cursor state (1=drawn, 2=erased)
Definition TGTextEdit.h:39
TGSearchType * fSearch
structure used by search dialog
Definition TGTextEdit.h:42
virtual void Opened()
Definition TGTextEdit.h:127
virtual void PrevChar()
Go to the previous character.
virtual Bool_t Paste()
Paste text into widget.
virtual Bool_t IsMenuEnabled() const
Definition TGTextEdit.h:102
virtual void SetFocus()
Definition TGTextEdit.h:109
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in text edit widget.
TGPopupMenu * fMenu
popup menu with editor actions
Definition TGTextEdit.h:41
virtual void ScrollCanvas(Int_t newTop, Int_t direction)
Scroll the canvas to new_top in the kVertical or kHorizontal direction.
Bool_t fEnableCursorWithoutFocus
enable cursor visibility when focus went out from text editor window (default is kTRUE)
Definition TGTextEdit.h:47
virtual void Home()
Move to beginning of line.
virtual Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Process context menu messages.
static TGGC * fgCursor1GC
Definition TGTextEdit.h:51
TViewTimer * fCurBlink
cursor blink timer
Definition TGTextEdit.h:40
virtual void End()
Move to end of line.
void Init()
Initialize a text edit widget.
static const TGGC & GetCursor0GC()
Return selection graphics context for text cursor.
virtual Bool_t HandleTimer(TTimer *t)
Handle timer cursor blink timer.
ULong_t GetLineLength()
Definition TGText.h:41
char * GetText(ULong_t pos, ULong_t length)
Get length characters from line starting at pos.
Definition TGText.cxx:184
A TGTextView is a text viewer widget.
Definition TGTextView.h:22
Int_t fMaxDescent
maximum descent in font
Definition TGTextView.h:29
virtual void Update()
update the whole window of text view
TGGC fNormGC
graphics context for drawing text
Definition TGTextView.h:31
Bool_t fReadOnly
text cannot be edited
Definition TGTextView.h:39
TGText * fText
text buffer
Definition TGTextView.h:25
virtual void UnMark()
Clear marked region.
virtual Bool_t IsSaved()
Definition TGTextView.h:77
virtual Long_t ToObjXCoord(Long_t xCoord, Long_t line)
Convert x screen coordinate to column in specified line.
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.
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.
virtual Long_t ReturnLongestLineWidth()
Return width of longest line.
TGText * fClipText
clipboard text buffer
Definition TGTextView.h:26
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.
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Bool_t fIsMarked
true if text is marked/selected
Definition TGTextView.h:36
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
virtual void Clicked(const char *word)
Definition TGTextView.h:138
TGGC fSelbackGC
graphics context for drawing marked background
Definition TGTextView.h:33
TGGC fSelGC
graphics context for drawing marked text
Definition TGTextView.h:32
virtual Bool_t SelectAll()
Select all text in the viewer.
TGText * GetText() const
Definition TGTextView.h:115
virtual void SetVsbPosition(Long_t newPos)
Set position of vertical scrollbar.
TGLongPosition fMarkedEnd
end position of marked text
Definition TGTextView.h:41
virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw lines in exposed region.
virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line)
Convert column number in specified line to screen coordinate.
virtual void Clear(Option_t *="")
Clear text view widget.
virtual void DataChanged()
Definition TGTextView.h:135
Bool_t IsReadOnly() const
Definition TGTextView.h:118
virtual Bool_t Copy()
Copy selected text to clipboard.
virtual void DoubleClicked(const char *word)
Definition TGTextView.h:139
virtual Bool_t HandleTimer(TTimer *t)
Handle scroll timer.
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in text editor.
virtual void SetSBRange(Int_t direction)
Set the range for the kVertical or kHorizontal scrollbar.
TGLongPosition fMarkedStart
start position of marked text
Definition TGTextView.h:40
virtual Long_t ToObjYCoord(Long_t yCoord)
Convert y screen coordinate to line number.
A TGText is a multi line text buffer.
Definition TGText.h:57
Bool_t InsChar(TGLongPosition pos, char c)
Insert character c at the specified position pos.
Definition TGText.cxx:707
void ReTab(Long_t row)
Redo all tabs in a line. Needed after a new tab is inserted.
Definition TGText.cxx:1087
Long_t RowCount() const
Definition TGText.h:106
Bool_t DelText(TGLongPosition start, TGLongPosition end)
Delete text between start and end positions.
Definition TGText.cxx:736
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:1143
Bool_t DelLine(ULong_t pos)
Delete specified row. Returns false if row does not exist.
Definition TGText.cxx:964
Bool_t Save(const char *fn)
Save text buffer to file fn.
Definition TGText.cxx:610
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:1197
Bool_t DelChar(TGLongPosition pos)
Delete character at specified position pos.
Definition TGText.cxx:691
Bool_t BreakLine(TGLongPosition pos)
Break line at position pos. Returns false if pos is not valid.
Definition TGText.cxx:1008
Bool_t InsText(TGLongPosition pos, const char *buf)
Insert single line at specified position.
Definition TGText.cxx:888
char * GetLine(TGLongPosition pos, ULong_t length)
Return string at position pos.
Definition TGText.cxx:997
char GetChar(TGLongPosition pos)
Get character a position pos. If character not valid return -1.
Definition TGText.cxx:723
Bool_t LoadBuffer(const char *txtbuf)
Load a 0 terminated buffer. Lines will be split at ' '.
Definition TGText.cxx:513
void Clear()
Clear text buffer.
Definition TGText.cxx:406
TGTextLine * GetCurrentLine() const
Definition TGText.h:102
const char * GetFileName() const
Definition TGText.h:88
Long_t GetLineLength(Long_t row)
Get length of specified line. Returns -1 if row does not exist.
Definition TGText.cxx:1043
TString AsString()
Returns content as ROOT string.
Definition TGText.cxx:1238
Atom_t fClipboard
clipboard property
Definition TGView.h:39
TGHScrollBar * fHsb
horizontal scrollbar
Definition TGView.h:43
TGVScrollBar * fVsb
vertical scrollbar
Definition TGView.h:44
TGLongPosition fVisible
position of visible region
Definition TGView.h:32
@ kHorizontal
Definition TGView.h:29
@ kVertical
Definition TGView.h:29
Int_t fScrolling
scrolling direction
Definition TGView.h:38
TGLongPosition fScrollVal
scroll value
Definition TGView.h:34
TGViewFrame * fCanvas
frame containing the text
Definition TGView.h:42
virtual void UpdateRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
update a part of view
Definition TGView.cxx:204
virtual void ScrollCanvas(Int_t newTop, Int_t direction)
Scroll the canvas to new_top in the kVertical or kHorizontal direction.
Definition TGView.cxx:464
TGRectangle fExposedRegion
exposed area
Definition TGView.h:36
Int_t fWidgetId
the widget id (used for event processing)
Definition TGWidget.h:46
const TGWindow * fMsgWindow
window which handles widget events
Definition TGWidget.h:48
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
Definition TGWindow.cxx:295
Bool_t Notify()
This method must be overridden to handle object notification.
TInsCharCom(TGTextEdit *te, char ch)
void SetEndPos(TGLongPosition end)
TInsTextCom(TGTextEdit *te)
Bool_t Notify()
This method must be overridden to handle object notification.
TGLongPosition fEndPos
A doubly linked list.
Definition TList.h:38
virtual void Add(TObject *obj)
Definition TList.h:81
virtual void RemoveLast()
Remove the last object of the list.
Definition TList.cxx:909
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:693
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
Mother of all ROOT objects.
Definition TObject.h:41
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition TObject.cxx:578
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:869
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
Basic string class.
Definition TString.h:136
Ssiz_t Length() const
Definition TString.h:410
const char * Data() const
Definition TString.h:369
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:2336
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2314
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1274
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
Definition TSystem.cxx:665
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition TSystem.cxx:1063
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition TSystem.cxx:474
virtual int ClosePipe(FILE *pipe)
Close the pipe.
Definition TSystem.cxx:674
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:86
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
#define Marked(f)
Definition render.c:146
Event structure.
Definition GuiTypes.h:174