//------------------------------------------------------------------------------ // custom grid implementation //------------------------------------------------------------------------------ CustomGrid::CustomGrid( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style, const wxString &name ) : wxGrid( parent, id, pos, size, style, name ) { //create grid SetTable( new wxGridStringTable(0, 0), true, wxGridSelectRows ); //some general settings EnableEditing( false ); EnableGridLines( true ); EnableDragGridSize( false ); SetMargins( 0, 0 ); EnableDragColMove( false ); EnableDragColSize( false ); EnableDragRowSize( false ); //init rows pref wxFileConfig *pConf = GetOCPNConfigObject(); if (pConf) { pConf->SetPath(_T("/Settings/GRIB")); m_IsDigit = pConf->Read(_T("GribDataTableRowPref"), _T("XXX")); } if( m_IsDigit.Len() != wxString(_T("XXX")).Len() ) m_IsDigit = _T("XXX"); //create structure for all numerical rows for( unsigned int i = 0; i < m_IsDigit.Len(); i++ ){ m_NumRow.push_back(wxNOT_FOUND); m_NumRowVal.push_back(std::vector <double>()); } //init labels attr wxFont labelfont = GetOCPNGUIScaledFont_PlugIn( _T("Dialog") ).MakeBold(); SetLabelFont(labelfont); wxColour colour; GetGlobalColor(_T("DILG0"), &colour); SetLabelBackgroundColour(colour); //set row label size int w; GetTextExtent( _T("Ab"), &w, NULL, 0, 0, &labelfont); double x = (double)w * 6.5; SetRowLabelSize((int)x); //colour settings GetGlobalColor(_T("GREEN1"), &m_greenColour); GetGlobalColor(_T("DILG1"), &m_greyColour); #ifdef __WXOSX__ m_bLeftDown = false; #endif //connect events at dialog level Connect(wxEVT_SCROLLWIN_THUMBTRACK, wxScrollEventHandler( CustomGrid::OnScroll ), NULL, this ); Connect(wxEVT_SIZE, wxSizeEventHandler( CustomGrid::OnResize ), NULL, this ); Connect(wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEventHandler( CustomGrid::OnLabeClick ), NULL, this ); //connect events at grid level GetGridWindow()->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler( CustomGrid::OnMouseEvent ), NULL, this ); GetGridWindow()->Connect(wxEVT_LEFT_UP, wxMouseEventHandler( CustomGrid::OnMouseEvent ), NULL, this ); GetGridWindow()->Connect(wxEVT_MOTION, wxMouseEventHandler( CustomGrid::OnMouseEvent ), NULL, this ); //timer event m_tRefreshTimer.Connect(wxEVT_TIMER, wxTimerEventHandler( CustomGrid::OnRefreshTimer ), NULL, this); }
Grid::Grid(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxGrid(parent, id, pos, size, style | wxWANTS_CHARS, name) { #if wxUSE_ACCESSIBILITY GetGridWindow()->SetAccessible(mAx = safenew GridAx(this)); #endif // RegisterDataType takes ownership of renderer and editor RegisterDataType(GRID_VALUE_TIME, safenew NumericRenderer{ NumericConverter::TIME }, safenew NumericEditor { NumericTextCtrl::TIME, wxT("seconds"), 44100.0 }); RegisterDataType(GRID_VALUE_FREQUENCY, safenew NumericRenderer{ NumericConverter::FREQUENCY }, safenew NumericEditor { NumericTextCtrl::FREQUENCY, wxT("Hz"), 44100.0 }); RegisterDataType(GRID_VALUE_CHOICE, safenew wxGridCellStringRenderer, safenew ChoiceEditor); }
/** ~MemoryGrid * * Destructor */ MemoryGrid::~MemoryGrid() { Disconnect(MemoryMenuBreakpoint, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnBreakpoint)); Disconnect(MemoryMenuTemppoint, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnTemppoint)); Disconnect(MemoryMenuWatchpoint, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnWatchpoint)); Disconnect(MemoryMenuBlackbox, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnBlackbox)); Disconnect(MemoryMenuAdvancedpoint, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnAdvancedpoint)); Disconnect(MemoryMenuPCHere, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnPCHere)); Disconnect(wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler(MemoryGrid::OnContextMenu), NULL, this); Disconnect(wxEVT_GRID_CELL_CHANGED, wxGridEventHandler(MemoryGrid::OnGridChanged), NULL, this); Disconnect(wxEVT_ACTIVATE, wxActivateEventHandler(MemoryGrid::OnActivate), NULL, this); GetGridWindow()->Disconnect(wxEVT_MOTION, wxMouseEventHandler(MemoryGrid::OnMotion), NULL, this); Disconnect(MemoryToolTipTimer, wxEVT_TIMER, wxTimerEventHandler(MemoryGrid::OnShowToolTip), NULL, this); }
wxSize ctlSQLGrid::GetBestSize(int row, int col) { wxSize size; wxGridCellAttr *attr = GetCellAttr(row, col); wxGridCellRenderer *renderer = attr->GetRenderer(this, row, col); if ( renderer ) { wxClientDC dc(GetGridWindow()); size = renderer->GetBestSize(*this, *attr, dc, row, col); renderer->DecRef(); } attr->DecRef(); return size; }
/** MemoryGrid * * Constructor */ MemoryGrid::MemoryGrid(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style) : wxGrid(parent, id, pos, size, style), timer(this, MemoryToolTipTimer) { last_address = 0x3000; highlight = true; SetUseNativeColLabels(); SetDefaultRowSize(12); Connect(MemoryMenuBreakpoint, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnBreakpoint)); Connect(MemoryMenuTemppoint, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnTemppoint)); Connect(MemoryMenuWatchpoint, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnWatchpoint)); Connect(MemoryMenuBlackbox, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnBlackbox)); Connect(MemoryMenuAdvancedpoint, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnAdvancedpoint)); Connect(MemoryMenuPCHere, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MemoryGrid::OnPCHere)); Connect(wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler(MemoryGrid::OnContextMenu), NULL, this); Connect(wxEVT_GRID_CELL_CHANGED, wxGridEventHandler(MemoryGrid::OnGridChanged), NULL, this); Connect(wxEVT_ACTIVATE, wxActivateEventHandler(MemoryGrid::OnActivate), NULL, this); GetGridWindow()->Connect(wxEVT_MOTION, wxMouseEventHandler(MemoryGrid::OnMotion), NULL, this); Connect(MemoryToolTipTimer, wxEVT_TIMER, wxTimerEventHandler(MemoryGrid::OnShowToolTip), NULL, this); }
Grid::Grid(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxGrid(parent, id, pos, size, style | wxWANTS_CHARS, name) { #if wxUSE_ACCESSIBILITY mAx = new GridAx(this); GetGridWindow()->SetAccessible(mAx); #endif RegisterDataType(GRID_VALUE_TIME, new TimeRenderer, new TimeEditor); RegisterDataType(GRID_VALUE_CHOICE, new wxGridCellStringRenderer, new ChoiceEditor); }
void ctlSQLGrid::AutoSizeColumns(bool setAsMin) { wxCoord newSize, oldSize; wxCoord maxSize, totalSize = 0, availSize; int col, nCols = GetNumberCols(); int row, nRows = GetNumberRows(); colMaxSizes.Empty(); /* We need to check each cell's width to choose best. wxGrid::AutoSizeColumns() * is good, but looping through long result sets gives a noticeable slowdown. * Thus we'll check every first 500 cells for each column. */ // First pass: auto-size columns for (col = 0 ; col < nCols; col++) { ColKeySizeHashMap::iterator it = colSizes.find(GetColKeyValue(col)); if (it != colSizes.end()) // Restore user-specified size { newSize = it->second; colMaxSizes.Add(-1); } else { wxClientDC dc(GetGridWindow()); newSize = 0; // get cells's width for (row = 0 ; row < wxMin(nRows, 500) ; row++) { wxSize size = GetBestSize(row, col); if ( size.x > newSize ) newSize = size.x; } // get column's label width wxCoord w, h; dc.SetFont( GetLabelFont() ); dc.GetMultiLineTextExtent( GetColLabelValue(col), &w, &h ); if ( GetColLabelTextOrientation() == wxVERTICAL ) w = h; if ( w > newSize ) newSize = w; if (!newSize) newSize = GetRowLabelSize(); else // leave some space around text newSize += 6; colMaxSizes.Add(newSize); } SetColSize(col, newSize); totalSize += newSize; } availSize = GetClientSize().GetWidth() - GetRowLabelSize(); // Second pass: shrink wide columns if exceeded available width if (totalSize > availSize) { // A wide column shouldn't take up more than 50% of the visible space maxSize = availSize / 2; for (col = 0 ; col < nCols ; col++) { oldSize = GetColSize(col); // Is too wide and no user-specified size if (oldSize > maxSize && !(col < (int)colMaxSizes.GetCount() && colMaxSizes[col] == -1)) { totalSize -= oldSize; /* Shrink wide column to maxSize. * If the rest of the columns are short, make sure to use all the remaining space, * but no more than oldSize (which is enough according to first pass) */ newSize = wxMin(oldSize, wxMax(maxSize, availSize - totalSize)); SetColSize(col, newSize); totalSize += newSize; } } } }