34
ctlSQLGrid::ctlSQLGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size)
35
: wxGrid(parent, id, pos, size, wxWANTS_CHARS|wxVSCROLL|wxHSCROLL)
38
wxFont fntCells(settings->GetSQLFont());
39
SetDefaultCellFont(fntCells);
41
wxFont fntLabel(settings->GetSystemFont());
42
fntLabel.SetWeight(wxBOLD);
43
SetLabelFont(fntLabel);
44
SetColLabelAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
46
SetColLabelSize(fntLabel.GetPointSize() *4);
47
SetDefaultCellOverflow(false);
49
wxAcceleratorEntry entries[1];
50
entries[0].Set(wxACCEL_CTRL, (int)'C', MNU_COPY);
51
wxAcceleratorTable accel(1, entries);
52
SetAcceleratorTable(accel);
54
Connect(wxID_ANY, wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEventHandler(ctlSQLGrid::OnLabelDoubleClick));
57
void ctlSQLGrid::OnCopy(wxCommandEvent& ev)
38
ctlSQLGrid::ctlSQLGrid(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size)
39
: wxGrid(parent, id, pos, size, wxWANTS_CHARS | wxVSCROLL | wxHSCROLL)
42
wxFont fntCells(settings->GetSQLFont());
43
SetDefaultCellFont(fntCells);
45
wxFont fntLabel(settings->GetSystemFont());
46
fntLabel.SetWeight(wxBOLD);
47
SetLabelFont(fntLabel);
48
SetColLabelAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
50
SetColLabelSize(fntLabel.GetPointSize() * 4);
51
SetDefaultCellOverflow(false);
53
wxAcceleratorEntry entries[1];
54
entries[0].Set(wxACCEL_CTRL, (int)'C', MNU_COPY);
55
wxAcceleratorTable accel(1, entries);
56
SetAcceleratorTable(accel);
58
Connect(wxID_ANY, wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEventHandler(ctlSQLGrid::OnLabelDoubleClick));
61
void ctlSQLGrid::OnCopy(wxCommandEvent &ev)
66
void ctlSQLGrid::OnMouseWheel(wxMouseEvent &event)
68
if (event.ControlDown())
70
wxFont fontlabel = GetLabelFont();
71
wxFont fontcells = GetDefaultCellFont();
72
if (event.GetWheelRotation() > 0)
74
fontlabel.SetPointSize(fontlabel.GetPointSize() - 1);
75
fontcells.SetPointSize(fontcells.GetPointSize() - 1);
79
fontlabel.SetPointSize(fontlabel.GetPointSize() + 1);
80
fontcells.SetPointSize(fontcells.GetPointSize() + 1);
82
SetLabelFont(fontlabel);
83
SetDefaultCellFont(fontcells);
84
SetColLabelSize(fontlabel.GetPointSize() * 4);
85
SetDefaultRowSize(fontcells.GetPointSize() * 2);
86
for (int index = 0; index < GetNumberCols(); index++)
87
SetColSize(index, -1);
62
94
wxString ctlSQLGrid::GetExportLine(int row)
64
return GetExportLine(row, 0, GetNumberCols() - 1);
96
return GetExportLine(row, 0, GetNumberCols() - 1);
68
100
wxString ctlSQLGrid::GetExportLine(int row, int col1, int col2)
77
cols.Alloc(col2 - col1 + 1);
78
for (i = col1; i <= col2; i++)
109
cols.Alloc(col2 - col1 + 1);
110
for (i = col1; i <= col2; i++)
83
return GetExportLine(row, cols);
115
return GetExportLine(row, cols);
86
118
wxString ctlSQLGrid::GetExportLine(int row, wxArrayInt cols)
91
if (GetNumberCols() == 0)
94
for (col=0 ; col < cols.Count() ; col++)
97
str.Append(settings->GetCopyColSeparator());
99
wxString text = GetCellValue(row, cols[col]);
123
if (GetNumberCols() == 0)
126
for (col = 0 ; col < cols.Count() ; col++)
129
str.Append(settings->GetCopyColSeparator());
131
wxString text = GetCellValue(row, cols[col]);
101
133
bool needQuote = false;
102
134
if (settings->GetCopyQuoting() == 1)
104
needQuote = IsColText(cols[col]);
136
needQuote = IsColText(cols[col]);
106
138
else if (settings->GetCopyQuoting() == 2)
107
139
/* Quote everything */
108
140
needQuote = true;
111
str.Append(settings->GetCopyQuoteChar());
114
str.Append(settings->GetCopyQuoteChar());
143
str.Append(settings->GetCopyQuoteChar());
146
str.Append(settings->GetCopyQuoteChar());
119
151
int ctlSQLGrid::Copy()
125
if (GetSelectedRows().GetCount())
127
wxArrayInt rows = GetSelectedRows();
129
for (i=0 ; i < rows.GetCount() ; i++)
131
str.Append(GetExportLine(rows.Item(i)));
133
if (rows.GetCount() > 1)
134
str.Append(END_OF_LINE);
137
copied = rows.GetCount();
139
else if (GetSelectedCols().GetCount())
141
wxArrayInt cols = GetSelectedCols();
142
size_t numRows = GetNumberRows();
144
for (i=0 ; i < numRows ; i++)
146
str.Append(GetExportLine(i, cols));
149
str.Append(END_OF_LINE);
154
else if (GetSelectionBlockTopLeft().GetCount() > 0 &&
155
GetSelectionBlockBottomRight().GetCount() > 0)
157
unsigned int x1, x2, y1, y2;
159
x1 = GetSelectionBlockTopLeft()[0].GetCol();
160
x2 = GetSelectionBlockBottomRight()[0].GetCol();
161
y1 = GetSelectionBlockTopLeft()[0].GetRow();
162
y2 = GetSelectionBlockBottomRight()[0].GetRow();
164
for (i = y1; i <= y2; i++)
166
str.Append(GetExportLine(i, x1, x2));
169
str.Append(END_OF_LINE);
172
copied = y2 - y1 + 1;
178
row = GetGridCursorRow();
179
col = GetGridCursorCol();
181
str.Append(GetExportLine(row, col, col));
185
if (copied && wxTheClipboard->Open())
187
wxTheClipboard->SetData(new wxTextDataObject(str));
188
wxTheClipboard->Close();
157
if (GetSelectedRows().GetCount())
159
wxArrayInt rows = GetSelectedRows();
161
for (i = 0 ; i < rows.GetCount() ; i++)
163
str.Append(GetExportLine(rows.Item(i)));
165
if (rows.GetCount() > 1)
166
str.Append(END_OF_LINE);
169
copied = rows.GetCount();
171
else if (GetSelectedCols().GetCount())
173
wxArrayInt cols = GetSelectedCols();
174
size_t numRows = GetNumberRows();
176
for (i = 0 ; i < numRows ; i++)
178
str.Append(GetExportLine(i, cols));
181
str.Append(END_OF_LINE);
186
else if (GetSelectionBlockTopLeft().GetCount() > 0 &&
187
GetSelectionBlockBottomRight().GetCount() > 0)
189
unsigned int x1, x2, y1, y2;
191
x1 = GetSelectionBlockTopLeft()[0].GetCol();
192
x2 = GetSelectionBlockBottomRight()[0].GetCol();
193
y1 = GetSelectionBlockTopLeft()[0].GetRow();
194
y2 = GetSelectionBlockBottomRight()[0].GetRow();
196
for (i = y1; i <= y2; i++)
198
str.Append(GetExportLine(i, x1, x2));
201
str.Append(END_OF_LINE);
204
copied = y2 - y1 + 1;
210
row = GetGridCursorRow();
211
col = GetGridCursorCol();
213
str.Append(GetExportLine(row, col, col));
217
if (copied && wxTheClipboard->Open())
219
wxTheClipboard->SetData(new wxTextDataObject(str));
220
wxTheClipboard->Close();
197
#define EXTRAEXTENT_HEIGHT 6
198
#define EXTRAEXTENT_WIDTH 6
200
void ctlSQLGrid::OnLabelDoubleClick(wxGridEvent& event)
230
void ctlSQLGrid::OnLabelDoubleClick(wxGridEvent &event)
202
int maxHeight, maxWidth;
203
GetClientSize(&maxWidth, &maxHeight);
204
int row = event.GetRow();
205
int col = event.GetCol();
207
int extent, extentWant=0;
211
for (col=0 ; col < GetNumberCols() ; col++)
213
extent = GetBestSize(row, col).GetHeight();
214
if (extent > extentWant)
218
extentWant += EXTRAEXTENT_HEIGHT;
219
extentWant = wxMax(extentWant, GetRowMinimalAcceptableHeight());
220
extentWant = wxMin(extentWant, maxHeight*3/4);
221
int currentHeight = GetRowHeight(row);
223
if (currentHeight >= maxHeight*3/4 || currentHeight == extentWant)
224
extentWant = GetRowMinimalAcceptableHeight();
225
else if (currentHeight < maxHeight/4)
226
extentWant = wxMin(maxHeight/4, extentWant);
227
else if (currentHeight < maxHeight/2)
228
extentWant = wxMin(maxHeight/2, extentWant);
229
else if (currentHeight < maxHeight*3/4)
230
extentWant = wxMin(maxHeight*3/4, extentWant);
232
if (extentWant != currentHeight)
235
if(IsCellEditControlShown())
237
HideCellEditControl();
238
SaveEditControlValue();
241
SetRowHeight(row, extentWant);
247
for (row=0 ; row < GetNumberRows() ; row++)
249
if (CheckRowPresent(row))
251
extent = GetBestSize(row, col).GetWidth();
252
if (extent > extentWant)
257
extentWant += EXTRAEXTENT_WIDTH;
258
extentWant = wxMax(extentWant, GetColMinimalAcceptableWidth());
259
extentWant = wxMin(extentWant, maxWidth*3/4);
260
int currentWidth=GetColumnWidth(col);
262
if (currentWidth >= maxWidth*3/4 || currentWidth == extentWant)
263
extentWant = GetColMinimalAcceptableWidth();
264
else if (currentWidth < maxWidth/4)
265
extentWant = wxMin(maxWidth/4, extentWant);
266
else if (currentWidth < maxWidth/2)
267
extentWant = wxMin(maxWidth/2, extentWant);
268
else if (currentWidth < maxWidth*3/4)
269
extentWant = wxMin(maxWidth*3/4, extentWant);
271
if (extentWant != currentWidth)
274
if(IsCellEditControlShown())
276
HideCellEditControl();
277
SaveEditControlValue();
279
SetColumnWidth(col, extentWant);
232
int maxHeight, maxWidth;
233
GetClientSize(&maxWidth, &maxHeight);
234
int row = event.GetRow();
235
int col = event.GetCol();
237
int extent, extentWant = 0;
241
for (col = 0 ; col < GetNumberCols() ; col++)
243
extent = GetBestSize(row, col).GetHeight();
244
if (extent > extentWant)
248
extentWant += EXTRAEXTENT_HEIGHT;
249
extentWant = wxMax(extentWant, GetRowMinimalAcceptableHeight());
250
extentWant = wxMin(extentWant, maxHeight * 3 / 4);
251
int currentHeight = GetRowHeight(row);
253
if (currentHeight >= maxHeight * 3 / 4 || currentHeight == extentWant)
254
extentWant = GetRowMinimalAcceptableHeight();
255
else if (currentHeight < maxHeight / 4)
256
extentWant = wxMin(maxHeight / 4, extentWant);
257
else if (currentHeight < maxHeight / 2)
258
extentWant = wxMin(maxHeight / 2, extentWant);
259
else if (currentHeight < maxHeight * 3 / 4)
260
extentWant = wxMin(maxHeight * 3 / 4, extentWant);
262
if (extentWant != currentHeight)
265
if(IsCellEditControlShown())
267
HideCellEditControl();
268
SaveEditControlValue();
271
SetRowHeight(row, extentWant);
277
for (row = 0 ; row < GetNumberRows() ; row++)
279
if (CheckRowPresent(row))
281
extent = GetBestSize(row, col).GetWidth();
282
if (extent > extentWant)
287
extentWant += EXTRAEXTENT_WIDTH;
288
extentWant = wxMax(extentWant, GetColMinimalAcceptableWidth());
289
extentWant = wxMin(extentWant, maxWidth * 3 / 4);
290
int currentWidth = GetColumnWidth(col);
292
if (currentWidth >= maxWidth * 3 / 4 || currentWidth == extentWant)
293
extentWant = GetColMinimalAcceptableWidth();
294
else if (currentWidth < maxWidth / 4)
295
extentWant = wxMin(maxWidth / 4, extentWant);
296
else if (currentWidth < maxWidth / 2)
297
extentWant = wxMin(maxWidth / 2, extentWant);
298
else if (currentWidth < maxWidth * 3 / 4)
299
extentWant = wxMin(maxWidth * 3 / 4, extentWant);
301
if (extentWant != currentWidth)
304
if(IsCellEditControlShown())
306
HideCellEditControl();
307
SaveEditControlValue();
309
SetColumnWidth(col, extentWant);
285
315
wxSize ctlSQLGrid::GetBestSize(int row, int col)
289
wxGridCellAttr* attr = GetCellAttr(row, col);
290
wxGridCellRenderer* renderer = attr->GetRenderer(this, row, col);
293
wxClientDC dc(GetGridWindow());
294
size = renderer->GetBestSize(*this, *attr, dc, row, col);
319
wxGridCellAttr *attr = GetCellAttr(row, col);
320
wxGridCellRenderer *renderer = attr->GetRenderer(this, row, col);
323
wxClientDC dc(GetGridWindow());
324
size = renderer->GetBestSize(*this, *attr, dc, row, col);