Dialogs.ListBoxes A Dialogs.Boxes.Containers has a list box whose default size fills all the way down to a visible Accept button. If none exists, almost all the way down to the dialog box. However its appearance can be resized by using the LeftTop, Size, and Centralize parameters. Single or multiple entries may be operated on, depending on the preferences set. An entry operation may be selected by clicking on the main menu or by right clicking to pop a context menu. At least one current entry is always highlighted. No highlighting when the list box is empty. Changing Colors Using the technique of setting colors in ColorHandler used in Dialogs.EditBoxes, colors for text and text background worked as expected. The problem is in highlighting the list box entry/entries. If one was satisfied with the default highlighted colors, then this method alone is sufficient. Changing system colors would globally affect all other controls and application. This is not desirable. There is too much housekeeping if OS.Windows.Controls.LB_Set_Cur_Sel and LB_Set_Sel messages are intercepted. For example, a finite state recognizer is used to keep track of all the single and multiple selections in MouseHandler; a link list to store the indices of the selected entries, etc. Owner draw list boxes offer more flexibility. Other objects such as icons may be drawn as well. For the uninitated, like me, the parameter, DefiningRect in DrawItemHandler does not contain the expected values. If the font size is changed to some other non default values, entries are displayed incorrectly. Much time and effort were spent trying to get information from the scanty available documents. With luck and experimenting, correct results were achieved. The values are for the default font and size. WM_MeasureItem could not be used because this message is sent when the list box is created but before the parent control initialization is performed. Hence OS.Windows.Dialogs.aDialog.all is always null and CONSTRAINT_ERROR is raised. The desired font ie FontOf(Container) must be selected into a device context and the list box entry height is set using TextHeightOf. To make life easier, default drawing actions are defined in OS.Windows.Procs and OS.Windows.Dialogs as handlers with a call to OS.Windows.Controls.ListBoxes.DrawEntry. Override DrawListBoxHandler if different actions are needed. Another problem is trying to scroll text into view correctly with the highlighted entry. It was an exercise in sheer frustration trying to look for the correct information for doing such simple things. It was also a great delight to discover a simple and elegant solution. The trick is to set the text height obtained by OS.Text.Size into the list box! With the single line in Dialogs.ListBoxes.InitContainerHandler, SetItemHeight(Container.SubclassListBox, ItemHeightOf(Container.SubclassListBox)); everything fell into place and things worked beautifully.... Whew!!! Handlers procedure AcceptedEntriesHandler(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class; SelectedIndices : OS.Windows.Controls.ListBoxes.IndexLocations); -- -- Each highlighted entry is processed when the Accept Button is pressed. This begins just after the -- SaveListBoxHandler is invoked. When there are no highlighted entries ie the list box is empty, then -- the handler is not invoked. procedure CancelHandler(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class; OkToExit : out boolean); -- -- Actions to be taken when the cancel button is pressed. OkToExit indicates the dialog box is to be -- exited or not. -- procedure CreateEntryAtIndexHandler(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class) return OS.Windows.Controls.ListBoxes.IndexLocations; -- -- By default, an entry is created after any highlighted entry. Derive this to override the default action. -- For example creating an entry at the first entry location, return (1 => 1), to append a new entry as -- the last entry of the list box, return (1 => OS.Windows.Controls.ListBoxes.TotalItems(ListBox)). -- procedure CreateEntryHandler(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class; CreatedAt : positive); -- -- Actions to be taken after an entry is created. -- procedure DeleteEntryHandler(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class; EntryToBeDeleted : positive; CanBeDeleted : boolean); -- -- Actions to be taken just before the entry is actually removed. Whether an entry can be removed -- depends on the value of CanBeDeleted. -- procedure EntryInputMouseHandler(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class; Event : OS.Mouse.Events; State : OS.Mouse.States; Point : OS.Points.Points; Handled : out boolean); -- -- Actions to be taken when clicking on a mouse button while an entry is being edited. For example, -- implementing a context menu for that entry. -- function EntryTextFormatHandler(Container : Containers; RawText : Wide_String; FormattedText : Wide_String) return Wide_String; -- -- Change RawInputText to a formatted one for display. The default is to pass it unchanged. -- procedure EntryValidationHandler(Container : Containers; RawInputText : Wide_String; Accepted : out boolean; ErrorMessage : out awStrings.awStrings); -- -- Detemines if the input text is valid. If not, Accepted is false and ErrorMessage is set to indicate -- the type of error. -- procedure ExtendContextMenuHandler(Container : in out Containers; ContextMenu : OS.Windows.Menus.Menus'Class; ListBoxCanBeEdited : boolean; TotalListBoxEntries : natural); -- -- Actions to extend the context menu. -- procedure ExtendControlHandler(Container : in out Containers; Control : OS.Windows.Ops.Windows'Class; ControlId : OS.IDs; Notification : OS.Windows.Notifications); -- -- Actions to be performed on the pressed control. Notification may be used for additional information. -- This is usually done by RouteToControlHandler. -- function ExtendTemplateHandler(Container : Containers) return OS.Windows.Controls.Templates.Templates; -- -- This is where additional controls can be added to the dialog box. -- procedure ExtendMainMenuHandler(Container : in out Containers; MainMenu : OS.Windows.Menus.Menus'Class; CanBeEdited : boolean); -- -- This is where main menu items can be defined. CanBeEdited indicates whether the list box can be -- edited or not. -- procedure ExtendMenuItemIdHandler(Container : in out Containers; MenuItemID : OS.Ids); -- -- Actions to be taken when a menu item is selected. Menu items can be from the main menu or the -- context menu. -- procedure LoadListBoxHandler(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class; Loaded : out boolean); -- -- Actions for loading contents of a list box. -- procedure MoveHandler(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class; FromIndex : positive; ToIndex : positive); -- -- Action to be taken just before an entry is moved. -- procedure PostDisplayActionHandler(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class); -- -- Actions to be taken after all controls are displayed. -- procedure RenameEntryHandler(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class; IndexToBeRenamed : positive; OldFormattedText : Wide_String; Cancelled : out boolean; Renamed : out boolean; CanBeRenamed : out boolean; ErrorMessage : out awStrings.awStrings); -- -- Actions to be taken just before an entry is renamed. -- procedure SaveListBoxEntries(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class; Saved : out boolean); -- -- Actions to save the list box entries. -- procedure SelectedEntryHandler(Container : in out Containers; ListBox : OS.Windows.Controls.ListBoxes.Controls'Class; SelectedIndices : OS.Windows.Controls.ListBoxes.IndexLocations); -- -- Actions to be taken when an entry or entries is selected ie highlighted. -- Home Back To Dialogs.EditBoxes Dialogs.Folders |