summaryrefslogtreecommitdiff
path: root/library/CustomGrid.h
blob: 97642159c46b79783ea60411d6f672772cb26c46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef CUSTOMGRID_H_INCLUDED
#define CUSTOMGRID_H_INCLUDED

#include <vector>
#include <wx/grid.h>
#include "../FreeFileSync.h"
#include "processXml.h"

using namespace FreeFileSync;


class CustomGridTable;
class CustomGridTableMiddle;
//##################################################################################

extern const wxGrid* leadGrid; //this global variable is not very nice...

class CustomGrid : public wxGrid
{
public:
    CustomGrid(wxWindow *parent,
               wxWindowID id,
               const wxPoint& pos   = wxDefaultPosition,
               const wxSize& size   = wxDefaultSize,
               long style           = wxWANTS_CHARS,
               const wxString& name = wxGridNameStr);

    virtual ~CustomGrid() {}

    //overwrite virtual method to finally get rid of the scrollbars
    virtual void SetScrollbar(int orientation, int position, int thumbSize, int range, bool refresh = true);

    virtual void DrawColLabel(wxDC& dc, int col);

    void initSettings(bool enableScrollbars,
                      CustomGrid* gridLeft,
                      CustomGrid* gridRight,
                      CustomGrid* gridMiddle,
                      GridView* gridRefUI,
                      FileCompareResult* gridData);

    //notify wxGrid that underlying table size has changed
    void updateGridSizes();

    //set sort direction indicator on UI
    void setSortMarker(const int sortColumn, const wxBitmap* bitmap = &wxNullBitmap);

    //set visibility, position and width of columns
    void setColumnAttributes(const xmlAccess::XmlGlobalSettings::ColumnAttributes& attr);
    xmlAccess::XmlGlobalSettings::ColumnAttributes getColumnAttributes();

    xmlAccess::XmlGlobalSettings::ColumnTypes getTypeAtPos(unsigned pos) const;

    static wxString getTypeName(xmlAccess::XmlGlobalSettings::ColumnTypes colType);

    static const unsigned COLUMN_TYPE_COUNT = 4;

protected:
    //set visibility, position and width of columns
    xmlAccess::XmlGlobalSettings::ColumnAttributes columnSettings;


    void adjustGridHeights();

    bool scrollbarsEnabled;
    CustomGrid* m_gridLeft;
    CustomGrid* m_gridRight;
    CustomGrid* m_gridMiddle;

    CustomGridTable* gridDataTable;

    int currentSortColumn;
    const wxBitmap* sortMarker;
};


class CustomGridLeft : public CustomGrid
{
public:
    CustomGridLeft(wxWindow *parent,
                   wxWindowID id,
                   const wxPoint& pos   = wxDefaultPosition,
                   const wxSize& size   = wxDefaultSize,
                   long style           = wxWANTS_CHARS,
                   const wxString& name = wxGridNameStr);

    ~CustomGridLeft() {}

    //this method is called when grid view changes: useful for parallel updating of multiple grids
    virtual void DoPrepareDC(wxDC& dc);

    virtual bool CreateGrid(int numRows, int numCols, wxGrid::wxGridSelectionModes selmode = wxGrid::wxGridSelectCells);
};


class CustomGridMiddle : public CustomGrid
{
public:
    CustomGridMiddle(wxWindow *parent,
                     wxWindowID id,
                     const wxPoint& pos   = wxDefaultPosition,
                     const wxSize& size   = wxDefaultSize,
                     long style           = wxWANTS_CHARS,
                     const wxString& name = wxGridNameStr);

    ~CustomGridMiddle() {}

    //this method is called when grid view changes: useful for parallel updating of multiple grids
    virtual void DoPrepareDC(wxDC& dc);

    virtual bool CreateGrid(int numRows, int numCols, wxGrid::wxGridSelectionModes selmode = wxGrid::wxGridSelectCells);

private:

    class GridCellRendererAddCheckbox : public wxGridCellStringRenderer
    {
    public:
        GridCellRendererAddCheckbox(CustomGridTableMiddle* gridDataTable) : m_gridDataTable(gridDataTable) {};


        virtual void Draw(wxGrid& grid,
                          wxGridCellAttr& attr,
                          wxDC& dc,
                          const wxRect& rect,
                          int row, int col,
                          bool isSelected);

    private:
        CustomGridTableMiddle* m_gridDataTable;
    };
};


class CustomGridRight : public CustomGrid
{
public:
    CustomGridRight(wxWindow *parent,
                    wxWindowID id,
                    const wxPoint& pos   = wxDefaultPosition,
                    const wxSize& size   = wxDefaultSize,
                    long style           = wxWANTS_CHARS,
                    const wxString& name = wxGridNameStr);

    ~CustomGridRight() {}

    //this method is called when grid view changes: useful for parallel updating of multiple grids
    virtual void DoPrepareDC(wxDC& dc);

    virtual bool CreateGrid(int numRows, int numCols, wxGrid::wxGridSelectionModes selmode = wxGrid::wxGridSelectCells);
};

#endif // CUSTOMGRID_H_INCLUDED
bgstack15