From 63e7d518bc2868df728191b483c0e2cc81c8d1f6 Mon Sep 17 00:00:00 2001 From: Fabien Bodard Date: Sat, 17 Dec 2011 20:25:27 +0000 Subject: [PATCH] [GB.REPORT] * NEW: ReportVPanel widget and arrange.Column arrange controls in columns * BUG: Layout now correctly reset dataindex git-svn-id: svn://localhost/gambas/trunk@4282 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- comp/src/gb.report/.info | 48 ++--- comp/src/gb.report/.list | 2 +- comp/src/gb.report/.src/Arrange.class | 1 + comp/src/gb.report/.src/ReportContainer.class | 174 +++++++++++++++++- .../gb.report/.src/ReportDrawingArea.class | 2 +- comp/src/gb.report/.src/ReportPanel.class | 2 +- comp/src/gb.report/.src/ReportVPanel.class | 18 ++ comp/src/gb.report/.src/Tests/Report8.class | 11 +- comp/src/gb.report/.src/Tests/Report8.report | 32 +++- comp/src/gb.report/img/control/vpanel.png | Bin 0 -> 293 bytes 10 files changed, 243 insertions(+), 47 deletions(-) create mode 100644 comp/src/gb.report/.src/ReportVPanel.class create mode 100644 comp/src/gb.report/img/control/vpanel.png diff --git a/comp/src/gb.report/.info b/comp/src/gb.report/.info index c3786c878..3fe617c0e 100644 --- a/comp/src/gb.report/.info +++ b/comp/src/gb.report/.info @@ -64,6 +64,10 @@ Vertical C i 2 +Column +C +i +4 Fill C i @@ -733,29 +737,6 @@ _GetActualBrush m PaintBrush (X1)i(Y1)i(X2)i(Y2)i -#ReportDrawingArea -ReportFrame -C -:Draw -: - - -_Properties -C -s -* -_Similar -C -s -ReportImage -_DefaultEvent -C -s -Draw -_Paint -m - -(Page)i(X)f(Y)f(hControl)TControl;(VirtualId)i #ReportFrame ReportControl @@ -1016,7 +997,7 @@ C _Properties C s -*,Arrangement{Arrange.None;Vertical;Horizontal;Fill}=Vertical +*,Arrangement{Arrange.None;Vertical;Horizontal;Column;Fill}=Vertical _Similar C s @@ -1125,6 +1106,25 @@ _Free m +#ReportVPanel +ReportContainer +C +_Properties +C +s +* +_Similar +C +s +ReportVBox +_new +m + + +_Free +m + + #_ReportBorderSide C diff --git a/comp/src/gb.report/.list b/comp/src/gb.report/.list index d4b903b61..740351ad1 100644 --- a/comp/src/gb.report/.list +++ b/comp/src/gb.report/.list @@ -7,7 +7,6 @@ ReportBorder ReportBrush ReportContainer ReportControl -ReportDrawingArea ReportFrame ReportHBox ReportImage @@ -19,4 +18,5 @@ ReportSection ReportSvgImage ReportTextLabel ReportVBox +ReportVPanel _ReportBorderSide diff --git a/comp/src/gb.report/.src/Arrange.class b/comp/src/gb.report/.src/Arrange.class index 7dc837abd..1090a9e1f 100644 --- a/comp/src/gb.report/.src/Arrange.class +++ b/comp/src/gb.report/.src/Arrange.class @@ -5,4 +5,5 @@ Export Optional Public Const {None} As Integer = 0 Public Const {Horizontal} As Integer = 1 Public Const {Vertical} As Integer = 2 +Public Const {Column} As Integer = 4 Public Const {Fill} As Integer = 5 diff --git a/comp/src/gb.report/.src/ReportContainer.class b/comp/src/gb.report/.src/ReportContainer.class index 8235d7c9b..f83e952b5 100644 --- a/comp/src/gb.report/.src/ReportContainer.class +++ b/comp/src/gb.report/.src/ReportContainer.class @@ -275,10 +275,10 @@ Public Sub _GetSizeHints(AvailableW As Float, AvailableH As Float, TotalWidth As Case Arrange.Vertical Return GetVSizeInt(AvailableW, AvailableH, TotalWidth, TotalHeight) - Case Arrange.Horizontal Return GetHSizeInt(AvailableW, AvailableH, TotalWidth, TotalHeight) - + Case Arrange.Column + Return GetCSizeInt(AvailableW, AvailableH, TotalWidth, TotalHeight) Case Arrange.Fill, Arrange.None Return Super._GetSizeHints(AvailableW, AvailableH, TotalWidth, TotalHeight) 'hMyHints.Height = AvailableH @@ -388,6 +388,27 @@ Private Function GetVSizeInt(AvailableW As Float, AvailableH As Float, TotalWidt End +Private Function GetCSizeInt(AvailableW As Float, AvailableH As Float, TotalWidth As Float, TotalHeight As Float) As TSizeHint + + Dim hSizeInt As New TSizeHint + Dim htmpInts As TSizeHint + Dim hChild As ReportControl ''Enfants + Dim fHeight, fSpacing, fWidth As Float + Dim i, j As Integer + Dim bExitLoop As Boolean + + 'D'abord utiliser la méthode du controle pour définir la taille + hSizeInt = Super._GetSizeHints(AvailableW, AvailableH, TotalWidth, TotalHeight) + + 'On ne peut pas dépasser la taille disponible (report sur prochaine page) + hSizeInt.Height = Min(hSizeInt.Height, AvailableH) + + Me._SizeInt = hSizeInt + + Return hSizeInt + +End + Public Function _GetData(sKey As String) As Variant If $bDataIsResult Then @@ -438,6 +459,7 @@ Public Sub _Reset() Dim hChild As ReportControl Me._CurItem = 0 + Me._DataIndex = 0 Me._PageChildren.Clear For Each hChild In Me.Children @@ -457,6 +479,8 @@ Public Sub _SetChildGeometry(X As Float, Y As Float, W As Float, H As Float, Con SetVChildGeometry(X, Y, W, H, ContPage, bInFixed) Case Arrange.Horizontal SetHChildGeometry(X, Y, W, H, ContPage, bInFixed) + Case Arrange.Column + SetCChildGeometry(X, Y, W, H, ContPage, bInFixed) Case Arrange.Fill SetFChildGeometry(X, Y, W, H, ContPage, bInFixed) Case Arrange.None @@ -465,6 +489,142 @@ Public Sub _SetChildGeometry(X As Float, Y As Float, W As Float, H As Float, Con End +Private Sub SetCChildGeometry(X As Float, Y As Float, W As Float, H As Float, ContPage As Integer, bInFixed As Boolean) + + Dim aPageItems As New TControl[] ''Éléments contenu par cette page + Dim aPageColumns As New TControl[][] + Dim aPageColumn As New TControl[] + Dim aColX As New Float[] + Dim hChildHints As TSizeHint ''Besoins en hauteur/largeur de l'enfant + Dim hChild As ReportControl ''Un enfant reportcontrol + Dim oChild As Object + Dim TH, fHeight, fSpc As Float + Dim fExp As Float + Dim iNExp As Integer + Dim O As Object + Dim i, j, k As Integer + Dim hTItem As TControl + 'Dim bPass As Boolean + Dim fX, fY, fTmpY As Float + Dim bExitLoop As Boolean + Dim AllowNextCol As Boolean + Dim fNextColStartPos, fCurColX As Float + + 'Initialisation des variables + fSpc = IIf(Me._RelativeSpacing, H * Me._Spacing / 100, Me._Spacing) 'ME._Spacing + 'On retire les marges a la hauteur et les bordures + H = H - Me.Padding._Top - Me.Padding._Bottom - Me.Border._Top - Me.Border._Bottom + 'on retire a la largeur les paddings (et les bordure ?) + W = W - Me.Padding._Left - Me.Padding._Right - Me.Border._Left - Me.Border._Right + + 'On positionne le curseur de position au coin a gauche + X = Me.Padding._Left + Me.Border._Left + Y = Me.Padding._Top + Me.Border._Top + + 'On initialise la hauteur total avec la hauteur disponible + TH = H + fCurColX = X + + 'On va retirer a la hauteur totale les éléments fixes + For i = Me._CurItem To Me.Children.Max + hChild = Me.Children[i] + For j = hchild._DataIndex To hchild._Count - 1 + hChildHints = hChild._GetSizeHints(W, TH, W, H) + hTItem = New TControl + hTItem.Ctrl = hChild + hTItem.SizeHint = hChildHints + ' Je cherche l'élément le plus large pour définir la position de la colonne suivante + If fNextColStartPos < fCurColX + hChildHints.Width Then fNextColStartPos = fCurColX + hChildHints.Width + 'Si un des éléments de colonne dépasse la largeur et qu'il n'est pas dans la première colonne + 'alors on annule toute la colonne + If fNextColStartPos > X + W Then + hchild._DataIndex = k + bExitLoop = True + 'Print "trop large", fNextColStartPos, X + W + Break + Endif + 'si on arrive en bas du container alor on change de colonne + If TH - hChildHints.Height < 0 Then + 'Print TH - hChildHints.Height + aPageColumns.Add(aPageColumn) + aColX.Add(fCurColX) + aPageColumn = New TControl[] + fCurColX = fNextColStartPos + fspc + k = j + TH = H + Endif + TH = TH - hChildHints.Height - fspc + hTItem.Index = j + aPageColumn.Add(hTItem) + + 'On l'ajoute a la page + Next + 'Print j & "/" & hchild._Count + 'Print Me._CurItem & "/" & Me.Children.Max + + If bExitLoop Then Break + Inc Me._CurItem + + Next + If Not bExitLoop Then + aColX.Add(fCurColX) + aPageColumns.Add(aPageColumn) + Endif + + 'On va mettre en page a présent + 'On définit la taille des éléments étendus + If iNexp Then + fExp = (TH + fExp) / iNexp + Endif + i = 0 + For Each aPageColumn In aPageColumns + fTmpY = Y + For Each hTItem In aPageColumn + + oChild = hTItem.Ctrl + 'Si l'élément est étendu on lui applique la taille répartie + If oChild.Expand And Not oChild.Ignore Then + 'If Me.Tag = "*" Then Stop + fHeight = fExp + Else + 'sinon il maintien sa taille + fHeight = hTItem.SizeHint.Height + Endif + + 'Print Object.Type(hChild) & " " & fHeight + If Not oChild.Ignore Then + hTItem._SetGeometry(aColX[i], fTmpY, hTItem.SizeHint.Width, fHeight) + + oChild._SetChildGeometry(aColX[i], fTmpY, hTItem.SizeHint.Width, fHeight, ContPage, bInFixed Or Me.Fixed) + fTmpY += fHeight + fspc + Else + fX = X + IIf(oChild._RelativeLeft, W * oChild._Left / 100, oChild._Left) + fY = Y + IIf(oChild._RelativeTop, H * oChild._Top / 100, oChild._Top) + hTItem._SetGeometry(fX, fY, hTItem.SizeHint.Width, fHeight) + oChild._SetChildGeometry(fX, fY, hTItem.SizeHint.Width, fHeight, ContPage, bInFixed Or Me.Fixed) + Endif + + If oChild Is ReportContainer Then + + If oChild._CurItem <= oChild.Children.max Then + 'Print "il reste des éléments dans " & oChild.Tag & " a la page " & ContPage + 'Print ochild.Children.max - ochild._CurItem + j = Me.Children.Find(oChild) + Me._CurItem = Min(Me._CurItem, j) + Endif + + Endif + + Next + Inc i + aPageItems.Insert(aPageColumn) + Next + 'Fin du processus + 'On ajoute cette page au dossier du conteneur + Me._PageChildren[ContPage] = aPageItems + +End + Private Sub SetVChildGeometry(X As Float, Y As Float, W As Float, H As Float, ContPage As Integer, bInFixed As Boolean) Dim aPageItems As New TControl[] ''Éléments contenu par cette page @@ -481,11 +641,6 @@ Private Sub SetVChildGeometry(X As Float, Y As Float, W As Float, H As Float, Co Dim fX, fY, fTmpY As Float Dim bExitLoop As Boolean - ' If Me.Tag = "*" Then - ' Print H - ' Stop - ' Endif - 'If Me.tag = "Contenu1" Then Print "H= " & H 'Initialisation des variables fSpc = IIf(Me._RelativeSpacing, H * Me._Spacing / 100, Me._Spacing) 'ME._Spacing 'On retire les marges a la hauteur et les bordures @@ -499,14 +654,13 @@ Private Sub SetVChildGeometry(X As Float, Y As Float, W As Float, H As Float, Co 'On initialise la hauteur total avec la hauteur disponible TH = H - 'If Me.Tag = "Contenu1" Then Print TH + 'On va retirer a la hauteur totale les éléments fixes - 'If Me.Tag = "ListeElements" Then Stop For i = 0 To Me.Children.Max hChild = Me.Children[i] If hChild.Fixed Then hChildHints = hChild._GetSizeHints(W, TH, W, H) - 'Print "Ajout de :" & Object.Type(hChild) + 'si l'index courant est inférieur a l'objet en cour du conteneur alors 'on l'ajoute a la page et on incrémente la place des objet étendu si il est étendu diff --git a/comp/src/gb.report/.src/ReportDrawingArea.class b/comp/src/gb.report/.src/ReportDrawingArea.class index 827783f0f..523ad4bd5 100644 --- a/comp/src/gb.report/.src/ReportDrawingArea.class +++ b/comp/src/gb.report/.src/ReportDrawingArea.class @@ -1,6 +1,6 @@ ' Gambas class file -Export +'Export Inherits ReportFrame Event Draw diff --git a/comp/src/gb.report/.src/ReportPanel.class b/comp/src/gb.report/.src/ReportPanel.class index ff2ce7cee..d05ebd325 100644 --- a/comp/src/gb.report/.src/ReportPanel.class +++ b/comp/src/gb.report/.src/ReportPanel.class @@ -2,7 +2,7 @@ Export Inherits ReportContainer -Public Const _Properties As String = "*,Arrangement{Arrange.None;Vertical;Horizontal;Fill}=Vertical" +Public Const _Properties As String = "*,Arrangement{Arrange.None;Vertical;Horizontal;Column;Fill}=Vertical" Public Const _Similar As String = "ReportVBox" Property Arrangement As Integer diff --git a/comp/src/gb.report/.src/ReportVPanel.class b/comp/src/gb.report/.src/ReportVPanel.class new file mode 100644 index 000000000..42ac7f47c --- /dev/null +++ b/comp/src/gb.report/.src/ReportVPanel.class @@ -0,0 +1,18 @@ +' Gambas class file + +Export +Inherits ReportContainer +Public Const _Properties As String = "*" +Public Const _Similar As String = "ReportVBox" + +Public Sub _new() + + Super._Arrangement = Arrange.Column + +End + +Public Sub _Free() + + Super._Free + +End \ No newline at end of file diff --git a/comp/src/gb.report/.src/Tests/Report8.class b/comp/src/gb.report/.src/Tests/Report8.class index 09789ab2d..7ef01eab7 100644 --- a/comp/src/gb.report/.src/Tests/Report8.class +++ b/comp/src/gb.report/.src/Tests/Report8.class @@ -1,7 +1,16 @@ ' Gambas class file Public Sub _new() + 'Report.Debug = True - Report.Debug = True + ReportHBox1.DataCount = 52 + ReportHBox1.Border.RoundCorner.TopRight = "5mm/5mm" + 'ReportHBox1.Border.RoundCorner.BottomRight = "5mm/5mm" + +End + +Public Sub ReportLabel1_Data() + + Last.data = "Salut Benoit " & Last.DataIndex End diff --git a/comp/src/gb.report/.src/Tests/Report8.report b/comp/src/gb.report/.src/Tests/Report8.report index 226eedc6d..f5156e92e 100644 --- a/comp/src/gb.report/.src/Tests/Report8.report +++ b/comp/src/gb.report/.src/Tests/Report8.report @@ -4,15 +4,29 @@ #MoveScaled(0,0,64,64) Index = 0 Text = ("") - { ReportLabel1 ReportLabel - #MoveScaled(4,9,62,4) - Width = "8cm" - Font = Font["+5"] - Padding = ReportPadding["Top:7mm;Bottom:7mm;Left:7mm;Right:7mm"] - AutoResize = True - Text = ("Salut Benoit") - Alignment = Align.Center - Rotate = 25 + { ReportPanel1 ReportVPanel + #MoveScaled(3,6,64,49) + Padding = ReportPadding["Top:4mm;Bottom:4mm;Left:4mm;Right:4mm"] + Expand = True + Spacing = "7mm" + { ReportHBox1 ReportHBox + #MoveScaled(0,0,64,8) + Width = "2cm" + Height = "2cm" + AutoResize = True + Border = ReportBorder["Top:1mm #000000;Bottom:1mm #000000;Left:1mm #000000;Right:1mm #000000"] + Background = ReportBrush["LinearGradient(0,0,1,1,[#3F1D00,#FF7F00],[0,1])"] + { ReportLabel1 ReportLabel + #MoveScaled(1,2,62,4) + Brush = ReportBrush["#FFFF00"] + Font = Font["+5"] + Padding = ReportPadding["Top:3mm;Bottom:3mm;Left:3mm;Right:3mm"] + Expand = True + AutoResize = True + Alignment = Align.Center + Rotate = 45 + } + } } Index = 0 } diff --git a/comp/src/gb.report/img/control/vpanel.png b/comp/src/gb.report/img/control/vpanel.png new file mode 100644 index 0000000000000000000000000000000000000000..f68a5eff22e54d47c968b16fff3455205a8c6b6c GIT binary patch literal 293 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Y)RhkE)4%c zaKYZ?lYt_f1s;*b3=G`DAk4@xYmNj^kiEpy*OmPSryPf|__rg+3xGmPJzX3_A`ZWu zevs>c0*~|ThxP00=iP1dSo&(py9)>O^sbq6&um&XMdPmd6BdS-)0b#@dd-~qMU<&w zf(XO=h>bqhV%uLu1f-_^F5CK$HQ;KQG}|l>o!{EAY7WQm)Y`w!XI!TCR;rw_tY+o& z_uCF=83p7Veb0PGXWxVUDiQw~42lm_+x>Vw;gk%=$;MyqQ!OW0PI%sE!=J*J!q>C) i!2*Fg>pl_BN`^^pXIjOIrtbqfn8DN4&t;ucLK6UO&2A(B literal 0 HcmV?d00001