~ubuntu-branches/ubuntu/trusty/glbsp/trusty

« back to all changes in this revision

Viewing changes to fltk/textbox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Darren Salt
  • Date: 2008-01-30 13:33:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080130133349-kgojg33vyiu8xbvp
Tags: 2.24-1
* New upstream release.
* Bumped the lib soname and the library package name due to one silly
  little binary incompatibility caused by changes in an exported struct.
  (Safe; nothing else currently in the archive has ever used libglbsp2.)
* Removed my patches since they're all applied upstream.
* Updated the list of documentation files.
* Build-time changes:
  - Switched from dh_movefiles to dh_install.
  - Updated my makefile to cope with upstream changes.
  - Corrected for debian-rules-ignores-make-clean-error.
  - Corrected for substvar-source-version-is-deprecated.
  - Link libglbsp, rather than glbsp, with libm and libz.
* Fixed shlibdeps. (Closes: #460387)
* Bumped standards version to 3.7.3 (no other changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//------------------------------------------------------------------------
2
 
// TEXTBOX : Unix/FLTK Text messages
3
 
//------------------------------------------------------------------------
4
 
//
5
 
//  GL-Friendly Node Builder (C) 2000-2005 Andrew Apted
6
 
//
7
 
//  Based on 'BSP 2.3' by Colin Reed, Lee Killough and others.
8
 
//
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.
13
 
//
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.
18
 
//
19
 
//------------------------------------------------------------------------
20
 
 
21
 
// this includes everything we need
22
 
#include "local.h"
23
 
 
24
 
 
25
 
// consistency check
26
 
#ifndef GLBSP_GUI
27
 
#error GLBSP_GUI should be defined when compiling this file
28
 
#endif
29
 
 
30
 
 
31
 
//
32
 
// TextBox Constructor
33
 
//
34
 
Guix_TextBox::Guix_TextBox(int x, int y, int w, int h) :
35
 
    Fl_Multi_Browser(x, y, w, h)
36
 
{
37
 
  // cancel the automatic 'begin' in Fl_Group constructor
38
 
  // (it's an ancestor of Fl_Browser).
39
 
  end();
40
 
 
41
 
  textfont(FL_COURIER);
42
 
  textsize(14);
43
 
 
44
 
#ifdef MACOSX
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
48
 
  // fits in nicely.
49
 
  has_scrollbar(BOTH_ALWAYS);
50
 
#endif
51
 
}
52
 
 
53
 
 
54
 
//
55
 
// TextBox Destructor
56
 
//
57
 
Guix_TextBox::~Guix_TextBox()
58
 
{
59
 
  // nothing to do
60
 
}
61
 
 
62
 
 
63
 
void Guix_TextBox::AddMsg(const char *msg, Fl_Color col, // = FL_BLACK,
64
 
    boolean_g bold) // = FALSE)
65
 
{
66
 
  const char *r;
67
 
 
68
 
  char buffer[2048];
69
 
  int b_idx;
70
 
 
71
 
  // setup formatting string
72
 
  buffer[0] = 0;
73
 
 
74
 
  if (col != FL_BLACK)
75
 
    sprintf(buffer, "@C%d", col);
76
 
 
77
 
  if (bold)
78
 
    strcat(buffer, "@b");
79
 
  
80
 
  strcat(buffer, "@.");
81
 
  b_idx = strlen(buffer);
82
 
 
83
 
  while ((r = strchr(msg, '\n')) != NULL)
84
 
  {
85
 
    strncpy(buffer+b_idx, msg, r - msg);
86
 
    buffer[b_idx + r - msg] = 0;
87
 
 
88
 
    if (r - msg == 0)
89
 
    {
90
 
      // workaround for FLTK bug
91
 
      strcpy(buffer+b_idx, " ");
92
 
    }
93
 
 
94
 
    add(buffer);
95
 
    msg = r+1;
96
 
  }
97
 
 
98
 
  if (strlen(msg) > 0)
99
 
  {
100
 
    strcpy(buffer+b_idx, msg);
101
 
    add(buffer);
102
 
  }
103
 
 
104
 
  // move browser to last line
105
 
  if (size() > 0)
106
 
    bottomline(size());
107
 
}
108
 
 
109
 
 
110
 
void Guix_TextBox::AddHorizBar()
111
 
{
112
 
  add(" ");
113
 
  add(" ");
114
 
  add("@-");
115
 
  add(" ");
116
 
  add(" ");
117
 
 
118
 
  // move browser to last line
119
 
  if (size() > 0)
120
 
    bottomline(size());
121
 
}
122
 
 
123
 
 
124
 
void Guix_TextBox::ClearLog()
125
 
{
126
 
  clear();
127
 
}
128
 
 
129
 
 
130
 
boolean_g Guix_TextBox::SaveLog(const char *filename)
131
 
{
132
 
  FILE *fp = fopen(filename, "w");
133
 
 
134
 
  if (! fp)
135
 
    return FALSE;
136
 
 
137
 
  for (int y=1; y <= size(); y++)
138
 
  {
139
 
    const char *L_txt = text(y);
140
 
 
141
 
    if (! L_txt)
142
 
    {
143
 
      fprintf(fp, "\n");
144
 
      continue;
145
 
    }
146
 
    
147
 
    if (L_txt[0] == '@' && L_txt[1] == '-')
148
 
    {
149
 
      fprintf(fp, "--------------------------------");
150
 
      fprintf(fp, "--------------------------------\n");
151
 
      continue;
152
 
    }
153
 
 
154
 
    // remove any '@' formatting info
155
 
 
156
 
    while (*L_txt == '@')
157
 
    {
158
 
      L_txt++;
159
 
      
160
 
      if (*L_txt == 0)
161
 
        break;
162
 
 
163
 
      char fmt_ch = *L_txt++;
164
 
 
165
 
      if (fmt_ch == '.')
166
 
        break;
167
 
 
168
 
      // uppercase formatting chars (e.g. @C) have an int argument
169
 
      if (isupper(fmt_ch))
170
 
      {
171
 
        while (isdigit(*L_txt))
172
 
          L_txt++;
173
 
      }
174
 
    }
175
 
 
176
 
    fprintf(fp, "%s\n", L_txt);
177
 
  }
178
 
  
179
 
  fclose(fp);
180
 
 
181
 
  return TRUE;
182
 
}
183
 
 
184
 
 
185
 
void Guix_TextBox::LockOut(boolean_g lock_it)
186
 
{
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.
190
 
}
191
 
 
192
 
 
193
 
//------------------------------------------------------------------------
194
 
 
195
 
//
196
 
// GUI_PrintMsg
197
 
//
198
 
void GUI_PrintMsg(const char *str, ...)
199
 
{
200
 
  char buffer[2048];
201
 
  
202
 
  va_list args;
203
 
 
204
 
  va_start(args, str);
205
 
  vsprintf(buffer, str, args);
206
 
  va_end(args);
207
 
 
208
 
  // handle pre-windowing text (ShowOptions and friends)
209
 
  if (! guix_win)
210
 
  {
211
 
    printf("%s", buffer);
212
 
    fflush(stdout);
213
 
    return;
214
 
  }
215
 
 
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);
220
 
  else
221
 
    guix_win->text_box->AddMsg(buffer);
222
 
}
223