Contributed by: Wayne Swanson
VisPro gives you the option of changing the behavior of controls used in the program via the call to VpItem with "SetStyleWord." StyleWords can be changed via "SetStyleBit" also but we'll cover that one another day.
Most of the StyleWord and StyleBit information can be found in the OS/2 Toolkit. If it seemed a mystery to you, here is a peek into it's use using a button as an example.
From the toolkit in the PmWin.h file we find the "No border" style for buttons:
BS_NOBORDER = 0x1000
To use this, we "could" just add it (the decimal equivalent) to the buttons existing StyleWord if no other styles were set but what if this or some other style is already set? By using the "BitOr" bif from rexxutil, we can conditionally add the style to a button. In other words, if the style "bit" for BS_NOBORDER is already set, using BitOr will leave it set or set it if it wasn't already no matter how many times you or someone else fiddles with it.
Let's assume that we want to have a button (ID = 1000) with no border. Start by defining the BS_NOBORDER value (we'll do this in decimal later for Vp's sake) and obtaining the current StyleWord of the button.
BS_NOBORDER = '1000'x
ButtonStyle = VpItem(window, 1000, 'GETSTYLEWORD')
VisPro returns StyleWords in decimal format so we need to convert it to binary format and "BitOr" it with the binary BS_NOBORDER value. We will also have to allow for the math to work past the usual 9 digits allowed by rexx and up that to "Numeric Digits 10" for the value we calculate to send back as the button StyleWord.
Numeric Digits 10
OldStyle = x2b(d2x(ButtonStyle))
OldStyle is now the binary representation of the button StyleWord. Lets get the binary value of BS_NOBORDER next.
BS_NOBORDER = Right(BS_NOBORDER,8,'0')
NewStyle = x2b(BS_NOBORDER)
Notice that we checked the length of the hex value of BS_NOBORDER and padded the left side of it with 0's before we converted it to binary to be sure we had a full 32 bits in the binary representation of the additional information for the new StyleWord.
Now we can use "BitOr" to set the StyleBit in the new StyleWord. Following that, we'll convert it to decimal and then make the call back to set the new StyleWord.
_or = BitOr(OldStyle,NewStyle)
ButtonStyle = x2d(b2x(_or))
Call VpItem window, 1000, 'SETSTYLEWORD', ButtonStyle
This is all well and good but in practice you may want to have a separate subroutine to do most of the work for you so all you have to do is call it with two values and use the returning value to set the new StyleWord. Here is an example you can use that sets two styles on a button. Paste the following code into the "When opened" event of a test program, copy the subroutine into your "SubProcs" directory and see if it works.
Notice that we are defining the BS_NOBORDER value as a decimal number here to aid in passing parameters to a subroutine.
/***********************************************************/
/******************* Set Button style **********************/
/* Drag a button to the canvas and set it's ID to 1000 */
/* Place this section of code in the "When opened" event */
/***********************************************************/
BS_NOBORDER = x2d('1000')
BS_NOPOINTERFOCUS = x2d('0800')
ButtonStyle = VpItem(window, 1000, 'GETSTYLEWORD')
ButtonStyle = NewStyleWord(ButtonStyle,BS_NOBORDER)
ButtonStyle = NewStyleWord(ButtonStyle,BS_NOPOINTERFOCUS)
Call VpItem window, 1000, 'SETSTYLEWORD', ButtonStyle
/***********************************************************/
/***********************************************************/
/********************* NewStyleWord ************************/
/* Place this section in your "SubProcs" directory */
/* */
/* OldWord = decimal representation of existing StyleWord */
/* NewStyle = decimal representation of new style */
/* Example: value = NewStyleWord(OldWord, NewStyle) */
/* */
/* Returns decimal representation of new StyleWord */
/***********************************************************/
NewStyleWord: PROCEDURE
parse arg OldWord, NewStyle
Numeric Digits 10
NewStyle = d2x(NewStyle,8)
value1 = x2b(d2x(OldWord))
value2 = x2b(NewStyle)
value = BitOr(value1,value2)
return x2d(b2x(value))
/***********************************************************/
In the above:
The "Newstyle=" line could be merged with the "value2 =" line easily but it is more clearly shown this way. The merged line would look like this:
value2 = x2b(d2x(NewStyle,8))
Or... for REAL fun and if you want to REALLY obfuscate it you could eliminate everything after the "Numeric Digits 10" line and just use a return value like this:
return x2d(b2x(BitOr(x2b(d2x(OldWord)),x2b(d2x(NewStyle,8)))))
I haven't actually used this line to test it but it "looks" correct... :-)