30
30
* Version Creation Date: 7/1/91
34
34
* File Description:
35
35
* Vibrant edit text functions
38
38
* --------------------------------------------------------------------------
39
* $Log: vibtexts.c,v $
40
* Revision 6.33 2006/09/27 18:30:00 kans
41
* support for Int4 scroll bars for switching between text and doc views in Sequin (CB)
43
* Revision 6.32 2006/09/14 19:18:29 ivanov
44
* Rollback last changes. All missed defines added to corelib/ncbiwin.h.
46
* Revision 6.31 2006/09/14 18:05:45 ivanov
47
* Fixed compilation errors on MS Windows
49
* Revision 6.30 2006/09/14 14:45:39 kans
50
* changes for 64-bit Windows (GC) plus a few CodeWarrior complaints (JK)
52
* Revision 6.29 2005/07/18 15:15:18 kans
53
* fixed minor xcode compiler warnings
55
* Revision 6.28 2004/07/19 13:36:43 bollin
56
* replaced obsolete XmFontListCreate function to get rid of run-time warnings
58
* Revision 6.27 2004/06/24 15:34:48 bollin
59
* added lines from Yoon Choi to make ctrl-A select all text in TextMode in
62
* Revision 6.26 2004/03/17 16:09:14 sinyakov
63
* WIN_MSWIN: fixed text box activation and text selection logic,
64
* do not reset currentText when text window loses focus (to match Motif version),
65
* removed scroll text size limit,
66
* in Nlm_SelectAText(): scroll selection into view for scroll text,
67
* in Nlm_TextGainFocus(), when focus changes to a single-line edit box,
68
* do not highlight all text, instead just set the cursor pos to beginning,
69
* in MyCls_OnChar(), multiline edit boxes accept tabs
70
* as input characters and not as focus change commands.
72
* Revision 6.25 2004/02/23 16:36:52 sinyakov
73
* Use Int4 instead of Int2 for cursor position and text selection in text boxes
75
* Revision 6.24 2004/02/17 16:01:15 bollin
76
* implemented Nlm_SetScrollTextOffset for Motif
78
* Revision 6.23 2004/02/12 20:29:09 kans
79
* put ifdef WIN_MOTIF wrapper around Nlm_KeepCrNlTextFieldCallback
81
* Revision 6.22 2004/02/12 20:05:10 bazhin
82
* Added callback function "Nlm_SetKeepCrNlTextFieldCallback(Nlm_TexT t)",
83
* which allows to copy-paste texts from multiple columns to single string.
85
* Revision 6.21 2004/02/09 17:46:27 bollin
86
* added fix from Yoon Choi for copy-paste from Windows clipboard into Unix application
88
* Revision 6.20 2004/02/06 19:27:33 bollin
89
* Use PostMessage to communicate with scrolling function on TextViewer window
91
* Revision 6.19 2004/02/05 16:25:05 kans
92
* revert to Nlm_GetTextVScrollBar and Nlm_GetTextHScrollBar being static, implement setOffset and getOffset for scroll text, since Windows scroll text has its own scroll bar
94
* Revision 6.18 2004/02/04 15:21:03 kans
95
* make GetTextVScrollBar and GetTextHScrollBar extern, to add search function to general text viewer
97
* Revision 6.17 2003/11/17 17:03:30 kans
98
* changed C++ style comments to C comments
100
* Revision 6.16 2003/11/03 21:51:34 sinyakov
101
* WIN_MSWIN: bugfix: strlen(title) moved out of loop condition
103
* Revision 6.15 2003/10/29 19:10:08 bazhin
104
* Added function Nlm_SetTextColor(Nlm_TexT t, Nlm_Uint4 r, Nlm_Uint4 g,
107
* Revision 6.14 2003/07/30 13:51:42 johnson
108
* MSWIN: multi-line text boxes now respond to 'enter' key
110
* Revision 6.13 2003/03/28 21:27:18 rsmith
111
* on Mac OS took out ClearCurrentScrap after Cut/Copy. It only erased whatever was copied.
113
* Revision 6.12 2003/01/07 15:08:11 shomrat
114
* Change condition in for loop in Nlm_SetScrollText
116
* Revision 6.11 2002/12/04 22:35:11 johnson
117
* WIN_MSWIN: replace UNIX '\n' with DOS "\r\n" in Nlm_SetScrollText
119
* Revision 6.10 2001/09/10 17:58:28 bazhin
120
* Removed odd lines from SetTextCursorBlinkRate() function.
122
* Revision 6.9 2001/09/10 17:34:10 bazhin
123
* Added function Nlm_SetTextCursorBlinkRate(Nlm_TexT t, Nlm_Int2 msec).
125
* Revision 6.8 2001/05/14 20:29:04 juran
126
* Redesign Mac clipboard support.
128
* Revision 6.7 2000/05/02 22:02:15 vakatov
129
* Nlm_TextCallback(): get rid of an extra condition
131
* Revision 6.6 2000/03/31 19:20:03 thiessen
134
* Revision 6.5 2000/02/07 20:17:36 lewisg
135
* minor bug fixes, use gui font for win32
137
* Revision 6.4 1998/07/02 18:24:35 vakatov
138
* Cleaned the code & made it pass through the C++ compilation
140
* Revision 6.3 1997/12/19 18:01:45 vakatov
141
* [X11,MSWIN] When pasting into a single-line text field, replace all
142
* non-printable characters by spaces
144
* Revision 6.2 1997/11/26 21:30:42 vakatov
145
* Fixed errors and warnings issued by C and C++ (GNU and Sun) compilers
147
* Revision 6.1 1997/10/18 23:30:16 kans
148
* implemented Nlm_GetTextCursorPos (DV)
150
* Revision 6.0 1997/08/25 18:57:44 madden
151
* Revision changed to 6.0
153
* Revision 5.22 1997/08/07 16:46:39 vakatov
154
* [WIN_MOTIF] Nlm_PasswordCallback() -- process <DEL> at the first text pos
156
* Revision 5.21 1997/08/07 13:38:32 kans
157
* password text does action callback on delete (Mac)
159
* Revision 5.20 1997/08/05 16:42:26 kans
160
* allowTextCallback not declared in Mac, so ifdefs changed in Nlm_SetTextCursorPos
162
* Revision 5.19 1997/08/04 14:15:14 vakatov
163
* Added Nlm_SetTextCursorPos() function
165
* Revision 5.18 1997/07/21 18:49:09 vakatov
166
* [WIN_MAC] SetPasswordText() -- moved "r" and "GetRect()"(sorry, missed
167
* that!) back to the if(Visible... scope
169
* Revision 5.17 1997/07/21 18:39:42 kans
170
* SetPasswordText r in Mac version at top scope
172
* Revision 5.16 1997/07/21 18:24:36 vakatov
173
* SetPasswordText() -- show all symbols as '*'
175
* Revision 5.15 1997/07/17 15:31:47 vakatov
176
* [WIN_MSWIN] Emulate non-editable text(crack WM_CHAR event in TextProc
177
* as the WinSDK's Edit_SetReadOnly lead to invalidation bug for ScrollText)
179
* Revision 5.14 1997/07/16 13:47:20 kans
180
* non-editable scroll text now scrolls on Mac
182
* Revision 5.12 1997/07/13 23:03:05 kans
183
* ScrollText height is in stdLineHeight units
185
* Revision 5.11 1997/07/08 13:42:06 kans
186
* ttool to rtool fix in Nlm_DrawScrollText/DCLAP
188
* Revision 5.10 1997/06/24 21:30:37 kans
189
* implemented SetTextEditable on Mac
191
* Revision 5.9 1997/06/24 19:10:00 vakatov
192
* Nlm_ScrollText() -- calculate the text box limits using the systemFont
193
* (not the current font!) dimensions
195
* Revision 5.8 1997/06/23 21:21:05 vakatov
196
* Added Nlm_SetTextEditable() function to allow/prohibit text editing
197
* [WIN_MOTIF] Made text widgets to fit the specified number of lines
199
* Revision 5.7 1997/04/25 16:14:06 vakatov
200
* [WIN_MOTIF,WIN_MSWIN] Catch and render(DoSendFocus) navigation key events
201
* Extensive code cleaning and type casting
203
* Revision 5.6 1997/02/12 17:47:28 vakatov
204
* [WIN_MOTIF] Do not reset selection when activating a window containing
205
* a text or when the text is empty
207
* Revision 5.5 1997/01/29 17:53:59 kans
208
* minor changes due to StringNCpy_0 change
210
* Revision 5.4 1997/01/29 16:41:22 kans
213
* Revision 5.3 1996/07/23 21:07:10 epstein
214
* Vakatov/Epstein avoid trying to clear an area on an unrealized window
216
* Revision 5.2 1996/06/18 15:44:56 vakatov
217
* Do not assign last (maxsize-1) symbol of output buffer
218
* in Nlm_GetScrollText() and Nlm_GetDialogText() to '\0'.
220
* Revision 5.1 1996/06/17 19:28:17 vakatov
221
* [WIN_MOTIF] Positioning of scrolled text postponed until its realization
223
* Revision 4.9 1996/05/08 20:42:52 vakatov
224
* [WIN_MOTIF] Nlm_PasswordCallback() function -- rewritten to avoid stack
225
* corruption on the case of too long(>30 symbols) user input and
226
* to make the password text field more convenient to edit;
227
* [ALL] Nlm_GetPasswordLength() function added (other than
228
* Nlm_TextLength()); a lot of other tiny changes and corrections
230
* Revision 4.8 1996/05/08 13:43:47 vakatov
231
* [WIN_MOTIF] Modified Nlm_SetPasswordText() to reset the password
233
* Revision 4.7 1996/05/03 17:02:08 kans
234
* added a cast to SelectText call
236
* Revision 4.6 1996/03/02 22:36:38 kans
237
* reduction of X traffic (DV)
239
* Revision 4.5 1996/02/13 17:24:07 kans
240
* accelerated set position prior to realization (Denis Vakatov)
242
* Revision 4.4 1995/11/27 16:04:00 kans
243
* ScrollText now handles killfocus and setfocus messages (VL)
245
* Revision 4.3 1995/11/27 15:13:41 kans
246
* allow select and deselect callbacks for DialogText and ScrollText (VL)
248
* Revision 4.2 1995/11/08 23:30:31 kans
249
* removed edit block fields, which belong in the application
251
* Revision 4.1 1995/10/10 15:51:53 kans
252
* fully implemented scroll text resizing
254
* Revision 2.52 1995/07/14 17:48:26 kans
255
* forces dialog, hidden text to use systemFont (AS)
257
* Revision 2.51 1995/05/20 18:27:38 kans
258
* corrected accidental prevention of passing returns to other objects
261
40
* ==========================================================================
942
static Nlm_Boolean Nlm_TextKey (Nlm_GraphiC t, Nlm_Char ch)
950
if (! Nlm_GetTextEditable ((Nlm_TexT) t)) return FALSE;
951
act = Nlm_GetActive ((Nlm_TexT) t);
952
if (act && ! Nlm_cmmdKey) {
954
h = Nlm_GetTextHandle ((Nlm_TexT) t);
955
Nlm_ScrollToInsertionPoint ((Nlm_TexT) t);
958
Nlm_UpdateScrollBar ((Nlm_TexT) t);
959
Nlm_ScrollToInsertionPoint ((Nlm_TexT) t);
961
Nlm_SetChanged ((Nlm_TexT) t, TRUE);
968
static Nlm_Boolean Nlm_DialogKey (Nlm_GraphiC t, Nlm_Char ch)
975
if (! Nlm_GetTextEditable ((Nlm_TexT) t)) return FALSE;
976
act = Nlm_GetActive ((Nlm_TexT) t);
977
if (act && ! Nlm_cmmdKey) {
978
if (ch == '\t' && Nlm_IsHiddenOrSpecialText ((Nlm_TexT) t)) {
979
Nlm_DoTabCallback ((Nlm_TexT) t);
981
} else if (ch == '\t') {
982
Nlm_DoSendFocus (t, ch);
984
} else if (ch == '\n' || ch == '\r' || ch == '\3') {
985
rsult = Nlm_DoReturnCallback ((Nlm_TexT) t);
986
} else if (ch != '\0') {
987
rsult = Nlm_TextKey (t, ch);
993
static Nlm_Boolean Nlm_PasswordKey (Nlm_GraphiC t, Nlm_Char ch)
1000
Nlm_Char password [MAX_PASSWORD];
1008
if (! Nlm_GetTextEditable ((Nlm_TexT) t)) return FALSE;
1009
act = Nlm_GetActive ((Nlm_TexT) t);
1010
if (act && ! Nlm_cmmdKey) {
1012
Nlm_DoSendFocus (t, ch);
1014
} else if (ch == '\n' || ch == '\r' || ch == '\3') {
1015
} else if (ch == '\b') {
1017
Nlm_SetPassword ((Nlm_TexT) t, "");
1018
h = Nlm_GetTextHandle ((Nlm_TexT) t);
1021
hp = (TEPtr) *((Handle) h);
1022
selEnd = hp->teLength;
1023
HUnlock ((Handle) h);
1024
Nlm_GetRect (t, &r);
1025
if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1026
TESetSelect (selStart, selEnd, h);
1028
Nlm_InsetRect (&r, 2, 2);
1030
Nlm_RecTToRectTool (&r, &rtool);
1031
TEUpdate (&rtool, h);
1034
} else if (ch != '\0') {
1035
Nlm_GetPassword ((Nlm_TexT) t, password, sizeof (password));
1036
len = (Nlm_Int2) Nlm_StringLen (password);
1037
if (len < sizeof (password) - 2) {
1038
password [len] = ch;
1039
password [len + 1] = '\0';
1041
Nlm_SetPassword ((Nlm_TexT) t, password);
1042
rsult = Nlm_TextKey (t, '*');
1048
768
static void Nlm_DrawDialogText (Nlm_GraphiC t)
918
static Nlm_Boolean Nlm_TextKey (Nlm_GraphiC t, Nlm_Char ch)
926
if (! Nlm_GetTextEditable ((Nlm_TexT) t)) return FALSE;
927
act = Nlm_GetActive ((Nlm_TexT) t);
928
if (act && ! Nlm_cmmdKey) {
930
h = Nlm_GetTextHandle ((Nlm_TexT) t);
931
#ifdef WIN_MAC_QUARTZ
932
TXNKeyDown(h, &Nlm_currentEvent );
934
Nlm_ScrollToInsertionPoint ((Nlm_TexT) t);
937
Nlm_UpdateScrollBar ((Nlm_TexT) t);
938
Nlm_ScrollToInsertionPoint ((Nlm_TexT) t);
941
Nlm_SetChanged ((Nlm_TexT) t, TRUE);
948
static Nlm_Boolean Nlm_DialogKey (Nlm_GraphiC t, Nlm_Char ch)
955
if (! Nlm_GetTextEditable ((Nlm_TexT) t)) return FALSE;
956
act = Nlm_GetActive ((Nlm_TexT) t);
957
if (act && ! Nlm_cmmdKey) {
958
if (ch == '\t' && Nlm_IsHiddenOrSpecialText ((Nlm_TexT) t)) {
959
Nlm_DoTabCallback ((Nlm_TexT) t);
961
} else if (ch == '\t') {
962
Nlm_DoSendFocus (t, ch);
964
} else if (ch == '\n' || ch == '\r' || ch == '\3') {
965
rsult = Nlm_DoReturnCallback ((Nlm_TexT) t);
966
} else if (ch != '\0') {
967
rsult = Nlm_TextKey (t, ch);
973
#ifndef WIN_MAC_QUARTZ
974
static Nlm_Boolean Nlm_PasswordKey (Nlm_GraphiC t, Nlm_Char ch)
981
Nlm_Char password [MAX_PASSWORD];
989
if (! Nlm_GetTextEditable ((Nlm_TexT) t)) return FALSE;
990
act = Nlm_GetActive ((Nlm_TexT) t);
991
if (act && ! Nlm_cmmdKey) {
993
Nlm_DoSendFocus (t, ch);
995
} else if (ch == '\n' || ch == '\r' || ch == '\3') {
996
} else if (ch == '\b') {
998
Nlm_SetPassword ((Nlm_TexT) t, "");
999
h = Nlm_GetTextHandle ((Nlm_TexT) t);
1002
hp = (TEPtr) *((Handle) h);
1003
selEnd = hp->teLength;
1004
HUnlock ((Handle) h);
1005
Nlm_GetRect (t, &r);
1006
if (Nlm_GetVisible (t) && Nlm_GetAllParentsVisible (t)) {
1007
TESetSelect (selStart, selEnd, h);
1009
Nlm_InsetRect (&r, 2, 2);
1011
Nlm_RecTToRectTool (&r, &rtool);
1012
TEUpdate (&rtool, h);
1015
} else if (ch != '\0') {
1016
Nlm_GetPassword ((Nlm_TexT) t, password, sizeof (password));
1017
len = (Nlm_Int2) Nlm_StringLen (password);
1018
if (len < sizeof (password) - 2) {
1019
password [len] = ch;
1020
password [len + 1] = '\0';
1022
Nlm_SetPassword ((Nlm_TexT) t, password);
1023
rsult = Nlm_TextKey (t, '*');
1028
#endif /* ! WIN_MAC_QUARTZ */
1182
1030
static Nlm_Boolean Nlm_IdleText (Nlm_GraphiC t, Nlm_PoinT pt)
1184
1032
{ Nlm_TextTool h;
1186
1034
if (Nlm_GetVisible (t) && Nlm_GetEnabled (t) && Nlm_GetActive ((Nlm_TexT) t)) {
1187
1035
h = Nlm_GetTextHandle ((Nlm_TexT) t);
1036
#ifdef WIN_MAC_QUARTZ