00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef CEYLAN_TEXT_BUFFER_H_
00028 #define CEYLAN_TEXT_BUFFER_H_
00029
00030
00031 #include "CeylanStringUtils.h"
00032
00033 #include <string>
00034 #include <list>
00035 #include <utility>
00036
00037
00038
00039
00040 namespace Ceylan
00041 {
00042
00043
00044
00060 class CEYLAN_DLL TextBuffer: public Ceylan::TextDisplayable
00061 {
00062
00063
00064 public:
00065
00066
00067
00069 class CEYLAN_DLL TextBufferException: public StringUtilsException
00070 {
00071
00072
00073 public:
00074
00075 TextBufferException( const std::string & message ) :
00076 StringUtilsException( message )
00077 {
00078
00079 }
00080
00081
00082 virtual ~TextBufferException() throw()
00083 {
00084
00085 }
00086
00087 } ;
00088
00089
00090
00095 enum TextLayout
00096 {
00097
00103 Raw,
00104
00109 WordWrapped,
00110
00115 Justified
00116
00117 } ;
00118
00119
00120
00122 typedef Ceylan::Uint8 CharAbscissa ;
00123
00124
00126 typedef Ceylan::Uint8 CharOrdinate ;
00127
00128
00129
00131 typedef Ceylan::Uint32 TextIndex ;
00132
00133
00135 typedef Ceylan::Uint32 LineIndex ;
00136
00137
00138
00158 TextBuffer( CharAbscissa screenWidth, CharOrdinate screenHeight,
00159 TextLayout layout = Raw ) ;
00160
00161
00163 virtual ~TextBuffer() throw() ;
00164
00165
00166
00167
00173 virtual CharAbscissa getWidth() const ;
00174
00175
00181 virtual CharOrdinate getHeight() const ;
00182
00183
00184
00186 virtual TextLayout getTextLayout() const ;
00187
00188
00189
00199 virtual void setTextLayout( TextLayout newLayout ) ;
00200
00201
00202
00207 virtual CharAbscissa getAlineaWidth() const ;
00208
00209
00210
00218 virtual void setAlineaWidth( CharAbscissa newAlineaWidth ) ;
00219
00220
00221
00232 virtual void add( const std::string & text ) ;
00233
00234
00235
00242 virtual void blank() ;
00243
00244
00245
00246
00247
00248
00249
00258 virtual bool jumpNextText() ;
00259
00260
00261
00270 virtual bool jumpPreviousText() ;
00271
00272
00273
00282 virtual bool jumpNextLine() ;
00283
00284
00285
00299 virtual void jumpNextLineNoRefresh() ;
00300
00301
00302
00311 virtual bool jumpPreviousLine() ;
00312
00313
00314
00323 typedef std::list<char *> TextGrid ;
00324
00325
00326
00339 virtual const TextGrid & getScreenLines() const ;
00340
00341
00342
00355 virtual const std::string toString(
00356 Ceylan::VerbosityLevels level = Ceylan::high ) const ;
00357
00358
00359
00361 static const CharAbscissa TabSpacing = 4 ;
00362
00363
00364
00365
00366 protected:
00367
00368
00378 virtual void recomputeGrids() ;
00379
00380
00381
00389 void updateScreenLines() ;
00390
00391
00392
00402 TextGrid & createTextGridFrom( const std::string & text ) ;
00403
00404
00406 void deleteTextGrid( TextGrid * grid ) ;
00407
00408
00409
00418 TextGrid & createRawGridFrom( const std::string & text ) ;
00419
00420
00421
00430 TextGrid & createAdvancedGridFrom( const std::string & text ) ;
00431
00432
00433
00439 LineIndex getHeightFromCurrentPosition() const ;
00440
00441
00442
00448 typedef std::pair<std::string, TextGrid*> TextEntry ;
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458 #pragma warning( push )
00459 #pragma warning( disable : 4251 )
00460
00462 typedef std::list<TextEntry> ListOfTexts ;
00463
00464 #pragma warning( pop )
00465
00466
00472 LineIndex getHeightFromEntry(
00473 ListOfTexts::const_iterator textIterator ) const ;
00474
00475
00476
00483 char * getNewLine() ;
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493 #pragma warning( push )
00494 #pragma warning( disable : 4251 )
00495
00496
00502 ListOfTexts _textEntries ;
00503
00504 #pragma warning( pop )
00505
00506
00508 CharAbscissa _width ;
00509
00510
00512 CharOrdinate _height ;
00513
00514
00515
00517 TextLayout _layout ;
00518
00519
00521 CharAbscissa _alineaWidth ;
00522
00523
00524
00525
00526
00527
00528
00529
00530 #pragma warning( push )
00531 #pragma warning( disable : 4251 )
00532
00534 ListOfTexts::const_iterator _currentText ;
00535
00536
00538 TextGrid::const_iterator _currentLine ;
00539
00540
00542 TextGrid _screenLines ;
00543
00544 #pragma warning( pop )
00545
00546
00547
00548 private:
00549
00550
00559 TextBuffer( const TextBuffer & source ) ;
00560
00561
00570 TextBuffer & operator = ( const TextBuffer & source ) ;
00571
00572
00573 } ;
00574
00575
00576 }
00577
00578
00579 #endif // CEYLAN_TEXT_BUFFER_H_
00580