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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
/*---------------------------------------------------------------------------*/
/* Logiciel de gestion de fichier de base de donnesSQLite */
/*---------------------------------------------------------------------------*/
/* Projet : wxSQLitePlus Version : 0.3.0.0 */
/* Fichier : specgrid.h */
/* Auteur : Fred Cailleau-Lepetit Date : 07/09/2007 */
/* email : softinthebox@free.fr Rvision : 01/03/2009 */
/*---------------------------------------------------------------------------*/
/* Copyright (C) Fred Cailleau-Lepetit 2007 */
/* Licence GNU General Public License http://www.fsf.org/copyleft/gpl.html */
/*---------------------------------------------------------------------------*/
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation (version 3).
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Ce programme est libre, vous pouvez le redistribuer et/ou le modifier
selon les termes de la Licence Publique Gnrale GNU publie par la
Free Software Foundation (version 3).
Ce programme est distribu car potentiellement utile, mais
SANS AUCUNE GARANTIE, ni explicite ni implicite, y compris
les garanties de commercialisation ou d'adaptation dans un but
spcifique. Reportez-vous la Licence Publique Gnrale GNU
pour plus de dtails.
*/
#ifndef _SPECGRID_H_
#define _SPECGRID_H_
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma interface "specgrid.h"
#endif
/*---------------------------------------------------------------------------*/
#include <wx/grid.h>
#include <wx/generic/gridctrl.h>
#include <wx/dynarray.h>
#include <wx/arrimpl.cpp>
/*---------------------------------------------------------------------------*/
#ifdef WXMAKINGDLL_WXSCPECGRID
#define WXDLLIMPEXP_SCPECGRID WXEXPORT
#elif defined(WXUSINGDLL_WXSCPECGRID)
#define WXDLLIMPEXP_SCPECGRID WXIMPORT
#else // not making nor using DLL
#define WXDLLIMPEXP_SCPECGRID
#endif
/*---------------------------------------------------------------------------*/
class wxSQLite3Database;
class WXDLLIMPEXP_SCPECGRID wxGridCellBlobEditorEvent;
/*---------------------------------------------------------------------------*/
class WXDLLIMPEXP_SCPECGRID wxCellsBlock
{
public:
wxCellsBlock()
{
m_LeftTop.Set(-1, -1);
m_RightBottom.Set(-1, -1);
}
wxCellsBlock(int left, int top, int right, int bottom)
{
m_LeftTop.Set(top, left);
m_RightBottom.Set(bottom, right);
}
wxCellsBlock(const wxGridCellCoords& topleft,
const wxGridCellCoords& bottomright)
{
m_LeftTop = topleft;
m_RightBottom = bottomright;
}
wxCellsBlock(const wxCellsBlock& cellsblock)
{
m_LeftTop = cellsblock.m_LeftTop;
m_RightBottom = cellsblock.m_RightBottom;
}
bool IsOk(){return (m_LeftTop.GetRow() < 0)||
(m_RightBottom.GetRow() < 0)||
(m_LeftTop.GetCol() < 0)||
(m_RightBottom.GetCol() < 0);}
inline wxCellsBlock& operator=(const wxCellsBlock& cellsblock)
{
m_LeftTop = cellsblock.m_LeftTop;
m_RightBottom = cellsblock.m_RightBottom;
return *this;
}
inline bool operator<(const wxCellsBlock& cellsblock) const
{
return (m_LeftTop.GetRow() < cellsblock.m_LeftTop.GetRow())||
((m_LeftTop.GetRow() == cellsblock.m_LeftTop.GetRow())&&
(m_RightBottom.GetCol() < cellsblock.m_RightBottom.GetCol()));
}
inline bool operator>(const wxCellsBlock& cellsblock) const
{
return (m_LeftTop.GetRow() > cellsblock.m_LeftTop.GetRow())||
((m_LeftTop.GetRow() == cellsblock.m_LeftTop.GetRow())&&
(m_RightBottom.GetCol() > cellsblock.m_RightBottom.GetCol()));
}
inline bool operator<=(const wxCellsBlock& cellsblock) const
{
return (m_LeftTop.GetRow() < cellsblock.m_LeftTop.GetRow())||
((m_LeftTop.GetRow() == cellsblock.m_LeftTop.GetRow())&&
(m_RightBottom.GetCol() <= cellsblock.m_RightBottom.GetCol()));
}
inline bool operator>=(const wxCellsBlock& cellsblock) const
{
return (m_LeftTop.GetRow() > cellsblock.m_LeftTop.GetRow())||
((m_LeftTop.GetRow() == cellsblock.m_LeftTop.GetRow())&&
(m_RightBottom.GetCol() >= cellsblock.m_RightBottom.GetCol()));
}
inline bool operator==(const wxCellsBlock& cellsblock) const
{
return (m_LeftTop.GetCol() == cellsblock.m_LeftTop.GetCol())&&
(m_LeftTop.GetRow() == cellsblock.m_LeftTop.GetRow())&&
(m_RightBottom.GetCol() == cellsblock.m_RightBottom.GetCol())&&
(m_RightBottom.GetRow() == cellsblock.m_RightBottom.GetRow());
}
wxGridCellCoords GetLeftTop(){return m_LeftTop;}
wxGridCellCoords GetRightBottom(){return m_RightBottom;}
int GetLeft(){return m_LeftTop.GetCol();}
int GetTop(){return m_LeftTop.GetRow();}
int GetRight(){return m_RightBottom.GetCol();}
int GetBottom(){return m_RightBottom.GetRow();}
private:
wxGridCellCoords m_LeftTop;
wxGridCellCoords m_RightBottom;
};
/*---------------------------------------------------------------------------*/
WX_DECLARE_OBJARRAY(wxCellsBlock, wxArrayOfCellsBlock);
/*---------------------------------------------------------------------------*/
class WXDLLIMPEXP_SCPECGRID wxSpecGrid : public wxGrid
{
DECLARE_DYNAMIC_CLASS(wxSpecGrid)
DECLARE_EVENT_TABLE()
public:
wxSpecGrid() : wxGrid(){}
virtual ~wxSpecGrid(){}
wxSpecGrid(wxWindow* parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxWANTS_CHARS,
const wxString& name = wxPanelNameStr) : wxGrid(parent, id,
pos, size,
style, name){}
void SetDefaultSelection(int row = -1, int col = -1);
bool HasFocus();
protected:
void OnCopy(wxCommandEvent& event);
void OnCopyUpdate(wxUpdateUIEvent& event);
void OnSelectAll(wxCommandEvent& event);
void OnSelectAllUpdate(wxUpdateUIEvent& event);
void OnRightDown(wxGridEvent& event);
void OnSelectCell(wxGridEvent& event);
void OnBlodEdit(wxGridCellBlobEditorEvent& event);
virtual wxMenu* CreateRightMenu();
private:
wxString GetDataBlock(const wxGridCellCoords& topleft,
const wxGridCellCoords& bottomright);
wxString GetDataBlock(const wxArrayOfCellsBlock& array);
};
/*---------------------------------------------------------------------------*/
class WXDLLIMPEXP_SCPECGRID wxDataGrid : public wxSpecGrid
{
DECLARE_DYNAMIC_CLASS(wxDataGrid)
DECLARE_EVENT_TABLE()
public:
wxDataGrid() : wxSpecGrid()
{m_IsFiltered = m_IsSorted = false;}
virtual ~wxDataGrid(){}
wxDataGrid(wxWindow* parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize) :
wxSpecGrid(parent, id, pos, size, wxHSCROLL|wxVSCROLL)
{m_IsFiltered = m_IsSorted = false;}
void SetDbTableViewName(wxSQLite3Database* db,
const wxString objectname,
const wxString& base = wxEmptyString);
void DoRefresh(bool usefilter = false);
void DoSort();
void DoFilter();
bool IsFiltered(){return m_IsFiltered;}
bool IsSorted(){return m_IsSorted;}
protected:
void OnFilter(wxCommandEvent& event);
void OnSort(wxCommandEvent& event);
void OnRefresh(wxCommandEvent& event);
void OnFilterSortUpdate(wxUpdateUIEvent& event);
virtual wxMenu* CreateRightMenu();
private:
wxSQLite3Database* m_db;
wxString m_Base;
wxString m_TableViewName;
wxArrayString m_StringsOrder;
wxString m_StringWhere;
bool m_IsFiltered;
bool m_IsSorted;
};
/*---------------------------------------------------------------------------*/
class WXDLLIMPEXP_SCPECGRID wxGridCellBlobRenderer : public wxGridCellStringRenderer
{
public:
wxGridCellBlobRenderer(bool displaynullvalue = true,
const wxString& defaultstring = _T("(blob)"));
virtual void Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
const wxRect& rect, int row, int col, bool isSelected);
virtual wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr,
wxDC& dc, int row, int col);
protected:
wxString GetString(const wxGrid& grid, int row, int col);
private:
bool m_IsNullValueDisplayed;
wxString m_DefaultString;
};
/*---------------------------------------------------------------------------*/
class WXDLLIMPEXP_SCPECGRID wxGridCellBlobEditor : public wxGridCellEditor, public wxEvtHandler
{
DECLARE_EVENT_TABLE()
public:
wxGridCellBlobEditor();
virtual void Create(wxWindow* parent, wxWindowID id,
wxEvtHandler* evtHandler);
virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
virtual void BeginEdit(int row, int col, wxGrid* grid);
#if wxCHECK_VERSION(2,9,0)
virtual bool EndEdit(int row, int col, const wxGrid* grid,
const wxString& oldval, wxString* newval);
virtual void ApplyEdit(int row, int col, wxGrid* grid);
#else
virtual bool EndEdit(int row, int col, wxGrid* grid);
#endif
virtual void Reset();
virtual wxGridCellEditor *Clone() const;
virtual wxString GetValue() const;
virtual void SetSize(const wxRect& rectOrig);
protected:
void OnBtnClick(wxCommandEvent& event);
private:
int m_Row;
int m_Col;
wxGrid* m_Grid;
};
/*---------------------------------------------------------------------------*/
class WXDLLIMPEXP_SCPECGRID wxGridCellBlobEditorEvent : public wxNotifyEvent
{
DECLARE_DYNAMIC_CLASS(wxGridCellBlobEditorEvent)
public:
wxGridCellBlobEditorEvent(wxEventType commandType = 0, int id = 0);
wxGridCellBlobEditorEvent(const wxGridCellBlobEditorEvent& event);
~wxGridCellBlobEditorEvent() {}
void SetRow(int val) {m_Row = val;}
void SetCol(int val) {m_Col = val;}
void SetGrid(wxGrid* val) {m_Grid = val;}
int GetRow() const {return m_Row;}
int GetCol() const {return m_Col;}
wxGrid* GetGrid() const {return m_Grid;}
virtual wxEvent* Clone() const {return new wxGridCellBlobEditorEvent(*this);}
private:
int m_Row; // Row number
int m_Col; // Col number
wxGrid* m_Grid; // Grid control
};
/*---------------------------------------------------------------------------*/
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_SCPECGRID, wxEVT_GRID_BLOBEDIT, 1670) // wxGridCellBlobEditorEventFunction
END_DECLARE_EVENT_TYPES()
typedef void (wxEvtHandler::*wxGridCellBlobEditorEventFunction)(wxGridCellBlobEditorEvent&);
#define EVT_GRID_BLOBEDIT(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_GRID_BLOBEDIT, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridCellBlobEditorEventFunction, & fn ), (wxObject *) NULL ),
/*---------------------------------------------------------------------------*/
#endif // _SPECGRID_H_
|