1
//------------------------------------------------------------------------
2
// TEXTBOX : Unix/FLTK Text messages
3
//------------------------------------------------------------------------
5
// GL-Friendly Node Builder (C) 2000-2007 Andrew Apted
7
// Based on 'BSP 2.3' by Colin Reed, Lee Killough and others.
9
// This program is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
//------------------------------------------------------------------------
21
// this includes everything we need
26
// TextBox Constructor
28
Guix_TextBox::Guix_TextBox(int x, int y, int w, int h) :
29
Fl_Multi_Browser(x, y, w, h)
31
// cancel the automatic 'begin' in Fl_Group constructor
32
// (it's an ancestor of Fl_Browser).
39
// the resize box in the lower right corner is a pain, it ends up
40
// covering the text box scroll button. Luckily when both scrollbars
41
// are active, FLTK leaves a square space in that corner and it
43
has_scrollbar(BOTH_ALWAYS);
51
Guix_TextBox::~Guix_TextBox()
57
void Guix_TextBox::AddMsg(const char *msg, Fl_Color col, // = FL_BLACK,
58
boolean_g bold) // = FALSE)
65
// setup formatting string
69
sprintf(buffer, "@C%d", col);
75
b_idx = strlen(buffer);
77
while ((r = strchr(msg, '\n')) != NULL)
79
strncpy(buffer+b_idx, msg, r - msg);
80
buffer[b_idx + r - msg] = 0;
84
// workaround for FLTK bug
85
strcpy(buffer+b_idx, " ");
94
strcpy(buffer+b_idx, msg);
98
// move browser to last line
104
void Guix_TextBox::AddHorizBar()
112
// move browser to last line
118
void Guix_TextBox::ClearLog()
124
boolean_g Guix_TextBox::SaveLog(const char *filename)
126
FILE *fp = fopen(filename, "w");
131
for (int y=1; y <= size(); y++)
133
const char *L_txt = text(y);
141
if (L_txt[0] == '@' && L_txt[1] == '-')
143
fprintf(fp, "--------------------------------");
144
fprintf(fp, "--------------------------------\n");
148
// remove any '@' formatting info
150
while (*L_txt == '@')
157
char fmt_ch = *L_txt++;
162
// uppercase formatting chars (e.g. @C) have an int argument
165
while (isdigit(*L_txt))
170
fprintf(fp, "%s\n", L_txt);
179
void Guix_TextBox::LockOut(boolean_g lock_it)
181
// Don't need to lock the text box. This routine is for
182
// completeness, e.g. in case some aspect of the text box should
183
// actually be locked.
187
//------------------------------------------------------------------------
192
void GUI_PrintMsg(const char *str, ...)
199
vsprintf(buffer, str, args);
202
// handle pre-windowing text (ShowOptions and friends)
205
printf("%s", buffer);
210
if (strncmp(buffer, "ATTENTION", 9) == 0)
211
guix_win->text_box->AddMsg(buffer, FL_RED, TRUE);
212
else if (strncmp(buffer, "Warning", 7) == 0)
213
guix_win->text_box->AddMsg(buffer, FL_RED);
215
guix_win->text_box->AddMsg(buffer);