fs-danaus
2023-03-30 665b0603d09890014f982fdfbd6ec47938f504b0
提交 | 用户 | age
25ab64 1 // ---------------------------------------------------------------------------------------------------------------------------
F 2 TGP.ActionSpan = function(){ return 0; } 
3 TGP.ActionSplit = function(){ return 0; } 
4
5 MS.RowSpan;
6 // ---------------------------------------------------------------------------------------------------------------------------
7 TGP.InitRowSpan = function(){
8 this.SpanCols = { };
9 for(var col in this.Cols) if(this.Cols[col].Spanned) this.SpanCols[col] = this.Cols[col];
10 for(var col in this.SpanCols) {
11    this.CreateRowSpan(this.XH,col); 
12    this.CreateRowSpan(this.XF,col); 
13    for(var B = this.XB.firstChild;B;B=B.nextSibling) this.CreateRowSpan(B,col); 
14    }
15 }
16 // ---------------------------------------------------------------------------------------------------------------------------
17 TGP.CreateRowSpan = function(row,col){
c35f05 18 var crs = col+"RowSpan", ccs = col+"Span", ok = 0, r = row.firstChild, C = this.Cols[col], CF = null, cpos = 0, rev = this.ReversedTree, ovr = C.Spanned==2;
25ab64 19 while(r){
F 20    var rs = r[crs]; if(rs==null) rs = r.Def[crs];
21    if(rs>1){
22       ok = 1; 
23       var cs = 1, n = r;
24       if(r.Spanned){ 
25          cs = r[ccs]; if(cs==null) cs = r.Def[ccs];
26          var CN = this.ColNames[C.Sec], pos = C.Pos; 
27          if(this.CPLastSec&&r.Fixed&&C.MainSec==1){
28             if(!CF){ CF = this.GetAllColPages(); for(var i=1;i<C.Sec;i++) cpos += this.ColNames[i].length; }
29             CN = CF; pos += cpos;
30             }
31          if(cs==0) { 
32             if(r[CN[pos-1]+"RowSpan"]==rs) { 
33                while(r&&rs-->=1) r = r.nextSibling; 
34                }
35             else r[crs] = null;   
36             continue; 
37             }  
38          }
39       
c35f05 40       for(var i=1;i<=rs;i++,r=r.nextSibling){ 
F 41          if(!r || r.Spanned && r[ccs]==0) { rs = i-0.5; break; } 
42          if(ovr && r!=n && (r[crs]!=null||r.Def[crs]!=null)) { rs = i-0.5; break; } 
25ab64 43          r.RowSpan = 1; r[crs] = 0; 
F 44          var j = 1; 
45          if(cs>1) { 
46             if(!r.Spanned) { r.Spanned = 1; this.UpdateSpan(r,this.SaveSpan); }
47             r[ccs] = cs; if(this.SaveSpan&&i==1) r[ccs+"Orig"] = cs;
48             for(;j<cs;j++) { r[CN[j+pos]+"RowSpan"] = 0; r[CN[j+pos]+"Span"] = 0; } 
49             }
50          else if(r.Spanned) r[col+"Span"] = 1; 
51          if(r.Spanned) {
52             var CN = this.ColNames[C.Sec], pos = C.Pos;
53             if(this.CPLastSec&&r.Fixed&&C.MainSec==1){
54                if(!CF){ CF = this.GetAllColPages(); for(var i=1;i<C.Sec;i++) cpos += this.ColNames[i].length; }
55                CN = CF; pos += cpos;
56                }
57             while(r[CN[j+pos]+"Span"]==0) r[CN[pos+j++]+"Span"] = 1; 
58             }
59          if(r.firstChild) {
60             if(rev ? i==1||i>=rs+1 : i>=rs) this.CreateRowSpan(r,col); 
61             else this.SetHidden(r,col,cs);
62             }
63          }
64       if(!n.Block || n.Block<rs) n.Block = Math.floor(rs);
65       n[crs] = rs; if(cs>1) for(var j=1;j<cs;j++) n[CN[j+pos]+"RowSpan"] = rs;
66       if(this.SaveSpan) n[crs+"Orig"] = rs;
67       }
68    else {
69       if(r.firstChild) this.CreateRowSpan(r,col);
70       r = r.nextSibling;
71       }
72    }
73 if(ok) {
74    this.LeftTD = 1;
75    this.RowSpan = 1;
76    }
c35f05 77 return ok;
25ab64 78 }
F 79 // -----------------------------------------------------------------------------------------------------------
80 TGP.SetHidden = function(row,col,span,O,rowonly,U){
81 var rp = rowonly?row.parentNode:row; if(rp.Spanned && rp[col+"Span"]==0) return;
82 if(!span) span = 1;
83 var C = this.Cols[col], S = this.ColNames[C.Sec], p = C.Pos;
84 if(this.CPLastSec&&row.Fixed&&C.MainSec==1){ S = this.GetAllColPages(); for(var i=1;i<C.Sec;i++) p += this.ColNames[i].length; }
85 for(var r=rowonly?row:row.firstChild;r;r=r.nextSibling) {
86    if(r.Spanned && r[col+"Span"]==0) { 
87       for(var cc=1;r[S[p-cc]+"Span"]==0;cc++); 
88       if(U) U.push(r.id,S[p-cc]+"Span",cc,r[S[p-cc]+"Span"]);
89       r[S[p-cc]+"Span"] = cc;
90       if(O) O[r.id] = r;
91       }
92    var setblk = null;
93    for(var i=0;i<span;i++) { 
94       if(r.RowSpan) {
95          if(r[S[i+p]+"RowSpan"]!=null && r.firstChild) this.ResetHidden(r,S[i+p],O,null,U);
96          if(U) U.push(r.id,S[i+p]+"RowSpan",null,r[S[i+p]+"RowSpan"]);
97          if(r[S[i+p]+"RowSpan"]!=null) { r[S[i+p]+"RowSpan"] = null; setblk = 1; }   
98          }
99       if(U) U.push(r.id,S[i+p]+"Span",0,r[S[i+p]+"Span"]);
100       r[S[i+p]+"Span"] = 0; 
101       }   
102    if(U) U.push(r.id,col+"Span",span,r[col+"Span"]);
103    r[col+"Span"] = span;
104    if(r[S[i+p]+"Span"]==0){
105       for(;r[S[i+p]+"Span"]==0;i++) { 
106          if(U){ if(r.RowSpan) U.push(r.id,S[i+p]+"RowSpan",null,r[S[i+p]+"RowSpan"]); U.push(r.id,S[i+p]+"Span",1,r[S[i+p]+"Span"]); }
107          if(r.RowSpan) r[S[i+p]+"RowSpan"] = null; r[S[i+p]+"Span"] = 1; 
108          } 
109       if(O) O[r.id] = r;
110       }
111    if(setblk) this.SetRowBlock(r,U);
112    if(r[col+"Visible"]!=-2) {
113       if(U) U.push(r.id,col+"ZalVisible",r[col+"Visible"],r[col+"ZalVisible"]);
114       r[col+"ZalVisible"] = r[col+"Visible"];
115       }
116    if(U) U.push(r.id,col+"Visible",-2,r[col+"Visible"]);
117    r[col+"Visible"] = -2;
118    if(!r.Spanned) { r.Spanned = 1; this.UpdateSpan(r); }
119    if(O) { 
120       if(span>1) O[r.id] = r; 
121       else { this.RefreshCell(r,col); if(U) U.RefreshCell.push(r.id,col); }
122       }
123    if(r.firstChild) this.SetHidden(r,col,span,O,null,U);
124    if(rowonly) break;
125    }
126 }
127 // -----------------------------------------------------------------------------------------------------------
128 TGP.ResetHidden = function(row,col,O,rowonly,U){
129 var C = this.Cols[col], S = this.ColNames[C.Sec], p = C.Pos;
130 if(this.CPLastSec&&row.Fixed&&C.MainSec==1){ S = this.GetAllColPages(); for(var i=1;i<C.Sec;i++) p += this.ColNames[i].length; }
131 for(var r=rowonly?row:row.firstChild;r;r=r.nextSibling) {
132    if(U) U.push(r.id,col+"Visible",r[col+"ZalVisible"],r[col+"Visible"],r.id,col+"ZalVisible",null,r[col+"ZalVisible"]);
133    r[col+"Visible"] = r[col+"ZalVisible"]; r[col+"ZalVisible"] = null;
134    var span = r[col+"Span"];
135    if(span>1) {
136       if(U) for(var i=0;i<span;i++) U.push(r.id,S[i+p]+"Span",1,r[S[i+p]+"Span"]);
137       for(var i=0;i<span;i++) r[S[i+p]+"Span"] = 1;
138       if(O) O[r.id] = r;
139       }
140    else if(O) { this.RefreshCell(r,col); if(U) U.RefreshCell.push(r.id,col); }
141    if(r.firstChild) this.ResetHidden(r,col,O,null,U);
142    if(rowonly) break;
143    }
144 }
145 // -----------------------------------------------------------------------------------------------------------
146 TGP.UpdateRowSpan = function(row,ch){
147 if(!this.RowSpan||!row.RowSpan) return;
c35f05 148 var D = [], MD = null, U = {};
25ab64 149 for(var col in this.SpanCols) if(row[col+"RowSpan"]!=null && row[col+"Span"]!=0) {
F 150    var rs = this.GetSpanRow(row,col), spn = rs[col+"RowSpan"], rv = null, ro = null; 
151    for(var i=1,r=rs,pls=0,ipls=0;i<=spn&&r;i++,r=r.nextSibling){
152       if(!r.Visible) { 
153          if(r.r1&&rv) ipls--; else pls--; 
154          if(!ro && r==row) ro = r;
155          }
156       else {
157          if(i!=spn && r.Hasch && (r.Expanded||BIEA&&!BIE8Strict&&i<=spn-1)) pls++;
158          if(BIEA&&!BIE8Strict&&rv) ipls = 0;
159          if(!rv) rv = r;
160          if(!ro && r!=row) ro = r;
161          }
162       }
163    if(ro!=rv && !ch){ 
164       if(ro && ro!=rs){
165          
166          var vis = ro.Visible; ro.Visible = 1;
167          if(rv) rv.Visible = 0;
168          D[D.length] = this.GetCell(ro,col);
169          if(col==this.MainCol&&!this.HideTree) MD = D[D.length-1];
170          if(rv) rv.Visible = 1; 
171          ro.Visible = vis;
172          }
173       if(rv && rv!=rs) {
174          this.RefreshRow(rv,this.Cols[col].Sec);
175          
176          }
177       }
178    if(rv){
179       var cell = this.GetCell(rv,col);
180       if(cell){
181          spn = Math.floor(spn+pls+ipls);
182          cell.rowSpan = spn;
183          var bcell = cell.nextSibling;
184          if(bcell && bcell.className.indexOf(this.Rtl?"NoRight":"NoLeft")>=0) bcell.rowSpan = spn;
185          if(col==this.MainCol && !this.HideTree && !row.Fixed) cell.previousSibling.rowSpan = spn;
c35f05 186          U[rv.id] = rv;
25ab64 187          }
F 188       }
189    }
c35f05 190 for(var id in U) this.UpdateRowHeight(U[id]);
25ab64 191
F 192 for(var i=0;i<D.length;i++){
193    var cell = D[i]; if(!cell) continue;
194    var par = cell.parentNode;
195    var bcell = cell.nextSibling;
196    if(bcell && bcell.className.indexOf(this.Rtl?"NoRight":"NoLeft")>=0) par.removeChild(bcell);
197    if(cell==MD) par.removeChild(cell.previousSibling);
198    par.removeChild(cell);
199    }
200 }
201 // -----------------------------------------------------------------------------------------------------------
202 TGP.GetSpannedCols = function(col){
203 if(!this.RowSpan) return [];
204 var Spn = [], C = this.Cols[col]; if(!C) return [];
205 var CN = this.ColNames[C.Sec];
206 for(var i=0;i<C.Pos;i++){
207    var c = this.Cols[CN[i]];
208    if(c.Spanned && (c.Visible || c.Hidden)) Spn[Spn.length] = CN[i];
209    }
210 return Spn;   
211 }
212 // -----------------------------------------------------------------------------------------------------------
213 TGP.GetSpanRow = function(row,col,vis){
214 if(row.Spanned && row[col+"Span"]=="0") col = this.GetPrevCol(col,row); 
215 while(row && row[col+"Visible"]==-2) row = row.parentNode;
216 while(row && row[col+"RowSpan"]==0) row = row.previousSibling;
217 if(vis) while(row && !row.Visible) row = row.nextSibling;
218 return row;
219 }
220 // -----------------------------------------------------------------------------------------------------------
221 TGP.GetLastSpanRow = function(row,col,vis){
222 if(row.Spanned && row[col+"Span"]=="0") col = this.GetPrevCol(col,row); 
223 while(row && row[col+"Visible"]==-2) row = row.parentNode;
224 var p = row;
225 if(row && row[col+"RowSpan"]>1) row = row.nextSibling;
226 while(row && row[col+"RowSpan"]==0) row = row.nextSibling;
227 if(p!=row) row = row ? this.GetPrev(row) : this.GetLast(p.parentNode);
228 if(vis) while(row && !row.Visible) row = row.previousSibling;
229 return row;
230 }
231
232 // -----------------------------------------------------------------------------------------------------------
233 TGP.GetSpanCell = function(row,col){
234 var C = this.Cols[col], S = this.ColNames[C.Sec], pos = C.Pos, sec = C.Sec;
235 if(this.CPLastSec&&row.Fixed&&C.MainSec==1){ S = this.GetAllColPages(); pos = null; sec = 1; }
236 while(row[col+"RowSpan"]==0) row = row.previousSibling; 
237 if(!row.Visible && row[col+"RowSpan"]>1){ 
238    for(var r=row.nextSibling;r&&r[col+"RowSpan"]==0&&!r.Visible;r=r.nextSibling);
239    if(!r) return null;
240    if(r.Visible) row = r; 
241    }
242 var  r = row["r"+sec]; if(!r) return null; 
243 if(row.Spanned && row[col+"Span"]==0) { 
244    if(pos==null) { for(var i=1,pos=C.Pos;i<C.Sec;i++) pos += this.ColNames[i].length; } 
245    for(var p=pos-1;p&&row[S[p]+"Span"]==0;p--);
246    col = S[p];
247    }
248 for(var i=0,p=this.LeftTD||sec==1?1:0;i<S.length;i++){
249    var c = S[i], C = this.Cols[c];
250    if(row[c+"RowSpan"]==0) {
251       for(var n=row.previousSibling,hid=0;n[c+"RowSpan"]==0;n=n.previousSibling) if(n.Visible) hid = 1; 
252       if(hid||n.Visible){ 
253          if(row.Spanned) i += row[c+"Span"]-1; 
254          continue;
255          }
256       }
257    if(!C.Visible&&!C.Hidden){ 
258       if(!row.Spanned) continue; 
259       var sp = row[c+"Span"];
260       for(var j=1;j<sp&&!this.Cols[S[i+j]].Visible&&!this.Cols[S[i+j]].Hidden;j++);
261       if(j==sp) {  
262          if(c==col) return null; 
263          i += sp-1;
264          continue; 
265          }
266       
267       }
c35f05 268    else if(c==this.MainCol && !this.HideTree || c==this.Gantt&&this.Cols[c].GanttPageLeft!=null) p++;
25ab64 269    if(row.Spanned) {
F 270       var sp = row[c+"Span"];
271       if(!sp){
272          info("Chyba span "+row.id+","+c+" !!!");
273          return null;
274          }
275       i += sp-1;
276       }
277    if(c==col) return r.cells[p];
278    var bcell = r.cells[p+1];
279    p += bcell && bcell.className.indexOf(this.Rtl?"NoRight":"NoLeft")>=0 ? 2 : 1;
280    }
281 return null; 
282 }
283 // -----------------------------------------------------------------------------------------------------------
284 TGP.GetSpanHeight = function(row,h){
285 if(BIE8Strict && !BIEA9 && BIEVER<=8) return h>this.RowHeight?h:this.RowHeight; 
286 var CC = {}, H = {}, CE = { }, RS = {}, setrs = BIEA&&!BIE;
287 for(var col in this.SpanCols) if((row[col+"RowSpan"] || row[col+"RowSpan"]==0 && this.GetSpanRow(row,col,1)==row) && (!row.Spanned||row[col+"Span"]!=0)) {
288    var cell = this.GetCell(row,col);
289    if(cell) {
290       H[col] = cell.offsetHeight;
291       CC[col] = this.SpanCols[col];
292       CE[col] = cell;
293       if(setrs) RS[col] = cell.rowSpan;
294       }
295    }
296
297 for(var col in CC) if(CE[col].offsetHeight) if(setrs) CE[col].rowSpan = 1; else CE[col].style.display = "none"; 
298 for(var col in CC) {
299    var spn = col+"RowSpan", vis = col+"Visible", hh = 0;
300    for(var r=this.GetNextVisible(row,1);r&&(r[spn]==0||r[vis]==-2);r=this.GetNextVisible(r,1)) if(r.r1) {
301       
302       var hhh = r.r1.offsetHeight;
303       if(r.r0 && r.r0.offsetHeight > hhh) hhh = r.r0.offsetHeight;
304       if(r.r2 && r.r2.offsetHeight > hhh) hhh = r.r2.offsetHeight;
305       hh += hhh;
306       
307       }  
308    hh = H[col]-hh;
309    if(h<hh) h = hh;
310    }
311
312 for(var col in CC) if(setrs) CE[col].rowSpan = RS[col]; else CE[col].style.display = "";
313
314 return h;
315 }
316 // -----------------------------------------------------------------------------------------------------------
317 TGP.RemoveRowSpan = function(rows,O,U){
318 var al = rows.length, X = {}, CF = null, cpos = 0, B = {};
319 if(rows[0].RowSpan){
320    for(var col in this.SpanCols){
321       if(!X[col] && rows[0][col+"RowSpan"]==0){
322          for(var a=1,rs=rows[0].previousSibling;rs&&rs[col+"RowSpan"]==0;rs=rs.previousSibling,a++);
323          var rsp = rs[col+"RowSpan"], sp = rs.Spanned ? rs[col+"Span"] : 1;
324          var apls = a+al<=rsp ? rsp-al : a+rsp-Math.floor(rsp); 
325          if(apls<=1) { apls = null; O[rs.id] = rs; }
326          else if(a+al>=rsp&&rows[0].previousSibling.firstChild) apls += 0.5;
327          var C = this.Cols[col], S = this.ColNames[C.Sec], p = C.Pos;
328          if(this.CPLastSec&&rs.Fixed&&C.MainSec==1){ 
329             if(!CF) { CF = this.GetAllColPages(); for(var i=1;i<C.Sec;i++) cpos += this.ColNames[i].length; } 
330             S = CF; p += cpos;
331             }
332          if(U) for(var i=0;i<sp;i++) U.push(rs.id,S[i+p]+"RowSpan",apls,rs[S[i+p]+"RowSpan"]);
333          for(var i=0;i<sp;i++) { rs[S[i+p]+"RowSpan"] = apls; X[S[i+p]] = 1; }
334          if(apls==null) this.ResetHidden(rs,col,O,null,U);
335          
336          for(var j=0;j<al;j++) {
337             var r = rows[j];
338             
339             if(U) {
340                if(sp>1) { U.push(r.id,col+"Span",1,r[col+"Span"]);  U.UpdateSpan[r.id] = 1; }
341                for(var i=0;i<sp;i++) U.push(r.id,S[i+p]+"RowSpan",null,r[S[i+p]+"RowSpan"]);
342                }
343             if(sp>1) { r[col+"Span"] = 1; this.UpdateSpan(r); }
344             for(var i=0;i<sp;i++) r[S[i+p]+"RowSpan"] = null;
345             if(r.firstChild) this.ResetHidden(r,col,O,null,U);
346             if(O) O[r.id] = r;
347             }
348          if(rs.Block>=a+al&&!B[rs.id]) {
349             if(U) U.push(rs.id,"Block",rs.Block-al,rs.Block);
350             rs.Block -= al; B[rs.id] = 1;
351             }
352          else if(rs.Block>a&&!B[rs.id]) { 
353             if(U) U.push(rs.id,"Block",a,rs.Block);
354             rs.Block = a; B[rs.id] = 1;
355             }
356          }
357       }
358    }
359 if(this.MainCol) for(var col in this.SpanCols) if(rows[0][col+"Visible"]==-2) {
360    for(var i=0;i<al;i++) this.ResetHidden(rows[i],col,O,1,U);
361    var p = rows[0].parentNode;
362    if(p.childNodes.length==rows.length&&p[col+"Visible"]!=-2) { 
363       var cell = this.GetCell(p,col); 
364       if(cell) cell.rowSpan--;
365       }
366    }
367 }
368 // -----------------------------------------------------------------------------------------------------------
369 TGP.AddRowSpan = function(rows,O,U){
370 var al = rows.length, prev = rows[0].previousSibling, next = rows[al-1].nextSibling, par = rows[0].parentNode, X = {}, CF = null, cpos = 0;
371 if(next && next.RowSpan) for(var col in this.SpanCols) if(!X[col] && next[col+"RowSpan"]==0) {
372    var rs = this.GetSpanRow(prev,col), sp = rs.Spanned ? rs[col+"Span"] : 1;
373    var C = this.Cols[col], S = this.ColNames[C.Sec], p = C.Pos;
374    if(this.CPLastSec&&rs.Fixed&&C.MainSec==1){ 
375       if(!CF) { CF = this.GetAllColPages(); for(var i=1;i<C.Sec;i++) cpos += this.ColNames[i].length; } 
376       S = CF; p += cpos;
377       }
378    if(U) for(var i=0;i<sp;i++) U.push(rs.id,S[i+p]+"RowSpan",rs[S[i+p]+"RowSpan"]+al,rs[S[i+p]+"RowSpan"]);
379    for(var i=0;i<sp;i++) rs[S[i+p]+"RowSpan"] += al;
380    for(var j=0;j<rows.length;j++){
381       var r = rows[j];
382       r.RowSpan = 1;
383       if(O) O[r.id] = r;
384       for(var i=0;i<sp;i++) { 
385          if(r[S[i+p]+"RowSpan"]>1) {  
386             var cc = S[i+p], spx = r.Spanned ? r[cc+"Span"] : 1; 
387             if(spx==0) { cc = this.GetSpanCol(r,cc); spx = r[cc+"Span"]; }
388             var pp = this.Cols[cc].Pos;
389             for(var k=r[S[i+p]+"RowSpan"],rr=r;k>=1&&rr;k--,rr=rr.nextSibling) {
390                for(var l=0;l<spx;l++){
391                   if(U) U.push(rr.id,S[l+pp]+"RowSpan",null,rr[S[l+pp]+"RowSpan"]);
392                   rr[S[l+pp]+"RowSpan"] = null;
393                   if(rr.firstChild&&k>1) this.ResetHidden(rr,S[l+pp],O,null,U); 
394                   }
395                }
396             this.SetRowBlock(r,U);
397             }
398          if(U) U.push(r.id,S[i+p]+"RowSpan",0,r[S[i+p]+"RowSpan"]);
399          r[S[i+p]+"RowSpan"] = 0; 
400          X[S[i+p]] = 1; 
401          }
402       if(r.Spanned && r[col+"Span"]==0){
403          for(var k=1;r[S[p-k]+"Span"]==0;k++);
404          
405          if(U) { U.push(r.id,S[p-k]+"Span",k,r[S[p-k]+"Span"]); U.UpdateSpan[r.id] = 1; }
406          r[S[p-k]+"Span"] = k; this.UpdateSpan(r);
407          }
408       if(sp>1) { 
409          
410          if(U) { U.push(r.id,col+"Span",sp,r[col+"Span"]); U.UpdateSpan[r.id] = 1; }
411          r.Spanned = 1; r[col+"Span"] = sp; this.UpdateSpan(r); 
412          }
413       if(r.firstChild) this.SetHidden(r,col,sp,O,null,U);
414       }
415    if(rs.Block<rs[col+"RowSpan"]) {
416       if(U) U.push(rs.id,"Block",rs[col+"RowSpan"],rs.Block);
417       rs.Block = rs[col+"RowSpan"];
418       
419       }
420    }
421 if(!next) next = prev; if(!next) next = par;
422 if(this.MainCol) for(var col in this.SpanCols) {
423    if(next[col+"Visible"]==-2 || next==par&&(par[col+"RowSpan"]==0||par[col+"RowSpan"]>1) && (par.nextSibling&&par.nextSibling[col+"RowSpan"]==0 || this.GetSpanRow(par,col)[col+"RowSpan"]%1)) {
424       var span = next[col+"Span"];
425       for(var i=0;i<al;i++) this.SetHidden(rows[i],col,span,O,1,U);
426       }
427    }
428
429 }
430 // -----------------------------------------------------------------------------------------------------------
431 TGP.GetUndoSpan = function(ref,upd){
432 var U = []; U.RefreshCell = []; U.UpdateSpan = {}; U.RefreshRow = ref?ref:{}; U.UpdateRowSpan = upd?upd:{}; return U;
433 }
434
435 // -----------------------------------------------------------------------------------------------------------
436 ME.RowSpan;
437
438 // -----------------------------------------------------------------------------------------------------------
439 MS.Move;
440 TGP.MoveRow = function(row,par,next,show,master,noexpand,prevspan){
441 if(row.Removed) return 0;
442 if(!this.RowSpan && !row.Block) return this.MoveRowOne(row,par,next,show,master,noexpand);
443 var moved = 0;
444 MS.RowSpan;
445 var A = [], oldpar = row.parentNode, oldprev = row.previousSibling, O = {};
446
447 this.GetBlock(row,A);    
448 if(A[0].parentNode==par) for(var i=0;i<A.length;i++) if(A[i]==next) return 0; 
449 var UR = null, UA = null; 
450 MS.Undo;
451 if(this.Undo&1&&this.OUndo) { 
452    this.UndoStart(); 
453    var US = {}; if(oldprev) US[oldprev.id] = 1; for(var i=0;i<A.length;i++) US[A[i].id] = 1;
454    UR = this.GetUndoSpan(O,US); UA = this.GetUndoSpan(O,US);
455    }
456 ME.Undo;
457 this.RemoveRowSpan(A,O,UR); if(UR) this.AddUndo({ Type:"RemoveSpan",Data:UR }); 
458
459 if(par&&!par.Page&&!par.Hasch) this.CreateChildren(par); 
460 this.RowSpan = 0; var zal = this.Rendering; this.Rendering = 1;
461 var lr = A[A.length-1], oldnext = lr.nextSibling, oldmoved = {}; for(var i=0;i<A.length;i++) oldmoved[A[i].id] = A[i].Moved;
462
463 for(var i=0;i<A.length;i++) moved |= this.MoveRowOne(A[i],par,next,show,master,noexpand,prevspan,1,1);
464 if(this.MainCol) for(var i=0;i<A.length;i++) this.UpdateRowIcons(A[i],show,1);
465 if(this.Undo&1) {
466    this.AddUndo({Type:"Move",Row:A[0],Parent:par,Next:next,OldParent:oldpar,OldNext:oldnext,Moved:oldmoved});
467    if(oldpar.Removed) { this.AddUndo({Type:"DelPage",Page:oldpar,Next:oldpar.Next}); oldpar.Next = null; }
468    }
469 if(this.SaveOrder && !Is(A[0],"NoUpload")) this.SetChange({ Row:A[0],Parent:par.id?par.id:par.Pos,Next:next?next.id:null,Moved:A[0].Moved });
470 this.RowSpan = 1; this.Rendering = zal;
471
472 this.AddRowSpan(A,O,UA); if(UA) this.AddUndo({Type:"AddSpan",Data:UA}); 
473 if(oldprev) this.UpdateRowSpan(oldprev,1);  
474 for(var i=0;i<A.length;i++) this.UpdateRowSpan(A[i],1);      
475 for(var ro in O) this.RefreshRow(O[ro]); 
476
477 if(this.Undo&1) this.UndoEnd();
478 if(show) this.Update();   
479 ME.RowSpan;
480 return moved;
481 }
482 ME.Move;
483 // -----------------------------------------------------------------------------------------------------------
484 TGP.GetBlock = function(row,A){
485 for(var block=1;block>0&&row;block--){
486    if(row.Block > block) block = row.Block;
487    A[A.length] = row;
488    row = row.nextSibling;
489    }
490 }
491 // -----------------------------------------------------------------------------------------------------------
492 MS.ColSpan$RowSpan;
493 // -----------------------------------------------------------------------------------------------------------
494 // -----------------------------------------------------------------------------------------------------------
495 TGP.GetSpanned = function(row,col,vis){
496 if(!row||row.Fixed||!col) return [row,col,row,col];
497 var r1 = row, r2 = row, c1 = col, c2 = col; 
498 if(r1.Spanned&&r1[c1+"Span"]!=1) c1 = this.GetSpanCol(r1,c1);
499 if(r1.RowSpan&&r1[c1+"RowSpan"]!=1||r1[c1+"Visible"]==-2) r1 = this.GetSpanRow(r1,c1);
500 if(r2.Spanned&&r2[c2+"Span"]!=1) c2 = this.GetLastSpanCol(r2,c2,vis);
501 if(r2.RowSpan&&r2[c2+"RowSpan"]!=1||r2[c2+"Visible"]==-2) r2 = this.GetLastSpanRow(r2,c2,vis);
502 if(vis){
503    if(!r1.Visible) r1 = this.GetNextVisible(r1);
504    if(!this.Cols[c1].Visible) c1 = this.GetNextCol(c1);
505    }
506 return [r1,c1,r2,c2];
507 }
508 // -----------------------------------------------------------------------------------------------------------
509 // -----------------------------------------------------------------------------------------------------------
510 MS.DynSpan;
511 // -----------------------------------------------------------------------------------------------------------
c35f05 512 TGP.SpanRange = function(r1,c1,r2,c2,plus,noshow){
25ab64 513
F 514 if(!plus) plus = 0;
515 MS.Animate; this.FinishAnimations(); ME.Animate;
516
517 if(r1.Fixed!=r2.Fixed){
518    if(r1.Fixed) { this.SpanRange(r1,c1,this.GetLastVisible(this.XH),c2); r1 = this.GetFirstVisible(); } 
519    if(r2.Fixed) { this.SpanRange(this.GetFirstVisible(this.XF),c1,r2,c2); r2 = this.GetLastVisible(); } 
520    }
521 if(this.Cols[c1].MainSec!=this.Cols[c2].MainSec){
522    if(this.Cols[c1].MainSec==0) { this.SpanRange(r1,c1,r2,this.GetLastCol(0)); c1 = this.GetFirstCol(1); } 
523    if(this.Cols[c1].MainSec==2) { this.SpanRange(r1,this.GetFirstCol(2),r2,c2); c2 = this.GetLastCol(1); }   
524    }
525
526 if(r1.parentNode!=r2.parentNode){
527    while(r1.Level > r2.Level) r1 = r1.parentNode;
528    while(r2.Level > r1.Level) { r2 = r2.parentNode; plus = 0.5; }
529    while(r1.parentNode!=r2.parentNode && r1.Level>0){ r1 = r1.parentNode; r2 = r2.parentNode; plus = 0.5; }
530    }
531
532 MS.ColPaging;
533 if(this.ColPaging && this.Cols[c1].Sec!=this.Cols[c2].Sec) {
534    this.MergeColPages(this.Cols[c1].Sec,this.Cols[c2].Sec);
535    }
536 ME.ColPaging;
537
538 MS.Paging;
539 if(r1.parentNode!=r2.parentNode){ 
540    var r = r1.parentNode.nextSibling.firstChild, p = r1.parentNode;
541    var zal = this.Rendering; this.Rendering = 1;
542    var A = [];
543    this.UndoStart();
544    while(1){
545       this.GetBlock(r,A);    
546       var n = this.GetNextSibling(A[A.length-1]);
547       this.MoveRow(r,p,null,1);
548       if(p==r2.parentNode) break;
549       r = n;
550       }
551    this.UndoEnd();
552    this.Rendering = zal;
553    }
554 ME.Paging;
555
556 MS.ChildParts;
557 if(this.ChildParts && r1.r1 && (!r2.r1 || r1.r1.parentNode!=r2.r1.parentNode)){ 
558    for(var r=r1.nextSibling;r.r1&&r.r1.parentNode==r1.r1.parentNode;r=r.nextSibling); 
559    for(var p=r1.r1.parentNode.parentNode.parentNode.previousSibling,num=0;p;p=p.previousSibling,num++); 
560    for(var nr=r2.nextSibling;r!=nr;r=r.nextSibling){
561       if(!r.r1) this.RenderChildPart(r.parentNode,num+1); 
562       var rev = this.ReversedTree;
563       for(var i=this.FirstSec;i<=this.LastSec;i++) if(r["r"+i]) {
564          var p = r["r"+i].parentNode;
565          if(rev){
566             MS.ReversedTree;
567             var ch = r.Hasch ? r["r"+i].previousSibling : null;
568             if(ch) r1["r"+i].parentNode.appendChild(ch);
569             r1["r"+i].parentNode.appendChild(r["r"+i]);
570             ME.ReversedTree;
571             }
572          else {
573             var ch = r.Hasch ? r["r"+i].nextSibling : null;
574             r1["r"+i].parentNode.appendChild(r["r"+i]);
575             if(ch) r1["r"+i].parentNode.appendChild(ch);
576             }
577          if(p.childNodes.length==1) { p = p.parentNode.parentNode; p.parentNode.removeChild(p); } 
578          }
579       }
580    }
581 ME.ChildParts;
582 if(r1==r2&&c1==c2&&!plus) return;
583
584 for(var r=r1;r&&r!=r2;r=r.nextSibling);
585 if(!r){ r = r1; r1 = r2; r2 = r; }
586 var C = this.Cols, sec = C[c1].Sec, S = this.ColNames[sec];
587 if(C[c1].Pos>C[c2].Pos) { var c = c1; c1 = c2; c2 = c; }
588 var p = C[c1].Pos, cc = C[c2].Pos-p+1, nc = S[p+cc];
589 var nr = r2.nextSibling, lr = nr, fr = r1, ma = 0, mb = 0, O = {}, undo = this.Undo && this.DynamicSpan && this.OUndo;
590
591 if(r2[c2+"Span"]>1) {
592    while(r2[S[p+cc]+"Span"]==0) cc++; 
593    nc = S[p+cc];
594    c2 = S[p+cc-1];
595    }
596 if(r2.RowSpan && r2[c2+"RowSpan"]!=1){
597    while(nr && nr[c2+"RowSpan"]==0) nr = nr.nextSibling;
598    lr = nr;
599    r2 = nr ? nr.previousSibling : r2.parentNode.lastChild;
600    }
601
602 MS.Undo;
603 if(this.Undo && !this.OUndo && (r1[c1+"RowSpan"]>1 || r1==r2) && (r1[c1+"Span"]==cc || c1==c2 && !r1.Spanned)){
604    for(var a=1,r=r1;r&&r!=r2;r=r.nextSibling,a++);
605    if(a+plus==r1[c1+"RowSpan"]||a==1&&!plus&&r1[c1+"RowSpan"]==null) return;
606    }
607 if(undo){ var aundo = this.CanUndo()+this.CanRedo()*2; }
608 this.UndoStart();
609 ME.Undo;
610 var DB = []; 
611
612 if(r1[c1+"Span"]==0 && r1[c1+"RowSpan"]==0){                             
613    for(var ro=r1,a=0;ro&&ro[c1+"RowSpan"]==0;ro=ro.nextSibling,a++);        
614    if(this.MainCol || undo){
615       for(var rm=r1;rm&&rm[c1+"RowSpan"]==0;rm=rm.previousSibling);         
616       if(this.MainCol && rm[c1+"RowSpan"]%1) a += 0.5;                      
617       }
618    for(var cm=p-1;cm&&r1[S[cm]+"Span"]==0;cm--) r1[S[cm]+"RowSpan"] = a;    
619    r1[S[cm]+"RowSpan"] = a;                                                 
620    MS.Undo;
621    if(undo) {
622       for(var co=p+1;co&&r1[S[co]+"Span"]==0;co++);                         
623       this.AddUndo({ Type:"SplitAuto",Row:rm,Row2:ro?ro.previousSibling:rm.parentNode.lastChild,Col:S[cm],Col2:S[co-1] }); 
624       }
625    ME.Undo;
626    }
627 if(nr && nr[c1+"Span"]==0 && nr[c1+"RowSpan"]==0){                    
628    for(var rm=nr,a=0;rm&&rm[S[p-1]+"RowSpan"]==0;rm=rm.previousSibling,a++);
629    if(this.MainCol&&rm&&rm[S[p-1]+"RowSpan"]%1) a += 0.5;
630    for(var cm=p-1;cm&&rm[S[cm]+"Span"]==0;cm--) rm[S[cm]+"RowSpan"] = a;    
631    rm[S[cm]+"RowSpan"] = a;                                                 
632    
633    if(this.MainCol && r2.firstChild) { this.ResetHidden(r2,S[cm],O); this.SetHidden(r2,S[cm],p-cm,O); } 
634    MS.Undo;
635    if(undo) {
636       for(var ro=nr.nextSibling;ro&&ro[c1+"RowSpan"]==0;ro=ro.nextSibling); 
637       for(var co=p+1;co&&rm[S[co]+"Span"]==0;co++);                         
638       this.AddUndo({ Type:"SplitAuto",Row:rm,Row2:ro?ro.previousSibling:rm.parentNode.lastChild,Col:S[cm],Col2:S[co-1] }); 
639       }
640    ME.Undo;
641    }
642 if(r1[nc+"Span"]==0 && r1[nc+"RowSpan"]==0){                          
643    for(var ro=r1,a=0;ro&&ro[nc+"RowSpan"]==0;ro=ro.nextSibling,a++);        
644    if(this.MainCol || undo){
645       for(var rm=r1;rm&&rm[nc+"RowSpan"]==0;rm=rm.previousSibling);         
646       if(rm[nc+"RowSpan"]%1) a += 0.5;                                      
647       }
648    for(var co=p+cc;co&&r1[S[co]+"Span"]==0;co++) r1[S[co]+"RowSpan"] = a;   
649    MS.Undo;
650    if(undo) {
651       for(var cm=p+cc-1;cm&&rm[S[cm]+"Span"]==0;cm--);                      
652       this.AddUndo({ Type:"SplitAuto",Row:rm,Row2:ro?ro.previousSibling:rm.parentNode.lastChild,Col:S[cm],Col2:S[co-1] }); 
653       }
654    ME.Undo;
655    }
656 if(nr && nr[nc+"Span"]==0 && nr[nc+"RowSpan"]==0){                    
657    for(var rm=nr,a=0;rm&&rm[nc+"RowSpan"]==0;rm=rm.previousSibling,a++);    
658    if(this.MainCol&&rm&&rm[nc+"RowSpan"]%1) a += 0.5;                                               
659    for(var co=p+cc;co&&rm[S[co]+"Span"]==0;co++) rm[S[co]+"RowSpan"] = a;   
660    if(this.MainCol && r2.firstChild || undo) { 
661       for(var cm=p+cc-1;cm&&rm[S[cm]+"Span"]==0;cm--);                      
662       if(this.MainCol && r2.firstChild){                                    
663          if(cm>=p) this.ResetHidden(r2,S[cm],O);                            
664          r2[nc+"Span"] = co-p-cc;                                           
665          this.SetHidden(r2,nc,co-p-cc,O);                                   
666          }
667       MS.Undo;
668       if(undo) {
669          for(var ro=nr.nextSibling;ro&&ro[nc+"RowSpan"]==0;ro=ro.nextSibling);          
670          this.AddUndo({ Type:"SplitAuto",Row:rm,Row2:ro?ro.previousSibling:rm.parentNode.lastChild,Col:S[cm],Col2:S[co-1] }); 
671          }
672       ME.Undo;
673       }
674    }
675
676 for(var i=p;i<p+cc;i++) {
677    if(nr && nr[S[i]+"RowSpan"]==0){ 
678       if(this.MainCol || undo) for(var rm=nr;rm&&rm[S[i]+"RowSpan"]==0;rm=rm.previousSibling); 
679       for(var ro=nr,a=0;ro&&ro[S[i]+"RowSpan"]==0;ro=ro.nextSibling,a++); 
680       if(a>mb) { lr = ro; mb = a; } 
681       for(var cm=i;cm&&nr[S[cm]+"Span"]==0;cm--); 
682       var cs = nr.Spanned ? nr[S[cm]+"Span"] : 1;
683       if(this.MainCol && rm[S[cm]+"RowSpan"]%1) a += 0.5;
684       for(var j=0;j<cs;j++) nr[S[cm+j]+"RowSpan"] = a; 
685       if(!nr.Block||nr.Block<a) nr.Block = a>1.5 ? Math.floor(a) : null;
686       MS.Undo;
687       if(undo){
688          for(var co=i+1;co&&nr[S[co]+"Span"]==0;co++);                         
689          this.AddUndo({ Type:"SplitAuto",Row:rm,Row2:ro?ro.previousSibling:rm.parentNode.lastChild,Col:S[cm],Col2:S[co-1] }); 
690          }
691       ME.Undo;
692       
693       
694       }
695    if(r1[S[i]+"RowSpan"]==0){ 
696       for(var rm=r1,a=0;rm&&rm[S[i]+"RowSpan"]==0;rm=rm.previousSibling,a++); 
697       if(a>ma) { fr = rm; ma = a; }               
698       for(var cm=i;cm&&r1[S[cm]+"Span"]==0;cm--); 
699       var cs = rm.Spanned ? rm[S[cm]+"Span"] : 1; 
700       if(this.MainCol && r1.previousSibling.firstChild) a += 0.5; 
701       for(var j=0;j<cs;j++) rm[S[cm+j]+"RowSpan"] = a; 
702       this.SetRowBlock(rm);
703       MS.Undo;
704       if(undo){
705          for(var ro=r1.nextSibling;ro&&ro[S[i]+"RowSpan"]==0;ro=ro.nextSibling); 
706          for(var co=i+1;co&&r1[S[co]+"Span"]==0;co++);                         
707          this.AddUndo({ Type:"SplitAuto",Row:rm,Row2:ro?ro.previousSibling:rm.parentNode.lastChild,Col:S[cm],Col2:S[co-1] }); 
708          }
709       ME.Undo;
710       
711       }
712    if(r2.firstChild && (r2[S[i]+"RowSpan"]==0||r2==r1) && !plus) this.ResetHidden(r2,S[i],O);
713    }
714
715 for(var r=r1;r!=nr;r=r.nextSibling){
716    if(r[c1+"Span"]==0){ 
717       for(var cm=p-1;cm&&r[S[cm]+"Span"]==0;cm--); 
718       r[S[cm]+"Span"] = p-cm;
719       if(r.firstChild && r.firstChild[S[cm]+"Visible"]==-2) this.SetHidden(r,S[cm],p-cm,O);
720       MS.Undo;
721       if(undo && r[c1+"RowSpan"]!=0){ 
722          for(var ro=r.nextSibling;ro&&ro[c1+"RowSpan"]==0;ro=ro.nextSibling); 
723          for(var co=p+1;co<S.length&&r[S[co]+"Span"]==0;co++); 
724          this.AddUndo({ Type:"SplitAuto",Row:r,Row2:ro?ro.previousSibling:r.parentNode.lastChild,Col:S[cm],Col2:S[co-1] }); 
725          }
726       ME.Undo;
727       
728       }
729    if(nc && r[nc+"Span"]==0){ 
730       for(var co=p+cc;co<S.length&&r[S[co]+"Span"]==0;co++); 
731       r[nc+"Span"] = co-p-cc;
732       if(r.firstChild && r.RowSpan || undo){
733          for(var cm=p+cc-1;cm&&r[S[cm]+"Span"]==0;cm--); 
734          if(r.firstChild && r.RowSpan && r.firstChild[S[cm]+"Visible"]==-2) this.SetHidden(r,nc,co-p-cc,O);
735          MS.Undo;
736          if(undo && r[nc+"RowSpan"]!=0){ 
737             for(var ro=r.nextSibling;ro&&ro[nc+"RowSpan"]==0;ro=ro.nextSibling); 
738             this.AddUndo({ Type:"SplitAuto",Row:r,Row2:ro?ro.previousSibling:r.parentNode.lastChild,Col:S[cm],Col2:S[co-1] }); 
739             }
740          ME.Undo;
741          }
742       
743       }
744    var db = this.DynamicBorder; this.DynamicBorder = null;
745    if(r.firstChild && (r!=r2||plus)){ 
746       for(var n=r.firstChild;n;n=n.nextSibling){
747          if(n.RowSpan||n.Spanned){
748             for(var j=p;j<p+cc;j++) if(n[S[j]+"RowSpan"]>1||n[S[j]+"Span"]>1) this.SplitSpanned(n,S[j],O);
749             }
750          }
751       if(r.RowSpan) for(var j=p;j<p+cc;j++) if(r[S[j]+"RowSpan"]>1||r[S[j]+"RowSpan"]==0) this.ResetHidden(r,S[j],O);
752       }
753    this.DynamicBorder = db;
754    MS.Undo;
755    if(undo && (r.RowSpan || r.Spanned)){
756       for(var i=p;i<p+cc;i++) { 
757          if(r[S[i]+"Span"]>1 && r[S[i]+"RowSpan"]!=0 || r[S[i]+"RowSpan"]>0 && r[S[i]+"Span"]!=0){
758             for(var ro=r.nextSibling;ro&&ro[S[i]+"RowSpan"]==0;ro=ro.nextSibling); 
759             for(var co=i+1;co<S.length&&r[S[co]+"Span"]==0;co++); 
760             this.AddUndo({ Type:"SplitAuto",Row:r,Row2:ro?ro.previousSibling:r.parentNode.lastChild,Col:S[i],Col2:S[co-1] }); 
761             } 
762          }
763       }
764    ME.Undo;
765    }
766
767 var rev = this.ReversedTree;
768 for(var r=r1,rc=0;r!=nr;r=r.nextSibling,rc++) { 
769    if(r1!=r2 || plus) r.RowSpan = 1; 
770    if(c1!=c2 && !r.Spanned) { r.Spanned = 1; this.UpdateSpan(r); }
771    for(var i=p;i<p+cc;i++) { r[S[i]+"Span"] = 0; r[S[i]+"RowSpan"] = r==r1?1:0; }
772    if(r.Block) this.SetRowBlock(r);
773    r[c1+"Span"] = cc;
774    if(r.firstChild && (rev ? r!=r1 : r!=r2||plus)) this.SetHidden(r,c1,cc,O);
775    }
776 if(rc>1 || plus) for(var i=p;i<p+cc;i++) { C[S[i]].Spanned = 1; r1[S[i]+"RowSpan"] = rc+plus; }
777 if(rc>1 && !(r1.Block>rc)) r1.Block = rc;
778 if(rc>1 || plus) this.RowSpan = 1;
779 if(cc>1) this.ColSpan = 1;
780
781 MS.Undo;
782 if(undo){
783    this.AddUndo({ Type:"Span",Row:r1,Row2:r2,Col:c1,Col2:c2,Plus:plus });
784    if(this.CanUndo()+this.CanRedo()*2!=aundo) this.CalculateSpaces(1);
785    }
786 this.UndoEnd();
787 ME.Undo;
788 if(r1.Fixed&&this.CPLastSec&&C[c1].MainSec==1) sec = 1;
789 var spnlen = this.SpannedColsLength;
c35f05 790 if(!this.LeftTD && this.MainCol) { this.LeftTD = 1; if(noshow<2) this.Render(); if(spnlen!=this.SpannedColsLength) this.UpdateHidden(); return; } 
F 791 if(!noshow) for(var r=fr;r!=lr;r=r.nextSibling) this.RefreshRow(r,sec);
25ab64 792 if(spnlen!=this.SpannedColsLength) this.UpdateHidden();
F 793
c35f05 794 if(!noshow){
F 795    for(var ro in O) this.RefreshRow(O[ro],sec);
796    for(var r=fr;r!=lr;r=r.nextSibling) this.UpdateRowHeight(r,0,1);
797    for(var ro in O) this.UpdateRowHeight(O[ro],0,1);
798    this.UpdateRowHeight(r1,0,1);
799    }
25ab64 800 if(this.FRow&&this.FCol){
F 801    if(this.FRow.RowSpan&&this.FRow[this.FCol+"RowSpan"]==0) this.FRow = this.GetSpanRow(this.FRow,this.FCol);
802    if(this.FRow.Spanned&&this.FRow[this.FCol+"Span"]==0) this.FCol = this.GetSpanCol(this.FRow,this.FCol);
803    }
804 }
805 // -----------------------------------------------------------------------------------------------------------
806 TGP.SetRowBlock = function(row,U){
807 var max = 1, C = this.SpanCols;
808 for(var c in C) if(max<row[c+"RowSpan"]) max = row[c+"RowSpan"];
809 var blk = max>1.5 ? Math.floor(max) : null;
810 if(blk==row.Block) return;
811 if(U) U.push(row.id,"Block",blk,row.Block);
812 row.Block = blk;
813 }
814 // -----------------------------------------------------------------------------------------------------------
815 TGP.SplitSpanned = function(row,col,R,test){
816 if(row.Space) return false;
817
818 var spn = row.Spanned ? row[col+"Span"] : 1; if(spn==0) { col = this.GetSpanCol(row,col); spn = row[col+"Span"]; }
819 var rspn = row.RowSpan ? row[col+"RowSpan"] : 1; if(rspn==0) { row = this.GetSpanRow(row,col); rspn = row[col+"RowSpan"]; }
820 if(rspn==null) rspn = 1;
821 if(rspn==1 && spn==1) return false;
822 if(test) return true;
823 var sec = this.Cols[col].Sec, S = this.ColNames[sec], E = [], p = this.Cols[col].Pos, O = R ? R : {}, lr = null;
824 if(spn>S.length-p) spn = S.length-p;
825 for(var r=row,i=1;i<=rspn&&r;r=r.nextSibling,i++) {
826    for(var j=0;j<spn;j++) { r[S[j+p]+"RowSpan"] = 1; r[S[j+p]+"Span"] = 1; }
827    if(r.firstChild) this.ResetHidden(r,col,O);
828    O[r.id] = r; lr = r;
829    }
830 if(row.Block==rspn) this.SetRowBlock(row);
831 MS.Undo; if(this.Undo && this.DynamicSpan && this.OUndo) this.AddUndo({ Type:R?"SplitAuto":"Split",Row:row,Row2:lr,Col:col,Col2:S[p+spn-1] }); ME.Undo;
832
833 if(!R){
834    
835    for(var ro in O) this.RefreshRow(O[ro],sec);
836    this.RefreshRow(row,sec);
837    for(var ro in O) this.UpdateRowHeight(O[ro],0,1);
838    this.UpdateRowHeight(row,0,1);
839    MS.Overlay;
840    if(this.Overlay>=2) {
841       for(var ro in O) this.UpdateOverlay(O[ro],sec);
842       this.UpdateOverlay(row,sec);
843       }
844    ME.Overlay;
845    }
846 MS.FocusRect; if(this.FocusRect&&row==this.FRow&&col==this.FCol&&!this.FRect) this.Focus(this.FRow,this.FCol,null,[row,col,lr,S[j+p-1]]); ME.FocusRect; 
847 return true;
848 }
849 // -----------------------------------------------------------------------------------------------------------
850 TGP.ActionSpan = function(F,T){
851 if(this.Locked["style"]||!this.DynamicSpan) return false;
852 var S = this.GetARanges(F,1,2,0,1), chg = 0;
853 for(var i=0;i<S.length;i++) {
854    var A = S[i]; if(!((A[0]!=A[2]||A[1]!=A[3]) && (this.GetSpanRow(A[2],A[3])!=A[0]||this.GetSpanCol(A[2],A[3])!=A[1]))) continue;
855    chg++;
856    if(!T) this.SpanRange(S[i][0],S[i][1],S[i][2],S[i][3]);
857    }
858
859 if(chg&&!T) {
860    this.CalculateSpaces(1);
861    this.Update();
862    if(this.AutoUpdate) this.UploadChanges();
863    }
864 return chg;
865 }
866 // -----------------------------------------------------------------------------------------------------------
867 TGP.ActionSplit = function(F,T){
868 if(this.Locked["style"]||!this.DynamicSpan) return false;
869 var S = this.GetARanges(F), chg = 0;
870 for(var i=0;i<S.length;i++) {
871    for(var r=S[i][0],n=this.GetNext(S[i][2]),cc=this.GetNextCol(S[i][3]);r!=n;r=this.GetNext(r)) if(r.RowSpan||r.Spanned){
872       for(var c=S[i][1];c!=cc;c=this.GetNextCol(c)) if((r.RowSpan && (r[c+"RowSpan"]==0||r[c+"RowSpan"]>1) || r.Spanned && r[c+"Span"]!=1) && this.SplitSpanned(r,c,null,T)) chg++;
873       }
874    }
875 if(S.Rows) {
876    var C = this.Cols;
877    for(var id in S.Rows) {
878       var r = S.Rows[id]; if(!r.RowSpan&&!r.Spanned) continue;
879       for(var c in C) if((r.RowSpan && (r[c+"RowSpan"]==0||r[c+"RowSpan"]>1) || r.Spanned && r[c+"Span"]!=1) && this.SplitSpanned(r,c,null,T)) chg++;
880       }
881    }
882 if(S.Cols){
883    var R = this.Rows;
884    for(var c in S.Cols){
885       for(var id in R) { var r = R[id]; if((r.RowSpan && (r[c+"RowSpan"]==0||r[c+"RowSpan"]>1) || r.Spanned && r[c+"Span"]!=1) && this.SplitSpanned(r,c,null,T)) chg++; }
886       }
887    }
888 if(chg&&!T) {
889    this.CalculateSpaces(1);
890    this.Update();
891    if(this.AutoUpdate) this.UploadChanges();
892    }
893 return chg;
894 }
895 // -----------------------------------------------------------------------------------------------------------
896 TGP.ActionSpanSelected = function(F,T){ return this.ActionSpan(F?F|2:2,T); }
897 TGP.ActionSpanCells = function(F,T){ return this.ActionSpan(F?F|1:1,T); }
898 TGP.ActionSplitCell = function(F,T){ return this.ActionSplit(F,T); }
899 TGP.ActionSplitSelected = function(F,T){ return this.ActionSplit(F?F|2:2,T); }
900 TGP.ActionSplitCells = function(F,T){ return this.ActionSplit(F?F|1:1,T); }
901 // -----------------------------------------------------------------------------------------------------------
902 // -----------------------------------------------------------------------------------------------------------
903 TGP.ActionAutoSpan = function(F,T,type){
904 var A = this.GetACell(F?F|64:64); if(!A) return false;
905 var row = A[0], col = A[1];
906 if(!this.DynamicSpan || !row || !col || F&&this.FRect&&(this.FRect[0]!=this.FRect[2]||this.FRect[1]!=this.FRect[3]) || row.Space || type&1&&!this.Cols[col].Spanned || type&2&&!row.Spanned ||this.Locked["style"]) return false;
907 return this.AutoSpanCell(row,col,type?type:3,T);
908 }
909 TGP.ActionAutoRowSpan = function(F,T){ return this.ActionAutoSpan(F,T,1); }
910 TGP.ActionAutoColSpan = function(F,T){ return this.ActionAutoSpan(F,T,2); }
911 // -----------------------------------------------------------------------------------------------------------
912 // -----------------------------------------------------------------------------------------------------------
913 TGP.AutoSpanCell = function(row,col,type,test){
914 if(!row||!col||row.Space||this.Locked["style"]) return false;
915 if(type==null) type = this.AutoSpan&3; if(!type) return false;
916 var lc = this.GetLastSpanCol(row,col); col = this.GetSpanCol(row,col);
917 var lr = this.GetLastSpanRow(row,col); row = this.GetSpanRow(row,col);
918
919 var A = [], I = this.Img; this.GetRowHTML(row,A,4,col);
920 var O = this.SpanCellTag;
921 if(!O){
922    O = document.createElement("div");
923    this.AppendTag(O);
924    O.style.position = "absolute";
925    O.style.visibility = "hidden";
926    O.style.left = "10px";
927    
928    O.style.top = "-100px";
929    O.style.whiteSpace = "nowrap";
930    this.SpanCellTag = O;
931    }
932 O.innerHTML = "<div class='"+A[1]+"'>"+A[0]+"</div>";
933 var W = O.offsetWidth, H = O.offsetHeight, c = col, r = row;
934
935 if(type&2){
936    while(c){
937       W -= this.Cols[c].Width;
938       if(W<=0) break;
939       c = this.GetNextCol(c);
940       if(!c && this.AutoColPages){ c = this.GetLastCol(); this.AddAutoColPages(); c = this.GetNextCol(c); }
941       }
942    if(!c) c = this.GetLastCol();
943    }
944 if(type&1){
945    var hh = this.RowHeight, act = this.AutoSpan&32;
946    while(r){
947       if(r.Visible) { 
948          if(act) H -= this.GetRowHeight(r); 
949          else { var h = row.Height; if(h==null) h = row.Def.Height; if(h==null) h = hh; H -= h; }
950          if(H<=0) break; 
951          }
952       if(r.firstChild){
953          H -= this.GetPageHeight(row,!act);
954          if(H<=0) { r = r.lastChild; break; }
955          }
956       r = this.GetNextSiblingVisible(r);
957       if(!r&&this.AutoPages&&!row.Fixed) { r = this.XB.lastChild.lastChild; this.AddAutoPages(); r = this.GetNextSibling(r); }
958       }
959    if(!r) r = this.GetLast(row.Fixed?row.parentNode:null);
960    }
961 if(r==lr&&c==lc) return false;
962 if(r==row&&c==col) { 
963    if(lc!=col|lr!=row) {
964       if(!test) this.SplitSpanned(row,col);
965       return true;
966       }
967    return false;
968    }
969 if(this.AutoSpan&16){
970    var C = [col];
971    if(c!=col) for(var zc=c,c=this.GetNextCol(col);c;c=this.GetNextCol(c)) { 
972       if(Get(row,c)) { c = C[C.length-1]; break; }
973       C[C.length] = c;
974       if(c==zc) break;
975       }
976    if(r!=row) for(var zr=r,r=this.GetNextVisible(row);r;r=this.GetNextVisible(r)){
977       for(var i=0;i<C.length;i++){ var cc = C[i]; if(Get(r,cc)) { r = this.GetPrevVisible(r); while(r.Level>row.Level) r = r.parentNode; zr = r; break; } }
978       if(r==zr) break;
979       }
980    }
981 if(r==lr&&c==lc) return false;
982 if(r==row&&c==col) { 
983    if(lc!=col|lr!=row) {
984       if(!test) this.SplitSpanned(row,col);
985       return true;
986       }
987    return false;
988    }
989 if(test) return true;
990 this.UndoStart();
991 if(lc!=col|lr!=row) this.SplitSpanned(row,col);
992 this.SpanRange(row,col,r,c);
993 this.UndoEnd();
994 this.Update();
995 return true;
996 }
997 // -----------------------------------------------------------------------------------------------------------
998 TGP.AutoSpanAllCells = function(type){
999 if(type==null) type = this.AutoSpan&3; if(!type) return false;
1000 var C = []; for(var c=this.GetFirstCol();c;c=this.GetNextCol(c)) if(!this.Cols[c].NoData) C[C.length] = c;
1001 for(var r=this.GetFirstVisible();r;r=this.GetNextVisible(r)) if(!r.NoData){
1002    for(var i=0;i<C.length;i++){
1003       var c = C[i];
1004       if(r.Spanned&&r[c+"Span"]==0||r.RowSpan&&r[c+"RowSpan"]==0) continue;
1005       this.AutoSpanCell(r,c,type);
1006       }
1007    }
1008 }
1009 // -----------------------------------------------------------------------------------------------------------
1010 ME.DynSpan;
1011 ME.ColSpan$RowSpan;