Update of /cvsroot/perl-win32-gui/Win32-GUI-Grid/samples
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15861/samples

Added Files:
        one.bmp test1.pl test2.pl test3.pl test4.pl test5.pl test6.pl 
        three.bmp two.bmp 
Log Message:
Added to repository

--- NEW FILE: test5.pl ---
#! perl -w
#
# - Custom Cell Type
# - Sort function
#
use strict;
use Win32::GUI;
use Win32::GUI::Grid;

# main Window
my $Window = new Win32::GUI::Window (
    -title    => "Win32::GUI::Grid test 5",
    -pos     => [100, 100],
    -size    => [400, 400],
    -name     => "Window",
) or die "new Window";

# Grid Window
my $Grid = new Win32::GUI::Grid (
    -parent  => $Window,
    -name    => "Grid",
    -pos     => [0, 0],
) or die "new Grid";

# Grid cell base
$Grid->SetDefCellType(GVIT_NUMERIC);  # Preset Cell type before cell creation

# Init Grid
$Grid->SetEditable(1);
$Grid->SetRows(10);
$Grid->SetColumns(10);
$Grid->SetFixedRows(1);
$Grid->SetFixedColumns(1);

# 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->SetCellType($row, $col, GVIT_NUMERIC);  # Set cell type after 
creation.
      $Grid->SetCellText($row, $col, $row*$col);
    }
  }
}

# Set Date edit control in cell (1,1)
$Grid->SetCellText(1, 1, "");
$Grid->SetCellType(1, 1, GVIT_DATE);

# Set Date edit control in cell (1,1)
$Grid->SetCellText(2, 1, "");
$Grid->SetCellType(2, 1, GVIT_DATECAL);

# Set Time edit control in cell (1,2)
$Grid->SetCellText(1, 2, "");
$Grid->SetCellType(1, 2, GVIT_TIME);

# Set Check edit control in cell (1,3)
$Grid->SetCellText(1, 3, "");
$Grid->SetCellType(1, 3, GVIT_CHECK);
$Grid->SetCellCheck(1, 3, 1);
print "Cell Check : ", $Grid->GetCellCheck(1, 3), "\n";

# Set Combobox edit control in cell (1,4)
$Grid->SetCellText(1, 4, "");
$Grid->SetCellType(1, 4, GVIT_COMBO);
$Grid->SetCellOptions(1, 4, ["Option 1", "Option 2", "Option 3"]);

# Set Listbox control in cell (1,5)
$Grid->SetCellText(1, 5, "");
$Grid->SetCellType(1, 5, GVIT_LIST);
$Grid->SetCellOptions(1, 5, ["Option 1", "Option 2", "Option 3"]);

# Set Url control in cell (1,6)
$Grid->SetCellText(1, 6, "www.perl.com");
$Grid->SetCellType(1, 6, GVIT_URL);
$Grid->SetCellOptions(1, 6, -autolaunch => 0);

# Set Url control in cell (2,6)
$Grid->SetCellText(2, 6, "www.perl.com");
$Grid->SetCellType(2, 6, GVIT_URL);
# Set uneditable cell (2,6)
$Grid->SetCellEditable(2, 6, 0);

# Sort Numeric reverse order  (Method 1)
# $Grid->SortNumericCells(5, 0);
# Sort Numeric reverse order (Method 2)
# $Grid->SortCells(5, 0, sub { my ($e1, $e2) = @_; return (int($e1) - int 
($e2)); } );
# Sort Numeric reverse order (Method 3)
# $Grid->SetSortFunction (sub { my ($e1, $e2) = @_; return (int($e1) - int 
($e2)); } );
# $Grid->SortCells(7, 0);
# $Grid->SetSortFunction (); # remove sort method

# 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);
}

sub Grid_BeginEdit {
  my ($col, $row) = @_;
  print "Begin Edit ($col, $row)\n";
}

sub Grid_ChangedEdit {
  my ($col, $row, $str) = @_;
  print "Changed Edit ($col, $row, $str)\n";
}

sub Grid_EndEdit {
  my ($col, $row) = @_;
  print "End Edit ($col, $row)\n";
}

--- NEW FILE: two.bmp ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: test3.pl ---
#! perl -w
# 
# Test Grid method
#   - Default cell setting
#   - font method
#
use strict;
use Win32::GUI;
use Win32::GUI::Grid;

# main Window
my $Window = new Win32::GUI::Window (
    -title    => "Win32::GUI::Grid test 3",
    -pos     => [100, 100],
    -size    => [400, 400],
    -name     => "Window",
) or die "new Window";

# Grid Window
my $Grid = $Window->AddGrid (
    -name    => "Grid",
    -pos     => [0, 0],
) or die "new Grid";

# Image list
my $IL = new Win32::GUI::ImageList(16, 16, 24, 3, 10);
$IL->Add("one.bmp");
$IL->Add("two.bmp");
$IL->Add("three.bmp");

# Attach ImageList to grid
$Grid->SetImageList($IL);

# Set default cell style
$Grid->SetDefCellTextColor(0,0, '#FF0000');
$Grid->SetDefCellTextColor(1,0, '#00FF00');
$Grid->SetDefCellTextColor(0,1, '#0000FF');

$Grid->SetDefCellBackColor(0,0, '#0000FF');
$Grid->SetDefCellBackColor(1,0, '#FF0000');
$Grid->SetDefCellBackColor(0,1, '#00FF00');

$Grid->SetDefCellFormat(0, 0, 
DT_RIGHT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX);
$Grid->SetDefCellFormat(0, 1, 
DT_RIGHT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX);
$Grid->SetDefCellFormat(1, 0, DT_LEFT|DT_WORDBREAK);

# Change default font
my %font = $Grid->GetDefCellFont(0,0);
$font {-bold} = 1;
$font {-height} = 10;
$Grid->SetDefCellFont(0,0, %font);

# Create Cells after set default style. (required for format ONLY)
$Grid->SetRows(50);
$Grid->SetColumns(10);
$Grid->SetFixedRows(1);
$Grid->SetFixedColumns(1);

# Fill Grid
for my $row (0..$Grid->GetRows()) {
  for my $col (0..$Grid->GetColumns()) {
    if ($row == 0) {
      $Grid->SetCellText($row, $col,"Column : $col");
      $Grid->SetCellImage($row, $col, 0); # Add bitmap
    }
    elsif ($col == 0) {
      $Grid->SetCellText($row, $col, "Row : $row");
      $Grid->SetCellImage($row, $col, 1); # Add bitmap
    }
    else {
      $Grid->SetCellText($row, $col, "Cell : ($row,$col)");
      $Grid->SetCellImage($row, $col, 2); # Add bitmap
    }
  }
}

# Set Cell font
$Grid->SetCellFont(0, 0, -name   => 'Arial' ,
                         -size => 12,
                         -italic => 1,
                         -bold => 1);

# Set font from a Win32::GUI::Font
my $F = new Win32::GUI::Font(
        -name => "MS Sans Serif",
        -size => 10,
        -bold => 1,
);
$Grid->SetCellFont(0, 1, $F->Info());

# 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);
}

sub Grid_Click {

 my ($row, $col) = @_;

 # Get font information
 print "\nFont for cell ($row, $col) :\n";
 my %font = $Grid->GetCellFont($row, $col);
 for my $key (keys %font) {
   print $key, " => ", $font{$key}, "\n";
 }

}

--- NEW FILE: test2.pl ---
#! perl -w
# 
# Test Grid method
#   - create option
#   - Color method
#   - ImageList support
#   - Event
#   - POINT, RECT method.

use strict;
use Win32::GUI;
use Win32::GUI::Grid;

# main Window
my $Window = new Win32::GUI::Window (
    -title    => "Win32::GUI::Grid test 2",
    -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";

# Image list
my $IL = new Win32::GUI::ImageList(16, 16, 24, 3, 10);
$IL->Add("one.bmp");
$IL->Add("two.bmp");
$IL->Add("three.bmp");

# Attach ImageList to grid
$Grid->SetImageList($IL);

# Change some color (different color format)
$Grid->SetGridBkColor([66,66,66]);
$Grid->SetGridLineColor('#0000ff');
$Grid->SetTitleTipBackClr('#00ff00');
$Grid->SetDefCellTextColor(0,0, 0x9F9F9F);
$Grid->SetDefCellBackColor(0,0, 0x003300);

# Some test
my ($x, $y) = $Grid->GetCellOrigin(1, 1);
print "CellOrigine(1,1) = ($x, $y)\n";
my ($left, $top, $right, $bottom) = $Grid->GetCellRect(1,1);
print "GetCellRect(1,1) ($left, $top, $right, $bottom)\n";
($left, $top, $right, $bottom) = $Grid->GetTextRect(1,1);
print "GetTextRect(1,1) ($left, $top, $right, $bottom)\n";
($x, $y) = $Grid->GetCellFromPt(85, 50);
print "GetCellFromPt(85,50) = ($x, $y)\n";

# Fill Grid
for my $row (0..$Grid->GetRows()) {
  for my $col (0..$Grid->GetColumns()) {
    if ($row == 0) {
      $Grid->SetCellFormat($row, $col, DT_LEFT|DT_WORDBREAK);
      $Grid->SetCellText($row, $col,"Column : $col");
      $Grid->SetCellImage($row, $col, 0); # Add bitmap
    }
    elsif ($col == 0) {
      $Grid->SetCellFormat($row, $col, 
DT_RIGHT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX);
      $Grid->SetCellText($row, $col, "Row : $row");
      $Grid->SetCellImage($row, $col, 1); # Add bitmap
    }
    else {
      $Grid->SetCellFormat($row, $col, 
DT_RIGHT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX);
      $Grid->SetCellText($row, $col, "Cell : ($row,$col)");
      $Grid->SetCellImage($row, $col, 2); # Add bitmap
    }
  }
}
# Resize Grid Cell
$Grid->AutoSize();

# Some test
($x, $y) = $Grid->GetCellOrigin(1, 1);
print "CellOrigine(1,1) = ($x, $y)\n";
($left, $top, $right, $bottom) =  $Grid->GetCellRect(1,1);
print "GetCellRect(1,1) ($left, $top, $right, $bottom)\n";
($left, $top, $right, $bottom) = $Grid->GetTextRect(1,1);
print "GetTextRect(1,1) ($left, $top, $right, $bottom)\n";
($x, $y) = $Grid->GetCellFromPt(85, 50);
print "GetCellFromPt(85,50) = ($x, $y)\n";

# 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);
}

sub Grid_Click {
  my ($col, $row) = @_;
  print "Click ($col, $row)\n";
}
sub Grid_RClick {
  my ($col, $row) = @_;
  print "Right Click ($col, $row)\n";
}
sub Grid_DblClick {
  my ($col, $row) = @_;
  print "Double Click ($col, $row)\n";
}
sub Grid_Changing {
  my ($col, $row) = @_;
  print "Selection Changing ($col, $row)\n";
}
sub Grid_Changed {
  my ($col, $row) = @_;
  print "Selection Changed ($col, $row)\n";
}
sub Grid_BeginEdit {
  my ($col, $row) = @_;
  print "Begin Edit ($col, $row)\n";
}
sub Grid_EndEdit {
  my ($col, $row) = @_;
  print "End Edit ($col, $row)\n";
}
sub Grid_BeginDrag {
  my ($col, $row) = @_;
  print "Begin Drag ($col, $row)\n";
}

--- NEW FILE: one.bmp ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: test4.pl ---
#! perl -w
#
# Test Grid method
#   - Virtual mode
#   - EndEdit event in virtual mode
#
use strict;
use Win32::GUI;
use Win32::GUI::Grid;

# main Window
my $Window = new Win32::GUI::Window (
    -title    => "Win32::GUI::Grid test 4",
    -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,             # Use create option
    -columns => 10,
    -fixedrows    => 1,
    -fixedcolumns => 1,
    -editable     => 1,
    -virtual      => 1,
) or die "new Grid";

# $Grid->SetVirtualMode(1);   # Set virtual before set rows and columns
# $Grid->SetRows(50);
# $Grid->SetColumns(10);
# $Grid->SetFixedRows(1);
# $Grid->SetFixedColumns(1);
# $Grid->SetEditable(1);

$Grid->SetCellBkColor(2, 2, 0xFF0000);

# 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);
}

# Virtual Grid request data
sub Grid_GetData {
 my ($row, $col) = @_;

 return "Cell ($row, $col)";
}

sub Grid_EndEdit {
  my ($col, $row, $str) = @_;
  print "End Edit ($col, $row) = $str\n";
  return 1;
}

--- NEW FILE: test6.pl ---
#! perl -w
#
# Test multiple Grid instance
# noflicker Win32::GUI support
#
use strict;
use Win32::GUI;
use Win32::GUI::Grid;

# main Window
my $Window = new Win32::GUI::Window (
    -title    => "Win32::GUI::Grid test 6",
    -pos     => [100, 100],
    -size    => [400, 400],
    -name     => "Window",
    -noflicker => 1,
) or die "new Window";

# Grid Window
my $Grid = new Win32::GUI::Grid (
    -parent  => $Window,
    -name    => "Grid",
    -pos     => [0, 0],
    -rows    => 10,
    -columns => 10,
    -fixedrows    => 1,
    -fixedcolumns => 1,
) or die "new Grid";

my $Grid2 = new Win32::GUI::Grid (
    -parent  => $Window,
    -name    => "Grid2",
    -pos     => [0, 0],
    -rows    => 10,
    -columns => 10,
    -fixedrows    => 1,
    -fixedcolumns => 1,
) or die "new Grid2";

# Fill Grid
for my $row (0..$Grid->GetRows()) {
  for my $col (0..$Grid->GetColumns()) {
    if ($row == 0) {
      $Grid->SetCellText($row, $col,"Column : $col");
      $Grid2->SetCellText($row, $col,"Column : $col");
    }
    elsif ($col == 0) {
      $Grid->SetCellText($row, $col, "Row : $row");
      $Grid2->SetCellText($row, $col, "Row : $row");
    }
    else {
      $Grid->SetCellText($row, $col, $row*$col);
      $Grid2->SetCellText($row, $col, $row*$col);
    }
  }
}


# Resize Grid Cell
$Grid->AutoSize();
$Grid2->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/2);
  $Grid2->Move (0, $height/2);
  $Grid2->Resize ($width, $height/2);
}

sub Grid_Click {

 my ($row, $col) = @_;
 print "Grid cell ($row, $col)\n";
}

sub Grid2_Click {

 my ($row, $col) = @_;
 print "Grid2 cell ($row, $col)\n";
}

--- NEW FILE: test1.pl ---
#! perl -w
#
# Test Basic Grid method
#
use strict;
use Win32::GUI;
use Win32::GUI::Grid;

# main Window
my $Window = new Win32::GUI::Window (
    -title    => "Win32::GUI::Grid test 1",
    -pos     => [100, 100],
    -size    => [400, 400],
    -name     => "Window",
) or die "new Window";

# Grid Window
my $Grid = new Win32::GUI::Grid (
    -parent  => $Window,
    -name    => "Grid",
    -pos     => [0, 0],
) or die "new Grid";

# Init Grid
$Grid->SetEditable(1);
$Grid->SetRows(50);
$Grid->SetColumns(10);
$Grid->SetFixedRows(1);
$Grid->SetFixedColumns(1);

# Fill Grid
for my $row (0..$Grid->GetRows()) {
  for my $col (0..$Grid->GetColumns()) {
    if ($row == 0) {
      $Grid->SetCellFormat($row, $col, DT_LEFT|DT_WORDBREAK);
      $Grid->SetCellText($row, $col,"Column : $col");
    }
    elsif ($col == 0) {
      $Grid->SetCellFormat($row, $col, 
DT_RIGHT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX);
      $Grid->SetCellText($row, $col, "Row : $row");
    }
    else {
      $Grid->SetCellFormat($row, $col, 
DT_RIGHT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX);
      $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);
}

--- NEW FILE: three.bmp ---
(This appears to be a binary file; contents omitted.)


Reply via email to