1
//////////////////////////////////////////////////////////////////////////
3
// pgAdmin III - PostgreSQL Tools
4
// RCS-ID: $Id: gqbGridRestTable.cpp 7758 2009-03-26 20:49:59Z dpage $
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
6
// This software is released under the BSD Licence
8
// gqbGridRestTable.cpp - Table implementation for Restrictions Panel Grid
10
//////////////////////////////////////////////////////////////////////////
17
#include <wx/settings.h>
19
#include <wx/notebook.h>
22
#include "gqb/gqbGridRestTable.h"
23
#include "gqb/gqbColumn.h"
24
#include "gqb/gqbQueryObjs.h"
25
#include "gqb/gqbViewPanels.h"
27
gqbGridRestTable::gqbGridRestTable(gqbRestrictions *_restrictions):
30
restrictions=_restrictions;
34
gqbGridRestTable::~gqbGridRestTable()
39
int gqbGridRestTable::GetNumberRows()
41
return (restrictions->restrictionsCount());
45
int gqbGridRestTable::GetNumberCols()
51
bool gqbGridRestTable::IsEmptyCell( int row, int col )
54
int count=restrictions->restrictionsCount();
62
wxString gqbGridRestTable::GetValue( int row, int col )
67
return ((gqbQueryRestriction*)restrictions->getRestrictionAt(row))->getLeft();
70
return ((gqbQueryRestriction*)restrictions->getRestrictionAt(row))->getRestriction();
73
return ((gqbQueryRestriction*)restrictions->getRestrictionAt(row))->getValue_s();
76
return ((gqbQueryRestriction*)restrictions->getRestrictionAt(row))->getConnector();
84
wxString gqbGridRestTable::GetColLabelValue( int col)
89
return _("Restricted Value");
98
return _("Connector");
105
void gqbGridRestTable::SetValue( int row, int col, const wxString& value )
110
((gqbQueryRestriction*)restrictions->getRestrictionAt(row))->setLeft(value);
113
((gqbQueryRestriction*)restrictions->getRestrictionAt(row))->setRestriction(value);
116
((gqbQueryRestriction*)restrictions->getRestrictionAt(row))->setValue_s(value);
119
((gqbQueryRestriction*)restrictions->getRestrictionAt(row))->setConnector(value);
125
void gqbGridRestTable::AppendItem(gqbQueryRestriction *item)
129
restrictions->addRestriction(item);
131
if (notify && GetView() )
133
wxGridTableMessage msg( this,
134
wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
135
(restrictions->restrictionsCount()-1),
137
GetView()->ProcessTableMessage( msg );
143
bool gqbGridRestTable::DeleteRows(size_t pos = 0, size_t numRows = 1)
145
if(pos>=0 && numRows==1)
147
gqbQueryRestriction *r=restrictions->getRestrictionAt(pos);
148
restrictions->removeRestriction(r);
150
// Notify Grid about the change
153
wxGridTableMessage msg( this,
154
wxGRIDTABLE_NOTIFY_ROWS_DELETED,
157
GetView()->ProcessTableMessage( msg );
168
// Removes all items from gqbGridTable
169
void gqbGridRestTable::emptyTableData()
172
int count=restrictions->restrictionsCount();
173
restrictions->deleteAllRestrictions();
175
if ( GetView() ) //Notify Grid about the change
177
wxGridTableMessage msg( this,
178
wxGRIDTABLE_NOTIFY_ROWS_DELETED,
181
GetView()->ProcessTableMessage( msg );
187
// Cell rendering utilities classes
190
void wxGridCellComboBoxRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
191
const wxRect& rectCell, int row, int col, bool isSelected)
193
wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
195
// first calculate button size
196
// don't draw outside the cell
197
int nButtonWidth = 17;
198
if (rectCell.height < 2) return;
200
rectButton.x = rectCell.x + rectCell.width - nButtonWidth;
201
rectButton.y = rectCell.y + 1;
202
int cell_rows, cell_cols;
203
attr.GetSize(&cell_rows, &cell_cols);
204
rectButton.width = nButtonWidth;
206
rectButton.height = rectCell.height-2;
208
rectButton.height = nButtonWidth;
210
SetTextColoursAndFont(grid, attr, dc, isSelected);
212
attr.GetAlignment(&hAlign, &vAlign);
214
// Leave room for button
215
wxRect rect = rectCell;
216
rect.SetWidth(rectCell.GetWidth() - rectButton.GetWidth()-2);
218
grid.DrawTextRectangle(dc, grid.GetCellValue(row, col), rect, hAlign, vAlign);
220
// Don't bother drawing if the cell is too small
221
if (rectButton.height < 4 || rectButton.width < 4)
225
wxColour colourBackGround = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
226
dc.SetBrush(wxBrush(colourBackGround, wxSOLID));
227
dc.SetPen(wxPen(colourBackGround, 1, wxSOLID));
228
dc.DrawRectangle(rectButton);
229
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID));
230
dc.DrawLine(rectButton.GetLeft(), rectButton.GetBottom(),
231
rectButton.GetRight(), rectButton.GetBottom());
232
dc.DrawLine(rectButton.GetRight(), rectButton.GetBottom(),
233
rectButton.GetRight(), rectButton.GetTop()-1);
234
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW),
236
dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetBottom()-1,
237
rectButton.GetRight()-1, rectButton.GetBottom()-1);
238
dc.DrawLine(rectButton.GetRight()-1, rectButton.GetBottom()-1,
239
rectButton.GetRight()-1, rectButton.GetTop());
240
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT),
242
dc.DrawLine(rectButton.GetRight()-2, rectButton.GetTop()+1,
243
rectButton.GetLeft()+1, rectButton.GetTop()+1);
244
dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetTop()+1,
245
rectButton.GetLeft()+1, rectButton.GetBottom()-1);
247
// Draw little triangle
251
point[0] = wxPoint(rectButton.GetLeft() + (rectButton.GetWidth()-nTriWidth)/2,
252
rectButton.GetTop()+(rectButton.GetHeight()-nTriHeight)/2);
253
point[1] = wxPoint(point[0].x+nTriWidth-1, point[0].y);
254
point[2] = wxPoint(point[0].x+3, point[0].y+nTriHeight-1);
255
dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), wxSOLID));
256
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID));
257
dc.DrawPolygon(3, point);
258
if (m_border == wxLAYOUT_TOP)
260
dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
261
dc.DrawLine(rectCell.GetRight(), rectCell.GetTop(),
262
rectCell.GetLeft(), rectCell.GetTop());
267
void wxGridCellButtonRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
268
const wxRect& rectCell, int row, int col, bool isSelected)
270
wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
272
// First calculate button size
273
// don't draw outside the cell
274
int nButtonWidth = 17;
275
if (rectCell.height < 2) return;
277
rectButton.x = rectCell.x + rectCell.width - nButtonWidth;
278
rectButton.y = rectCell.y + 1;
279
int cell_rows, cell_cols;
280
attr.GetSize(&cell_rows, &cell_cols);
281
rectButton.width = nButtonWidth;
283
rectButton.height = rectCell.height-2;
285
rectButton.height = nButtonWidth;
287
SetTextColoursAndFont(grid, attr, dc, isSelected);
289
attr.GetAlignment(&hAlign, &vAlign);
291
// Leave room for button
292
wxRect rect = rectCell;
293
rect.SetWidth(rectCell.GetWidth() - rectButton.GetWidth()-2);
295
grid.DrawTextRectangle(dc, grid.GetCellValue(row, col), rect, hAlign, vAlign);
298
// Don't bother drawing if the cell is too small draw 3-d button
299
if (rectButton.height < 4 || rectButton.width < 4)
302
wxColour colourBackGround = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
303
dc.SetBrush(wxBrush(colourBackGround, wxSOLID));
304
dc.SetPen(wxPen(colourBackGround, 1, wxSOLID));
305
dc.DrawRectangle(rectButton);
306
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID));
307
dc.DrawLine(rectButton.GetLeft(), rectButton.GetBottom(),
308
rectButton.GetRight(), rectButton.GetBottom());
309
dc.DrawLine(rectButton.GetRight(), rectButton.GetBottom(),
310
rectButton.GetRight(), rectButton.GetTop()-1);
311
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW),
313
dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetBottom()-1,
314
rectButton.GetRight()-1, rectButton.GetBottom()-1);
315
dc.DrawLine(rectButton.GetRight()-1, rectButton.GetBottom()-1,
316
rectButton.GetRight()-1, rectButton.GetTop());
317
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT),
319
dc.DrawLine(rectButton.GetRight()-2, rectButton.GetTop()+1,
320
rectButton.GetLeft()+1, rectButton.GetTop()+1);
321
dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetTop()+1,
322
rectButton.GetLeft()+1, rectButton.GetBottom()-1);
324
// Draw little plus symbol
325
dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), wxSOLID));
326
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID));
330
point[0] = wxPoint(rectButton.GetLeft() + (rectButton.GetWidth()-nPlusWidth)/2, rectButton.GetTop()+(rectButton.GetHeight()/2)-1);
331
point[1] = wxPoint(point[0].x+nPlusWidth, point[0].y);
332
point[2] = wxPoint(rectButton.GetLeft() + (rectButton.GetWidth())/2, rectButton.GetTop()+(rectButton.GetHeight()-nPlusHeight)/2);
333
point[3] = wxPoint(point[2].x,point[2].y+nPlusHeight);
334
dc.DrawLine(point[0],point[1]);
335
dc.DrawLine(point[2],point[3]);
337
if (m_border == wxLAYOUT_TOP)
339
dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
340
dc.DrawLine(rectCell.GetRight(), rectCell.GetTop(),
341
rectCell.GetLeft(), rectCell.GetTop());
347
// Cell editing utilities classes
349
dxGridCellSizedChoiceEditor::dxGridCellSizedChoiceEditor(const wxArrayString& choices, bool allowOthers)
350
:wxGridCellChoiceEditor(choices,allowOthers)
355
dxGridCellSizedChoiceEditor::dxGridCellSizedChoiceEditor(size_t count, const wxString choices[], bool allowOthers)
356
:wxGridCellChoiceEditor(count,choices, allowOthers)
361
wxGridCellEditor *dxGridCellSizedChoiceEditor::Clone() const
363
dxGridCellSizedChoiceEditor *editor = new
364
dxGridCellSizedChoiceEditor();
369
void dxGridCellSizedChoiceEditor::Show(bool show, wxGridCellAttr *attr)
371
wxGridCellEditor::Show(show, attr);