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