222 TString *TGTextEntry::fgClipboardText = 0;
223 const TGFont *TGTextEntry::fgDefaultFont = 0;
224 const TGGC *TGTextEntry::fgDefaultSelectedGC = 0;
225 const TGGC *TGTextEntry::fgDefaultSelectedBackgroundGC = 0;
226 const TGGC *TGTextEntry::fgDefaultGC = 0;
228 TGTextEntry *gBlinkingEntry = 0;
232 class TBlinkTimer :
public TTimer {
234 TGTextEntry *fTextEntry;
236 TBlinkTimer(TGTextEntry *t, Long_t ms) : TTimer(ms, kTRUE) { fTextEntry = t; }
243 Bool_t TBlinkTimer::Notify()
245 fTextEntry->HandleTimer(0);
251 ClassImp(TGTextEntry);
257 TGTextEntry::TGTextEntry(
const TGWindow *p, TGTextBuffer *text, Int_t
id,
258 GContext_t norm, FontStruct_t font, UInt_t options,
260 TGFrame(p, 1, 1, options | kOwnBackground, back)
262 TGGC *normgc = fClient->GetResourcePool()->GetGCPool()->FindGC(norm);
269 fNormGC = GetDefaultGC();
279 TGTextEntry::TGTextEntry(
const TGWindow *parent,
const char *text, Int_t
id) :
280 TGFrame(parent, 1, 1, kSunkenFrame | kDoubleBorder | kOwnBackground, fgWhitePixel)
284 fNormGC = GetDefaultGC();
285 fFontStruct = GetDefaultFontStruct();
286 fText =
new TGTextBuffer();
287 fText->AddText(0, !text && !parent ? GetName() : text);
297 TGTextEntry::TGTextEntry(
const TString &contents,
const TGWindow *parent, Int_t
id) :
298 TGFrame(parent, 1, 1, kSunkenFrame | kDoubleBorder | kOwnBackground, fgWhitePixel)
302 fNormGC = GetDefaultGC();
303 fFontStruct = GetDefaultFontStruct();
304 fText =
new TGTextBuffer();
305 fText->AddText(0, contents.Data());
313 TGTextEntry::~TGTextEntry()
319 if (
this == gBlinkingEntry) gBlinkingEntry = 0;
325 void TGTextEntry::Init()
327 fWidgetFlags = kWidgetWantFocus | kWidgetIsEnabled;
328 fSelGC = GetDefaultSelectedGC();
329 fSelbackGC = GetDefaultSelectedBackgroundGC()();
337 fAlignment= kTextLeft;
338 fInsertMode = kInsert;
339 fDefWidth = fDefHeight = 0;
341 int tw, max_ascent, max_descent;
342 tw = gVirtualX->TextWidth(fFontStruct, GetText(), fText->GetTextLength());
345 TString dummy(
'w', fText->GetBufferLength());
346 tw = gVirtualX->TextWidth(fFontStruct, dummy.Data(), dummy.Length());
348 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
349 Resize(tw + 8, max_ascent + max_descent + 7);
351 Int_t offset = IsFrameDrawn() ? 4 : 0;
352 if ((offset == 0) && fParent->InheritsFrom(
"TGComboBox"))
355 fCursorIX = fStartIX = fEndIX = fOffset = 0;
356 fSelectionOn = fCursorOn = kFALSE;
359 fClipboard = fClient->GetResourcePool()->GetClipboard();
361 gVirtualX->SetCursor(fId, fClient->GetResourcePool()->GetTextCursor());
363 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
364 kButtonPressMask | kButtonReleaseMask |
365 kButtonMotionMask, kNone, kNone);
367 AddInput(kKeyPressMask | kFocusChangeMask | kStructureNotifyMask |
368 kEnterWindowMask | kLeaveWindowMask);
370 SetWindowAttributes_t wattr;
371 wattr.fMask = kWAWinGravity | kWABitGravity;
372 wattr.fBitGravity = 1;
373 wattr.fWinGravity = 1;
374 gVirtualX->ChangeWindowAttributes(fId, &wattr);
377 fHasOwnFont = kFALSE;
378 fEditDisabled = kEditDisableHeight;
384 TGDimension TGTextEntry::GetDefaultSize()
const
386 UInt_t w = (GetOptions() & kFixedWidth) || (fDefWidth == 0) ? fWidth : fDefWidth;
387 UInt_t h = (GetOptions() & kFixedHeight) || (fDefHeight == 0) ? fHeight : fDefHeight;
388 return TGDimension(w, h);
394 void TGTextEntry::SetDefaultSize(UInt_t w, UInt_t h)
403 void TGTextEntry::ReturnPressed()
405 SendMessage(fMsgWindow, MK_MSG(kC_TEXTENTRY, kTE_ENTER), fWidgetId, 0);
406 fClient->ProcessLine(fCommand, MK_MSG(kC_TEXTENTRY, kTE_ENTER),fWidgetId, 0);
408 Emit(
"ReturnPressed()");
414 void TGTextEntry::ShiftTabPressed()
416 Emit(
"ShiftTabPressed()");
422 void TGTextEntry::TabPressed()
424 SendMessage(fMsgWindow, MK_MSG(kC_TEXTENTRY, kTE_TAB), fWidgetId, 0);
425 fClient->ProcessLine(fCommand, MK_MSG(kC_TEXTENTRY, kTE_TAB), fWidgetId, 0);
427 Emit(
"TabPressed()");
433 void TGTextEntry::TextChanged(
const char *)
435 SendMessage(fMsgWindow, MK_MSG(kC_TEXTENTRY, kTE_TEXTCHANGED),fWidgetId, 0);
436 fClient->ProcessLine(fCommand, MK_MSG(kC_TEXTENTRY, kTE_TEXTCHANGED),fWidgetId, 0);
438 Emit(
"TextChanged(char*)", GetText());
444 void TGTextEntry::CursorOutLeft()
446 Emit(
"CursorOutLeft()");
452 void TGTextEntry::CursorOutRight()
454 Emit(
"CursorOutRight()");
460 void TGTextEntry::CursorOutUp()
462 Emit(
"CursorOutUp()");
468 void TGTextEntry::CursorOutDown()
470 Emit(
"CursorOutDown()");
476 void TGTextEntry::DoubleClicked()
478 Emit(
"DoubleClicked()");
487 TString TGTextEntry::GetDisplayText()
const
491 switch (GetEchoMode()) {
499 res.Prepend(
'*', fText->GetTextLength());
508 void TGTextEntry::SetState(Bool_t state)
511 SetFlags(kWidgetIsEnabled);
512 SetBackgroundColor(fgWhitePixel);
514 ClearFlags(kWidgetIsEnabled);
515 SetBackgroundColor(GetDefaultFrameBackground());
517 if (fCurBlink) fCurBlink->Remove();
519 fClient->NeedRedraw(
this);
525 Int_t TGTextEntry::GetCharacterIndex(Int_t xcoord)
527 int tw, ix, up, down, len;
530 TString dt = GetDisplayText();
532 tw = gVirtualX->TextWidth(fFontStruct, dt.Data(), len);
533 if (xcoord < 0)
return 0;
534 if (xcoord > tw)
return len;
539 while (up-down > 1) {
541 tw = gVirtualX->TextWidth(fFontStruct, fText->GetString(), ix);
546 if (tw == xcoord)
break;
551 ix = TMath::Max(ix, 0);
552 ix = TMath::Min(ix, len);
562 void TGTextEntry::SetFrameDrawn(Bool_t enable)
564 if (fFrameDrawn == enable)
return;
566 fFrameDrawn = enable;
567 fClient->NeedRedraw(
this);
576 void TGTextEntry::SetAlignment(ETextJustification mode)
578 if ((mode == kTextRight ||
579 mode == kTextCenterX ||
580 mode == kTextLeft)) {
582 SetWindowAttributes_t wattr;
583 wattr.fMask = kWAWinGravity | kWABitGravity;
584 wattr.fWinGravity = 1;
586 if (mode == kTextLeft) {
587 wattr.fBitGravity = 1;
588 }
else if (mode == kTextRight) {
589 wattr.fBitGravity = 3;
591 wattr.fBitGravity = 5;
594 gVirtualX->ChangeWindowAttributes(fId, &wattr);
598 fClient->NeedRedraw(
this);
606 void TGTextEntry::SetInsertMode(EInsertMode mode)
608 if (fInsertMode == mode)
return;
611 fClient->NeedRedraw(
this);
621 void TGTextEntry::SetText(
const char *text, Bool_t emit)
623 TString oldText(GetText());
626 fText->AddText(0, text);
628 Int_t dif = fText->GetTextLength() - fMaxLen;
629 if (dif > 0) fText->RemoveText(fMaxLen, dif);
632 if (oldText != GetText()) {
635 fClient->NeedRedraw(
this);
646 void TGTextEntry::SetMaxLength(Int_t maxlen)
648 fMaxLen = maxlen < 0 ? 0 : maxlen;
650 Int_t dif = fText->GetTextLength() - fMaxLen;
651 if (dif > 0) fText->RemoveText(fMaxLen, dif);
653 SetCursorPosition(0);
672 void TGTextEntry::SetEchoMode(EEchoMode mode)
674 if (fEchoMode == mode)
return;
676 Int_t offset = IsFrameDrawn() ? 4 : 0;
677 if ((offset == 0) && fParent->InheritsFrom(
"TGComboBox"))
680 if (GetEchoMode() == kNoEcho) { fCursorX = offset; }
682 fClient->NeedRedraw(
this);
691 TString TGTextEntry::GetMarkedText()
const
693 Int_t minP = MinMark();
694 Int_t len = MaxMark() - minP;
695 TString res(GetText()+minP,len);
703 void TGTextEntry::NewMark(Int_t newPos)
705 TString dt = GetDisplayText();
706 Int_t offset = IsFrameDrawn() ? 4 : 0;
707 if ((offset == 0) && fParent->InheritsFrom(
"TGComboBox"))
709 Int_t x = fOffset + offset;
710 Int_t len = dt.Length();
712 Int_t pos = newPos < len ? newPos : len;
713 fEndIX = pos < 0 ? 0 : pos;
715 fSelectionOn = fSelectionOn && (fEndIX != fStartIX) && (GetEchoMode() != kNoEcho) ;
716 SetCursorPosition(pos);
719 fEndX = x + gVirtualX->TextWidth(fFontStruct, dt.Data() , fEndIX);
720 fStartX = x + gVirtualX->TextWidth(fFontStruct, dt.Data() , fStartIX);
728 void TGTextEntry::SetCursorPosition(Int_t newPos)
730 Int_t offset = IsFrameDrawn() ? 4 : 0;
731 if ((offset == 0) && fParent->InheritsFrom(
"TGComboBox"))
733 if (GetEchoMode() == kNoEcho) { fCursorX = offset;
return; }
736 TString dt = GetDisplayText();
738 Int_t x = fOffset + offset;
739 Int_t len = dt.Length();
747 if (newPos > len) CursorOutRight();
756 fCursorX = x + gVirtualX->TextWidth(fFontStruct, dt.Data(), fCursorIX);
759 fStartIX = fCursorIX;
768 void TGTextEntry::MarkWord(Int_t pos)
771 while (i >= 0 && isprint(GetText()[i]) && !isspace(GetText()[i])) i--;
773 Int_t newStartIX = i;
776 while (isprint(GetText()[i]) && !isspace(GetText()[i])) i++;
777 while(isspace(GetText()[i])) i++;
779 fSelectionOn = kTRUE;
780 fStartIX = newStartIX;
789 void TGTextEntry::Insert(
const char *newText)
791 TString old(GetText());
794 if (t.IsNull())
return;
796 for (
int i=0; i<t.Length(); i++) {
797 if (t[i] <
' ') t[i] =
' ';
800 Int_t minP = MinMark();
801 Int_t maxP = MaxMark();
802 Int_t cp = fCursorIX;
804 if (HasMarkedText()) {
805 fText->RemoveText(minP, maxP-minP);
809 if (fInsertMode == kReplace) fText->RemoveText(cp,t.Length());
810 Int_t ncp = TMath::Min(cp+t.Length(), GetMaxLength());
811 fText->AddText(cp, t.Data());
812 Int_t dlen = fText->GetTextLength()-GetMaxLength();
813 if (dlen>0) fText->RemoveText(GetMaxLength(),dlen);
815 SetCursorPosition(ncp);
816 if (old != GetText()) TextChanged();
823 void TGTextEntry::CursorRight(Bool_t mark, Int_t steps)
825 Int_t cp = fCursorIX + steps;
827 if (cp == fCursorIX) {
829 fSelectionOn = kFALSE;
830 fEndIX = fStartIX = fCursorIX;
833 fSelectionOn = kTRUE;
836 fSelectionOn = kFALSE;
837 SetCursorPosition(cp);
845 void TGTextEntry::CursorLeft(Bool_t mark, Int_t steps)
847 CursorRight(mark, -steps);
855 void TGTextEntry::CursorWordForward(Bool_t mark)
858 while (i < (Int_t)fText->GetTextLength() && !isspace(GetText()[i])) ++i;
859 while (i < (Int_t)fText->GetTextLength() && isspace(GetText()[i])) ++i;
860 CursorRight(mark, i - fCursorIX);
868 void TGTextEntry::CursorWordBackward(Bool_t mark)
871 while (i > 0 && isspace(GetText()[i-1])) --i;
872 while (i > 0 && !isspace(GetText()[i-1])) --i;
873 CursorLeft(mark, fCursorIX - i);
883 void TGTextEntry::Backspace()
885 if (HasMarkedText()) {
887 }
else if (fCursorIX > 0) {
900 void TGTextEntry::Del()
902 Int_t minP = MinMark();
903 Int_t maxP = MaxMark();
904 Int_t offset = IsFrameDrawn() ? 4 : 0;
905 Int_t w = GetWidth() - 2 * offset;
907 if (HasMarkedText()) {
908 fText->RemoveText(minP, maxP-minP);
909 fSelectionOn = kFALSE;
910 TString dt = GetDisplayText();
911 Int_t textWidth = gVirtualX->TextWidth(fFontStruct, dt.Data(), dt.Length());
912 fOffset = w - textWidth - 1;
913 SetCursorPosition(minP);
914 }
else if (fCursorIX != (Int_t)fText->GetTextLength()) {
915 fSelectionOn = kFALSE;
916 fText->RemoveText(fCursorIX , 1);
917 TString dt = GetDisplayText();
918 Int_t textWidth = gVirtualX->TextWidth(fFontStruct, dt.Data(), dt.Length());
919 fOffset = w - textWidth - 1;
920 SetCursorPosition(fCursorIX);
929 void TGTextEntry::Remove()
931 if (fCursorIX < (Int_t)fText->GetTextLength()) {
932 fText->RemoveText(fCursorIX , fText->GetTextLength() - fCursorIX);
933 SetCursorPosition(fCursorIX);
943 void TGTextEntry::CopyText()
const
945 if (HasMarkedText() && GetEchoMode() == kNormal) {
946 if (!fgClipboardText) fgClipboardText =
new TString();
947 *fgClipboardText = GetMarkedText();
948 gVirtualX->SetPrimarySelectionOwner(fId);
957 void TGTextEntry::Paste()
959 if (gVirtualX->GetPrimarySelectionOwner() == kNone) {
961 if (fgClipboardText) Insert(fgClipboardText->Data());
963 gVirtualX->ConvertPrimarySelection(fId, fClipboard, 0);
971 void TGTextEntry::Cut()
973 if (HasMarkedText()) {
982 void TGTextEntry::Clear(Option_t *)
993 void TGTextEntry::Home(Bool_t mark)
997 fSelectionOn = kTRUE;
998 fStartIX = fCursorIX;
1002 fSelectionOn = kFALSE;
1003 SetCursorPosition(0);
1013 void TGTextEntry::End(Bool_t mark)
1015 TString dt = GetDisplayText();
1016 Int_t len = dt.Length();
1018 fOffset = (Int_t)GetWidth() - gVirtualX->TextWidth(fFontStruct, dt.Data(), len);
1019 if (fOffset > 0) fOffset = 0;
1022 fSelectionOn = kTRUE;
1023 fStartIX = fCursorIX;
1027 fSelectionOn = kFALSE;
1028 SetCursorPosition(len);
1038 void TGTextEntry::SelectAll()
1040 fSelectionOn = kTRUE;
1042 NewMark(fText->GetTextLength());
1050 void TGTextEntry::Deselect()
1052 fSelectionOn = kFALSE;
1053 fEndIX = fStartIX = fCursorIX;
1060 void TGTextEntry::DrawBorder()
1062 switch (fOptions & (kSunkenFrame | kRaisedFrame | kDoubleBorder)) {
1063 case kSunkenFrame | kDoubleBorder:
1064 if (gClient->GetStyle() < 2) {
1065 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, fWidth-2, 0);
1066 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, 0, fHeight-2);
1067 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, fWidth-3, 1);
1068 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, 1, fHeight-3);
1070 gVirtualX->DrawLine(fId, GetHilightGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
1071 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
1072 gVirtualX->DrawLine(fId, GetBckgndGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
1073 gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-2, 1, fWidth-2, fHeight-2);
1077 TGFrame::DrawBorder();
1085 void TGTextEntry::DoRedraw()
1087 Int_t x, y, max_ascent, max_descent, h;
1088 Int_t offset = IsFrameDrawn() ? 4 : 0;
1089 if ((offset == 0) && fParent->InheritsFrom(
"TGComboBox"))
1091 TString dt = GetDisplayText();
1092 Int_t len = dt.Length();
1095 Int_t border = IsFrameDrawn() ? fBorderWidth : 0;
1097 gVirtualX->ClearArea(fId, border, border,
1098 fWidth - (border << 1), fHeight - (border << 1));
1100 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
1102 h = max_ascent + max_descent;
1103 y = (fHeight - h) >> 1 ;
1104 x = fOffset + offset;
1106 if (fEchoMode == kNoEcho) {
1107 fSelectionOn = kFALSE;
1111 if ((GetInsertMode() == kInsert) || (fEchoMode == kNoEcho)) {
1114 gVirtualX->DrawLine(fId, GetBlackGC()(), fCursorX, y - 1,
1117 gVirtualX->DrawString(fId, fNormGC(), x, y + max_ascent, dt.Data(), len);
1121 gVirtualX->DrawString(fId, fNormGC(), x, y + max_ascent, dt.Data(), len);
1124 Int_t ind = fCursorIX < len-1 ? fCursorIX : len - 1;
1125 Int_t charWidth = ind < 0 || fCursorIX > len - 1 ? 4 :
1126 gVirtualX->TextWidth(fFontStruct, &dt[ind],1);
1128 Int_t before = gVirtualX->TextWidth(fFontStruct, dt, fCursorIX) + x;
1130 gVirtualX->FillRectangle(fId, fSelbackGC , before, y ,
1133 if (fCursorIX < len)
1134 gVirtualX->DrawString(fId, fSelGC(), before, y + max_ascent, &dt[ind], 1);
1139 int xs, ws, ixs, iws;
1141 xs = TMath::Min(fStartX, fEndX);
1142 ws = TMath::Abs(fEndX - fStartX);
1143 ixs = TMath::Min(fStartIX, fEndIX);
1144 iws = TMath::Abs(fEndIX - fStartIX);
1146 gVirtualX->FillRectangle(fId, fSelbackGC, xs, y, ws, h + 1);
1148 gVirtualX->DrawString(fId, fSelGC(), xs, y + max_ascent,
1149 dt.Data() + ixs, iws);
1151 if (IsFrameDrawn()) DrawBorder();
1226 Bool_t TGTextEntry::HandleKey(Event_t* event)
1232 if (fTip && event->fType == kGKeyPress) fTip->Hide();
1234 if (!IsEnabled() || event->fType != kGKeyPress)
return kTRUE;
1236 gVirtualX->LookupString(event, tmp,
sizeof(tmp), keysym);
1240 if ((EKeySym)keysym == kKey_Enter || (EKeySym)keysym == kKey_Return) {
1243 if (!TestBit(kNotDeleted))
return kTRUE;
1244 fSelectionOn = kFALSE;
1246 }
else if (event->fState & kKeyShiftMask && (EKeySym)keysym == kKey_Backtab) {
1248 fSelectionOn = kFALSE;
1251 }
else if ((EKeySym)keysym == kKey_Tab) {
1254 fSelectionOn = kFALSE;
1256 }
else if (event->fState & kKeyControlMask) {
1257 switch ((EKeySym)keysym & ~0x20) {
1259 Home(event->fState & kKeyShiftMask);
1262 CursorLeft(event->fState & kKeyShiftMask);
1271 End(event->fState & kKeyShiftMask);
1274 CursorRight(event->fState & kKeyShiftMask);
1280 HasMarkedText() ? Del() : Remove();
1296 CursorWordForward(event->fState & kKeyShiftMask);
1299 CursorWordBackward(event->fState & kKeyShiftMask);
1304 }
else if (n && keysym <127 && keysym >=32 &&
1305 (EKeySym)keysym != kKey_Delete &&
1306 (EKeySym)keysym != kKey_Backspace) {
1309 fSelectionOn = kFALSE;
1312 switch ((EKeySym)keysym) {
1320 CursorLeft(event->fState & kKeyShiftMask);
1323 CursorRight(event->fState & kKeyShiftMask);
1325 case kKey_Backspace:
1329 Home(event->fState & kKeyShiftMask);
1332 End(event->fState & kKeyShiftMask);
1338 SetInsertMode(GetInsertMode() == kInsert ? kReplace : kInsert);
1346 fClient->NeedRedraw(
this);
1354 Bool_t TGTextEntry::HandleButton(Event_t *event)
1356 if (fTip) fTip->Hide();
1358 if (!IsEnabled())
return kTRUE;
1360 if (event->fType == kButtonPress) {
1362 if (fEchoMode == kNoEcho)
return kTRUE;
1364 if (event->fCode == kButton1) {
1365 Int_t offset = IsFrameDrawn() ? 4 : 0;
1366 if ((offset == 0) && fParent->InheritsFrom(
"TGComboBox"))
1368 Int_t x = fOffset + offset;
1369 Int_t position = GetCharacterIndex(event->fX - x);
1370 fSelectionOn = kFALSE;
1371 SetCursorPosition(position);
1373 }
else if (event->fCode == kButton2) {
1374 if (gVirtualX->GetPrimarySelectionOwner() == kNone) {
1376 PastePrimary(fClient->GetDefaultRoot()->GetId(), kCutBuffer, kFALSE);
1378 gVirtualX->ConvertPrimarySelection(fId, fClipboard, event->fTime);
1382 if (event->fType == kButtonRelease)
1383 if (event->fCode == kButton1)
1392 Bool_t TGTextEntry::HandleCrossing(Event_t *event)
1394 if (event->fType == kEnterNotify) {
1395 if (fTip) fTip->Reset();
1397 if (fTip) fTip->Hide();
1406 Bool_t TGTextEntry::HandleMotion(Event_t *event)
1408 if (!IsEnabled() || (GetEchoMode() == kNoEcho))
return kTRUE;
1410 Int_t offset = IsFrameDrawn() ? 4 : 0;
1411 if ((offset == 0) && fParent->InheritsFrom(
"TGComboBox"))
1413 Int_t x = fOffset + offset;
1414 Int_t position = GetCharacterIndex(event->fX - x);
1415 fSelectionOn = kTRUE;
1425 Bool_t TGTextEntry::HandleDoubleClick(Event_t *event)
1427 if (!IsEnabled())
return kTRUE;
1429 Int_t offset = IsFrameDrawn() ? 4 : 0;
1430 if ((offset == 0) && fParent->InheritsFrom(
"TGComboBox"))
1432 Int_t x = fOffset + offset ;
1436 if (fEchoMode == kNoEcho)
return kTRUE;
1438 Int_t position = GetCharacterIndex(event->fX - x);
1446 Bool_t TGTextEntry::HandleConfigureNotify(Event_t* event)
1448 TGFrame::HandleConfigureNotify(event);
1449 Bool_t wasSelection = fSelectionOn;
1450 Int_t end = fEndIX, start = fStartIX;
1451 fSelectionOn = kFALSE;
1453 SetCursorPosition(fCursorIX);
1454 fSelectionOn = wasSelection;
1457 if (fSelectionOn) NewMark(fEndIX);
1464 Bool_t TGTextEntry::HandleFocusChange(Event_t *event)
1466 if (!IsEnabled())
return kTRUE;
1469 if (event->fType == kFocusIn) {
1471 if (!fCurBlink) fCurBlink =
new TBlinkTimer(
this, 500);
1473 gBlinkingEntry =
this;
1474 gSystem->AddTimer(fCurBlink);
1478 if (fCurBlink) fCurBlink->Remove();
1481 fClient->NeedRedraw(
this);
1488 Bool_t TGTextEntry::HandleSelection(Event_t *event)
1490 PastePrimary((Window_t)event->fUser[0], (Atom_t)event->fUser[3], kTRUE);
1497 Bool_t TGTextEntry::HandleSelectionClear(Event_t * )
1499 fSelectionOn = kFALSE;
1500 fEndIX = fStartIX = fCursorIX;
1501 fClient->NeedRedraw(
this);
1508 Bool_t TGTextEntry::HandleSelectionRequest(Event_t *event)
1516 reply.fType = kSelectionNotify;
1517 reply.fTime =
event->fTime;
1518 reply.fUser[0] =
event->fUser[0];
1519 reply.fUser[1] =
event->fUser[1];
1520 reply.fUser[2] =
event->fUser[2];
1521 reply.fUser[3] =
event->fUser[3];
1523 targets[0] = gVirtualX->InternAtom(
"TARGETS", kFALSE);
1524 targets[1] = gVirtualX->InternAtom(
"XA_STRING", kFALSE);
1526 if ((Atom_t)event->fUser[2] == targets[0]) {
1527 type = gVirtualX->InternAtom(
"XA_ATOM", kFALSE);
1528 gVirtualX->ChangeProperty((Window_t) event->fUser[0], (Atom_t) event->fUser[3],
1529 type, (UChar_t*) targets, (Int_t) 2);
1531 gVirtualX->SendEvent((Window_t)event->fUser[0], &reply);
1536 if (fgClipboardText) len = fgClipboardText->Length();
1537 buffer =
new char[len+1];
1538 if (fgClipboardText) strlcpy (buffer, fgClipboardText->Data(), len+1);
1540 gVirtualX->ChangeProperty((Window_t) event->fUser[0], (Atom_t) event->fUser[3],
1541 (Atom_t) event->fUser[2], (UChar_t*) buffer,
1545 gVirtualX->SendEvent((Window_t)event->fUser[0], &reply);
1554 void TGTextEntry::PastePrimary(Window_t wid, Atom_t property, Bool_t del)
1559 if (!IsEnabled())
return;
1561 gVirtualX->GetPasteBuffer(wid, property, data, nchar, del);
1563 if (nchar) Insert(data.Data());
1564 fClient->NeedRedraw(
this);
1570 Bool_t TGTextEntry::HandleTimer(TTimer *)
1572 fCursorOn = !fCursorOn;
1580 Bool_t TGTextEntry::IsCursorOutOfFrame()
1585 Int_t offset = IsFrameDrawn() ? 4 : 0;
1586 if ((offset == 0) && fParent->InheritsFrom(
"TGComboBox"))
1588 Int_t w = GetWidth();
1589 return ((fCursorX < offset) || (fCursorX > w-offset));
1595 void TGTextEntry::ScrollByChar()
1597 if (GetEchoMode() == kNoEcho)
return;
1599 TString dt = GetDisplayText();
1600 Int_t len = dt.Length();
1601 Int_t ind = fCursorIX < len-1 ? fCursorIX : len-1;
1602 Int_t charWidth = ind < 0 ? 4 : gVirtualX->TextWidth(fFontStruct, &dt[ind],1);
1603 Int_t w = GetWidth();
1605 Int_t offset = IsFrameDrawn() ? 4 : 0;
1606 if ((offset == 0) && fParent->InheritsFrom(
"TGComboBox"))
1609 if (fCursorX < offset) {
1610 fOffset += charWidth;
1611 fCursorX += charWidth;
1620 }
else if (fCursorX > w-offset) {
1621 fOffset -= charWidth;
1622 fCursorX -= charWidth;
1639 void TGTextEntry::UpdateOffset()
1641 TString dt = GetDisplayText();
1642 Int_t textWidth = gVirtualX->TextWidth(fFontStruct, dt.Data() , dt.Length());
1643 Int_t offset = IsFrameDrawn() ? 4 : 0;
1644 if ((offset == 0) && fParent->InheritsFrom(
"TGComboBox"))
1646 Int_t w = GetWidth() - 2 * offset;
1648 if (fAlignment == kTextRight) fOffset = w - textWidth - 1;
1649 else if (fAlignment == kTextCenterX) fOffset = (w - textWidth)/2;
1650 else if (fAlignment == kTextLeft) fOffset = 0;
1651 if (textWidth > 0 && textWidth > w) {
1652 if (IsCursorOutOfFrame()) ScrollByChar();
1661 void TGTextEntry::SetToolTipText(
const char *text, Long_t delayms)
1668 if (text && strlen(text))
1669 fTip =
new TGToolTip(fClient->GetDefaultRoot(),
this, text, delayms);
1675 void TGTextEntry::SetFocus()
1677 if (gBlinkingEntry && (gBlinkingEntry !=
this)) {
1678 gBlinkingEntry->fCurBlink->Remove();
1689 void TGTextEntry::InsertText(
const char *text, Int_t pos)
1691 Int_t position = TMath::Min((Int_t)fText->GetTextLength(), pos);
1692 TString newText(GetText());
1693 newText.Insert(position, text);
1694 SetText(newText.Data());
1703 void TGTextEntry::AppendText(
const char *text)
1705 InsertText(text, fText->GetTextLength());
1713 void TGTextEntry::RemoveText(Int_t start, Int_t end)
1715 Int_t pos = TMath::Min(start, end);
1716 Int_t len = TMath::Abs(end-start);
1717 TString newText(GetText());
1718 newText.Remove(pos, len);
1719 SetText(newText.Data());
1727 void TGTextEntry::SetFont(FontStruct_t font, Bool_t local)
1729 if (font == fFontStruct)
return;
1731 FontH_t v = gVirtualX->GetFontHandle(font);
1736 TGGC *gc =
new TGGC(fNormGC);
1737 fHasOwnFont = kTRUE;
1739 gc =
new TGGC(fSelGC);
1745 fClient->NeedRedraw(
this);
1752 void TGTextEntry::SetFont(
const char *fontName, Bool_t local)
1754 TGFont *font = fClient->GetFont(fontName);
1756 SetFont(font->GetFontStruct(), local);
1764 void TGTextEntry::SetFont(TGFont *font, Bool_t local)
1767 SetFont(font->GetFontStruct(), local);
1775 void TGTextEntry::SetTextColor(Pixel_t color, Bool_t local)
1778 TGGC *gc =
new TGGC(fNormGC);
1779 fHasOwnFont = kTRUE;
1783 fNormGC.SetForeground(color);
1784 fClient->NeedRedraw(
this);
1791 void TGTextEntry::SetTextColor(TColor *color, Bool_t local)
1794 SetTextColor(color->GetPixel(), local);
1801 FontStruct_t TGTextEntry::GetDefaultFontStruct()
1804 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
1805 return fgDefaultFont->GetFontStruct();
1811 const TGGC &TGTextEntry::GetDefaultGC()
1814 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
1815 return *fgDefaultGC;
1821 const TGGC &TGTextEntry::GetDefaultSelectedGC()
1823 if (!fgDefaultSelectedGC)
1824 fgDefaultSelectedGC = gClient->GetResourcePool()->GetSelectedGC();
1825 return *fgDefaultSelectedGC;
1831 const TGGC &TGTextEntry::GetDefaultSelectedBackgroundGC()
1833 if (!fgDefaultSelectedBackgroundGC)
1834 fgDefaultSelectedBackgroundGC = gClient->GetResourcePool()->GetSelectedBckgndGC();
1835 return *fgDefaultSelectedBackgroundGC;
1841 void TGTextEntry::SavePrimitive(std::ostream &out, Option_t *option )
1846 option = GetName()+5;
1847 TString parGC, parFont;
1850 parFont.Form(
"%s::GetDefaultFontStruct()",IsA()->GetName());
1853 parGC.Form(
"%s::GetDefaultGC()()",IsA()->GetName());
1855 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC.GetGC())) {
1856 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
1858 ufont->SavePrimitive(out, option);
1859 parFont.Form(
"ufont->GetFontStruct()");
1862 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC.GetGC());
1864 userGC->SavePrimitive(out, option);
1865 parGC.Form(
"uGC->GetGC()");
1869 if (fBackground != GetWhitePixel()) SaveUserColor(out, option);
1871 out <<
" TGTextEntry *";
1872 out << GetName() <<
" = new TGTextEntry(" << fParent->GetName()
1873 <<
", new TGTextBuffer(" << GetBuffer()->GetBufferLength() <<
")";
1875 if (fBackground == GetWhitePixel()) {
1876 if (GetOptions() == (kSunkenFrame | kDoubleBorder)) {
1877 if (fFontStruct == GetDefaultFontStruct()) {
1878 if (fNormGC() == GetDefaultGC()()) {
1879 if (fWidgetId == -1) {
1880 out <<
");" << std::endl;
1882 out <<
"," << fWidgetId <<
");" << std::endl;
1885 out <<
"," << fWidgetId <<
"," << parGC.Data() <<
");" << std::endl;
1888 out <<
"," << fWidgetId <<
"," << parGC.Data() <<
"," << parFont.Data()
1889 <<
");" << std::endl;
1892 out <<
"," << fWidgetId <<
"," << parGC.Data() <<
"," << parFont.Data()
1893 <<
"," << GetOptionString() <<
");" << std::endl;
1896 out <<
"," << fWidgetId <<
"," << parGC.Data() <<
"," << parFont.Data()
1897 <<
"," << GetOptionString() <<
",ucolor);" << std::endl;
1899 if (option && strstr(option,
"keep_names"))
1900 out <<
" " << GetName() <<
"->SetName(\"" << GetName() <<
"\");" << std::endl;
1902 out <<
" " << GetName() <<
"->SetMaxLength(" << GetMaxLength() <<
");" << std::endl;
1904 out <<
" " << GetName() <<
"->SetAlignment(";
1906 if (fAlignment == kTextLeft)
1907 out <<
"kTextLeft);" << std::endl;
1909 if (fAlignment == kTextRight)
1910 out <<
"kTextRight);" << std::endl;
1912 if (fAlignment == kTextCenterX)
1913 out <<
"kTextCenterX);" << std::endl;
1915 out <<
" " << GetName() <<
"->SetText(" << quote << GetText() << quote
1916 <<
");" << std::endl;
1918 out <<
" " << GetName() <<
"->Resize("<< GetWidth() <<
"," << GetName()
1919 <<
"->GetDefaultHeight());" << std::endl;
1921 if ((fDefWidth > 0) || (fDefHeight > 0)) {
1922 out <<
" " << GetName() <<
"->SetDefaultSize(";
1923 out << fDefWidth <<
"," << fDefHeight <<
");" << std::endl;
1927 TString tiptext = fTip->GetText()->GetString();
1928 tiptext.ReplaceAll(
"\n",
"\\n");
1930 out << GetName() <<
"->SetToolTipText(" << quote
1931 << tiptext << quote <<
");" << std::endl;