~ubuntu-branches/ubuntu/natty/glbsp/natty

« back to all changes in this revision

Viewing changes to gui/textbox.cc

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