layout/xul/grid/examples/dynamicgrid.xul

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

     1 <?xml version="1.0"?> 
     2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
     3    - License, v. 2.0. If a copy of the MPL was not distributed with this
     4    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     7 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> 
     8 <?xml-stylesheet href="gridsample.css" type="text/css"?> 
    10 <!DOCTYPE window> 
    13 <window orient="vertical" 
    14         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    15 		onload="start()"> 
    17 <script>
    19    var selected;
    20    var count = 0;
    22    function isCell(box)
    23    {
    24      if (box.localName == "row" || 
    25 	     box.localName == "column" ||
    26 		 box.localName == "rows" ||
    27 		 box.localName == "columns" ||
    28 		 box.localName == "grid")
    29 		 return false;
    31 	 return true;
    32    }
    34    function start()
    35    {
    36       selectIt(window.document.getElementById("rows"));
    37    }
    39    function selectIt(box)
    40    {
    41      if (!box)
    42 	   return;
    44      var a = box.getAttribute("selected");
    45 	 if (a != "true") {
    46 	   box.setAttribute("selected","true");
    47   	   if (selected)
    48 	      selected.setAttribute("selected","false");
    50 	   selected = box;
    51      }
    52    }
    54    function addCellSelectionHandle(box)
    55    {
    56 	 box.setAttribute("oncommand", "selectIt(this);");
    57    }
    59    function addRowColumnSelectionHandle(box)
    60    {
    61 	 box.setAttribute("onclick", "selectIt(this);");
    62    }
    64    function createButton(str)
    65    {
    66 	 var b = document.createElement("button");
    67 	 b.setAttribute("label", str+count);
    68 	 count++;
    69 	 addCellSelectionHandle(b);
    70 	 return b;
    71    }
    73    function createRow()
    74    {
    75 	 var b = document.createElement("row");
    76  	 b.setAttribute("dynamic","true");
    78 	 addRowColumnSelectionHandle(b);
    79 	 return b;
    80    }
    82    function createColumn()
    83    {
    84 	 var b = document.createElement("column");
    85 	 b.setAttribute("dynamic","true");
    86 	 addRowColumnSelectionHandle(b);
    87 	 return b;
    88    }
    90    function createText(str)
    91    {
    92 	 var text = document.createElement("text");
    93 	 text.setAttribute("value", str+count);
    94 	 count++;
    95 	 text.setAttribute("style", "font-size: 40pt");
    96 	 addCellSelectionHandle(text);
    97 	 return text;
    98    }
   100    function appendElement(element, prepend)
   101    {
   102      if (!selected)
   103 	    return;
   105      setUserAttribute(element);
   107 	 if (selected.localName == "rows") 
   108 	   appendRow(false);
   109      else if (selected.localName == "columns")
   110 	   appendColumn(false);
   112 	 if (selected.localName == "row" || selected.localName == "column" ) { // is row or column
   113 		 selected.appendChild(element); 
   114 	 } else {
   115 		  var parent = selected.parentNode;
   116 		  if (prepend)
   117 		    parent.insertBefore(element, selected);	 
   118 		  else {
   119 		    var next = selected.nextSibling;
   120 			if (next)
   121 		      parent.insertBefore(element,next);
   122 			else
   123 			  parent.appendChild(element);
   124 		  }
   125 	 }
   127 	 selectIt(element);
   128    }
   130    function getRows(box)
   131    {
   132       return window.document.getElementById("rows");
   133    }
   135    function getColumns(box)
   136    {
   137       return window.document.getElementById("columns");
   138    }
   140    function setUserAttribute(element)
   141    {
   142    	 var attributeBox = document.getElementById("attributebox");
   143 	 var valueBox = document.getElementById("valuebox");
   144 	 var attribute = attributeBox.value;
   145 	 var value = valueBox.value;
   146 	 if (attribute != "")
   147 	   element.setAttribute(attribute,value);
   148    }
   150    function appendRowColumn(rowColumn, prepend)
   151    {
   152      if (!selected)
   153 	    return;
   155      setUserAttribute(rowColumn); 
   157      var row = rowColumn;
   159 	 // first see what we are adding.
   161 	 if (isCell(selected)) { // if cell then select row/column
   162 	   selectIt(selected.parentNode);
   163 	 }
   165 	 if (selected.localName == "row" || selected.localName == "rows")
   166 	   if (row.localName == "column") {
   167 	     selectIt(getColumns(selected)); 
   168 		 dump("Selecting the column")
   169 		 dump("Selected="+selected.localName);
   170 		 }
   172 	 if (selected.localName == "column" || selected.localName == "columns")
   173 	   if (row.localName == "row")
   174 	     selectIt(getRows(selected));
   176 	 if (selected.localName == "rows" || selected.localName == "columns" ) 
   177 	 { // if rows its easy
   178 		 selected.appendChild(row); 
   179 	 } else {
   180 		  var parent = selected.parentNode;
   181 		  if (prepend)
   182 		    parent.insertBefore(row, selected);	 
   183 		  else {
   184 		    var next = selected.nextSibling;
   185 			if (next)
   186 		      parent.insertBefore(row,next);
   187 			else
   188 			  parent.appendChild(row);
   189 		  }
   190 	 }
   192      selectIt(row);
   193    }
   195  function appendRow(prepend)
   196  {
   197    var row = createRow();
   198    appendRowColumn(row,prepend);
   199  }
   202  function appendColumn(prepend)
   203  {
   204    var column = createColumn();
   205    appendRowColumn(column,prepend);
   206  }
   209  function selectRows()
   210  {
   211     var rows = getRows();
   212 	if (rows.firstChild)
   213       selectIt(rows.firstChild);
   214 	else
   215 	  selectIt(rows);
   216  }
   219  function selectColumns()
   220  {
   221     var columns = getColumns();
   222 	if (columns.firstChild)
   223       selectIt(columns.firstChild);
   224 	else
   225 	  selectIt(columns);
   226  }
   228  function nextElement()
   229  {
   230    if (!selected)
   231      return;
   233    selectIt(selected.nextSibling);
   234  }
   236  function previousElement()
   237  {
   238    if (!selected)
   239      return;
   241    selectIt(selected.previousSibling);
   242  }
   244  function selectRow()
   245  {
   246    if (!selected)
   247      return;
   249    if (selected.localName == "row")
   250      return;
   252    if (isCell(selected)) {
   253      if (selected.parentNode.localName == "row")
   254        selectIt(selected.parentNode);
   255    }
   256  }
   258  function selectColumn()
   259  {
   260    if (!selected)
   261      return;
   263    if (selected.localName == "column")
   264      return;
   266    if (isCell(selected)) {
   267      if (selected.parentNode.localName == "column")
   268        selectIt(selected.parentNode);
   269    }
   270  }
   272  function collapseGrid()
   273  {
   274 	 var grid = document.getElementById("grid");
   275 	 var collapsed = grid.getAttribute("collapsed");
   277 	 if (collapsed == "")
   278 	   grid.setAttribute("collapsed","true");
   279 	 else
   280    	   grid.setAttribute("collapsed","");
   282  }
   284  function collapseElement()
   285  {
   286    if (selected) {
   287 	 var collapsed = selected.getAttribute("collapsed");
   289 	 if (collapsed == "")
   290 	   selected.setAttribute("collapsed","true");
   291 	 else
   292    	   selected.setAttribute("collapsed","");
   293 	}
   294  }
   296 </script>
   298     <hbox flex="1" style="border: 2px inset gray; overflow: auto">
   299 	 <vbox flex="1">
   300 	  <hbox>
   301 		<grid id="grid" style="border: 2px solid red;">
   302 		   <columns id="columns">
   303 		   </columns>
   305 		   <rows start="true" id="rows">
   306 		   </rows>
   307 		</grid>
   308 	    <spacer flex="1"/>
   309       </hbox>
   310  	    <spacer flex="1"/>
   311 	 </vbox>
   312     </hbox>
   314     <grid style="background-color: blue">
   315 	   <columns>
   316              <column flex="1"/> 
   317              <column flex="1"/>
   318              <column flex="1"/>             
   319              <column flex="1"/>
   320  	   </columns>
   321 	 <rows>
   323          <row>
   324 		  <button label="append row" oncommand="appendRow(false);"/>
   325 		  <button label="prepend row" oncommand="appendRow(true);"/>
   327 		  <button label="append column" oncommand="appendColumn(false);"/>
   328 		  <button label="prepend column" oncommand="appendColumn(true);"/>
   329 		 </row>
   331         <row>
   333 		 <button label="append button" oncommand="appendElement(createButton('button'),false);"/>
   334 		 <button label="prepend button" oncommand="appendElement(createButton('button'),true);"/>
   336 		 <button label="append text" oncommand="appendElement(createText('text'),false);"/>
   337 		 <button label="prepend text" oncommand="appendElement(createText('text'),true);"/>
   339         </row>
   341 		 <row>
   343  	     <button label="select rows" oncommand="selectRows()"/>
   344 	     <button label="select columns" oncommand="selectColumns()"/>
   346 		 <button label="next" oncommand="nextElement()"/>
   347 		 <button label="previous" oncommand="previousElement()"/>
   349         </row>
   351 	<hbox align="center">
   352  	     <button label="collapse/uncollapse grid" flex="1" oncommand="collapseGrid()"/>
   353  	     <button label="collapse/uncollapse element" flex="1" oncommand="collapseElement()"/>
   354         </hbox>
   358 	<hbox>
   360          <text value="attribute"/>
   361 		 <textbox id="attributebox" value="" flex="1"/>
   362          <text value="value"/>
   363 		 <textbox id="valuebox" value="" flex="2"/>
   364         </hbox>
   367        </rows>
   368 	</grid>
   370 </window>

mercurial