Blame view

GUI/SW2/SRC/src/utility/TextCtrl.cpp 8.83 KB
886c558b   Steve Greedy   SACAMOS Public Re...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
//**************************************************************************************************
//                                          TextCtrl.cpp                                           *
//                                         --------------                                          *
// Started     : 2004-06-21                                                                        *
// Last Update : 2015-04-03                                                                        *
// Copyright   : (C) 2004-2016 MSWaters                                                            *
//**************************************************************************************************

//**************************************************************************************************
//                                                                                                 *
//      This program is free software; you can redistribute it and/or modify it under the          *
//      terms of the GNU General Public License as published by the Free Software Foundation;      *
//      either version 3 of the License, or (at your option) any later version.                    *
//                                                                                                 *
//**************************************************************************************************

#include "TextCtrl.hpp"

//**************************************************************************************************
// Initialize static variables for class

int  TextCtrl::m_iLinesMax = TXT_LNSDEF;
int  TextCtrl::m_iLinesDsp = TXT_DISPDEF;

//**************************************************************************************************
// Constructor.

TextCtrl::TextCtrl( void ) : wxTextCtrl( )
{
  bSetInitMsg( TXT_INITMSG );

  bClear( );
}

//**************************************************************************************************
// Destructor.

TextCtrl::~TextCtrl( )
{
}

//**************************************************************************************************
// Create an instantance of this object.
//
// Argument List :
//   poWin  - The parent window
//   oWinID - The window identifier
//
// Return Values :
//   true  - Success
//   false - Failure

bool  TextCtrl::bCreate( wxWindow * poWin, wxWindowID oWinID )
{
  long  lStyle;

  // Check if the object has already been created
  if( bIsCreated( ) )                                                               return( true );

  lStyle = wxTE_MULTILINE | wxTE_READONLY | wxSUNKEN_BORDER | wxTE_DONTWRAP |
           wxHSCROLL;
  if( ! Create( poWin, oWinID, wxT(""), wxDefaultPosition, wxDefaultSize, lStyle )) return( false );

  SetFont( FONT_MONO );

  return( bClear( ) );
}

//**************************************************************************************************
// Clear the text control.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  TextCtrl::bClear( void )
{
  long  lStyle;

  m_iLinesCnt = 0;

  // Check if the object has already been created
  if( ! bIsCreated( ) ) return( false );

  // Left-justify the text control contents
  lStyle = GetWindowStyle( );
  lStyle &= ~( wxTE_LEFT | wxTE_CENTER | wxTE_RIGHT );
  lStyle |= wxTE_LEFT;
  SetWindowStyle( lStyle );

  Clear( );              // Clear the text control contents
  SetEditable( false );  // Make the text control non-editable
  DiscardEdits( );       // Clear internal modified flag as if the current changes had been saved

  return( true );
}

//**************************************************************************************************
// Clear the text control and display a message to the user.
//
// Return Values :
//   true  - Success
//   false - Failure

bool  TextCtrl::bInitialize( void )
{
  int  i1;

  // Check if the object has already been created
  if( ! bIsCreated( ) ) return( false );

  bClear( );        // Clear the text control contents

  if( ! m_osInitMsg.IsEmpty( ) )
  {
    // Center the default message horizontally
    SetWindowStyle( GetWindowStyle( ) | wxTE_CENTRE );

    // Display the requisite number of blank lines
    for( i1=1; i1<TXT_INITLNS; i1++ )
      AppendText( wxT("\n") );

    // Display the default message
    AppendText( m_osInitMsg );
  }

  DiscardEdits( );  // Clear internal modified flag as if the current changes had been saved

  return( true );
}

//**************************************************************************************************
// Is the text control empty (ie. contains nothing or just the initialization message).
//
// Return Values :
//   true  - Success
//   false - Failure

bool  TextCtrl::bIsEmpty( void )
{
  long  li1;

  if( wxTextCtrl::IsEmpty( ) )                                return( true );

  for( li1=1; li1<TXT_INITLNS; li1++ )
    if( ! GetLineText( li1-1 ).IsEmpty( ) )                   return( false );

  if( GetLineText( li1 ).Find( m_osInitMsg ) == wxNOT_FOUND ) return( false );

  return( true );
}

//**************************************************************************************************
// Set the initialization message to be displayed.
//
// Argument List :
//   rosMsg - The initialization message
//
// Return Values :
//   true  - Success
//   false - Failure

bool  TextCtrl::bSetInitMsg( const wxString & rosMsg )
{
  if( rosMsg.Length( ) > 60 ) return( false );

  m_osInitMsg = rosMsg;

  return( true );
}

//**************************************************************************************************
// Set the maximum number of lines to be loaded into the control.
//
// Argument List :
//   iLines - The maximum number of lines to be displayed
//
// Return Values :
//   true  - Success
//   false - Failure

bool  TextCtrl::bSetLinesMax( int iLines )
{
  if( iLines<TXT_LNSMIN || iLines>TXT_LNSMAX ) return( false );

  m_iLinesMax = iLines;

  return( true );
}

//**************************************************************************************************
// Set the number of lines to be displayed in the control.
//
// Argument List :
//   iLines - The number of lines to be displayed
//
// Return Values :
//   true  - Success
//   false - Failure

bool  TextCtrl::bSetLinesDsp( int iLines )
{
  if( iLines<TXT_DISPMIN || iLines>TXT_DISPMAX ) return( false );

  m_iLinesDsp = iLines;

  return( true );
}


//**************************************************************************************************
// Append a line of text to the text control.
//
// Argument List :
//   rosLine - The line of text to append
//
// Return Values :
//   true  - Success
//   false - Failure

bool  TextCtrl::bAppendLine( const wxString & rosLine )
{
  // Check if the object has already been created
  if( ! bIsCreated( ) )            return( false );

  // Check that the max. lines hasn't been reached
  if( m_iLinesCnt >= m_iLinesMax ) return( false );

  // Append this text and a line terminator
  *this << rosLine << wxT('\n');
  m_iLinesCnt++;

  return( true );
}

//**************************************************************************************************
// Append the contents of a file to the text control.
//
// Argument List :
//   roFName - The file name to append
//
// Return Values :
//   true  - Success
//   false - Failure

bool  TextCtrl::bAppendFile( const wxString & roFName )
{
  wxString  os1;
  size_t    szt1;

  // Check if the object has already been created
  if( ! bIsCreated( ) ) return( false );

  // Open the file
  wxTextFile  oFile( roFName );
  if( ! oFile.Open( ) )
  {
    *this << wxT("Couldn't load the file containing the process output :\n  ");
    if( roFName.IsEmpty( ) ) *this << wxT("The log file name is empty!");
    else                     *this << roFName;
    return( false );
  }

  // Check that the file isn't empty
  if( oFile.GetLineCount( ) > 0 )
  { // Append the file contents to the text control
    for( szt1=0; szt1<oFile.GetLineCount( ); szt1++ )
    {
      os1 = oFile.GetLine( szt1 );
      if( ! bAppendLine( os1 ) )
      {
        *this << wxT("\nText control maximum line count (ie. ") << m_iLinesMax
              << wxT(") reached.\n");
        break;
      }
    }
  }
  else *this << wxT("There is no process output.");

  oFile.Close( );    // Close the log file

  SetInsertionPoint( 0 ); // Go to the top of the text control

  return( true );
}

//**************************************************************************************************
// Load the contents of a file into the text control.
//
// Argument List :
//   roFName - The file name to load
//
// Return Values :
//   true  - Success
//   false - Failure

bool  TextCtrl::bLoadFile( const wxString & roFName )
{
  // Check if the object has already been created
  if( ! bIsCreated( ) ) return( false );

  bClear( ); // Clear the text control

  return( bAppendFile( roFName ) );
}

//**************************************************************************************************