#Include TCHUI.System #Include %occConstant // ==================================================== // Een collectie aan gemeenschappelijke TCHUI routines // ==================================================== UserAvailable() ;Check of de ingelogde gebruiker bekend is... Quit:(%Application.User.%Id()'="") 1 Do $$$ShowMsgBoxSimple("Van Hoecke - Kennisanker","Uw gebruikersnaam is niet bekend, verwittig ICT.") Do %Screen.Canvas.ChangeFont(%Screen.Font) Kill %Application,%Screen,%Input Quit 0 ;Create environment CreateEnv Set %Application=##class(TCHUI.TApplication).Create() Do %Application.AttachDebugEvents() Set %Screen=##class(TCHUI.TScreen).Create($$$ttVT520) Set %Input=##class(TCHUI.TInput).Create() Do %Screen.Clear() Quit BootApp(FormClass,Name,Caption,AttachDebugEvents,FormType) try { Set FormType=$G(FormType,$$$ftMain) Set %Application=##class(TCHUI.TApplication).Create() Set AttachDebugEvents=$G(AttachDebugEvents,1) Do:(AttachDebugEvents) %Application.AttachDebugEvents() Set %Screen=##class(TCHUI.TScreen).Create($$$ttVT520) Set %Input=##class(TCHUI.TInput).Create() Do %Screen.Clear() Set Name=$G(Name,$P(FormClass,".",$L(FormClass,"."))) Set Form=%Application.CreateForm(FormClass,Name,$G(Caption,Name),1,1,%Screen.Height,%Screen.Width,,$$$ftMain) Do %Application.Run() Do %Screen.Canvas.ChangeFont(%Screen.Font) } catch { new Exception set Exception = ##class(TECH.ExceptionHandler).Catch() do ##class(vhLib.Logger).LogEnMailExceptie(Exception) Do $$$ShowMsgBoxSimple($G(Caption,$G(Name,"Applicatie")),"Er heeft zich een onverwachte fout voorgedaan.") } kill %Control,%Application,%Screen,%Input Quit GetDefaultFGColor(FormType,FontSelect) Set Font=%Screen.Fonts(FormType,FontSelect) Quit Font.FGColor GetDefaultBGColor(FormType,FontSelect) Set Font=%Screen.Fonts(FormType,FontSelect) Quit Font.BGColor PointInRect(Y, X, lbRect) Quit (Y'<$LI(lbRect,1)) && (X'<$LI(lbRect,2)) && (Y'>$LI(lbRect,3)) && (X'>$LI(lbRect,4)) // Geef een control op en krijg zijn form terug GetParentForm(Control) Quit:(Control="") "" For Quit:(Control.Parent="") Set Control=Control.Parent Quit $S(Control.%IsA("TCHUI.TForm"):Control,1:"") // Geef een control op en krijg een 'leesbare' naam terug GetDebugControlName(Control) Quit:('$IsObject(Control)) "(nil)" Set Name=Control.%ClassName(1) Set:($L(Name,"TCHUI.")=2) Name=$P(Name,"TCHUI.",2) If Control.%IsA("TCHUI.TControlBasis") Do . Set Name=Control.Name_" ("_Name_")" . For Quit:(Control.Parent="") Set Control=Control.Parent, Name=Control.Name_"."_Name Quit Name ShowObjs() New Form Set Form=%Application.CreateForm("TCHUI.Utils.COS.MainForm","frmCOS","COS Terminal Edition",1,1,%Screen.Height,%Screen.Width,,$$$ftDialog) Do Form.lstObjects.Refresh() Do Form.ShowModal() Do Form.Destroy() Quit GetWordWrap(Input,Width,varHeight) Set varHeight=0 ;Indien width=0 of kleiner, dan hoeven zelfs niet eens proberen te wrappen Quit:($G(Width,0)<1) "" New Output,Char,InputLoop,LineLoop,LastSpacePos,tmpLine,tmpWordLine Set Output="" ;Wrapped output string Set InputLoop=1 ;Loop doorheen alle chars aanwezig in input Set LineLoop=1 ;Telt het aantal chars per lijn en zorgt ervoor dat param 'Width' niet wordt overschreden Set LastSpacePos=0 ;Onthoud de positie van de laatste spatie (InputLoop zal hierheen+1 terugspringen bij Width overschrijding) Set tmpLine="" ;Deze var houdt tijdelijk inputchars bij ;Lopen doorheen alle chars van param 'Input' For Set Char=$E(Input,InputLoop) Quit:(Char="") Do . ; gevonden in de input? huidige lijnbuffer heeft Width niet overschreden, deze dus gewoon verwerken (zal zelfde genereren) . If Char=$C(13) && ($E(Input,InputLoop+1)=$C(10)) Do Quit .. Do ProcessLine(1,1) .. Set InputLoop=InputLoop+2 ;Volgend karakter reeds uitgelezen + quit if -> loop + 2 . ; gevonden in input . If Char=" " Do .. Set LastSpacePos=InputLoop ;Positie in input onthouden voor wanneer Width wo overschreden .. Set tmpWordLine=tmpLine ;Plaats lijnbuffer in wordbuffer, deze buffer bevat dan 'woorden' . ;Huidige lijnbuffer overschrijdt opgegeven width . If LineLoop>Width Do .. Do ProcessLine((LastSpacePos=0)) ;Schrijf de huidig vergaarde lijn of wordbuffer naar buiten (afh of dat er een spatie werd gevonden of niet) . ;Zoniet, voeg karakter toe aan lijnbuffer . Else Do .. Set tmpLine=tmpLine_Char . Set InputLoop=InputLoop+1 . Set LineLoop=LineLoop+1 ;Verwerk de nog overgebleven bufferinhoud Do ProcessLine(1) Set varHeight=$L(Output,$$$NL) Quit Output ProcessLine(PushLine,WasEnter) Set WasEnter=$G(WasEnter,0) New AddToOutput ;Huidige ingelezen lijnbuffer aan output toevoegen If PushLine Do . Set AddToOutput=tmpLine ;Enkel de wordbuffer aan output toevoegen, inputteller terugzetten op laatste spatie zodat we vanaf hier ;de nieuwe chars voor de volgende lijn kunnen inlezen (+1 volgt na uitvoering rtn) Else Do . Set InputLoop=LastSpacePos . Set AddToOutput=tmpWordLine ;Output vervolledigen Set Output=$S(Output="":"",1:Output_$$$NL)_AddToOutput ;Indien lijnbuffer werd toegevoegd, dan is het uigelezen char 'genegeerd' omdat deze LineLoop>Width triggerde, dit toevoegen aan ;nieuwe buffer zodat het toch nog verwerkt wordt (uitzondering: enter) If PushLine && 'WasEnter Do . Set tmpLine=Char . Set LineLoop=1 Else Do . Set tmpLine="" . Set LineLoop=WasEnter Set LastSpacePos=0 Quit // ***************************************************************************************************** // InputBox // ***************************************************************************************************** InputBox(Caption,Message,DefaultValue,Width,PasswordChar) #Define cntDefaultWidth 50 ;Message form New MsgForm Set MsgForm=%Application.CreateForm("TCHUI.TForm","dlgInput"_$TR(Caption," ",""),Caption,1,1,10,30,,$$$ftDialog) New FormWidth Set FormWidth=$G(Width,$$$cntDefaultWidth) Set MsgForm.Width=FormWidth Set MsgForm.Left=(%Screen.Width-FormWidth)\2 ;FormHeight bepalen adhv message New Memo Set Memo=##class(TCHUI.TMemo).Create(MsgForm,"mmoMsg","",3,3,2,FormWidth-3,2,2,,$LB($$$clUltraLight,$$$clUltraDark)) Set Memo.TabStop=0 Set Memo.Text=Message Do Memo.Wrap() ;Indien slechts 1 row, neem dan toch een plaats van hoogte 3 in beslag Set Memo.Height=Memo.Rows New FormHeight Set FormHeight=Memo.Height+7 Set MsgForm.Height=FormHeight Set MsgForm.Top=(%Screen.Height-FormHeight)\2 ;Msg kader New Kader Set Kader=##class(TCHUI.TKader).Create(MsgForm,"kdrMsg",Caption,1,1,MsgForm.Height,MsgForm.Width,1,1,,) ;Lijn boven buttons New Line Set Line=##class(TCHUI.TLijn).CreateLijn($$$loHorizontal,MsgForm,"lnMsg",FormHeight-2,1,FormWidth,FormHeight-2,,,$LB($LB(1,"ML"),$LB(,"MR"))) ;Creatie van de buttons op de form New Button,BtnCaption Set BtnCaption=$$ButtonToCaption($$$mbCancel) Set Button=##class(TCHUI.TButton).Create(MsgForm,"Btn"_BtnCaption,BtnCaption,FormHeight-1,FormWidth-11,1,10,5,5,,$LB($$$clUltraLight,$$$clDark),$$$alCenter) Set Button.ModalResult=$$$mrCancel Set BtnCaption=$$ButtonToCaption($$$mbOk) Set Button=##class(TCHUI.TButton).Create(MsgForm,"Btn"_BtnCaption,BtnCaption,FormHeight-1,FormWidth-22,1,10,4,4,,$LB($$$clUltraLight,$$$clDark),$$$alCenter) Set Button.ModalResult=$$$mrOk Set Button.Default=1 New Edit Set Edit=##class(TCHUI.TEdit).Create(MsgForm,"txtValue","",FormHeight-4,3,1,FormWidth-4,3,3) Set Edit.Value=DefaultValue Set Edit.AutoErase=1 Set:($D(PasswordChar)) Edit.PasswordChar=$E(PasswordChar) New Result Set Result=MsgForm.ShowModal() Set DefaultValue=Edit.Value Do MsgForm.Destroy() Quit Result // ***************************************************************************************************** // Flying Message // ***************************************************************************************************** CreateFM(Caption,Message,AddProgressBar,SeperateProgressBar) Set AddProgressBar=$G(AddProgressBar,0) Set SeperateProgressBar=$G(SeperateProgressBar,1) New FormHeight Set FormHeight=$S(AddProgressBar && SeperateProgressBar:7,1:5) Set MsgForm=%Application.CreateForm("TCHUI.TForm","dlgFly"_$TR(Caption," ",""),Caption,1,1,FormHeight,60,,$$$ftDialog) Do MsgForm.Center() New Kader Set Kader=##class(TCHUI.TKader).Create(MsgForm,"kdrMsg",Caption,1,1,MsgForm.Height,MsgForm.Width,1,1,,) If SeperateProgressBar Do . Set Label=##class(TCHUI.TLabel).Create(MsgForm,"lblMsg",Message,3,3,2,56,2,2,,$LB(,,$$$fsNoUnderline),$$$alCenter) If AddProgressBar Do . New Top . Set Top=$S(SeperateProgressBar:5,1:3) . Set ProgressBar=##class(TCHUI.TProgressBar).Create(MsgForm,"pbMsg","",Top,3,2,56,3,3) . If SeperateProgressBar Do .. Set ProgressBar.Position=0 . Else Do .. Set ProgressBar.ShowPercentage=0 .. Set ProgressBar.Caption=Message . Set ProgressBar.FGColor=$$GetDefaultBGColor($$$ftDialog,$$$fsInvert) . Set ProgressBar.BGColor=$$GetDefaultFGColor($$$ftDialog,$$$fsEdit) Do MsgForm.Show() Quit ChangeFM(Message) Set Label.Caption=Message Quit ChangeFMPB(Position) Set ProgressBar.Position=Position Quit DestroyFM() Kill Label,ProgressBar Do MsgForm.Hide() Do MsgForm.Destroy() Kill MsgForm Quit // ***************************************************************************************************** // MessageBox // ***************************************************************************************************** MessageBox(Caption,Message,lbButtons,MessageType=$$$mtInformation,DefaultButton=$$$mbCancel) #Define cntMinButtonWidth 10 #Define cntButtonSpace 2 #Define cntMinFormWidth 60 Set lbButtons=$G(lbButtons,$LB($$$mbOk)) ;Message form New MsgForm,Font Set Font=$S(MessageType=$$$mtError:$LB($$$clRed),1:"") Set MsgForm=%Application.CreateForm("TCHUI.TForm","dlg"_$TR(Caption," ",""),Caption,1,1,10,30,Font,$$$ftDialog) ;Formwidth achterhalen adhv buttons New Loop,BtnWidth,BtnWidthSum,ButtonType,BtnCaption Set BtnWidthSum=0 For Loop=1:1:$LL(lbButtons) Do . Set ButtonType=$LI(lbButtons,Loop) . Set BtnCaption=$$ButtonToCaption(ButtonType) . Set BtnWidth=$L(BtnCaption)+2 . Set:(BtnWidth<$$$cntMinButtonWidth) BtnWidth=$$$cntMinButtonWidth . If Loop=1 Do .. Set BtnWidthSum=BtnWidth . Else Do .. Set BtnWidthSum=BtnWidthSum+$$$cntButtonSpace+BtnWidth New FormWidth Set FormWidth=BtnWidthSum+4 Set:(FormWidth<$$$cntMinFormWidth) FormWidth=$$$cntMinFormWidth Set MsgForm.Width=FormWidth Set MsgForm.Left=(%Screen.Width-FormWidth)\2 New ButtonOffsetLeft Set ButtonOffsetLeft=((FormWidth-BtnWidthSum)\2)+1 New Label,LabelWidth Set LabelWidth=FormWidth-4 Set Label=##class(TCHUI.TLabel).Create(MsgForm,"lblMsg","",3,3,2,LabelWidth,2) Set Label.Sizing=$$$lsFixed New WrappedMsg,varRows Set Label.Caption=$$GetWordWrap(Message,LabelWidth,.varRows) Set Label.Height=varRows New FormHeight If varRows>17 Do . Set FormHeight=varRows+4 . Set Label.Top=2 Else Do . Set FormHeight=varRows+6 . Set Label.Top=3 Set MsgForm.Height=FormHeight Set MsgForm.Top=(%Screen.Height-FormHeight)\2 ;Msg kader New Kader Set Kader=##class(TCHUI.TKader).Create(MsgForm,"kdrMsg",Caption,1,1,MsgForm.Height,MsgForm.Width,1,1,,) ;Lijn boven buttons New Line Set Line=##class(TCHUI.TLijn).CreateLijn($$$loHorizontal,MsgForm,"lnMsg",FormHeight-2,1,FormWidth,FormHeight-2,,,$LB($LB(1,"ML"),$LB(,"MR"))) ;Creatie van de buttons op de form New Button,DefButton Set BtnWidthSum=0, DefButton=0 For Loop=1:1:$LL(lbButtons) Do . Set ButtonType=$LI(lbButtons,Loop) . Set BtnCaption=$$ButtonToCaption(ButtonType) . Set BtnWidth=$L(BtnCaption)+2 . Set:(BtnWidth<$$$cntMinButtonWidth) BtnWidth=$$$cntMinButtonWidth . Set Button=##class(TCHUI.TButton).Create(MsgForm,"Btn"_BtnCaption,BtnCaption,FormHeight-1,ButtonOffsetLeft+BtnWidthSum,1,BtnWidth,(2+Loop),(2+Loop),,$LB($$$clUltraLight,$$$clDark),$$$alCenter) . Set BtnWidthSum=BtnWidthSum+BtnWidth+2 . Set Button.ModalResult=$$ButtonToModalResult(ButtonType) . Set:(ButtonType=DefaultButton) DefButton=Button Set:($IsObject(DefButton)) MsgForm.ActiveControl=DefButton New Result Set Result=MsgForm.ShowModal() Do MsgForm.Destroy() Quit Result ButtonToModalResult(Button) Quit $CASE(Button,$$$mbYes:$$$mrYes,$$$mbNo:$$$mrNo,$$$mbOk:$$$mrOk,$$$mbCancel:$$$mrCancel,$$$mbAbort:$$$mrAbort,$$$mbRetry:$$$mrRetry,$$$mbIgnore:$$$mrIgnore,$$$mbAll:$$$mrAll,$$$mbNoToAll:$$$mrNoToAll,$$$mbYesToAll:$$$mrYesToAll,$$$mbHelp:$$$mrHelp,$$$mbSave:$$$mrSave,$$$mbNoSave:$$$mrNoSave,:Button) ButtonToCaption(Button) Quit $CASE(Button,$$$mbYes:$$$SMsgDlgYes,$$$mbNo:$$$SMsgDlgNo,$$$mbOk:$$$SMsgDlgOk,$$$mbCancel:$$$SMsgDlgCancel,$$$mbAbort:$$$SMsgDlgAbort,$$$mbRetry:$$$SMsgDlgRetry,$$$mbIgnore:$$$SMsgDlgIgnore,$$$mbAll:$$$SMsgDlgAll,$$$mbNoToAll:$$$SMsgDlgNoToAll,$$$mbYesToAll:$$$SMsgDlgYesToAll,$$$mbHelp:$$$SMsgDlgHelp,$$$mbSave:$$$SMsgDlgSave,$$$mbNoSave:$$$SMsgDlgNoSave,:Button)