Correction of stiff dialog box of vpiCommonDialogs::ask predicate
Posted: 1 Apr 2016 7:31
Symptom №1:
The original dialog shows only three buttons. The others are beyond the client area of the window.
Symptom №2:
The sizes of push buttons are fixed. Long words appear truncated.
The essence of my correction is:
Example usage: Validation of integer controls:
The original dialog shows only three buttons. The others are beyond the client area of the window.
Symptom №2:
The sizes of push buttons are fixed. Long words appear truncated.
The essence of my correction is:
Code: Select all
class facts
ask_result:integer := 0.
default: positive :=0.
right: integer:=265. %<== Fact for determination of the necessary width.
bottom:integer:=0. %<== Fact for determination of the necessary bottom.
clauses
ask(Title, Prompt, ButtonTitlesList,Default) = ask_result :-
L=list::length(ButtonTitlesList),
bottom:=40+20*L,
Parent=vpi::getParentWindow(),
ParentFont=winGetFont(Parent),
fontGetAttrs(ParentFont,_,_)=FontName,
Static=ctl(
wdef(wc_Text,rct(2,2,152,20*L),
Prompt,u_DlgBase),10001,[wsf_AlignCenter]),
Flags=[wsf_Group,wsf_TabStop,wsf_AlignCenter ],
FlagsD=[wsf_Default|Flags],
Ctl_List=
[
CtlI
||
I=std::fromTo(0,L-1),
if I=Default then FlagsI=FlagsD else FLagsI=Flags end if,
ButtonTitle=list::nth(convert(positive,I),ButtonTitlesList),
% 2016.04.01. These lines determine the necessary with and height of the buttons based on the estimated text extent.
winGetTextExtent(Parent,ButtonTitle,W,H),
Right=math::max(210,165+W),
Bottom=17+math::max(H+5,20)*I,
right:=math::max(Right,right),
bottom:=math::max(bottom,Bottom),
CtlI=ctl(
wdef(wc_PushButton,rct(155,5+20*I,Right,Bottom),ButtonTitle,u_DlgBase),
I,FlagsI)
],
% 2016.04.01. Final stretch of the window
RCT=rct(50,40,right+60,bottom+10),
FontDef=dlgFont(
wdef(wd_Modal,RCT,Title,u_DlgBase),FontName,8,[wsf_TitleBar]),
default:=math::min(L-1,Default),
_ = vpi::winCreateDynDialog(Parent,[FontDef,Static|Ctl_List],
dlg_ask_eh,gui_api::lNull).
Code: Select all
% 2016.03.29. Validation of integer controls.
validateIntegerControl(IC) = control::contentsInvalid(Source,FocusControl,Msg) :-
IC:validate()=control::contentsInvalid(Source,FocusControl,Msg),
FocusControl:setFocus(),
Resp=extendedCommonDialogs::ask(substitute,Msg,value_choice_list,1),
substituteSpecialInteger(IC,Resp),
!.
validateIntegerControl(IC) = control::contentsOK :-
retractAll(previousInteger(IC,_)),
assertz(previousInteger(IC,IC:getInteger())).