-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextWindow.cc
117 lines (87 loc) · 3.09 KB
/
TextWindow.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
-------------------------------------------------------------------------
OBJECT NAME: TextWindow.cc
FULL NAME:
DESCRIPTION:
COPYRIGHT: University Corporation for Atmospheric Research, 1998-2001
-------------------------------------------------------------------------
*/
#include "TextWindow.h"
#include <Xm/Frame.h>
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#include <Xm/Text.h>
#include <Xm/TextF.h>
/* -------------------------------------------------------------------- */
TextWindow::TextWindow(const Widget parent, const char name[]) : WinForm(parent, name, Form)
{
Cardinal n;
Arg args[8];
Widget drFrame, drRC, b[4];
char space[32];
n = 0;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
drFrame = XmCreateFrame(Window(), (char *)"buttonFrame", args, n);
XtManageChild(drFrame);
n = 0;
drRC = XmCreateRowColumn(drFrame, (char *)"buttonRC", args, n);
XtManageChild(drRC);
n = 0;
b[0] = XmCreatePushButton(drRC, (char *)"dismissButton", args, n);
b[1] = XmCreatePushButton(drRC, (char *)"printButton", args, n);
b[2] = XmCreatePushButton(drRC, (char *)"saveButton", args, n);
b[3] = XmCreatePushButton(drRC, (char *)"searchButton", args, n);
XtManageChildren(b, 4);
n = 0;
searchTxt = XmCreateTextField(drRC, (char *)"searchTxt", args, n);
XtManageChild(searchTxt);
n = 0;
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNtopWidget, drFrame); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
strcpy(space, name); strcat(space, (char *)"Text");
text = XmCreateScrolledText(Window(), space, args, n);
XtManageChild(text);
XtAddCallback(b[0], XmNactivateCallback, DismissText, this);
XtAddCallback(b[1], XmNactivateCallback, PrintText, text);
XtAddCallback(b[2], XmNactivateCallback, SaveText, text);
XtAddCallback(b[3], XmNactivateCallback, SearchText, this);
} /* END CONSTRUCTOR */
/* -------------------------------------------------------------------- */
void TextWindow::Search()
{
char *target;
int len;
bool found;
XmTextPosition searchPos;
static XmTextPosition currPos = 0;
len = XmTextGetLastPosition(text);
XmTextSetHighlight(text, 0, len, XmHIGHLIGHT_NORMAL);
target = XmTextFieldGetString(searchTxt);
if ((len = strlen(target)) == 0)
{
XtFree(target);
return;
}
currPos = 0;
found = XmTextFindString(text, currPos, target, XmTEXT_FORWARD, &searchPos);
if (found)
XmTextSetTopCharacter(text, searchPos);
while (found)
{
XmTextSetHighlight(text, searchPos, searchPos+len, XmHIGHLIGHT_SELECTED);
currPos = searchPos + 1;
found = XmTextFindString(text, currPos, target, XmTEXT_FORWARD, &searchPos);
}
XtFree(target);
} /* END SEARCH */
/* -------------------------------------------------------------------- */
TextWindow::~TextWindow()
{
Clear();
}
/* END TEXTWINDOW.CC */