~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to pgadmin/include/frm/frmEditGrid.h

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2011-06-07 23:03:54 UTC
  • mfrom: (1.3.1 upstream) (13 sid)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110607230354-3td4j9y71u4ahcvj
Tags: 1.14.0~beta1-1
* New upstream development release, adding Build-Depends on
  postgresql-server-dev-all >= 117~.
* Add Build-Depends on quilt, (un)patch to debian/rules and patch for fixing
  the include for kwlist.h in pgadmin/db/keywords.c.
* Add pg_config --includedir-server output to CPPFLAGS.
* Remove unrecognized configure options: --with-wx-config,
  --with-pgsql-include, --enable-gtk2, --enable-unicode.
* Clean up manually the files that are left behind after the broken
  distclean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//////////////////////////////////////////////////////////////////////////
2
2
//
3
3
// pgAdmin III - PostgreSQL Tools
4
 
// 
5
 
// Copyright (C) 2002 - 2010, The pgAdmin Development Team
 
4
//
 
5
// Copyright (C) 2002 - 2011, The pgAdmin Development Team
6
6
// This software is released under the PostgreSQL Licence
7
7
//
8
8
// frmEditGrid.h - The SQL Edit Grid form
39
39
class cacheLine
40
40
{
41
41
public:
42
 
    cacheLine() { cols=0; stored=false; readOnly=false; }
43
 
    ~cacheLine() { if (cols) delete[] cols; }
 
42
        cacheLine()
 
43
        {
 
44
                cols = 0;
 
45
                stored = false;
 
46
                readOnly = false;
 
47
        }
 
48
        ~cacheLine()
 
49
        {
 
50
                if (cols) delete[] cols;
 
51
        }
44
52
 
45
 
    wxString *cols;
46
 
    bool stored, readOnly;
 
53
        wxString *cols;
 
54
        bool stored, readOnly;
47
55
};
48
56
 
49
57
 
50
58
class cacheLinePool
51
59
{
52
60
public:
53
 
    cacheLinePool(int initialLines);
54
 
    ~cacheLinePool();
55
 
    cacheLine *operator[] (int line) { return Get(line); }
56
 
    cacheLine *Get(int lineNo);
57
 
    bool IsFilled(int lineNo);
58
 
    void Delete(int lineNo);
 
61
        cacheLinePool(int initialLines);
 
62
        ~cacheLinePool();
 
63
        cacheLine *operator[] (int line)
 
64
        {
 
65
                return Get(line);
 
66
        }
 
67
        cacheLine *Get(int lineNo);
 
68
        bool IsFilled(int lineNo);
 
69
        void Delete(int lineNo);
59
70
 
60
71
private:
61
 
    cacheLine **ptr;
62
 
    int anzLines;
 
72
        cacheLine **ptr;
 
73
        int anzLines;
63
74
};
64
75
 
65
76
 
66
77
class sqlCell
67
78
{
68
79
public:
69
 
    sqlCell() { ClearCell(); }
70
 
 
71
 
    void SetCell(long r, long c) { row = r; col = c; }
72
 
    void ClearCell() { row = -1; col = -1; }
73
 
    bool IsSet() { return row != -1 && col != -1; }
74
 
 
75
 
    long GetRow() { return row; }
76
 
    long GetCol() { return col; }
 
80
        sqlCell()
 
81
        {
 
82
                ClearCell();
 
83
        }
 
84
 
 
85
        void SetCell(long r, long c)
 
86
        {
 
87
                row = r;
 
88
                col = c;
 
89
        }
 
90
        void ClearCell()
 
91
        {
 
92
                row = -1;
 
93
                col = -1;
 
94
        }
 
95
        bool IsSet()
 
96
        {
 
97
                return row != -1 && col != -1;
 
98
        }
 
99
 
 
100
        long GetRow()
 
101
        {
 
102
                return row;
 
103
        }
 
104
        long GetCol()
 
105
        {
 
106
                return col;
 
107
        }
77
108
 
78
109
private:
79
 
    long row;
80
 
    long col;
 
110
        long row;
 
111
        long col;
81
112
};
82
113
 
83
 
// we cannot derive from wxGridCellAttr because destructor is private but not virtual 
 
114
// we cannot derive from wxGridCellAttr because destructor is private but not virtual
84
115
class sqlCellAttr
85
116
{
86
117
public:
87
 
    sqlCellAttr()  { attr = new wxGridCellAttr; isPrimaryKey=false; needResize=false; }
88
 
    ~sqlCellAttr() { attr->DecRef(); }
89
 
    int size();
90
 
    int precision();
 
118
        sqlCellAttr()
 
119
        {
 
120
                attr = new wxGridCellAttr;
 
121
                isPrimaryKey = false;
 
122
                needResize = false;
 
123
        }
 
124
        ~sqlCellAttr()
 
125
        {
 
126
                attr->DecRef();
 
127
        }
 
128
        int size();
 
129
        int precision();
91
130
 
92
 
    wxGridCellAttr *attr;
93
 
    wxString Quote(pgConn *conn, const wxString &value);
94
 
    OID type;
95
 
    long typlen, typmod;
96
 
    wxString name, typeName, displayTypeName;
97
 
    bool numeric, isPrimaryKey, needResize;
 
131
        wxGridCellAttr *attr;
 
132
        wxString Quote(pgConn *conn, const wxString &value);
 
133
        OID type;
 
134
        long typlen, typmod;
 
135
        wxString name, typeName, displayTypeName;
 
136
        bool numeric, isPrimaryKey, needResize;
98
137
};
99
138
 
100
139
 
103
142
class ctlSQLEditGrid : public ctlSQLGrid
104
143
{
105
144
public:
106
 
    ctlSQLEditGrid(wxFrame *parent, wxWindowID id, const wxPoint& pos, const wxSize& size);
 
145
        ctlSQLEditGrid(wxFrame *parent, wxWindowID id, const wxPoint &pos, const wxSize &size);
107
146
 
108
 
    sqlTable *GetTable() { return (sqlTable*)wxGrid::GetTable(); }
109
 
    //wxSize GetBestSize(int row, int col);
110
 
    void ResizeEditor(int row, int col);
111
 
    wxArrayInt GetSelectedRows() const;
112
 
    bool CheckRowPresent(int row);
113
 
    virtual bool IsColText(int col);
 
147
        sqlTable *GetTable()
 
148
        {
 
149
                return (sqlTable *)wxGrid::GetTable();
 
150
        }
 
151
        //wxSize GetBestSize(int row, int col);
 
152
        void ResizeEditor(int row, int col);
 
153
        wxArrayInt GetSelectedRows() const;
 
154
        bool CheckRowPresent(int row);
 
155
        virtual bool IsColText(int col);
114
156
};
115
157
 
116
158
class sqlTable : public wxGridTableBase
117
159
{
118
160
public:
119
 
    sqlTable(pgConn *conn, pgQueryThread *thread, const wxString& tabName, const OID relid, bool _hasOid, const wxString& _pkCols, char _relkind);
120
 
    ~sqlTable();
121
 
    bool StoreLine();
122
 
    void UndoLine(int row);
123
 
 
124
 
    int GetNumberRows();
125
 
    int GetNumberStoredRows();
126
 
    int GetNumberCols();
127
 
    wxString GetColLabelValue(int col);
128
 
    wxString GetColLabelValueUnformatted(int col);
129
 
    wxString GetRowLabelValue(int row);
130
 
    wxGridCellAttr* GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind);
131
 
 
132
 
    wxString GetValue(int row, int col);
133
 
    void SetValue(int row, int col, const wxString &value);
134
 
 
135
 
    bool IsEmptyCell(int row, int col) { return false; }
136
 
    bool needsResizing(int col) { return columns[col].needResize; }
137
 
    bool AppendRows(size_t rows);
138
 
    bool DeleteRows(size_t pos, size_t rows);
139
 
    int  LastRow() { return lastRow; }
140
 
    bool IsColText(int col);
141
 
    bool IsColBoolean(int col);
142
 
 
143
 
    bool CheckInCache(int row);
144
 
    bool IsLineSaved(int row) { return GetLine(row)->stored; }
145
 
 
146
 
    bool Paste();
 
161
        sqlTable(pgConn *conn, pgQueryThread *thread, const wxString &tabName, const OID relid, bool _hasOid, const wxString &_pkCols, char _relkind);
 
162
        ~sqlTable();
 
163
        bool StoreLine();
 
164
        void UndoLine(int row);
 
165
 
 
166
        int GetNumberRows();
 
167
        int GetNumberStoredRows();
 
168
        int GetNumberCols();
 
169
        wxString GetColLabelValue(int col);
 
170
        wxString GetColLabelValueUnformatted(int col);
 
171
        wxString GetRowLabelValue(int row);
 
172
        wxGridCellAttr *GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind);
 
173
 
 
174
        wxString GetValue(int row, int col);
 
175
        void SetValue(int row, int col, const wxString &value);
 
176
 
 
177
        bool IsEmptyCell(int row, int col)
 
178
        {
 
179
                return false;
 
180
        }
 
181
        bool needsResizing(int col)
 
182
        {
 
183
                return columns[col].needResize;
 
184
        }
 
185
        bool AppendRows(size_t rows);
 
186
        bool DeleteRows(size_t pos, size_t rows);
 
187
        int  LastRow()
 
188
        {
 
189
                return lastRow;
 
190
        }
 
191
        bool IsColText(int col);
 
192
        bool IsColBoolean(int col);
 
193
 
 
194
        bool CheckInCache(int row);
 
195
        bool IsLineSaved(int row)
 
196
        {
 
197
                return GetLine(row)->stored;
 
198
        }
 
199
 
 
200
        bool Paste();
147
201
 
148
202
private:
149
 
    pgQueryThread *thread;
150
 
    pgConn *connection;
151
 
    bool hasOids;
152
 
    char relkind;
153
 
    wxString tableName;
154
 
    OID relid;
155
 
    wxString primaryKeyColNumbers;
156
 
 
157
 
    cacheLine *GetLine(int row);
158
 
    wxString MakeKey(cacheLine *line);
159
 
    void SetNumberEditor(int col, int len);
160
 
 
161
 
    cacheLinePool *dataPool, *addPool;
162
 
    cacheLine savedLine;
163
 
    int lastRow;
164
 
 
165
 
    int *lineIndex;     // reindex of lines in dataSet to handle deleted rows
166
 
 
167
 
    int nCols;          // columns from dataSet
168
 
    int nRows;          // rows initially returned by dataSet
169
 
    int rowsCached;     // rows read from dataset; if nRows=rowsCached, dataSet can be deleted
170
 
    int rowsAdded;      // rows added (never been in dataSet)
171
 
    int rowsStored;     // rows added and stored to db
172
 
    int rowsDeleted;    // rows deleted from initial dataSet
173
 
    sqlCellAttr *columns;
 
203
        pgQueryThread *thread;
 
204
        pgConn *connection;
 
205
        bool hasOids;
 
206
        char relkind;
 
207
        wxString tableName;
 
208
        OID relid;
 
209
        wxString primaryKeyColNumbers;
 
210
 
 
211
        cacheLine *GetLine(int row);
 
212
        wxString MakeKey(cacheLine *line);
 
213
        void SetNumberEditor(int col, int len);
 
214
 
 
215
        cacheLinePool *dataPool, *addPool;
 
216
        cacheLine savedLine;
 
217
        int lastRow;
 
218
 
 
219
        int *lineIndex;     // reindex of lines in dataSet to handle deleted rows
 
220
 
 
221
        int nCols;          // columns from dataSet
 
222
        int nRows;          // rows initially returned by dataSet
 
223
        int rowsCached;     // rows read from dataset; if nRows=rowsCached, dataSet can be deleted
 
224
        int rowsAdded;      // rows added (never been in dataSet)
 
225
        int rowsStored;     // rows added and stored to db
 
226
        int rowsDeleted;    // rows deleted from initial dataSet
 
227
        sqlCellAttr *columns;
174
228
 
175
229
        wxArrayInt colMap;
176
230
 
177
 
    friend class ctlSQLEditGrid;
 
231
        friend class ctlSQLEditGrid;
178
232
};
179
233
 
180
234
 
184
238
class frmEditGrid : public pgFrame
185
239
{
186
240
public:
187
 
    frmEditGrid(frmMain *form, const wxString& _title, pgConn *conn, pgSchemaObject *obj);
188
 
    ~frmEditGrid();
 
241
        frmEditGrid(frmMain *form, const wxString &_title, pgConn *conn, pgSchemaObject *obj, bool ascending = true);
 
242
        ~frmEditGrid();
189
243
 
190
 
    void ShowForm(bool filter = false);
191
 
    void Go();
192
 
    wxString GetSortCols() const { return orderBy; } ;
193
 
    void SetSortCols(const wxString &cols);
194
 
    wxString GetFilter() const { return rowFilter; } ;
195
 
    void SetFilter(const wxString &filter);
196
 
    int GetLimit() const { return limit; } ;
197
 
    void SetLimit(const int rowlimit);
198
 
    wxMenu *GetFileMenu() { return fileMenu; };
199
 
    wxMenu *GetEditMenu() { return editMenu; };
 
244
        void ShowForm(bool filter = false);
 
245
        void Go();
 
246
        wxString GetSortCols() const
 
247
        {
 
248
                return orderBy;
 
249
        } ;
 
250
        void SetSortCols(const wxString &cols);
 
251
        wxString GetFilter() const
 
252
        {
 
253
                return rowFilter;
 
254
        } ;
 
255
        void SetFilter(const wxString &filter);
 
256
        int GetLimit() const
 
257
        {
 
258
                return limit;
 
259
        } ;
 
260
        void SetLimit(const int rowlimit);
 
261
        wxMenu *GetFileMenu()
 
262
        {
 
263
                return fileMenu;
 
264
        };
 
265
        wxMenu *GetEditMenu()
 
266
        {
 
267
                return editMenu;
 
268
        };
200
269
 
201
270
private:
202
 
    void OnEraseBackground(wxEraseEvent& event);
203
 
    void OnSize(wxSizeEvent& event);
204
 
    
205
 
    void OnCloseWindow(wxCloseEvent& event);
206
 
    void OnClose(wxCommandEvent& event);
207
 
    void OnHelp(wxCommandEvent& event);
208
 
    void OnContents(wxCommandEvent& event);
209
 
    void OnRefresh(wxCommandEvent& event);
210
 
    void OnDelete(wxCommandEvent& event);
211
 
    void OnOptions(wxCommandEvent& event);
212
 
    void OnSave(wxCommandEvent& event);
213
 
    bool DoSave();
 
271
        void OnEraseBackground(wxEraseEvent &event);
 
272
        void OnSize(wxSizeEvent &event);
 
273
 
 
274
        void OnCloseWindow(wxCloseEvent &event);
 
275
        void OnClose(wxCommandEvent &event);
 
276
        void OnHelp(wxCommandEvent &event);
 
277
        void OnContents(wxCommandEvent &event);
 
278
        void OnRefresh(wxCommandEvent &event);
 
279
        void OnDelete(wxCommandEvent &event);
 
280
        void OnOptions(wxCommandEvent &event);
 
281
        void OnSave(wxCommandEvent &event);
 
282
        bool DoSave();
214
283
        void CancelChange();
215
 
    void OnUndo(wxCommandEvent& event);
216
 
    void OnCellChange(wxGridEvent& event);
217
 
    void OnGridSelectCells(wxGridRangeSelectEvent& event);
218
 
    void OnEditorShown(wxGridEvent& event);
219
 
    void OnEditorHidden(wxGridEvent& event);
220
 
    void OnKey(wxKeyEvent& event);
221
 
    void OnCopy(wxCommandEvent& event);
222
 
    void OnIncludeFilter(wxCommandEvent& event);
223
 
    void OnExcludeFilter(wxCommandEvent& event);
224
 
    void OnRemoveFilters(wxCommandEvent& event);
225
 
    void OnAscSort(wxCommandEvent& event);
226
 
    void OnDescSort(wxCommandEvent& event);
227
 
    void OnRemoveSort(wxCommandEvent& event);
228
 
    void OnPaste(wxCommandEvent& event);
229
 
    void OnLabelDoubleClick(wxGridEvent& event);
230
 
    void OnLabelRightClick(wxGridEvent& event);
231
 
    void OnCellRightClick(wxGridEvent& event);
232
 
    void Abort();
233
 
    void OnToggleScratchPad(wxCommandEvent& event);
234
 
    void OnToggleLimitBar(wxCommandEvent& event);
235
 
    void OnToggleToolBar(wxCommandEvent& event);
236
 
    void OnAuiUpdate(wxAuiManagerEvent& event);
237
 
    void OnDefaultView(wxCommandEvent& event);
238
 
 
239
 
    wxAuiManager manager;
240
 
    ctlSQLEditGrid *sqlGrid;
241
 
 
242
 
    frmMain *mainForm;
243
 
    pgConn *connection;
244
 
    pgQueryThread *thread;
245
 
    wxMenu *fileMenu, *editMenu, *viewMenu, *toolsMenu, *helpMenu;
246
 
    ctlMenuToolbar *toolBar;
247
 
    wxComboBox *cbLimit;
248
 
    wxTextCtrl *scratchPad;
249
 
 
250
 
    char relkind;
251
 
    OID relid;
252
 
    bool hasOids;
253
 
    wxString tableName;
254
 
    wxString primaryKeyColNumbers;
255
 
    wxString orderBy;
256
 
    wxString rowFilter;
257
 
    int limit;
258
 
    sqlCell *editorCell;
259
 
    bool closing;
260
 
 
261
 
    DECLARE_EVENT_TABLE()
 
284
        void OnUndo(wxCommandEvent &event);
 
285
        void OnCellChange(wxGridEvent &event);
 
286
        void OnGridSelectCells(wxGridRangeSelectEvent &event);
 
287
        void OnEditorShown(wxGridEvent &event);
 
288
        void OnEditorHidden(wxGridEvent &event);
 
289
        void OnKey(wxKeyEvent &event);
 
290
        void OnCopy(wxCommandEvent &event);
 
291
        void OnIncludeFilter(wxCommandEvent &event);
 
292
        void OnExcludeFilter(wxCommandEvent &event);
 
293
        void OnRemoveFilters(wxCommandEvent &event);
 
294
        void OnAscSort(wxCommandEvent &event);
 
295
        void OnDescSort(wxCommandEvent &event);
 
296
        void OnRemoveSort(wxCommandEvent &event);
 
297
        void OnPaste(wxCommandEvent &event);
 
298
        void OnLabelDoubleClick(wxGridEvent &event);
 
299
        void OnLabelRightClick(wxGridEvent &event);
 
300
        void OnCellRightClick(wxGridEvent &event);
 
301
        void Abort();
 
302
        void OnToggleScratchPad(wxCommandEvent &event);
 
303
        void OnToggleLimitBar(wxCommandEvent &event);
 
304
        void OnToggleToolBar(wxCommandEvent &event);
 
305
        void OnAuiUpdate(wxAuiManagerEvent &event);
 
306
        void OnDefaultView(wxCommandEvent &event);
 
307
 
 
308
        wxAuiManager manager;
 
309
        ctlSQLEditGrid *sqlGrid;
 
310
 
 
311
        frmMain *mainForm;
 
312
        pgConn *connection;
 
313
        pgQueryThread *thread;
 
314
        wxMenu *fileMenu, *editMenu, *viewMenu, *toolsMenu, *helpMenu;
 
315
        ctlMenuToolbar *toolBar;
 
316
        wxComboBox *cbLimit;
 
317
        wxTextCtrl *scratchPad;
 
318
 
 
319
        char relkind;
 
320
        OID relid;
 
321
        bool hasOids;
 
322
        wxString tableName;
 
323
        wxString primaryKeyColNumbers;
 
324
        wxString orderBy;
 
325
        wxString rowFilter;
 
326
        int limit;
 
327
        sqlCell *editorCell;
 
328
        bool closing;
 
329
 
 
330
        DECLARE_EVENT_TABLE()
262
331
};
263
332
 
264
333
 
265
334
class editGridFactoryBase : public contextActionFactory
266
335
{
267
336
public:
268
 
    bool CheckEnable(pgObject *obj);
 
337
        bool CheckEnable(pgObject *obj);
269
338
 
270
339
protected:
271
 
    editGridFactoryBase(menuFactoryList *list) : contextActionFactory(list) { rowlimit = 0; }
272
 
    wxWindow *ViewData(frmMain *form, pgObject *obj, bool filter);
 
340
        editGridFactoryBase(menuFactoryList *list) : contextActionFactory(list)
 
341
        {
 
342
                rowlimit = 0;
 
343
        }
 
344
        wxWindow *ViewData(frmMain *form, pgObject *obj, bool filter);
273
345
        int rowlimit;
 
346
        bool pkAscending;
274
347
};
275
348
 
276
349
 
277
350
class editGridFactory : public editGridFactoryBase
278
351
{
279
352
public:
280
 
    editGridFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
281
 
    wxWindow *StartDialog(frmMain *form, pgObject *obj);
 
353
        editGridFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
 
354
        wxWindow *StartDialog(frmMain *form, pgObject *obj);
282
355
};
283
356
 
284
357
 
285
358
class editGridFilteredFactory : public editGridFactoryBase
286
359
{
287
360
public:
288
 
    editGridFilteredFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
289
 
    wxWindow *StartDialog(frmMain *form, pgObject *obj);
 
361
        editGridFilteredFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
 
362
        wxWindow *StartDialog(frmMain *form, pgObject *obj);
290
363
};
291
364
 
292
365
class editGridLimitedFactory : public editGridFactoryBase
293
366
{
294
367
public:
295
 
        editGridLimitedFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar, int limit);
 
368
        editGridLimitedFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar, int limit, bool ascending);
296
369
        wxWindow *StartDialog(frmMain *form, pgObject *obj);
297
370
};
298
371