My dialog tricks
Posted: 4 Oct 2010 7:52
Hi,
It's the time not only to ask something but to publish some tricks about dialog handling.
1. Validation of strings by length [after trimming] and allowed characters.
2. Comparison of two string which should contain V2>=V1 integer values.
3. Easy hangling of DIALOG_INTS e.g. in dialog_..._update procedures.
4. Usage of synchronized list boxed instead of grids or columns separated by tabulators.
4. a) Optional Integer control to enhance navigation.
5. Move selection in one or more list boxes based on an integer control.
6. Display explanation of the control in focus in the status line.
Usage:
Insert include statements into VIPTOOLS.PRE
and VPITOOL.PRO, respectively.
Declarations are in mydialog.pre:
Clauses are in mydialog.pro:
The above were written in version 5. The following tricks are in version 7.
myDialogTricks.cl
The clauses - myDialogTricks.pro
It's the time not only to ask something but to publish some tricks about dialog handling.
1. Validation of strings by length [after trimming] and allowed characters.
2. Comparison of two string which should contain V2>=V1 integer values.
3. Easy hangling of DIALOG_INTS e.g. in dialog_..._update procedures.
4. Usage of synchronized list boxed instead of grids or columns separated by tabulators.
4. a) Optional Integer control to enhance navigation.
5. Move selection in one or more list boxes based on an integer control.
6. Display explanation of the control in focus in the status line.
Usage:
Insert include statements into VIPTOOLS.PRE
Code: Select all
ifdef use_dlgpack
include "dialog\\dialog.pre"
include "mydialog.pre"
enddef
Code: Select all
ifdef use_dlgpack
include "dialog\\dialog.pro"
include "mydialog.pro"
enddef
Code: Select all
% 30.4.2007 % **** Extensions to dialog pack ****
GLOBAL PREDICATES
trim_validate_str(STRING Input, STRING Corrected, INTEGER Min_Length, INTEGER Max_Length, char Lowest_Allowed, char Highest_Allowed, string Error_Message)
-( i , o , i , i , i , i , i )
my_validate_str(STRING Corrected, INTEGER Min_Length, INTEGER Max_Length, char Lowest_Allowed, char Highest_Allowed, string Error_Message)
-( i , i , i , i , i , i )
change_case(STRING Input, STRING Corrected, char Lowest_Allowed, char Highest_Allowed)
-( i , o , i , i )
prohibited_char(STRING Entry, char Lowest_Allowed, char Highest_Allowed)
my_compare_int(STRING S1, STRING S2, dialog_int V1, dialog_int V2, string Error_Message)
-( i , i , o , o , i )
procedure INTEGER my_dialog_GetInt(WINDOW,DIALOG_CONTROL_ID)
procedure INTEGER my_dialog_VLGetInt(DIALOG_CONTROL_ID,DIALOG_VAL_LIST)
Code: Select all
% 30.4.2007 % **** Extensions to dialog pack ****
CLAUSES
trim_validate_str(S, C, Min_Length, Max_Length, Lowest_Allowed, Highest_Allowed, Error_Message) if
fronttoken(S,Token,RestString),
concat(Token,RestString,F),
searchchar(F,' ',FoundPos),
Length=FoundPos-1,
frontstr(Length,F,K,_),
change_case(K, C, Lowest_Allowed, Highest_Allowed),
my_validate_str(C, Min_Length, Max_Length, Lowest_Allowed, Highest_Allowed, Error_Message).
change_case(S, C, _, Highest_Allowed) if
Highest_Allowed<='Z',
!,
upper_lower(S,C).
change_case(S, C, Lowest_Allowed, Highest_Allowed) if
Lowest_Allowed>='a',
Highest_Allowed<='z',
!,
upper_lower(C,S).
change_case(S, S, _, _).
my_validate_str(S, Min_Length, _, _, _, Error_Message) if
str_len(S,Length),
Length<Min_length,
dlg_Error("Too Short Entry", Error_Message),
fail.
my_validate_str(S, _, Max_Length, _, _, Error_Message) if
str_len(S,Length),
Length>Max_length,
dlg_Error("Too Long Entry", Error_Message),
fail.
my_validate_str(S, _, _, Lowest_Allowed, Highest_Allowed, Error_Message) if
prohibited_char(S, Lowest_Allowed, Highest_Allowed),
!,
dlg_Error("Invalid Characters", Error_Message),
fail.
my_validate_str(_, _, _, _, _, _).
prohibited_char(Entry, Lowest_Allowed, _) if
frontchar(Entry,FrontChar,_),
Frontchar<Lowest_Allowed,
!.
prohibited_char(Entry, _, Highest_Allowed) if
frontchar(Entry,FrontChar,_),
Frontchar>Highest_Allowed,
!.
prohibited_char(Entry, Lowest_Allowed, Highest_Allowed) if
frontchar(Entry,_,RestString),
!,
prohibited_char(RestString, Lowest_Allowed, Highest_Allowed).
my_compare_int(S1, S2, _, _, Error_Message) if
str_int(S1,V1),
str_int(S2,V2),
V2<V1,
!,
dlg_Error("Invalid Values", Error_Message),
fail.
my_compare_int(S1, S2, K1, K2, _) if
str_int(S1,V1),
str_int(S2,V2),
V2>=V1,
K1=i(V1),
K2=i(V2),
!.
my_compare_int(S1, S2, void, void, _) if
not(str_int(S1,_)),
not(str_int(S2,_)),
!.
my_compare_int(S1, S2, void, K2, _) if
not(str_int(S1,_)),
str_int(S2,V2),
K2=i(V2),
!.
my_compare_int(S1, S2, K1, void, _) if
not(str_int(S2,_)),
str_int(S1,V1),
K1=i(V1),
!.
my_dialog_GetInt (WINDOW,DIALOG_CONTROL_ID,I) if V = dialog_GetInt (WINDOW,DIALOG_CONTROL_ID), V=i(I).
my_dialog_VLGetInt (DIALOG_CONTROL_ID,DIALOG_VAL_LIST,I) if V = dialog_VLGetInt (DIALOG_CONTROL_ID,DIALOG_VAL_LIST), V=i(I).
myDialogTricks.cl
Code: Select all
/*****************************************************************************
% @Project: SOAP
% @File name: myDialogTricks.cl
% @Written by: Copyright (c) Budapest, Hungary 2009 Ferenc Nagy PhD.
% @short My dialog tricks.
% @detail Typical dialog handling tricks for the project.
% @end
******************************************************************************/
class myDialogTricks
open core
domains
listBox_list = listbox*.
predicates
classInfo : core::classInfo.
% @short Class information predicate.
% @detail This predicate represents information predicate of this class.
% @end
predicates
% Synchronize selection in two or more list boxes.
synchronizeListBoxes:(listBox Changed, listbox_list Followers, positive Index) procedure (i,i,o).
% Synchronize selection in two or more list boxes and the selection index in an integer control.
synchronizeListBoxesandInteger:(listBox Changed, listbox_list Followers, integercontrol) procedure (i,i,i).
% Move selection in one or more list boxes based on an integer control.
moveSelection:(integercontrol, listbox_list Followers) procedure (i,i).
% Fill rows of synchronized list boxes with list of strings.
fillListBoxes:(listbox_list Synchronized, core::string_list) procedure (i,i).
% Fill rows of synchronized list boxes with list of strings and
% change the count of found and index of selected rows.
fillListBoxesand2Integers:(listbox_list Synchronized, core::string_list, integercontrol Found, integercontrol Selected) procedure (i,i,i,i).
% Copy selected line of the list box to the status line.
copySelectedToStatusLine:(listBox LBox, vpiDomains::menuTag StatusField) determ (i,i).
% Initialize status line.
initializeStatusLine:(string Text, vpiDomains::menuTag StatusField) procedure (i,i).
% Display explanation of the control in focus in the status line.
explainInStatusLine:(string Dialog, string Control, string Explanation) procedure (i,i,i).
end class myDialogTricks
Code: Select all
/*****************************************************************************
% @Project: SOAP
% @File name: myDialogTricks.pro
% @Written by: Copyright (c) Budapest, Hungary 2009 Ferenc Nagy PhD.
% @short My dialog tricks.
% @detail Typical dialog handling tricks for the project.
% @end
******************************************************************************/
implement myDialogTricks
open core
constants
className = "com/visual-prolog/myDialogTricks/myDialogTricks".
classVersion = "$JustDate: $$Revision: $".
clauses
classInfo(className, classVersion).
% Synchronize selection in two or more list boxes.
synchronizeListBoxes(Changed, Followers, Index) :-
Index=Changed:tryGetSelectedIndex(),
foreach Elem = list::getMember_nd(Followers) do
Elem:selectAt(Index, true)
end foreach,
!.
synchronizeListBoxes(_, _,0).
% Synchronize selection in two or more list boxes and the selection index in an integer control.
synchronizeListBoxesandInteger(Changed, Followers, Ictl) :-
synchronizeListBoxes(Changed, Followers, Index),
Index1=Index+1,
Ictl:setInteger(Index1).
% Move selection in one or more list boxes based on an integer control.
moveSelection(IntegerControl, Followers) :-
Index=IntegerControl:getInteger()-1,
foreach Elem = list::getMember_nd(Followers) do
Elem:selectAt(Index, true)
end foreach.
% Fill rows of synchronized list boxes with list of strings.
fillListBoxes([ ], _) :- !.
fillListBoxes( _ , [ ]) :- !.
fillListBoxes([Lbox1|RestSynchronized], [Head|Tail]) :-
Lbox1:add(Head),
fillListBoxes(RestSynchronized, Tail).
% Fill rows of synchronized list boxes with list of strings and
% change the count of found and index of selected rows.
fillListBoxesand2Integers([Lbox1|RestSynchronized], String_List, Found, Selected) :-
fillListBoxes([Lbox1|RestSynchronized], String_List),
Found:setInteger(LBox1:getCount()),
Selected:setInteger(1),
!.
fillListBoxesand2Integers(_, _, _, _).
% Copy selected line of the list box to the status line.
copySelectedToStatusLine(LBox, StatusField) :-
[Sel1|_]=LBox:getSelectedItems(),
Task = vpi::getTaskWindow(),
vpiToolbar::setValue(Task, StatusField, vpitoolbar::text_value(Sel1)).
% Initialize status line.
initializeStatusLine(Text, StatusField) :-
Task = vpi::getTaskWindow(),
vpiToolbar::setValue(Task, StatusField, vpitoolbar::text_value(Text)).
% Display explanation of the control in focus in the status line.
explainInStatusLine(Dialog, Control, Explanation) :-
Task = vpi::getTaskWindow(),
DC=string::format("% %",Dialog,Control),
vpiToolbar::setValue(Task, resourceIdentifiers::idt_1, vpitoolbar::text_value(DC)),
vpiToolbar::setValue(Task, resourceIdentifiers::idt_help_line,vpitoolbar::text_value(Explanation)).
end implement myDialogTricks