viewer.h
Go to the documentation of this file.00001 #ifndef viewer_h_included
00002 #define viewer_h_included
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
00028
00036
00037 #include <cxxtls/cursorwindow.h>
00038 #include <memory>
00039 #include <vector>
00040 #include <list>
00041
00042 namespace cxxtls
00043 {
00044
00045 class ViewerManager;
00046
00047 class Viewer
00048
00111
00112 : public CursorWindow::viewport::repaint_handler
00113 {
00114
00115 protected:
00116
00117 ViewerManager* manager_;
00118
00119 public:
00120
00121 Viewer(ViewerManager* man)
00122 : manager_(man)
00123 {
00124 }
00125
00126 ViewerManager* manager() { return manager_; }
00127
00128 virtual void operator() ( CursorWindow::viewport * vp,
00129 int cmd
00130 ) = 0;
00135
00136 virtual bool handle_event( CursorWindow::input_event const * e,
00137 CursorWindow::viewport * vp
00138 ) = 0;
00163
00164 virtual std::string const &application_name() const = 0;
00170
00171 virtual std::string description() const = 0;
00177
00178 virtual void help();
00179
00180
00181
00182
00183
00184 virtual bool is_dirty() const;
00189
00190 typedef CursorWindow::viewport viewport;
00191 typedef CursorWindow::row_col row_col;
00192 typedef CursorWindow::input_event input_event;
00193
00194 typedef std::list<std::string> paste_buffer_type;
00195
00196 paste_buffer_type* paste_buffer();
00197
00198
00199 void commitPasteBuffer() const;
00200 void fetchPasteBuffer();
00201
00202 virtual void set_row_col_hint(size_t line, size_t column, bool repaint=false) {}
00215
00216 virtual bool fetchAllLines(std::list<std::string> &output);
00227
00228 };
00229
00230 class ListViewer
00231 : public Viewer
00232
00289 {
00290 public:
00291
00292 struct policies
00293
00305
00306 {
00307 virtual ~policies();
00308
00309 std::vector<std::string> strings_;
00310 std::string title_;
00311
00312 virtual std::string const& application_name() const =0;
00315
00316 virtual std::string description() const =0;
00320
00321 virtual int handle_event(input_event const *e,
00322 size_t index,
00323 ViewerManager* vm
00324 ) =0;
00353
00354 virtual void handle_resize(CursorWindow::row_col const &new_size);
00363
00364
00365 virtual bool is_marked(size_t index)=0;
00366
00367
00368
00369
00370
00371 virtual bool is_special(size_t index);
00372
00373
00374 virtual std::auto_ptr< std::list<std::string> > help_text()=0;
00380
00381
00382 virtual bool fetchAllLines(std::list< std::string > &output );
00384
00385 };
00386
00387 private:
00388
00389 std::auto_ptr<policies> com_;
00390
00391 size_t display_top_;
00392 size_t cur_row_;
00393 int first_row_;
00394
00395 bool active_;
00396
00397 std::string search_string_;
00398
00399 public:
00400
00401 ListViewer(policies* comtable, ViewerManager* man)
00402 : Viewer(man),
00403 com_(comtable),
00404 display_top_(0),
00405 cur_row_(0),
00406 first_row_(1),
00407 active_(false)
00408 {
00414
00415 }
00416
00417 void operator() ( viewport * vp,int cmd);
00420
00421 bool handle_event(input_event const * e, viewport * vp);
00422
00423 void repaint(viewport *vp)
00424
00425 {
00426 (*this)(vp, activate );
00427 }
00428
00429 void output_row_text(viewport * vp, int i)
00430 {
00431
00432
00433 if(i < (int)(com_->strings_.size()) )
00434 *vp << com_->strings_[i];
00435 }
00436
00437 inline int line_attribute(bool selected, size_t index, bool is_bottom);
00441
00442 int find_string(size_t index, ViewerManager* vm);
00448
00449
00450 int find_string(size_t index);
00455
00456 virtual void help();
00457
00458 std::string const& application_name() const
00461 {
00462 return com_->application_name();
00463 }
00464
00465 std::string description() const
00468 {
00469 return com_->description();
00470 }
00471
00472 virtual bool fetchAllLines(std::list<std::string> &output);
00474
00475
00476 };
00477
00478 }
00479
00480 #endif