1
//------------------------------------------------------------------------
2
// TEXTBOX : Unix/FLTK Text messages
3
//------------------------------------------------------------------------
5
// GL-Friendly Node Builder (C) 2000-2005 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
27
#error GLBSP_GUI should be defined when compiling this file
32
// TextBox Constructor
34
Guix_TextBox::Guix_TextBox(int x, int y, int w, int h) :
35
Fl_Multi_Browser(x, y, w, h)
37
// cancel the automatic 'begin' in Fl_Group constructor
38
// (it's an ancestor of Fl_Browser).
45
// the resize box in the lower right corner is a pain, it ends up
46
// covering the text box scroll button. Luckily when both scrollbars
47
// are active, FLTK leaves a square space in that corner and it
49
has_scrollbar(BOTH_ALWAYS);
57
Guix_TextBox::~Guix_TextBox()
63
void Guix_TextBox::AddMsg(const char *msg, Fl_Color col, // = FL_BLACK,
64
boolean_g bold) // = FALSE)
71
// setup formatting string
75
sprintf(buffer, "@C%d", col);
81
b_idx = strlen(buffer);
83
while ((r = strchr(msg, '\n')) != NULL)
85
strncpy(buffer+b_idx, msg, r - msg);
86
buffer[b_idx + r - msg] = 0;
90
// workaround for FLTK bug
91
strcpy(buffer+b_idx, " ");
100
strcpy(buffer+b_idx, msg);
104
// move browser to last line
110
void Guix_TextBox::AddHorizBar()
118
// move browser to last line
124
void Guix_TextBox::ClearLog()
130
boolean_g Guix_TextBox::SaveLog(const char *filename)
132
FILE *fp = fopen(filename, "w");
137
for (int y=1; y <= size(); y++)
139
const char *L_txt = text(y);
147
if (L_txt[0] == '@' && L_txt[1] == '-')
149
fprintf(fp, "--------------------------------");
150
fprintf(fp, "--------------------------------\n");
154
// remove any '@' formatting info
156
while (*L_txt == '@')
163
char fmt_ch = *L_txt++;
168
// uppercase formatting chars (e.g. @C) have an int argument
171
while (isdigit(*L_txt))
176
fprintf(fp, "%s\n", L_txt);
185
void Guix_TextBox::LockOut(boolean_g lock_it)
187
// Don't need to lock the text box. This routine is for
188
// completeness, e.g. in case some aspect of the text box should
189
// actually be locked.
193
//------------------------------------------------------------------------
198
void GUI_PrintMsg(const char *str, ...)
205
vsprintf(buffer, str, args);
208
// handle pre-windowing text (ShowOptions and friends)
211
printf("%s", buffer);
216
if (strncmp(buffer, "ATTENTION", 9) == 0)
217
guix_win->text_box->AddMsg(buffer, FL_RED, TRUE);
218
else if (strncmp(buffer, "Warning", 7) == 0)
219
guix_win->text_box->AddMsg(buffer, FL_RED);
221
guix_win->text_box->AddMsg(buffer);