NIREP

EzGrid.cpp

Go to the documentation of this file.
00001 
00002 #include "EzGrid.h"
00003 #include <wx/config.h>
00004 // For compilers that support precompilation, includes "wx/wx.h".
00005 #include "wx/wxprec.h"
00006 
00007 #ifdef __BORLANDC__
00008 #pragma hdrstop
00009 #endif
00010 
00011 #ifndef WX_PRECOMP
00012 #include "wx/wx.h"
00013 #endif
00014 
00015 BEGIN_EVENT_TABLE(EzGrid, wxGrid)
00016         EVT_GRID_CELL_LEFT_CLICK(EzGrid::OnCellLeftClick )
00017 #ifdef __WXGTK__
00018     EVT_MOUSEWHEEL(EzGrid::OnMouseWheel)
00019 #endif
00020 END_EVENT_TABLE()
00021 
00022 
00023 EzGrid::EzGrid(wxWindow *parent,
00024         wxWindowID id,  const wxPoint& pos,
00025         const wxSize& size, long style,
00026         const wxString& name) : wxGrid(parent, id, pos, size, style, name),
00027         m_selTemp(NULL)
00028 {
00029         // Adjust the default row height to be more compact
00030         wxFont font = GetLabelFont();
00031         int nWidth = 0;
00032         int nHeight = 18;
00033         GetTextExtent(wxT("W"), &nWidth, &nHeight, NULL, NULL, &font);
00034         SetColLabelSize(nHeight+6);
00035         #ifdef __WXGTK__
00036         SetDefaultRowSize(nHeight+8, TRUE);
00037         #else
00038         SetDefaultRowSize(nHeight+4, TRUE);
00039         #endif
00040 }
00041 
00042 EzGrid::~EzGrid()
00043 {
00044         // Save column widths
00045         wxConfigBase *cfg = wxConfigBase::Get();
00046         wxString strCol;
00047         for (int nCol = 0; nCol < GetNumberCols(); nCol++)
00048         {
00049                 strCol.Printf(wxT("column%d"), nCol);
00050                 cfg->Write(strCol, (long)GetColSize(nCol));
00051         }
00052 }
00053 
00054 
00055 void EzGrid::OnCellLeftClick(wxGridEvent& ev)
00056 {
00057         // This forces the cell to go into edit mode directly
00058         m_waitForSlowClick = TRUE;
00059         SetGridCursor(ev.GetRow(), ev.GetCol());
00060         // Store the click co-ordinates in the editor if possible
00061         // if an editor has created a ClientData area, we presume it's
00062         // a wxPoint and we store the click co-ordinates
00063         wxGridCellEditor* pEditor  = GetCellEditor(ev.GetRow(), ev.GetCol());
00064         wxPoint* pClickPoint = (wxPoint*)pEditor->GetClientData();
00065         if (pClickPoint)
00066         {
00067                 *pClickPoint = ClientToScreen(ev.GetPosition());
00068 #ifndef __WINDOWS__
00069                 //EnableCellEditControl(true);
00070 #endif
00071         }
00072         // hack to prevent selection from being lost when click combobox
00073         if (ev.GetCol() == 0 && IsInSelection(ev.GetRow(), ev.GetCol()))
00074         {
00075                 m_selTemp = m_selection;
00076                 m_selection = NULL;
00077         }
00078         pEditor->DecRef();
00079         ev.Skip();
00080 }
00081 
00082 #ifdef __WXGTK__
00083 void EzGrid::OnMouseWheel( wxMouseEvent& event )
00084 {
00085     int nWheelRotation = event.GetWheelRotation();
00086 //    int lines = nWheelRotation / event.GetWheelDelta();
00087         int x, y;
00088         GetViewStart(&x, &y);
00089         if (nWheelRotation < 0) y+=5;
00090         else y -= 5;
00091         Scroll(x, y);
00092 }
00093 #endif
00094 
00095 void EzGrid::PreviousState()
00096 {
00097         wxConfigBase *cfg = wxConfigBase::Get();
00098         wxString strCol;
00099         long nColWidth;
00100         for (int nCol = 0; nCol < GetNumberCols(); nCol++)
00101         {
00102                 strCol.Printf(wxT("column%d"), nCol);
00103                 if (cfg->Read(strCol, &nColWidth))
00104                         SetColSize(nCol, nColWidth);
00105         }
00106 }
00107 
00108 wxSize EzGrid::DoGetBestSize() const
00109 {
00110         return wxSize(100, 80);
00111 }
00112 
00113 void EzGrid::SetNumberRows(int nRows)
00114 {
00115         if (GetRows() > 0) DeleteRows(0, GetRows());
00116         if (nRows > 0) AppendRows(nRows);
00117 }
00118 
00119 void EzGrid::RecalcRowLabel()
00120 {
00121         wxFont font = GetLabelFont();
00122         int nWidth = 0;
00123         int nHeight = 0;
00124         GetTextExtent(wxString::Format(wxT("%d"), GetRows()),
00125                                                                 &nWidth, &nHeight, NULL, NULL, &font);
00126         if (nWidth < 12) nWidth = 12;
00127         SetRowLabelSize(nWidth+6);
00128 //      SetRowLabelSize(0);
00129 }
00130 
00131 
00132 void EzGrid::UpdateNumRows()
00133 {
00134         m_numRows = m_table->GetNumberRows();
00135         m_numCols = m_table->GetNumberCols();
00136 }
00137 
00138 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines