--- lib/TWiki/Plugins/EditTablePlugin/Core.pm.orig 2007-02-21 11:12:53.000000000 +0000 +++ lib/TWiki/Plugins/EditTablePlugin/Core.pm 2007-02-21 11:21:52.000000000 +0000 @@ -22,7 +22,7 @@ use Assert; use vars qw( - $preSp %params @format @formatExpanded + $preSp %params @format @formatExpanded $rcCellFormat $rcCellFormatExpanded $prefsInitialized $prefCHANGEROWS $prefEDITBUTTON $prefQUIETSAVE $nrCols $encodeStart $encodeEnd $table $query @@ -182,6 +182,11 @@ $tmp =~ s/\s*\|*\s*$//o; $$theHashRef{'format'} = $tmp if( $tmp ); + $tmp = &TWiki::Func::extractNameValuePair( $theArgs, "cells" ); + $tmp =~ s/^\s*\|*\s*//o; + $tmp =~ s/\s*\|*\s*$//o; + $$theHashRef{"rccellformat"} = $tmp if( $tmp ); + $tmp = TWiki::Func::extractNameValuePair( $theArgs, 'changerows' ); $$theHashRef{'changerows'} = $tmp if( $tmp ); @@ -214,6 +219,62 @@ return @aFormat; } +sub parseRCCellFormat +{ + my( $theFormat, $theTopic, $theWeb, $doExpand ) = @_; + + $theFormat =~ s/\$nop(\(\))?//gos; # remove filler + $theFormat =~ s/\$quot(\(\))?/\"/gos; # expand double quote + $theFormat =~ s/\$percnt(\(\))?/\%/gos; # expand percent + $theFormat =~ s/\$dollar(\(\))?/\$/gos; # expand dollar + if( $doExpand ) { + # expanded form to be able to use %-vars in format + $theFormat =~ s///gos; + $theFormat = TWiki::Func::expandCommonVariables( $theFormat, $theTopic, $theWeb ); + } + my $cFormat = {}; + foreach my $cellFormat (split( /\s*\|\s*/, $theFormat )) { + if ($cellFormat =~ m/^\s*[0-9]+\s*x\s*[0-9]+\s*,/) { + # x format + my ($row,$col,$format) = ($cellFormat =~ m/^\s*([0-9]+)\s*x\s*([0-9]+)\s*,(.*)/); + $cFormat->{$row} = {} if not exists $cFormat->{$row}; + $cFormat->{$row}->{$col-1} = $format; + } elsif ($cellFormat =~ m/^\s*R[0-9]+:C[0-9]+\s*,/i) { + # R:C format + my ($row,$col,$format) = ($cellFormat =~ m/^\s*R([0-9]+):C([0-9]+)\s*,(.*)/); + $cFormat->{$row} = {} if not exists $cFormat->{$row}; + $cFormat->{$row}->{$col-1} = $format; + } elsif ($cellFormat =~ m/^\s*R[0-9]+:C[0-9]+\.\.R[0-9]+:C[0-9]+\s*,/i) { + # R:C..R:C format + my ($row_min,$col_min,$row_max,$col_max,$format) = ($cellFormat =~ m/^\s*R([0-9]+):C([0-9]+)\.\.R([0-9]+):C([0-9]+)\s*,(.*)/); + $cFormat->{range} = [] if not exists $cFormat->{range}; + push @{$cFormat->{range}}, {'row_min'=>$row_min, 'col_min'=>$col_min-1, 'row_max'=>$row_max, 'col_max'=>$col_max-1, 'format'=>$format}; + } + } + + return $cFormat; +} + + +sub findRCCellFormat { + my ($theFormat, $row, $col) = @_; + + return $theFormat->{$row}->{$col} if exists $theFormat->{$row}->{$col}; + + if (exists $theFormat->{range}) { + foreach my $r (@{$theFormat->{range}}) { + if ($row >= $r->{row_min} and + $row <= $r->{row_max} and + $col >= $r->{col_min} and + $col <= $r->{col_max}) { + return $r->{format}; + } + } + } + + return undef; +} + sub handleEditTableTag { my( $theWeb, $theTopic, $thePreSpace, $theArgs ) = @_; @@ -262,6 +323,15 @@ @format = parseFormat( $params{format}, $theTopic, $theWeb, 0 ); @formatExpanded = parseFormat( $params{format}, $theTopic, $theWeb, 1 ); + + if (exists $params{"rccellformat"} and defined $params{"rccellformat"} and $params{"rccellformat"} !~ /^\s$/) { + $rcCellFormat = parseRCCellFormat( $params{"rccellformat"}, $theTopic, $theWeb, 0 ); + $rcCellFormatExpanded = parseRCCellFormat( $params{"rccellformat"}, $theTopic, $theWeb, 1 ); + } else { + $rcCellFormat = {}; + $rcCellFormatExpanded = {} + } + $nrCols = @format; # FIXME: No handling yet of footer @@ -388,8 +458,18 @@ my $text = ''; my $i = @format - 1; $i = $theCol if( $theCol < $i ); - my @bits = split( /,\s*/, $format[$i] ); - my @bitsExpanded = split( /,\s*/, $formatExpanded[$i] ); + my @bits; + my @bitsExpanded; + my $rcBitsFormat = findRCCellFormat($rcCellFormat, $theRowNr, $theCol); + if ($rcBitsFormat) { + # per cell or cell range override + @bits = split( /,\s*/, $rcBitsFormat); + @bitsExpanded = split( /,\s*/, findRCCellFormat($rcCellFormatExpanded, $theRowNr, $theCol)); + } else { + # per column override + @bits = split( /,\s*/, $format[$i] ); + @bitsExpanded = split( /,\s*/, $formatExpanded[$i] ); + } my $cellFormat = ''; $theValue =~ s/\s*%EDITCELL{(.*?)}%/&parseEditCellFormat( $1, $cellFormat )/eo;