textctrl.cpp

来自「gspiceui电子CAD仿真程序.用于电路参数模拟仿真」· C++ 代码 · 共 285 行

CPP
285
字号
//*****************************************************************************//                                 TextCtrl.cpp                               *//                                --------------                              *//  Started     : 21/06/2004                                                  *//  Last Update : 20/07/2005                                                  *//  Copyright   : (C) 2004 by MSWaters                                        *//  Email       : M.Waters@bom.gov.au                                         *//*****************************************************************************//*****************************************************************************//                                                                            *//    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 2 of the License, or       *//    (at your option) any later version.                                     *//                                                                            *//*****************************************************************************#include "TextCtrl.hpp"// Initialize static varibale for classint  TextCtrl::m_iLinesMax = TXTCTL_LINESDEF;int  TextCtrl::m_iLinesDsp = TXTCTL_DISPDEF;//*****************************************************************************// Constructor.TextCtrl::TextCtrl( void ) : wxTextCtrl( ){  bSetInitMsg( TXTCTL_INITMSG );  m_iLinesCnt = 0;}//*****************************************************************************// Destructor.TextCtrl::~TextCtrl( ){}//*****************************************************************************// Create an instantance of this object.//// Argument List://   poWin  - The parent window//   oWinID - The window identifier//// Return Values://   TRUE  - Success//   FALSE - Failurebool  TextCtrl::bCreate( wxWindow * poWin, wxWindowID oWinID ){  long  lStyle;  // Check if the object has already been created  if( bIsCreated( ) ) return( TRUE );#if wxCHECK_VERSION(2,5,4)  wxFont  oFont1(  8, wxMODERN, wxNORMAL, wxFONTFLAG_BOLD );#else  wxFont  oFont1( 12, wxMODERN, wxNORMAL, wxNORMAL );#endif  lStyle = wxTE_MULTILINE | wxTE_READONLY | wxSUNKEN_BORDER | wxTE_DONTWRAP |           wxHSCROLL;  if( ! Create( poWin,oWinID,wxT(""),wxDefaultPosition,wxDefaultSize,lStyle ) )    return( FALSE );  SetFont( oFont1 );  return( bClear( ) );}//*****************************************************************************// Clear the text control.//// Return Values://   TRUE  - Success//   FALSE - Failurebool  TextCtrl::bClear( void ){  // Check if the object has already been created  if( ! bIsCreated( ) ) return( FALSE );  Clear( );  m_iLinesCnt = 0;  SetEditable( FALSE );  return( TRUE );}//*****************************************************************************// Clear the text control and display a message to the user.//// Return Values://   TRUE  - Success//   FALSE - Failurevoid  TextCtrl::Initialize( void ){  wxString  os1;  long  lStyle;  int   i1;  // Check if the object has already been created  if( ! bIsCreated( ) ) return;  bClear( );  if( ! m_osInitMsg.IsEmpty( ) )  {    // Center the message in the control ??? 04/09/2003 Doesn't work    lStyle = GetWindowStyle( ) | wxTE_CENTRE;    SetWindowStyle( lStyle );    // Center the message artifically since the above doesn't work ???    os1.Empty( );    i1 = iGetLinesDsp( ) / 2;    if( i1 % 2 == 0 ) i1 -= 1;    os1.Append( wxT('\n'), i1 );    i1 = ( TXTCTL_VIEWCOLS - m_osInitMsg.Length( ) ) / 2;    os1.Append( wxT(' '), i1 );    os1 << m_osInitMsg;    SetValue( os1 );      // Display the default message  }}//*****************************************************************************// Set the initialization message to be displayed.//// Argument List://   rosMsg - The initialization message//// Return Values://   true  - Success//   false - Failurebool  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 - Failurebool  TextCtrl::bSetLinesMax( int iLines ){  if( iLines<TXTCTL_LINESMIN || iLines>TXTCTL_LINESMAX ) 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 - Failurebool  TextCtrl::bSetLinesDsp( int iLines ){  if( iLines<TXTCTL_DISPMIN || iLines>TXTCTL_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 - Failurebool  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 - Failurebool  TextCtrl::bAppendFile( const wxString & roFName ){  wxString  os1;  // 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( os1=oFile.GetFirstLine( ); !oFile.Eof( ); os1=oFile.GetNextLine( ) )    {      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 - Failurebool  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 ) );}//*****************************************************************************

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?