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 ~TGTextEditHist() override { Delete(); }
67
68 Bool_t Notify() override
69 { //
70 TObject *obj = Last();
71 if (!obj) return kFALSE;
72
73 obj->Notify(); // execute undo action
74 RemoveLast();
75 delete obj;
76 return kTRUE;
77 }
78};
79
80///////////////////////////////////////////////////////////////////////////////
81class TGTextEditCommand : public TObject {
82protected:
85
86public:
89 fEdit->GetHistory()->Add(this);
90 }
91 void SetPos(TGLongPosition pos) { fPos = pos; }
92};
93
94///////////////////////////////////////////////////////////////////////////////
96
97public:
99 fEdit->InsChar(ch);
100 }
101 Bool_t Notify() override
102 { //
104 fEdit->NextChar();
105 fEdit->DelChar();
106 return kTRUE;
107 }
108};
109
110///////////////////////////////////////////////////////////////////////////////
112
113private:
114 char fChar;
115
116public:
118 fPos.fX--;
120 fEdit->DelChar();
121 }
122 Bool_t Notify() override
123 { //
124 if (fChar > 0) {
127 } else {
128 fPos.fY--;
129 fEdit->BreakLine();
130 }
131 return kTRUE;
132 }
133};
134
135///////////////////////////////////////////////////////////////////////////////
137
138public:
140 fEdit->BreakLine();
141 fPos.fX = 0;
142 fPos.fY++;
143 }
144
145 Bool_t Notify() override
146 { //
148 fEdit->DelChar();
149 return kTRUE;
150 }
151};
152
153///////////////////////////////////////////////////////////////////////////////
155private:
157
158public:
159 char fChar;
160
162 }
163
165 fEndPos = end;
166 }
167
168 Bool_t Notify() override
169 { //
171
172 if (fChar > 0) {
174 } else if (fPos.fY != fEndPos.fY) {
176 }
178 fEdit->Update();
179 return kTRUE;
180 }
181};
182
183///////////////////////////////////////////////////////////////////////////////
185
186private:
190
191public:
193 fText = new TGText(txt);
195 }
197 fText = new TGText(dtc.fText);
199 }
200 ~TDelTextCom() override { delete fText; }
201
203 if (this != &dtc) {
204 if (fText) delete fText;
205 fText = new TGText(dtc.fText);
207 }
208 return *this;
209 }
210
212 fEndPos = end;
213 }
214
216
217 Bool_t Notify() override
218 { //
219 TGLongPosition start_src, end_src;
220 start_src.fX = start_src.fY = 0;
221 end_src.fY = fText->RowCount() - 1;
222 end_src.fX = fText->GetLineLength(end_src.fY) - 1;
223
224 fEdit->GetText()->InsText(fPos, fText, start_src, end_src);
225
226 if (fBreakLine) {
227 fEndPos.fY++;
230 } else {
231 fEndPos.fX++;
232 }
233
235 fEdit->Update();
236 return kTRUE;
237 }
238};
239
240
242
243
244////////////////////////////////////////////////////////////////////////////////
245/// Create a text edit widget.
246
248 UInt_t sboptions, Pixel_t back) :
249 TGTextView(parent, w, h, id, sboptions, back)
250{
251 Init();
252}
253
254////////////////////////////////////////////////////////////////////////////////
255/// Create a text edit widget. Initialize it with the specified text buffer.
256
258 Int_t id, UInt_t sboptions, Pixel_t back) :
259 TGTextView(parent, w, h, text, id, sboptions, back)
260{
261 Init();
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// Create a text edit widget. Initialize it with the specified string.
266
268 const char *string, Int_t id, UInt_t sboptions,
269 Pixel_t back) :
270 TGTextView(parent, w, h, string, id, sboptions, back)
271{
272 Init();
273}
274
275////////////////////////////////////////////////////////////////////////////////
276/// Cleanup text edit widget.
277
279{
282 }
283 delete fCurBlink;
284 delete fMenu;
285 delete fHistory;
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Initialize a text edit widget.
290
292{
295 fCursorState = 1;
296 fCurrent.fY = fCurrent.fX = 0;
298 fCurBlink = 0;
299 fSearch = 0;
302
304
305 // create popup menu with default editor actions
307 fMenu->AddEntry("New", kM_FILE_NEW);
308 fMenu->AddEntry("Open...", kM_FILE_OPEN);
310 fMenu->AddEntry("Close", kM_FILE_CLOSE);
311 fMenu->AddEntry("Save", kM_FILE_SAVE);
312 fMenu->AddEntry("Save As...", kM_FILE_SAVEAS);
314 fMenu->AddEntry("Print...", kM_FILE_PRINT);
316 fMenu->AddEntry("Cut", kM_EDIT_CUT);
317 fMenu->AddEntry("Copy", kM_EDIT_COPY);
318 fMenu->AddEntry("Paste", kM_EDIT_PASTE);
319 fMenu->AddEntry("Select All", kM_EDIT_SELECTALL);
321 fMenu->AddEntry("Find...", kM_SEARCH_FIND);
322 fMenu->AddEntry("Find Again", kM_SEARCH_FINDAGAIN);
323 fMenu->AddEntry("Goto...", kM_SEARCH_GOTO);
324
325 fMenu->Associate(this);
326
327 fHistory = new TGTextEditHist();
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Enable/disable menu items in function of what is possible.
332
334{
335 if (fText->RowCount() == 1 && fText->GetLineLength(0) <= 0) {
344 } else {
353 }
354
355 if (IsSaved())
357 else
359
360 if (fIsMarked) {
363 } else {
366 }
367}
368
369////////////////////////////////////////////////////////////////////////////////
370/// Return width of longest line in widget.
371
373{
375 linewidth += 3*fScrollVal.fX;
376 return linewidth;
377}
378
379////////////////////////////////////////////////////////////////////////////////
380/// Clear text edit widget.
381
383{
384 fCursorState = 1;
385 fCurrent.fY = fCurrent.fX = 0;
387}
388
389////////////////////////////////////////////////////////////////////////////////
390/// Save file. If filename==0 ask user via dialog for a filename, if in
391/// addition saveas==kTRUE always ask for new filename. Returns
392/// kTRUE if file was correctly saved, kFALSE otherwise.
393
395{
396 if (!filename) {
397 Bool_t untitled = !strlen(fText->GetFileName()) ? kTRUE : kFALSE;
398 if (untitled || saveas) {
399 static TString dir(".");
400 static Bool_t overwr = kFALSE;
401 TGFileInfo fi;
403 fi.SetIniDir(dir);
404 fi.fOverwrite = overwr;
405 new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
406 overwr = fi.fOverwrite;
407 if (fi.fFilename && strlen(fi.fFilename)) {
408 dir = fi.fIniDir;
409 return fText->Save(fi.fFilename);
410 }
411 return kFALSE;
412 }
413 return fText->Save(fText->GetFileName());
414 }
415
416 return fText->Save(filename);
417}
418
419////////////////////////////////////////////////////////////////////////////////
420/// Copy text.
421
423{
424 if (!fIsMarked || ((fMarkedStart.fX == fMarkedEnd.fX) &&
426 return kFALSE;
427 }
428
430
432 del = del || (!fMarkedEnd.fX && (fCurrent.fY != fMarkedEnd.fY));
433 del = del && fClipText->AsString().Length() > 0;
434
435 if (del) {
436 TGLongPosition pos;
437 pos.fY = fClipText->RowCount();
438 pos.fX = 0;
439 fClipText->InsText(pos, 0);
440 }
441
442 return kTRUE;
443}
444
445////////////////////////////////////////////////////////////////////////////////
446/// Cut text.
447
449{
450 if (!Copy()) {
451 return kFALSE;
452 }
453 Delete();
454
455 return kTRUE;
456}
457
458////////////////////////////////////////////////////////////////////////////////
459/// Paste text into widget.
460
462{
463 if (fReadOnly) {
464 return kFALSE;
465 }
466
467 if (fIsMarked) {
468 TString sav = fClipText->AsString();
470 Delete();
471 fClipText->Clear();
472 fClipText->LoadBuffer(sav.Data());
473 }
474
475 gVirtualX->ConvertPrimarySelection(fId, fClipboard, 0);
476
477 return kTRUE;
478}
479
480////////////////////////////////////////////////////////////////////////////////
481/// Send current buffer to printer.
482
484{
485 TString msg;
486
487 msg.Form("%s -P%s\n", gPrintCommand, gPrinter);
488 FILE *p = gSystem->OpenPipe(msg.Data(), "w");
489 if (p) {
490 char *buf1, *buf2;
491 Long_t len;
492 ULong_t i = 0;
493 TGLongPosition pos;
494
495 pos.fX = pos.fY = 0;
496 while (pos.fY < fText->RowCount()) {
497 len = fText->GetLineLength(pos.fY);
498 if (len < 0) len = 0;
499 buf1 = fText->GetLine(pos, len);
500 buf2 = new char[len + 2];
501 strncpy(buf2, buf1, (UInt_t)len);
502 buf2[len] = '\n';
503 buf2[len+1] = '\0';
504 while (buf2[i] != '\0') {
505 if (buf2[i] == '\t') {
506 ULong_t j = i+1;
507 while (buf2[j] == 16)
508 j++;
509 // coverity[secure_coding]
510 strcpy(buf2+i+1, buf2+j);
511 }
512 i++;
513 }
514 fwrite(buf2, sizeof(char), strlen(buf2)+1, p);
515
516 delete [] buf1;
517 delete [] buf2;
518 pos.fY++;
519 }
521
522 Bool_t untitled = !strlen(fText->GetFileName()) ? kTRUE : kFALSE;
523 msg.Form("Printed: %s\nLines: %ld\nUsing: %s -P%s",
524 untitled ? "Untitled" : fText->GetFileName(),
526 new TGMsgBox(fClient->GetDefaultRoot(), this, "Editor", msg.Data(),
528 } else {
529 msg.Form("Could not execute: %s -P%s\n", gPrintCommand, gPrinter);
530 new TGMsgBox(fClient->GetDefaultRoot(), this, "Editor", msg.Data(),
532 }
533}
534
535////////////////////////////////////////////////////////////////////////////////
536/// Delete selection.
537
539{
540 if (!fIsMarked || fReadOnly) {
541 return;
542 }
543
544 if (fMarkedStart.fX == fMarkedEnd.fX &&
547
548 if (fCurrent.fY == fText->RowCount()-1 && fCurrent.fX == len) {
549 gVirtualX->Bell(0);
550 return;
551 }
552
553 new TDelCharCom(this);
554 return;
555 }
556
557 TGLongPosition pos, endPos;
558 Bool_t delast = kFALSE;
559
560 endPos.fX = fMarkedEnd.fX - 1;
561 endPos.fY = fMarkedEnd.fY;
562
563 if (endPos.fX == -1) {
564 pos = fCurrent;
565 if (endPos.fY > 0) {
566 SetCurrent(endPos);
567 DelChar();
568 endPos.fY--;
569 SetCurrent(pos);
570 }
571 endPos.fX = fText->GetLineLength(endPos.fY);
572 if (endPos.fX < 0) {
573 endPos.fX = 0;
574 }
575 delast = kTRUE;
576 }
577
578 // delete command for undo
579 TDelTextCom *dcom = new TDelTextCom(this, fClipText);
580 dcom->SetPos(fMarkedStart);
581 dcom->SetEndPos(endPos);
582
583 if (delast || ((fText->GetLineLength(endPos.fY) == endPos.fX+1) &&
584 (fClipText->RowCount() > 1))) {
585 TGLongPosition p = endPos;
586
587 p.fY--;
588 if (!delast) p.fX++;
589 dcom->SetEndPos(p);
590 dcom->SetBreakLine(kTRUE);
591 }
592
593 fText->DelText(fMarkedStart, endPos);
594
595 pos.fY = ToObjYCoord(fVisible.fY);
596
597 if (fMarkedStart.fY < pos.fY) {
598 pos.fY = fMarkedStart.fY;
599 }
600 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
601 if (fMarkedStart.fX < pos.fX) {
602 pos.fX = fMarkedStart.fX;
603 }
604
607 th = th < 0 ? 0 : th;
608 ys = ys < 0 ? 0 : ys;
609
610 // clear
611 if ((th < 0) || (th < (Int_t)fCanvas->GetHeight())) {
612 gVirtualX->ClearArea(fCanvas->GetId(), 0, ys,
613 fCanvas->GetWidth(), fCanvas->GetHeight() - ys);
614 }
615
617
623
625 UnMark();
626
627 // only to make sure that IsSaved() returns true in case everything has
628 // been deleted
629 if (fText->RowCount() == 1 && fText->GetLineLength(0) == 0) {
630 delete fText;
631 fText = new TGText();
632 fText->Clear();
633 }
634}
635
636////////////////////////////////////////////////////////////////////////////////
637/// Search for string in the specified direction. If direction is true
638/// the search will be in forward direction.
639
640Bool_t TGTextEdit::Search(const char *string, Bool_t direction,
641 Bool_t caseSensitive)
642{
643 if (!IsMapped()) return kFALSE;
644
649 }
650
651 TGLongPosition pos;
652 if (!fText->Search(&pos, fCurrent, string, direction, caseSensitive)) {
653 fCurrent.fX = 1;
654 fCurrent.fY = 1;
655
656 if (!fText->Search(&pos, fCurrent, string, direction, caseSensitive)) { //try again
657 TString msg;
658 msg.Form("Couldn't find \"%s\"", string);
659 gVirtualX->Bell(20);
660 new TGMsgBox(fClient->GetDefaultRoot(), fCanvas, "TextEdit",
661 msg.Data(), kMBIconExclamation, kMBOk, 0);
662 return kFALSE;
663 }
664 return kTRUE;
665 }
666 UnMark();
669 fMarkedStart.fX = pos.fX;
670 fMarkedEnd.fX = fMarkedStart.fX + strlen(string);
671
672 if (direction) {
674 } else {
676 }
677
678 pos.fY = ToObjYCoord(fVisible.fY);
679 if (fCurrent.fY < pos.fY ||
681 pos.fY = fMarkedStart.fY;
682 }
683 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
684
685 if (fCurrent.fX < pos.fX ||
687 pos.fX = fMarkedStart.fX;
688 }
689
692
695
696 return kTRUE;
697}
698
699////////////////////////////////////////////////////////////////////////////////
700/// Replace text starting at textPos.
701
702Bool_t TGTextEdit::Replace(TGLongPosition textPos, const char *oldText,
703 const char *newText, Bool_t direction, Bool_t caseSensitive)
704{
705 TGLongPosition pos;
706 if (!fText->Replace(textPos, oldText, newText, direction, caseSensitive)) {
707 return kFALSE;
708 }
709 UnMark();
711 fMarkedStart.fY = fMarkedEnd.fY = textPos.fY;
712 fMarkedStart.fX = textPos.fX;
713 fMarkedEnd.fX = fMarkedStart.fX + strlen(newText);
714
715 if (direction) {
717 } else {
719 }
720
721 pos.fY = ToObjYCoord(fVisible.fY);
722 if (fCurrent.fY < pos.fY ||
724 pos.fY = fMarkedStart.fY;
725 }
726 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
727 if (fCurrent.fX < pos.fX ||
729 pos.fX = fMarkedStart.fX;
730 }
731
734
737
738 return kTRUE;
739}
740
741////////////////////////////////////////////////////////////////////////////////
742/// Goto the specified line.
743
745{
746 if (line < 0)
747 line = 0;
748 if (line >= fText->RowCount())
749 line = fText->RowCount() - 1;
750 if (column < 0)
751 column = 0;
752 if (column > fText->GetLineLength(line))
753 column = fText->GetLineLength(line);
754
755 TGLongPosition gotopos, pos;
756 gotopos.fY = line;
757 gotopos.fX = column;
758 SetCurrent(gotopos);
759
760 pos.fY = ToObjYCoord(fVisible.fY);
761 if (fCurrent.fY < pos.fY ||
763 pos.fY = gotopos.fY;
764
767
768 UnMark();
771 fMarkedStart.fX = 0;
773
774 return kTRUE;
775}
776
777////////////////////////////////////////////////////////////////////////////////
778/// Sets the mode how characters are entered.
779
781{
782 if (fInsertMode == mode) return;
783
785}
786
787////////////////////////////////////////////////////////////////////////////////
788/// If cursor if on, turn it off.
789
791{
792 if (fCursorState == 1) {
793 DrawCursor(2);
794 }
795 fCursorState = 2;
796}
797
798////////////////////////////////////////////////////////////////////////////////
799/// Turn cursor on.
800
802{
803 DrawCursor(1);
804 fCursorState = 1;
805
806 if (fCurBlink) {
807 fCurBlink->Reset();
808 }
809}
810
811////////////////////////////////////////////////////////////////////////////////
812/// Make the specified position the current position.
813
815{
816 CursorOff();
817
818 fCurrent.fY = new_coord.fY;
819 fCurrent.fX = new_coord.fX;
820
821 CursorOn();
822
824 DataChanged();
825}
826
827////////////////////////////////////////////////////////////////////////////////
828/// Draw cursor. If mode = 1 draw cursor, if mode = 2 erase cursor.
829
831{
832 char count = -1;
833 char cursor = ' ';
835 return;
836 }
837
842 if (fCurrent.fY < fText->RowCount()) {
843 count = fText->GetChar(fCurrent);
844 }
845 if (count == -1 || count == '\t') {
846 cursor = ' ';
847 } else {
848 cursor = count;
849 }
850
851 if (mode == 2) {
852 if (fIsMarked && count != -1) {
861 // back ground fillrectangle
862 gVirtualX->FillRectangle(fCanvas->GetId(), fSelbackGC(),
868 if (count != -1)
871 } else {
872 gVirtualX->ClearArea(fCanvas->GetId(),
878 if (count != -1)
881 }
882 } else {
883 gVirtualX->ClearArea(fCanvas->GetId(),
891 }
892 } else {
893 if (mode == 1) {
894 gVirtualX->FillRectangle(fCanvas->GetId(), fCursor1GC,
897 2,
899 }
900 }
901 }
902}
903
904////////////////////////////////////////////////////////////////////////////////
905/// Adjust current position.
906
908{
909 TGLongPosition pos;
910 pos.fY = fCurrent.fY;
911 pos.fX = fCurrent.fX;
912
913 if (pos.fY < ToObjYCoord(fVisible.fY)) {
914 pos.fY = ToObjYCoord(fVisible.fY);
915 } else if (ToScrYCoord(pos.fY+1) >= (Int_t) fCanvas->GetHeight()) {
917 }
918 if (pos.fX < ToObjXCoord(fVisible.fX, pos.fY)) {
919 pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
920 } else if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t) fCanvas->GetWidth()) {
921 pos.fX = ToObjXCoord(fVisible.fX + fCanvas->GetWidth(), pos.fY)-1;
922 }
923 if (pos.fY != fCurrent.fY || pos.fX != fCurrent.fX) {
924 SetCurrent(pos);
925 }
926}
927
928////////////////////////////////////////////////////////////////////////////////
929/// Handle timer cursor blink timer.
930
932{
933 if (t != fCurBlink) {
935 return kTRUE;
936 }
937
938 if (fCursorState == 1) {
939 fCursorState = 2;
940 } else {
941 fCursorState = 1;
942 }
943
945
946 return kTRUE;
947}
948
949////////////////////////////////////////////////////////////////////////////////
950/// Handle selection notify event.
951
953{
955 Int_t nchar;
956
957 gVirtualX->GetPasteBuffer((Window_t)event->fUser[0], (Atom_t)event->fUser[3],
958 data, nchar, kFALSE);
959
960 if (!nchar) return kTRUE;
961
962 delete fClipText;
963
964 fClipText = new TGText;
965 fClipText->LoadBuffer(data.Data());
966
967 TGLongPosition start_src, end_src, pos;
968
969 pos.fX = pos.fY = 0;
970 start_src.fY = start_src.fX = 0;
971 end_src.fY = fClipText->RowCount()-1;
972 end_src.fX = fClipText->GetLineLength(end_src.fY)-1;
973
974 if (end_src.fX < 0) {
975 end_src.fX = 0;
976 }
977
978 // undo command
979 TInsTextCom *icom = new TInsTextCom(this);
980 icom->fChar = fText->GetChar(fCurrent);
981 fText->InsText(fCurrent, fClipText, start_src, end_src);
982
984
985 fExposedRegion.fX = 0;
987
988 pos.fY = fCurrent.fY + fClipText->RowCount()-1;
990
991 if (start_src.fY == end_src.fY) {
992 pos.fX = pos.fX + fCurrent.fX;
993 }
994
995 icom->SetEndPos(pos);
996
997 // calculate exposed region
1000
1001 SetCurrent(pos);
1002
1003 if (ToScrYCoord(pos.fY) >= (Int_t)fCanvas->GetHeight()) {
1004 pos.fY = ToScrYCoord(pos.fY) + fVisible.fY - fCanvas->GetHeight()/2;
1007 } else {
1008 pos.fY = fVisible.fY;
1009 }
1010 if (ToScrXCoord(pos.fX, fCurrent.fY) >= (Int_t) fCanvas->GetWidth()) {
1011 pos.fX = ToScrXCoord(pos.fX, fCurrent.fY) + fVisible.fX + fCanvas->GetWidth()/2;
1012 } else if (ToScrXCoord(pos.fX, fCurrent.fY < 0) && pos.fX != 0) {
1013 if (fVisible.fX - (Int_t)fCanvas->GetWidth()/2 > 0) {
1014 pos.fX = fVisible.fX - fCanvas->GetWidth()/2;
1015 } else {
1016 pos.fX = 0;
1017 }
1018 } else {
1019 pos.fX = fVisible.fX;
1020 }
1021
1026
1027 fClient->NeedRedraw(this);
1028
1029 return kTRUE;
1030}
1031
1034
1035////////////////////////////////////////////////////////////////////////////////
1036/// Handle mouse button event in text edit widget.
1037
1039{
1040 if (event->fWindow != fCanvas->GetId()) {
1041 return kFALSE;
1042 }
1043
1044 TGLongPosition pos;
1045
1047
1048 if (event->fType == kButtonPress) {
1049 SetFocus();
1050 //Update();
1051
1052 if (event->fCode == kButton1 || event->fCode == kButton2) {
1053 pos.fY = ToObjYCoord(fVisible.fY + event->fY);
1054 if (pos.fY >= fText->RowCount()) {
1055 pos.fY = fText->RowCount()-1;
1056 }
1057 pos.fX = ToObjXCoord(fVisible.fX+event->fX, pos.fY);
1058 if (pos.fX >= fText->GetLineLength(pos.fY)) {
1059 pos.fX = fText->GetLineLength(pos.fY);
1060 }
1061 while (fText->GetChar(pos) == 16) {
1062 pos.fX++;
1063 }
1064
1065 SetCurrent(pos);
1066
1068 char *word = line->GetWord(pos.fX);
1069 Clicked((const char*)word); // emit signal
1070 delete [] word;
1071 }
1072 if (event->fCode == kButton2) {
1073 if (gVirtualX->GetPrimarySelectionOwner() != kNone) {
1074 gVirtualX->ConvertPrimarySelection(fId, fClipboard, event->fTime);
1075 Update();
1076 return kTRUE;
1077 }
1078 }
1079 if (event->fCode == kButton3) {
1080 // do not handle during guibuilding
1081 if (fClient->IsEditable() || !fEnableMenu) {
1082 return kTRUE;
1083 }
1084 SetMenuState();
1085 fMenu->PlaceMenu(event->fXRoot, event->fYRoot, kTRUE, kTRUE);
1086 }
1087 gDbl_clk = kFALSE;
1088 gTrpl_clk = kFALSE;
1089 }
1090
1091 return kTRUE;
1092}
1093
1094////////////////////////////////////////////////////////////////////////////////
1095/// Handle double click event.
1096
1098{
1099 if (event->fWindow != fCanvas->GetId()) {
1100 return kFALSE;
1101 }
1102
1103 if (event->fCode != kButton1) {
1104 return kFALSE;
1105 }
1106 if (!fText->GetCurrentLine()->GetText()) {// empty line
1107 return kFALSE;
1108 }
1109
1110 SetFocus();
1111 TGLongPosition pos;
1112 pos.fY = ToObjYCoord(fVisible.fY + event->fY);
1113
1114 if (gDbl_clk && (event->fTime - fgLastClick < 350)) { // triple click
1115 fgLastClick = event->fTime;
1116 gDbl_clk = kFALSE;
1117 gTrpl_clk = kTRUE;
1118 fMarkedStart.fY = fMarkedEnd.fY = pos.fY;
1119 fIsMarked = kTRUE;
1120 fMarkedStart.fX = 0;
1121 fMarkedEnd.fX = strlen(fText->GetCurrentLine()->GetText());
1122 Marked(kTRUE);
1125 return kTRUE;
1126 }
1127
1128 if (gTrpl_clk && (event->fTime - fgLastClick < 350)) { // 4 click
1129 fgLastClick = event->fTime;
1130 gTrpl_clk = kFALSE;
1131 fIsMarked = kTRUE;
1132 fMarkedStart.fY = 0;
1133 fMarkedStart.fX = 0;
1134 fMarkedEnd.fY = fText->RowCount()-1;
1136 if (fMarkedEnd.fX < 0) {
1137 fMarkedEnd.fX = 0;
1138 }
1140 return kTRUE;
1141 }
1142
1143 gDbl_clk = kTRUE;
1144 gTrpl_clk = kFALSE;
1145
1146 if (pos.fY >= fText->RowCount()) {
1147 pos.fY = fText->RowCount() - 1;
1148 }
1149 pos.fX = ToObjXCoord(fVisible.fX + event->fX, pos.fY);
1150
1151 if (pos.fX >= fText->GetLineLength(pos.fY)) {
1152 pos.fX = fText->GetLineLength(pos.fY);
1153 }
1154 while (fText->GetChar(pos) == 16) {
1155 pos.fX++;
1156 }
1157
1158 SetCurrent(pos);
1159
1160 fMarkedStart.fY = fMarkedEnd.fY = pos.fY;
1161 char *line = fText->GetCurrentLine()->GetText();
1163 Int_t start = pos.fX;
1164 Int_t end = pos.fX;
1165 Int_t i = pos.fX;
1166
1167 if (line[i] == ' ' || line[i] == '\t') {
1168 while (start >= 0) {
1169 if (line[start] == ' ' || line[start] == '\t') --start;
1170 else break;
1171 }
1172 ++start;
1173 while (end < (Int_t)len) {
1174 if (line[end] == ' ' || line[end] == '\t') ++end;
1175 else break;
1176 }
1177 } else if (isalnum(line[i])) {
1178 while (start >= 0) {
1179 if (isalnum(line[start])) --start;
1180 else break;
1181 }
1182 ++start;
1183 while (end < (Int_t)len) {
1184 if (isalnum(line[end])) ++end;
1185 else break;
1186 }
1187 } else {
1188 while (start >= 0) {
1189 if (isalnum(line[start]) || line[start] == ' ' || line[start] == '\t') {
1190 break;
1191 } else {
1192 --start;
1193 }
1194 }
1195 ++start;
1196 while (end < (Int_t)len) {
1197 if (isalnum(line[end]) || line[end] == ' ' || line[end] == '\t') {
1198 break;
1199 } else {
1200 ++end;
1201 }
1202 }
1203 }
1204
1205 fMarkedStart.fX = start;
1206 fIsMarked = kTRUE;
1207 fMarkedEnd.fX = end;
1208 Marked(kTRUE);
1209
1210 len = end - start; //length
1211 char *word = new char[len + 1];
1212 word[len] = '\0';
1213 strncpy(word, line+start, (UInt_t)len);
1214 DoubleClicked((const char *)word); // emit signal
1215
1216 delete [] word;
1217// delete [] line;
1218
1221
1222 return kTRUE;
1223}
1224
1225////////////////////////////////////////////////////////////////////////////////
1226/// Handle mouse motion event in text edit widget.
1227
1229{
1230 TGLongPosition pos;
1231 if (event->fWindow != fCanvas->GetId()) {
1232 return kTRUE;
1233 }
1234
1235 if (fScrolling == -1) {
1236 pos.fY = ToObjYCoord(fVisible.fY+event->fY);
1237 if (pos.fY >= fText->RowCount()) {
1238 pos.fY = fText->RowCount()-1;
1239 }
1240 pos.fX = ToObjXCoord(fVisible.fX+event->fX, pos.fY);
1241 if (pos.fX > fText->GetLineLength(pos.fY)) {
1242 pos.fX = fText->GetLineLength(pos.fY);
1243 }
1244 if (fText->GetChar(pos) == 16) {
1245 if (pos.fX < fCurrent.fX) {
1246 pos.fX = fCurrent.fX;
1247 }
1248 if (pos.fX > fCurrent.fX) {
1249 do {
1250 pos.fX++;
1251 } while (fText->GetChar(pos) == 16);
1252 }
1253 }
1254 event->fY = (Int_t)ToScrYCoord(pos.fY);
1255 event->fX = (Int_t)ToScrXCoord(pos.fX, pos.fY);
1256 if (pos.fY != fCurrent.fY || pos.fX != fCurrent.fX) {
1258 SetCurrent(pos);
1259 }
1260 }
1261 return kTRUE;
1262}
1263
1264////////////////////////////////////////////////////////////////////////////////
1265/// The key press event handler converts a key press to some line editor
1266/// action.
1267
1269{
1270 Bool_t mark_ok = kFALSE;
1271 char input[10];
1272 Int_t n;
1273 UInt_t keysym;
1274
1275 if (event->fType == kGKeyPress) {
1276 gVirtualX->LookupString(event, input, sizeof(input), keysym);
1277 n = strlen(input);
1278
1279 AdjustPos();
1280
1281 switch ((EKeySym)keysym) { // ignore these keys
1282 case kKey_Shift:
1283 case kKey_Control:
1284 case kKey_Meta:
1285 case kKey_Alt:
1286 case kKey_CapsLock:
1287 case kKey_NumLock:
1288 case kKey_ScrollLock:
1289 return kTRUE;
1290 default:
1291 break;
1292 }
1293 if (event->fState & kKeyControlMask) { // Cntrl key modifier pressed
1294 switch((EKeySym)keysym & ~0x20) { // treat upper and lower the same
1295 case kKey_A:
1296 SelectAll();
1297 return kTRUE;
1298 case kKey_B:
1299 mark_ok = kTRUE;
1300 PrevChar();
1301 break;
1302 case kKey_C:
1303 Copy();
1304 return kTRUE;
1305 case kKey_D:
1306 if (fIsMarked) {
1307 Cut();
1308 } else {
1310 if (fCurrent.fY == fText->RowCount()-1 && fCurrent.fX == len) {
1311 gVirtualX->Bell(0);
1312 return kTRUE;
1313 }
1314 NextChar();
1315 new TDelCharCom(this);
1316 }
1317 break;
1318 case kKey_E:
1319 mark_ok = kTRUE;
1320 End();
1321 break;
1322 case kKey_H:
1323 if (fCurrent.fX || fCurrent.fY) new TDelCharCom(this);
1324 else gVirtualX->Bell(0);
1325 break;
1326 case kKey_K:
1327 End();
1328 fIsMarked = kTRUE;
1330 Cut();
1331 break;
1332 case kKey_U:
1333 Home();
1334 UnMark();
1337 End();
1338 fIsMarked = kTRUE;
1340 Cut();
1341 break;
1342 case kKey_V:
1343 case kKey_Y:
1344 Paste();
1345 return kTRUE;
1346 case kKey_X:
1347 Cut();
1348 return kTRUE;
1349 case kKey_Z:
1350 fHistory->Notify(); // undo action
1351 return kTRUE;
1352 case kKey_F:
1353 Search(kFALSE);
1354 return kTRUE;
1355 case kKey_L:
1356 {
1357 Long_t ret = fCurrent.fY+1;
1358 new TGGotoDialog(fClient->GetDefaultRoot(), this, 400, 150, &ret);
1359 if (ret > -1) {
1360 ret--; // user specifies lines starting at 1
1361 Goto(ret);
1362 }
1363 return kTRUE;
1364 }
1365 case kKey_Home:
1366 {
1367 TGLongPosition pos;
1368 pos.fY = 0;
1369 pos.fX = 0;
1370 SetHsbPosition(0);
1371 SetVsbPosition(0);
1372 SetCurrent(pos);
1373 }
1374 break;
1375 case kKey_End:
1376 {
1377 TGLongPosition pos;
1378 pos.fY = fText->RowCount()-1;
1379 pos.fX = fText->GetLineLength(pos.fY);
1380 if (fVsb && fVsb->IsMapped())
1382 SetCurrent(pos);
1383 }
1384 break;
1385 default:
1386 return kTRUE;
1387 }
1388 }
1389 if (n && keysym >= 32 && keysym < 127 && // printable keys
1390 !(event->fState & kKeyControlMask) &&
1391 (EKeySym)keysym != kKey_Delete &&
1392 (EKeySym)keysym != kKey_Backspace) {
1393
1394 if (fIsMarked) {
1395 Cut();
1396 }
1397 new TInsCharCom(this, input[0]);
1398
1399 } else {
1400
1401 switch ((EKeySym)keysym) {
1402 case kKey_F3:
1403 // typically FindAgain action
1405 kTRUE);
1406 SetMenuState();
1410 FindAgain();
1411 }
1412 break;
1413 case kKey_Delete:
1414 if (fIsMarked) {
1415 Cut();
1416 } else {
1418 if (fCurrent.fY == fText->RowCount()-1 && fCurrent.fX == len) {
1419 gVirtualX->Bell(0);
1420 return kTRUE;
1421 }
1422 NextChar();
1423 new TDelCharCom(this);
1424 }
1425 break;
1426 case kKey_Return:
1427 case kKey_Enter:
1428 new TBreakLineCom(this);
1429 break;
1430 case kKey_Tab:
1431 new TInsCharCom(this, '\t');
1432 break;
1433 case kKey_Backspace:
1434 if (fIsMarked) {
1435 Cut();
1436 } else {
1437 if (fCurrent.fX || fCurrent.fY) {
1438 new TDelCharCom(this);
1439 } else {
1440 gVirtualX->Bell(0);
1441 }
1442 }
1443 break;
1444 case kKey_Left:
1445 mark_ok = kTRUE;
1446 PrevChar();
1447 break;
1448 case kKey_Right:
1449 mark_ok = kTRUE;
1450 NextChar();
1451 break;
1452 case kKey_Up:
1453 mark_ok = kTRUE;
1454 LineUp();
1455 break;
1456 case kKey_Down:
1457 mark_ok = kTRUE;
1458 LineDown();
1459 break;
1460 case kKey_PageUp:
1461 mark_ok = kTRUE;
1462 ScreenUp();
1463 break;
1464 case kKey_PageDown:
1465 mark_ok = kTRUE;
1466 ScreenDown();
1467 break;
1468 case kKey_Home:
1469 mark_ok = kTRUE;
1470 Home();
1471 break;
1472 case kKey_End:
1473 mark_ok = kTRUE;
1474 End();
1475 break;
1476 case kKey_Insert: // switch on/off insert mode
1478 break;
1479 default:
1480 break;
1481 }
1482 }
1483 if ((event->fState & kKeyShiftMask) && mark_ok) {
1484 fIsMarked = kTRUE;
1486 Copy();
1488 kTRUE);
1489 Marked(kTRUE);
1490 } else {
1491 UnMark();
1493 fWidgetId, kFALSE);
1496 }
1497 }
1498 return kTRUE;
1499}
1500
1501////////////////////////////////////////////////////////////////////////////////
1502/// Handle mouse crossing event.
1503
1505{
1506 if (event->fWindow != fCanvas->GetId()) {
1507 return kTRUE;
1508 }
1509 if (gVirtualX->GetInputFocus() != fCanvas->GetId()) {
1510 if (event->fType == kEnterNotify) {
1511 if (!fCurBlink) {
1512 fCurBlink = new TViewTimer(this, 500);
1513 }
1514 fCurBlink->Reset();
1516 } else {
1517 if (fCurBlink) fCurBlink->Remove();
1518 if (!fEnableCursorWithoutFocus && (fCursorState == 1)) {
1519 DrawCursor(2);
1520 fCursorState = 2;
1521 } else if (fCursorState == 2) {
1522 DrawCursor(1);
1523 fCursorState = 1;
1524 }
1525 }
1526 }
1527
1529
1530 return kTRUE;
1531}
1532
1533////////////////////////////////////////////////////////////////////////////////
1534/// Handle focus change event in text edit widget.
1535
1537{
1538 if (event->fWindow != fCanvas->GetId()) {
1539 return kTRUE;
1540 }
1541
1542 // check this when porting to Win32
1543 if ((event->fCode == kNotifyNormal) && (event->fState != kNotifyPointer)) {
1544 if (event->fType == kFocusIn) {
1545 if (!fCurBlink) {
1546 fCurBlink = new TViewTimer(this, 500);
1547 }
1548 fCurBlink->Reset();
1550 } else {
1551 if (fCurBlink) fCurBlink->Remove();
1552 if (fCursorState == 2) {
1553 DrawCursor(1);
1554 fCursorState = 1;
1555 }
1556 }
1557 fClient->NeedRedraw(this);
1558 }
1559 return kTRUE;
1560}
1561
1562////////////////////////////////////////////////////////////////////////////////
1563/// Invokes search dialog.
1564
1566{
1567 static TGSearchType *srch = 0;
1568 Int_t ret = 0;
1569
1570 if (!srch) srch = new TGSearchType;
1571 srch->fClose = close;
1572
1573 if (!close) {
1576 fCanvas, 400, 150, srch, &ret);
1577 }
1578 TGSearchDialog::SearchDialog()->Connect("TextEntered(char *)", "TGTextEdit",
1579 this, "Search(char *,Bool_t,Bool_t)");
1581 } else {
1582 new TGSearchDialog(fClient->GetDefaultRoot(), fCanvas, 400, 150, srch, &ret);
1583 if (ret) {
1584 Search(srch->fBuffer);
1585 }
1586 }
1587}
1588
1589////////////////////////////////////////////////////////////////////////////////
1590/// Process context menu messages.
1591
1593{
1594 TString msg2;
1595 TGTextView::ProcessMessage(msg, parm1, parm2);
1596
1597 switch(GET_MSG(msg)) {
1598 case kC_COMMAND:
1599 switch(GET_SUBMSG(msg)) {
1600 case kCM_MENU:
1601 switch (parm1) {
1602 case kM_FILE_NEW:
1603 case kM_FILE_CLOSE:
1604 case kM_FILE_OPEN:
1605 if (!IsSaved()) {
1606 Int_t retval;
1607 Bool_t untitled = !strlen(fText->GetFileName()) ? kTRUE : kFALSE;
1608
1609 msg2.Form("Save \"%s\"?",
1610 untitled ? "Untitled" : fText->GetFileName());
1611 new TGMsgBox(fClient->GetDefaultRoot(), this, "Editor",
1612 msg2.Data(), kMBIconExclamation,
1613 kMBYes | kMBNo | kMBCancel, &retval);
1614
1615 if (retval == kMBCancel)
1616 return kTRUE;
1617 if (retval == kMBYes)
1618 if (!SaveFile(0))
1619 return kTRUE;
1620 }
1621 Clear();
1622 if (parm1 == kM_FILE_CLOSE) {
1624 fWidgetId, 0);
1625 Closed();
1626 }
1627 if (parm1 == kM_FILE_OPEN) {
1628 TGFileInfo fi;
1630 new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen, &fi);
1631 if (fi.fFilename && strlen(fi.fFilename)) {
1632 LoadFile(fi.fFilename);
1634 fWidgetId, 0);
1635 Opened();
1636 }
1637 }
1638 break;
1639 case kM_FILE_SAVE:
1640 if (SaveFile(0)) {
1642 fWidgetId, 0);
1643 Saved();
1644 }
1645 break;
1646 case kM_FILE_SAVEAS:
1647 if (SaveFile(0, kTRUE)) {
1649 fWidgetId, 0);
1650 SavedAs();
1651 }
1652 break;
1653 case kM_FILE_PRINT:
1654 {
1655 Int_t ret = 0;
1656 if (!gPrinter) {
1657 gPrinter = StrDup("892_2_cor"); // use gEnv
1658 gPrintCommand = StrDup("xprint");
1659 }
1660 new TGPrintDialog(fClient->GetDefaultRoot(), this, 400, 150,
1661 &gPrinter, &gPrintCommand, &ret);
1662 if (ret)
1663 Print();
1664 }
1665 break;
1666 case kM_EDIT_CUT:
1667 Cut();
1668 break;
1669 case kM_EDIT_COPY:
1670 Copy();
1671 break;
1672 case kM_EDIT_PASTE:
1673 Paste();
1674 break;
1675 case kM_EDIT_SELECTALL:
1676 SelectAll();
1677 break;
1678 case kM_SEARCH_FIND:
1679 {
1680 Search(kFALSE);
1681 }
1682 break;
1684 if (!fSearch) {
1686 kM_SEARCH_FIND, 0);
1687 return kTRUE;
1688 }
1691 msg2.Form("Couldn't find \"%s\"", fSearch->fBuffer);
1692 new TGMsgBox(fClient->GetDefaultRoot(), this, "Editor",
1693 msg2.Data(), kMBIconExclamation, kMBOk, 0);
1694 }
1695 break;
1696 case kM_SEARCH_GOTO:
1697 {
1698 Long_t ret = fCurrent.fY+1;
1699 new TGGotoDialog(fClient->GetDefaultRoot(), this, 400, 150, &ret);
1700 if (ret > -1) {
1701 ret--; // user specifies lines starting at 1
1702 Goto(ret);
1703 }
1704 }
1705 break;
1706 default:
1707 printf("No action implemented for menu id %zd\n", (size_t)parm1);
1708 break;
1709 }
1710 default:
1711 break;
1712 }
1713 break;
1714
1715 default:
1716 break;
1717 }
1718 return kTRUE;
1719}
1720
1721////////////////////////////////////////////////////////////////////////////////
1722/// Insert a character in the text edit widget.
1723
1724void TGTextEdit::InsChar(char character)
1725{
1726 if (fReadOnly) return;
1727
1728 char *charstring = 0;
1729 TGLongPosition pos;
1730
1731 if (character == '\t') {
1732 pos.fX = fCurrent.fX;
1733 pos.fY = fCurrent.fY;
1734 fText->InsChar(pos, '\t');
1735 pos.fX++;
1736 while (pos.fX & 0x7) {
1737 pos.fX++;
1738 }
1739 fText->ReTab(pos.fY);
1741 UInt_t(ToScrYCoord(pos.fY+1) - ToScrYCoord(pos.fY)));
1743 if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
1744 if (pos.fX != fText->GetLineLength(fCurrent.fY)) {
1746 } else {
1748 }
1749 }
1750 SetCurrent(pos);
1751 return;
1752 } else {
1753 if (fInsertMode == kReplace) {
1754 fCurrent.fX++;
1755 new TDelCharCom(this);
1756 }
1757 fText->InsChar(fCurrent, character);
1758 pos.fX = fCurrent.fX + 1;
1759 pos.fY = fCurrent.fY;
1760 charstring = new char[2];
1761 charstring[1] = '\0';
1762 charstring[0] = character;
1763 }
1765 if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
1766 if (pos.fX != fText->GetLineLength(fCurrent.fY)) {
1768 } else {
1769 SetHsbPosition(fVisible.fX/fScrollVal.fX+strlen(charstring));
1770 }
1771 if (!fHsb)
1772 gVirtualX->DrawString(fCanvas->GetId(), fNormGC(),
1775 charstring, strlen(charstring));
1776 } else {
1777#ifdef R__HAS_COCOA
1778 //I would use const, but some members of TGTextLine are non-const.
1779 if (TGTextLine *currentLine = fText->GetCurrentLine()) {
1780 const ULong_t lineStart = ToObjXCoord(fVisible.fX, fCurrent.fY);
1781 if (lineStart < currentLine->GetLineLength()) {
1782 const char *textToRender = currentLine->GetText(lineStart, currentLine->GetLineLength() - lineStart);
1783 //The next two lines can throw and textToRender will leak, but ROOT does not care about such things. :(
1784 gVirtualX->ClearArea(fCanvas->GetId(), Int_t(ToScrXCoord(0, fCurrent.fY)),
1785 Int_t(ToScrYCoord(fCurrent.fY)), UInt_t(ToScrXCoord(currentLine->GetLineLength(), fCurrent.fY)),
1787 gVirtualX->DrawString(fCanvas->GetId(), fNormGC(), Int_t(ToScrXCoord(0, fCurrent.fY)),
1789 textToRender, -1);
1790 delete [] textToRender;
1791 }
1792 }
1793#else
1794 gVirtualX->CopyArea(fCanvas->GetId(), fCanvas->GetId(), fNormGC(),
1800 gVirtualX->ClearArea(fCanvas->GetId(),
1803 UInt_t(ToScrXCoord(fCurrent.fX+strlen(charstring), fCurrent.fY) -
1806 gVirtualX->DrawString(fCanvas->GetId(), fNormGC(),
1809 charstring, strlen(charstring));
1810 fCursorState = 2; // the ClearArea effectively turned off the cursor
1811#endif
1812 }
1813 delete [] charstring;
1814 SetCurrent(pos);
1815}
1816
1817////////////////////////////////////////////////////////////////////////////////
1818/// Delete a character from the text edit widget.
1819
1821{
1822 if (fReadOnly) {
1823 return;
1824 }
1825
1826 char *buffer;
1827 TGLongPosition pos, pos2;
1828 Long_t len;
1829
1830 pos.fY = fCurrent.fY;
1831 pos.fX = fCurrent.fX;
1832 UInt_t h = 0;
1833
1834 if (fCurrent.fX > 0) {
1835 Int_t y = (Int_t)ToScrYCoord(pos.fY);
1836 h = UInt_t(ToScrYCoord(pos.fY+2) - y);
1837 if (!y) h = h << 1;
1838
1839 pos.fX--;
1840 if (fText->GetChar(pos) == 16) {
1841 do {
1842 pos.fX++;
1843 fText->DelChar(pos);
1844 pos.fX -= 2;
1845 } while (fText->GetChar(pos) != '\t');
1846
1847 pos.fX++;
1848 fText->DelChar(pos);
1849 pos.fX--;
1850 fText->ReTab(pos.fY);
1851 UpdateRegion(0, y, fCanvas->GetWidth(), h);
1852 } else {
1853 pos.fX = fCurrent.fX;
1854 fText->DelChar(pos);
1855 pos.fX = fCurrent.fX - 1;
1856 }
1857 if (ToScrXCoord(fCurrent.fX-1, fCurrent.fY) < 0) {
1859 }
1861 UpdateRegion(0, y, fCanvas->GetWidth(), h);
1862 } else {
1863 if (fCurrent.fY > 0) {
1865 if (len > 0) {
1866 buffer = fText->GetLine(fCurrent, len);
1867 pos.fY--;
1868 pos.fX = fText->GetLineLength(fCurrent.fY-1);
1869 fText->InsText(pos, buffer);
1870 pos.fY++;
1871 delete [] buffer;
1872 } else {
1873 pos.fX = fText->GetLineLength(fCurrent.fY-1);
1874 }
1875
1876 pos2.fY = ToScrYCoord(fCurrent.fY+1);
1877 pos.fY = fCurrent.fY - 1;
1879
1880 if (ToScrXCoord(pos.fX, fCurrent.fY-1) >= (Int_t)fCanvas->GetWidth()) {
1882 }
1883
1884#ifdef R__HAS_COCOA
1886#else
1888 gVirtualX->CopyArea(fCanvas->GetId(), fCanvas->GetId(), fNormGC(), 0,
1889 Int_t(pos2.fY), fWidth, h, 0, (Int_t)ToScrYCoord(fCurrent.fY));
1890 if (ToScrYCoord(pos.fY) < 0) {
1892 }
1894#endif
1897 }
1898 }
1899
1900 SetCurrent(pos);
1901}
1902
1903////////////////////////////////////////////////////////////////////////////////
1904/// Break a line.
1905
1907{
1908 if (fReadOnly) return;
1909
1910 TGLongPosition pos;
1912 if (ToScrYCoord(fCurrent.fY+2) <= (Int_t)fCanvas->GetHeight()) {
1913#ifdef R__HAS_COCOA
1915#else
1916 gVirtualX->CopyArea(fCanvas->GetId(), fCanvas->GetId(), fNormGC(), 0,
1920 0, (Int_t)ToScrYCoord(fCurrent.fY+2));
1923#endif
1924 if (fVisible.fX != 0) {
1925 SetHsbPosition(0);
1926 }
1929 } else {
1935 }
1936 pos.fY = fCurrent.fY+1;
1937 pos.fX = 0;
1938 SetCurrent(pos);
1939}
1940
1941////////////////////////////////////////////////////////////////////////////////
1942/// Scroll the canvas to new_top in the kVertical or kHorizontal direction.
1943
1944void TGTextEdit::ScrollCanvas(Int_t new_top, Int_t direction)
1945{
1946 CursorOff();
1947
1948 TGTextView::ScrollCanvas(new_top, direction);
1949
1950 CursorOn();
1951}
1952
1953////////////////////////////////////////////////////////////////////////////////
1954/// Redraw the text edit widget.
1955
1957{
1958 CursorOff();
1959
1961
1962 CursorOn();
1963}
1964
1965////////////////////////////////////////////////////////////////////////////////
1966/// Go to the previous character.
1967
1969{
1970 if (fCurrent.fY == 0 && fCurrent.fX == 0) {
1971 gVirtualX->Bell(0);
1972 return;
1973 }
1974
1975 TGLongPosition pos;
1976 Long_t len;
1977
1978 pos.fY = fCurrent.fY;
1979 pos.fX = fCurrent.fX;
1980 if (fCurrent.fX > 0) {
1981 pos.fX--;
1982 while (fText->GetChar(pos) == 16) {
1983 pos.fX--;
1984 }
1985
1986 if (ToScrXCoord(pos.fX, pos.fY) < 0) {
1987 if (fVisible.fX-(Int_t)fCanvas->GetWidth()/2 >= 0) {
1989 } else {
1990 SetHsbPosition(0);
1991 }
1992 }
1993 } else {
1994 if (fCurrent.fY > 0) {
1995 pos.fY = fCurrent.fY - 1;
1996 len = fText->GetLineLength(pos.fY);
1997 if (ToScrYCoord(fCurrent.fY) <= 0) {
1999 }
2000 if (ToScrXCoord(len, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
2003 }
2004 pos.fX = len;
2005 }
2006 }
2007 SetCurrent(pos);
2008}
2009
2010////////////////////////////////////////////////////////////////////////////////
2011/// Go to next character.
2012
2014{
2016
2017 if (fCurrent.fY == fText->RowCount()-1 && fCurrent.fX == len) {
2018 gVirtualX->Bell(0);
2019 return;
2020 }
2021
2022 TGLongPosition pos;
2023 pos.fY = fCurrent.fY;
2024 if (fCurrent.fX < len) {
2025 if (fText->GetChar(fCurrent) == '\t') {
2026 pos.fX = fCurrent.fX + 8 - (fCurrent.fX & 0x7);
2027 } else {
2028 pos.fX = fCurrent.fX + 1;
2029 }
2030
2031 if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
2033 }
2034 } else {
2035 if (fCurrent.fY < fText->RowCount()-1) {
2036 pos.fY = fCurrent.fY + 1;
2037 if (ToScrYCoord(pos.fY+1) >= (Int_t)fCanvas->GetHeight()) {
2039 }
2040 SetHsbPosition(0);
2041 pos.fX = 0;
2042 }
2043 }
2044 SetCurrent(pos);
2045}
2046
2047////////////////////////////////////////////////////////////////////////////////
2048/// Make current position first line in window by scrolling up.
2049
2051{
2052 TGLongPosition pos;
2053 Long_t len;
2054 if (fCurrent.fY > 0) {
2055 pos.fY = fCurrent.fY - 1;
2056 if (ToScrYCoord(fCurrent.fY) <= 0) {
2058 }
2060 if (fCurrent.fX > len) {
2061 if (ToScrXCoord(len, pos.fY) <= 0) {
2062 if (ToScrXCoord(len, pos.fY) < 0) {
2065 } else {
2066 SetHsbPosition(0);
2067 }
2068 }
2069 pos.fX = len;
2070 } else {
2072 }
2073
2074 while (fText->GetChar(pos) == 16) {
2075 pos.fX++;
2076 }
2077 SetCurrent(pos);
2078 }
2079}
2080
2081////////////////////////////////////////////////////////////////////////////////
2082/// Move one line down.
2083
2085{
2086 TGLongPosition pos;
2087 Long_t len;
2088 if (fCurrent.fY < fText->RowCount()-1) {
2090 pos.fY = fCurrent.fY + 1;
2091 if (ToScrYCoord(pos.fY+1) > (Int_t)fCanvas->GetHeight()) {
2093 }
2094 if (fCurrent.fX > len) {
2095 if (ToScrXCoord(len, pos.fY) <= 0) {
2096 if (ToScrXCoord(len, pos.fY) < 0) {
2098 } else {
2099 SetHsbPosition(0);
2100 }
2101 }
2102 pos.fX = len;
2103 } else {
2105 }
2106
2107 while (fText->GetChar(pos) == 16) {
2108 pos.fX++;
2109 }
2110 SetCurrent(pos);
2111 }
2112}
2113
2114////////////////////////////////////////////////////////////////////////////////
2115/// Move one screen up.
2116
2118{
2119 TGLongPosition pos;
2120 pos.fX = fCurrent.fX;
2122 if (fVisible.fY - (Int_t)fCanvas->GetHeight() >= 0) { // +1
2124 } else {
2125 pos.fY = 0;
2126 SetVsbPosition(0);
2127 }
2128 while (fText->GetChar(pos) == 16) {
2129 pos.fX++;
2130 }
2131 SetCurrent(pos);
2132}
2133
2134////////////////////////////////////////////////////////////////////////////////
2135/// Move one screen down.
2136
2138{
2139 TGLongPosition pos;
2140 pos.fX = fCurrent.fX;
2142 Long_t count = fText->RowCount()-1;
2143 if ((Int_t)fCanvas->GetHeight() < ToScrYCoord(count)) {
2145 } else {
2146 pos.fY = count;
2147 }
2148 while (fText->GetChar(pos) == 16) {
2149 pos.fX++;
2150 }
2151 SetCurrent(pos);
2152}
2153
2154////////////////////////////////////////////////////////////////////////////////
2155/// Move to beginning of line.
2156
2158{
2159 TGLongPosition pos;
2160 pos.fY = fCurrent.fY;
2161 pos.fX = 0;
2162 SetHsbPosition(0);
2163 SetCurrent(pos);
2164}
2165
2166////////////////////////////////////////////////////////////////////////////////
2167/// Move to end of line.
2168
2170{
2171 TGLongPosition pos;
2172 pos.fY = fCurrent.fY;
2173 pos.fX = fText->GetLineLength(pos.fY);
2174 if (ToScrXCoord(pos.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()) {
2176 }
2177 SetCurrent(pos);
2178}
2179
2180////////////////////////////////////////////////////////////////////////////////
2181/// Return selection graphics context for text cursor.
2182
2184{
2185 if (!fgCursor0GC) {
2188 }
2189 return *fgCursor0GC;
2190}
2191
2192////////////////////////////////////////////////////////////////////////////////
2193/// Return default graphics context for text cursor.
2194
2196{
2197 if (!fgCursor1GC) {
2198 fgCursor1GC = new TGGC(GetDefaultGC());
2200 }
2201 return *fgCursor1GC;
2202}
2203
2204////////////////////////////////////////////////////////////////////////////////
2205/// Save a text edit widget as a C++ statement(s) on output stream out
2206
2207void TGTextEdit::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2208{
2209 char quote = '"';
2210 out << " TGTextEdit *";
2211 out << GetName() << " = new TGTextEdit(" << fParent->GetName()
2212 << "," << GetWidth() << "," << GetHeight()
2213 << ");"<< std::endl;
2214 if (option && strstr(option, "keep_names"))
2215 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
2216
2217 if (IsReadOnly()) {
2218 out << " " << GetName() << "->SetReadOnly(kTRUE);" << std::endl;
2219 }
2220
2221 if (!IsMenuEnabled()) {
2222 out << " " << GetName() << "->EnableMenu(kFALSE);" << std::endl;
2223 }
2224
2226 out << " " << GetName() << "->ChangeBackground(" << fCanvas->GetBackground() << ");" << std::endl;
2227 }
2228
2229 TGText *txt = GetText();
2230 Bool_t fromfile = strlen(txt->GetFileName()) ? kTRUE : kFALSE;
2231 TString fn;
2232
2233 if (fromfile) {
2234 const char *filename = txt->GetFileName();
2237 } else {
2238 fn = TString::Format("Txt%s", GetName()+5);
2239 txt->Save(fn.Data());
2240 }
2241 out << " " << GetName() << "->LoadFile(" << quote << fn.Data() << quote << ");" << std::endl;
2242}
Handle_t Atom_t
WM token.
Definition GuiTypes.h:37
@ 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
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
@ kGXxor
src XOR dst
Definition GuiTypes.h:74
@ kGXand
src AND dst
Definition GuiTypes.h:69
const Mask_t kKeyShiftMask
Definition GuiTypes.h:195
const Handle_t kNone
Definition GuiTypes.h:88
const Mask_t kKeyControlMask
Definition GuiTypes.h:197
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
@ kButton2
Definition GuiTypes.h:214
@ kButton3
Definition GuiTypes.h:214
@ kButton1
Definition GuiTypes.h:214
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
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
long Longptr_t
Definition RtypesCore.h:75
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
@ 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
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t cursor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t del
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t nchar
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char text
R__EXTERN void * gTQSender
Definition TQObject.h:46
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2557
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
#define gVirtualX
Definition TVirtualX.h:337
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() override
This method must be overridden to handle object notification (the base implementation is no-op).
TBreakLineCom(TGTextEdit *te)
Bool_t Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
TDelCharCom(TGTextEdit *te)
void SetEndPos(TGLongPosition end)
Bool_t fBreakLine
TGLongPosition fEndPos
~TDelTextCom() override
TGText * fText
TDelTextCom(TGTextEdit *te, TGText *txt)
void SetBreakLine(Bool_t on)
TDelTextCom & operator=(const TDelTextCom &dtc)
Bool_t Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
TDelTextCom(const TDelTextCom &dtc)
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:381
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 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
void MapRaised() override
map raised
Definition TGFrame.h:205
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:25
Handle_t GetId() const
Definition TGObject.h:41
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
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() override
'Notify' all objects in this collection.
~TGTextEditHist() override
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
TGTextEdit(const TGTextEdit &)=delete
virtual Bool_t Goto(Long_t line, Long_t column=0)
Goto the specified line.
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.
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion event in text edit widget.
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.
Bool_t HandleDoubleClick(Event_t *event) override
Handle double click event.
EInsertMode GetInsertMode() const
Definition TGTextEdit.h:99
void Delete(Option_t *="") override
Delete selection.
void ScrollCanvas(Int_t newTop, Int_t direction) override
Scroll the canvas to new_top in the kVertical or kHorizontal direction.
void SavePrimitive(std::ostream &out, Option_t *="") override
Save a text edit widget as a C++ statement(s) on output stream out.
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
void Clear(Option_t *="") override
Clear text edit widget.
virtual void DelChar()
Delete a character from the text edit widget.
Bool_t HandleFocusChange(Event_t *event) override
Handle focus change event in text edit widget.
GContext_t fCursor0GC
graphics context for erasing cursor
Definition TGTextEdit.h:37
virtual void SavedAs()
Definition TGTextEdit.h:129
virtual void LineDown()
Move one line down.
virtual void ScreenDown()
Move one screen down.
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Process context menu messages.
Bool_t Copy() override
Copy text.
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.
void Print(Option_t *="") const override
Send current buffer to printer.
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.
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
Bool_t Search(const char *string, Bool_t direction=kTRUE, Bool_t caseSensitive=kFALSE) override
Search for string in the specified direction.
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
Bool_t HandleKey(Event_t *event) override
The key press event handler converts a key press to some line editor action.
virtual void SetFocus()
Definition TGTextEdit.h:109
void DrawRegion(Int_t x, Int_t y, UInt_t width, UInt_t height) override
Redraw the text edit widget.
TGPopupMenu * fMenu
popup menu with editor actions
Definition TGTextEdit.h:41
~TGTextEdit() override
Cleanup text edit widget.
Bool_t HandleSelection(Event_t *event) override
Handle selection notify event.
Bool_t HandleButton(Event_t *event) override
Handle mouse button event in text edit widget.
Bool_t HandleTimer(TTimer *t) override
Handle timer cursor blink timer.
Long_t ReturnLongestLineWidth() override
Return width of longest line in widget.
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.
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
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.
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.
void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h) override
Draw lines in exposed region.
virtual Long_t ToScrYCoord(Long_t yCoord)
Convert line number to screen coordinate.
virtual Long_t ReturnLongestLineWidth()
Return width of longest line.
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
TGText * fClipText
clipboard text buffer
Definition TGTextView.h:26
static const TGGC & GetDefaultSelectedGC()
Return selection graphics context in use.
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Bool_t HandleTimer(TTimer *t) override
Handle scroll timer.
Bool_t fIsMarked
true if text is marked/selected
Definition TGTextView.h:36
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion event in the text editor widget.
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 Long_t ToScrXCoord(Long_t xCoord, Long_t line)
Convert column number in specified line to screen coordinate.
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
Bool_t HandleButton(Event_t *event) override
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.
void Clear(Option_t *="") override
Clear text view widget.
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
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
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
TInsCharCom(TGTextEdit *te, char ch)
Bool_t Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
Bool_t Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
void SetEndPos(TGLongPosition end)
TInsTextCom(TGTextEdit *te)
TGLongPosition fEndPos
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:691
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:468
void RemoveLast() override
Remove the last object of the list.
Definition TList.cxx:907
Mother of all ROOT objects.
Definition TObject.h:41
virtual Bool_t Notify()
This method must be overridden to handle object notification (the base implementation is no-op).
Definition TObject.cxx:611
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=nullptr, void *receiver=nullptr, const char *slot=nullptr)
Disconnects signal of this object from slot of receiver.
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
const char * Data() const
Definition TString.h:376
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:2378
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2356
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:662
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:471
virtual int ClosePipe(FILE *pipe)
Close the pipe.
Definition TSystem.cxx:671
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
void Reset()
Reset the timer.
Definition TTimer.cxx:159
void Remove() override
Definition TTimer.h:86
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
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
Int_t fY
pointer x, y coordinates in event window
Definition GuiTypes.h:178
Int_t fXRoot
Definition GuiTypes.h:179
Window_t fWindow
window reported event is relative to
Definition GuiTypes.h:176
UInt_t fState
key or button mask
Definition GuiTypes.h:181
Int_t fYRoot
coordinates relative to root
Definition GuiTypes.h:179
Int_t fX
Definition GuiTypes.h:178
Time_t fTime
time event event occurred in ms
Definition GuiTypes.h:177
UInt_t fCode
key or button code
Definition GuiTypes.h:180
Longptr_t fUser[5]
5 longs can be used by client message events NOTE: only [0], [1] and [2] may be used.
Definition GuiTypes.h:187