Membres inscrits :598
Membres en ligne : 0
Invités en ligne : 5


|
| Menu Snippets (navigation): |
| Détails du snippet : [wxSheet] "Un expander" pour la Scroll-Bar |
| Informations sur l'auteur de ce snippet : | |
|
Hors ligne
| mick009 (Membre)
Inscrit le : 03-04-2008
Messages: 122
Snippets: 3
Tutoriels: 0
|
| Introduction / Description : | |
Ce code permet d'avoir un wxSheet qui quand on monte ou quand on descend, les rows et cols se détruisent pour prendre déjà moins de mémoire (même si cela en prend pas beaucoup) et deuxièmement, pour avoir un wxSheet qui s'étend vers l'infini ^^
Attention : le code est assez long et compliqué !
Alors dans le header de votre classe (qui dérive de wxSheet), vous créez une énumération, des méthodes et des attributs :
Code Cpp:enum MoveUtilisateur{ MoveCol, MoveRow }; ... /* Méthodes pour la scroolbar */ void ScrollEventDown(wxScrollEvent &event); void ScrollEventUp(wxScrollEvent &event); void KeyEvent(wxKeyEvent& event); void MoveDown(MoveUtilisateur MoveDirection, int nbr_move = 1); void MoveUp(MoveUtilisateur MoveDirection); wxArraySheetCoords m_array_sheet_coords; wxArrayString m_array_sheet_value; wxArraySheetCellAttr m_array_sheet_attr; Dans l'implémentation, voici ce qui devrait y avoir :
Code Cpp:/* Obtient les mouvements (bas) de la scrollbar */ void Grid::ScrollEventDown(wxScrollEvent &event){ event.Skip(); if(event.GetOrientation() == wxVERTICAL) MoveDown(MoveRow); else MoveDown(MoveCol); } /* Obtient les mouvements (haut) de la scrollbar */ void Grid::ScrollEventUp(wxScrollEvent &event){ event.Skip(); if(event.GetOrientation() == wxVERTICAL) MoveUp(MoveRow); else MoveUp(MoveCol); } /* Obtient les touches activées du clavier */ void Grid::KeyEvent(wxKeyEvent& event){ event.Skip(); int keyPressed = event.GetKeyCode(); switch(keyPressed){ case WXK_PAGEDOWN: MoveDown(MoveRow, 10); break; case WXK_DOWN: MoveDown(MoveRow); break; case WXK_PAGEUP: MoveUp(MoveRow, 10); break; case WXK_UP: MoveUp(MoveRow); break; case WXK_LEFT: MoveUp(MoveCol); break; case WXK_RIGHT: MoveDown(MoveCol); break; } } /* Bouge vers le bas */ void Grid::MoveDown(MoveUtilisateur MoveDirection, int nbr_move){ /* Création et assignation des variables */ wxArraySheetCoords ArrayScreen = GetVisibleGridCellsBlock().GetArrayCoords(); wxSheetCoords LastsCoords = ArrayScreen.Item(ArrayScreen.GetCount() - 1); wxSheetCoords Coords; if(MoveDirection == MoveRow && LastsCoords.GetRow()-nbr_move == GetNumberRows()-nbr_move-1){ InsertRows(GetNumberRows(), nbr_move); Coords.SetRow(GetNumberRows()-1); /* Boucle pour lire la nouvelle ligne entière */ for(int i = 0 ; i < GetNumberCols() ; i++){ Coords.SetCol(i); for(int y = 0 ; y < m_array_sheet_coords.GetCount() ; y++){ if(m_array_sheet_coords.Item(y) == Coords){ SetCellValue(Coords, m_array_sheet_value.Item(y)); SetAttr(Coords, m_array_sheet_attr.Item(y), wxSHEET_AttrCell); m_array_sheet_coords.RemoveAt(y); m_array_sheet_value.RemoveAt(y); m_array_sheet_attr.RemoveAt(y); } } } ForceRefresh(); } else if(MoveDirection == MoveCol && LastsCoords.GetCol()-5 == GetNumberCols()-6){ InsertCols(GetNumberCols(), nbr_move); ForceRefresh(); } } /* Bouge vers le haut */ void Grid::MoveUp(MoveUtilisateur MoveDirection){ wxSheetCoords Coords; /* Si on monte en vertical */ if(MoveDirection == MoveRow && GetNumberRows() > m_min_rows){ /* Lecture des cellules des lignes à supprimer */ int i = GetNumberRows(); int lim; if(GetGridCursorCell().GetRow() > m_min_rows) lim = GetGridCursorCell().GetRow(); else lim = m_min_rows; while(i > lim){ Coords.SetRow(i-1); for(int y = 0 ; y < GetNumberCols() ; y++){ Coords.SetCol(y); if(GetGridCellAttr(Coords) != GetDefaultGridCellAttr()){ m_array_sheet_coords.Add(Coords); m_array_sheet_value.Add(GetCellValue(Coords)); m_array_sheet_attr.Add(GetGridCellAttr(Coords)); } } DeleteRows(i-1, 1); i--; } } else if(MoveDirection == MoveCol && GetNumberCols() > m_min_cols){ /* Lecture des cellules de la ligne à supprimer */ Coords.SetCol(GetNumberCols()); for(int i = 0 ; i < GetNumberRows() ; i++){ Coords.SetRow(i); if(GetGridCellAttr(Coords) != GetDefaultGridCellAttr()){ m_array_sheet_coords.Add(Coords); m_array_sheet_value.Add(GetCellValue(Coords)); m_array_sheet_attr.Add(GetGridCellAttr(Coords)); } } DeleteCols(GetNumberCols()-1, 1); } Refresh(true); } /* Declaration des signaux */ BEGIN_EVENT_TABLE(Grid, wxSheet) EVT_COMMAND_SCROLL_LINEDOWN(wxSheet::ID_VERT_SCROLLBAR, Grid::ScrollEventDown) EVT_COMMAND_SCROLL_LINEDOWN(wxSheet::ID_HORIZ_SCROLLBAR, Grid::ScrollEventDown) EVT_COMMAND_SCROLL_LINEUP(wxSheet::ID_VERT_SCROLLBAR, Grid::ScrollEventUp) EVT_COMMAND_SCROLL_LINEUP(wxSheet::ID_HORIZ_SCROLLBAR, Grid::ScrollEventUp) EVT_CHAR(Grid::KeyEvent) END_EVENT_TABLE()
Ceci n'est peut-être pas la meilleure solution, mais c'en est une ! Si vous avez des améliorations à me proposez, je les écouterais
Il n'y a pas encore de commentaire pour ce snippet.
| Menu Snippets (navigation): |
|