From f7556ff05f5cf0a5be1e494a477fd463db4a9236 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Mon, 24 Mar 2003 18:50:10 +0000 Subject: [PATCH] Removed old grid code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19757 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- Makefile.in | 63 +- configure.in | 13 - distrib/msw/cw.rsp | 1 - distrib/msw/cw_mac.rsp | 2 - distrib/msw/generic.rsp | 12 - distrib/msw/gtk.rsp | 12 - distrib/msw/makefile.rsp | 1 - distrib/msw/motif.rsp | 12 - distrib/msw/vc.rsp | 7 +- distrib/msw/x11.rsp | 12 - include/wx/db.h | 13 +- include/wx/generic/grid.h | 7 +- include/wx/generic/gridctrl.h | 4 +- include/wx/generic/gridg.h | 429 --- include/wx/generic/gridsel.h | 5 +- samples/configure.in | 1 - samples/grid/Makefile.in | 17 +- samples/grid/grid.cpp | 350 --- samples/grid/grid.def | 8 - samples/grid/grid.rc | 5 - samples/grid/griddemo.cpp | 1361 +++++++++ samples/grid/{grid.dsp => griddemo.dsp} | 60 +- samples/grid/griddemo.h | 261 ++ samples/grid/{grid.pro => griddemo.pro} | 6 +- samples/grid/griddemo.rc | 2 + samples/grid/{gridM5.xml => griddemoM5.xml} | 42 +- samples/grid/{gridM7.mcp => griddemoM7.mcp} | Bin samples/grid/makefile.b32 | 15 +- samples/grid/makefile.bcc | 11 +- samples/grid/makefile.dos | 13 +- samples/grid/makefile.g95 | 11 +- samples/grid/makefile.sc | 9 +- samples/grid/makefile.twn | 26 +- samples/grid/makefile.vc | 12 +- samples/grid/makefile.wat | 8 +- samples/makefile.b32 | 4 - samples/makefile.vc | 4 - src/generic/grid.cpp | 8 +- src/generic/gridctrl.cpp | 2 +- src/generic/gridg.cpp | 2858 ------------------- src/generic/gridsel.cpp | 3 +- 41 files changed, 1803 insertions(+), 3887 deletions(-) delete mode 100644 include/wx/generic/gridg.h delete mode 100644 samples/grid/grid.cpp delete mode 100644 samples/grid/grid.def delete mode 100644 samples/grid/grid.rc create mode 100644 samples/grid/griddemo.cpp rename samples/grid/{grid.dsp => griddemo.dsp} (79%) create mode 100644 samples/grid/griddemo.h rename samples/grid/{grid.pro => griddemo.pro} (87%) create mode 100644 samples/grid/griddemo.rc rename samples/grid/{gridM5.xml => griddemoM5.xml} (99%) rename samples/grid/{gridM7.mcp => griddemoM7.mcp} (100%) delete mode 100644 src/generic/gridg.cpp diff --git a/Makefile.in b/Makefile.in index 756cc72895..95aaa8ac0a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -51,13 +51,12 @@ VP7 = @top_srcdir@/src/jpeg VP8 = @top_srcdir@/src/tiff VP9 = @top_srcdir@/src/zlib VPA = @top_srcdir@/src/regex -VP10 = @top_srcdir@/src/iodbc -VP11 = @top_srcdir@/src/msw/ole +VP10 = @top_srcdir@/src/msw/ole # the comment at the end of the next line is needed because otherwise autoconf # would remove this line completely - it contains a built-in hack to remove # any VPATH assignment not containing ':' -VPATH = $(VP1)@PATH_IFS@$(VP2)@PATH_IFS@$(VP3)@PATH_IFS@$(VP4)@PATH_IFS@$(VP5)@PATH_IFS@$(VP6)@PATH_IFS@$(VP7)@PATH_IFS@$(VP8)@PATH_IFS@$(VP9)@PATH_IFS@$(VPA)@PATH_IFS@$(VP10)@PATH_IFS@$(VP11) # ':' for autoconf +VPATH = $(VP1)@PATH_IFS@$(VP2)@PATH_IFS@$(VP3)@PATH_IFS@$(VP4)@PATH_IFS@$(VP5)@PATH_IFS@$(VP6)@PATH_IFS@$(VP7)@PATH_IFS@$(VP8)@PATH_IFS@$(VP9)@PATH_IFS@$(VPA)@PATH_IFS@$(VP10) # ':' for autoconf prefix = @prefix@ exec_prefix = @exec_prefix@ @@ -113,7 +112,7 @@ MSWDIR = $(WXDIR)/src/msw PMDIR = $(WXDIR)/src/os2 MACDIR = $(WXDIR)/src/mac COCOADIR = $(WXDIR)/src/cocoa -ODBCDIR = $(WXDIR)/src/iodbc +# ODBCDIR = $(WXDIR)/src/iodbc FTDIR = $(WXDIR)/src/freetype INCDIR = $(WXDIR)/include SAMPDIR = $(WXDIR)/samples @@ -286,22 +285,22 @@ TIFFOBJS = \ tif_write.o \ tif_zip.o -IODBCOBJS = \ - catalog.o \ - connect.o \ - dlf.o \ - dlproc.o \ - execute.o \ - fetch.o \ - hdbc.o \ - henv.o \ - herr.o \ - hstmt.o \ - info.o \ - itrace.o \ - misc.o \ - prepare.o \ - result.o +# IODBCOBJS = \ +# catalog.o \ +# connect.o \ +# dlf.o \ +# dlproc.o \ +# execute.o \ +# fetch.o \ +# hdbc.o \ +# henv.o \ +# herr.o \ +# hstmt.o \ +# info.o \ +# itrace.o \ +# misc.o \ +# prepare.o \ +# result.o ############################## Rules ################################## @@ -631,7 +630,6 @@ ALL_GUI_DIST: ALL_DIST mkdir $(DISTDIR)/src/png mkdir $(DISTDIR)/src/jpeg mkdir $(DISTDIR)/src/tiff - mkdir $(DISTDIR)/src/iodbc mkdir $(DISTDIR)/src/unix cp $(SRCDIR)/*.in $(DISTDIR)/src cp $(COMMDIR)/*.cpp $(DISTDIR)/src/common @@ -656,13 +654,14 @@ ALL_GUI_DIST: ALL_DIST cp $(TIFFDIR)/*.h $(DISTDIR)/src/tiff cp $(TIFFDIR)/*.c $(DISTDIR)/src/tiff cp $(TIFFDIR)/README $(DISTDIR)/src/tiff - cp $(ODBCDIR)/*.h $(DISTDIR)/src/iodbc - cp $(ODBCDIR)/*.c $(DISTDIR)/src/iodbc - cp $(ODBCDIR)/*.ci $(DISTDIR)/src/iodbc - cp $(ODBCDIR)/*.exp $(DISTDIR)/src/iodbc - cp $(ODBCDIR)/README $(DISTDIR)/src/iodbc - cp $(ODBCDIR)/NEWS $(DISTDIR)/src/iodbc - cp $(ODBCDIR)/Changes.log $(DISTDIR)/src/iodbc + #mkdir $(DISTDIR)/src/iodbc + #cp $(ODBCDIR)/*.h $(DISTDIR)/src/iodbc + #cp $(ODBCDIR)/*.c $(DISTDIR)/src/iodbc + #cp $(ODBCDIR)/*.ci $(DISTDIR)/src/iodbc + #cp $(ODBCDIR)/*.exp $(DISTDIR)/src/iodbc + #cp $(ODBCDIR)/README $(DISTDIR)/src/iodbc + #cp $(ODBCDIR)/NEWS $(DISTDIR)/src/iodbc + #cp $(ODBCDIR)/Changes.log $(DISTDIR)/src/iodbc BASE_DIST: ALL_DIST # make --disable-gui the default @@ -1022,7 +1021,7 @@ SAMPLES_DIST: ALL_GUI_DIST mkdir $(DISTDIR)/samples/grid cp $(SAMPDIR)/grid/Makefile.in $(DISTDIR)/samples/grid cp $(SAMPDIR)/grid/makefile.unx $(DISTDIR)/samples/grid - cp $(SAMPDIR)/grid/*.cpp $(DISTDIR)/samples/grid + cp $(SAMPDIR)/grid/*.cpp $(SAMPDIR)/grid/*.h $(DISTDIR)/samples/grid mkdir $(DISTDIR)/samples/help mkdir $(DISTDIR)/samples/help/doc @@ -1189,12 +1188,6 @@ SAMPLES_DIST: ALL_GUI_DIST cp $(SAMPDIR)/dialup/makefile.unx $(DISTDIR)/samples/dialup cp $(SAMPDIR)/dialup/*.cpp $(DISTDIR)/samples/dialup - mkdir $(DISTDIR)/samples/newgrid - cp $(SAMPDIR)/newgrid/Makefile.in $(DISTDIR)/samples/newgrid - cp $(SAMPDIR)/newgrid/makefile.unx $(DISTDIR)/samples/newgrid - cp $(SAMPDIR)/newgrid/*.cpp $(DISTDIR)/samples/newgrid - cp $(SAMPDIR)/newgrid/*.h $(DISTDIR)/samples/newgrid - mkdir $(DISTDIR)/samples/notebook cp $(SAMPDIR)/notebook/Makefile.in $(DISTDIR)/samples/notebook cp $(SAMPDIR)/notebook/makefile.unx $(DISTDIR)/samples/notebook diff --git a/configure.in b/configure.in index cf965a570d..3f9a95025d 100644 --- a/configure.in +++ b/configure.in @@ -434,7 +434,6 @@ if test $DEBUG_CONFIGURE = 1; then DEFAULT_wxUSE_DISPLAY=no DEFAULT_wxUSE_GAUGE=no DEFAULT_wxUSE_GRID=no - DEFAULT_wxUSE_NEW_GRID=no DEFAULT_wxUSE_IMAGLIST=no DEFAULT_wxUSE_LISTBOX=no DEFAULT_wxUSE_LISTCTRL=no @@ -609,7 +608,6 @@ else DEFAULT_wxUSE_DISPLAY=no DEFAULT_wxUSE_GAUGE=yes DEFAULT_wxUSE_GRID=yes - DEFAULT_wxUSE_NEW_GRID=yes DEFAULT_wxUSE_IMAGLIST=yes DEFAULT_wxUSE_LISTBOX=yes DEFAULT_wxUSE_LISTCTRL=yes @@ -884,7 +882,6 @@ if test "$wxUSE_CONTROLS" = "yes"; then DEFAULT_wxUSE_CHOICE=yes DEFAULT_wxUSE_GAUGE=yes DEFAULT_wxUSE_GRID=yes - DEFAULT_wxUSE_NEW_GRID=yes DEFAULT_wxUSE_IMAGLIST=yes DEFAULT_wxUSE_LISTBOX=yes DEFAULT_wxUSE_LISTCTRL=yes @@ -923,7 +920,6 @@ elif test "$wxUSE_CONTROLS" = "no"; then DEFAULT_wxUSE_CHOICE=no DEFAULT_wxUSE_GAUGE=no DEFAULT_wxUSE_GRID=no - DEFAULT_wxUSE_NEW_GRID=no DEFAULT_wxUSE_IMAGLIST=no DEFAULT_wxUSE_LISTBOX=no DEFAULT_wxUSE_LISTCTRL=no @@ -975,7 +971,6 @@ if test "x$wxUSE_COCOA" != "x" -a "$wxUSE_COCOA" != "0" ; then DEFAULT_wxUSE_FINDREPLDLG=no DEFAULT_wxUSE_FONTDLG=no DEFAULT_wxUSE_GRID=no - DEFAULT_wxUSE_NEW_GRID=no DEFAULT_wxUSE_NUMBERDLG=no DEFAULT_wxUSE_PROGRESSDLG=no DEFAULT_wxUSE_PROPSHEET=no @@ -999,7 +994,6 @@ WX_ARG_ENABLE(combobox, [ --enable-combobox use wxComboBox class], wxU WX_ARG_ENABLE(display, [ --enable-display use wxDisplay class], wxUSE_DISPLAY) WX_ARG_ENABLE(gauge, [ --enable-gauge use wxGauge class], wxUSE_GAUGE) WX_ARG_ENABLE(grid, [ --enable-grid use wxGrid class], wxUSE_GRID) -WX_ARG_ENABLE(newgrid, [ --enable-newgrid use new wxGrid class], wxUSE_NEW_GRID) WX_ARG_ENABLE(imaglist, [ --enable-imaglist use wxImageList class], wxUSE_IMAGLIST) WX_ARG_ENABLE(listbox, [ --enable-listbox use wxListBox class], wxUSE_LISTBOX) WX_ARG_ENABLE(listctrl, [ --enable-listctrl use wxListCtrl class], wxUSE_LISTCTRL) @@ -4863,13 +4857,6 @@ if test "$wxUSE_GAUGE" = "yes"; then USES_CONTROLS=1 fi -if test "$wxUSE_NEW_GRID" = "yes"; then - wxUSE_GRID="yes" - AC_DEFINE(wxUSE_NEW_GRID) - USES_CONTROLS=1 - SAMPLES_SUBDIRS="$SAMPLES_SUBDIRS newgrid" -fi - if test "$wxUSE_GRID" = "yes"; then AC_DEFINE(wxUSE_GRID) USES_CONTROLS=1 diff --git a/distrib/msw/cw.rsp b/distrib/msw/cw.rsp index 108452a03d..82869a191b 100644 --- a/distrib/msw/cw.rsp +++ b/distrib/msw/cw.rsp @@ -57,7 +57,6 @@ samples/minimal/*W7.xml samples/mobile/*W7.xml samples/multimon/*W7.xml samples/nativdlg/*W7.xml -samples/newgrid/*W7.xml samples/notebook/*W7.xml samples/oleauto/*W7.xml samples/opengl/*W7.xml diff --git a/distrib/msw/cw_mac.rsp b/distrib/msw/cw_mac.rsp index 55621df2ff..f1140ac369 100644 --- a/distrib/msw/cw_mac.rsp +++ b/distrib/msw/cw_mac.rsp @@ -101,8 +101,6 @@ samples/multimon/*M?.xml samples/multimon/*.mcp samples/nativdlg/*M?.xml samples/nativdlg/*.mcp -samples/newgrid/*M?.xml -samples/newgrid/*.mcp samples/notebook/*M?.xml samples/notebook/*.mcp samples/oleauto/*M?.xml diff --git a/distrib/msw/generic.rsp b/distrib/msw/generic.rsp index 652c0392d8..1b179cf4ef 100644 --- a/distrib/msw/generic.rsp +++ b/distrib/msw/generic.rsp @@ -819,18 +819,6 @@ samples/multimon/*.ico samples/multimon/*.bmp samples/multimon/*.pro -samples/newgrid/*.cpp -samples/newgrid/*.h -samples/newgrid/*.def -samples/newgrid/*.rc -samples/newgrid/*.txt -samples/newgrid/makefile* -samples/newgrid/*.xbm -samples/newgrid/*.xpm -samples/newgrid/*.ico -samples/newgrid/*.bmp -samples/newgrid/*.pro - samples/notebook/*.cpp samples/notebook/*.h samples/notebook/makefile* diff --git a/distrib/msw/gtk.rsp b/distrib/msw/gtk.rsp index 85a4a392bc..99e06bcd39 100644 --- a/distrib/msw/gtk.rsp +++ b/distrib/msw/gtk.rsp @@ -15,18 +15,6 @@ src/gtk/*.cpp src/gtk/*.c src/gtk/*.xbm -src/iodbc/*.c -src/iodbc/*.ci -src/iodbc/*.h -src/iodbc/IAFA-PACKAGE -src/iodbc/README -src/iodbc/*.exp -src/iodbc/*.mk -src/iodbc/autoconfig -src/iodbc/build -src/iodbc/Changes.log -src/iodbc/postgres/*.h - misc/afm/*.afm misc/gs_afm/*.afm diff --git a/distrib/msw/makefile.rsp b/distrib/msw/makefile.rsp index 72e01745ed..cee12e6042 100644 --- a/distrib/msw/makefile.rsp +++ b/distrib/msw/makefile.rsp @@ -23,7 +23,6 @@ samples/exec/Makefile.in samples/event/Makefile.in samples/grid/Makefile.in samples/keyboard/Makefile.in -samples/newgrid/Makefile.in samples/help/Makefile.in samples/internat/Makefile.in samples/ipc/Makefile.in diff --git a/distrib/msw/motif.rsp b/distrib/msw/motif.rsp index 6650151ec9..b24f5a1132 100644 --- a/distrib/msw/motif.rsp +++ b/distrib/msw/motif.rsp @@ -18,18 +18,6 @@ src/x11/makefile* src/x11/*.inc src/x11/*.xbm -src/iodbc/*.c -src/iodbc/*.ci -src/iodbc/*.h -src/iodbc/IAFA-PACKAGE -src/iodbc/README -src/iodbc/*.exp -src/iodbc/*.mk -src/iodbc/autoconfig -src/iodbc/build -src/iodbc/Changes.log -src/iodbc/postgres/*.h - include/wx/motif/*.h include/wx/x11/*.h diff --git a/distrib/msw/vc.rsp b/distrib/msw/vc.rsp index c9cc4f8cdf..71a22b26c3 100644 --- a/distrib/msw/vc.rsp +++ b/distrib/msw/vc.rsp @@ -93,8 +93,8 @@ samples/exec/exec.dsw samples/font/font.dsp samples/font/font.dsw -samples/grid/grid.dsp -samples/grid/grid.dsw +samples/grid/griddemo.dsp +samples/grid/griddemo.dsw samples/help/help.dsp samples/help/help.dsw @@ -170,9 +170,6 @@ samples/multimon/multimon_test.dsw samples/nativdlg/nativdlg.dsp samples/nativdlg/nativdlg.dsw -samples/newgrid/newgrid.dsp -samples/newgrid/newgrid.dsw - samples/notebook/notebook.dsp samples/notebook/notebook.dsw diff --git a/distrib/msw/x11.rsp b/distrib/msw/x11.rsp index 45b844b8ee..864e3bc340 100644 --- a/distrib/msw/x11.rsp +++ b/distrib/msw/x11.rsp @@ -6,18 +6,6 @@ src/x11/makefile* src/x11/*.inc src/x11/*.xbm -src/iodbc/*.c -src/iodbc/*.ci -src/iodbc/*.h -src/iodbc/IAFA-PACKAGE -src/iodbc/README -src/iodbc/*.exp -src/iodbc/*.mk -src/iodbc/autoconfig -src/iodbc/build -src/iodbc/Changes.log -src/iodbc/postgres/*.h - include/wx/x11/*.h include/wx/x11/nanox/X11/*.h diff --git a/include/wx/db.h b/include/wx/db.h index ecb4f3ab6a..8cd409a0ce 100644 --- a/include/wx/db.h +++ b/include/wx/db.h @@ -76,16 +76,11 @@ #include "sql.h" #include "sqlext.h" #include "odbcinst.h" -#elif defined( __VMS ) - // For OpenVMS use the ones from the library +#else + // Use the ones from the library extern "C" { - #include - #include - } -#else // !__VISUALC__, !__VMS - extern "C" { - #include "wx/isql.h" - #include "wx/isqlext.h" + #include + #include } #endif diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index a09c66fe91..cab62c5661 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -11,10 +11,6 @@ #include "wx/defs.h" -#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) -#include "wx/generic/gridg.h" -#else - #ifndef __WXGRID_H__ #define __WXGRID_H__ @@ -2079,6 +2075,5 @@ extern const int wxEVT_GRID_CHANGE_SEL_LABEL; #endif -#endif // #ifndef __WXGRID_H__ +#endif // ifndef wxUSE_GRID -#endif // ifndef wxUSE_NEW_GRID diff --git a/include/wx/generic/gridctrl.h b/include/wx/generic/gridctrl.h index 3cc0c7e157..b607c32607 100644 --- a/include/wx/generic/gridctrl.h +++ b/include/wx/generic/gridctrl.h @@ -16,7 +16,7 @@ #pragma interface "gridctrl.h" #endif -#if wxUSE_GRID || wxUSE_NEW_GRID +#if wxUSE_GRID #include "wx/grid.h" #include "wx/string.h" @@ -154,7 +154,7 @@ private: }; -#endif // #if wxUSE_GRID || wxUSE_NEW_GRID +#endif // #if wxUSE_GRID #endif //_WX_GENERIC_GRIDCTRL_H_ diff --git a/include/wx/generic/gridg.h b/include/wx/generic/gridg.h deleted file mode 100644 index 86bbb6cd68..0000000000 --- a/include/wx/generic/gridg.h +++ /dev/null @@ -1,429 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: gridg.h -// Purpose: wxGenericGrid -// Author: Julian Smart -// Modified by: Michael Bedward -// Added edit in place facility, 20 April 1999 -// Added cursor key control, 29 Jun 1999 -// Created: 01/02/97 -// RCS-ID: $Id$ -// Copyright: (c) -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef __GRIDH_G__ -#define __GRIDH_G__ - -#if defined(__GNUG__) && !defined(__APPLE__) -#pragma interface "gridg.h" -#endif - -#include "wx/defs.h" - -#if wxUSE_GRID - -#include "wx/panel.h" -#include "wx/string.h" -#include "wx/scrolbar.h" -#include "wx/event.h" - -#define wxGRID_DEFAULT_EDIT_WIDTH 300 -#define wxGRID_DEFAULT_EDIT_HEIGHT 27 -#define wxGRID_DEFAULT_EDIT_X 2 -#define wxGRID_DEFAULT_EDIT_Y 1 -#define wxGRID_DEFAULT_SHEET_TOP 31 -#define wxGRID_DEFAULT_SHEET_LEFT 0 -#define wxGRID_DEFAULT_CELL_HEIGHT 20 -#define wxGRID_DEFAULT_CELL_WIDTH 80 -#define wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH 40 -#define wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT 20 - -#define WXGENERIC_GRID_VERSION 0.5 - -class WXDLLEXPORT wxGridEvent; -class WXDLLEXPORT wxGridCell; - -class WXDLLEXPORT wxGenericGrid : public wxPanel -{ - DECLARE_DYNAMIC_CLASS(wxGenericGrid) - -public: - wxGenericGrid(); - - wxGenericGrid(wxWindow *parent, int x, int y, int width, int height, long style = 0, char *name = "grid") - { - Create(parent, -1, wxPoint(x, y), wxSize(width, height), style, name); - } - wxGenericGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style = 0, const wxString& name = "grid") - { - Create(parent, id, pos, size, style, name); - } - ~wxGenericGrid(); - - bool Create(wxWindow *parent, wxWindowID, const wxPoint& pos, const wxSize& size, long style = 0, const wxString& name = "grid"); - - bool CreateGrid(int nRows, int nCols, wxString **cellValues = (wxString **) NULL, short *widths = (short *) NULL, - short defaultWidth = wxGRID_DEFAULT_CELL_WIDTH, short defaultHeight = wxGRID_DEFAULT_CELL_HEIGHT); - void PaintGrid(wxDC& dc); - void ClearGrid(); - virtual wxGridCell *GetCell(int row, int col) const; - wxGridCell ***GetCells() const { return m_gridCells; } - bool InsertCols(int pos = 0, int n = 1, bool updateLabels = TRUE); - bool InsertRows(int pos = 0, int n = 1, bool updateLabels = TRUE); - bool AppendCols(int n = 1, bool updateLabels = TRUE); - bool AppendRows(int n = 1, bool updateLabels = TRUE); - bool DeleteCols(int pos = 0, int n = 1, bool updateLabels = TRUE); - bool DeleteRows(int pos = 0, int n = 1, bool updateLabels = TRUE); - - // Cell accessors - void SetCellValue(const wxString& val, int row, int col); - wxString& GetCellValue(int row, int col) const; - void SetCellAlignment(int flag, int row, int col); - void SetCellAlignment(int flag); - int GetCellAlignment(int row, int col) const; - int GetCellAlignment() const; - void SetCellTextColour(const wxColour& val, int row, int col); - void SetCellTextColour(const wxColour& col); - wxColour& GetCellTextColour(int row, int col) const; - wxColour& GetCellTextColour() const { return (wxColour&) m_cellTextColour; } - void SetCellBackgroundColour(const wxColour& col); - void SetCellBackgroundColour(const wxColour& colour, int row, int col); - wxColour& GetCellBackgroundColour() const { return (wxColour&) m_cellBackgroundColour; } - wxColour& GetCellBackgroundColour(int row, int col) const; - wxFont& GetCellTextFont() const { return (wxFont&) m_cellTextFont; } - wxFont& GetCellTextFont(int row, int col) const; - void SetCellTextFont(const wxFont& fnt); - void SetCellTextFont(const wxFont& fnt, int row, int col); - wxBitmap *GetCellBitmap(int row, int col) const; - void SetCellBitmap(wxBitmap *bitmap, int row, int col); - void *SetCellData(void *data, int row, int col); - void *GetCellData(int row, int col); - - // Size accessors - void SetColumnWidth(int col, int width); - int GetColumnWidth(int col) const; - void SetRowHeight(int row, int height); - int GetRowHeight(int row) const; - int GetViewHeight() const { return m_viewHeight; } - int GetViewWidth() const { return m_viewWidth; } - - // Label accessors - void SetLabelSize(int orientation, int sz); - int GetLabelSize(int orientation) const; - void SetLabelAlignment(int orientation, int alignment); - int GetLabelAlignment(int orientation) const; - wxGridCell *GetLabelCell(int orientation, int pos) const; - void SetLabelValue(int orientation, const wxString& val, int pos); - wxString& GetLabelValue(int orientation, int pos) const; - void SetLabelTextColour(const wxColour& colour); - void SetLabelBackgroundColour(const wxColour& colour); - wxColour& GetLabelTextColour() const { return (wxColour&) m_labelTextColour; } - wxColour& GetLabelBackgroundColour() { return (wxColour&) m_labelBackgroundColour; } - wxFont& GetLabelTextFont() { return (wxFont&) m_labelTextFont; } - void SetLabelTextFont(const wxFont& fnt) { m_labelTextFont = fnt; } - - // Miscellaneous accessors - int GetCursorRow() const { return m_wCursorRow; } - int GetCursorColumn() const { return m_wCursorColumn; } - void SetGridCursor(int row, int col); - int GetRows() const { return m_totalRows; } - int GetCols() const { return m_totalCols; } - int GetScrollPosX() const { return m_scrollPosX; } - int GetScrollPosY() const { return m_scrollPosY; } - void SetScrollPosX(int pos) { m_scrollPosX = pos; } - void SetScrollPosY(int pos) { m_scrollPosY = pos; } - wxTextCtrl *GetTextItem() const { return m_textItem; } - wxScrollBar *GetHorizScrollBar() const { return m_hScrollBar; } - wxScrollBar *GetVertScrollBar() const { return m_vScrollBar; } - bool GetEditable() const { return m_editable; } - void SetEditable(bool edit); - - bool GetEditInPlace() const { return m_editInPlace; } - void SetEditInPlace(bool edit = TRUE); - - wxRect& GetCurrentRect() const { return (wxRect&) m_currentRect; } - bool CurrentCellVisible() const { return m_currentRectVisible; } - void SetDividerPen(const wxPen& pen) { m_divisionPen = pen; } - wxPen& GetDividerPen() const { return (wxPen&) m_divisionPen; } - - // High-level event handling - // Override e.g. to check value of current cell; but call - // base member for default processing. - virtual void OnSelectCellImplementation(wxDC *dc, int row, int col); - - virtual void OnSelectCell(int WXUNUSED(row), int WXUNUSED(col)) {}; - void _OnSelectCell(wxGridEvent& event); - - // Override to create your own class of grid cell - virtual wxGridCell *OnCreateCell(); - void _OnCreateCell(wxGridEvent& event); - - // Override to change labels e.g. creation of grid, inserting/deleting a row/col. - // By default, auto-labels the grid. - virtual void OnChangeLabels(); - void _OnChangeLabels(wxGridEvent& event); - - // Override to change the label of the edit field when selecting a cell - // By default, sets it to e.g. A12 - virtual void OnChangeSelectionLabel(); - void _OnChangeSelectionLabel(wxGridEvent& event); - - // Override for event processing - virtual void OnCellChange(int WXUNUSED(row), int WXUNUSED(col)) {}; - virtual void OnCellLeftClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {}; - virtual void OnCellRightClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {}; - virtual void OnLabelLeftClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {}; - virtual void OnLabelRightClick(int WXUNUSED(row), int WXUNUSED(col), int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(control), bool WXUNUSED(shift)) {}; - - void _OnCellChange(wxGridEvent& event); - void _OnCellLeftClick(wxGridEvent& event); - void _OnCellRightClick(wxGridEvent& event); - void _OnLabelLeftClick(wxGridEvent& event); - void _OnLabelRightClick(wxGridEvent& event); - - // Activation: call from wxFrame::OnActivate - void OnActivate(bool active); - - // Miscellaneous - void AdjustScrollbars(); - void UpdateDimensions(); - - void SetCurrentRect (int Row, int Column, int canvasW = -1, int canvasH = -1); - void HighlightCell(wxDC *dc, bool doHighlight); - void DrawCellText(); - void SetGridClippingRegion(wxDC *dc); - - virtual bool CellHitTest(int x, int y, int *row, int *col); - virtual bool LabelSashHitTest(int x, int y, int *orientation, int *rowOrCol, int *startPos); - virtual bool LabelHitTest(int x, int y, int *row, int *col); - - // Painting - virtual void DrawLabelAreas(wxDC *dc); - virtual void DrawEditableArea(wxDC *dc); - virtual void DrawGridLines(wxDC *dc); - virtual void DrawColumnLabels(wxDC *dc); - virtual void DrawColumnLabel(wxDC *dc, wxRect *rect, int col); - virtual void DrawRowLabels(wxDC *dc); - virtual void DrawRowLabel(wxDC *dc, wxRect *rect, int row); - virtual void DrawCells(wxDC *dc); - virtual void DrawCellValue(wxDC *dc, wxRect *rect, int row, int col); - virtual void DrawCellBackground(wxDC *dc, wxRect *rect, int row, int col); - virtual void DrawTextRect(wxDC *dc, const wxString& text, wxRect *rect, int flag); - virtual void DrawBitmapRect(wxDC *dc, wxBitmap *bitmap, wxRect *rect, int flag); - - // Refresh cell and optionally set the text field - void RefreshCell(int row, int col, bool setText = FALSE); - - // Don't refresh within the outer pair of these. - void BeginBatch() { m_batchCount ++; } - void EndBatch() { m_batchCount --; } - int GetBatchCount() { return m_batchCount; } - - // implementation from now on - - void OnPaint(wxPaintEvent& event); - void OnEraseBackground(wxEraseEvent& event); - void OnMouseEvent(wxMouseEvent& event); - void OnSize(wxSizeEvent& event); - void OnText(wxCommandEvent& ev); - void OnTextEnter(wxCommandEvent& ev); - void OnTextInPlace(wxCommandEvent& ev); - void OnTextInPlaceEnter(wxCommandEvent& ev); - void OnGridScroll(wxScrollEvent& ev); - -protected: - wxPanel* m_editingPanel; // Contains the text control - wxTextCtrl* m_textItem; - wxTextCtrl* m_inPlaceTextItem; - - wxScrollBar* m_hScrollBar; - wxScrollBar* m_vScrollBar; - int m_wCursorRow; - int m_wCursorColumn; - wxRect m_currentRect; - bool m_currentRectVisible; - wxGridCell*** m_gridCells; - wxGridCell** m_rowLabelCells; - wxGridCell** m_colLabelCells; - - bool m_editCreated; - bool m_editable; - bool m_editInPlace; - bool m_inOnTextInPlace; - bool m_inScroll; - - int m_totalRows; - int m_totalCols; - - // Row and column we're currently looking at - int m_scrollPosX; - int m_scrollPosY; - - // Dimensions - int m_leftOfSheet; - int m_topOfSheet; - int m_rightOfSheet; // Calculated from m_colWidths - int m_bottomOfSheet; // Calculated from m_rowHeights - int m_totalGridWidth; // Total 'virtual' size - int m_totalGridHeight; - int m_viewHeight; // Number of rows displayed - int m_viewWidth; // Number of columns displayed - int m_cellHeight; // For now, a default - int m_verticalLabelWidth; - int m_horizontalLabelHeight; - int m_verticalLabelAlignment; - int m_horizontalLabelAlignment; - int m_cellAlignment; - short* m_colWidths; // Dynamically allocated - short* m_rowHeights; // Dynamically allocated - int m_scrollWidth; // Vert. scroll width, horiz. scroll height - - // Colours - wxColour m_cellTextColour; - wxColour m_cellBackgroundColour; - wxFont m_cellTextFont; - wxColour m_labelTextColour; - wxColour m_labelBackgroundColour; - wxBrush m_labelBackgroundBrush; - wxFont m_labelTextFont; - wxPen m_divisionPen; - wxPen m_highlightPen; - wxBitmap* m_doubleBufferingBitmap; - - // Position of Edit control - wxRect m_editControlPosition; - - // Drag status - int m_dragStatus; - int m_dragRowOrCol; - int m_dragStartPosition; - int m_dragLastPosition; - wxCursor m_horizontalSashCursor; - wxCursor m_verticalSashCursor; - - // To avoid multiple refreshes, use Begin/EndBatch - int m_batchCount; - - DECLARE_EVENT_TABLE() -}; - -#define wxGRID_TEXT_CTRL 2000 -#define wxGRID_HSCROLL 2001 -#define wxGRID_VSCROLL 2002 -#define wxGRID_EDIT_IN_PLACE_TEXT_CTRL 2003 - -class WXDLLEXPORT wxGridCell : public wxObject -{ -public: - wxString textValue; - wxFont font; - wxColour textColour; - wxColour backgroundColour; - wxBrush backgroundBrush; - wxBitmap* cellBitmap; - void* cellData; // intended for additional data associated with a cell - int alignment; - - wxGridCell(wxGenericGrid *window = (wxGenericGrid *) NULL); - ~wxGridCell(); - - virtual wxString& GetTextValue() const { return (wxString&) textValue; } - virtual void SetTextValue(const wxString& str) { textValue = str; } - wxFont& GetFont() const { return (wxFont&) font; } - void SetFont(const wxFont& f) { font = f; } - wxColour& GetTextColour() const { return (wxColour&) textColour; } - void SetTextColour(const wxColour& colour) { textColour = colour; } - wxColour& GetBackgroundColour() const { return (wxColour&) backgroundColour; } - void SetBackgroundColour(const wxColour& colour); - wxBrush& GetBackgroundBrush() const { return (wxBrush&) backgroundBrush; } - void SetBackgroundBrush(const wxBrush& brush) { backgroundBrush = brush; } - int GetAlignment() const { return alignment; } - void SetAlignment(int align) { alignment = align; } - wxBitmap *GetCellBitmap() const { return cellBitmap; } - void SetCellBitmap(wxBitmap *bitmap) { cellBitmap = bitmap; } - - void *SetCellData(void *data) { void *rc = cellData; cellData = data; return rc; } - void *GetCellData() const { return cellData; } -}; - -class WXDLLEXPORT wxGrid : public wxGenericGrid -{ -public: - wxGrid() : wxGenericGrid() { } - wxGrid(wxWindow *parent, int x=-1, int y=-1, int width=-1, int height=-1, - long style=0, char *name = "gridWindow") - : wxGenericGrid(parent, x, y, width, height, style, name) - { - } - wxGrid(wxWindow *parent, wxWindowID id, const wxPoint& pos, - const wxSize& size, long style = 0, const wxString& name = "grid") - : wxGenericGrid(parent, id, pos, size, style, name) - { - } - -}; - -class WXDLLEXPORT wxGridEvent : public wxCommandEvent -{ - DECLARE_DYNAMIC_CLASS(wxGridEvent) - -public: - wxGridEvent() - : wxCommandEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1), - m_control(0), m_shift(0), m_cell(0) - { - } - - wxGridEvent(int id, wxEventType type, wxObject* obj, - int row=-1, int col=-1, int x=-1, int y=-1, - bool control=FALSE, bool shift=FALSE) - : wxCommandEvent(type, id), m_row(row), m_col(col), m_x(x), m_y(y), - m_control(control), m_shift(shift), m_cell(0) - { - SetEventObject(obj); - } - -//private: - int m_row; - int m_col; - int m_x; - int m_y; - bool m_control; - bool m_shift; - wxGridCell* m_cell; - - int GetRow() const { return m_row; } - int GetCol() const { return m_col; } - wxPoint GetPosition() const { return wxPoint( m_x, m_y ); } - wxGridCell* GetCell() const { return m_cell; } - bool ControlDown() const { return m_control; } - bool ShiftDown() const { return m_shift; } -}; - -const wxEventType wxEVT_GRID_SELECT_CELL = wxEVT_FIRST + 1575; -const wxEventType wxEVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576; -const wxEventType wxEVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577; -const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578; -const wxEventType wxEVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1579; -const wxEventType wxEVT_GRID_CELL_LCLICK = wxEVT_FIRST + 1580; -const wxEventType wxEVT_GRID_CELL_RCLICK = wxEVT_FIRST + 1581; -const wxEventType wxEVT_GRID_LABEL_LCLICK = wxEVT_FIRST + 1582; -const wxEventType wxEVT_GRID_LABEL_RCLICK = wxEVT_FIRST + 1583; - - -typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&); - -#define EVT_GRID_SELECT_CELL(fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL), -#define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL), -#define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL), -#define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL), -#define EVT_GRID_CELL_CHANGE(fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL), -#define EVT_GRID_CELL_LCLICK(fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_GRID_CELL_LCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL), -#define EVT_GRID_CELL_RCLICK(fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_GRID_CELL_RCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL), -#define EVT_GRID_LABEL_LCLICK(fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_GRID_LABEL_LCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL), -#define EVT_GRID_LABEL_RCLICK(fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_GRID_LABEL_RCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL), - -#endif // wxUSE_GRID - -#endif // __GRIDH_G__ - diff --git a/include/wx/generic/gridsel.h b/include/wx/generic/gridsel.h index cae07fe7ef..76747894a3 100644 --- a/include/wx/generic/gridsel.h +++ b/include/wx/generic/gridsel.h @@ -11,7 +11,7 @@ #include "wx/defs.h" -#if defined(wxUSE_NEW_GRID) && (wxUSE_NEW_GRID) +#if wxUSE_NEW_GRID #ifndef __WXGRIDSEL_H__ #define __WXGRIDSEL_H__ @@ -88,4 +88,5 @@ private: }; #endif // #ifdef __WXGRIDSEL_H__ -#endif // #ifndef wxUSE_NEW_GRID +#endif // #ifndef wxUSE_GRID + diff --git a/samples/configure.in b/samples/configure.in index e412e8d77b..ad87c0d798 100644 --- a/samples/configure.in +++ b/samples/configure.in @@ -65,7 +65,6 @@ AC_OUTPUT([ mobile/styles/Makefile multimon/Makefile nativedlg/Makefile - newgrid/Makefile notebook/Makefile oleauto/Makefile ownerdrw/Makefile diff --git a/samples/grid/Makefile.in b/samples/grid/Makefile.in index 417e793d96..482ad0d73e 100644 --- a/samples/grid/Makefile.in +++ b/samples/grid/Makefile.in @@ -1,11 +1,21 @@ -# Purpose: makefile for grid example (UNIX). -# Created: 2000-03-15 +# +# File: makefile.unx +# Author: Julian Smart +# Created: 1998 +# Updated: +# Copyright: (c) 1998 Julian Smart +# +# "%W% %G%" +# +# Makefile for wxGrid example (UNIX). top_srcdir = @top_srcdir@/.. top_builddir = ../.. program_dir = samples/grid -PROGRAM=grid +DATAFILES = + +PROGRAM=griddemo OBJECTS =$(PROGRAM).o DEPFILES=$(PROGRAM).d @@ -13,4 +23,3 @@ DEPFILES=$(PROGRAM).d include ../../src/makeprog.env @IF_GNU_MAKE@-include $(DEPFILES) - diff --git a/samples/grid/grid.cpp b/samples/grid/grid.cpp deleted file mode 100644 index 8ede06bd2d..0000000000 --- a/samples/grid/grid.cpp +++ /dev/null @@ -1,350 +0,0 @@ -/* - * File: grid.cpp - * Purpose: wxGrid test - - PLEASE NOTE: this sample is deprecated. See - newgrid for a sample based on the newer wxGrid API. - - * Author: Julian Smart - * Created: 1995 - * Updated: - * Copyright: (c) 1995, AIAI, University of Edinburgh - */ - -static const char sccsid[] = "%W% %G%"; - -// For compilers that support precompilation, includes "wx/wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WX_PRECOMP -#include "wx/wx.h" -#endif - -#include "wx/grid.h" -#include "wx/colordlg.h" - -// Define a new application type -class MyApp: public wxApp -{ -public: - virtual bool OnInit(void); - virtual int OnExit(); -}; - - -// Define a new frame type -class MyFrame: public wxFrame -{ public: - wxGrid *grid; - MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size); - - void ToggleEditable(wxCommandEvent& event); - void ToggleEditInPlace(wxCommandEvent& event); - void ToggleRowLabel(wxCommandEvent& event); - void ToggleColLabel(wxCommandEvent& event); - void ToggleDividers(wxCommandEvent& event); - void LeftCell(wxCommandEvent& event); - void CentreCell(wxCommandEvent& event); - void RightCell(wxCommandEvent& event); - void ColourLabelBackground(wxCommandEvent& event); - void ColourLabelText(wxCommandEvent& event); - void NormalLabelColouring(wxCommandEvent& event); - void ColourCellBackground(wxCommandEvent& event); - void ColourCellText(wxCommandEvent& event); - void NormalCellColouring(wxCommandEvent& event); - void Quit(wxCommandEvent& event); - - void OnActivate(wxActivateEvent& event); - -DECLARE_EVENT_TABLE() -}; - -wxBitmap *cellBitmap1 = (wxBitmap *) NULL; -wxBitmap *cellBitmap2 = (wxBitmap *) NULL; - -// ID for the menu quit command -#define GRID_QUIT 1 -#define GRID_TOGGLE_EDITABLE 2 -#define GRID_TOGGLE_EDITINPLACE 22 -#define GRID_LEFT_CELL 3 -#define GRID_CENTRE_CELL 4 -#define GRID_RIGHT_CELL 5 -#define GRID_TOGGLE_ROW_LABEL 6 -#define GRID_TOGGLE_COL_LABEL 7 -#define GRID_COLOUR_LABEL_BACKGROUND 8 -#define GRID_COLOUR_LABEL_TEXT 9 -#define GRID_NORMAL_LABEL_COLOURING 10 -#define GRID_COLOUR_CELL_BACKGROUND 11 -#define GRID_COLOUR_CELL_TEXT 12 -#define GRID_NORMAL_CELL_COLOURING 13 -#define GRID_TOGGLE_DIVIDERS 14 - -// Main proc - -IMPLEMENT_APP(MyApp) - -// `Main program' equivalent, creating windows and returning main app frame -bool MyApp::OnInit(void) -{ -#ifdef __WXMSW__ - cellBitmap1 = new wxBitmap(_T("bitmap1")); - cellBitmap2 = new wxBitmap(_T("bitmap2")); -#endif - - // Create the main frame window - MyFrame *frame = new MyFrame(NULL, _T("wxGrid Sample"), wxPoint(50, 50), wxSize(450, 300)); - - // Give it an icon -#ifdef __WXMSW__ - frame->SetIcon(wxIcon(_T("mondrian"))); -#endif - - // Make a menubar - wxMenu *file_menu = new wxMenu; - file_menu->Append(GRID_QUIT, _T("E&xit")); - - wxMenu *settings_menu = new wxMenu; - settings_menu->Append(GRID_TOGGLE_EDITABLE, _T("&Toggle editable")); - settings_menu->Append(GRID_TOGGLE_EDITINPLACE, _T("&Toggle edit in place")); - settings_menu->Append(GRID_TOGGLE_ROW_LABEL, _T("Toggle ro&w label")); - settings_menu->Append(GRID_TOGGLE_COL_LABEL, _T("Toggle co&l label")); - settings_menu->Append(GRID_TOGGLE_DIVIDERS, _T("Toggle ÷rs")); - settings_menu->AppendSeparator(); - settings_menu->Append(GRID_LEFT_CELL, _T("&Left cell alignment ")); - settings_menu->Append(GRID_CENTRE_CELL, _T("&Centre cell alignment ")); - settings_menu->Append(GRID_RIGHT_CELL, _T("&Right cell alignment ")); - settings_menu->AppendSeparator(); - settings_menu->Append(GRID_COLOUR_LABEL_BACKGROUND, _T("Choose a label &background colour")); - settings_menu->Append(GRID_COLOUR_LABEL_TEXT, _T("Choose a label fore&ground colour")); - settings_menu->Append(GRID_NORMAL_LABEL_COLOURING, _T("&Normal label colouring")); - settings_menu->AppendSeparator(); - settings_menu->Append(GRID_COLOUR_CELL_BACKGROUND, _T("Choo&se a cell &background colour")); - settings_menu->Append(GRID_COLOUR_CELL_TEXT, _T("Choose &a cell foreground colour")); - settings_menu->Append(GRID_NORMAL_CELL_COLOURING, _T("N&ormal cell colouring")); - - wxMenuBar *menu_bar = new wxMenuBar; - menu_bar->Append(file_menu, _T("&File")); - menu_bar->Append(settings_menu, _T("&Settings")); - frame->SetMenuBar(menu_bar); - - // Make a grid - frame->grid = new wxGrid(frame, 0, 0, 400, 400); - - frame->grid->CreateGrid(10, 8); - frame->grid->SetColumnWidth(3, 200); - frame->grid->SetRowHeight(4, 45); - frame->grid->SetCellValue(_T("First cell"), 0, 0); - frame->grid->SetCellValue(_T("Another cell"), 1, 1); - frame->grid->SetCellValue(_T("Yet another cell"), 2, 2); - frame->grid->SetCellTextFont(wxFont(10, wxROMAN, wxITALIC, wxNORMAL), 0, 0); - frame->grid->SetCellTextColour(*wxRED, 1, 1); - frame->grid->SetCellBackgroundColour(*wxCYAN, 2, 2); - if (cellBitmap1 && cellBitmap2) - { - frame->grid->SetCellAlignment(wxCENTRE, 5, 0); - frame->grid->SetCellAlignment(wxCENTRE, 6, 0); - frame->grid->SetCellBitmap(cellBitmap1, 5, 0); - frame->grid->SetCellBitmap(cellBitmap2, 6, 0); - } - - frame->grid->UpdateDimensions(); - - // Show the frame - frame->Show(TRUE); - - wxMessageBox(wxT("Please note: this is an obsolete sample using the old wxGrid API.\nPlease compile newgrid instead."), wxT("wxGrid"), wxICON_INFORMATION|wxOK, frame); - - SetTopWindow(frame); - return TRUE; -} - -int MyApp::OnExit() -{ - if (cellBitmap1) - { - delete cellBitmap1; - cellBitmap1 = (wxBitmap *) NULL; - } - - if (cellBitmap2) - { - delete cellBitmap2; - cellBitmap1 = (wxBitmap *) NULL; - } - - // exit code is 0, everything is ok - return 0; -} - - -// My frame constructor -MyFrame::MyFrame(wxFrame *frame, const wxString& title, - const wxPoint& pos, const wxSize& size): - wxFrame(frame, -1, title, pos, size) -{ - grid = (wxGrid*) NULL; -} - -BEGIN_EVENT_TABLE(MyFrame, wxFrame) - EVT_MENU(GRID_TOGGLE_EDITABLE, MyFrame::ToggleEditable) - EVT_MENU(GRID_TOGGLE_EDITINPLACE, MyFrame::ToggleEditInPlace) - EVT_MENU(GRID_TOGGLE_ROW_LABEL, MyFrame::ToggleRowLabel) - EVT_MENU(GRID_TOGGLE_COL_LABEL, MyFrame::ToggleColLabel) - EVT_MENU(GRID_TOGGLE_DIVIDERS, MyFrame::ToggleDividers) - EVT_MENU(GRID_LEFT_CELL, MyFrame::LeftCell) - EVT_MENU(GRID_CENTRE_CELL, MyFrame::CentreCell) - EVT_MENU(GRID_RIGHT_CELL, MyFrame::RightCell) - EVT_MENU(GRID_COLOUR_LABEL_BACKGROUND, MyFrame::ColourLabelBackground) - EVT_MENU(GRID_COLOUR_LABEL_TEXT, MyFrame::ColourLabelText) - EVT_MENU(GRID_NORMAL_LABEL_COLOURING, MyFrame::NormalLabelColouring) - EVT_MENU(GRID_COLOUR_CELL_BACKGROUND, MyFrame::ColourCellBackground) - EVT_MENU(GRID_COLOUR_CELL_TEXT, MyFrame::ColourCellText) - EVT_MENU(GRID_NORMAL_CELL_COLOURING, MyFrame::NormalCellColouring) - EVT_MENU(GRID_QUIT, MyFrame::Quit) -END_EVENT_TABLE() - -void MyFrame::ToggleEditable(wxCommandEvent& WXUNUSED(event)) -{ - grid->SetEditable(!grid->GetEditable()); - grid->Refresh(); -} - -void MyFrame::ToggleEditInPlace(wxCommandEvent& WXUNUSED(event)) -{ - grid->SetEditInPlace(!grid->GetEditInPlace()); - grid->Refresh(); -} - -void MyFrame::ToggleRowLabel(wxCommandEvent& WXUNUSED(event)) -{ - if (grid->GetLabelSize(wxVERTICAL) > 0) - grid->SetLabelSize(wxVERTICAL, 0); - else - grid->SetLabelSize(wxVERTICAL, 40); - - grid->Refresh(); -} - -void MyFrame::ToggleColLabel(wxCommandEvent& WXUNUSED(event)) -{ - if (grid->GetLabelSize(wxHORIZONTAL) > 0) - grid->SetLabelSize(wxHORIZONTAL, 0); - else - grid->SetLabelSize(wxHORIZONTAL, 20); - - grid->Refresh(); -} - -void MyFrame::ToggleDividers(wxCommandEvent& WXUNUSED(event)) -{ - if (!grid->GetDividerPen().Ok()) - grid->SetDividerPen(wxPen(wxT("LIGHT GREY"), 1, wxSOLID)); - else - grid->SetDividerPen(wxNullPen); - - grid->Refresh(); -} - -void MyFrame::LeftCell(wxCommandEvent& WXUNUSED(event)) -{ - grid->SetCellAlignment(wxLEFT); - grid->Refresh(); -} - -void MyFrame::CentreCell(wxCommandEvent& WXUNUSED(event)) -{ - grid->SetCellAlignment(wxCENTRE); - grid->Refresh(); -} - -void MyFrame::RightCell(wxCommandEvent& WXUNUSED(event)) -{ - grid->SetCellAlignment(wxRIGHT); - grid->Refresh(); -} - -void MyFrame::ColourLabelBackground(wxCommandEvent& WXUNUSED(event)) -{ - wxColourData data; - data.SetChooseFull(TRUE); - wxColourDialog dialog(this, &data); - if (dialog.ShowModal() != wxID_CANCEL) - { - wxColourData retData = dialog.GetColourData(); - wxColour col = retData.GetColour(); - grid->SetLabelBackgroundColour(col); - grid->Refresh(); - } -} - -void MyFrame::ColourLabelText(wxCommandEvent& WXUNUSED(event)) -{ - wxColourData data; - data.SetChooseFull(TRUE); - wxColourDialog dialog(this, &data); - if (dialog.ShowModal() != wxID_CANCEL) - { - wxColourData retData = dialog.GetColourData(); - wxColour col = retData.GetColour(); - grid->SetLabelTextColour(col); - grid->Refresh(); - } -} - -void MyFrame::NormalLabelColouring(wxCommandEvent& WXUNUSED(event)) -{ - grid->SetLabelBackgroundColour(*wxLIGHT_GREY); - grid->SetLabelTextColour(*wxBLACK); - grid->Refresh(); -} - -void MyFrame::ColourCellBackground(wxCommandEvent& WXUNUSED(event)) -{ - wxColourData data; - data.SetChooseFull(TRUE); - wxColourDialog dialog(this, &data); - if (dialog.ShowModal() != wxID_CANCEL) - { - wxColourData retData = dialog.GetColourData(); - wxColour col = retData.GetColour(); - grid->SetCellBackgroundColour(col); - grid->Refresh(); - } -} - -void MyFrame::ColourCellText(wxCommandEvent& WXUNUSED(event)) -{ - wxColourData data; - data.SetChooseFull(TRUE); - wxColourDialog dialog(this, &data); - if (dialog.ShowModal() != wxID_CANCEL) - { - wxColourData retData = dialog.GetColourData(); - wxColour col = retData.GetColour(); - grid->SetCellTextColour(col); - grid->Refresh(); - } -} - -void MyFrame::NormalCellColouring(wxCommandEvent& WXUNUSED(event)) -{ - grid->SetCellBackgroundColour(*wxWHITE); - grid->SetCellTextColour(*wxBLACK); - grid->Refresh(); -} - -void MyFrame::Quit(wxCommandEvent& WXUNUSED(event)) -{ - this->Close(TRUE); -} - -// Ensure that the grid's edit control always has the focus. -void MyFrame::OnActivate(wxActivateEvent& event) -{ - if (grid) grid->OnActivate(event.GetActive()); -} - diff --git a/samples/grid/grid.def b/samples/grid/grid.def deleted file mode 100644 index 3ff4e2c552..0000000000 --- a/samples/grid/grid.def +++ /dev/null @@ -1,8 +0,0 @@ -NAME Grid -DESCRIPTION 'wxTableWindow Test' -EXETYPE WINDOWS -STUB 'WINSTUB.EXE' -CODE PRELOAD MOVEABLE DISCARDABLE -DATA PRELOAD MOVEABLE MULTIPLE -HEAPSIZE 1024 -STACKSIZE 16192 diff --git a/samples/grid/grid.rc b/samples/grid/grid.rc deleted file mode 100644 index 571ada1f2a..0000000000 --- a/samples/grid/grid.rc +++ /dev/null @@ -1,5 +0,0 @@ -#include "wx/msw/wx.rc" - -bitmap1 BITMAP "bitmap1.bmp" -bitmap2 BITMAP "bitmap2.bmp" - diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp new file mode 100644 index 0000000000..31ff32bb5c --- /dev/null +++ b/samples/grid/griddemo.cpp @@ -0,0 +1,1361 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: griddemo.cpp +// Purpose: Grid control wxWindows sample +// Author: Michael Bedward +// Modified by: +// RCS-ID: $Id$ +// Copyright: (c) Michael Bedward, Julian Smart +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation + #pragma interface +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "wx/colordlg.h" +#include "wx/fontdlg.h" + +#include "wx/grid.h" +#include "wx/generic/gridctrl.h" + +#include "griddemo.h" + +// ---------------------------------------------------------------------------- +// wxWin macros +// ---------------------------------------------------------------------------- + +IMPLEMENT_APP( GridApp ) + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// GridApp +// ---------------------------------------------------------------------------- + +bool GridApp::OnInit() +{ + GridFrame *frame = new GridFrame; + frame->Show( TRUE ); + + return TRUE; +} + +// ---------------------------------------------------------------------------- +// GridFrame +// ---------------------------------------------------------------------------- + +BEGIN_EVENT_TABLE( GridFrame, wxFrame ) + EVT_MENU( ID_TOGGLEROWLABELS, GridFrame::ToggleRowLabels ) + EVT_MENU( ID_TOGGLECOLLABELS, GridFrame::ToggleColLabels ) + EVT_MENU( ID_TOGGLEEDIT, GridFrame::ToggleEditing ) + EVT_MENU( ID_TOGGLEROWSIZING, GridFrame::ToggleRowSizing ) + EVT_MENU( ID_TOGGLECOLSIZING, GridFrame::ToggleColSizing ) + EVT_MENU( ID_TOGGLEGRIDSIZING, GridFrame::ToggleGridSizing ) + EVT_MENU( ID_TOGGLEGRIDLINES, GridFrame::ToggleGridLines ) + EVT_MENU( ID_AUTOSIZECOLS, GridFrame::AutoSizeCols ) + EVT_MENU( ID_CELLOVERFLOW, GridFrame::CellOverflow ) + EVT_MENU( ID_RESIZECELL, GridFrame::ResizeCell ) + EVT_MENU( ID_SETLABELCOLOUR, GridFrame::SetLabelColour ) + EVT_MENU( ID_SETLABELTEXTCOLOUR, GridFrame::SetLabelTextColour ) + EVT_MENU( ID_SETLABEL_FONT, GridFrame::SetLabelFont ) + EVT_MENU( ID_ROWLABELHORIZALIGN, GridFrame::SetRowLabelHorizAlignment ) + EVT_MENU( ID_ROWLABELVERTALIGN, GridFrame::SetRowLabelVertAlignment ) + EVT_MENU( ID_COLLABELHORIZALIGN, GridFrame::SetColLabelHorizAlignment ) + EVT_MENU( ID_COLLABELVERTALIGN, GridFrame::SetColLabelVertAlignment ) + EVT_MENU( ID_GRIDLINECOLOUR, GridFrame::SetGridLineColour ) + EVT_MENU( ID_INSERTROW, GridFrame::InsertRow ) + EVT_MENU( ID_INSERTCOL, GridFrame::InsertCol ) + EVT_MENU( ID_DELETEROW, GridFrame::DeleteSelectedRows ) + EVT_MENU( ID_DELETECOL, GridFrame::DeleteSelectedCols ) + EVT_MENU( ID_CLEARGRID, GridFrame::ClearGrid ) + EVT_MENU( ID_SELCELLS, GridFrame::SelectCells ) + EVT_MENU( ID_SELROWS, GridFrame::SelectRows ) + EVT_MENU( ID_SELCOLS, GridFrame::SelectCols ) + + EVT_MENU( ID_SET_CELL_FG_COLOUR, GridFrame::SetCellFgColour ) + EVT_MENU( ID_SET_CELL_BG_COLOUR, GridFrame::SetCellBgColour ) + + EVT_MENU( ID_ABOUT, GridFrame::About ) + EVT_MENU( wxID_EXIT, GridFrame::OnQuit ) + EVT_MENU( ID_VTABLE, GridFrame::OnVTable) + EVT_MENU( ID_BUGS_TABLE, GridFrame::OnBugsTable) + EVT_MENU( ID_SMALL_GRID, GridFrame::OnSmallGrid) + + EVT_MENU( ID_DESELECT_CELL, GridFrame::DeselectCell) + EVT_MENU( ID_DESELECT_COL, GridFrame::DeselectCol) + EVT_MENU( ID_DESELECT_ROW, GridFrame::DeselectRow) + EVT_MENU( ID_DESELECT_ALL, GridFrame::DeselectAll) + EVT_MENU( ID_SELECT_CELL, GridFrame::SelectCell) + EVT_MENU( ID_SELECT_COL, GridFrame::SelectCol) + EVT_MENU( ID_SELECT_ROW, GridFrame::SelectRow) + EVT_MENU( ID_SELECT_ALL, GridFrame::SelectAll) + EVT_MENU( ID_SELECT_UNSELECT, GridFrame::OnAddToSelectToggle) + + EVT_MENU( ID_SET_HIGHLIGHT_WIDTH, GridFrame::OnSetHighlightWidth) + EVT_MENU( ID_SET_RO_HIGHLIGHT_WIDTH, GridFrame::OnSetROHighlightWidth) + + EVT_GRID_LABEL_LEFT_CLICK( GridFrame::OnLabelLeftClick ) + EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick ) + EVT_GRID_ROW_SIZE( GridFrame::OnRowSize ) + EVT_GRID_COL_SIZE( GridFrame::OnColSize ) + EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell ) + EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected ) + EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged ) + + EVT_GRID_EDITOR_SHOWN( GridFrame::OnEditorShown ) + EVT_GRID_EDITOR_HIDDEN( GridFrame::OnEditorHidden ) +END_EVENT_TABLE() + + +GridFrame::GridFrame() + : wxFrame( (wxFrame *)NULL, -1, _T("wxWindows grid class demo"), + wxDefaultPosition, + wxDefaultSize ) +{ + int gridW = 600, gridH = 300; + int logW = gridW, logH = 100; + + wxMenu *fileMenu = new wxMenu; + fileMenu->Append( ID_VTABLE, _T("&Virtual table test\tCtrl-V")); + fileMenu->Append( ID_BUGS_TABLE, _T("&Bugs table test\tCtrl-B")); + fileMenu->Append( ID_SMALL_GRID, _T("&Small Grid test\tCtrl-S")); + fileMenu->AppendSeparator(); + fileMenu->Append( wxID_EXIT, _T("E&xit\tAlt-X") ); + + wxMenu *viewMenu = new wxMenu; + viewMenu->Append( ID_TOGGLEROWLABELS, _T("&Row labels"), _T(""), wxITEM_CHECK ); + viewMenu->Append( ID_TOGGLECOLLABELS, _T("&Col labels"), _T(""), wxITEM_CHECK ); + viewMenu->Append( ID_TOGGLEEDIT, _T("&Editable"), _T(""), wxITEM_CHECK ); + viewMenu->Append( ID_TOGGLEROWSIZING, _T("Ro&w drag-resize"), _T(""), wxITEM_CHECK ); + viewMenu->Append( ID_TOGGLECOLSIZING, _T("C&ol drag-resize"), _T(""), wxITEM_CHECK ); + viewMenu->Append( ID_TOGGLEGRIDSIZING, _T("&Grid drag-resize"), _T(""), wxITEM_CHECK ); + viewMenu->Append( ID_TOGGLEGRIDLINES, _T("&Grid Lines"), _T(""), wxITEM_CHECK ); + viewMenu->Append( ID_SET_HIGHLIGHT_WIDTH, _T("&Set Cell Highlight Width..."), _T("") ); + viewMenu->Append( ID_SET_RO_HIGHLIGHT_WIDTH, _T("&Set Cell RO Highlight Width..."), _T("") ); + viewMenu->Append( ID_AUTOSIZECOLS, _T("&Auto-size cols") ); + viewMenu->Append( ID_CELLOVERFLOW, _T("&Overflow cells"), _T(""), wxITEM_CHECK ); + viewMenu->Append( ID_RESIZECELL, _T("&Resize cell (7,1)"), _T(""), wxITEM_CHECK ); + + wxMenu *rowLabelMenu = new wxMenu; + + viewMenu->Append( ID_ROWLABELALIGN, _T("R&ow label alignment"), + rowLabelMenu, + _T("Change alignment of row labels") ); + + rowLabelMenu->Append( ID_ROWLABELHORIZALIGN, _T("&Horizontal") ); + rowLabelMenu->Append( ID_ROWLABELVERTALIGN, _T("&Vertical") ); + + wxMenu *colLabelMenu = new wxMenu; + + viewMenu->Append( ID_COLLABELALIGN, _T("Col l&abel alignment"), + colLabelMenu, + _T("Change alignment of col labels") ); + + colLabelMenu->Append( ID_COLLABELHORIZALIGN, _T("&Horizontal") ); + colLabelMenu->Append( ID_COLLABELVERTALIGN, _T("&Vertical") ); + + wxMenu *colMenu = new wxMenu; + colMenu->Append( ID_SETLABELCOLOUR, _T("Set &label colour...") ); + colMenu->Append( ID_SETLABELTEXTCOLOUR, _T("Set label &text colour...") ); + colMenu->Append( ID_SETLABEL_FONT, _T("Set label fo&nt...") ); + colMenu->Append( ID_GRIDLINECOLOUR, _T("&Grid line colour...") ); + colMenu->Append( ID_SET_CELL_FG_COLOUR, _T("Set cell &foreground colour...") ); + colMenu->Append( ID_SET_CELL_BG_COLOUR, _T("Set cell &background colour...") ); + + wxMenu *editMenu = new wxMenu; + editMenu->Append( ID_INSERTROW, _T("Insert &row") ); + editMenu->Append( ID_INSERTCOL, _T("Insert &column") ); + editMenu->Append( ID_DELETEROW, _T("Delete selected ro&ws") ); + editMenu->Append( ID_DELETECOL, _T("Delete selected co&ls") ); + editMenu->Append( ID_CLEARGRID, _T("Cl&ear grid cell contents") ); + + wxMenu *selectMenu = new wxMenu; + selectMenu->Append( ID_SELECT_UNSELECT, _T("Add new cells to the selection"), + _T("When off, old selection is deselected before ") + _T("selecting the new cells"), wxITEM_CHECK ); + selectMenu->Append( ID_SELECT_ALL, _T("Select all")); + selectMenu->Append( ID_SELECT_ROW, _T("Select row 2")); + selectMenu->Append( ID_SELECT_COL, _T("Select col 2")); + selectMenu->Append( ID_SELECT_CELL, _T("Select cell (3, 1)")); + selectMenu->Append( ID_DESELECT_ALL, _T("Deselect all")); + selectMenu->Append( ID_DESELECT_ROW, _T("Deselect row 2")); + selectMenu->Append( ID_DESELECT_COL, _T("Deselect col 2")); + selectMenu->Append( ID_DESELECT_CELL, _T("Deselect cell (3, 1)")); + wxMenu *selectionMenu = new wxMenu; + selectMenu->Append( ID_CHANGESEL, _T("Change &selection mode"), + selectionMenu, + _T("Change selection mode") ); + + selectionMenu->Append( ID_SELCELLS, _T("Select &Cells") ); + selectionMenu->Append( ID_SELROWS, _T("Select &Rows") ); + selectionMenu->Append( ID_SELCOLS, _T("Select C&ols") ); + + + wxMenu *helpMenu = new wxMenu; + helpMenu->Append( ID_ABOUT, _T("&About wxGrid demo") ); + + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append( fileMenu, _T("&File") ); + menuBar->Append( viewMenu, _T("&View") ); + menuBar->Append( colMenu, _T("&Colours") ); + menuBar->Append( editMenu, _T("&Edit") ); + menuBar->Append( selectMenu, _T("&Select") ); + menuBar->Append( helpMenu, _T("&Help") ); + + SetMenuBar( menuBar ); + + m_addToSel = FALSE; + + grid = new wxGrid( this, + -1, + wxPoint( 0, 0 ), + wxSize( 400, 300 ) ); + + logWin = new wxTextCtrl( this, + -1, + wxEmptyString, + wxPoint( 0, gridH + 20 ), + wxSize( logW, logH ), + wxTE_MULTILINE ); + + logger = new wxLogTextCtrl( logWin ); + m_logOld = logger->SetActiveTarget( logger ); + logger->SetTimestamp( NULL ); + + // this will create a grid and, by default, an associated grid + // table for strings + grid->CreateGrid( 0, 0 ); + grid->AppendRows(100); + grid->AppendCols(100); + + int ir = grid->GetNumberRows(); + grid->DeleteRows(0, ir); + grid->AppendRows(ir); + + grid->SetRowSize( 0, 60 ); + grid->SetCellValue( 0, 0, _T("Ctrl+Home\nwill go to\nthis cell") ); + + grid->SetCellValue( 0, 1, _T("A long piece of text to demonstrate wrapping.") ); + grid->SetCellRenderer(0 , 1, new wxGridCellAutoWrapStringRenderer); + grid->SetCellEditor( 0, 1 , new wxGridCellAutoWrapStringEditor); + + grid->SetCellValue( 0, 2, _T("Blah") ); + grid->SetCellValue( 0, 3, _T("Read only") ); + grid->SetReadOnly( 0, 3 ); + + grid->SetCellValue( 0, 4, _T("Can veto edit this cell") ); + + grid->SetCellValue( 0, 5, _T("Press\nCtrl+arrow\nto skip over\ncells") ); + + grid->SetRowSize( 99, 60 ); + grid->SetCellValue( 99, 99, _T("Ctrl+End\nwill go to\nthis cell") ); + grid->SetCellValue( 1, 0, _T("This default cell will overflow into neighboring cells, but not if you turn overflow off.")); + + grid->SetCellTextColour(1, 2, *wxRED); + grid->SetCellBackgroundColour(1, 2, *wxGREEN); + + grid->SetCellValue( 1, 4, _T("I'm in the middle")); + + grid->SetCellValue(2, 2, _T("red")); + + grid->SetCellTextColour(2, 2, *wxRED); + grid->SetCellValue(3, 3, _T("green on grey")); + grid->SetCellTextColour(3, 3, *wxGREEN); + grid->SetCellBackgroundColour(3, 3, *wxLIGHT_GREY); + + grid->SetCellValue(4, 4, _T("a weird looking cell")); + grid->SetCellAlignment(4, 4, wxALIGN_CENTRE, wxALIGN_CENTRE); + grid->SetCellRenderer(4, 4, new MyGridCellRenderer); + + grid->SetCellValue(3, 0, _T("0")); + grid->SetCellRenderer(3, 0, new wxGridCellBoolRenderer); + grid->SetCellEditor(3, 0, new wxGridCellBoolEditor); + + wxGridCellAttr *attr; + attr = new wxGridCellAttr; + attr->SetTextColour(*wxBLUE); + grid->SetColAttr(5, attr); + attr = new wxGridCellAttr; + attr->SetBackgroundColour(*wxRED); + grid->SetRowAttr(5, attr); + + grid->SetCellValue(2, 4, _T("a wider column")); + grid->SetColSize(4, 120); + grid->SetColMinimalWidth(4, 120); + + grid->SetCellTextColour(5, 8, *wxGREEN); + grid->SetCellValue(5, 8, _T("Bg from row attr\nText col from cell attr")); + grid->SetCellValue(5, 5, _T("Bg from row attr Text col from col attr and this text is so long that it covers over many many empty cells but is broken by one that isn't")); + + grid->SetColFormatFloat(6); + grid->SetCellValue(0, 6, _T("3.1415")); + grid->SetCellValue(1, 6, _T("1415")); + grid->SetCellValue(2, 6, _T("12345.67890")); + + grid->SetColFormatFloat(7, 6, 2); + grid->SetCellValue(0, 7, _T("3.1415")); + grid->SetCellValue(1, 7, _T("1415")); + grid->SetCellValue(2, 7, _T("12345.67890")); + + const wxString choices[] = + { + _T("Please select a choice"), + _T("This takes two cells"), + _T("Another choice"), + }; + grid->SetCellEditor(4, 0, new wxGridCellChoiceEditor(WXSIZEOF(choices), choices)); + grid->SetCellSize(4, 0, 1, 2); + grid->SetCellValue(4, 0, choices[0]); + grid->SetCellOverflow(4, 0, FALSE); + + grid->SetCellSize(7, 1, 3, 4); + grid->SetCellAlignment(7, 1, wxALIGN_CENTRE, wxALIGN_CENTRE); + grid->SetCellValue(7, 1, _T("Big box!")); + + wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); + topSizer->Add( grid, + 1, + wxEXPAND ); + + topSizer->Add( logWin, + 0, + wxEXPAND ); + + SetAutoLayout( TRUE ); + SetSizer( topSizer ); + + topSizer->Fit( this ); + topSizer->SetSizeHints( this ); + + Centre(); + SetDefaults(); +} + + +GridFrame::~GridFrame() +{ + delete wxLog::SetActiveTarget(m_logOld); +} + + +void GridFrame::SetDefaults() +{ + GetMenuBar()->Check( ID_TOGGLEROWLABELS, TRUE ); + GetMenuBar()->Check( ID_TOGGLECOLLABELS, TRUE ); + GetMenuBar()->Check( ID_TOGGLEEDIT, TRUE ); + GetMenuBar()->Check( ID_TOGGLEROWSIZING, TRUE ); + GetMenuBar()->Check( ID_TOGGLECOLSIZING, TRUE ); + GetMenuBar()->Check( ID_TOGGLEGRIDSIZING, TRUE ); + GetMenuBar()->Check( ID_TOGGLEGRIDLINES, TRUE ); + GetMenuBar()->Check( ID_CELLOVERFLOW, TRUE ); +} + + +void GridFrame::ToggleRowLabels( wxCommandEvent& WXUNUSED(ev) ) +{ + if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS ) ) + { + grid->SetRowLabelSize( grid->GetDefaultRowLabelSize() ); + } + else + { + grid->SetRowLabelSize( 0 ); + } +} + + +void GridFrame::ToggleColLabels( wxCommandEvent& WXUNUSED(ev) ) +{ + if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS ) ) + { + grid->SetColLabelSize( grid->GetDefaultColLabelSize() ); + } + else + { + grid->SetColLabelSize( 0 ); + } +} + + +void GridFrame::ToggleEditing( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->EnableEditing( + GetMenuBar()->IsChecked( ID_TOGGLEEDIT ) ); +} + + +void GridFrame::ToggleRowSizing( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->EnableDragRowSize( + GetMenuBar()->IsChecked( ID_TOGGLEROWSIZING ) ); +} + + +void GridFrame::ToggleColSizing( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->EnableDragColSize( + GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING ) ); +} + +void GridFrame::ToggleGridSizing( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->EnableDragGridSize( + GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING ) ); +} + + +void GridFrame::ToggleGridLines( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->EnableGridLines( + GetMenuBar()->IsChecked( ID_TOGGLEGRIDLINES ) ); +} + +void GridFrame::OnSetHighlightWidth( wxCommandEvent& WXUNUSED(ev) ) +{ + wxString choices[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")}; + + wxSingleChoiceDialog dlg(this, _T("Choose the thickness of the highlight pen:"), + _T("Pen Width"), 11, choices); + + int current = grid->GetCellHighlightPenWidth(); + dlg.SetSelection(current); + if (dlg.ShowModal() == wxID_OK) { + grid->SetCellHighlightPenWidth(dlg.GetSelection()); + } +} + +void GridFrame::OnSetROHighlightWidth( wxCommandEvent& WXUNUSED(ev) ) +{ + wxString choices[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")}; + + wxSingleChoiceDialog dlg(this, _T("Choose the thickness of the highlight pen:"), + _T("Pen Width"), 11, choices); + + int current = grid->GetCellHighlightROPenWidth(); + dlg.SetSelection(current); + if (dlg.ShowModal() == wxID_OK) { + grid->SetCellHighlightROPenWidth(dlg.GetSelection()); + } +} + + + +void GridFrame::AutoSizeCols( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->AutoSizeColumns(); + grid->Refresh(); +} + +void GridFrame::CellOverflow( wxCommandEvent& ev ) +{ + grid->SetDefaultCellOverflow(ev.IsChecked()); + grid->Refresh(); +} + +void GridFrame::ResizeCell( wxCommandEvent& ev ) +{ + if (ev.IsChecked()) + grid->SetCellSize( 7, 1, 5, 5 ); + else + grid->SetCellSize( 7, 1, 1, 5 ); + grid->Refresh(); +} + +void GridFrame::SetLabelColour( wxCommandEvent& WXUNUSED(ev) ) +{ + wxColourDialog dlg( NULL ); + if ( dlg.ShowModal() == wxID_OK ) + { + wxColourData retData; + retData = dlg.GetColourData(); + wxColour colour = retData.GetColour(); + + grid->SetLabelBackgroundColour( colour ); + } +} + + +void GridFrame::SetLabelTextColour( wxCommandEvent& WXUNUSED(ev) ) +{ + wxColourDialog dlg( NULL ); + if ( dlg.ShowModal() == wxID_OK ) + { + wxColourData retData; + retData = dlg.GetColourData(); + wxColour colour = retData.GetColour(); + + grid->SetLabelTextColour( colour ); + } +} + +void GridFrame::SetLabelFont( wxCommandEvent& WXUNUSED(ev) ) +{ + wxFont font = wxGetFontFromUser(this); + if ( font.Ok() ) + { + grid->SetLabelFont(font); + } +} + +void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) ) +{ + int horiz, vert; + grid->GetRowLabelAlignment( &horiz, &vert ); + + switch ( horiz ) + { + case wxALIGN_LEFT: + horiz = wxALIGN_CENTRE; + break; + + case wxALIGN_CENTRE: + horiz = wxALIGN_RIGHT; + break; + + case wxALIGN_RIGHT: + horiz = wxALIGN_LEFT; + break; + } + + grid->SetRowLabelAlignment( horiz, -1 ); +} + +void GridFrame::SetRowLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) ) +{ + int horiz, vert; + grid->GetRowLabelAlignment( &horiz, &vert ); + + switch ( vert ) + { + case wxALIGN_TOP: + vert = wxALIGN_CENTRE; + break; + + case wxALIGN_CENTRE: + vert = wxALIGN_BOTTOM; + break; + + case wxALIGN_BOTTOM: + vert = wxALIGN_TOP; + break; + } + + grid->SetRowLabelAlignment( -1, vert ); +} + + +void GridFrame::SetColLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) ) +{ + int horiz, vert; + grid->GetColLabelAlignment( &horiz, &vert ); + + switch ( horiz ) + { + case wxALIGN_LEFT: + horiz = wxALIGN_CENTRE; + break; + + case wxALIGN_CENTRE: + horiz = wxALIGN_RIGHT; + break; + + case wxALIGN_RIGHT: + horiz = wxALIGN_LEFT; + break; + } + + grid->SetColLabelAlignment( horiz, -1 ); +} + + +void GridFrame::SetColLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) ) +{ + int horiz, vert; + grid->GetColLabelAlignment( &horiz, &vert ); + + switch ( vert ) + { + case wxALIGN_TOP: + vert = wxALIGN_CENTRE; + break; + + case wxALIGN_CENTRE: + vert = wxALIGN_BOTTOM; + break; + + case wxALIGN_BOTTOM: + vert = wxALIGN_TOP; + break; + } + + grid->SetColLabelAlignment( -1, vert ); +} + + +void GridFrame::SetGridLineColour( wxCommandEvent& WXUNUSED(ev) ) +{ + wxColourDialog dlg( NULL ); + if ( dlg.ShowModal() == wxID_OK ) + { + wxColourData retData; + retData = dlg.GetColourData(); + wxColour colour = retData.GetColour(); + + grid->SetGridLineColour( colour ); + } +} + + +void GridFrame::InsertRow( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->InsertRows( grid->GetGridCursorRow(), 1 ); +} + + +void GridFrame::InsertCol( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->InsertCols( grid->GetGridCursorCol(), 1 ); +} + + +void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) ) +{ + if ( grid->IsSelection() ) + { + grid->BeginBatch(); + for ( int n = 0; n < grid->GetNumberRows(); ) + if ( grid->IsInSelection( n , 0 ) ) + grid->DeleteRows( n, 1 ); + else + n++; + grid->EndBatch(); + } +} + + +void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) ) +{ + if ( grid->IsSelection() ) + { + grid->BeginBatch(); + for ( int n = 0; n < grid->GetNumberCols(); ) + if ( grid->IsInSelection( 0 , n ) ) + grid->DeleteCols( n, 1 ); + else + n++; + grid->EndBatch(); + } +} + + +void GridFrame::ClearGrid( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->ClearGrid(); +} + +void GridFrame::SelectCells( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->SetSelectionMode( wxGrid::wxGridSelectCells ); +} + +void GridFrame::SelectRows( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->SetSelectionMode( wxGrid::wxGridSelectRows ); +} + +void GridFrame::SelectCols( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->SetSelectionMode( wxGrid::wxGridSelectColumns ); +} + +void GridFrame::SetCellFgColour( wxCommandEvent& WXUNUSED(ev) ) +{ + wxColour col = wxGetColourFromUser(this); + if ( col.Ok() ) + { + grid->SetDefaultCellTextColour(col); + grid->Refresh(); + } +} + +void GridFrame::SetCellBgColour( wxCommandEvent& WXUNUSED(ev) ) +{ + wxColour col = wxGetColourFromUser(this); + if ( col.Ok() ) + { + // Check the new Refresh function by passing it a rectangle + // which exactly fits the grid. + wxRect r(wxPoint(0, 0), grid->GetSize()); + grid->SetDefaultCellBackgroundColour(col); + grid->Refresh(TRUE, &r); + } +} + +void GridFrame::DeselectCell(wxCommandEvent& WXUNUSED(event)) +{ + grid->DeselectCell(3, 1); +} + +void GridFrame::DeselectCol(wxCommandEvent& WXUNUSED(event)) +{ + grid->DeselectCol(2); +} + +void GridFrame::DeselectRow(wxCommandEvent& WXUNUSED(event)) +{ + grid->DeselectRow(2); +} + +void GridFrame::DeselectAll(wxCommandEvent& WXUNUSED(event)) +{ + grid->ClearSelection(); +} + +void GridFrame::SelectCell(wxCommandEvent& WXUNUSED(event)) +{ + grid->SelectBlock(3, 1, 3, 1, m_addToSel); +} + +void GridFrame::SelectCol(wxCommandEvent& WXUNUSED(event)) +{ + grid->SelectCol(2, m_addToSel); +} + +void GridFrame::SelectRow(wxCommandEvent& WXUNUSED(event)) +{ + grid->SelectRow(2, m_addToSel); +} + +void GridFrame::SelectAll(wxCommandEvent& WXUNUSED(event)) +{ + grid->SelectAll(); +} + +void GridFrame::OnAddToSelectToggle(wxCommandEvent& event) +{ + m_addToSel = event.IsChecked(); +} + +void GridFrame::OnLabelLeftClick( wxGridEvent& ev ) +{ + logBuf = _T(""); + if ( ev.GetRow() != -1 ) + { + logBuf << _T("Left click on row label ") << ev.GetRow(); + } + else if ( ev.GetCol() != -1 ) + { + logBuf << _T("Left click on col label ") << ev.GetCol(); + } + else + { + logBuf << _T("Left click on corner label"); + } + + if ( ev.ShiftDown() ) logBuf << _T(" (shift down)"); + if ( ev.ControlDown() ) logBuf << _T(" (control down)"); + wxLogMessage( wxT("%s"), logBuf.c_str() ); + + // you must call event skip if you want default grid processing + // + ev.Skip(); +} + + +void GridFrame::OnCellLeftClick( wxGridEvent& ev ) +{ + logBuf = _T(""); + logBuf << _T("Left click at row ") << ev.GetRow() + << _T(" col ") << ev.GetCol(); + wxLogMessage( wxT("%s"), logBuf.c_str() ); + + // you must call event skip if you want default grid processing + // (cell highlighting etc.) + // + ev.Skip(); +} + + +void GridFrame::OnRowSize( wxGridSizeEvent& ev ) +{ + logBuf = _T(""); + logBuf << _T("Resized row ") << ev.GetRowOrCol(); + wxLogMessage( wxT("%s"), logBuf.c_str() ); + + ev.Skip(); +} + + +void GridFrame::OnColSize( wxGridSizeEvent& ev ) +{ + logBuf = _T(""); + logBuf << _T("Resized col ") << ev.GetRowOrCol(); + wxLogMessage( wxT("%s"), logBuf.c_str() ); + + ev.Skip(); +} + + +void GridFrame::OnSelectCell( wxGridEvent& ev ) +{ + logBuf = _T(""); + if ( ev.Selecting() ) + logBuf << _T("Selected "); + else + logBuf << _T("Deselected "); + logBuf << _T("cell at row ") << ev.GetRow() + << _T(" col ") << ev.GetCol() + << _T(" ( ControlDown: ")<< (ev.ControlDown() ? 'T':'F') + << _T(", ShiftDown: ")<< (ev.ShiftDown() ? 'T':'F') + << _T(", AltDown: ")<< (ev.AltDown() ? 'T':'F') + << _T(", MetaDown: ")<< (ev.MetaDown() ? 'T':'F') << _T(" )"); + wxLogMessage( wxT("%s"), logBuf.c_str() ); + + // you must call Skip() if you want the default processing + // to occur in wxGrid + ev.Skip(); +} + +void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) +{ + logBuf = _T(""); + if ( ev.Selecting() ) + logBuf << _T("Selected "); + else + logBuf << _T("Deselected "); + logBuf << _T("cells from row ") << ev.GetTopRow() + << _T(" col ") << ev.GetLeftCol() + << _T(" to row ") << ev.GetBottomRow() + << _T(" col ") << ev.GetRightCol() + << _T(" ( ControlDown: ")<< (ev.ControlDown() ? 'T':'F') + << _T(", ShiftDown: ")<< (ev.ShiftDown() ? 'T':'F') + << _T(", AltDown: ")<< (ev.AltDown() ? 'T':'F') + << _T(", MetaDown: ")<< (ev.MetaDown() ? 'T':'F') << _T(" )"); + wxLogMessage( wxT("%s"), logBuf.c_str() ); + + ev.Skip(); +} + +void GridFrame::OnCellValueChanged( wxGridEvent& ev ) +{ + logBuf = _T(""); + logBuf << _T("Value changed for cell at") + << _T(" row ") << ev.GetRow() + << _T(" col ") << ev.GetCol(); + + wxLogMessage( wxT("%s"), logBuf.c_str() ); + + ev.Skip(); +} + +void GridFrame::OnEditorShown( wxGridEvent& ev ) +{ + + if ( (ev.GetCol() == 4) && + (ev.GetRow() == 0) && + (wxMessageBox(_T("Are you sure you wish to edit this cell"), + _T("Checking"),wxYES_NO) == wxNO ) ) { + + ev.Veto(); + return; + } + + wxLogMessage( wxT("Cell editor shown.") ); + + ev.Skip(); +} + +void GridFrame::OnEditorHidden( wxGridEvent& ev ) +{ + + if ( (ev.GetCol() == 4) && + (ev.GetRow() == 0) && + (wxMessageBox(_T("Are you sure you wish to finish editing this cell"), + _T("Checking"),wxYES_NO) == wxNO ) ) { + + ev.Veto(); + return; + } + + wxLogMessage( wxT("Cell editor hidden.") ); + + ev.Skip(); +} + +void GridFrame::About( wxCommandEvent& WXUNUSED(ev) ) +{ + (void)wxMessageBox( _T("\n\nwxGrid demo \n\n") + _T("Michael Bedward \n") + _T("mbedward@ozemail.com.au \n\n"), + _T("About"), + wxOK ); +} + + +void GridFrame::OnQuit( wxCommandEvent& WXUNUSED(ev) ) +{ + Close( TRUE ); +} + +void GridFrame::OnBugsTable(wxCommandEvent& ) +{ + BugsGridFrame *frame = new BugsGridFrame; + frame->Show(TRUE); +} + +void GridFrame::OnSmallGrid(wxCommandEvent& ) +{ + wxFrame* frame = new wxFrame(NULL, -1, _T("A Small Grid"), + wxDefaultPosition, wxSize(640, 480)); + wxPanel* panel = new wxPanel(frame, -1); + wxGrid* grid = new wxGrid(panel, -1, wxPoint(10,10), wxSize(400,400), + wxWANTS_CHARS | wxSIMPLE_BORDER); + grid->CreateGrid(3,3); + frame->Show(TRUE); +} + +void GridFrame::OnVTable(wxCommandEvent& ) +{ + static long s_sizeGrid = 10000; + +#ifdef __WXMOTIF__ + // MB: wxGetNumberFromUser doesn't work properly for wxMotif + wxString s; + s << s_sizeGrid; + s = wxGetTextFromUser( _T("Size of the table to create"), + _T("Size:"), + s ); + + s.ToLong( &s_sizeGrid ); + +#else + s_sizeGrid = wxGetNumberFromUser(_T("Size of the table to create"), + _T("Size: "), + _T("wxGridDemo question"), + s_sizeGrid, + 0, 32000, this); +#endif + + if ( s_sizeGrid != -1 ) + { + BigGridFrame* win = new BigGridFrame(s_sizeGrid); + win->Show(TRUE); + } +} + +// ---------------------------------------------------------------------------- +// MyGridCellRenderer +// ---------------------------------------------------------------------------- + +// do something that the default renderer doesn't here just to show that it is +// possible to alter the appearance of the cell beyond what the attributes +// allow +void MyGridCellRenderer::Draw(wxGrid& grid, + wxGridCellAttr& attr, + wxDC& dc, + const wxRect& rect, + int row, int col, + bool isSelected) +{ + wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected); + + dc.SetPen(*wxGREEN_PEN); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawEllipse(rect); +} + +// ---------------------------------------------------------------------------- +// MyGridCellAttrProvider +// ---------------------------------------------------------------------------- + +MyGridCellAttrProvider::MyGridCellAttrProvider() +{ + m_attrForOddRows = new wxGridCellAttr; + m_attrForOddRows->SetBackgroundColour(*wxLIGHT_GREY); +} + +MyGridCellAttrProvider::~MyGridCellAttrProvider() +{ + m_attrForOddRows->DecRef(); +} + +wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col, + wxGridCellAttr::wxAttrKind kind /* = wxGridCellAttr::Any */) const +{ + wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind); + + if ( row % 2 ) + { + if ( !attr ) + { + attr = m_attrForOddRows; + attr->IncRef(); + } + else + { + if ( !attr->HasBackgroundColour() ) + { + wxGridCellAttr *attrNew = attr->Clone(); + attr->DecRef(); + attr = attrNew; + attr->SetBackgroundColour(*wxLIGHT_GREY); + } + } + } + + return attr; +} + +// ============================================================================ +// BigGridFrame and BigGridTable: Sample of a non-standard table +// ============================================================================ + +BigGridFrame::BigGridFrame(long sizeGrid) + : wxFrame(NULL, -1, _T("Plugin Virtual Table"), + wxDefaultPosition, wxSize(500, 450)) +{ + m_grid = new wxGrid(this, -1, wxDefaultPosition, wxDefaultSize); + m_table = new BigGridTable(sizeGrid); + + // VZ: I don't understand why this slows down the display that much, + // must profile it... + //m_table->SetAttrProvider(new MyGridCellAttrProvider); + + m_grid->SetTable(m_table, TRUE); + +#if defined __WXMOTIF__ + // MB: the grid isn't getting a sensible default size under wxMotif + int cw, ch; + GetClientSize( &cw, &ch ); + m_grid->SetSize( cw, ch ); +#endif +} + +// ============================================================================ +// BugsGridFrame: a "realistic" table +// ============================================================================ + +// ---------------------------------------------------------------------------- +// bugs table data +// ---------------------------------------------------------------------------- + +enum Columns +{ + Col_Id, + Col_Summary, + Col_Severity, + Col_Priority, + Col_Platform, + Col_Opened, + Col_Max +}; + +enum Severity +{ + Sev_Wish, + Sev_Minor, + Sev_Normal, + Sev_Major, + Sev_Critical, + Sev_Max +}; + +static const wxString severities[] = +{ + _T("wishlist"), + _T("minor"), + _T("normal"), + _T("major"), + _T("critical"), +}; + +static struct BugsGridData +{ + int id; + wxChar summary[80]; + Severity severity; + int prio; + wxChar platform[12]; + bool opened; +} gs_dataBugsGrid [] = +{ + { 18, _T("foo doesn't work"), Sev_Major, 1, _T("wxMSW"), TRUE }, + { 27, _T("bar crashes"), Sev_Critical, 1, _T("all"), FALSE }, + { 45, _T("printing is slow"), Sev_Minor, 3, _T("wxMSW"), TRUE }, + { 68, _T("Rectangle() fails"), Sev_Normal, 1, _T("wxMSW"), FALSE }, +}; + +static const wxChar *headers[Col_Max] = +{ + _T("Id"), + _T("Summary"), + _T("Severity"), + _T("Priority"), + _T("Platform"), + _T("Opened?"), +}; + +// ---------------------------------------------------------------------------- +// BugsGridTable +// ---------------------------------------------------------------------------- + +wxString BugsGridTable::GetTypeName(int WXUNUSED(row), int col) +{ + switch ( col ) + { + case Col_Id: + case Col_Priority: + return wxGRID_VALUE_NUMBER;; + + case Col_Severity: + // fall thorugh (TODO should be a list) + + case Col_Summary: + return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING); + + case Col_Platform: + return wxString::Format(_T("%s:all,MSW,GTK,other"), wxGRID_VALUE_CHOICE); + + case Col_Opened: + return wxGRID_VALUE_BOOL; + } + + wxFAIL_MSG(_T("unknown column")); + + return wxEmptyString; +} + +int BugsGridTable::GetNumberRows() +{ + return WXSIZEOF(gs_dataBugsGrid); +} + +int BugsGridTable::GetNumberCols() +{ + return Col_Max; +} + +bool BugsGridTable::IsEmptyCell( int row, int col ) +{ + return FALSE; +} + +wxString BugsGridTable::GetValue( int row, int col ) +{ + const BugsGridData& gd = gs_dataBugsGrid[row]; + + switch ( col ) + { + case Col_Id: + case Col_Priority: + case Col_Opened: + wxFAIL_MSG(_T("unexpected column")); + break; + + case Col_Severity: + return severities[gd.severity]; + + case Col_Summary: + return gd.summary; + + case Col_Platform: + return gd.platform; + } + + return wxEmptyString; +} + +void BugsGridTable::SetValue( int row, int col, const wxString& value ) +{ + BugsGridData& gd = gs_dataBugsGrid[row]; + + switch ( col ) + { + case Col_Id: + case Col_Priority: + case Col_Opened: + wxFAIL_MSG(_T("unexpected column")); + break; + + case Col_Severity: + { + size_t n; + for ( n = 0; n < WXSIZEOF(severities); n++ ) + { + if ( severities[n] == value ) + { + gd.severity = (Severity)n; + break; + } + } + + if ( n == WXSIZEOF(severities) ) + { + wxLogWarning(_T("Invalid severity value '%s'."), + value.c_str()); + gd.severity = Sev_Normal; + } + } + break; + + case Col_Summary: + wxStrncpy(gd.summary, value, WXSIZEOF(gd.summary)); + break; + + case Col_Platform: + wxStrncpy(gd.platform, value, WXSIZEOF(gd.platform)); + break; + } +} + +bool BugsGridTable::CanGetValueAs( int WXUNUSED(row), int col, const wxString& typeName ) +{ + if ( typeName == wxGRID_VALUE_STRING ) + { + return TRUE; + } + else if ( typeName == wxGRID_VALUE_BOOL ) + { + return col == Col_Opened; + } + else if ( typeName == wxGRID_VALUE_NUMBER ) + { + return col == Col_Id || col == Col_Priority || col == Col_Severity; + } + else + { + return FALSE; + } +} + +bool BugsGridTable::CanSetValueAs( int row, int col, const wxString& typeName ) +{ + return CanGetValueAs(row, col, typeName); +} + +long BugsGridTable::GetValueAsLong( int row, int col ) +{ + const BugsGridData& gd = gs_dataBugsGrid[row]; + + switch ( col ) + { + case Col_Id: + return gd.id; + + case Col_Priority: + return gd.prio; + + case Col_Severity: + return gd.severity; + + default: + wxFAIL_MSG(_T("unexpected column")); + return -1; + } +} + +bool BugsGridTable::GetValueAsBool( int row, int col ) +{ + if ( col == Col_Opened ) + { + return gs_dataBugsGrid[row].opened; + } + else + { + wxFAIL_MSG(_T("unexpected column")); + + return FALSE; + } +} + +void BugsGridTable::SetValueAsLong( int row, int col, long value ) +{ + BugsGridData& gd = gs_dataBugsGrid[row]; + + switch ( col ) + { + case Col_Priority: + gd.prio = value; + break; + + default: + wxFAIL_MSG(_T("unexpected column")); + } +} + +void BugsGridTable::SetValueAsBool( int row, int col, bool value ) +{ + if ( col == Col_Opened ) + { + gs_dataBugsGrid[row].opened = value; + } + else + { + wxFAIL_MSG(_T("unexpected column")); + } +} + +wxString BugsGridTable::GetColLabelValue( int col ) +{ + return headers[col]; +} + +BugsGridTable::BugsGridTable() +{ +} + +// ---------------------------------------------------------------------------- +// BugsGridFrame +// ---------------------------------------------------------------------------- + +BugsGridFrame::BugsGridFrame() + : wxFrame(NULL, -1, _T("Bugs table"), + wxDefaultPosition, wxSize(500, 300)) +{ + wxGrid *grid = new wxGrid(this, -1, wxDefaultPosition); + wxGridTableBase *table = new BugsGridTable(); + table->SetAttrProvider(new MyGridCellAttrProvider); + grid->SetTable(table, TRUE); + + wxGridCellAttr *attrRO = new wxGridCellAttr, + *attrRangeEditor = new wxGridCellAttr, + *attrCombo = new wxGridCellAttr; + + attrRO->SetReadOnly(); + attrRangeEditor->SetEditor(new wxGridCellNumberEditor(1, 5)); + attrCombo->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities), + severities)); + + grid->SetColAttr(Col_Id, attrRO); + grid->SetColAttr(Col_Priority, attrRangeEditor); + grid->SetColAttr(Col_Severity, attrCombo); + + grid->SetMargins(0, 0); + + grid->Fit(); + SetClientSize(grid->GetSize()); +} + + diff --git a/samples/grid/grid.dsp b/samples/grid/griddemo.dsp similarity index 79% rename from samples/grid/grid.dsp rename to samples/grid/griddemo.dsp index 3cf0021106..ac2eab78a5 100644 --- a/samples/grid/grid.dsp +++ b/samples/grid/griddemo.dsp @@ -1,26 +1,26 @@ -# Microsoft Developer Studio Project File - Name="grid" - Package Owner=<4> +# Microsoft Developer Studio Project File - Name="griddemo" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Application" 0x0101 -CFG=grid - Win32 Debug +CFG=griddemo - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE -!MESSAGE NMAKE /f "grid.mak". +!MESSAGE NMAKE /f "griddemo.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE -!MESSAGE NMAKE /f "grid.mak" CFG="grid - Win32 Debug" +!MESSAGE NMAKE /f "griddemo.mak" CFG="griddemo - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE -!MESSAGE "grid - Win32 Release DLL" (based on "Win32 (x86) Application") -!MESSAGE "grid - Win32 Debug DLL" (based on "Win32 (x86) Application") -!MESSAGE "grid - Win32 Release" (based on "Win32 (x86) Application") -!MESSAGE "grid - Win32 Debug" (based on "Win32 (x86) Application") +!MESSAGE "griddemo - Win32 Release DLL" (based on "Win32 (x86) Application") +!MESSAGE "griddemo - Win32 Debug DLL" (based on "Win32 (x86) Application") +!MESSAGE "griddemo - Win32 Release" (based on "Win32 (x86) Application") +!MESSAGE "griddemo - Win32 Debug" (based on "Win32 (x86) Application") !MESSAGE # Begin Project @@ -30,7 +30,7 @@ CPP=cl.exe MTL=midl.exe RSC=rc.exe -!ELSEIF "$(CFG)" == "grid - Win32 Release DLL" +!ELSEIF "$(CFG)" == "griddemo - Win32 Release DLL" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 @@ -44,11 +44,11 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W4 /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /YX /FD /c -# ADD CPP /nologo /W4 /O2 /I "../../include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MD /D WXUSINGDLL /I..\..\lib\mswdll +# ADD CPP /nologo /W4 /O2 /I "..\..\include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MD /D WXUSINGDLL /I..\..\lib\mswdll # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" /I "../../include" -# ADD RSC /l 0x409 /d "NDEBUG" /I "../../include" +# ADD BASE RSC /l 0x409 /d "NDEBUG" /I "..\..\include" +# ADD RSC /l 0x409 /d "NDEBUG" /I "..\..\include" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo @@ -56,7 +56,7 @@ LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /machine:I386 ..\..\lib\wxmsw250.lib -!ELSEIF "$(CFG)" == "grid - Win32 Debug DLL" +!ELSEIF "$(CFG)" == "griddemo - Win32 Debug DLL" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 @@ -70,11 +70,11 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W4 /Zi /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /YX /FD /c -# ADD CPP /nologo /W4 /Zi /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MDd /D "__WXDEBUG__" /D "WXDEBUG=1" /D WXUSINGDLL /I..\..\lib\mswdlld +# ADD CPP /nologo /W4 /Zi /Od /I "..\..\include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MDd /D "__WXDEBUG__" /D "WXDEBUG=1" /D WXUSINGDLL /I..\..\lib\mswdlld # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" /I "../../include" -# ADD RSC /l 0x409 /d "_DEBUG" /I "../../include" +# ADD BASE RSC /l 0x409 /d "_DEBUG" /I "..\..\include" +# ADD RSC /l 0x409 /d "_DEBUG" /I "..\..\include" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo @@ -82,7 +82,7 @@ LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept ..\..\lib\wxmsw250d.lib -!ELSEIF "$(CFG)" == "grid - Win32 Release" +!ELSEIF "$(CFG)" == "griddemo - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 @@ -96,11 +96,11 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W4 /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /YX /FD /c -# ADD CPP /nologo /W4 /O2 /I "../../include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MD /I..\..\lib\msw +# ADD CPP /nologo /W4 /O2 /I "..\..\include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MD /I..\..\lib\msw # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 -# ADD BASE RSC /l 0x409 /d "NDEBUG" /I "../../include" -# ADD RSC /l 0x409 /d "NDEBUG" /I "../../include" +# ADD BASE RSC /l 0x409 /d "NDEBUG" /I "..\..\include" +# ADD RSC /l 0x409 /d "NDEBUG" /I "..\..\include" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo @@ -108,7 +108,7 @@ LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /machine:I386 ..\..\lib\zlib.lib ..\..\lib\regex.lib ..\..\lib\png.lib ..\..\lib\jpeg.lib ..\..\lib\tiff.lib ..\..\lib\wxmsw.lib -!ELSEIF "$(CFG)" == "grid - Win32 Debug" +!ELSEIF "$(CFG)" == "griddemo - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 @@ -122,11 +122,11 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W4 /Zi /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /YX /FD /c -# ADD CPP /nologo /W4 /Zi /Od /I "../../include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MDd /D "__WXDEBUG__" /D "WXDEBUG=1" /I..\..\lib\mswd +# ADD CPP /nologo /W4 /Zi /Od /I "..\..\include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MDd /D "__WXDEBUG__" /D "WXDEBUG=1" /I..\..\lib\mswd # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 -# ADD BASE RSC /l 0x409 /d "_DEBUG" /I "../../include" -# ADD RSC /l 0x409 /d "_DEBUG" /I "../../include" +# ADD BASE RSC /l 0x409 /d "_DEBUG" /I "..\..\include" +# ADD RSC /l 0x409 /d "_DEBUG" /I "..\..\include" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo @@ -138,17 +138,17 @@ LINK32=link.exe # Begin Target -# Name "grid - Win32 Release DLL" -# Name "grid - Win32 Debug DLL" -# Name "grid - Win32 Release" -# Name "grid - Win32 Debug" +# Name "griddemo - Win32 Release DLL" +# Name "griddemo - Win32 Debug DLL" +# Name "griddemo - Win32 Release" +# Name "griddemo - Win32 Debug" # Begin Source File -SOURCE=.\grid.cpp +SOURCE=.\griddemo.cpp # End Source File # Begin Source File -SOURCE=.\grid.rc +SOURCE=.\griddemo.rc # End Source File # End Target # End Project diff --git a/samples/grid/griddemo.h b/samples/grid/griddemo.h new file mode 100644 index 0000000000..3fa91e0ce5 --- /dev/null +++ b/samples/grid/griddemo.h @@ -0,0 +1,261 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: griddemo.h +// Purpose: Grid control wxWindows sample +// Author: Michael Bedward +// Modified by: +// RCS-ID: $Id$ +// Copyright: (c) Michael Bedward, Julian Smart +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + + +#ifndef griddemo_h +#define griddemo_h + +#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) + #error "This sample requires the new wxGrid class." +#endif + +class wxGrid; + +class GridApp : public wxApp +{ +public: + bool OnInit(); +}; + + +class GridFrame : public wxFrame +{ + wxGrid *grid; + wxTextCtrl *logWin; + wxLogTextCtrl *logger; + wxString logBuf; + + void SetDefaults(); + + void ToggleRowLabels( wxCommandEvent& ); + void ToggleColLabels( wxCommandEvent& ); + void ToggleEditing( wxCommandEvent& ); + void ToggleRowSizing( wxCommandEvent& ); + void ToggleColSizing( wxCommandEvent& ); + void ToggleGridSizing( wxCommandEvent& ); + void ToggleGridLines( wxCommandEvent& ); + void AutoSizeCols( wxCommandEvent& ); + void CellOverflow( wxCommandEvent& ); + void ResizeCell( wxCommandEvent& ); + void SetLabelColour( wxCommandEvent& ); + void SetLabelTextColour( wxCommandEvent& ); + void SetLabelFont(wxCommandEvent &); + void SetRowLabelHorizAlignment( wxCommandEvent& ); + void SetRowLabelVertAlignment( wxCommandEvent& ); + void SetColLabelHorizAlignment( wxCommandEvent& ); + void SetColLabelVertAlignment( wxCommandEvent& ); + void SetGridLineColour( wxCommandEvent& ); + + void SetCellFgColour(wxCommandEvent &); + void SetCellBgColour(wxCommandEvent &); + + void InsertRow( wxCommandEvent& ); + void InsertCol( wxCommandEvent& ); + void DeleteSelectedRows( wxCommandEvent& ); + void DeleteSelectedCols( wxCommandEvent& ); + void ClearGrid( wxCommandEvent& ); + void SelectCells( wxCommandEvent& ); + void SelectRows( wxCommandEvent& ); + void SelectCols( wxCommandEvent& ); + + void DeselectCell(wxCommandEvent& event); + void DeselectCol(wxCommandEvent& event); + void DeselectRow(wxCommandEvent& event); + void DeselectAll(wxCommandEvent& event); + void SelectCell(wxCommandEvent& event); + void SelectCol(wxCommandEvent& event); + void SelectRow(wxCommandEvent& event); + void SelectAll(wxCommandEvent& event); + void OnAddToSelectToggle(wxCommandEvent& event); + + void OnLabelLeftClick( wxGridEvent& ); + void OnCellLeftClick( wxGridEvent& ); + void OnRowSize( wxGridSizeEvent& ); + void OnColSize( wxGridSizeEvent& ); + void OnSelectCell( wxGridEvent& ); + void OnRangeSelected( wxGridRangeSelectEvent& ); + void OnCellValueChanged( wxGridEvent& ); + + void OnEditorShown(wxGridEvent&); + void OnEditorHidden(wxGridEvent&); + + void OnSetHighlightWidth(wxCommandEvent&); + void OnSetROHighlightWidth(wxCommandEvent&); + +public: + GridFrame(); + ~GridFrame(); + + void OnQuit( wxCommandEvent& ); + void About( wxCommandEvent& ); + void OnVTable( wxCommandEvent& ); + void OnBugsTable( wxCommandEvent& ); + void OnSmallGrid( wxCommandEvent& ); + + enum + { + ID_TOGGLEROWLABELS = 100, + ID_TOGGLECOLLABELS, + ID_TOGGLEEDIT, + ID_TOGGLEROWSIZING, + ID_TOGGLECOLSIZING, + ID_TOGGLEGRIDSIZING, + ID_TOGGLEGRIDLINES, + ID_AUTOSIZECOLS, + ID_CELLOVERFLOW, + ID_RESIZECELL, + ID_SETLABELCOLOUR, + ID_SETLABELTEXTCOLOUR, + ID_SETLABEL_FONT, + ID_ROWLABELALIGN, + ID_ROWLABELHORIZALIGN, + ID_ROWLABELVERTALIGN, + ID_COLLABELALIGN, + ID_COLLABELHORIZALIGN, + ID_COLLABELVERTALIGN, + ID_GRIDLINECOLOUR, + ID_INSERTROW, + ID_INSERTCOL, + ID_DELETEROW, + ID_DELETECOL, + ID_CLEARGRID, + ID_CHANGESEL, + ID_SELCELLS, + ID_SELROWS, + ID_SELCOLS, + ID_SET_CELL_FG_COLOUR, + ID_SET_CELL_BG_COLOUR, + ID_ABOUT, + ID_VTABLE, + ID_BUGS_TABLE, + ID_SMALL_GRID, + ID_SELECT_UNSELECT, + ID_SELECT_ALL, + ID_SELECT_ROW, + ID_SELECT_COL, + ID_SELECT_CELL, + ID_DESELECT_ALL, + ID_DESELECT_ROW, + ID_DESELECT_COL, + ID_DESELECT_CELL, + + ID_SET_HIGHLIGHT_WIDTH, + ID_SET_RO_HIGHLIGHT_WIDTH, + + ID_TESTFUNC + }; + + wxLog *m_logOld; + + // add the cells to selection when using commands from select menu? + bool m_addToSel; + + DECLARE_EVENT_TABLE() +}; + +class MyGridCellRenderer : public wxGridCellStringRenderer +{ +public: + virtual void Draw(wxGrid& grid, + wxGridCellAttr& attr, + wxDC& dc, + const wxRect& rect, + int row, int col, + bool isSelected); +}; + +// ---------------------------------------------------------------------------- +// demonstration of virtual table which doesn't store all of its data in +// memory +// ---------------------------------------------------------------------------- + +class BigGridTable : public wxGridTableBase +{ +public: + BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; } + + int GetNumberRows() { return m_sizeGrid; } + int GetNumberCols() { return m_sizeGrid; } + wxString GetValue( int row, int col ) + { + return wxString::Format(wxT("(%d, %d)"), row, col); + } + + void SetValue( int , int , const wxString& ) { /* ignore */ } + bool IsEmptyCell( int , int ) { return FALSE; } + +private: + long m_sizeGrid; +}; + +class BigGridFrame : public wxFrame +{ +public: + BigGridFrame(long sizeGrid); + +private: + wxGrid* m_grid; + BigGridTable* m_table; +}; + +// ---------------------------------------------------------------------------- +// an example of custom attr provider: this one makes all odd rows appear grey +// ---------------------------------------------------------------------------- + +class MyGridCellAttrProvider : public wxGridCellAttrProvider +{ +public: + MyGridCellAttrProvider(); + virtual ~MyGridCellAttrProvider(); + + virtual wxGridCellAttr *GetAttr(int row, int col, + wxGridCellAttr::wxAttrKind kind) const; + +private: + wxGridCellAttr *m_attrForOddRows; +}; + +// ---------------------------------------------------------------------------- +// another, more realistic, grid example: shows typed columns and more +// ---------------------------------------------------------------------------- + +class BugsGridTable : public wxGridTableBase +{ +public: + BugsGridTable(); + + virtual int GetNumberRows(); + virtual int GetNumberCols(); + virtual bool IsEmptyCell( int row, int col ); + virtual wxString GetValue( int row, int col ); + virtual void SetValue( int row, int col, const wxString& value ); + + virtual wxString GetColLabelValue( int col ); + + virtual wxString GetTypeName( int row, int col ); + virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); + virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); + + virtual long GetValueAsLong( int row, int col ); + virtual bool GetValueAsBool( int row, int col ); + + virtual void SetValueAsLong( int row, int col, long value ); + virtual void SetValueAsBool( int row, int col, bool value ); +}; + +class BugsGridFrame : public wxFrame +{ +public: + BugsGridFrame(); +}; + + +#endif // griddemo_h + diff --git a/samples/grid/grid.pro b/samples/grid/griddemo.pro similarity index 87% rename from samples/grid/grid.pro rename to samples/grid/griddemo.pro index 358c625b82..5995643965 100644 --- a/samples/grid/grid.pro +++ b/samples/grid/griddemo.pro @@ -12,6 +12,6 @@ CONFIG = wx #WXCONFIGS = Debug Release DebugDll ReleaseDll # project files -SOURCES = grid.cpp -RC_FILE = grid.rc -TARGET = grid +SOURCES = griddemo.cpp +RC_FILE = griddemo.rc +TARGET = griddemo diff --git a/samples/grid/griddemo.rc b/samples/grid/griddemo.rc new file mode 100644 index 0000000000..82bdf07561 --- /dev/null +++ b/samples/grid/griddemo.rc @@ -0,0 +1,2 @@ +#include "wx/msw/wx.rc" + diff --git a/samples/grid/gridM5.xml b/samples/grid/griddemoM5.xml similarity index 99% rename from samples/grid/gridM5.xml rename to samples/grid/griddemoM5.xml index 8f9f4c30e0..bc1200b102 100644 --- a/samples/grid/gridM5.xml +++ b/samples/grid/griddemoM5.xml @@ -480,7 +480,7 @@ MWMerge_MacOS_copyResources1 MWMerge_MacOS_skipResources - ”¹à + ”ݐ =ÃH =Ø: @@ -556,7 +556,7 @@ MWProject_PPC_typeApplication - MWProject_PPC_outfilegrid Classic Release + MWProject_PPC_outfilegriddemo Classic Release MWProject_PPC_filecreator1061109567 MWProject_PPC_filetype1095782476 MWProject_PPC_size3840 @@ -664,7 +664,7 @@ Name - grid.cpp + griddemo.cpp MacOS Text @@ -891,7 +891,7 @@ Name - grid.cpp + griddemo.cpp MacOS @@ -1456,7 +1456,7 @@ MWMerge_MacOS_copyResources1 MWMerge_MacOS_skipResources - ”¹à + ”ݐ =ÃH =Ø: @@ -1532,7 +1532,7 @@ MWProject_PPC_typeApplication - MWProject_PPC_outfilegrid Classic Debug + MWProject_PPC_outfilegriddemo Classic Debug MWProject_PPC_filecreator1061109567 MWProject_PPC_filetype1095782476 MWProject_PPC_size3840 @@ -1640,7 +1640,7 @@ Name - grid.cpp + griddemo.cpp MacOS Text Debug @@ -1867,7 +1867,7 @@ Name - grid.cpp + griddemo.cpp MacOS @@ -2424,7 +2424,7 @@ MWMerge_MacOS_copyResources1 MWMerge_MacOS_skipResources - ”¹à + ”ݐ =ÃH =Ø: @@ -2500,7 +2500,7 @@ MWProject_PPC_typeApplication - MWProject_PPC_outfilegrid Carbon Debug + MWProject_PPC_outfilegriddemo Carbon Debug MWProject_PPC_filecreator1061109567 MWProject_PPC_filetype1095782476 MWProject_PPC_size3840 @@ -2608,7 +2608,7 @@ Name - grid.cpp + griddemo.cpp MacOS Text Debug @@ -2681,7 +2681,7 @@ Name - grid.cpp + griddemo.cpp MacOS @@ -3128,7 +3128,7 @@ MWMerge_MacOS_copyResources1 MWMerge_MacOS_skipResources - ”¹à + ”ݐ =ÃH =Ø: @@ -3204,7 +3204,7 @@ MWProject_PPC_typeApplication - MWProject_PPC_outfilegrid Carbon Release + MWProject_PPC_outfilegriddemo Carbon Release MWProject_PPC_filecreator1061109567 MWProject_PPC_filetype1095782476 MWProject_PPC_size3840 @@ -3298,21 +3298,21 @@ Name - grid.cpp + griddemo.cpp MacOS Text Name - png.lib + zlib.lib MacOS Library Name - zlib.lib + png.lib MacOS Library @@ -3375,17 +3375,17 @@ Name - grid.cpp + griddemo.cpp MacOS Name - png.lib + zlib.lib MacOS Name - zlib.lib + png.lib MacOS @@ -3413,7 +3413,7 @@ Classic Release Name - grid.cpp + griddemo.cpp MacOS wx diff --git a/samples/grid/gridM7.mcp b/samples/grid/griddemoM7.mcp similarity index 100% rename from samples/grid/gridM7.mcp rename to samples/grid/griddemoM7.mcp diff --git a/samples/grid/makefile.b32 b/samples/grid/makefile.b32 index 05eecd7959..b606a6649a 100644 --- a/samples/grid/makefile.b32 +++ b/samples/grid/makefile.b32 @@ -1,10 +1,17 @@ -# Purpose: makefile for grid example (BC++ 32bit) -# Created: 2000-03-15 +# +# File: makefile.b32 +# Author: Michael Bedward +# Created: 1999 +# Updated: +# Copyright: +# +# Makefile : Builds sample for 32-bit BC++ WXDIR = $(WXWIN) -TARGET=grid -OBJECTS = $(TARGET).obj +TARGET=griddemo + +OBJECTS = griddemo.obj !include $(WXDIR)\src\makeprog.b32 diff --git a/samples/grid/makefile.bcc b/samples/grid/makefile.bcc index 37c91fe0af..42ddcecda7 100644 --- a/samples/grid/makefile.bcc +++ b/samples/grid/makefile.bcc @@ -1,5 +1,10 @@ -# Purpose: makefile for grid example (BC++ 16bit) -# Created: 2000-03-15 +# +# File: makefile.bcc +# Author: Michael Bedward +# Created: 1999 +# Updated: +# +# Builds a BC++ 16-bit sample !if "$(WXWIN)" == "" !error You must define the WXWIN variable in autoexec.bat, e.g. WXWIN=c:\wx @@ -7,7 +12,7 @@ WXDIR = $(WXWIN) -TARGET=grid +TARGET=griddemo OBJECTS=$(TARGET).obj !include $(WXDIR)\src\makeprog.bcc diff --git a/samples/grid/makefile.dos b/samples/grid/makefile.dos index 6ebe4f8a5e..e841765992 100644 --- a/samples/grid/makefile.dos +++ b/samples/grid/makefile.dos @@ -1,9 +1,16 @@ -# Purpose: makefile for grid example (VC++ 1.5x) -# Created: 2000-03-15 +# +# File: makefile.dos +# Author: Michael Bedward +# Created: 1999 +# Updated: +# +# Makefile : Builds 16-bit sample, VC++ 1.5 +# Use FINAL=1 argument to nmake to build final version with no debugging +# info WXDIR = $(WXWIN) -TARGET=grid +TARGET=griddemo OBJECTS=$(TARGET).obj !include $(WXDIR)\src\makeprog.msc diff --git a/samples/grid/makefile.g95 b/samples/grid/makefile.g95 index e2f55732d5..b81d8cc55c 100644 --- a/samples/grid/makefile.g95 +++ b/samples/grid/makefile.g95 @@ -1,9 +1,14 @@ -# Purpose: makefile for grid example (Cygwin/Mingw32) -# Created: #03.01.00 +# +# File: makefile.g95 +# Author: Michael Bedward +# Created: 1999 +# Updated: +# +# Makefile for wxWindows sample (Cygwin/Mingw32). WXDIR = ../.. -TARGET=grid +TARGET=griddemo OBJECTS = $(TARGET).o include $(WXDIR)/src/makeprog.g95 diff --git a/samples/grid/makefile.sc b/samples/grid/makefile.sc index 200240cfc9..61968af568 100644 --- a/samples/grid/makefile.sc +++ b/samples/grid/makefile.sc @@ -1,17 +1,16 @@ -# Purpose: makefile for grid example (Symantec C++) -# Created: 2000-03-15 +# Symantec C++ makefile WXDIR = $(WXWIN) WXLIB = $(WXDIR)\lib\wx.lib INCDIR = $(WXDIR)\include INCLUDE=$(INCDIR) -TARGET=grid +TARGET=griddemo include $(WXDIR)\src\makesc.env -grid.exe: grid.obj $(DEFFILE) grid.res +griddemo.exe: griddemo.obj $(DEFFILE) griddemo.res *$(CC) $(LDFLAGS) -o$@ $** $(LIBS) - *$(RC) -k grid.res + *$(RC) -k griddemo.res sc32.def: echo EXETYPE NT > sc32.def diff --git a/samples/grid/makefile.twn b/samples/grid/makefile.twn index 6ceef03622..b2877e55e8 100644 --- a/samples/grid/makefile.twn +++ b/samples/grid/makefile.twn @@ -7,29 +7,29 @@ WXDIR = ../.. # this central makefile. include $(WXDIR)/src/maketwin.env -OBJECTS = $(OBJDIR)/grid.$(OBJSUFF) $(OBJDIR)/grid.$(OBJSUFF) +OBJECTS = $(OBJDIR)/griddemo.$(OBJSUFF) $(OBJDIR)/griddemo.$(OBJSUFF) -all: $(OBJDIR) grid$(GUISUFFIX)$(EXESUFF) +all: $(OBJDIR) griddemo$(GUISUFFIX)$(EXESUFF) wx: $(OBJDIR): mkdir $(OBJDIR) -grid$(GUISUFFIX)$(EXESUFF): $(OBJECTS) $(WXLIB) - $(CC) $(LDFLAGS) -o grid$(GUISUFFIX)$(EXESUFF) $(OBJECTS) $(LDLIBS) +griddemo$(GUISUFFIX)$(EXESUFF): $(OBJECTS) $(WXLIB) + $(CC) $(LDFLAGS) -o griddemo$(GUISUFFIX)$(EXESUFF) $(OBJECTS) $(LDLIBS) -$(OBJDIR)/grid.$(OBJSUFF): grid.$(SRCSUFF) - $(CC) -c $(CPPFLAGS) -o $@ grid.$(SRCSUFF) +$(OBJDIR)/griddemo.$(OBJSUFF): griddemo.$(SRCSUFF) + $(CC) -c $(CPPFLAGS) -o $@ griddemo.$(SRCSUFF) -grid.c: grid.rc - $(RESCOMP) $(RCINPUTSWITCH) grid.rc $(RCOUTPUTSWITCH) grid.c $(RESFLAGS) +griddemo.c: griddemo.rc + $(RESCOMP) $(RCINPUTSWITCH) griddemo.rc $(RCOUTPUTSWITCH) griddemo.c $(RESFLAGS) -$(OBJDIR)/grid.$(OBJSUFF): grid.c - $(CC) -c $(CPPFLAGS) -o $@ grid.c +$(OBJDIR)/griddemo.$(OBJSUFF): griddemo.c + $(CC) -c $(CPPFLAGS) -o $@ griddemo.c -#$(OBJDIR)/grid.o: grid.rc -# $(RESCOMP) $(RCINPUTSWITCH) grid.rc $(RCOUTPUTSWITCH) $(OBJDIR)/grid.o $(RESFLAGS) +#$(OBJDIR)/griddemo.o: griddemo.rc +# $(RESCOMP) $(RCINPUTSWITCH) griddemo.rc $(RCOUTPUTSWITCH) $(OBJDIR)/griddemo.o $(RESFLAGS) clean: - rm -f $(OBJECTS) grid$(GUISUFFIX).exe core *.rsc *.res + rm -f $(OBJECTS) griddemo$(GUISUFFIX).exe core *.rsc *.res diff --git a/samples/grid/makefile.vc b/samples/grid/makefile.vc index 3c88d2b859..57a2f981c5 100644 --- a/samples/grid/makefile.vc +++ b/samples/grid/makefile.vc @@ -1,10 +1,16 @@ -# Purpose: makefile for grid example (VC++ 32bit) -# Created: 2000-03-15 +# +# File: makefile.vc +# Author: Michael Bedward +# Created: 1999 +# Updated: +# +# Makefile : Builds sample (VC++, WIN32) +# Use FINAL=1 argument to nmake to build final version with no debug info. # Set WXDIR for your system WXDIR = $(WXWIN) -PROGRAM=grid +PROGRAM=griddemo OBJECTS = $(PROGRAM).obj !include $(WXDIR)\src\makeprog.vc diff --git a/samples/grid/makefile.wat b/samples/grid/makefile.wat index 9d71a42089..b13250e211 100644 --- a/samples/grid/makefile.wat +++ b/samples/grid/makefile.wat @@ -1,9 +1,11 @@ -# Purpose: makefile for grid example (Watcom) -# Created: 2000-03-15 +# +# Makefile for WATCOM +# +# WXDIR = $(%WXWIN) -PROGRAM = grid +PROGRAM = griddemo OBJECTS = $(PROGRAM).obj !include $(WXDIR)\src\makeprog.wat diff --git a/samples/makefile.b32 b/samples/makefile.b32 index de856f954e..1127459741 100644 --- a/samples/makefile.b32 +++ b/samples/makefile.b32 @@ -69,8 +69,6 @@ all: make -f makefile.b32 FINAL=$(FINAL) WXUSINGDLL=$(WXUSINGDLL) cd $(WXDIR)\samples\grid make -f makefile.b32 FINAL=$(FINAL) WXUSINGDLL=$(WXUSINGDLL) - cd $(WXDIR)\samples\newgrid - make -f makefile.b32 FINAL=$(FINAL) WXUSINGDLL=$(WXUSINGDLL) cd $(WXDIR)\samples\help make -f makefile.b32 FINAL=$(FINAL) WXUSINGDLL=$(WXUSINGDLL) @@ -213,8 +211,6 @@ clean: make -f makefile.b32 clean cd $(WXDIR)\samples\grid make -f makefile.b32 clean - cd $(WXDIR)\samples\newgrid - make -f makefile.b32 clean cd $(WXDIR)\samples\help make -f makefile.b32 clean cd $(WXDIR)\samples\html diff --git a/samples/makefile.vc b/samples/makefile.vc index 78d17950dc..102ce4ee51 100644 --- a/samples/makefile.vc +++ b/samples/makefile.vc @@ -68,8 +68,6 @@ all: nmake -f makefile.vc $(MAKEFLAGS) cd $(WXDIR)\samples\grid nmake -f makefile.vc $(MAKEFLAGS) - cd $(WXDIR)\samples\newgrid - nmake -f makefile.vc $(MAKEFLAGS) cd $(WXDIR)\samples\help nmake -f makefile.vc $(MAKEFLAGS) !if "$(PNGSETUP)"=="" @@ -188,8 +186,6 @@ clean: nmake -f makefile.vc clean cd $(WXDIR)\samples\grid nmake -f makefile.vc clean - cd $(WXDIR)\samples\newgrid - nmake -f makefile.vc clean cd $(WXDIR)\samples\help nmake -f makefile.vc clean cd $(WXDIR)\samples\html diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 5bdb101ff6..7a3e26851c 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -32,10 +32,6 @@ #if wxUSE_GRID -#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) - #include "gridg.cpp" -#else // wxUSE_NEW_GRID - #ifndef WX_PRECOMP #include "wx/utils.h" #include "wx/dcclient.h" @@ -10031,7 +10027,5 @@ wxGridEditorCreatedEvent::wxGridEditorCreatedEvent(int id, wxEventType type, m_ctrl = ctrl; } - -#endif // !wxUSE_NEW_GRID/wxUSE_NEW_GRID - #endif // wxUSE_GRID + diff --git a/src/generic/gridctrl.cpp b/src/generic/gridctrl.cpp index 0fd5a3fead..473f509125 100644 --- a/src/generic/gridctrl.cpp +++ b/src/generic/gridctrl.cpp @@ -19,7 +19,7 @@ #pragma hdrstop #endif -#if wxUSE_GRID || wxUSE_NEW_GRID +#if wxUSE_GRID #ifndef WX_PRECOMP #include "wx/textctrl.h" diff --git a/src/generic/gridg.cpp b/src/generic/gridg.cpp deleted file mode 100644 index ea105c3457..0000000000 --- a/src/generic/gridg.cpp +++ /dev/null @@ -1,2858 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: gridg.cpp -// Purpose: wxGenericGrid -// Author: Julian Smart -// Modified by: Michael Bedward -// Added edit in place facility, 20 Apr 1999 -// Added cursor key control, 29 Jun 1999 -// Gerhard Gruber -// Added keyboard navigation, client data, other fixes -// Created: 04/01/98 -// RCS-ID: $Id$ -// Copyright: (c) Julian Smart -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ - #pragma implementation "gridg.h" - #pragma interface -#endif - -// For compilers that support precompilation, includes "wx/wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - -#if wxUSE_GRID && !(wxUSE_NEW_GRID) - -#ifndef WX_PRECOMP - #include "wx/utils.h" - #include "wx/dcclient.h" - #include "wx/dcmemory.h" - #include "wx/textctrl.h" - #include "wx/settings.h" -#endif - -#include - -#include "wx/string.h" - -#include "wx/generic/gridg.h" - - -// Values used to adjust the size of the in-place-edit control, and other -// goodies. Per-platform tweaks should be done here. -#ifdef __WXMSW__ -#define wxIPE_ADJUST -2 -#define wxIPE_STYLE wxNO_BORDER -#define wxIPE_HIGHLIGHT 1 -#define wxUSE_DOUBLE_BUFFERING 1 -#endif - -#ifdef __WXPM__ -#define wxIPE_ADJUST -1 -#define wxIPE_STYLE wxNO_BORDER -#define wxIPE_HIGHLIGHT 1 -#define wxUSE_DOUBLE_BUFFERING 1 -#endif - -#ifdef __WXGTK__ -#define wxIPE_ADJUST -1 -#define wxIPE_STYLE wxNO_BORDER -#define wxIPE_HIGHLIGHT 0 -#define wxUSE_DOUBLE_BUFFERING 1 -#endif - -#ifdef __WXMOTIF__ -#define wxIPE_ADJUST 2 -#define wxIPE_STYLE wxNO_BORDER -#define wxIPE_HIGHLIGHT 0 -#define wxUSE_DOUBLE_BUFFERING 0 -#endif - -#ifndef wxIPE_ADJUST -#define wxIPE_ADJUST 2 -#define wxIPE_STYLE wxNO_BORDER -#define wxIPE_HIGHLIGHT 0 -#define wxUSE_DOUBLE_BUFFERING 0 -#endif - - - -#define wxGRID_DRAG_NONE 0 -#define wxGRID_DRAG_LEFT_RIGHT 1 -#define wxGRID_DRAG_UP_DOWN 2 - -IMPLEMENT_DYNAMIC_CLASS(wxGenericGrid, wxPanel) -IMPLEMENT_DYNAMIC_CLASS(wxGridEvent, wxEvent) - -BEGIN_EVENT_TABLE(wxGenericGrid, wxPanel) - EVT_SIZE(wxGenericGrid::OnSize) - EVT_PAINT(wxGenericGrid::OnPaint) - EVT_ERASE_BACKGROUND(wxGenericGrid::OnEraseBackground) - EVT_MOUSE_EVENTS(wxGenericGrid::OnMouseEvent) - EVT_TEXT(wxGRID_TEXT_CTRL, wxGenericGrid::OnText) - EVT_TEXT(wxGRID_EDIT_IN_PLACE_TEXT_CTRL, wxGenericGrid::OnTextInPlace) - EVT_TEXT_ENTER(wxGRID_TEXT_CTRL, wxGenericGrid::OnTextEnter) - EVT_TEXT_ENTER(wxGRID_EDIT_IN_PLACE_TEXT_CTRL, wxGenericGrid::OnTextInPlaceEnter) - EVT_COMMAND_SCROLL(wxGRID_HSCROLL, wxGenericGrid::OnGridScroll) - EVT_COMMAND_SCROLL(wxGRID_VSCROLL, wxGenericGrid::OnGridScroll) - - // default wxGridEvent handlers - EVT_GRID_SELECT_CELL(wxGenericGrid::_OnSelectCell) - EVT_GRID_CREATE_CELL(wxGenericGrid::_OnCreateCell) - EVT_GRID_CHANGE_LABELS(wxGenericGrid::_OnChangeLabels) - EVT_GRID_CHANGE_SEL_LABEL(wxGenericGrid::_OnChangeSelectionLabel) - EVT_GRID_CELL_CHANGE(wxGenericGrid::_OnCellChange) - EVT_GRID_CELL_LCLICK(wxGenericGrid::_OnCellLeftClick) - EVT_GRID_CELL_RCLICK(wxGenericGrid::_OnCellRightClick) - EVT_GRID_LABEL_LCLICK(wxGenericGrid::_OnLabelLeftClick) - EVT_GRID_LABEL_RCLICK(wxGenericGrid::_OnLabelRightClick) - -END_EVENT_TABLE() - - -wxGenericGrid::wxGenericGrid() -{ - m_viewWidth = 0; - m_viewHeight = 0; - m_batchCount = 0; - m_hScrollBar = (wxScrollBar *) NULL; - m_vScrollBar = (wxScrollBar *) NULL; - m_cellTextColour = *wxBLACK; - m_cellBackgroundColour = *wxWHITE; - m_labelTextColour = *wxBLACK; -// m_labelBackgroundColour = *wxLIGHT_GREY; - m_labelBackgroundColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ); - m_labelBackgroundBrush = wxNullBrush; - m_labelTextFont = wxNullFont; - m_cellTextFont = wxNullFont; - m_textItem = (wxTextCtrl *) NULL; - m_currentRectVisible = FALSE; - m_editable = TRUE; - - m_editInPlace = FALSE; - m_inOnTextInPlace = FALSE; - m_inScroll = FALSE; - -#if defined(__WIN95__) - m_scrollWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); -#elif defined(__WXGTK__) - m_scrollWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); -#else - m_scrollWidth = 16; -#endif - m_dragStatus = wxGRID_DRAG_NONE; - m_dragRowOrCol = 0; - m_dragStartPosition = 0; - m_dragLastPosition = 0; - m_divisionPen = wxNullPen; - m_highlightPen = wxNullPen; - m_leftOfSheet = wxGRID_DEFAULT_SHEET_LEFT; - m_topOfSheet = wxGRID_DEFAULT_SHEET_TOP; - m_cellHeight = wxGRID_DEFAULT_CELL_HEIGHT; - m_totalGridWidth = 0; - m_totalGridHeight = 0; - m_colWidths = (short *) NULL; - m_rowHeights = (short *) NULL; - m_verticalLabelWidth = wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH; - m_horizontalLabelHeight = wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT; - m_verticalLabelAlignment = wxCENTRE; - m_horizontalLabelAlignment = wxCENTRE; - m_editControlPosition.x = wxGRID_DEFAULT_EDIT_X; - m_editControlPosition.y = wxGRID_DEFAULT_EDIT_Y; - m_editControlPosition.width = wxGRID_DEFAULT_EDIT_WIDTH; - m_editControlPosition.height = wxGRID_DEFAULT_EDIT_HEIGHT; - m_wCursorRow = 0; - m_wCursorColumn = 0; - m_scrollPosX = 0; - m_scrollPosY = 0; - m_editCreated = FALSE; - m_totalRows = 0; - m_totalCols = 0; - m_gridCells = (wxGridCell ***) NULL; - m_rowLabelCells = (wxGridCell **) NULL; - m_colLabelCells = (wxGridCell **) NULL; - m_textItem = (wxTextCtrl *) NULL; -} - -bool wxGenericGrid::Create(wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) -{ - m_viewWidth = 0; - m_viewHeight = 0; - m_batchCount = 0; - m_editingPanel = (wxPanel *) NULL; - m_hScrollBar = (wxScrollBar *) NULL; - m_vScrollBar = (wxScrollBar *) NULL; - m_cellTextColour = *wxBLACK; - m_cellBackgroundColour = *wxWHITE; - m_labelTextColour = *wxBLACK; -// m_labelBackgroundColour = *wxLIGHT_GREY; - m_labelBackgroundColour = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ); - m_labelBackgroundBrush = wxNullBrush; - m_labelTextFont = * wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxBOLD); - m_cellTextFont = * wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL); - m_textItem = (wxTextCtrl *) NULL; - m_currentRectVisible = FALSE; - m_editable = TRUE; - m_editInPlace = FALSE; - m_inOnTextInPlace = FALSE; - m_inScroll = FALSE; -#if defined(__WIN95__) - m_scrollWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); -#elif defined(__WXGTK__) - m_scrollWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); -#else - m_scrollWidth = 16; -#endif - m_dragStatus = wxGRID_DRAG_NONE; - m_dragRowOrCol = 0; - m_dragStartPosition = 0; - m_dragLastPosition = 0; - m_divisionPen = * wxThePenList->FindOrCreatePen(wxT("LIGHT GREY"), 1, wxSOLID); - m_highlightPen = * wxBLACK_PEN; - m_doubleBufferingBitmap = (wxBitmap *) NULL; - - if (!m_horizontalSashCursor.Ok()) - { - m_horizontalSashCursor = wxCursor(wxCURSOR_SIZEWE); - m_verticalSashCursor = wxCursor(wxCURSOR_SIZENS); - } - - SetLabelBackgroundColour(m_labelBackgroundColour); - - m_leftOfSheet = wxGRID_DEFAULT_SHEET_LEFT; - m_topOfSheet = wxGRID_DEFAULT_SHEET_TOP; - m_cellHeight = wxGRID_DEFAULT_CELL_HEIGHT; - m_totalGridWidth = 0; - m_totalGridHeight = 0; - m_colWidths = (short *) NULL; - m_rowHeights = (short *) NULL; - - m_verticalLabelWidth = wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH; - m_horizontalLabelHeight = wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT; - m_verticalLabelAlignment = wxCENTRE; - m_horizontalLabelAlignment = wxCENTRE; - m_editControlPosition.x = wxGRID_DEFAULT_EDIT_X; - m_editControlPosition.y = wxGRID_DEFAULT_EDIT_Y; - m_editControlPosition.width = wxGRID_DEFAULT_EDIT_WIDTH; - m_editControlPosition.height = wxGRID_DEFAULT_EDIT_HEIGHT; - - m_wCursorRow = 0; - m_wCursorColumn = 0; - - m_scrollPosX = 0; - m_scrollPosY = 0; - - /* Store the rect. coordinates for the current cell */ - SetCurrentRect(m_wCursorRow, m_wCursorColumn); - - m_editCreated = FALSE; - - m_totalRows = 0; - m_totalCols = 0; - m_gridCells = (wxGridCell ***) NULL; - m_rowLabelCells = (wxGridCell **) NULL; - m_colLabelCells = (wxGridCell **) NULL; - m_textItem = (wxTextCtrl *) NULL; - - wxPanel::Create(parent, id, pos, size, style, name); - - m_editingPanel = new wxPanel(this); - - m_textItem = new wxTextCtrl(m_editingPanel, wxGRID_TEXT_CTRL, wxT(""), - wxPoint(m_editControlPosition.x, m_editControlPosition.y), - wxSize(m_editControlPosition.width, -1), - wxTE_PROCESS_ENTER); - m_textItem->Show(TRUE); - m_textItem->SetFocus(); - int controlW, controlH; - - m_textItem->GetSize(&controlW, &controlH); - m_editControlPosition.height = controlH; - - m_topOfSheet = m_editControlPosition.y + controlH + 2; - - m_editCreated = TRUE; - - m_hScrollBar = new wxScrollBar(this, wxGRID_HSCROLL, wxPoint(0, 0), wxSize(20, 100), wxHORIZONTAL); - m_vScrollBar = new wxScrollBar(this, wxGRID_VSCROLL, wxPoint(0, 0), wxSize(100, 20), wxVERTICAL); - -// SetSize(pos.x, pos.y, size.x, size.y); - - m_inPlaceTextItem = new wxTextCtrl( (wxPanel*)this, wxGRID_EDIT_IN_PLACE_TEXT_CTRL, wxT(""), - wxPoint( m_currentRect.x-wxIPE_ADJUST, m_currentRect.y-wxIPE_ADJUST ), - wxSize( m_currentRect.width+wxIPE_ADJUST*2, m_currentRect.height+wxIPE_ADJUST*2 ), - wxNO_BORDER | wxTE_PROCESS_ENTER ); - m_inPlaceTextItem->Show(m_editInPlace); - if ( m_editInPlace ) - m_inPlaceTextItem->SetFocus(); - - return TRUE; -} - -wxGenericGrid::~wxGenericGrid() -{ - ClearGrid(); -} - -void wxGenericGrid::ClearGrid() -{ - int i,j; - if (m_gridCells) - { - for (i = 0; i < m_totalRows; i++) - { - for (j = 0; j < m_totalCols; j++) - if (m_gridCells[i][j]) - delete m_gridCells[i][j]; - delete[] m_gridCells[i]; - } - delete[] m_gridCells; - m_gridCells = (wxGridCell ***) NULL; - } - if (m_colWidths) - delete[] m_colWidths; - m_colWidths = (short *) NULL; - if (m_rowHeights) - delete[] m_rowHeights; - m_rowHeights = (short *) NULL; - - if (m_rowLabelCells) - { - for (i = 0; i < m_totalRows; i++) - delete m_rowLabelCells[i]; - delete[] m_rowLabelCells; - m_rowLabelCells = (wxGridCell **) NULL; - } - if (m_colLabelCells) - { - for (i = 0; i < m_totalCols; i++) - delete m_colLabelCells[i]; - delete[] m_colLabelCells; - m_colLabelCells = (wxGridCell **) NULL; - } - if (m_doubleBufferingBitmap) - { - delete m_doubleBufferingBitmap; - m_doubleBufferingBitmap = (wxBitmap *) NULL; - } -} - -bool wxGenericGrid::CreateGrid(int nRows, int nCols, wxString **cellValues, short *widths, - short defaultWidth, short defaultHeight) -{ - m_totalRows = nRows; - m_totalCols = nCols; - - int i,j; - m_colWidths = new short[nCols]; - m_rowHeights = new short[nRows]; - for (i = 0; i < nCols; i++) - if (widths) - m_colWidths[i] = widths[i]; - else - m_colWidths[i] = defaultWidth; - for (i = 0; i < nRows; i++) - m_rowHeights[i] = defaultHeight; - - m_gridCells = new wxGridCell **[nRows]; - - for (i = 0; i < nRows; i++) - m_gridCells[i] = new wxGridCell *[nCols]; - - for (i = 0; i < nRows; i++) - for (j = 0; j < nCols; j++) - if (cellValues) - { - //m_gridCells[i][j] = OnCreateCell(); - wxGridEvent g_evt(GetId(), wxEVT_GRID_CREATE_CELL, this, i, j); - GetEventHandler()->ProcessEvent(g_evt); - m_gridCells[i][j] = g_evt.m_cell; - m_gridCells[i][j]->SetTextValue(cellValues[i][j]); - } - else - m_gridCells[i][j] = (wxGridCell *) NULL; - - m_rowLabelCells = new wxGridCell *[nRows]; - for (i = 0; i < nRows; i++) - m_rowLabelCells[i] = new wxGridCell(this); - m_colLabelCells = new wxGridCell *[nCols]; - for (i = 0; i < nCols; i++) - m_colLabelCells[i] = new wxGridCell(this); - - m_wCursorRow = m_wCursorColumn = 0; - SetCurrentRect(0, 0); - - // Need to determine various dimensions - UpdateDimensions(); - - // Number of 'lines' - int objectSizeX = m_totalCols; - int pageSizeX = 1; - int viewLengthX = m_totalCols; - -/* - m_hScrollBar->SetViewLength(viewLengthX); - m_hScrollBar->SetObjectLength(objectSizeX); - m_hScrollBar->SetPageSize(pageSizeX); -*/ - m_hScrollBar->SetScrollbar(m_hScrollBar->GetThumbPosition(), pageSizeX, objectSizeX, viewLengthX); - - int objectSizeY = m_totalRows; - int pageSizeY = 1; - int viewLengthY = m_totalRows; - -/* - m_vScrollBar->SetViewLength(viewLengthY); - m_vScrollBar->SetObjectLength(objectSizeY); - m_vScrollBar->SetPageSize(pageSizeY); -*/ - - m_vScrollBar->SetScrollbar(m_vScrollBar->GetThumbPosition(), pageSizeY, objectSizeY, viewLengthY); - - AdjustScrollbars(); - - //OnChangeLabels(); - wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS, this); - GetEventHandler()->ProcessEvent(g_evt); - - //OnChangeSelectionLabel(); - wxGridEvent g_evt2(GetId(), wxEVT_GRID_CHANGE_SEL_LABEL, this); - GetEventHandler()->ProcessEvent(g_evt2); - - return TRUE; -} - -// Need to determine various dimensions -void wxGenericGrid::UpdateDimensions() -{ - int canvasWidth, canvasHeight; - GetSize(&canvasWidth, &canvasHeight); - - if (m_editCreated && m_editable) - { - int controlW, controlH; - GetTextItem()->GetSize(&controlW, &controlH); - m_topOfSheet = m_editControlPosition.y + controlH + 2; - } - else - m_topOfSheet = 0; - m_rightOfSheet = m_leftOfSheet + m_verticalLabelWidth; - int i; - for (i = m_scrollPosX; i < m_totalCols; i++) - { - if (m_rightOfSheet > canvasWidth) - break; - else - m_rightOfSheet += m_colWidths[i]; - } - m_bottomOfSheet = m_topOfSheet + m_horizontalLabelHeight; - for (i = m_scrollPosY; i < m_totalRows; i++) - { - if (m_bottomOfSheet > canvasHeight) - break; - else - m_bottomOfSheet += m_rowHeights[i]; - } - - m_totalGridWidth = m_leftOfSheet + m_verticalLabelWidth; - for (i = 0; i < m_totalCols; i++) - { - m_totalGridWidth += m_colWidths[i]; - } - m_totalGridHeight = m_topOfSheet + m_horizontalLabelHeight; - for (i = 0; i < m_totalRows; i++) - { - m_totalGridHeight += m_rowHeights[i]; - } -} - -wxGridCell *wxGenericGrid::GetCell(int row, int col) const -{ - if (!m_gridCells) - return (wxGridCell *) NULL; - - if ((row >= m_totalRows) || (col >= m_totalCols)) - return (wxGridCell *) NULL; - - wxGridCell *cell = m_gridCells[row][col]; - if (!cell) - { - // m_gridCells[row][col] = OnCreateCell(); - wxGridEvent g_evt(GetId(), wxEVT_GRID_CREATE_CELL, (wxGenericGrid*) this, row, col); - GetEventHandler()->ProcessEvent(g_evt); - m_gridCells[row][col] = g_evt.m_cell; - return m_gridCells[row][col]; - } - else - return cell; -} - -void wxGenericGrid::SetGridClippingRegion(wxDC *dc) -{ - int m_scrollWidthHoriz = 0; - int m_scrollWidthVert = 0; - int cw, ch; - GetClientSize(&cw, &ch); - - if (m_hScrollBar && m_hScrollBar->IsShown()) - m_scrollWidthHoriz = m_scrollWidth; - if (m_vScrollBar && m_vScrollBar->IsShown()) - m_scrollWidthVert = m_scrollWidth; - - // Don't paint over the scrollbars - dc->SetClippingRegion(m_leftOfSheet, m_topOfSheet, - cw - m_scrollWidthVert - m_leftOfSheet, ch - m_scrollWidthHoriz - m_topOfSheet); -} - -void wxGenericGrid::OnPaint(wxPaintEvent& WXUNUSED(event)) -{ - int w, h; - GetClientSize(&w, &h); - - bool useDoubleBuffering = (bool) wxUSE_DOUBLE_BUFFERING; - if (useDoubleBuffering) - { - // Reuse the old bitmap if possible - - if (!m_doubleBufferingBitmap || - (m_doubleBufferingBitmap->GetWidth() < w || m_doubleBufferingBitmap->GetHeight() < h)) - { - if (m_doubleBufferingBitmap) - delete m_doubleBufferingBitmap; - m_doubleBufferingBitmap = new wxBitmap(w, h); - } - if (!m_doubleBufferingBitmap || !m_doubleBufferingBitmap->Ok()) - { - // If we couldn't create a new bitmap, perhaps because resources were low, - // then don't complain, just don't double-buffer - if (m_doubleBufferingBitmap) - delete m_doubleBufferingBitmap; - m_doubleBufferingBitmap = (wxBitmap *) NULL; - useDoubleBuffering = FALSE; - } - } - - if (useDoubleBuffering) - { - wxPaintDC paintDC(this); - wxMemoryDC dc(& paintDC); - dc.SelectObject(* m_doubleBufferingBitmap); - - PaintGrid(dc); - - int vertScrollBarWidth = m_scrollWidth; - int horizScrollBarHeight = m_scrollWidth; - if (m_vScrollBar && !m_vScrollBar->IsShown()) - vertScrollBarWidth = 0; - if (m_hScrollBar && !m_hScrollBar->IsShown()) - horizScrollBarHeight = 0; - - paintDC.Blit(m_leftOfSheet, m_topOfSheet, w - vertScrollBarWidth - m_leftOfSheet, h - horizScrollBarHeight - m_topOfSheet, - &dc, m_leftOfSheet, m_topOfSheet, wxCOPY); - - dc.SelectObject(wxNullBitmap); - } - else - { - wxPaintDC dc(this); - PaintGrid(dc); - } -} - -void wxGenericGrid::PaintGrid(wxDC& dc) -{ - dc.BeginDrawing(); - dc.SetOptimization(FALSE); - - SetGridClippingRegion(& dc); - - DrawLabelAreas(& dc); - - DrawEditableArea(& dc); - DrawColumnLabels(& dc); - DrawRowLabels(& dc); - DrawCells(& dc); - DrawGridLines(& dc); - - /* Hilight present cell */ - SetCurrentRect(m_wCursorRow, m_wCursorColumn); - if (m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace))) - HighlightCell(& dc, TRUE); - - dc.DestroyClippingRegion(); - dc.SetOptimization(TRUE); - dc.EndDrawing(); -} - -// Erase (some of) the background. -// Currently, a Windows-only optimisation. -void wxGenericGrid::OnEraseBackground(wxEraseEvent& WXUNUSED(event) ) -{ - wxClientDC dc(this); - dc.BeginDrawing(); - dc.SetOptimization(FALSE); - - int w, h; - GetClientSize(& w, & h); - dc.SetBrush(*wxLIGHT_GREY_BRUSH); - dc.SetPen(*wxLIGHT_GREY_PEN); - - if (m_hScrollBar && m_hScrollBar->IsShown() && m_vScrollBar && m_vScrollBar->IsShown()) - { - dc.DrawRectangle(w - m_scrollWidth, h - m_scrollWidth, m_scrollWidth, m_scrollWidth); - } - - dc.SetOptimization(TRUE); - dc.EndDrawing(); -} - - -void wxGenericGrid::DrawLabelAreas(wxDC *dc) -{ - int cw, ch; - GetClientSize(&cw, &ch); - - dc->SetPen(*wxTRANSPARENT_PEN); -// dc->SetBrush(*dc->GetBackground()); - - // Should blank out any area which isn't going to be painted over. -// dc->DrawRectangle(m_leftOfSheet, m_bottomOfSheet, cw - m_leftOfSheet, ch - m_bottomOfSheet); -// dc->DrawRectangle(m_rightOfSheet, m_topOfSheet, cw - m_rightOfSheet, ch - m_topOfSheet); - - // Paint the label areas - dc->SetBrush(m_labelBackgroundBrush); -// dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_rightOfSheet - m_leftOfSheet + 1, m_horizontalLabelHeight + 1); - dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, cw-m_leftOfSheet, m_horizontalLabelHeight + 1); -// dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_verticalLabelWidth + 1, m_bottomOfSheet - m_topOfSheet + 1); - dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_verticalLabelWidth + 1, ch-m_topOfSheet); -} - -void wxGenericGrid::DrawEditableArea(wxDC *dc) -{ - int cw, ch; - GetClientSize(&cw, &ch); - - dc->SetPen(*wxTRANSPARENT_PEN); - dc->SetBrush(*wxTheBrushList->FindOrCreateBrush(m_cellBackgroundColour, wxSOLID)); -// dc->DrawRectangle(m_leftOfSheet+m_verticalLabelWidth, m_topOfSheet+m_horizontalLabelHeight, -// m_rightOfSheet-(m_leftOfSheet+m_verticalLabelWidth) + 1, m_bottomOfSheet - (m_topOfSheet+m_horizontalLabelHeight) + 1); - dc->DrawRectangle(m_leftOfSheet+m_verticalLabelWidth, m_topOfSheet+m_horizontalLabelHeight, - cw-(m_leftOfSheet+m_verticalLabelWidth), ch - (m_topOfSheet+m_horizontalLabelHeight)); -} - -void wxGenericGrid::DrawGridLines(wxDC *dc) -{ - int cw, ch; - GetClientSize(&cw, &ch); - - int i; - - if (m_divisionPen.Ok()) - { - dc->SetPen(m_divisionPen); - - int heightCount = m_topOfSheet + m_horizontalLabelHeight; - - // Draw horizontal grey lines for cells - for (i = m_scrollPosY; i < (m_totalRows+1); i++) - { - if (heightCount > ch) - break; - else - { - dc->DrawLine(m_leftOfSheet, heightCount, - cw, heightCount); - if (i < m_totalRows) - heightCount += m_rowHeights[i]; - } - } - } - - if (m_verticalLabelWidth > 0) - { - dc->SetPen(*wxBLACK_PEN); - - // Draw horizontal black lines for row labels - int heightCount = m_topOfSheet + m_horizontalLabelHeight; - for (i = m_scrollPosY; i < (m_totalRows+1); i++) - { - if (heightCount > ch) - break; - else - { - dc->DrawLine(m_leftOfSheet, heightCount, - m_verticalLabelWidth, heightCount); - if (i < m_totalRows) - heightCount += m_rowHeights[i]; - } - } - // Draw a black vertical line for row number cells - dc->DrawLine(m_leftOfSheet + m_verticalLabelWidth, m_topOfSheet, - m_leftOfSheet + m_verticalLabelWidth, ch); - // First vertical line - dc->DrawLine(m_leftOfSheet, m_topOfSheet, m_leftOfSheet, ch); - - dc->SetPen(*wxWHITE_PEN); - - // Draw highlights on row labels - heightCount = m_topOfSheet + m_horizontalLabelHeight; - for (i = m_scrollPosY; i < m_totalRows; i++) - { - if (heightCount > ch) - break; - else - { - dc->DrawLine(m_leftOfSheet+1, heightCount+1, - m_verticalLabelWidth, heightCount+1); - dc->DrawLine(m_leftOfSheet+1, heightCount+1, - m_leftOfSheet+1, heightCount + m_rowHeights[i] - 1); - heightCount += m_rowHeights[i]; - } - } - // Last one - down to the floor. - dc->DrawLine(m_leftOfSheet+1, heightCount+1, - m_verticalLabelWidth, heightCount+1); - dc->DrawLine(m_leftOfSheet+1, heightCount+1, - m_leftOfSheet+1, ch); - - } - - if (m_divisionPen.Ok()) - { - dc->SetPen(m_divisionPen); - - // Draw vertical grey lines for cells - int widthCount = m_leftOfSheet + m_verticalLabelWidth; - for (i = m_scrollPosX; i < m_totalCols; i++) - { - if (widthCount > cw) - break; - else - { - // Skip the first one - if (i != m_scrollPosX) - { - dc->DrawLine(widthCount, m_topOfSheet + m_horizontalLabelHeight, - widthCount, m_bottomOfSheet); - } - widthCount += m_colWidths[i]; - } - } - // Last one - dc->DrawLine(widthCount, m_topOfSheet + m_horizontalLabelHeight, - widthCount, m_bottomOfSheet); - } - - dc->SetPen(*wxBLACK_PEN); - - // Draw two black horizontal lines for column number cells - dc->DrawLine( - m_leftOfSheet, m_topOfSheet, - cw, m_topOfSheet); - dc->DrawLine(m_leftOfSheet, m_topOfSheet + m_horizontalLabelHeight, - cw, m_topOfSheet + m_horizontalLabelHeight); - - if (m_horizontalLabelHeight > 0) - { - int widthCount = m_leftOfSheet + m_verticalLabelWidth; - - // Draw black vertical lines for column number cells - for (i = m_scrollPosX; i < m_totalCols; i++) - { - if (widthCount > cw) - break; - else - { - dc->DrawLine(widthCount, m_topOfSheet, - widthCount, m_topOfSheet + m_horizontalLabelHeight); - widthCount += m_colWidths[i]; - } - } - - // Last one - dc->DrawLine(widthCount, m_topOfSheet, - widthCount, m_topOfSheet + m_horizontalLabelHeight); - - // Draw highlights - dc->SetPen(*wxWHITE_PEN); - widthCount = m_leftOfSheet + m_verticalLabelWidth; - - for (i = m_scrollPosX; i < m_totalCols; i++) - { - if (widthCount > cw) - break; - else - { - dc->DrawLine(widthCount+1, m_topOfSheet+1, - widthCount+m_colWidths[i], m_topOfSheet+1); - dc->DrawLine(widthCount+1, m_topOfSheet+1, - widthCount+1, m_topOfSheet+m_horizontalLabelHeight); - widthCount += m_colWidths[i]; - } - } - // Last one - to the right side of the canvas. - dc->DrawLine(widthCount+1, m_topOfSheet+1, - cw, m_topOfSheet+1); - dc->DrawLine(widthCount+1, m_topOfSheet+1, - widthCount+1, m_topOfSheet+m_horizontalLabelHeight); - - } -} - -void wxGenericGrid::DrawColumnLabels(wxDC *dc) -{ - int cw, ch; - GetClientSize(&cw, &ch); - - if (m_horizontalLabelHeight == 0) - return; - - int i; - wxRect rect; - - // Draw letters for columns - rect.y = m_topOfSheet + 1; - rect.height = m_horizontalLabelHeight - 1; - - dc->SetTextBackground(m_labelBackgroundColour); - dc->SetBackgroundMode(wxTRANSPARENT); -// dc->SetTextForeground(m_labelTextColour); - - int widthCount = m_leftOfSheet + m_verticalLabelWidth; - for (i = m_scrollPosX; i < m_totalCols; i++) - { - if (widthCount > cw) - break; - else - { - rect.x = 1 + widthCount; - rect.width = m_colWidths[i]; - DrawColumnLabel(dc, &rect, i); - - widthCount += m_colWidths[i]; - } - } -} - -void wxGenericGrid::DrawColumnLabel(wxDC *dc, wxRect *rect, int col) -{ - wxGridCell *cell = GetLabelCell(wxHORIZONTAL, col); - if (cell) - { - wxRect rect2; - rect2 = *rect; - rect2.x += 3; - rect2.y += 2; - rect2.width -= 5; - rect2.height -= 4; - dc->SetTextForeground(GetLabelTextColour()); - dc->SetFont(GetLabelTextFont()); - if ( !cell->GetTextValue().IsNull() ) - DrawTextRect(dc, cell->GetTextValue(), &rect2, GetLabelAlignment(wxHORIZONTAL)); - } -} - -void wxGenericGrid::DrawRowLabels(wxDC *dc) -{ - int cw, ch; - GetClientSize(&cw, &ch); - - if (m_verticalLabelWidth == 0) - return; - - int i; - wxRect rect; - - // Draw numbers for rows - rect.x = m_leftOfSheet; - rect.width = m_verticalLabelWidth; - - int heightCount = m_topOfSheet + m_horizontalLabelHeight; - - dc->SetTextBackground(m_labelBackgroundColour); - dc->SetBackgroundMode(wxTRANSPARENT); - - for (i = m_scrollPosY; i < m_totalRows; i++) - { - if (heightCount > ch) - break; - else - { - rect.y = 1 + heightCount; - rect.height = m_rowHeights[i]; - DrawRowLabel(dc, &rect, i); - - heightCount += m_rowHeights[i]; - } - } -} - -void wxGenericGrid::DrawRowLabel(wxDC *dc, wxRect *rect, int row) -{ - wxGridCell *cell = GetLabelCell(wxVERTICAL, row); - if (cell) - { - wxRect rect2; - rect2 = *rect; - rect2.x += 3; - rect2.y += 2; - rect2.width -= 5; - rect2.height -= 4; - dc->SetTextForeground(GetLabelTextColour()); - dc->SetFont(GetLabelTextFont()); - if ( !cell->GetTextValue().IsNull() ) - DrawTextRect(dc, cell->GetTextValue(), &rect2, GetLabelAlignment(wxVERTICAL)); - } -} - -void wxGenericGrid::DrawCells(wxDC *dc) -{ - int cw, ch; - GetClientSize(&cw, &ch); - - int i,j; - - // Draw value corresponding to each cell - for (i = m_scrollPosY; i < m_totalRows; i++) - { - for (j = m_scrollPosX; j < m_totalCols; j++) - { - SetCurrentRect(i, j, cw, ch); - if (m_currentRectVisible) - { - DrawCellBackground(dc, &m_currentRect, i, j); - DrawCellValue(dc, &m_currentRect, i, j); - } - if (m_currentRect.x > cw) - break; - } - if (m_currentRect.y > ch) - break; - } - dc->SetBackgroundMode(wxSOLID); - dc->SetPen(*wxBLACK_PEN); -} - -void wxGenericGrid::DrawCellBackground(wxDC *dc, wxRect *rect, int row, int col) -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - { - dc->SetBrush(cell->GetBackgroundBrush()); - dc->SetPen(*wxTRANSPARENT_PEN); - -#if 0 // In wxWin 2.0 the dc code is exact. RR. -#ifdef __WXMOTIF__ - dc->DrawRectangle(rect->x+1, rect->y+1, rect->width-1, rect->height-1); -#else - dc->DrawRectangle(rect->x+1, rect->y+1, rect->width, rect->height); -#endif -#endif - - dc->DrawRectangle(rect->x+1, rect->y+1, rect->width-1, rect->height-1); - - dc->SetPen(*wxBLACK_PEN); - } -} - -void wxGenericGrid::DrawCellValue(wxDC *dc, wxRect *rect, int row, int col) -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - { - wxBitmap *bitmap = cell->GetCellBitmap(); - wxRect rect2; - rect2 = *rect; - rect2.x += 3; - rect2.y += 2; - rect2.width -= 5; - rect2.height -= 4; - - if (bitmap) - { - DrawBitmapRect(dc, bitmap, &rect2, cell->GetAlignment()); - } - else - { - dc->SetBackgroundMode(wxTRANSPARENT); - dc->SetTextForeground(cell->GetTextColour()); - dc->SetFont(cell->GetFont()); - - if ( !cell->GetTextValue().IsNull() ) - DrawTextRect(dc, cell->GetTextValue(), &rect2, cell->GetAlignment()); - } - } -} - -void wxGenericGrid::AdjustScrollbars() -{ - int cw, ch; - GetClientSize(&cw, &ch); - - // We find the view size by seeing how many rows/cols fit on - // the current view. - // BUT... this means that the scrollbar should be adjusted every time - // it's scrolled, as well as when sized, because with variable size rows/cols, - // the number of rows/col visible on the view differs according to what bit - // you're looking at. The object length is always the same, but the - // view length differs. - - // Since this may not be known until the end of this function, we should probably call AdjustScrollbars - // twice. - int vertScrollBarWidth = m_scrollWidth; - int horizScrollBarHeight = m_scrollWidth; - if (m_vScrollBar && !m_vScrollBar->IsShown()) - vertScrollBarWidth = 0; - if (m_hScrollBar && !m_hScrollBar->IsShown()) - horizScrollBarHeight = 0; - - int noHorizSteps = 0; - int noVertSteps = 0; - - if (m_totalGridWidth + vertScrollBarWidth > cw) - { - int widthCount = 0; - - int i; - int nx = 0; - for (i = m_scrollPosX ; i < m_totalCols; i++) - { - widthCount += m_colWidths[i]; - // A partial bit doesn't count, we still have to scroll to see the - // rest of it - if (widthCount + m_leftOfSheet + m_verticalLabelWidth > (cw-vertScrollBarWidth)) - break; - else - nx ++; - } - - noHorizSteps += nx; - } - m_viewWidth = noHorizSteps; - - if (m_totalGridHeight + horizScrollBarHeight > ch) - { - int heightCount = 0; - - int i; - int ny = 0; - for (i = m_scrollPosY ; i < m_totalRows; i++) - { - heightCount += m_rowHeights[i]; - // A partial bit doesn't count, we still have to scroll to see the - // rest of it - if (heightCount + m_topOfSheet + m_horizontalLabelHeight > (ch-horizScrollBarHeight)) - break; - else - ny ++; - } - - noVertSteps += ny; - } - - m_viewHeight = noVertSteps; - - if (m_totalGridWidth + vertScrollBarWidth <= cw) - { - if ( m_hScrollBar ) - m_hScrollBar->Show(FALSE); - SetScrollPosX(0); - } - else - { - if ( m_hScrollBar ) - m_hScrollBar->Show(TRUE); - } - - if (m_totalGridHeight + horizScrollBarHeight <= ch) - { - if ( m_vScrollBar ) - m_vScrollBar->Show(FALSE); - SetScrollPosY(0); - } - else - { - if ( m_vScrollBar ) - m_vScrollBar->Show(TRUE); - } - - UpdateDimensions(); // Necessary in case m_scrollPosX/Y changed - - vertScrollBarWidth = m_scrollWidth; - horizScrollBarHeight = m_scrollWidth; - if (m_vScrollBar && !m_vScrollBar->IsShown()) - vertScrollBarWidth = 0; - if (m_hScrollBar && !m_hScrollBar->IsShown()) - horizScrollBarHeight = 0; - - if (m_hScrollBar && m_hScrollBar->IsShown()) - { - int nCols = GetCols(); - m_hScrollBar->SetScrollbar(m_hScrollBar->GetThumbPosition(), wxMax(noHorizSteps, 1), (noHorizSteps == 0) ? 1 : nCols, wxMax(noHorizSteps, 1)); - -/* - m_hScrollBar->SetSize(m_leftOfSheet, ch - m_scrollWidth -2, // why -2 ? Robert. - cw - vertScrollBarWidth - m_leftOfSheet, m_scrollWidth); -*/ - m_hScrollBar->SetSize(m_leftOfSheet, ch - m_scrollWidth, - cw - vertScrollBarWidth - m_leftOfSheet, m_scrollWidth); - - } - - if (m_vScrollBar && m_vScrollBar->IsShown()) - { - int nRows = GetRows(); - - m_vScrollBar->SetScrollbar(m_vScrollBar->GetThumbPosition(), wxMax(noVertSteps, 1), (noVertSteps == 0) ? 1 : nRows, wxMax(noVertSteps, 1)); - m_vScrollBar->SetSize(cw - m_scrollWidth, m_topOfSheet, - m_scrollWidth, ch - m_topOfSheet - horizScrollBarHeight); - } -} - -void wxGenericGrid::OnSize(wxSizeEvent& WXUNUSED(event) ) -{ - if (!m_vScrollBar || !m_hScrollBar) - return; - - AdjustScrollbars(); - - int cw, ch; - GetClientSize(&cw, &ch); - - if (m_editCreated && m_editingPanel && GetTextItem() && GetTextItem()->IsShown()) - { - m_editingPanel->SetSize(0, 0, cw, m_editControlPosition.height + m_editControlPosition.y + 2); - GetTextItem()->SetSize(m_editControlPosition.x, m_editControlPosition.y, - cw - 2*m_editControlPosition.x, m_editControlPosition.height); - } -} - -bool wxGenericGrid::CellHitTest(int x, int y, int *row, int *col) -{ - // Find the selected cell and call OnSelectCell - if (x >= (m_leftOfSheet + m_verticalLabelWidth) && y >= (m_topOfSheet + m_horizontalLabelHeight) && - x <= m_rightOfSheet && y <= m_bottomOfSheet) - { - // Calculate the cell number from x and y - x -= (m_verticalLabelWidth + m_leftOfSheet); - y -= (m_topOfSheet + m_horizontalLabelHeight); - - int i; - - // Now we need to do a hit test for which row we're on - int currentHeight = 0; - for (i = m_scrollPosY; i < m_totalRows; i++) - { - if (y >= currentHeight && y <= (currentHeight + m_rowHeights[i])) - { - *row = i; - break; - } - currentHeight += m_rowHeights[i]; - } - - // Now we need to do a hit test for which column we're on - int currentWidth = 0; - for (i = m_scrollPosX; i < m_totalCols; i++) - { - if (x >= currentWidth && x <= (currentWidth + m_colWidths[i])) - { - *col = i; - break; - } - currentWidth += m_colWidths[i]; - } - return TRUE; - } - return FALSE; -} - -bool wxGenericGrid::LabelSashHitTest(int x, int y, int *orientation, int *rowOrCol, int *startPos) -{ - int i; - int tolerance = 3; - - if (x >= (m_leftOfSheet + m_verticalLabelWidth) && y >= m_topOfSheet && - x <= m_rightOfSheet && y <= (m_topOfSheet + m_horizontalLabelHeight)) - { - // We may be on a column label sash. - int currentWidth = m_leftOfSheet + m_verticalLabelWidth; - for (i = m_scrollPosX; i < m_totalCols; i++) - { - if (x >= (currentWidth + m_colWidths[i] - tolerance) && x <= (currentWidth + m_colWidths[i] + tolerance)) - { - *orientation = wxHORIZONTAL; - *rowOrCol = i; - *startPos = currentWidth; - return TRUE; - } - currentWidth += m_colWidths[i]; - } - return FALSE; - } - else if (x >= m_leftOfSheet && y >= (m_topOfSheet + m_horizontalLabelHeight) && - x <= (m_leftOfSheet + m_verticalLabelWidth) && y <= m_bottomOfSheet) - { - // We may be on a row label sash. - int currentHeight = m_topOfSheet + m_horizontalLabelHeight; - for (i = m_scrollPosY; i < m_totalRows; i++) - { - if (y >= (currentHeight + m_rowHeights[i] - tolerance) && y <= (currentHeight + m_rowHeights[i] + tolerance)) - { - *orientation = wxVERTICAL; - *rowOrCol = i; - *startPos = currentHeight; - return TRUE; - } - currentHeight += m_rowHeights[i]; - } - return FALSE; - } - return FALSE; -} - -bool wxGenericGrid::LabelHitTest(int x, int y, int *row, int *col) -{ - // Find the selected label - if (x >= m_leftOfSheet && y >= m_topOfSheet && - x <= m_rightOfSheet && y <= m_bottomOfSheet) - { - // Calculate the cell number from x and y - x -= m_leftOfSheet; - y -= m_topOfSheet; - - int i; - - // Now we need to do a hit test for which row we're on - int currentHeight = m_horizontalLabelHeight; - for (i = m_scrollPosY; i < m_totalRows; i++) - { - if (y >= currentHeight && y <= (currentHeight + m_rowHeights[i])) - { - *row = i; - break; - } - currentHeight += m_rowHeights[i]; - } - if (y >= 0 && y <= m_horizontalLabelHeight) - { - *row = -1; - } - - // Now we need to do a hit test for which column we're on - int currentWidth = m_verticalLabelWidth; - for (i = m_scrollPosX; i < m_totalCols; i++) - { - if (x >= currentWidth && x <= (currentWidth + m_colWidths[i])) - { - *col = i; - break; - } - currentWidth += m_colWidths[i]; - } - if (x >= 0 && x <= m_verticalLabelWidth) - { - *col = -1; - } - - if ((*col == -1) || (*row == -1)) - { - return TRUE; - } - } - return FALSE; -} - -void wxGenericGrid::OnMouseEvent(wxMouseEvent& ev) -{ - if (ev.LeftDown()) - { - wxClientDC dc(this); - dc.BeginDrawing(); - - int row, col; - if (CellHitTest((int)ev.GetX(), (int)ev.GetY(), &row, &col)) - { - OnSelectCellImplementation(& dc, row, col); - - //OnCellLeftClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown()); - wxGridEvent g_evt(GetId(), wxEVT_GRID_CELL_LCLICK, this, - row, col, (int)ev.GetX(), (int)ev.GetY(), - ev.ControlDown(), ev.ShiftDown()); - GetEventHandler()->ProcessEvent(g_evt); - - } - if (LabelHitTest((int)ev.GetX(), (int)ev.GetY(), &row, &col)) - { - //OnLabelLeftClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown()); - wxGridEvent g_evt(GetId(), wxEVT_GRID_LABEL_LCLICK, this, - row, col, (int)ev.GetX(), (int)ev.GetY(), - ev.ControlDown(), ev.ShiftDown()); - GetEventHandler()->ProcessEvent(g_evt); - - } - dc.EndDrawing(); - } - else if (ev.Dragging() && ev.LeftIsDown()) - { - switch (m_dragStatus) - { - case wxGRID_DRAG_NONE: - { - int orientation; - if (LabelSashHitTest((int)ev.GetX(), (int)ev.GetY(), &orientation, &m_dragRowOrCol, &m_dragStartPosition)) - { - if (orientation == wxHORIZONTAL) - { - m_dragStatus = wxGRID_DRAG_LEFT_RIGHT; - SetCursor(m_horizontalSashCursor); - m_dragLastPosition = (int)ev.GetX(); - } - else - { - m_dragStatus = wxGRID_DRAG_UP_DOWN; - SetCursor(m_verticalSashCursor); - m_dragLastPosition = (int)ev.GetY(); - } - wxClientDC dc(this); - dc.BeginDrawing(); - dc.SetLogicalFunction(wxINVERT); - if (orientation == wxHORIZONTAL) - dc.DrawLine((int)ev.GetX(), m_topOfSheet, (int)ev.GetX(), m_bottomOfSheet); - else - dc.DrawLine(m_leftOfSheet, (int)ev.GetY(), m_rightOfSheet, (int)ev.GetY()); - dc.EndDrawing(); - - CaptureMouse(); - } - break; - } - case wxGRID_DRAG_LEFT_RIGHT: - { - wxClientDC dc(this); - dc.BeginDrawing(); - dc.SetLogicalFunction(wxINVERT); - dc.DrawLine(m_dragLastPosition, m_topOfSheet, m_dragLastPosition, m_bottomOfSheet); - - dc.DrawLine((int)ev.GetX(), m_topOfSheet, (int)ev.GetX(), m_bottomOfSheet); - dc.EndDrawing(); - - m_dragLastPosition = (int)ev.GetX(); - SetCursor(m_horizontalSashCursor); - break; - } - case wxGRID_DRAG_UP_DOWN: - { - wxClientDC dc(this); - dc.BeginDrawing(); - dc.SetLogicalFunction(wxINVERT); - dc.DrawLine(m_leftOfSheet, m_dragLastPosition, m_rightOfSheet, m_dragLastPosition); - - dc.DrawLine(m_leftOfSheet, (int)ev.GetY(), m_rightOfSheet, (int)ev.GetY()); - dc.EndDrawing(); - - m_dragLastPosition = (int)ev.GetY(); - SetCursor(m_verticalSashCursor); - break; - } - } - } - else if (ev.Moving()) - { - int rowOrCol, orientation, startPos; - if (LabelSashHitTest((int)ev.GetX(), (int)ev.GetY(), &orientation, &rowOrCol, &startPos)) - { - if (orientation == wxHORIZONTAL) - SetCursor(m_horizontalSashCursor); - else - SetCursor(m_verticalSashCursor); - } - else - SetCursor(*wxSTANDARD_CURSOR); - } - else if (ev.LeftUp()) - { - switch (m_dragStatus) - { - case wxGRID_DRAG_LEFT_RIGHT: - { - wxClientDC dc(this); - dc.BeginDrawing(); - dc.SetLogicalFunction(wxINVERT); - dc.DrawLine(m_dragLastPosition, m_topOfSheet, m_dragLastPosition, m_bottomOfSheet); - dc.SetLogicalFunction(wxCOPY); - dc.EndDrawing(); - - ReleaseMouse(); - if (ev.GetX() > m_dragStartPosition) - { - m_colWidths[m_dragRowOrCol] = (short)(ev.GetX() - m_dragStartPosition); - UpdateDimensions(); - AdjustScrollbars(); - Refresh(); - } - SetCursor(*wxSTANDARD_CURSOR); - int cw, ch; - GetClientSize(&cw, &ch); - wxSizeEvent evt; - OnSize(evt); - break; - } - case wxGRID_DRAG_UP_DOWN: - { - wxClientDC dc(this); - dc.BeginDrawing(); - dc.SetLogicalFunction(wxINVERT); - dc.DrawLine(m_leftOfSheet, m_dragLastPosition, m_rightOfSheet, m_dragLastPosition); - dc.SetLogicalFunction(wxCOPY); - dc.EndDrawing(); - - ReleaseMouse(); - if (ev.GetY() > m_dragStartPosition) - { - m_rowHeights[m_dragRowOrCol] = (short)(ev.GetY() - m_dragStartPosition); - UpdateDimensions(); - AdjustScrollbars(); - Refresh(); - } - SetCursor(*wxSTANDARD_CURSOR); - break; - } - } - m_dragStatus = wxGRID_DRAG_NONE; - } - else if (ev.RightDown()) - { - int row, col; - if (CellHitTest((int)ev.GetX(), (int)ev.GetY(), &row, &col)) - { - //OnCellRightClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown()); - wxGridEvent g_evt(GetId(), wxEVT_GRID_CELL_RCLICK, this, - row, col, (int)ev.GetX(), (int)ev.GetY(), - ev.ControlDown(), ev.ShiftDown()); - GetEventHandler()->ProcessEvent(g_evt); - - } - if (LabelHitTest((int)ev.GetX(), (int)ev.GetY(), &row, &col)) - { - //OnLabelRightClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown()); - wxGridEvent g_evt(GetId(), wxEVT_GRID_LABEL_RCLICK, this, - row, col, (int)ev.GetX(), (int)ev.GetY(), - ev.ControlDown(), ev.ShiftDown()); - GetEventHandler()->ProcessEvent(g_evt); - } - } -} - -void wxGenericGrid::OnSelectCellImplementation(wxDC *dc, int row, int col) -{ - m_wCursorColumn = col; - m_wCursorRow = row; - - //OnChangeSelectionLabel(); - wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_SEL_LABEL, this); - GetEventHandler()->ProcessEvent(g_evt); - - SetGridClippingRegion(dc); - - // Remove the highlight from the old cell - if ( m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace))) - { - HighlightCell(dc, FALSE); - } - - - // Highlight the new cell and copy its content to the edit control - SetCurrentRect(m_wCursorRow, m_wCursorColumn); - wxGridCell *cell = GetCell(m_wCursorRow, m_wCursorColumn); - if (cell) - { - if ( cell->GetTextValue().IsNull() ) - m_textItem->SetValue(wxT("")); - else - m_textItem->SetValue(cell->GetTextValue()); - } - - SetGridClippingRegion(dc); - - - if ( m_editable && m_editInPlace ) - { - int x, y, width, height; - if ( m_currentRect.x <= 0 ) - { - x = 0; - width = m_currentRect.width + wxIPE_ADJUST; - } - else - { - x = m_currentRect.x - wxIPE_ADJUST; - width = m_currentRect.width + wxIPE_ADJUST*2; - } - - if ( m_currentRect.y <= 0 ) - { - y = 0; - height = m_currentRect.height + wxIPE_ADJUST; - } - else - { - y = m_currentRect.y - wxIPE_ADJUST; - height = m_currentRect.height + wxIPE_ADJUST*2; - } - - m_inPlaceTextItem->SetSize( x, y, width, height ); - - if ( cell ) { - m_inPlaceTextItem->SetFont( cell->GetFont() ); - m_inPlaceTextItem->SetBackgroundColour(cell->GetBackgroundColour()); - m_inPlaceTextItem->SetForegroundColour(cell->GetTextColour()); - - if ( cell->GetTextValue().IsNull() ) { - m_inPlaceTextItem->SetValue( wxT("") ); - } - else { - m_inPlaceTextItem->SetValue( cell->GetTextValue() ); - } - } - - m_inPlaceTextItem->Show(TRUE); - m_inPlaceTextItem->SetFocus(); -#if defined(__VISAGECPP__) - { - int highlight = wxIPE_HIGHLIGHT; - if (highlight != 0) - HighlightCell(dc, TRUE); - } -#else - if (wxIPE_HIGHLIGHT != 0) - HighlightCell(dc, TRUE); -#endif - } - else if (!wxIPE_HIGHLIGHT) - { - // 1) Why isn't this needed for Windows?? - // Probably because of the SetValue?? JS. - // 2) Arrrrrgh. This isn't needed anywhere, - // of course. One hour of debugging... RR. - // - // 3) It *is* needed for Motif - michael - // - // 4) It *seems* to be needed whenever - // wxIPE_HIGHLIGHT is not set (i.e. - // for both wxGTK and wxMOTIF)... SN. - if (!(m_editable && m_editInPlace))) - HighlightCell(dc, TRUE); - } - - dc->DestroyClippingRegion(); - - OnSelectCell(row, col); - wxGridEvent g_evt2(GetId(), wxEVT_GRID_SELECT_CELL, this, row, col); - GetEventHandler()->ProcessEvent(g_evt2); -} - -wxGridCell *wxGenericGrid::OnCreateCell() -{ - return new wxGridCell(this); -} - -void wxGenericGrid::OnChangeLabels() -{ - char buf[100]; - int i; - for (i = 0; i < m_totalRows; i++) - { - sprintf(buf, wxT("%d"), i+1); - SetLabelValue(wxVERTICAL, buf, i); - } - // A...Z,AA...ZZ,AAA...ZZZ, etc. - for (i = 0; i < m_totalCols; i++) - { - int j; - int noTimes = (i/26 + 1); - int ch = (i % 26) + 65; - buf[0] = 0; - for (j = 0; j < noTimes; j++) - { - char buf2[20]; - sprintf(buf2, wxT("%c"), (char)ch); - strcat(buf, buf2); - } - SetLabelValue(wxHORIZONTAL, buf, i); - } -} - -void wxGenericGrid::OnChangeSelectionLabel() -{ - if (!GetEditable()) - return; - - wxString rowLabel(GetLabelValue(wxVERTICAL, GetCursorRow())); - wxString colLabel(GetLabelValue(wxHORIZONTAL, GetCursorColumn())); - - wxString newLabel = colLabel + rowLabel; - if ((newLabel.Length() > 0) && (newLabel.Length() <= 8) && GetTextItem()) - { -// GetTextItem()->SetLabel(newLabel); - } -} - -void wxGenericGrid::HighlightCell(wxDC *dc, bool doHighlight) -{ - wxPen savePen = dc->GetPen(); - if (doHighlight) - dc->SetPen(m_highlightPen); - else - dc->SetPen(*wxThePenList->FindOrCreatePen(m_cellBackgroundColour, 1, wxSOLID)); - - // Top - dc->DrawLine( m_currentRect.x + 1, - m_currentRect.y + 1, - m_currentRect.x + m_currentRect.width - 1, - m_currentRect.y + 1); - // Right - dc->DrawLine( m_currentRect.x + m_currentRect.width - 1, - m_currentRect.y + 1, - m_currentRect.x + m_currentRect.width - 1, - m_currentRect.y + m_currentRect.height - 1 ); - // Bottom - dc->DrawLine( m_currentRect.x + m_currentRect.width - 1, - m_currentRect.y + m_currentRect.height - 1, - m_currentRect.x + 1, - m_currentRect.y + m_currentRect.height - 1); - // Left - dc->DrawLine( m_currentRect.x + 1, - m_currentRect.y + m_currentRect.height - 1, - m_currentRect.x + 1, - m_currentRect.y + 1); - - dc->SetPen(savePen); -} - -void wxGenericGrid::DrawCellText() -{ - if (!m_currentRectVisible) - return; - - wxGridCell *cell = GetCell(GetCursorRow(), GetCursorColumn()); - if (!cell) - return; - - wxClientDC dc(this); - dc.BeginDrawing(); - - SetGridClippingRegion(& dc); - - dc.SetBackgroundMode(wxTRANSPARENT); - dc.SetBrush(cell->GetBackgroundBrush()); - - wxString editValue = m_textItem->GetValue(); - - wxRect rect; - rect = m_currentRect; - rect.x += 3; - rect.y += 2; - rect.width -= 5; - rect.height -= 4; - - // FIXME: what's this string of spaces supposed to represent? - DrawTextRect(& dc, wxT(" "), &rect, wxLEFT); - DrawTextRect(& dc, editValue, &rect, cell->GetAlignment()); - - dc.DestroyClippingRegion(); - - dc.SetBackgroundMode(wxSOLID); - - dc.EndDrawing(); -} - -void wxGenericGrid::SetCurrentRect(int Row, int Column, int canvasW, int canvasH) -{ - int currentWidth = m_leftOfSheet + m_verticalLabelWidth; - int i; - for (i = m_scrollPosX; i < Column; i++) - currentWidth += m_colWidths[i]; - - int currentHeight = m_topOfSheet + m_horizontalLabelHeight; - for (i = m_scrollPosY; i < Row; i++) - currentHeight += m_rowHeights[i]; - - m_currentRect.x = currentWidth; - m_currentRect.y = currentHeight; - m_currentRect.width = m_colWidths ? (m_colWidths[Column]) : 0; - m_currentRect.height = m_rowHeights ? (m_rowHeights[Row]) : 0; - - if (Row < m_scrollPosY || Column < m_scrollPosX) - m_currentRectVisible = FALSE; - else if ((canvasW != -1 && canvasH != -1) && (m_currentRect.x > canvasW || m_currentRect.y > canvasH)) - m_currentRectVisible = FALSE; - else m_currentRectVisible = TRUE; -} - -static bool wxRectIntersection(wxRect *rect1, wxRect *rect2, wxRect *rect3) -{ - int x2_1 = rect1->x + rect1->width; - int y2_1 = rect1->y + rect1->height; - - int x2_2 = rect2->x + rect2->width; - int y2_2 = rect2->y + rect2->height; - - int x2_3, y2_3; - - // Check for intersection - if ((rect1->x > x2_2) || (rect2->x > x2_1) || - (rect1->y > y2_2) || (rect2->y > y2_1)) - { - // No intersection - rect3->x = rect3->y = rect3->width = rect3->height = 0; - return FALSE; - } - - if (rect1->x > rect2->x) - rect3->x = rect1->x; - else - rect3->x = rect2->x; - if (rect1->y > rect2->y) - rect3->y = rect1->y; - else - rect3->y = rect2->y; - - if (x2_1 > x2_2) - x2_3 = x2_2; - else - x2_3 = x2_1; - if (y2_1 > y2_2) - y2_3 = y2_2; - else - y2_3 = y2_1; - - rect3->width = (int)(x2_3 - rect3->x); - rect3->height = (int)(y2_3 - rect3->y); - return TRUE; -} - -void wxGenericGrid::DrawTextRect(wxDC *dc, const wxString& text, wxRect *rect, int flag) -{ - dc->BeginDrawing(); - - // Ultimately, this functionality should be built into wxWindows, - // and optimized for each platform. E.g. on Windows, use DrawText - // passing a clipping rectangle, so that the wxWindows clipping region - // does not have to be used to implement this. - - // If we're already clipping, we need to find the intersection - // between current clipping area and text clipping area. - - wxRect clipRect; - wxRect clipRect2; - long clipX, clipY, clipW, clipH; - dc->GetClippingBox(&clipX, &clipY, &clipW, &clipH); - clipRect.x = (int)clipX; clipRect.y = (int)clipY; - clipRect.width = (int)clipW; clipRect.height = (int)clipH; - - bool alreadyClipping = TRUE; - - if (clipRect.x == 0 && clipRect.y == 0 && clipRect.width == 0 && clipRect.height == 0) - { - alreadyClipping = FALSE; - clipRect2.x = rect->x; clipRect2.y = rect->y; - clipRect2.width = rect->width; clipRect2.height = rect->height; - } - else - { - // Find intersection. - if (!wxRectIntersection(rect, &clipRect, &clipRect2)) - return; - } - - if (alreadyClipping) - dc->DestroyClippingRegion(); - - dc->SetClippingRegion(clipRect2.x, clipRect2.y, clipRect2.width, clipRect2.height); - long textWidth, textHeight; - - dc->GetTextExtent(text, &textWidth, &textHeight); - - // Do alignment - float x,y; - switch (flag) - { - case wxRIGHT: - { - x = (rect->x + rect->width - textWidth - (float)1.0); - y = (rect->y + (rect->height - textHeight)/(float)2.0); - break; - } - case wxCENTRE: - { - x = (rect->x + (rect->width - textWidth)/(float)2.0); - y = (rect->y + (rect->height - textHeight)/(float)2.0); - break; - } - case wxLEFT: - default: - { - x = (rect->x + (float)1.0); - y = (rect->y + (rect->height - textHeight)/(float)2.0); - break; - } - } - dc->DrawText(text, (long)x, (long)y ); - - dc->DestroyClippingRegion(); - - // Restore old clipping - if (alreadyClipping) - dc->SetClippingRegion(clipRect.x, clipRect.y, clipRect.width, clipRect.height); - - dc->EndDrawing(); -} - -void wxGenericGrid::DrawBitmapRect(wxDC *dc, wxBitmap *bitmap, wxRect *rect, int flag) -{ - dc->BeginDrawing(); - - // Ultimately, this functionality should be built into wxWindows, - // and optimized for each platform. E.g. on Windows, use DrawText - // passing a clipping rectangle, so that the wxWindows clipping region - // does not have to be used to implement this. - - // If we're already clipping, we need to find the intersection - // between current clipping area and text clipping area. - - wxRect clipRect; - wxRect clipRect2; - long clipX, clipY, clipW, clipH; - dc->GetClippingBox(&clipX, &clipY, &clipW, &clipH); - clipRect.x = (int)clipX; clipRect.y = (int)clipY; - clipRect.width = (int)clipW; clipRect.height = (int)clipH; - - bool alreadyClipping = TRUE; - - if (clipRect.x == 0 && clipRect.y == 0 && clipRect.width == 0 && clipRect.height == 0) - { - alreadyClipping = FALSE; - clipRect2.x = rect->x; clipRect2.y = rect->y; - clipRect2.width = rect->width; clipRect2.height = rect->height; - } - else - { - // Find intersection. - if (!wxRectIntersection(rect, &clipRect, &clipRect2)) - return; - } - - if (alreadyClipping) - dc->DestroyClippingRegion(); - - dc->SetClippingRegion(clipRect2.x, clipRect2.y, clipRect2.width, clipRect2.height); - float bitmapWidth, bitmapHeight; - - bitmapWidth = bitmap->GetWidth(); - bitmapHeight = bitmap->GetHeight(); - - // Do alignment - long x,y; - switch (flag) - { - case wxRIGHT: - { - x = (long)(rect->x + rect->width - bitmapWidth - 1); - y = (long)(rect->y + (rect->height - bitmapHeight)/2.0); - break; - } - case wxCENTRE: - { - x = (long)(rect->x + (rect->width - bitmapWidth)/2.0); - y = (long)(rect->y + (rect->height - bitmapHeight)/2.0); - break; - } - case wxLEFT: - default: - { - x = (long)(rect->x + 1); - y = (long)(rect->y + (rect->height - bitmapHeight)/2.0); - break; - } - } - wxMemoryDC dcTemp; - dcTemp.SelectObject(*bitmap); - - dc->Blit( (long)x, (long)y, (long)bitmapWidth, (long)bitmapHeight, &dcTemp, 0, 0); - dcTemp.SelectObject(wxNullBitmap); - - dc->DestroyClippingRegion(); - - // Restore old clipping - if (alreadyClipping) - dc->SetClippingRegion(clipRect.x, clipRect.y, clipRect.width, clipRect.height); - - dc->EndDrawing(); -} - -void wxGenericGrid::OnActivate(bool active) -{ - if (active) - { - // Edit control should always have the focus - if (GetTextItem() && GetEditable()) - { - GetTextItem()->SetFocus(); - wxGridCell *cell = GetCell(GetCursorRow(), GetCursorColumn()); - if (cell) - GetTextItem()->SetValue(cell->GetTextValue()); - } - } -} - -void wxGenericGrid::SetCellValue(const wxString& val, int row, int col) -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - { - cell->SetTextValue(val); - - RefreshCell(row, col, TRUE); - } -} - -void wxGenericGrid::RefreshCell(int row, int col, bool setText) -{ - // Don't refresh within a pair of batch brackets - if (GetBatchCount() > 0) - return; - - int cw, ch; - GetClientSize(&cw, &ch); - - SetCurrentRect(row, col, cw, ch); - if (m_currentRectVisible) - { - wxGridCell *cell = GetCell(row, col); - - bool currentPos = FALSE; - if (row == m_wCursorRow && col == m_wCursorColumn && GetTextItem() && GetTextItem()->IsShown() && setText) - { - GetTextItem()->SetValue(cell->GetTextValue()); - currentPos = TRUE; - } - // Gets refreshed anyway in MSW -#ifdef __WXMSW__ - if (!currentPos) -#endif - { - wxClientDC dc(this); - dc.BeginDrawing(); - DrawCellBackground(& dc, &m_currentRect, row, col); - DrawCellValue(& dc, &m_currentRect, row, col); - dc.EndDrawing(); - } - } -} - -wxString& wxGenericGrid::GetCellValue(int row, int col) const -{ - static wxString emptyString(wxT("")); - - wxGridCell *cell = GetCell(row, col); - if (cell) - return cell->GetTextValue(); - else - return emptyString; -} - -void wxGenericGrid::SetColumnWidth(int col, int width) -{ - if (col <= m_totalCols) - m_colWidths[col] = width; -} - -int wxGenericGrid::GetColumnWidth(int col) const -{ - if (col <= m_totalCols) - return m_colWidths[col]; - else - return 0; -} - -void wxGenericGrid::SetRowHeight(int row, int height) -{ - if (row <= m_totalRows) - m_rowHeights[row] = height; -} - -int wxGenericGrid::GetRowHeight(int row) const -{ - if (row <= m_totalRows) - return m_rowHeights[row]; - else - return 0; -} - -void wxGenericGrid::SetLabelSize(int orientation, int sz) -{ - if (orientation == wxHORIZONTAL) - m_horizontalLabelHeight = sz; - else - m_verticalLabelWidth = sz; - UpdateDimensions(); - SetCurrentRect(GetCursorRow(), GetCursorColumn()); -} - -int wxGenericGrid::GetLabelSize(int orientation) const -{ - if (orientation == wxHORIZONTAL) - return m_horizontalLabelHeight; - else - return m_verticalLabelWidth; -} - -wxGridCell *wxGenericGrid::GetLabelCell(int orientation, int pos) const -{ - if (orientation == wxHORIZONTAL) - { - if (m_colLabelCells && pos < m_totalCols) - return m_colLabelCells[pos]; - else - return (wxGridCell *) NULL; - } - else - { - if (m_rowLabelCells && pos < m_totalRows) - return m_rowLabelCells[pos]; - else - return (wxGridCell *) NULL; - } -} - -void wxGenericGrid::SetLabelValue(int orientation, const wxString& val, int pos) -{ - wxGridCell *cell = GetLabelCell(orientation, pos); - if (cell) - cell->SetTextValue(val); -} - -wxString& wxGenericGrid::GetLabelValue(int orientation, int pos) const -{ - static wxString emptyString = wxT(""); - wxGridCell *cell = GetLabelCell(orientation, pos); - if (cell) - return cell->GetTextValue(); - else - return emptyString; -} - -void wxGenericGrid::SetLabelAlignment(int orientation, int align) -{ - if (orientation == wxHORIZONTAL) - m_horizontalLabelAlignment = align; - else - m_verticalLabelAlignment = align; - UpdateDimensions(); - SetCurrentRect(GetCursorRow(), GetCursorColumn()); -} - -int wxGenericGrid::GetLabelAlignment(int orientation) const -{ - if (orientation == wxHORIZONTAL) - return m_horizontalLabelAlignment; - else - return m_verticalLabelAlignment; -} - -void wxGenericGrid::SetLabelTextColour(const wxColour& colour) -{ - m_labelTextColour = colour; - -} - -void wxGenericGrid::SetLabelBackgroundColour(const wxColour& colour) -{ - m_labelBackgroundColour = colour; - m_labelBackgroundBrush = * wxTheBrushList->FindOrCreateBrush(m_labelBackgroundColour, wxSOLID); -} - -void wxGenericGrid::SetEditable(bool edit) -{ - m_editable = edit; - if (edit) - { - int controlW, controlH; - m_textItem->GetSize(&controlW, &controlH); - m_editControlPosition.height = controlH; - - m_topOfSheet = m_editControlPosition.x + controlH + 2; - if (m_textItem) - { - m_editingPanel->Show(TRUE); - m_textItem->Show(TRUE); - m_textItem->SetFocus(); - } - - if (m_inPlaceTextItem) - { - m_inPlaceTextItem->Show(TRUE); - m_inPlaceTextItem->SetFocus(); - } - } - else - { - m_topOfSheet = 0; - if (m_textItem) - { - m_textItem->Show(FALSE); - m_editingPanel->Show(FALSE); - } - - if ( m_inPlaceTextItem ) - { - m_inPlaceTextItem->Show(FALSE); - } - } - UpdateDimensions(); - SetCurrentRect(GetCursorRow(), GetCursorColumn()); - - int cw, ch; - GetClientSize(&cw, &ch); - wxSizeEvent evt; - OnSize(evt); -/* - int cw, ch; - int m_scrollWidth = 16; - GetClientSize(&cw, &ch); - - if (m_vScrollBar) - m_vScrollBar->SetSize(cw - m_scrollWidth, m_topOfSheet, - m_scrollWidth, ch - m_topOfSheet - m_scrollWidth); -*/ -} - - -void wxGenericGrid::SetEditInPlace(bool edit) -{ - if ( m_editInPlace != edit ) - { - m_editInPlace = edit; - - if ( m_editInPlace ) // switched on - { - if ( m_currentRectVisible && m_editable ) - { - m_inPlaceTextItem->SetSize( m_currentRect.x-wxIPE_ADJUST, - m_currentRect.y-wxIPE_ADJUST, - m_currentRect.width+wxIPE_ADJUST*2, - m_currentRect.height+wxIPE_ADJUST*2 ); - - wxGridCell *cell = GetCell(m_wCursorRow, m_wCursorColumn); - - if ( cell ) { - m_inPlaceTextItem->SetFont( cell->GetFont() ); - m_inPlaceTextItem->SetBackgroundColour(cell->GetBackgroundColour()); - m_inPlaceTextItem->SetForegroundColour(cell->GetTextColour()); - - if ( cell->GetTextValue().IsNull() ) { - m_inPlaceTextItem->SetValue( wxT("") ); - } - else { - m_inPlaceTextItem->SetValue( cell->GetTextValue() ); - } - } - - m_inPlaceTextItem->Show( TRUE ); - m_inPlaceTextItem->SetFocus(); - } - } - else // switched off - { - m_inPlaceTextItem->Show( FALSE ); - } - } -} - - -void wxGenericGrid::SetCellAlignment(int flag, int row, int col) -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - cell->SetAlignment(flag); -} - -int wxGenericGrid::GetCellAlignment(int row, int col) const -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - return cell->GetAlignment(); - else - return m_cellAlignment; -} - -void wxGenericGrid::SetCellAlignment(int flag) -{ - m_cellAlignment = flag; - int i,j; - for (i = 0; i < GetRows(); i++) - for (j = 0; j < GetCols(); j++) - if (GetCell(i, j)) - GetCell(i, j)->SetAlignment(flag); -} - -int wxGenericGrid::GetCellAlignment(void) const -{ - return m_cellAlignment; -} - -void wxGenericGrid::SetCellBackgroundColour(const wxColour& col) -{ - m_cellBackgroundColour = col; - int i,j; - for (i = 0; i < GetRows(); i++) - for (j = 0; j < GetCols(); j++) - if (GetCell(i, j)) - GetCell(i, j)->SetBackgroundColour(col); -} - -void wxGenericGrid::SetCellBackgroundColour(const wxColour& val, int row, int col) -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - { - cell->SetBackgroundColour(val); - RefreshCell(row, col); - } -} - -wxColour& wxGenericGrid::GetCellBackgroundColour(int row, int col) const -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - return cell->GetBackgroundColour(); - else - return (wxColour&) m_cellBackgroundColour; -} - -void wxGenericGrid::SetCellTextColour(const wxColour& val, int row, int col) -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - { - cell->SetTextColour(val); - RefreshCell(row, col); - } -} - -void wxGenericGrid::SetCellTextFont(const wxFont& fnt, int row, int col) -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - { - cell->SetFont(fnt); - RefreshCell(row, col); - } -} - -wxFont& wxGenericGrid::GetCellTextFont(int row, int col) const -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - return (wxFont&) cell->GetFont(); - else - return (wxFont&) m_cellTextFont; -} - -wxColour& wxGenericGrid::GetCellTextColour(int row, int col) const -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - return (wxColour&) cell->GetTextColour(); - else - return (wxColour&) m_cellTextColour; -} - -void wxGenericGrid::SetCellTextColour(const wxColour& val) -{ - m_cellTextColour = val; - int i,j; - for (i = 0; i < GetRows(); i++) - for (j = 0; j < GetCols(); j++) - if (GetCell(i, j)) - GetCell(i, j)->SetTextColour(val); -} - -void wxGenericGrid::SetCellTextFont(const wxFont& fnt) -{ - m_cellTextFont = fnt; - int i,j; - for (i = 0; i < GetRows(); i++) - for (j = 0; j < GetCols(); j++) - if (GetCell(i, j)) - GetCell(i, j)->SetFont(fnt); -} - -void wxGenericGrid::SetCellBitmap(wxBitmap *bitmap, int row, int col) -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - { - cell->SetCellBitmap(bitmap); - RefreshCell(row, col); - } -} - -wxBitmap *wxGenericGrid::GetCellBitmap(int row, int col) const -{ - wxGridCell *cell = GetCell(row, col); - if (cell) - { - return cell->GetCellBitmap(); - } - else - return (wxBitmap *) NULL; -} - -bool wxGenericGrid::InsertCols(int pos, int n, bool updateLabels) -{ - if (pos > m_totalCols) - return FALSE; - - if (!m_gridCells) - return CreateGrid(1, n); - else - { - int i, j; - // Cells - for (i = 0; i < m_totalRows; i++) - { - wxGridCell **cols = m_gridCells[i]; - wxGridCell **newCols = new wxGridCell *[m_totalCols + n]; - for (j = 0; j < pos; j++) - newCols[j] = cols[j]; - for (j = pos; j < pos + n; j++) - newCols[j] = new wxGridCell(this); - for (j = pos + n; j < m_totalCols + n; j++) - newCols[j] = cols[j - n]; - - delete[] cols; - m_gridCells[i] = newCols; - } - - // Column widths - short *newColWidths = new short[m_totalCols + n]; - for (j = 0; j < pos; j++) - newColWidths[j] = m_colWidths[j]; - for (j = pos; j < pos + n; j++) - newColWidths[j] = wxGRID_DEFAULT_CELL_WIDTH; - for (j = pos + n; j < m_totalCols + n; j++) - newColWidths[j] = m_colWidths[j - n]; - delete[] m_colWidths; - m_colWidths = newColWidths; - - // Column labels - wxGridCell **newLabels = new wxGridCell *[m_totalCols + n]; - for (j = 0; j < pos; j++) - newLabels[j] = m_colLabelCells[j]; - for (j = pos; j < pos + n; j++) - newLabels[j] = new wxGridCell(this); - for (j = pos + n; j < m_totalCols + n; j++) - newLabels[j] = m_colLabelCells[j - n]; - - delete[] m_colLabelCells; - m_colLabelCells = newLabels; - - m_totalCols += n; - - if (updateLabels) { - //OnChangeLabels(); - wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS, this); - GetEventHandler()->ProcessEvent(g_evt); - } - - UpdateDimensions(); - AdjustScrollbars(); - return TRUE; - } -} - -bool wxGenericGrid::InsertRows(int pos, int n, bool updateLabels) -{ - if (pos > m_totalRows) - return FALSE; - - if (!m_gridCells) - return CreateGrid(n, 1); - else - { - int i, j; - - wxGridCell ***rows = new wxGridCell **[m_totalRows + n]; - - // Cells - for (i = 0; i < pos; i++) - rows[i] = m_gridCells[i]; - - for (i = pos; i < pos + n; i++) - { - rows[i] = new wxGridCell *[m_totalCols]; - for (j = 0; j < m_totalCols; j++) - rows[i][j] = new wxGridCell(this); - } - - for (i = pos + n; i < m_totalRows + n; i++) - rows[i] = m_gridCells[i - n]; - - delete[] m_gridCells; - m_gridCells = rows; - - // Row heights - short *newRowHeights = new short[m_totalRows + n]; - for (i = 0; i < pos; i++) - newRowHeights[i] = m_rowHeights[i]; - for (i = pos; i < pos + n; i++) - newRowHeights[i] = wxGRID_DEFAULT_CELL_HEIGHT; - for (i = pos + n; i < m_totalRows + n; i++) - newRowHeights[i] = m_rowHeights[i - n]; - delete[] m_rowHeights; - m_rowHeights = newRowHeights; - - // Column labels - wxGridCell **newLabels = new wxGridCell *[m_totalRows + n]; - for (i = 0; i < pos; i++) - newLabels[i] = m_rowLabelCells[i]; - for (i = pos; i < pos + n; i++) - newLabels[i] = new wxGridCell(this); - for (i = pos + n; i < m_totalRows + n; i++) - newLabels[i] = m_rowLabelCells[i - n]; - - delete[] m_rowLabelCells; - m_rowLabelCells = newLabels; - - m_totalRows += n; - - if (updateLabels) { - //OnChangeLabels(); - wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS, this); - GetEventHandler()->ProcessEvent(g_evt); - } - - UpdateDimensions(); - AdjustScrollbars(); - return TRUE; - } -} - -bool wxGenericGrid::AppendCols(int n, bool updateLabels) -{ - return InsertCols(GetCols(), n, updateLabels); -} - -bool wxGenericGrid::AppendRows(int n, bool updateLabels) -{ - return InsertRows(GetRows(), n, updateLabels); -} - -bool wxGenericGrid::DeleteRows(int pos, int n, bool updateLabels) -{ - if (pos > m_totalRows) - return FALSE; - if (!m_gridCells) - return FALSE; - - int i; - - wxGridCell ***rows = new wxGridCell **[m_totalRows - n]; - - // Cells - for (i = 0; i < pos; i++) - rows[i] = m_gridCells[i]; - - for (i = pos + n; i < m_totalRows; i++) - rows[i-n] = m_gridCells[i]; - - delete[] m_gridCells; - m_gridCells = rows; - - // Row heights - short *newRowHeights = new short[m_totalRows - n]; - for (i = 0; i < pos; i++) - newRowHeights[i] = m_rowHeights[i]; - for (i = pos + n; i < m_totalRows; i++) - newRowHeights[i-n] = m_rowHeights[i]; - delete[] m_rowHeights; - m_rowHeights = newRowHeights; - - // Column labels - wxGridCell **newLabels = new wxGridCell *[m_totalRows - n]; - for (i = 0; i < pos; i++) - newLabels[i] = m_rowLabelCells[i]; - for (i = pos + n; i < m_totalRows; i++) - newLabels[i-n] = m_rowLabelCells[i]; - - delete[] m_rowLabelCells; - m_rowLabelCells = newLabels; - - m_totalRows -= n; - - if (updateLabels){ - //OnChangeLabels(); - wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS, this); - GetEventHandler()->ProcessEvent(g_evt); - } - UpdateDimensions(); - AdjustScrollbars(); - return TRUE; -} - -bool wxGenericGrid::DeleteCols(int pos, int n, bool updateLabels) -{ - if (pos + n > m_totalCols) - return FALSE; - if (!m_gridCells) - return FALSE; - - int i, j; - - // Cells - for (i = 0; i < m_totalRows; i++) - { - wxGridCell **cols = m_gridCells[i]; - wxGridCell **newCols = new wxGridCell *[m_totalCols - n]; - for (j = 0; j < pos; j++) - newCols[j] = cols[j]; - for (j = pos; j < pos + n; j++) - delete cols[j]; - for (j = pos + n; j < m_totalCols; j++) - newCols[j-n] = cols[j]; - - delete[] cols; - m_gridCells[i] = newCols; - } - - // Column widths - short *newColWidths = new short[m_totalCols - n]; - for (j = 0; j < pos; j++) - newColWidths[j] = m_colWidths[j]; - for (j = pos + n; j < m_totalCols; j++) - newColWidths[j-n] = m_colWidths[j]; - delete[] m_colWidths; - m_colWidths = newColWidths; - - // Column labels - wxGridCell **newLabels = new wxGridCell *[m_totalCols - n]; - for (j = 0; j < pos; j++) - newLabels[j] = m_colLabelCells[j]; - for (j = pos + n; j < m_totalCols; j++) - newLabels[j-n] = m_colLabelCells[j]; - - delete[] m_colLabelCells; - m_colLabelCells = newLabels; - - m_totalCols -= n; - - if (updateLabels) { - //OnChangeLabels(); - wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS, this); - GetEventHandler()->ProcessEvent(g_evt); - } - UpdateDimensions(); - AdjustScrollbars(); - return TRUE; -} - -void wxGenericGrid::SetGridCursor(int row, int col) -{ - if (row >= m_totalRows || col >= m_totalCols) - return; - - if (row == GetCursorRow() && col == GetCursorColumn()) - return; - - wxClientDC dc(this); - dc.BeginDrawing(); - - SetGridClippingRegion(& dc); - - if (m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace))) - HighlightCell(& dc, FALSE); - - m_wCursorRow = row; - m_wCursorColumn = col; - - int cw, ch; - GetClientSize(&cw, &ch); - - SetCurrentRect(row, col, cw, ch); - - if (m_currentRectVisible && (wxIPE_HIGHLIGHT || !(m_editable && m_editInPlace))) - HighlightCell(& dc, TRUE); - - dc.DestroyClippingRegion(); - dc.EndDrawing(); -} - -// ---------------------------------------------------------------------------- -// Grid cell -// ---------------------------------------------------------------------------- - -wxGridCell::wxGridCell(wxGenericGrid *window) -{ - cellBitmap = (wxBitmap *) NULL; - font = wxNullFont; - backgroundBrush = wxNullBrush; - if (window) - textColour = window->GetCellTextColour(); - else - textColour.Set(0,0,0); - if (window) - backgroundColour = window->GetCellBackgroundColour(); - else - backgroundColour.Set(255,255,255); - - if (window) - font = window->GetCellTextFont(); - else - font = * wxTheFontList->FindOrCreateFont(12, wxSWISS, wxNORMAL, wxNORMAL); - - SetBackgroundColour(backgroundColour); - - if (window) - alignment = window->GetCellAlignment(); - else - alignment = wxLEFT; - - cellData = (void *)NULL; -} - -wxGridCell::~wxGridCell() -{ -} - -void wxGridCell::SetBackgroundColour(const wxColour& colour) -{ - backgroundColour = colour; - backgroundBrush = * wxTheBrushList->FindOrCreateBrush(backgroundColour, wxSOLID); -} - -void wxGenericGrid::OnText(wxCommandEvent& WXUNUSED(ev) ) -{ - // michael - added this conditional to prevent change to - // grid cell text when edit control is hidden but still has - // focus - // - if ( m_editable ) - { - wxGenericGrid *grid = this; - wxGridCell *cell = grid->GetCell(grid->GetCursorRow(), grid->GetCursorColumn()); - if (cell && grid->CurrentCellVisible()) - { - cell->SetTextValue(grid->GetTextItem()->GetValue()); - if ( m_editInPlace && !m_inOnTextInPlace ) - { - m_inPlaceTextItem->SetValue( grid->GetTextItem()->GetValue() ); - } - - if (!m_editInPlace) { - wxClientDC dc(grid); - - dc.BeginDrawing(); - grid->SetGridClippingRegion(& dc); - grid->DrawCellBackground(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn()); - grid->DrawCellValue(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn()); - grid->HighlightCell(& dc, TRUE); - dc.DestroyClippingRegion(); - dc.EndDrawing(); - } - - //grid->OnCellChange(grid->GetCursorRow(), grid->GetCursorColumn()); - wxGridEvent g_evt(GetId(), wxEVT_GRID_CELL_CHANGE, grid, - grid->GetCursorRow(), grid->GetCursorColumn()); - GetEventHandler()->ProcessEvent(g_evt); - - // grid->DrawCellText(); - } - } -} - -void wxGenericGrid::OnTextEnter(wxCommandEvent& WXUNUSED(ev) ) -{ - // move the cursor down the current row (if possible) - // when the enter key has been pressed - // - if ( m_editable ) - { - if ( GetCursorRow() < GetRows()-1 ) - { - wxClientDC dc( this ); - dc.BeginDrawing(); - OnSelectCellImplementation(& dc, - GetCursorRow()+1, - GetCursorColumn() ); - dc.EndDrawing(); - } - } -} - -void wxGenericGrid::OnTextInPlace(wxCommandEvent& ev ) -{ - if ( m_editable ) - { - wxGenericGrid *grid = this; - wxGridCell *cell = grid->GetCell(grid->GetCursorRow(), grid->GetCursorColumn()); - if (cell && grid->CurrentCellVisible()) - { - m_inOnTextInPlace = TRUE; - grid->GetTextItem()->SetValue( m_inPlaceTextItem->GetValue() ); - OnText( ev ); - m_inOnTextInPlace = FALSE; - } - } -} - -void wxGenericGrid::OnTextInPlaceEnter(wxCommandEvent& WXUNUSED(ev) ) -{ - // move the cursor down the current row (if possible) - // when the enter key has been pressed - // - if ( m_editable ) - { - if ( GetCursorRow() < GetRows()-1 ) - { - wxClientDC dc( this ); - dc.BeginDrawing(); - OnSelectCellImplementation(& dc, - GetCursorRow()+1, - GetCursorColumn() ); - dc.EndDrawing(); - } - } -} - -void wxGenericGrid::OnGridScroll(wxScrollEvent& ev) -{ - if ( m_inScroll ) - return; - - if ( m_editInPlace ) m_inPlaceTextItem->Show(FALSE); - - m_inScroll = TRUE; - wxGenericGrid *win = this; - - bool change = FALSE; - - if (ev.GetEventObject() == win->GetHorizScrollBar()) - { - change = (ev.GetPosition() != m_scrollPosX); - win->SetScrollPosX(ev.GetPosition()); - } - else - { - change = (ev.GetPosition() != m_scrollPosY); - win->SetScrollPosY(ev.GetPosition()); - } - - win->UpdateDimensions(); - - win->SetCurrentRect(win->GetCursorRow(), win->GetCursorColumn()); - - // Because rows and columns can be arbitrary sizes, - // the scrollbars will need to be adjusted to reflect the - // current view. - AdjustScrollbars(); - - if (change) win->Refresh(FALSE); - - if ( m_editInPlace && m_currentRectVisible ) - { - m_inPlaceTextItem->SetSize( m_currentRect.x-wxIPE_ADJUST, - m_currentRect.y-wxIPE_ADJUST, - m_currentRect.width+wxIPE_ADJUST*2, - m_currentRect.height+wxIPE_ADJUST*2 ); - m_inPlaceTextItem->Show( TRUE ); - m_inPlaceTextItem->SetFocus(); - } - - m_inScroll = FALSE; - -} - - -//---------------------------------------------------------------------- -// Default wxGridEvent handlers -// (just redirect to the pre-existing virtual methods) - -void wxGenericGrid::_OnSelectCell(wxGridEvent& ev) -{ - OnSelectCell(ev.m_row, ev.m_col); -} - -void wxGenericGrid::_OnCreateCell(wxGridEvent& ev) -{ - ev.m_cell = OnCreateCell(); -} - -void wxGenericGrid::_OnChangeLabels(wxGridEvent& WXUNUSED(ev)) -{ - OnChangeLabels(); -} - -void wxGenericGrid::_OnChangeSelectionLabel(wxGridEvent& WXUNUSED(ev)) -{ - OnChangeSelectionLabel(); -} - -void wxGenericGrid::_OnCellChange(wxGridEvent& ev) -{ - OnCellChange(ev.m_row, ev.m_col); -} - -void wxGenericGrid::_OnCellLeftClick(wxGridEvent& ev) -{ - OnCellLeftClick(ev.m_row, ev.m_col, ev.m_x, ev.m_y, ev.m_control, ev.m_shift); -} - -void wxGenericGrid::_OnCellRightClick(wxGridEvent& ev) -{ - OnCellRightClick(ev.m_row, ev.m_col, ev.m_x, ev.m_y, ev.m_control, ev.m_shift); -} - -void wxGenericGrid::_OnLabelLeftClick(wxGridEvent& ev) -{ - OnLabelLeftClick(ev.m_row, ev.m_col, ev.m_x, ev.m_y, ev.m_control, ev.m_shift); -} - -void wxGenericGrid::_OnLabelRightClick(wxGridEvent& ev) -{ - OnLabelRightClick(ev.m_row, ev.m_col, ev.m_x, ev.m_y, ev.m_control, ev.m_shift); -} - -void *wxGenericGrid::SetCellData(void *data, int row, int col) -{ - void *rc = NULL; - - wxGridCell *cell = GetCell(row, col); - if ( cell ) - rc = cell->SetCellData(data); - - return rc; -} - -void *wxGenericGrid::GetCellData(int row, int col) -{ - void *rc = NULL; - - wxGridCell *cell = GetCell(row, col); - if ( cell ) - rc = cell->GetCellData(); - - return rc; -} - -#endif // wxUSE_GRID && !(wxUSE_NEW_GRID) diff --git a/src/generic/gridsel.cpp b/src/generic/gridsel.cpp index bac2f8950b..56c8460a49 100644 --- a/src/generic/gridsel.cpp +++ b/src/generic/gridsel.cpp @@ -30,7 +30,7 @@ #pragma hdrstop #endif -#if defined(wxUSE_NEW_GRID) && (wxUSE_NEW_GRID) +#if wxUSE_GRID #include "wx/generic/gridsel.h" @@ -1083,3 +1083,4 @@ int wxGridSelection::BlockContain( int topRow1, int leftCol1, } #endif + -- 2.45.2