Saturday, May 20, 2006


I have a basic implementation of scrolled lists up under Cocoa (based on NSTableView) that support the following: adding, appending, and removing strings to the list, querying selection count, and obtaining the nth selection.

The XML markup for the above screen looks like the following:

<?xml version="1.0"?>

<window name="main" title="GridList Test" main="true" width="600" height="300" x="100" y="100" position="center, mouse">
<script type="text/javascript" src="resources/content/list.js"/>
<box orient="vertical">
<spacer/>
<gridlist id="gridlisttest" width="100" height="100"/>
<spacer/>
<box orient="horizontal">
<spacer/>
<button label="Add" onclick="return Add();"/>
<spacer/>
<button label="Append" onclick="return Append();"/>
<spacer/>
<button label="Selection Count" onclick="return GetSelectionCount();"/>
<spacer/>
<button label="Selections" onclick="return GetSelections();"/>
<spacer/>
<button label="Remove" onclick="return Remove();"/>
<spacer/>
</box>
</box>
</window>

JavaScript code that supports the operations described above uses the DOM to locate the item (e.q., search based on ID), then calls functions implemented on the resulting object, as usual. Here is the JavaScript for the buttons shown in the screen shot:

function Add()
{
dump("Inside of list.js::Add\n");
var obj = document.getElementById("gridlisttest");
if (obj) {
obj.addItem("Mozart", 1);
}
}

function Append()
{
dump("Inside of list.js::Append\n");
var obj = document.getElementById("gridlisttest");
if (obj) {
obj.appendItem("Amadeus");
}
}

function Remove()
{
dump("Inside of list.js::Remove\n");
var obj = document.getElementById("gridlisttest");
if (obj) {
obj.removeItemByPosition(1);
}
}

function GetSelectionCount()
{
dump("Inside of list.js::Remove\n");
var obj = document.getElementById("gridlisttest");
if (obj) {
var count = obj.getSelectionCount();
dump("Selection count is " + count + "\n");
}
}

function GetSelections()
{
var obj = document.getElementById("gridlisttest");
if (obj) {
var i;
for (i = 0; i < obj.getSelectionCount(); i++) {
var sel = obj.getSelection(i);
dump("Selection " + i + " is " + sel + "\n");
}
}
}

0 Comments:

Post a Comment

<< Home