Win32::GUI::Grid - add a grid control to Win32::GUI.
use strict; use Win32::GUI; use Win32::GUI::Grid; # main Window my $Window = new Win32::GUI::Window ( -title => "Win32::GUI::Grid", -pos => [100, 100], -size => [400, 400], -name => "Window", ) or die "new Window"; # Grid Window my $Grid = $Window->AddGrid ( -name => "Grid", -pos => [0, 0], -rows => 50, -columns => 10, -fixedrows => 1, -fixedcolumns => 1, -editable => 1, ) or die "new Grid"; # Fill Grid for my $row (0..$Grid->GetRows()) { for my $col (0..$Grid->GetColumns()) { if ($row == 0) { $Grid->SetCellText($row, $col,"Column : $col"); } elsif ($col == 0) { $Grid->SetCellText($row, $col, "Row : $row"); } else { $Grid->SetCellText($row, $col, "Cell : ($row,$col)"); } } } # Resize Grid Cell $Grid->AutoSize(); # Event loop $Window->Show(); Win32::GUI::Dialog(); # Main window event handler sub Window_Terminate { return -1; } sub Window_Resize { my ($width, $height) = ($Window->GetClientRect)[2..3]; $Grid->Resize ($width, $height); } # Grid event handler sub Grid_Click { my ($col, $row) = @_; print "Click on Cell ($col, $row)\n"; }
This package uses the MFC Grid control 2.25 By Chris Maunder. homepage: http://www.codeproject.com/miscctrl/gridctrl.asp
new
Create a new grid control.
Parameter : -name : Window name -parent : Parent window -left : Left position -top : Top position -width : Width -height : Heigth -pos : [x, y] position -size : [w, h] size -visible : Visible -hscroll : Horizontal scroll -vscroll : Vertical scroll -enable : Enable -style : Default style -pushstyle : Push style -popstyle : Pop style -rows : Total rows -columns : Total columns -fixedrows : Fixed rows -fixedcolumns : Fixed columns -editable : Editable -doublebuffer : Double buffering display
Win32::GUI::Window::AddGrid
A Win32::GUI short cut for create a grid. Automaticly, create parent link.
SetRows
Sets the number of rows (including fixed rows), Returning TRUE on success.
GetRows
Returns the number of rows (including fixed rows).
SetColumns
Sets the number of columns (including fixed columns), Returning TRUE on success.
GetColumns
Returns the number of columns (including fixed columns)
SetFixedRows
Sets the number of fixed rows, returning TRUE on success.
GetFixedRows
Returns the number of fixed rows
SetFixedColumns
Sets the number of columns, returning TRUE on success.
GetFixedColumns
Returns the number of fixed columns
SetRowHeight
Sets the height of row nRow.
GetRowHeight
Gets the height of row nRow.
SetColumnWidth
Sets the width of column nCol.
GetColumnWidth
Gets the width of column nCol
GetFixedRowsHeight
Gets the combined height of the fixed rows.
GetFixedColumnsWidth
Gets the combined width of the fixed columns.
GetVirtualHeight
Gets the combined height of all the rows.
GetVirtualWidth
Gets the combined width of all the columns.
GetCellOrigin
Gets the topleft point for cell (nRow,nCol). Cell must be visible for success. Return an [x, y] if successful.
GetCellRect
Gets the bounding rectangle for the given cell. Cell must be visible for success. Return an [left, top, right, bottom] array if successful.
GetTextRect
Gets the bounding rectangle for the text in the given cell. Cell must be visible for success. Return an [left, top, right, bottom] array if successful..
GetTextExtent
Gets the bounding rectangle for the given text for the given cell. Return an [width, height] array if successful.
GetCellTextExtent
Gets the bounding rectangle for the text in the given cell. Return an [width, height] array if successful.
GetCellFromPt
Gets the cell position from the given point. Return an [row, col] if successful.
SetVirtualMode
Sets grid in virtual mode. See _GetData Event for provide data.
GetVirtualMode
Gets virtual mode.
SetImageList
Sets the current image list for the grid. The control only takes a copy of the pointer to the image list, not a copy of the list itself.
GetImageList
Gets the current image list for the grid.
SetGridLines
Sets which (if any) gridlines are displayed.
Possible values. GVL_NONE = No grid lines GVL_HORZ = Horizontal lines only GVL_VERT = Vertical lines only GVL_BOTH = Both vertical and horizontal lines
GetGridLines
Gets which (if any) gridlines are displayed.
SetEditable
Sets if the grid is editable.
IsEditable
Gets whether or not the grid is editable.
SetListMode
Sets the grid into (or out of) List mode. When the grid is in list mode, full row selection is enabled and clicking on the column header will sort the grid by rows.
GetListMode
Get whether or not the grid is in list mode.
SetSingleRowSelection
Sets the grid into (or out of) Single row selection mode. This mode is only effective when in ListMode. When in this mode, only a single row at a time can be selected, so the grid behaves somewhat like a multicolumn listbox.
GetSingleRowSelection
Get whether or not the grid is in single row selection mode.
SetSingleColSelection
Sets the grid into (or out of) Single column selection mode. When in this mode, only a single column at a time can be selected.
GetSingleColSelection
Get whether or not the grid is in single column selection mode.
EnableSelection
Sets whether or not the grid cells can be selected.
IsSelectable
Get whether or not grid cells are selectable.
SetFixedRowSelection
Set whether or not clicking on a fixed row selects the cells next to it.
GetFixedRowSelection
Get whether or not clicking on a fixed row selects the cells next to it.
SetFixedColumnSelection
Set whether or not clicking on a fixed column selects the cells underneath.
GetFixedColumnSelection
Get whether or not clicking on a fixed column selects the cells underneath.
EnableDragAndDrop
Sets whether drag and drop is enabled.
GetDragAndDrop
Get whether drag and drop is allowed.
SetRowResize
Sets whether or not rows can be resized.
GetRowResize
Gets whether or not rows can be resized.
SetColumnResize
Sets whether or not columns can be resized.
GetColumnResize
Gets whether or not columns can be resized.
SetHandleTabKey
Sets whether or not the TAB key is used to move the cell selection.
GetHandleTabKey
Gets whether or not the TAB key is used to move the cell selection.
SetDoubleBuffering
Sets whether or not double buffering is used when painting (avoids flicker).
GetDoubleBuffering
Gets whether or not double buffering is used when painting.
EnableTitleTips
Sets whether or not titletips are used.
GetTitleTips
Gets whether or not titletips are used.
SetTrackFocusCell
Sets whether or not the fixed cells on the same row/column as the current focus cell are highlighted with a sunken border.
GetTrackFocusCell
Gets whether or not the fixed cells on the same row/column as the current focus cell are highlighted with a sunken border.
SetFrameFocusCell
Sets whether or not the cell with the focus is highlighted with a framed border.
GetFrameFocusCell
Gets whether or not the focus cell is highlighted with a framed border.
SetAutoSizeStyle
Sets how the auto-sizing should be performed.
Possible values. GVS_BOTH = use fixed and non fixed cells; GVS_HEADER = use only the fixed cells; GVS_DATA = use only non-fixed cells.
GetAutoSizeStyle
Gets how the auto-sizing should be performed
EnableHiddenColUnhide
Sets whether or not hidden (0-width) columns can be unhidden by the user resizing the column.
GetHiddenColUnhide
Gets whether or not hidden (0-width) columns can be unhidden by the user resizing the column.
void EnableHiddenRowUnhide
Sets whether or not hidden (0-height) rows can be unhidden by the user resizing the row.
GetHiddenRowUnhide
Gets whether or not hidden (0-height) rows can be unhidden by the user resizing the row.
EnableColumnHide
Sets whether or columns can be contracted to 0 width via mouse.
GetColumnHide
Gets whether or not columns can be contracted to 0 width via mouse.
void EnableRowHide
Sets whether or not rows can be contracted to 0 height via mouse.
GetRowHide
SetGridBkColor
Sets the background colour of the control (the area outside fixed and non-fixed cells).
GetGridBkColor
Gets the background colour of the control.
SetGridLineColor
Sets the colour of the gridlines.
GetGridLineColor
Gets the colour of the grid lines.
SetTitleTipBackClr
Sets the background colour of the titletips.
GetTitleTipBackClr
Gets the background colour of the titletips.
SetTitleTipTextClr
Sets the text colour of the titletips.
GetTitleTipTextClr
Gets the text colour of the titletips.
Change and query the default cell implementation for the desired cell type. bFixedRow and bFixedCol specify whether the cell is fixed (in row, column or both) or unfixed. Use this to set default properties for the grid. Actual cells in the grid have their values set as default values when they are first created. They will use GetDefCell to query the grids default cell properties and use these values for drawing themselves.
SetDefCellTextColor
Sets the text colour of the default cell type.
GetDefCellTextColor
Gets the text colour of default cell type.
SetDefCellBackColor
Sets the background colour of the default cell type.
GetDefCellBackColor
SetDefCellWidth
Sets the width of default cell type.
GetDefCellWidth
Gets the width of default cell type.
SetDefCellHeight
Sets the height of default cell type.
GetDefCellHeight
Gets the height of default cell type.
SetDefCellMargin
Sets the Margin of default cell type.
GetDefCellMargin
Gets the Margin of default cell type.
SetDefCellFormat
Sets the format of default cell type.
GetDefCellFormat
Gets the format of default cell type.
SetDefCellStyle
Sets the style of default cell type.
GetDefCellStyle
Gets the style of default cell type.
SetDefCellFont
Sets the font of default cell type.
GetDefCellFont
Gets the font of default cell type.
SetDefCellType
Change default cell type.
Cell type :
GVIT_NUMERIC = Numeric control edit GVIT_DATE = Date control GVIT_DATECAL = Date control with calendar control GVIT_TIME = Time control GVIT_CHECK = Check Box GVIT_COMBO = Combo Box GVIT_LIST = List Box GVIT_URL = Url control
SetCellType
Change cell type.
SetCellCheck
Set check box state. (GVIT_CHECK Only)
GetCellCheck
Get check box state. (GVIT_CHECK Only)
SetCellOptions
Set cells options.
For GVIT_COMBO, GVIT_LIST : An array reference with list of string value (["Option1","Option2"])
For GVIT_CHECK : -checked => 0/1 : Set check.
For GVIT_URL : -autolaunch => 0/1 : Set autolauch mode (default : 1).
SetModified
Sets the modified flag for a cell. If no row or columns is specified, then change affects the entire grid.
GetModified
Gets the modified flag for a cell, or if no cell, it returns the status for the entire grid.
SetCellText
Sets the text for the given cell. Returns TRUE on success
GetCellText
Gets the text for the given cell.
SetCellData
Sets the lParam (user-defined data) field for the given cell. Returns TRUE on success.
GetCellData
Gets the lParam (user-defined data) field for the given cell.
SetCellImage
Sets the image index for the given cell. Returns TRUE on success.
GetCellImage
Gets the image index for the given cell.
SetCellState
Sets the state of the given cell. Returns TRUE on success.
GetCellState
Gets the state of the given cell.
SetCellFormat
Sets the format of the given cell. Returns TRUE on success.
Default implementation of cell drawing uses CDC::DrawText, so any of the DT_* formats are available:
DT_TOP DT_LEFT DT_CENTER DT_RIGHT DT_VCENTER DT_BOTTOM DT_WORDBREAK DT_SINGLELINE DT_EXPANDTABS DT_TABSTOP DT_NOCLIP DT_EXTERNALLEADING DT_CALCRECT DT_NOPREFIX DT_INTERNAL DT_EDITCONTROL DT_PATH_ELLIPSIS DT_END_ELLIPSIS DT_MODIFYSTRING DT_RTLREADING DT_WORD_ELLIPSIS
GetCellFormat
Gets the format of the given cell (default returns a CDC::DrawText DT_* format).
SetCellBkColor
Sets the background colour of the given cell. Returns TRUE on success
GetCellBkColor
Gets the background colour of the given cell.
SetCellColor
Sets the foreground colour of the given cell. Returns TRUE on success.
GetCellColor
Gets the foreground colour of the given cell.
SetCellFont
Sets the font of the given cell. Returns TRUE on success.
GetCellFont
Gets the font of the given cell.
EnsureCellVisible
Ensures that the specified cell is visible.
IsCellVisible
Returns TRUE if the cell is visible.
IsCellSelected
Returns TRUE if the cell is selected
SetCellEditable
Sets the edtitable state of the given cell.
IsCellEditable
Returns TRUE if the cell is editable.
IsCellEditing
Returns TRUE if the cell is currently being edited.
IsCellFixed
Returns TRUE if the cell is a fixed cell.
GetSelectedCount
Gets the number of selected cells.
SetFocusCell
Sets the cell with the focus
GetFocusCell
Gets the cell with the focus.
InsertColumn
Inserts a column at the position given by nCol, or at the end of all columns if nCol is < 0. strHeading is the column heading and nFormat the format. Returns the position of the inserted column.
InsertRow
Inserts a row at the position given by nRow, or at the end of all rows if nRow is < 0. strHeading is the row heading. The format of each cell in the row will be that of the cell in the first row of the same column. Returns the position of the inserted row.
DeleteColumn
Deletes column "nColumn", return TRUE on success.
DeleteRow
Deletes row "nRow", return TRUE on success.
DeleteAllCells
Deletes all rows and contents in the grid.
DeleteNonFixedRows
Deletes all non-fixed rows in the grid.
AutoSizeRow
Auto sizes the row to the size of the largest item. If bResetScroll is TRUE then the scroll bars will be reset.
AutoSizeColumn
Auto sizes the column to the size of the largest item. nAutoSizeStyle sets the way the autosize will occur. If bResetScroll is TRUE then the scroll bars will be reset.
AutoSizing options :
GVS_DEFAULT = default GVS_HEADER = Size using column fixed cells data only GVS_DATA = Size using column non-fixed cells data only GVS_BOTH = Size using column fixed and non-fixed
AutoSizeRows
Auto sizes all rows.
AutoSizeColumns
Auto sizes all columns. nAutoSizeStyle sets the way the autosize will occur.
AutoSize
Auto sizes all rows and columns. nAutoSizeStyle sets the way the autosize will occur.
ExpandColumnsToFit
Expands the column widths to fit the grid area. If bExpandFixed is TRUE then fixed columns will be modified, otherwise they will not be affected.
ExpandLastColumn
Expands the last column width to fill any remaining grid area.
ExpandRowsToFit
Expands the row heights to fit the grid area. If bExpandFixed is TRUE then fixed rows will be modified, otherwise they will not be affected.
ExpandToFit
Expands the rows and columns to fit the grid area. If bExpandFixed is TRUE then fixed cells will be modified, otherwise they will not be affected.
SetRedraw
Stops/starts redraws on things like changing the number of rows and columns and autosizing, but not for user-intervention such as resizes.
RedrawCell
Redraws the given cell. Drawing will be via the hDC if one is supplied.
RedrawRow
Redraws the given row.
RedrawColumn
Redraws the given column.
Refresh
Redraws the entire grid.
GetCellRange
Gets the range of cells for the entire grid. Return an [nMinRow, nMinCol, nMaxRow, nMaxCol] array.
SetSelectedCellRange
Sets the range of selected cells.
GetSelectedCellRange
Gets the range of selected cells. Return an [nMinRow, nMinCol, nMaxRow, nMaxCol] array.
IsValid
Returns TRUE if the given row and column is valid.
GetNextCell
Searches for a cell that has the specified properties and that bears the specified relationship to a given item.
Cell Searching options :
GVNI_FOCUSED = Search for focus cell GVNI_SELECTED = Search for selected cells GVNI_DROPHILITED = Search for drop highlighted cells GVNI_READONLY = Search for read-only cells GVNI_FIXED = Search for fixed cells GVNI_MODIFIED = Search for modified cells GVNI_ABOVE = Search above initial cell GVNI_BELOW = Search below initial cell GVNI_TOLEFT = Search to the left of the initial cell GVNI_TORIGHT = Search to the right of the initial cell GVNI_ALL = Search all cells in the grid starting from the given cell GVNI_AREA = Search all cells below and to the right of the given cell
ClearCells
Clear cell in range.
AutoFill
Auto fill witk blank cell.
SetHeaderSort
Sets whether or not rows are sorted on column header clicks in ListMode.
GetHeaderSort
Gets whether or not rows are sorted on column header clicks in ListMode.
SetSortColumn
Sets the index of the currently sorted column.
GetSortColumn
Gets the index of the currently sorted column.
SetSortAscending
Sets whether the current sort column is sorted ascending.
GetSortAscending
Gets whether the current sort column is sorted ascending.
SortTextCells
Sorts the grid on the given column based on cell text. Returns TRUE on success
SortNumericCells
Sorts the grid on the given column based on cell numeric text. Returns TRUE on success
SortCells
Sort given method and given sort order. Optional a custom sort fonction.
Sort Function sample :
sub { my ($e1, $e2) = @_; return (int($e1) - int ($e2)); }
SetSortFunction
Set or Remove Perl sort function.
If nCol is -1, Set or remove a default sort method. If nCol is a valid column , Set or remove a sort method for this column only.
TODO
Save
TBD
Load
OnEditCut
Copies contents of selected cells to clipboard and deletes the contents of the selected cells. (Ctrl-X)
OnEditCopy
Copies contents of selected cells to clipboard. (Ctrl-C)
OnEditPaste
Pastes the contents of the clipboard to the grid. (Ctrl-V)
OnEditSelectAll
Not actually a clipboard function, but handy nevertheless. This routine selects all cells in the grid. (Ctrl-A)
_Click
Simple left click event.
_RClick
Simple right click event.
_DblClick
Double left click event.
_Changing
Start changing selection event.
_Changed
Selection have change event.
_BeginEdit
Start Cell Edit event. Return non zero value to prevent editing.
_ChangedEdit
ListBox selection change event. str is current selected item. Available with GVIT_COMBO, GVIT_LIST.
_EndEdit
End Cell Edit event. Return non zero value to prevent change.
[virtual Mode Only] str contains edited cell data.
_BeginDrag
Begin drag event.
_GetData
[virtual Mode Only] You must return cell data.
_CacheHint
[virtual Mode Only] Range before request data.
MFC Grid Control by Chris Maunder
Win32::GUI Microsoft Foundation Classes (MFC)
Laurent Rocher (lrocher@cpan.org)
Copyright 2003..2006 by Laurent Rocher (lrocher@cpan.org).
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html
Modified code from the MFC Grid control by Chris Maunder is statically linked into this module. The MFC Grid control is released with the following notice:
This code may be used in compiled form in any way you desire (including commercial use). The code may be redistributed unmodified by any means providing it is not sold for profit without the authors written consent, and providing that this notice and the authors name and all copyright notices remains intact. However, this file and the accompanying source code may not be hosted on a website or bulletin board without the authors written permission. This software is provided "as is" without express or implied warranty. Use it at your own risk! Whilst I have made every effort to remove any undesirable "features", I cannot be held responsible if it causes any damage or loss of time or data.
To install Win32::GUI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::GUI
CPAN shell
perl -MCPAN -e shell install Win32::GUI
For more information on module installation, please visit the detailed CPAN module installation guide.