<@doc hierarchy="GMLDOM"> Layout Code (c) SAP AG 2003-2006. All rights reserved. Aspect ToolbarLayout for Layout; inherit ControlGroupLayout; override virtual property type = 'toolbar'; constructor(board, parent) this.supercall(); var c = RULE('getChildWidgets', base); for (var iter in c) $DOM.createAspect('#NS[Layout]', c[iter], this.board, this); end override virtual method paint(parentElement) this.supercall(); var toolbands = base.toolbands; var board = this.board; for (var iter in toolbands) { var child = board.getWidget(iter); if (child) child.paint(); } end override virtual method repaintContents(attr) this.supercall(); var toolbands = base.toolbands; var board = this.board; for (var iter in toolbands) { var child = board.getWidget(iter); if (child) child.repaint(attr); } end override virtual method setRect(rect, snap) this.supercall(); var widths = []; var sum = rect.w; var bases = this.base.getToolbands(); for (var iter in bases) { var ctl = bases[iter]; var w = ctl.size.split(' ')[0]; widths.push(w); sum -= w; } if (sum != 0) widths[0] = INT(widths[0]) + sum; var i = 0; var pos = 0; var toolbands = base.toolbands; var board = this.board; for (var iter in toolbands) { var ctl = board.getWidget(iter); //if (ctl.base.id != bases[i].id) continue; var w = widths[i++]; if (ctl) { ctl.setPos({x: pos, y: 0}, snap); ctl.setSize({w: w, h: rect.h}, snap); } pos += w; } end override virtual method layoutContents(focusWidget, operation) var sessionCache = this.board.sessionCache; var pSize = SPLIT(sessionCache[base.parent.id + '_size'] ? sessionCache[base.parent.id + '_size'].value : base.parent.size); var bSize = SPLIT(base.size); var changes = {}; if (pSize[0] != bSize[0]) { bSize[0] = pSize[0]; changes[base.id + '_size'] = {object: base, prop: 'size', value: bSize[0] + ' ' + bSize[1]}; } var rootInfo = this.buildRearrangeParams(focusWidget, operation, bSize); var board = this.board; var size = RULE('rearrangeWidgets', base, board, rootInfo, changes); var repaint = !ISEMPTY(changes); var heightChanged = size.h != bSize[1]; if (repaint) RULE('doApplyLayout', base, changes); var toolbands = base.toolbands; for (var iter in toolbands) { var child = board.getWidget(iter); repaint |= child.layoutContents(focusWidget, operation); } if (repaint) { this.repaint('layout'); this.board.adjustSelection(); } return heightChanged; end override virtual method updateElements(operation, syncElems) this.supercall(); var toolbands = base.toolbands; var board = this.board; for (var iter in toolbands) { var child = board.getWidget(iter); if (child) child.updateElements(operation, syncElems); } end override virtual method buildRearrangeParams(focusWidget, operation, contentsSize, syncElems) var board = this.board; var sessionCache = board.sessionCache; var withLabel = { 'core.gml2:InputField' :true, 'core.gml2:ComboBox' :true, 'core.gml2:DropDown' :true, 'core.gml2:DatePicker' :true, 'core.gml2:DateTimePicker' :true }; if (!contentsSize) { contentsSize = SPLIT(base.size); contentsSize[0] = SPLIT(sessionCache[base.parent.id + '_size'] ? sessionCache[base.parent.id + '_size'].value : base.parent.size)[0]; } var rootInfo = { object : base, w : INT(contentsSize[0]||320), h : INT(contentsSize[1]||24), dHeight : this.defaultHeight, focus : null, // if children contain focusWidget's ctlInfo, this points to it. operation : operation, children : [], // ctlInfo of child objects (groups/controls) syncElems : syncElems }; var toolbands = base.toolbands; var uWidths = {}; var cWidths = {}; var maxTBLabelWidth = board.textedit._maxTBLabelWidth; var current = board.selection.current; var gap = 4; for (var iter in toolbands) { var controls = toolbands[iter].controls; controls = operation == 'move' && focusWidget && focusWidget.parentID == iter ? sortControls(controls, sessionCache) : SORTN(controls, 'index'); var usedWidth = gap; var controlWidths = []; for (j in controls) { var control = controls[j]; var cSize = SPLIT(sessionCache[control.id + '_size'] ? sessionCache[control.id + '_size'].value : control.size); var width = getLabelWidth(control, board.getWidget(control), maxTBLabelWidth) + INT(cSize[0]||100); usedWidth += width + gap; controlWidths.push(width); } uWidths[iter] = usedWidth; cWidths[iter] = controlWidths; } for (var iter in toolbands) { var ctlWidget = board.getWidget(iter); var ctl = toolbands[iter]; var pos = SPLIT(ctl.pos); var size = SPLIT(ctl.size); var ctlInfo = { object : ctl, x : INT(pos[0]||0), y : INT(pos[1]||0), w : INT(size[0]||160), h : INT(size[1]||24), index : ctl.index, // object's index in its parent. freeSize : ctlWidget&&ctlWidget.freeSize, minWidth : ctlWidget&&ctlWidget.minWidth||0, defaultWidth : ctlWidget&&ctlWidget.defaultWidth||0, usedWidth : uWidths[ctl.id], controlWidths : cWidths[ctl.id], focus : null, // if children contain focusWidget's ctlInfo, this points to it. children : null // ctlInfo of child objects (groups/controls) }; rootInfo.children.push(ctlInfo); if (focusWidget && focusWidget.id == iter) rootInfo.focus = ctlInfo; } return rootInfo; function getLabelWidth(control, widget, maxTBLabelWidth) { if (!control.Class.fullname in withLabel || control.label == '') return 0; var width = MIN(widget&&widget.labelWidth||0, maxTBLabelWidth); return width; } function sortControls(controls, sessionCache) { var arr = []; for (var x in controls) arr.push(controls[x]); return arr.sort(compareCtlInfo); function compareCtlInfo(a, b) { var aPos = SPLIT(sessionCache[a.id + '_pos'] ? sessionCache[a.id + '_pos'].value : a.pos); var bPos = SPLIT(sessionCache[b.id + '_pos'] ? sessionCache[b.id + '_pos'].value : b.pos); var aX = INT(aPos[0]||0), bX = INT(bPos[0]||0); var aY = INT(aPos[1]||0), bY = INT(bPos[1]||0); if (aY > bY) return 1; if (aY < bY) return -1; if (aX > bX) return 1; if (aX < bX) return -1; return 0; } } end