CARDS 2.4.87
Package manager for the NuTyX GNU/Linux distribution
table_base.h
1 /*
2  * table_base.h
3  *
4  * Copyright 2015-2018 Thierry Nuttens <tnut@nutyx.org>
5  * Copyright 2017-2018 Gianni Peschiutta <artemia@nutyx.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  *
22  *
23  */
24 
25 #ifndef TABLE_BASE_H
26 #define TABLE_BASE_H
27 
28 #include <stdio.h>
29 #include <string.h>
30 #include <vector>
31 #include <algorithm>
32 
33 #include <ctype.h>
34 
35 #include <FL/Fl.H>
36 #include <FL/fl_ask.H>
37 #include <FL/Fl_Double_Window.H>
38 #include <FL/fl_draw.H>
39 #include <FL/Fl_Table_Row.H>
40 #include <FL/Fl_Menu.H>
41 #include "cards_wrapper.h"
42 #include "pixmaps/checked.xpm"
43 #include "pixmaps/download.xpm"
44 #include "pixmaps/deleted.xpm"
45 
46 #define MARGIN 20
47 
48 using namespace std;
49 using namespace cards;
50 
51 // A single row of columns
52 class Row
53 {
54 public:
55  Row(){data=nullptr;}
56  vector<string> cols;
57  void* data;
58 };
59 
60 // Class for handling the sorting column using std::sort
62 {
63 private:
64  int _col, _reverse;
65 
66 public:
67  SortColumn (int col, int reverse);
68  bool operator() (const Row &a, const Row &b);
69 };
70 
77 class TableBase : public Fl_Table_Row, public CEventHandler
78 {
79 public:
86  TableBase(int x, int y, int w, int h, const char *l=0);
87 
94  virtual ~TableBase(){}
95 
102  virtual void refresh_table() = 0; // Load the packages list
103  void autowidth(int pad); // Automatically set the columns widths to the longuest string
104  void resize_window(); // Resize the parent window to size of table
105  void setFilter(const string& pValue);
106 
107 protected:
108  vector<string> colTitle;
109 
110  // table cell drawing
111  void draw_cell(TableContext context, int R=0, int C=0, int X=0, int Y=0, int W=0, int H=0);
112  // sort the table by a column
113  void sort_column(int col, int reverse=0);
114  void draw_sort_arrow(int X, int Y, int W, int H);
115 
116  void OnDoJobListFinished (const CEH_RC rc);
117  void OnRefreshPackageFinished (const CEH_RC rc);
118  void OnJobListChange(const CEH_RC rc);
119  virtual void OnDrawCell(TableContext, int, int, int, int, int, int){}
120  virtual void OnEvent(TableContext, int, int){}
121 
122 private:
123  static void event_callback(Fl_Widget*,void*);
124  void event_callback2();
125 
126 protected:
127  string _filter;
128  vector<Row> _rowdata;
129  int _sort_reverse;
130  int _sort_lastcol;
131  CWrapper* _cards;
132 };
133 
134 #endif
135 
Definition: table_base.h:77
Definition: cards_wrapper.h:58
Definition: cards_event_handler.h:61
Definition: table_base.h:52
Definition: cards_client.cxx:26
Definition: table_base.h:61
virtual ~TableBase()
Destructor.
Definition: table_base.h:94