CARDS 2.4.140
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
49using namespace std;
50using namespace cards;
51
52// A single row of columns
53class Row
54{
55public:
56 Row(){data=nullptr;}
57 vector<string> cols;
58 void* data;
59};
60
61// Class for handling the sorting column using std::sort
63{
64private:
65 int _col, _reverse;
66
67public:
68 SortColumn (int col, int reverse);
69 bool operator() (const Row &a, const Row &b);
70};
71
78class TableBase : public Fl_Table_Row, public CEventHandler
79{
80public:
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
108protected:
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
123private:
124 static void event_callback(Fl_Widget*,void*);
125 void event_callback2();
126
127protected:
128 string _filter;
129 vector<Row> _rowdata;
130 int _sort_reverse;
131 int _sort_lastcol;
132 CWrapper* _cards;
133};
134
135#endif
136
Definition: table_base.h:54
Definition: table_base.h:63
Definition: table_base.h:79
void draw_sort_arrow(int X, int Y, int W, int H)
Draw sort arrow.
Definition: table_base.cxx:84
TableBase(int x, int y, int w, int h, const char *l=0)
Constructor.
Definition: table_base.cxx:52
void sort_column(int col, int reverse=0)
Sort a column up or down.
Definition: table_base.cxx:77
void resize_window()
Resize parent widows to size of tableau.
Definition: table_base.cxx:200
virtual void refresh_table()=0
Populate the tab with package installed.
void setFilter(const string &pValue)
Redefine filter and refresh the tab.
Definition: table_base.cxx:246
void autowidth(int pad)
Automatically set columns widths to the longuest string.
Definition: table_base.cxx:138
virtual ~TableBase()
Destructor.
Definition: table_base.h:95
void OnJobListChange(const CEH_RC rc)
Callback.
Definition: table_base.cxx:254
void draw_cell(TableContext context, int R=0, int C=0, int X=0, int Y=0, int W=0, int H=0)
Handle drawing all cells in table.
Definition: table_base.cxx:112
Definition: cards_event_handler.h:63
Definition: cards_wrapper.h:60