- This topic has 0 replies, 5,448 voices, and was last updated 14 years, 6 months ago by deleyd.
-
AuthorPosts
-
July 25, 2006 at 5:44 am #1873deleydParticipant
Introduction to CMAC. 12.6
DIALOG BOXES: The ListBoxConcept
You first create a new window and fill the window with lines of text you want to display in the ListBox. Then when you call DlgAddCtrl to create the ListBox you specify the window number of the window you created by adding "/WIN="+str(<window number>) to the misc parameter.Notes
- [*:2wbocv00]You need to delete your window when your done with it.[/*:m:2wbocv00]
[*:2wbocv00]Because window numbers can change as windows are added and deleted, I recommend saving the window ID of your new window, and using TranslateWindowID(<winID>) to get the window number.[/*:m:2wbocv00][/list:o:2wbocv00](When you call DlgExecute it will set your window attributes to System & Hidden.)[code:2wbocv00]#include Win32.sh
#include Dialog.shvoid MyListBoxDlg1()
{
int Dlg, Result, MyListBoxWinID;
int OrigWinID = Window_ID;
int tr = refresh;
int ti = insert_mode;
refresh = false;
insert_mode = true;create_window;
MyListBoxWinID = Window_Id;
TEXT("ONE. This is line one");
CR;
TEXT("TWO. This is line two");
CR;
TEXT("THREE. This is line three");
CR;
TEXT("FOUR. This is line four");
CR;
TEXT("FIVE. This is line five");
TOF; // Wherever we position ourselves in this window
// determines what line is initially selected.DlgCreate( Dlg );
DlgAddCtrl( Dlg, Dlg_ListBox, "",
1, 1, // X, Y
40, 5, // Width, Height
1000, 0, // CtrlID, flags
"/WIN=" + Str(TranslateWindowID(MyListBoxWinID)) );
Result = DlgExecute( Dlg, 1000, "My ListBox Dialog1",
"",
"",
0 );Make_Message("Result="+str(result));
//Don’t forget to clean up!
DlgKill( Dlg );
Switch_Win_Id(MyListBoxWinID);
Delete_Window;
Switch_Win_Id(OrigWinID); // Restore original window
refresh = tr; // Restore refresh
insert_mode = ti; // Restore insert mode AFTER
// restoring refresh
}
[/code:2wbocv00]
Example:
A vertical scroll bar will automatically appear if the list is longer than the window:
You can force a vertical scroll bar to appear even if the list isn’t longer than the window by specifying the dlgf_lb_ScrollBar flag:
If a line is longer than the width of the window a horizontal scroll bar is not added by default:
You can force a horizontal scroll bar to appear by specifying the dlgf_lb_HScroll flag and specifying a horizontal scrolling width by adding "/HSCROLL=<n>" to the misc parameters (e.g. "/HSCROLL=60".) A horizontal scroll bar will appear even if no line in the list is longer than the window width. To determine a good value of <n>, see the discussion of /HSCROLL=<n> below.
You can add a triangle pointer to the beginning of the selected line by specifying the dlgf_lbPtr flag. In this case the selected line is outlined rather than highlighted:
Normally you can select only one line at a time. You can modify this so you can select several lines at a time by specifying the dlgf_lb_ExtendedSel flag. To select a block of lines select one line then hold down the Shift key and select another line. To select individual lines hold down the Ctrl key:
You can change a line to be a header line by prefixing the line with "\x7F@\xFE="
OPTIONAL FLAGS:
(These flags may be added to the flags parameter of the call to DlgAddCtrl. These flags are defined in Dialog.s. dlgf_lb… = dialog flag for listBox.)dlgf_lbIncSearch
Incremental Search. For example, typing "t" will select the first line starting with letter "t". Then typing "e" will select the first line starting with "te".This flag is identical to specifying "/INCO=1" in the misc parameter string.
If you specify dlgf_lbIncSearch or "/INCO=1" then you may also optionally specify "/INCSTR=<string>" in the misc parameter string to start out the incremental search with some characters. For example, you can specify the dlgf_IncSearch flag or "/INCO=1" as a misc parameter, then add "/INCSTR=te" to the misc parameter string, and when the listbox first displays it will be as if the user already entered the keys "t" "e".
(See macro MyListBoxDlg9 in MyListBoxDlgs.s attached below.)
dlgf_lbPtr
Adds a triangle pointer to the beginning of the selected line. The selected line is outlined rather than highlighted.dlgf_lb_ScrollBar
Use this to force a vertical scrollbar in a listbox. A vertical scrollbar will appear even if the list is not longer than the window. If the list is not longer than the window then the vertical scrollbar will be grayed out since there’s nothing to scroll. Without this flag a vertical scrollbar will appear automatically only if the list is longer than the window.dlgf_lb_ExtendedSel
Allow multiple selections. With this flag you can select several lines at once. To select a block of lines select one line then hold down the Shift key and select another line. To select individual lines hold down the Ctrl key.dlgf_lb_HScroll
To get a horizontal scrollbar you must specify both the dlgf_lb_HScroll flag and add "/HSCROLL=<n>" to the misc parameter string to specify a width. Example: "/HSCROLL=60". To determine a good value of <n>, see the discussion of /HSCROLL=<n> below.dlgf_lb_NoDblClick
The comment in Dialog.s for this flag says, "No double click on the list items." However this flag doesn’t seem to work.REQUIRED misc PARAMETER:
/WIN=<window number>
Specifies the window number to fetch the lines from that fill the ListBox. You may translate a window ID to a window number by using TranslateWindowID.OPTIONAL misc PARAMETERS:
"/HSCROLL=<n>"
You can force a horizontal scroll bar to appear by specifying the dlgf_lb_HScroll flag and specifying a horizontal scrolling width by adding "/HSCROLL=<n>" to the misc parameters (e.g. "/HSCROLL=60"). A horizontal scroll bar will appear even if no line in the list is longer than the window width.To arrive at a value for <n> I suggest multiplying the maximum number of characters you expect to have in a line by 1.80 then adding 3. The code is a bit awkward because you have to convert your integer number of characters to a real value in order to multiply by 1.80, then convert back to an integer value. If maxlength is the maximum number of characters you expect in a line, the code would be: [code:2wbocv00]"/HSCROLL=" + str((Int_R(Real_I(maxlength)*1.80))+3)[/code:2wbocv00]
This ensures a string consisting entirely of uppercase "M" characters will still fit. However, since the width of a character varies, and most characters are not as wide as an uppercase "M", normal strings may be quite a bit shorter than this calculated width. If you expect mostly lowercase letters than a value of 1.13 instead of 1.80 may work fine. (See macro MyListBoxDlg10 in MyListBoxDlgs.s attached below.)
"/SLINE=<n>"
Startline. Normally all the lines in your window will be displayed in your listbox. If you want you can specify a start line in your window. The listbox will contain lines from your window starting at line n. If not specified then the start line is line #1."/RECS=<n>"
Number of records. Normally all the lines in your window will be displayed in your listbox. If you want you can specify the number of lines from your window you want to display in the listbox. Can be used in combination with "/SLINE=<n>" so you can specify both a starting line and the number of records (lines) from your window you want displayed in the listbox."/INCO=1"
Identical to specifying dlgf_lbIncSearch in flags parameter. See dlgf_lbIncSearch flag above for a description."/INCSTR=<string>"
Option which can be added if "/INCO=1" or dlgf_lbIncSearch flag is specified. Start out the incremental search with these characters. Example: "/INCSTR=te" will look for the first line starting with "t", then look for a line starting with "te" (if one exists). When the listbox first displays it will be as if the user already entered the keys "t" "e"./DELWCMD=<id_delete_ctrlid>
Will send this message to your DlgProc hook macro when the delete key is pressed, as if a button with ctrlid <id_delete_ctrlid> were clicked.
[code:2wbocv00] case wm_Command :
ParseWmCommand( &wms, WParam, LParam );
switch ( wms.CtrlId ) {
case Dlg_Wcmd_Init :
case 1 :
case 998 :
case <id_delete_ctrlid>: (delete key was pressed.)
[/code:2wbocv00]/INSWCMD=<id_insert_ctrlid>
Will send this message to your DlgProc hook macro when the insert key is pressed, as if a button with ctrlid <id_insert_ctrlid> were clicked.
[code:2wbocv00] case wm_Command :
ParseWmCommand( &wms, WParam, LParam );
switch ( wms.CtrlId ) {
case Dlg_Wcmd_Init :
case 1 :
case 998 :
case <id_insert_ctrlid>: (insert key was pressed.)
[/code:2wbocv00]/CHANGEMAC=<macro>
Your change macro is called by the hook macro DlgMessageProc when it receives notify code lbn_SelChange./FOCUSMAC=<macro>
Your focus macro is called by the hook macro DlgMessageProc when it receives notify code lbn_SetFocus or lbn_KillFocus. For lbn_SetFocus the string "/FOCUS=1" is added to MParm_Str./SUBCLASS=<macro>
See article.Multiple Column Listboxes
To create a multiple column listbox you precede each column with "\x7F" and a field name in the window associated with the listbox. Then in the control-title (3rd param) of DlgAddCtrl you specify the field name and width. In the following code example I have named column 1 "NUMBER" and column 2 "LETTER":[code:2wbocv00]TEXT("\x7F"+"NUMBER=ONE" +"\x7F"+"LETTER=Alpha"); CR;
TEXT("\x7F"+"NUMBER=TWO" +"\x7F"+"LETTER=Beta"); CR;
TEXT("\x7F"+"NUMBER=THREE"+"\x7F"+"LETTER=Gamma"); CR;
TEXT("\x7F"+"NUMBER=FOUR" +"\x7F"+"LETTER=Delta"); CR;
TEXT("\x7F"+"NUMBER=FIVE" +"\x7F"+"LETTER=Epsilon"); CR;
TEXT("\x7F"+"NUMBER=SIX" +"\x7F"+"LETTER=Zeta");
...
DlgCreate( Dlg );
DlgAddCtrl( Dlg, Dlg_ListBox, "\x7F"+"NUMBER=/W=15" +
"\x7F"+"LETTER=/W=15",
1, 1, // X, Y
80, 5, // Width, Height
1000, 0, // CtrlID, flags
"/WIN=" + Str(TranslateWindowID(MyListBoxWinID)) );
[/code:2wbocv00]
(Note I separate "\x7F" from the rest of the text. See note for Caveat #2 Double Quoted Strings at )OPTIONAL control-title PARAMETERS:
(Note: These are for control-title (3rd param) of DlgAddCtrl. Don’t confuse these with above parameters which go in misc param of DlgAddCtrl.)<field-name>=
Name each column of your multi-column listbox./W=<field_width>
Width of the column. Play with this until it’s the width you want. This is not the number of characters that will fit. As a general rule of thumb, for ordinary mostly lowercase text multiply the number of characters you want to fit by 1.13 to get a value for /W=. To fit a string of uppercase M characters multiply the number of uppercase M characters you want to fit by 1.80 ./H=<height>
Alters the height of each line in the ListBox. You can play with this to see what it does, or omit it to get the default./IS=1
Designates this as the incremental search field. For use when you want a column other than the first column to be the one used for the incremental search field. See macro MyListBoxDlg12 in MyListBoxDlgs.s attached below for an example./T=<field_type>
Field types are defined in ListCtrl.sh . The field types are:
_ft_text (0) – This is the default if /T= is not specified.
_ft_bitmap (1) – No examples.
_ft_keylabel (2) – No examples. ListCtrl.sh says "/KL=keylabel"
_ft_bitmap_transp (3) – See macro MyListBoxDlg14 in MyListBoxDlgs.s attached below.
_ft_checkmark (4) – See macro MyListBoxDlg13 in MyListBoxDlgs.s attached below.
_ft_ext_text (5) – No examples. ListCtrl.sh says /FT=font handle, /FC=foreground color rgb, /BC=background color rgb, /TX=text.
_ft_menu (6) – No examples. ListCtrl.sh says /TX=text, char 254 = menu separator, /IN=indent.
_ft_shell (7) – No examples. ListCtrl.sh says, "Parameters is path to a file"Checkmarks
You can specify a column to be optional checkmarks by adding /T="+str(_ft_checkmark) to the field control. See macro MyListBoxDlg13 in MyListBoxDlgs.s attached below.Bitmap Images
You can specify a column to be bitmap images by adding /T="+str(_ft_bitmap_transp) to the field control for a column. See macro MyListBoxDlg14 in MyListBoxDlgs.s attached below.In addition to these bitmaps, you can also use any button bitmap. Go to MACRO -> RUN and enter "SET_BITMAP" to get a menu of all button bitmaps available. (For these you will need to specify a suitable value for /H=<height> so the whole bitmap will display.)
-
AuthorPosts
- You must be logged in to reply to this topic.