Page History
...
Window and control styles are designed as bitmasks. Each style typically uses one bit of the STYLE property, and is either set (1) or not set (0). To set a style, you bitor the current style with the style that you want to add. For example, the following subroutine could be used to set a specific style for a specific control:
Code Block |
---|
subroutine SetStyle(CtrlEntID, AddStyle) declare function Get_Property declare subroutine Set_Property * get the current style Style = Get_Property(CtrlEntID, "STYLE") * the style property can be in hex format but bitor only works with decimal integers if Style [1,2] _eqc "0x" then convert @lower.case to @upper.case in Style Style = iconv(Style [3,99], "MX") end * add the new style Style = bitor(Style, AddStyle) Set_Property(CtrlEntID, "STYLE", Style) return |
To clear a style, you bitand the current style with all styles but the style that you are removing. The following subroutine could be used to clear a specific style for a specific control:
...
Code Block |
---|
subroutine ClearStyle(CtrlEntID, RemoveStyle) declare function Get_Property declare subroutine Set_Property * get the current style Style = Get_Property(CtrlEntID, "STYLE") * the style property can be in hex format but bitor only works with decimal integers if Style [1,2] _eqc "0x" then convert @lower.case to @upper.case in Style Style = iconv(Style [3,99], "MX") end * remove the specified style Style = bitand(Style, bitnot(RemoveStyle)) Set_Property(CtrlEntID, "STYLE", Style) return |
...
To test if a style is set, use the bitand function on the current style with the style that you are looking for. The following function could be used to test if a style is set for a specific control:
Code Block |
---|
function IsStyleSet(CtrlEntID, TestStyle) declare function Get_Property declare subroutine Set_Property * Get the current style Style = Get_Property(CtrlEntID, "STYLE") * the style property can be in hex format but bitor only works with decimal integers. if Style [1,2] _eqc "0x" then convert @lower.case to @upper.case in Style Style = iconv(Style [3,99], "MX") end * check for the specified style bExists = (bitand(Style, TestStyle) > 0) return bExists |
Some styles cannot be set or cleared using the STYLE property. This is due to how the controls are implemented internally. Because of this, save your work before testing style changes. For styles that can not be set or cleared, you must destroy the control and re-create it with the desired style. Although this sounds difficult, the following example can be modified and used for almost all cases. Also the TABBED_TEMPLATE form in the Examples application uses a similar method to change bitmap check-boxes into bitmap radio buttons in the CREATE event.
...
Code Block |
---|
/* this code snippet changes a bitmap control into a control that displays system icons, as displayed in Windows messages; this code is from the message designer in the UI Workspace(PSPOS_BITMAP$ can be INFO, QUESTION, EXCLAMATION, and HAND) */ $insert PS_Equates Struct = Get_Property(CtrlEntID, "ORIG_STRUCT") Struct<1, PSPOS_SDKSTYLE$> = "0x50000003" Struct<1, PSPOS_BITMAP$ > = "INFO" Struct<1, PSPOS_VISIBLE$ > = TRUE$ Struct<1, PSPOS_PSSTYLE$ > = "" Utility("DESTROY", CtrlEntID) Utility("CREATE", Struct) * Here is another example which changes the justification of an edit control: * This code snippet assumes that the variable Just is set to L, R, or C (left, right or center) $insert PS_Equates equ ES_LEFT to 0 equ ES_CENTER to 1 equ ES_RIGHT to 2 /* since the control is going to be destroyed then recreated, get the current text value so it isn't lost */ Text = Get_Property(CtrlEntID, "TEXT") Style = Get_Property(CtrlEntID, "STYLE") Struct = Get_Property(CtrlEntID, "ORIG_STRUCT") if Style [1,2] _eqc "0x" then convert @lower.case to @upper.case in Style Style = iconv(Style [3,99], "MX") end * first turn off left, right, and center justification All = bitor(ES_LEFT, bitor(ES_CENTER, ES_RIGHT)) Style = bitand(Style, bitnot(All)) * next, turn on specific justification style begin case case Just = "L" AddStyle = ES_LEFT case Just = "C" AddStyle = ES_CENTER case Just = "R" AddStyle = ES_RIGHT end case Style = bitor(Style, AddStyle) * next, destroy and recreate the control with the new just Struct<1, PSPOS_SDKSTYLE$> = Style Struct<1, PSPOS_TEXT$ > = Text Utility("DESTROY", CtrlEntID) Utility("CREATE", Struct) |