1
//------------------------------------------------------------------------
2
// BOOK : Unix/FLTK Manual Code
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
25
Guix_Book *guix_book_win;
28
static void book_quit_CB(Fl_Widget *w, void *data)
31
guix_book_win->want_quit = TRUE;
34
static void book_contents_CB(Fl_Widget *w, void *data)
37
guix_book_win->want_page = 0;
40
static void book_prev_CB(Fl_Widget *w, void *data)
43
guix_book_win->want_page = guix_book_win->cur_page - 1;
46
static void book_next_CB(Fl_Widget *w, void *data)
49
guix_book_win->want_page = guix_book_win->cur_page + 1;
52
static void book_selector_CB(Fl_Widget *w, void *data)
55
guix_book_win->FollowLink(guix_book_win->browser->value() - 1);
59
//------------------------------------------------------------------------
64
Guix_Book::Guix_Book() : Fl_Window(guix_prefs.manual_w,
65
guix_prefs.manual_h, "glBSP Manual")
67
// cancel the automatic 'begin' in Fl_Group constructor
70
size_range(MANUAL_WINDOW_MIN_W, MANUAL_WINDOW_MIN_H);
71
position(guix_prefs.manual_x, guix_prefs.manual_y);
72
color(MAIN_BG_COLOR, MAIN_BG_COLOR);
74
// allow manual closing of window
75
callback((Fl_Callback *) book_quit_CB);
78
want_page = BOOK_NO_PAGE;
79
want_reformat = FALSE;
82
// create buttons in top row
84
group = new Fl_Group(0, h() - 34, w(), 34);
90
contents = new Fl_Button(CX, CY, 96, 26, "&Contents");
91
contents->box(FL_ROUND_UP_BOX);
92
contents->callback((Fl_Callback *) book_contents_CB);
97
prev = new Fl_Button(CX, CY, 96, 26, "<< &Prev");
98
prev->box(FL_ROUND_UP_BOX);
99
prev->callback((Fl_Callback *) book_prev_CB);
104
next = new Fl_Button(CX, CY, 96, 26, "&Next >>");
105
next->box(FL_ROUND_UP_BOX);
106
next->callback((Fl_Callback *) book_next_CB);
111
quit = new Fl_Button(w() - 96 - 24, CY, 96, 26, "Close");
112
quit->box(FL_ROUND_UP_BOX);
113
quit->callback((Fl_Callback *) book_quit_CB);
116
Fl_Box *invis_2 = new Fl_Box(CX, 0, w() - 96 - 10 - CX, 20);
119
group->resizable(invis_2);
121
// create the browser
123
browser = new Fl_Hold_Browser(0, 0, w(), h() - 34);
124
browser->callback((Fl_Callback *) book_selector_CB);
133
// read initial pos (same logic as in Guix_MainWin)
136
init_x = x(); init_y = y();
137
init_w = w(); init_h = h();
144
Guix_Book::~Guix_Book()
146
// update preferences if user moved the window
147
if (x() != init_x || y() != init_y)
149
guix_prefs.manual_x = x();
150
guix_prefs.manual_y = y();
153
if (w() != init_w || h() != init_h)
155
guix_prefs.manual_w = w();
156
guix_prefs.manual_h = h();
159
guix_prefs.manual_page = cur_page;
163
void Guix_Book::resize(int X, int Y, int W, int H)
165
if (W != w() || H != h())
166
want_reformat = TRUE;
168
Fl_Window::resize(X, Y, W, H);
172
int Guix_Book::PageCount()
174
// we don't need anything super efficient
178
for (count=0; book_pages[count].text; count++)
185
void Guix_Book::LoadPage(int new_num)
187
if (new_num < 0 || new_num >= PageCount())
192
want_page = BOOK_NO_PAGE;
193
want_reformat = FALSE;
200
if (cur_page == PageCount() - 1)
205
// -- create browser text --
210
const char ** lines = book_pages[cur_page].text;
214
for (i=0; lines[i]; i++)
216
ParaAddLine(lines[i]);
221
browser->position(0);
225
void Guix_Book::FollowLink(int line)
233
const char * L = book_pages[cur_page].text[line];
235
if (L[0] == '#' && L[1] == 'L')
237
want_page = (L[2] - '0') * 10 + (L[3] - '0');
241
// for lines without links, the best we can do is just clear the
249
void Guix_Book::Update()
251
if (want_page != BOOK_NO_PAGE)
253
else if (want_reformat)
262
void Guix_Book::ParaStart()
264
in_paragraph = FALSE;
268
void Guix_Book::ParaEnd()
270
if (in_paragraph && para_buf[0] != 0)
272
browser->add(para_buf);
275
in_paragraph = FALSE;
279
void Guix_Book::ParaAddWord(const char *word)
281
// set current font for fl_width()
282
fl_font(browser->textfont(), browser->textsize());
285
if (para_buf[0] != 0 && (fl_width(para_buf) + fl_width(' ') +
286
fl_width(word) > para_width))
288
browser->add(para_buf);
293
if (para_buf[0] == 0)
295
// prefix with spaces to indent paragraph
296
int count = major_indent + (first_line ? 0 : minor_indent);
300
for (count--; count >= 0; count--)
301
para_buf[count] = ' ';
304
strcat(para_buf, " ");
306
strcat(para_buf, word);
310
void Guix_Book::ParaAddLine(const char *line)
312
if (line[0] == 0 || line[0] == '#' || line[0] == '@')
315
if (line[0] == '#' && line[1] == 'L')
317
browser->add(line + 4);
323
if (! (line[0] == '#' && line[1] == 'P'))
329
major_indent = (line[2] - '0') * 6 + 1;
330
minor_indent = (line[3] - '0');
338
para_width = browser->w() - 24 - (int)fl_width(' ') * major_indent;
341
// OK, we must be in paragraph mode here
345
while (isspace(*line))
354
while (*line && word_len < 98)
357
// '#-' : non-break space.
358
// '. ' : add a non-break space after dot
360
if (line[0] == '#' && line[1] == '-')
362
word_buf[word_len++] = ' ';
366
else if (line[0] == '.' && line[1] == ' ')
368
word_buf[word_len++] = '.';
369
word_buf[word_len++] = ' ';
370
word_buf[word_len++] = ' ';
378
word_buf[word_len++] = *line++;
381
word_buf[word_len] = 0;
383
ParaAddWord(word_buf);
388
//------------------------------------------------------------------------
391
Guix_License *guix_lic_win;
393
static void license_quit_CB(Fl_Widget *w, void *data)
396
guix_lic_win->want_quit = TRUE;
400
// License Constructor
402
Guix_License::Guix_License() : Fl_Window(guix_prefs.manual_w,
403
guix_prefs.manual_h, "glBSP License")
405
// cancel the automatic 'begin' in Fl_Group constructor
408
size_range(MANUAL_WINDOW_MIN_W, MANUAL_WINDOW_MIN_H);
409
position(guix_prefs.manual_x, guix_prefs.manual_y);
410
color(MAIN_BG_COLOR, MAIN_BG_COLOR);
412
// allow manual closing of window
413
callback((Fl_Callback *) license_quit_CB);
417
// create close button in bottom row
419
Fl_Box *invis_1 = new Fl_Box(0, 0, 30, 30);
422
group = new Fl_Group(0, h() - 34, w(), 34);
423
group->resizable(invis_1);
426
quit = new Fl_Button(w() - 96 - 24, h() - 30, 96, 26, "Close");
427
quit->box(FL_ROUND_UP_BOX);
428
quit->callback((Fl_Callback *) license_quit_CB);
431
// create the browser
435
browser = new Fl_Browser(0, 0, w(), h() - 34);
437
for (i=0; license_text[i]; i++)
438
browser->add(license_text[i]);
440
browser->position(0);
449
// read initial pos (same logic as in Guix_MainWin)
452
init_x = x(); init_y = y();
453
init_w = w(); init_h = h();
458
// License Destructor
460
Guix_License::~Guix_License()
462
// update preferences if user moved the window
463
if (x() != init_x || y() != init_y)
465
guix_prefs.manual_x = x();
466
guix_prefs.manual_y = y();
469
if (w() != init_w || h() != init_h)
471
guix_prefs.manual_w = w();
472
guix_prefs.manual_h = h();