Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Table View and grids



Hi Philip,

Wow! Again many thanks for that help and the time you invested. I do understand now, and it's also easy to implement now. 
Here the code if it would help anybody
(given a popup with "No Grid, Vertical Grid, Horizontal Grid, Vertical & Horizontal Grid")
on action theObject
call method "setGridStyleMask:" of theTable with parameter (content of theObject)
end

(given a matrix with buttons "Vertical, Horizontal" where vertical has a tag 1 and horizontal has a tag 2)
on clicked theObject
set vGrid to ((content of cell 1 of theObject) as integer) * (tag of cell 1 of theObject)
set hGrid to ((content of cell 2 of theObject) as integer) * (tag of cell 2 of theObject)
call method "setGridStyleMask:" of theTable with parameter (vGrid + hGrid)
end clicked

(given a matrix with buttons "A, B, …" where tags start at 0)
on clicked theObject
set theP to 0
repeat with i from 1 to …
set theResult to ((content of cell i of theObject) as integer) * (2 ^ (tag of cell i of theObject))
set theP to the theP + theResult
end
end clicked


What good book on the C language (as for a dummy/beginner) do you recommend?

Kind regards
Andreas

On 04.06.2006, at 13:32, Philip Aker wrote:

On 2006-06-03, at 18:09:35, Andreas Kiel wrote:

The below is just what I found and where I failed. Your mail made me just try 0,1,2,3 as parameters and that worked. But I still don't understand the below description of setting parameters

Hi Andreas,

enum {
    NSTableViewGridNone = 0,
    NSTableViewSolidVerticalGridLineMask = 1 << 0,
    NSTableViewSolidHorizontalGridLineMask = 1 << 1
};

setGridStyleMask takes an unsigned int parameter so you should be able to get by with the number 1 to specify vertical grid only.

A full description of what I think you need to know is best left to a good book on the C language. 

A 'mask' value refers to the setting of specific bits in an integer value. One or more mask values are bitwise inclusive OR'ed together to form a 'flag' value. This 'flag' is an integer value which is passed as a parameter to a C language function. The purpose of the flag parameter is to indicate 0 or more choices the function will branch on to compute its result.

The mask values are determined by calculating what the value of an integer would be if certain bits are turned on. The easiest way to visualize this is to run through the bits in the integer sequentially starting from bit 0. So lets say we have a 4 bit integer. Then the computed values from any one of it's bits being ON are:

Bit 0 ON = 1
Bit 1 ON = 2
Bit 2 ON = 4
Bit 3 ON = 8

You can see that each value is unique, and furthermore, that each of these values when added to any of the other values will give a unique value. The convention to define the mask values for the grid style in NSTableView uses the binary left shift operator (<<).

We can see the integer value of any mask value like those which have been defined above easily in Terminal by using the expr procedure from the Tcl language. Invoke the Tcl interpreter tclsh like so:

[me]# tclsh
% expr 1 << 0
1
% expr 1 << 1
2
% expr 1 << 2
4
% expr 1 << 3
8
% exit
[me]#

So finally, we can notice that the computed value for NSTableViewSolidVerticalGridLineMask is 1 and the value for NSTableViewSolidHorizontalGridLineMask is 2. If our situation requires both horizontal and vertical grid lines, then we can supply the flag (gridStyle) in any of the C languages by using the bitwise OR operator (|) to add the two mask values:

unsigned int gridStyle = NSTableViewSolidVerticalGridLineMask | NSTableViewSolidHorizontalGridLineMask;

But, since AppleScript is brain dead when it comes to bitwise operations, we have to compute the values manually to use them in scripts. That's one area where the traditional scripting languages like Tcl and Perl are much better.

HTH,

Philip Aker
philip->vcn.dot.bc.dot.ca





 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden

References: 
 >Table View and grids (From: Andreas Kiel <email@hidden>)
 >Re: Table View and grids (From: Philip Aker <email@hidden>)
 >Re: Table View and grids (From: Andreas Kiel <email@hidden>)
 >Re: Table View and grids (From: Philip Aker <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.