User:CBM-c-/VS-List Browsers part 1: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
(expand)
 
(32 intermediate revisions by the same user not shown)
Line 4: Line 4:




= Creation and columns =
Some of you know me as Orso from the now defunct Vectorlab, I maintained it for many years. Here is the List Browsers article from the former Vectorlab site. For better understanding please use the comprehensive example at [[User:CBM-c-/Dialog with List Browser| Dialog with List Browser]].


For better understanding please use the comprehensive example at [[User:CBM-c-/Dialog with List Browser| Dialog with List Browser]].
By --[[User:CBM-c-|_c_]] 01:31, 31 December 2020 (EST),
By --[[User:CBM-c-|_c_]] ([[User talk:CBM-c-|talk]]) 03:08, 31 December 2020 (EST) (previously Orso B. Schmid)
previously Orso.B.Schmid, 2009-2018.




{| class="wikitable" style="margin: auto;"
= List Browsers =
|-
! [[User:CBM-c-/VS-List_Browsers| Introduction]]
! List_Browsers_part_1
! [[User:CBM-c-/VS-List_Browsers_part_2| List_Browsers_part_2]]
|}


List Browsers allow for great layout, advanced data management, but also amazing layout features within the single cells. Is not difficult to load them with some text data and make them display a whatever list. Still the advanced settings of List Browsers are quite enigmatic. After years of trial and error, I attempt here to resume what I discovered. If you find an error, I'd be glad to be informed. I am a user and had no reference literature for this article which is based on pure experience, if you are a programmer you will probably find the terms employed not quite the right ones.


== Create a List Browser ==
Since List Browsers are so complex, the best way to learn how to use them is to have some free code available for experiments. Free code for List Browsers can be counted on one hand and none of the snippets available tells you a single thing about Control Types, Edit Display Types, Item Display Types, Column Data Items and so on.


List Browsers are called in a Layout Creation routine with [[VS:CreateLB]].
Use the example [[User:CBM-c-/Dialog with List Browser| Dialog with List Browser]] to experiment with the List Browser's options.


<code lang="pas">
CreateLB(dialogID: LONGINT; componentID: LONGINT;
widthInCharacters: INTEGER; heightInCharacters: INTEGER);
</code>


; '''widthInCharacters''', '''heightInCharacters''': is different between Mac and PC. Basically on Mac all dialog items with a scroll bar interpret the width excluding the bar. This will influence the width of dialog elements such as PullDown menus, List Browsers, Lists and such. These items won't align with Static Text, Edit fields and similar: the scroll bar will be outside alignment. You must correct the width programmatically.


{| class="wikitable" style="margin: auto;"
|-
! [[User:CBM-c-/VS-List_Browsers_part_1| Part 1: Creation]]
! [[User:CBM-c-/VS-List_Browsers_part_2| Part 2: Columns]]
! [[User:CBM-c-/VS-List_Browsers_part_3| Part 3: Rows and Cells]]
! [[User:CBM-c-/VS-List_Browsers_part_4| Part 4: Events]]
|}


=== List Browsers in resizable dialogs ===
== Introduction ==


List Browsers are special dialog items with a built-in binding to their parent container. If a dialog is resizable, they resize width and height automatically, without any [[VS:SetEdgeBinding| Edge Binding]]. For this reason you'll prefer to leave List Browsers outside groups: they will fit beautifully to the dialog window without you to bother.
The display of List Browsers is determined by the right combination of four settings: Control Type, Display Type, Cell's Column Owner, Column Data Items.


<code lang="pas">
This is all rather difficult, specially because it is not documented. It resembles a 4D-puzzle.
dlog := CreateResizableLayout('List Browsers test', TRUE, 'Close', '', TRUE, FALSE);
{ ... }
CreateLB(dlog, cLB, cLBWidth, cLBHeight);
</code>




== Load a List Browser ==
{| class="wikitable" style="margin: auto;"
|-
! colspan="3"| [[User:CBM-c-/VS-List_Browsers_part_2#Column_Data_Items| Column Data Items]]
! List Browser set up


Your List Browser after creation is just an empty container without columns, rows or any data. Before loading the List Browser it is important to understand what needs to be loaded once and if there are things that needs to be loaded repeatedly, after destroying data. Aside of images, which must be really loaded only once, all other List Browser elements can be loaded, destroyed, created or modified according to your needs. The typical script will set up a List Browser once in [[VS:Creating_a_Custom_Dialog_Box| SetupDialogC]] and manipulate repeatedly only rows data. Usually you will:
|-
| colspan="3" style="text-align: center;"| Icons, Strings
| rowspan="4" |
* [[#Create_a_List_Browser|  Create a List Browser]]
* [[#Icon List|  Create a List of Icons]] (optional)
* [[User:CBM-c-/VS-List_Browsers_part_2#Columns|  Create columns]]
*: For each column:
*: [[User:CBM-c-/VS-List_Browsers_part_2#Control_Type|  Set Control Type]] (optional)
*: [[User:CBM-c-/VS-List_Browsers_part_2#Display_Type| Set Display Type]] (optional)
*: [[User:CBM-c-/VS-List_Browsers_part_2#Column_Data_Items_List|  Create a List of Column Data Items]] (optional)


* add Icons always only once
* [[User:CBM-c-/VS-List_Browsers_part_3#Rows_and_Cells|  Insert rows]]
* add Columns most times once
*: For each row loop down all columns
* add Column Data Items most times only once
*: and set for each cell:
* add/delete/modify Cells repeatedly
** [[User:CBM-c-/VS-List_Browsers_part_2#Column_Owner_Type|  Column Owner Type]] (optional)
** cell values:
*** string and/or image, or
*** item from a [[User:CBM-c-/VS-List_Browsers_part_2#Column_Data_Items_List|  List of Column Data Items]] (optional)


Then you'll organize your loading code as follows:
|-
! colspan="2" | [[User:CBM-c-/VS-List_Browsers_part_2#Column|  Column]]
!  [[User:CBM-c-/VS-List_Browsers_part_3#Rows_and_Cells|  Cell]]


* needs loading once --> has a place in the SetupDialogC CASE item of your dialog driver routine
|-
* needs loading repeatedly --> resides in a subroutine with wider validity scope (including SetupDialogC for the first run).
! [[User:CBM-c-/VS-List_Browsers_part_2#Control_Type|  Control Type]]
 
display HOW
 
=== Items and Sub-items (0-based) ===
 
At start the main difficulty in understanding List Browsers is caused by the naming of the various routine parameters. Everyone will struggle initially with "itemIndex" and "subItemIndex", sometimes also called (more clearly) "columnIndex". The official documentation uses names not consequently. Just some examples:
 
 
<code lang="pas">
GetLBItemInfo(dialogID: LONGINT; componentID: LONGINT; itemIndex: INTEGER; subItemIndex: INTEGER;
VAR itemString: STRING; VAR imageIndex: INTEGER): BOOLEAN;
 
GetLBItemData(nDialogID, nComponentID :LONGINT; nItemIndex, nSubItemIndex :INTEGER;
VAR nUserData :LONGINT);
 
InsertLBColumn( dialogID:LONGINT; componentID:LONGINT; columnIndex:INTEGER;
headerString:STRING; width:INTEGER):INTEGER;
</code>
 
;  row index: itemIndex, nItemIndex
; column index: subItemIndex, nSubItemIndex, columnIndex
If you see both parameters for row and for column you know that you'll target a cell (intersection of row and column).
 
All indexes in List Browsers are 0-based:
 
* [[#Icon (List)| Icons]]
* [[#Column Data Items (list)| Column Data Items]]
* [[#Columns| Columns]]
* [[#Rows and Cells| Rows and Cells]]
 
This implies that for setting the absence of an image -for example- you need to pass "-1". Take care to init your variables to -1. Mind the routine AddLBImage which on Mac might return "0" also if it failed to insert an image.
 
Many mistakes in List Browsers are caused by unwanted 0-indexes in images or Column Data Items.
 
 
== Icon (List) ==
 
Very relevant for the layout of a List Browser is the list of icons (optional). Here you store small icons that will be available to the whole List Browser. The icons must be either loaded from external resource files or recycled among the built-in Vectorworks icons. They can be used directly from the singular cells and/or be used to build data in the List of Data Items of a column. An Icon List can be created using [[VS:AddListBrowserImage]].
 
There is a single routine allowing to load icon resources without pre-loading them in the Icon List first: [[VS:SetLBImageIndexes]], which applies only to columns with control type Multiple Icons.
 
To my knowledge, once loaded the original indexes of the icon-resources are lost: for example it's not possible to fetch the original resource index of icon "2" in the Icon List and substitute it with something else. This is only possible on Mac using columns of type Multiple Icons when they are loaded with [[VS:SetLBImageIndexes]], but I didn't try this with the new routine, only with its precursor: SetLBMultImageIndexes (obsolete).
 
It's also not possible to delete the image-list from the List Browser, once created. For this reason images must be loaded only once In SetupDialogC and attention be paid that [[VS:AddListBrowserImage]] doesn't land in any repetitive routine: this would add the same image over and over again, each time increasing the index count.
 
The sequence defined by adding images is not relevant if you need the icons for singular cells or for a List of Data Items, but becomes very important if your icons need to be displayed in Radio columns, since this control follows the insertion order of the Icon List precisely.
 
<code lang="pas">
AddListBrowserImage(dialogID: LONGINT; listBrowserID: LONGINT; imageSpecifier: DYNARRAY[] of CHAR): INTEGER;
</code>
 
; imageSpecifier: the path to the image resource (since VW 2104), for example: 'Vectorworks/ResourceBrowser/WallStyle.png'.
: I prefer to "borrow" icons from the application self, where there is a very large choice: loading resources from Vectorworks spares you the creation of your own resource file[s]. The application ships with a huge number of icons and you always find something that fits your needs.
 
; result (0-based): the index of the newly inserted icon. This increases at each newly inserted icon. Once added, images cannot be deleted and stay with the List Browser until script ends. For this reason Images should be added to the List Browser only once. This is best done in the SetupDialogC section of the dialog driver.
: Since the index is 0-based you should remember later to use "-1" for telling cells not to use images. Whenever you see a routine allowing for an image index (for example [[VS:SetLBItemInfo]]) and you don't want an image to load, set the image index parameter to "-1". A typical mistake is to write "0", which will load the first image in the LB, if any loaded. If you didn't load images into your LB previously, you don't need to bother much.


! [[User:CBM-c-/VS-List_Browsers_part_2#Display_Type|  Display Type]]
display WHICH DATA


=== Example: toggling only three images ===
! [[User:CBM-c-/VS-List_Browsers_part_2#Column_Owner_Type|  Column Owner Type]]
display WHAT


<div style="margin: 1em; border: dotted 1px #aaa; padding: 1em; background-color: #F2F2F2;">
<code lang="pas">
{ add three images to a List Browser }
gImgCnt := -1; { init }
gImgCnt := AddListBrowserImage(gD, cLB_Styles, 'Vectorworks/Standard Images/Visible'); { visible: black eye }
gImgCnt := AddListBrowserImage(gD, cLB_Styles, 'Vectorworks/Standard Images/Invisible'); { invisible: cross }
</code>
[[File:c_LB_toggleImgs.png| left| Toggle Images]]
Since we know that the list starts at zero and the counter always increases by 1, we store the final index in the variable "gImgCnt". If something goes wrong, we have the needed "-1" value to declare the lack of images. To access them later we'll only need to subtract to this variable. You might prefer to access indexes in this fashion whenever your script uses only few images.
</div>
== Columns ==
After creating an (optional) [[#Icon (List)| List of icons]] you can proceed to add columns to the List Browser. While creating each column, it is simple to set immediately its appearance and eventually some modifiers which affect -it goes without saying- the whole column and all cells there included. A column creates ready to display text which doesn't react on clicks. Any other display involves a resetting of [[#Control Type| Control Type]] and [[#Display Type| Display Type]].
Most of the times you create columns only at dialog setup and in a loop. If you do it only once -because you won't delete columns later- the loop needs a place in '''SetupDialogC''' and nowhere else. Nothing forbids you, though, to delete columns and redo them according to your script needs. In this case you'll have the column creation in a sub-routine callable on demand with a wider script scope. But is seldom.
{| class="wikitable" style="margin: auto;"
! Settings !! Modifiers !! Column set up
|-
|-
|  
|  
* [[#Column Titles| Titles]]
# [[User:CBM-c-/VS-List_Browsers_part_2#Static|  Static]]
* [[#Column Lines| Column Lines]]
# [[User:CBM-c-/VS-List_Browsers_part_2#Radio| Radio]]
* [[#Sorting| Column Sorting]]
# [[User:CBM-c-/VS-List_Browsers_part_2#Multi_State| Multi State]]
# [[User:CBM-c-/VS-List_Browsers_part_2#Single_Instance_Icon|  Single Instance Icon]]
# [[User:CBM-c-/VS-List_Browsers_part_2#Static_icon|  Static icon]]
# [[User:CBM-c-/VS-List_Browsers_part_2#Number| Number]]
# [[User:CBM-c-/VS-List_Browsers_part_2#Multiple_Icons| Multiple Icons]]


|
|
* [[#Control Type| Control Type]]
# Image
* [[#Display Type| Item or Edit Display Type]]
# Text only
* [[#Column Data Items| List of Column Data Items]]
# Image and Text


|
|
Insert columns using [[VS:InsertLBColumn]]. Set for each column:
:  0. [[User:CBM-c-/VS-List_Browsers_part_3#None|  None]]
* [[#Column Titles| title appearance]]
# [[User:CBM-c-/VS-List_Browsers_part_3#Solid_rect| Solid rect]]
* if modifiers are needed, also set up:
# [[User:CBM-c-/VS-List_Browsers_part_3#Dual_solid_rect|  Dual solid rect]]
** [[#Control Type| Control Type]] (optional)
# [[User:CBM-c-/VS-List_Browsers_part_3#Pattern_and_Dual_Pattern| Pattern rect]]
** [[#Display Type| Item or Edit Display Type]] (optional)
# [[User:CBM-c-/VS-List_Browsers_part_3#Pattern_and_Dual_Pattern| Dual pattern rect]]
** [[#Column Data Items| List of Column Data Items]] (optional)
# [[User:CBM-c-/VS-List_Browsers_part_3#Gradients_and_Images| Gradient or image]]
 
# [[User:CBM-c-/VS-List_Browsers_part_3#Blank| Blank]]
Outside any loop set for the whole List Browser:
# [[User:CBM-c-/VS-List_Browsers_part_3#Text| Text]]
* [[#Column Lines| Column Lines]] (optional)
# [[User:CBM-c-/VS-List_Browsers_part_3#Dashed_line| Dashed line]]
* [[#Drag and Drop| Drag and Drop Column]] (optional)
* [[#Sorting| Sort Column]] column (optional)
|}
|}


<code lang="pas">
GetNumLBColumns( dialogID:LONGINT; componentID:LONGINT):INTEGER;
</code>


Count of columns present in a List Browser. You will use this call while adding or relating to columns. Remember to decrease the count of columns of -1, if you use it as column index reference, since -again- column indexes are 0-based
[[File:c_LB_NNAclasses.png| center]]


<code lang="pas">
== Lists Validity Scope ==
InsertLBColumn( dialogID:LONGINT; componentID:LONGINT; columnIndex:INTEGER;
headerString:STRING; width:INTEGER):INTEGER;
</code>


Inserts a column ready to be filled with text cells. Call [[VS:InsertLBColumn]] for each column to be inserted, use the returned index for further column settings. Defaults upon creation are:
List Browsers are more than tables of cells, they browse lists. You must imagine them like special containers with built-in lists of data which can be created and used on need. These lists have different validity scope.


* [[#Control Type| Control Type]]: Static = 1
; List of icons: available to the whole List Browser.
* [[#Item Display| Item Display]]: Text Only = 2 (Upon creation the Display type is "0", however the reason)


; result (0-based): index of the new column in the List Browser.
; Column Data Items: available to one column. Column Data Items will often use images from the List Browser's Image list, but they can also contain only strings.
; columnIndex: at which position in the List Browser the column should be inserted.
: ''BUG: passing "0" as insertion position the title will center after the first row. Moreover in VW 13 if the List Browser has icons loaded, an icon will unexpectedly appear in the title. For this reason is always wise to insert new columns only at the end using GetNumLBColumns.''
; headerString: the column's title (string). The title aligns left by default. If a different alignment is needed it can be fixed later with [[VS:SetLBColumnHeaderJust]].
; width: the width of the column. Can be modified anytime using [[VS:SetLBColumnWidth]]. Don't pass a zero width.


<code lang="pas">
GetLBColumnWidth( dialogID:LONGINT; componentID:LONGINT; columnIndex:INTEGER;
VAR width:INTEGER):BOOLEAN;
SetLBColumnWidth( dialogID:LONGINT; componentID:LONGINT;
fromColumn:INTEGER; toColumn:INTEGER; width:INTEGER):BOOLEAN;
</code>


; fromColumn, toColumn: the range of columns where the width should apply. Mind that the title seems to create a large white space at the end. You should dimension columns rather large otherwise they won't display the whole title text. Under VW 14+ you can use [[VS:GetLBHeaderTextWidth]] to dimension precisely your column width.
== Create a List Browser ==
Often you'll create columns in a loop from string arrays or external files data. In this case you insert the columns with some default width and reset precisely only those columns that need to be different.
: ''BUG: Column widths "0" crash VW 13 (fixed by build 87094). You must programmatically avoid them and also make sure that your user is not in the position of resizing them to zero, if you wish to grant compatibility with VW 13.''
 
<code lang="pas">
GetLBHeaderTextWidth(className: STRING; allowForSortIcon: BOOLEAN): INTEGER ;
</code>


(VW14+) returns the column width needed to fit the column title without resizing. There is a parameter "allowForSortIcon". I didn't try this call yet.
List Browsers are called in a Layout Creation routine with '''CreateLB'''.
 
 
=== Column Titles ===
 
Frequently an array of string is a good way to create the titles in a loop. Other times data will be loaded from external files or from existing document objects. Whatever system you choose, you shall remember that column titles cannot be changed after creation. In order to change a column's title the only solution is to destroy the column and recreate it. This can be done with [[VS:DeleteLBColumn]].


<code lang="pas">
<code lang="pas">
SetLBColumnImage(nDialogID, nComponentID :LONGINT;  
CreateLB(dialogID: LONGINT; listBrowserID: LONGINT;  
nColumnIndex, nImageIndex :INTEGER) :BOOLEAN;
widthInCharacters: INTEGER; heightInCharacters: INTEGER);
</code>
</code>


; result: FALSE if the column index "nColumnIndex" points to a column that doesn't exists. Note that the routine doesn't return false if the icon index "nImageIndex" points to a missing icon.
[[VS:CreateLB]] Creates an empty List Browser with no rows and no columns.
; nImageIndex: Use an icon as column title. This replaces the text, you cannot have both text and icon. The image must available in the List Browser's Icon List.


<code lang="pas">
; '''widthInCharacters''', '''heightInCharacters''': is different between Mac and PC. Basically on Mac all dialog items with a scroll bar interpret the width excluding the bar. This will influence the width of dialog elements such as PullDown menus, List Browsers, Lists and such. These items won't align with Static Text, Edit fields and similar: the scroll bar will be outside alignment. You must correct the width programmatically.
GetLBColumnHeaderJust( dialogID:LONGINT; componentID:LONGINT; columnIndex:INTEGER;  
VAR justification:INTEGER):BOOLEAN;
SetLBColumnHeaderJust( dialogID:LONGINT; componentID:LONGINT; columnIndex:INTEGER;
justification:INTEGER):BOOLEAN;
</code>


Modify the alignment of the column title. Use following constants:
: 1 = Left
: 2 = Center
: 3 = Right


<code lang="pas">
=== List Browsers in resizable dialogs ===
GetLBColumnHeaderToolTip( dialogID:LONGINT; componentID:LONGINT; columnIndex:INTEGER;
VAR toolTipPrimaryText:STRING; VAR toolTipSubText:STRING):BOOLEAN;


SetLBColumnHeaderToolTip( dialogID:LONGINT; componentID:LONGINT; columnIndex:INTEGER;
List Browsers are special dialog items with a built-in binding to their parent container. If a dialog is resizable, they resize width and height automatically, without any [[VS:SetEdgeBinding| Edge Binding]]. For this reason you'll prefer to leave List Browsers outside groups: they will fit beautifully to the dialog window without you to bother.
toolTipPrimaryText:STRING; toolTipSubText:STRING):BOOLEAN;
justification:INTEGER):BOOLEAN;
</code>
 
Gets/sets hovering tips for the column headers. Setting tool tips is quite handy when the column width will certainly be too small and titles will be cropped: pass then titles as tool tip.
 
; toolTipPrimaryText: text appearing on hovering over the column title.
; toolTipSubText: text appearing pressing the cmd/alt (Mac/Win) key while hovering.
: ''BUG: don't use GetLBColumnHeaderToolTip if you plan to use your script on VW 13. It crashes VW under Mac (fixed by VW 14, built 90067).''
 
 
=== Column Lines ===
 
Column lines are the gray vertical lines drawn between each column. They are optional. Columns with control type [[#Radio| Radio]] have an extra option for setting the sub-titles column lines.


<code lang="pas">
<code lang="pas">
AreLBColumnLinesEnabled(dialogID: LONGINT; componentID: LONGINT): BOOLEAN;
dlog := CreateResizableLayout('List Browsers test', TRUE, 'Close', '', TRUE, FALSE);
{ ... }
CreateLB(dlog, lb, lbWidth, lbHeight);
</code>
</code>


Checks on/off status of column lines for a List Browser.


<code lang="pas">
== Load a List Browser ==
EnableLBColumnLines(dialogID: LONGINT; componentID: LONGINT;
enableColumnLines:BOOLEAN);
</code>


Default: FALSE. Toggles the vertical column lines on/off. It affects a whole List Browser, so this call shall be kept outside repetitive routines. Usually it is called at the end of the List Browser setup routine. Don't confuse it with [[VS:EnableLBRadioColumnLines]].
Your List Browser after creation is just an empty container without columns, rows or any data. Before loading the List Browser it is important to understand what needs to be loaded once and if there are things that needs to be loaded repeatedly, after destroying data. Aside of images, which must be really loaded only once, all other List Browser elements can be loaded, destroyed, created or modified according to your needs. The typical script will set up a List Browser once in [[VS:Creating_a_Custom_Dialog_Box| SetupDialogC]] and manipulate repeatedly only rows data. Usually you will:


<code lang="pas">
* add [[#Icon List| Icons]] always only once
AreLBRadioColumnLinesEnabled(dialogID: LONGINT; componentID: LONGINT; columnIndex: INTEGER): BOOLEAN;
* add [[User:CBM-c-/VS-List_Browsers_part_2#Columns| Columns]] most times once
</code>
* add [[User:CBM-c-/VS-List_Browsers_part_2#Column Data Items List| Column Data Items]] most times only once
* add/delete/modify [[User:CBM-c-/VS-List_Browsers_part_3#Rows and Cells| Rows and Cells]] repeatedly


(only for control type [[#Radio| Radio]]) Checks on/off status of the sub-column lines for a chosen radio column. Note that this applies to a column, not to the whole List Browser as AreLBColumnLinesEnabled.
Then you'll organize your loading code as follows:


<code lang="pas">
* needs loading once --> has a place in the [[VS:Creating_a_Custom_Dialog_Box| SetupDialogC]] CASE item of your dialog driver routine
EnableLBRadioColumnLines(dialogID: LONGINT; componentID: LONGINT; columnIndex: INTEGER;
* needs loading repeatedly --> resides in a subroutine with wider validity scope (including [[VS:Creating_a_Custom_Dialog_Box| SetupDialogC]] for the first run).
enableRadioColumnLines: BOOLEAN);
</code>


Default: FALSE. (only for control type [[#Radio| Radio]]) Draws extra gray vertical lines for each sub-column in the chosen Radio column. For this to show you need:


* Column with control type [[#Radio| Radio]]
=== Items and Sub-items, index (0-based) ===
* [[#Column Data Items (list)| List of Column Data Items]]
This is applied on column index basis. Most of the times only a single Radio column is needed in a List Browser, so you'll choose to enable the radio vertical lines at the end of -and outside- the column creation loop (if any).


At start the main difficulty in understanding List Browsers is caused by the naming of the various routine parameters. Everyone will struggle initially with "itemIndex" and "subItemIndex", sometimes also called (more clearly) "columnIndex". The official documentation uses names not consequently. Just some examples:


=== Column Data Items (List) ===
; row index: itemIndex, nItemIndex
; column index: subItemIndex, nSubItemIndex, columnIndex


If you're not a programmer -like me-, you'll struggle quite a bit to understand what Data Items are and above all what they do: they are items in a list of data. This list is available to the column where it's defined. I believe that a column can use only ONE list. At least in Vectorscript I could distinguish no access to multiple lists for a single column index.
If you see both parameters for row and for column you know that you'll target a cell (intersection of row and column).


Whenever you start using List Browsers, soon or later you have the burning wish to coerce cells to a certain list of values. If you could, you'd just love to insert a pull-down menu in your cell, perhaps one with images in it, but this is not possible. You have ''Column Data Items'' instead. These, once defined, are available column-wide. With Column Data Items you can coerce all cells in a column to show only values present in a list. Each list element is a ''Column Data Item''.
All indexes in List Browsers are 0-based:


[[File:c_LB_ColumnDataItemsImgs.png| right| Column Data Items]] For example you could wish to pair the string "visible" with the black-eye icon. Probably you would like to have more of these items, so you'll define also an item <string "invisible" with the cross icon> and <string "grayed" with the grayed-eye icon>. For each you need to create one ''Data Item'' using [[VS:InsertLBColumnDataItem]] (and you already loaded the icons in the List Browser's Icon List through [[VS:AddListBrowserImage]]).
* [[#Icon List| Icons]]
* [[User:CBM-c-/VS-List_Browsers_part_2#Column Data Items List| Column Data Items]]
* [[User:CBM-c-/VS-List_Browsers_part_2#Columns| Columns]]
* [[User:CBM-c-/VS-List_Browsers_part_3#Rows and Cells| Rows and Cells]]


Not all column's Control Types manage these lists, but for those who do, you will observe that cells using Column Data Items will stop being free and only display a range of Data Items values. For example: "visible, invisible, grayed" and/or show the respective images on user's click.
This implies that for setting the absence of an image -for example- you need to pass "-1". Take care to init your variables to -1. Mind the routine '''AddListBrowserImage''' which on Mac might return "0" also if it failed to insert an image.


The sequence in which you create the data items is relevant. ''Column Data Items'' build an indexed list whose order is used by the columns where you apply them. The behavior of your cells depends on the column's [[#Control type| Control Type]]. Moreover is influenced by the chosen column's [[#Display Type| Display Type]]. The only exception is the control [[#Radio| Radio]], which uses the insertion order of the Icon List.
Many mistakes in List Browsers are caused by unwanted 0-indexes in images or Column Data Items.
 
; On-click behavior: you can distinguish among column's controls which display their list of Column Data Items on click and those who don't. All cells can be loaded with one ''Column Data Item'' using [[VS:SetLBItemUsingColumnDataItem]], but only cells whose columns belong to [[#Multi State| Multi State]] and [[#Single Instance| Single Instance Icon]] will toggle Data items on click (even if they weren't pre-loaded using [[VS:SetLBItemUsingColumnDataItem]]). Radio columns do this too, but are a world on their own, please see [[#Radio| Radio]].
 
Column Data Items are to be used only on columns with control type [[#Multi State| Multi State]], [[#Single Instance| Single Instance Icon]] or [[#Radio| Radio]]. And -stating the obvious- you have no reason whatsoever to use these controls without Column Data Items. But in rare circumstances you might find comfortable to store hidden data in Column Data Items just to be able to fetch it on need even from columns whose click-response is not available, like Static.
 
; Control [[#Multi State| Multi State]] or [[#Single Instance| Single Instance Icon]]: you should always pre-load cells using with this control type with [[VS:SetLBItemUsingColumnDataItem]] in order to have proper start values. Don't use [[VS:SetLBItemInfo]]. This is particularly important for cells whose column has control type Single Instance Icon. Under circumstances you'll like to pre-load an empty image.
 
; Control [[#Radio| Radio]]: it has the peculiar behavior to load all images starting with the first defined in the Icon List, unregarded the icon indexes passed in [[VS:InsertLBColumnDataItem]]. It can only display images ignoring text altogether.
 
{| class="wikitable" style="margin: auto;"
|-
! colspan="3" | Column Data Items and Control Type
 
|-
! width="150px" | [[#Control_Type| Control Type]] || [[#Edit_Display| Edit Display]] || Response on click
 
|-
| 1 [[#Static| Static]]
| colspan="2" style="text-align: center;" |  &lt;doesn't respond&gt;
 
|-
| 2 [[#Radio| Radio]]
|
* Image
* Text and Image
 
| Shows multiple choices with icons, creates a sub-column for each call to [[#Column Data Items (list)| Manage the Data Items List]] [[VS:InsertLBColumnDataItem]], although it displays the [[#Icon (List)| Icons]], in a sequence. Upon clicking on a sub-column, the image corresponding to the sub-column index (0-based) will show. Is unable to display text.


|-
| 3 [[#Multi_State| Multi State]]
|
* any


| At each click displays the next Data Item by index in the list.
== Icon List ==


|-
Very relevant for the layout of a List Browser is the list of icons (optional). Here you store small icons that will be available to the whole List Browser. The icons must be either loaded from external resource files or recycled from the built-in Vectorworks icons. They can be used directly from the singular cells and/or be used to build data in the List of Data Items of a column. An [[#Icon List| Icon List]] can be created using '''AddListBrowserImage'''.
| 4 [[#Single_Instance_Icon| Single Instance Icon]]  
|
* any


| Upon clicking in a cell display "item 1" of the ''Data Item list''.
There is a single routine allowing to load icon resources without pre-loading them in the [[#Icon List| Icon List]] first: '''SetLBImageIndexes''', which applies only to columns with control type Multiple Icons.  
Any previous selection will be set to "item 0" in the list. Thus you'll have one single instance of item 1 in a whole column. For this control you need only two Column Data Items, the others don't display.


|-
To my knowledge, once loaded the original indexes of the icon-resources are lost: for example it's not possible to fetch the original resource index of icon "2" in the '''Icon List''' and substitute it with something else. This is only possible on Mac using columns of type Multiple Icons when they are loaded with '''SetLBImageIndexes''', but I didn't try this with the new routine, only with its precursor: ''AddLBImage'' (obsolete).
| 5 [[#Static_Icon| Static Icon]]
| colspan="2" style="text-align: center;"| &lt;doesn't respond&gt;


|-
It's also not possible to delete the image-list from the List Browser, once created. For this reason images must be loaded only once In [[VS:Creating_a_Custom_Dialog_Box| SetupDialogC]] and attention be paid that '''AddListBrowserImage''' doesn't land in any repetitive routine: this would add the same image over and over again, each time increasing the index count.
| 6 [[#Number| Number]]
| colspan="2" style="text-align: center;"| &lt;doesn't respond&gt;


|-
The sequence defined by adding images is not relevant if you need the icons for singular cells or for a List of Data Items, but becomes very important if your icons need to be displayed in Radio columns, since this control follows the insertion order of the [[#Icon List| Icon List]] precisely.
| 7 [[#Multiple_Icons_.28OBSOLETE.29| Multiple Icons]]
| colspan="2" style="text-align: center;" | &lt;doesn't respond&gt;
|}


==== Manage the Data Items List ====


<code lang="pas">
<code lang="pas">
InsertLBColumnDataItem( dialogID:LONGINT; componentID:LONGINT; columnIndex:INTEGER;
AddListBrowserImage(dialogID: LONGINT; listBrowserID: LONGINT; imageSpecifier: DYNARRAY[] of CHAR): INTEGER;
itemString:STRING; imageOn:INTEGER; imageOff:INTEGER; itemData:LONGINT):INTEGER;
</code>
</code>
[[VS:AddListBrowserImage]] Adds an image to the list of images that a list browser can use.


Inserts one Data Item in the list for the chosen column. You will repeat the call for each Item to be inserted in your Column Data Items list.
; imageSpecifier: the path to the image resource (since VW 2014), for example: 'Vectorworks/ResourceBrowser/WallStyle.png'.
: I prefer to use icons from the application self, where there is a very large choice: loading resources from Vectorworks spares you the creation of your own resource file[s]. The application ships with a huge number of icons and you always find something that fits your needs.


; result (0-based): index of the newly inserted Data Item. Most of the times is advisable to store only the start or end value of a Data Item List and use that adding or subtracting needed indexes. You might prefer this approach instead of storing singular Item indexes.
; result (0-based): the index of the newly inserted icon. This increases at each newly inserted icon. Once added, images cannot be deleted and stay with the List Browser until script ends. For this reason Images should be added to the List Browser only once. This is best done in the [[VS:Creating_a_Custom_Dialog_Box| SetupDialogC]] section of the dialog driver.
 
: Since the index is 0-based you should remember later to use "-1" for telling cells not to use images. Whenever you see a routine allowing for an image index (for example [[VS:SetLBItemInfo]]) and you don't want an image to load, set the image index parameter to "-1". A typical mistake is to write "0", which will load the first image in the LB, if any loaded. If you didn't load images into your LB previously, you don't need to bother much.
; itemString: the string attached to this index of Column Data Item. MUST be defined otherwise the item doesn't insert in the List.
:* [[#Multi State| Multi State]], [[#Single Instance| Single Instance Icon]]: you can decide to create a Data Item containing only strings setting both "imageOn" and "imageOff" to "-1".
:* [[#Radio| Radio]]: no string support, but the string must be nevertheless defined.


; imageOn: is an icon index of the Icon List, the image to be triggered on user's click. Set to "-1" to make image undefined.
:* [[#Multi State| Multi State]] : the icon shown when selecting a cell. At each further click, the next image in the list will be displayed. When the list has reached the end, the whole begins anew from the start.
:* [[#Single Instance| Single Instance Icon]]: on click shows image index 1. Any other selection shows image index 0.
:* [[#Radio| Radio]]: see dedicated chapter.


; imageOff: is an icon index of the Icon List, the image to be triggered on deselection. Set to "-1" to make the icon undefined.
=== Use custom icons ===
:* [[#Radio| Radio]]: set this in alternative to imageOn. You shouldn't have both "imageOn" and "imageOff" defined in a single call to InsertLBColumnDataItem. See [[#Radio| Radio]].
:* [[#Multi State| Multi State]] and [[#Single Instance| Single Instance Icon]]: don't support "imageOff".


; itemData: elsewhere called "User data". No idea how to use this. If you set something here it will block toggles, if the Longint passed exceeds the Icon List. See User Data.
* Create icons of size 16/16 px with a resolution of 72dpi.
* Save them as .png file
* Place them in the same folder where you have your plug-in .vsm file


; Notes: If you don't want to load images pass "-1" to the parameters "imageOn" and "imageOff". Here is to be noted that:
See [[#Example: visibility toggle| Example: visibility toggle]] for a method to access them.
:* [[#Multi State| Multi State]] and [[#Single Instance| Single Instance Icon]] columns: ignore the "-1" and show the last valid image previously defined. If no images has been defined at all, the cells show nothing.
:* [[#Radio| Radio]] columns: show white space


* [[#Multi State| Multi State]] and [[#Single Instance| Single Instance Icon]] add the images according to the index passed in the parameter "imageOn". [[#Radio| Radio]] columns add them according to the Icon List's index corresponding to the count of calls of the routine InsertLBColumnDataItem. This has been damn tough to find out.
=== Use icons from Vectorworks.app ===
(only [[#Radio| Radio]]) If you load the parameter "imageOff" you should leave "imageOn" to "-1". Then it will display the image defined for off. If you define both, you'll have "imageOn" permanently visible both on selection and not. All other control types (supporting Column Data Items) will only use imageOn.


<code lang="pas">
You can use all images shipped in VectorworksXX.app. There are also images stored in the SDK libraries provided by the various plug-ins:
GetLBColumnDataItemInfo(dialogID: LONGINT; componentID: LONGINT; columnIndex: INTEGER;
* on Mac
columnDataItemIndex: INTEGER;
** right-click on the application icon Vectorworks 20xx.app or any .vwlibrary file from the Plug-in Folder
VAR itemString:STRING; VAR imageOn: INTEGER; VAR imageOff:INTEGER; VAR itemData: LONGINT): BOOLEAN;
** select '''Show Package Contents'''
</code>
** navigate to /Contents/Resources/xxx.vwr/Images
** use the file path name without @2x and suffix
* on Win (to do)




Query a Data Items List of a column for the values associated to a particular item index.


; columnDataItemIndex: the column data item to be queried
=== Example: selection toggle ===
; itemString: the item text associated with that data item
; imageOn: the "on" image associated with that data item on selection
; imageOff: the "off" image associated with that data item on deselection
; itemData: the item user data. See User Data


<code lang="pas">
The most frequent mistake in dealing with toggles, is to think that an icon list index is the same as a Column Data Item index. They are not the same list, so they might be the same only if the icon list is exactly identical with the Column Data Item list.
FindLBColumnDataItem( dialogID:LONGINT; componentID:LONGINT; columnIndex:INTEGER; itemString:STRING;
VAR columnDataItemIndex:INTEGER):BOOLEAN;
</code>


Example:
* add 4 images to a list browser: pen, paint bucket, select and blank. The list sequence is 0, 1, 2, 3
* add 2 column data items to a column: select and blank. The index sequence is 0, 1, whereby img 0 and 1 correspond to 2 and 3 in the LB index.


Queries a Data Items List for a specific string and returns the index of the found Data Item, if any. If no item can be found returns FALSE and sets the variable "columnDataItemIndex" to "-1".
<div style="margin: 1em; border: dotted 1px #aaa; padding: 1em; background-color: #F2F2F2;">


[[File:c_LB_toggleSel.png| right| Toggle Selection]]


<code lang="pas">
<code lang="pas">
RemoveLBColumnDataItem( dialogID:LONGINT; componentID:LONGINT; columnIndex:INTEGER;
columnDataItemIndex:INTEGER):BOOLEAN;
RemoveAllLBColumnDataItems( dialogID:LONGINT; componentID:LONGINT; columnIndex:INTEGER);
</code>


Remove one or all items from a Column Data List.
{ in the list browser setup, in SetupDialogC: }


==== Examples ====
{ add blank and selection images to a List Browser and index them: }
penLBindex := AddListBrowserImage(dlog, LB, 'Vectorworks/Attributes/Pen.png'); { sets icon index for pen, not in usage, only for extra index }
bucketLBindex := AddListBrowserImage(dlog, LB, 'Vectorworks/Attributes/PaintBucket.png'); { bucket, not in usage, only for extra index }
uncheckedLBindex := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Blank.png'); { not selected, we use it later }
checkedLBindex := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Checkmark.png'); { selected, we use it later }


Here words don't help. If you wish to understand the deepness of Column Data Items lists, you must go through some experiments. Get nuts with this:
{ during column creation : }
{ make a cell toggle status on click }
temp_b := SetLBControlType(dlog, LB, col, 3); { kLBctrMultiState }
temp_b := SetLBItemDisplayType(dlog, LB, col, 1); { kLBdispImageOnly }


<div style="margin: 1em; border: dotted 1px #aaa; padding: 1em; background-color: #F2F2F2;">
{ upon click on a cell in this column, the value will toggle between "offIndex" and "onIndex" }
offIndex := InsertLBColumnDataItem(dlog, LB, col, '-', uncheckedLBindex, -1, 0);
onIndex := InsertLBColumnDataItem(dlog, LB, col, 'v', checkedLBindex, -1, 0);


{ variant: text-only toggle: }
{ temp_b := SetLBItemDisplayType(dlog, LB, col, 2); } { kLBdispTextOnly }
{ offIndex := InsertLBColumnDataItem(dlog, LB, col, '-', -1, -1, 0); }
{ onIndex := InsertLBColumnDataItem(dlog, LB, col, 'v', -1, -1, 0); }


===== Example: Data Item won't insert because of empty string =====
{ ... }


<code lang="pas">
{ while loading cell values: }
{ will be ignored since the string is missing }
temp_b := SetLBItemUsingColumnDataItem(dlog, LB, row, col, onIndex); { set a cell to show as "selected"  }
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, '', imgIndex, -1, 0);
temp_b := SetLBItemUsingColumnDataItem(dlog, LB, row, col, offIndex); { set a cell to show as "not selected"  }
</code>
</code>
</div>


===== Example: text only toggles =====
=== Example: visibility toggle ===


<code lang="pas">
If you need to see the standard access to an image toggle, please first look at the example above. This example is a bit more complex than the previous and uses relative indexes. You prefer this approach to save on the amount of variables needed.
{ text only toggles: use Edit Display "Text only" }
dataItemCnt1 := InsertLBColumnDataItem(dlog, LB, col, 'Orso', -1, -1, 0);
dataItemCnt1 := InsertLBColumnDataItem(dlog, LB, col, 'Atta', -1, -1, 0);
dataItemCnt1 := InsertLBColumnDataItem(dlog, LB, col, 'Ax', -1, -1, 0);
</code>
 
===== Example: text/image toggles =====


<div style="margin: 1em; border: dotted 1px #aaa; padding: 1em; background-color: #F2F2F2;">
<code lang="pas">
<code lang="pas">
{ text/image toggles: use Edit Display "Image and text"}
{ add three images to a List Browser and index them: }
{ gImgCnt is the count of images loaded in the Icon List }
imgCnt := -1; { init }
dataItemCnt3 := InsertLBColumnDataItem(dlog, LB, col, 'image 1', gImgCnt-2, -1, 0);
imgVis := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Visible');
dataItemCnt3 := InsertLBColumnDataItem(dlog, LB, col, 'image 2', gImgCnt-1, -1, 0);
imgInvis := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Invisible');
dataItemCnt3 := InsertLBColumnDataItem(dlog, LB, col, 'image 3', gImgCnt, -1, 0);
imgGray := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Gray');
</code>


===== Example: only string and one image at start: icon 2 =====
{ Alternatively, store only the total count. Retrive them by offset to the count: }
imgCnt := -1; { init }
imgCnt := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Visible');
imgCnt := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Invisible');
imgCnt := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Gray');


<code lang="pas">
{ Or use your own icons : }
{ emtpy on "Radio", always image 2 on "Multi State" and "Single instance" }
{ fetch the file path to the .vsm file }
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, 'string only', 2, -1, 0);
IF (GetPluginInfo(pioName, pioRecordHandle)) & FindFileInPluginFolder(Concat(pioName, '.vsm'), pluginPath) THEN
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, 'string only 2', -1, -1, 0);  
path2img := Concat(pluginPath, 'Imgs'); { path to a folder named 'Imgs' in your Plug-in folder }
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, 'string only 3', -1, -1, 0);
{ ... }
</code>


===== Example: targeted index sequence =====
{ retrive your custom images during SetupDialogC }
 
imgCnt := -1; { init }
<code lang="pas">
imgCnt := AddListBrowserImage(dlog, LB, Concat(path2img, '/Visible.png'));
{ having 10 items defined in the Icon list }
imgCnt := AddListBrowserImage(dlog, LB, Concat(path2img, '/Invisible.png'));
{ sequence 0, 1, 2, 3 on "Radio" }
imgCnt := AddListBrowserImage(dlog, LB, Concat(path2img, '/Gray.png'));  
{ sequence 8, 9, 6, 5 on "Multi State" }
{ sequence 8, 9 on "Single instance" }
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, 'image 8', 8, -1, 0);
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, 'image 9', 9, -1, 0);
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, 'image 6', 6, -1, 0);
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, 'image 5', 5, -1, 0);
</code>
</code>


===== Example: use imageOff on Radio column =====
[[File:c_LB_toggleImgs.png| left| Toggle Images]]


<code lang="pas">
Since we know that the list starts at zero and the counter always increases by 1, we store the final index in the variable "imgCnt". If something goes wrong, we have the needed "-1" value to declare the lack of images. To access them later we'll only need to subtract to this variable. You might prefer to access indexes in this fashion whenever your script uses only few images.
{ having 10 items defined in the Icon list }
{ sequence -, 1, 2, 3 on "Radio", with image 9 on sub-col 0 when NOT selected }
{ sequence 0, 0, 0, 0 on "Multi State" (facit: always image 0, perfectly senseless) }
{ sequence 0, 0 on "Single instance" }
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, 'image 9 on off', -1, 9, 0);
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, 'image 1', 0, -1, 0);
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, 'image 2', 0, -1, 0);
dataItemCnt := InsertLBColumnDataItem(dlog, LB, col, 'image 3', 0, -1, 0);
</code>
</div>
</div>


{| class="wikitable" style="margin: auto;"
|-
! [[User:CBM-c-/VS-List_Browsers| Introduction]]
! List_Browsers_part_1
! [[User:CBM-c-/VS-List_Browsers_part_2| List_Browsers_part_2]]
|}
gImgCnt := AddListBrowserImage(gD, cLB_Styles, 'Vectorworks/Standard Images/Visible'); { visible: black eye }
gImgCnt := AddListBrowserImage(gD, cLB_Styles, 'Vectorworks/Standard Images/Invisible'); { invisible: cross }
</code>
[[File:c_LB_toggleImgs.png| left| Toggle Images]]
Since we know that the list starts at zero and the counter always increases by 1, we store the final index in the variable "gImgCnt". If something goes wrong, we have the needed "-1" value to declare the lack of images. To access them later we'll only need to subtract to this variable. You might prefer to access indexes in this fashion whenever your script uses only few images.
</div>




{| class="wikitable" style="margin: auto;"
{| class="wikitable" style="margin: auto;"
|-
|-
! [[User:CBM-c-/VS-List_Browsers| Introduction]]
! [[User:CBM-c-/VS-List_Browsers_part_1| Part 1: Creation]]
! List_Browsers_part_1
! [[User:CBM-c-/VS-List_Browsers_part_2| Part 2: Columns]]
! [[User:CBM-c-/VS-List_Browsers_part_2| List_Browsers_part_2]]
! [[User:CBM-c-/VS-List_Browsers_part_3| Part 3: Rows and Cells]]
! [[User:CBM-c-/VS-List_Browsers_part_4| Part 4: Events]]
|}
|}

Latest revision as of 10:10, 31 January 2021


Some of you know me as Orso from the now defunct Vectorlab, I maintained it for many years. Here is the List Browsers article from the former Vectorlab site. For better understanding please use the comprehensive example at Dialog with List Browser.

By --_c_ 01:31, 31 December 2020 (EST), previously Orso.B.Schmid, 2009-2018.


List Browsers

List Browsers allow for great layout, advanced data management, but also amazing layout features within the single cells. Is not difficult to load them with some text data and make them display a whatever list. Still the advanced settings of List Browsers are quite enigmatic. After years of trial and error, I attempt here to resume what I discovered. If you find an error, I'd be glad to be informed. I am a user and had no reference literature for this article which is based on pure experience, if you are a programmer you will probably find the terms employed not quite the right ones.

Since List Browsers are so complex, the best way to learn how to use them is to have some free code available for experiments. Free code for List Browsers can be counted on one hand and none of the snippets available tells you a single thing about Control Types, Edit Display Types, Item Display Types, Column Data Items and so on.

Use the example Dialog with List Browser to experiment with the List Browser's options.


Part 1: Creation Part 2: Columns Part 3: Rows and Cells Part 4: Events

Introduction

The display of List Browsers is determined by the right combination of four settings: Control Type, Display Type, Cell's Column Owner, Column Data Items.

This is all rather difficult, specially because it is not documented. It resembles a 4D-puzzle.


Column Data Items List Browser set up
Icons, Strings
Column Cell
Control Type

display HOW

Display Type

display WHICH DATA

Column Owner Type

display WHAT

  1. Static
  2. Radio
  3. Multi State
  4. Single Instance Icon
  5. Static icon
  6. Number
  7. Multiple Icons
  1. Image
  2. Text only
  3. Image and Text
0. None
  1. Solid rect
  2. Dual solid rect
  3. Pattern rect
  4. Dual pattern rect
  5. Gradient or image
  6. Blank
  7. Text
  8. Dashed line


Lists Validity Scope

List Browsers are more than tables of cells, they browse lists. You must imagine them like special containers with built-in lists of data which can be created and used on need. These lists have different validity scope.

List of icons
available to the whole List Browser.
Column Data Items
available to one column. Column Data Items will often use images from the List Browser's Image list, but they can also contain only strings.


Create a List Browser

List Browsers are called in a Layout Creation routine with CreateLB.

CreateLB(dialogID: LONGINT; listBrowserID: LONGINT; 
	widthInCharacters: INTEGER; heightInCharacters: INTEGER);

VS:CreateLB Creates an empty List Browser with no rows and no columns.

widthInCharacters, heightInCharacters
is different between Mac and PC. Basically on Mac all dialog items with a scroll bar interpret the width excluding the bar. This will influence the width of dialog elements such as PullDown menus, List Browsers, Lists and such. These items won't align with Static Text, Edit fields and similar: the scroll bar will be outside alignment. You must correct the width programmatically.


List Browsers in resizable dialogs

List Browsers are special dialog items with a built-in binding to their parent container. If a dialog is resizable, they resize width and height automatically, without any Edge Binding. For this reason you'll prefer to leave List Browsers outside groups: they will fit beautifully to the dialog window without you to bother.

dlog := CreateResizableLayout('List Browsers test', TRUE, 'Close', '', TRUE, FALSE);
{ ... }
CreateLB(dlog, lb, lbWidth, lbHeight);


Load a List Browser

Your List Browser after creation is just an empty container without columns, rows or any data. Before loading the List Browser it is important to understand what needs to be loaded once and if there are things that needs to be loaded repeatedly, after destroying data. Aside of images, which must be really loaded only once, all other List Browser elements can be loaded, destroyed, created or modified according to your needs. The typical script will set up a List Browser once in SetupDialogC and manipulate repeatedly only rows data. Usually you will:

Then you'll organize your loading code as follows:

  • needs loading once --> has a place in the SetupDialogC CASE item of your dialog driver routine
  • needs loading repeatedly --> resides in a subroutine with wider validity scope (including SetupDialogC for the first run).


Items and Sub-items, index (0-based)

At start the main difficulty in understanding List Browsers is caused by the naming of the various routine parameters. Everyone will struggle initially with "itemIndex" and "subItemIndex", sometimes also called (more clearly) "columnIndex". The official documentation uses names not consequently. Just some examples:

row index
itemIndex, nItemIndex
column index
subItemIndex, nSubItemIndex, columnIndex

If you see both parameters for row and for column you know that you'll target a cell (intersection of row and column).

All indexes in List Browsers are 0-based:

This implies that for setting the absence of an image -for example- you need to pass "-1". Take care to init your variables to -1. Mind the routine AddListBrowserImage which on Mac might return "0" also if it failed to insert an image.

Many mistakes in List Browsers are caused by unwanted 0-indexes in images or Column Data Items.


Icon List

Very relevant for the layout of a List Browser is the list of icons (optional). Here you store small icons that will be available to the whole List Browser. The icons must be either loaded from external resource files or recycled from the built-in Vectorworks icons. They can be used directly from the singular cells and/or be used to build data in the List of Data Items of a column. An Icon List can be created using AddListBrowserImage.

There is a single routine allowing to load icon resources without pre-loading them in the Icon List first: SetLBImageIndexes, which applies only to columns with control type Multiple Icons.

To my knowledge, once loaded the original indexes of the icon-resources are lost: for example it's not possible to fetch the original resource index of icon "2" in the Icon List and substitute it with something else. This is only possible on Mac using columns of type Multiple Icons when they are loaded with SetLBImageIndexes, but I didn't try this with the new routine, only with its precursor: AddLBImage (obsolete).

It's also not possible to delete the image-list from the List Browser, once created. For this reason images must be loaded only once In SetupDialogC and attention be paid that AddListBrowserImage doesn't land in any repetitive routine: this would add the same image over and over again, each time increasing the index count.

The sequence defined by adding images is not relevant if you need the icons for singular cells or for a List of Data Items, but becomes very important if your icons need to be displayed in Radio columns, since this control follows the insertion order of the Icon List precisely.


AddListBrowserImage(dialogID: LONGINT; listBrowserID: LONGINT; imageSpecifier: DYNARRAY[] of CHAR): INTEGER;

VS:AddListBrowserImage Adds an image to the list of images that a list browser can use.

imageSpecifier
the path to the image resource (since VW 2014), for example: 'Vectorworks/ResourceBrowser/WallStyle.png'.
I prefer to use icons from the application self, where there is a very large choice: loading resources from Vectorworks spares you the creation of your own resource file[s]. The application ships with a huge number of icons and you always find something that fits your needs.
result (0-based)
the index of the newly inserted icon. This increases at each newly inserted icon. Once added, images cannot be deleted and stay with the List Browser until script ends. For this reason Images should be added to the List Browser only once. This is best done in the SetupDialogC section of the dialog driver.
Since the index is 0-based you should remember later to use "-1" for telling cells not to use images. Whenever you see a routine allowing for an image index (for example VS:SetLBItemInfo) and you don't want an image to load, set the image index parameter to "-1". A typical mistake is to write "0", which will load the first image in the LB, if any loaded. If you didn't load images into your LB previously, you don't need to bother much.


Use custom icons

  • Create icons of size 16/16 px with a resolution of 72dpi.
  • Save them as .png file
  • Place them in the same folder where you have your plug-in .vsm file

See Example: visibility toggle for a method to access them.

Use icons from Vectorworks.app

You can use all images shipped in VectorworksXX.app. There are also images stored in the SDK libraries provided by the various plug-ins:

  • on Mac
    • right-click on the application icon Vectorworks 20xx.app or any .vwlibrary file from the Plug-in Folder
    • select Show Package Contents
    • navigate to /Contents/Resources/xxx.vwr/Images
    • use the file path name without @2x and suffix
  • on Win (to do)


Example: selection toggle

The most frequent mistake in dealing with toggles, is to think that an icon list index is the same as a Column Data Item index. They are not the same list, so they might be the same only if the icon list is exactly identical with the Column Data Item list.

Example:

  • add 4 images to a list browser: pen, paint bucket, select and blank. The list sequence is 0, 1, 2, 3
  • add 2 column data items to a column: select and blank. The index sequence is 0, 1, whereby img 0 and 1 correspond to 2 and 3 in the LB index.
Toggle Selection
Toggle Selection

{ in the list browser setup, in SetupDialogC: }

{ add blank and selection images to a List Browser and index them: }
penLBindex := AddListBrowserImage(dlog, LB, 'Vectorworks/Attributes/Pen.png'); { sets icon index for pen, not in usage, only for extra index }
bucketLBindex := AddListBrowserImage(dlog, LB, 'Vectorworks/Attributes/PaintBucket.png'); { bucket, not in usage, only for extra index }
uncheckedLBindex := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Blank.png'); { not selected, we use it later }
checkedLBindex := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Checkmark.png'); { selected, we use it later }

{ during column creation : }
{ make a cell toggle status on click }
temp_b := SetLBControlType(dlog, LB, col, 3); { kLBctrMultiState }
temp_b := SetLBItemDisplayType(dlog, LB, col, 1); { kLBdispImageOnly }

{ upon click on a cell in this column, the value will toggle between "offIndex" and "onIndex" }
offIndex := InsertLBColumnDataItem(dlog, LB, col, '-', uncheckedLBindex, -1, 0);
onIndex := InsertLBColumnDataItem(dlog, LB, col, 'v', checkedLBindex, -1, 0);

{ variant: text-only toggle: }
{ temp_b := SetLBItemDisplayType(dlog, LB, col, 2); } { kLBdispTextOnly }
{ offIndex := InsertLBColumnDataItem(dlog, LB, col, '-', -1, -1, 0); }
{ onIndex := InsertLBColumnDataItem(dlog, LB, col, 'v', -1, -1, 0); }

{ ... }

{ while loading cell values: }
temp_b := SetLBItemUsingColumnDataItem(dlog, LB, row, col, onIndex); { set a cell to show as "selected"  }
temp_b := SetLBItemUsingColumnDataItem(dlog, LB, row, col, offIndex); { set a cell to show as "not selected"  }

Example: visibility toggle

If you need to see the standard access to an image toggle, please first look at the example above. This example is a bit more complex than the previous and uses relative indexes. You prefer this approach to save on the amount of variables needed.

{ add three images to a List Browser and index them: }
imgCnt := -1; { init }
imgVis := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Visible');
imgInvis := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Invisible');
imgGray := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Gray');

{ Alternatively, store only the total count. Retrive them by offset to the count: }
imgCnt := -1; { init }
imgCnt := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Visible');
imgCnt := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Invisible');
imgCnt := AddListBrowserImage(dlog, LB, 'Vectorworks/Standard Images/Gray'); 

{ Or use your own icons : }
{ fetch the file path to the .vsm file }
IF (GetPluginInfo(pioName, pioRecordHandle)) & FindFileInPluginFolder(Concat(pioName, '.vsm'), pluginPath) THEN
	path2img := Concat(pluginPath, 'Imgs'); { path to a folder named 'Imgs' in your Plug-in folder }
	{ ... }

{ retrive your custom images during SetupDialogC }
imgCnt := -1; { init }
imgCnt := AddListBrowserImage(dlog, LB, Concat(path2img, '/Visible.png'));
imgCnt := AddListBrowserImage(dlog, LB, Concat(path2img, '/Invisible.png'));
imgCnt := AddListBrowserImage(dlog, LB, Concat(path2img, '/Gray.png')); 
Toggle Images
Toggle Images

Since we know that the list starts at zero and the counter always increases by 1, we store the final index in the variable "imgCnt". If something goes wrong, we have the needed "-1" value to declare the lack of images. To access them later we'll only need to subtract to this variable. You might prefer to access indexes in this fashion whenever your script uses only few images.


Part 1: Creation Part 2: Columns Part 3: Rows and Cells Part 4: Events