This forum is for general support of Xbase++
Koverhage
Posts: 151 Joined: Mon Feb 01, 2010 8:45 am
#1
Post
by Koverhage » Wed Dec 05, 2018 12:00 am
Hello,
i want add a function to change the font size as needed with the
xbeK_P_CTRL_MINUS and xbeK_P_CTRL_PLUS keys
How i can do this ?
I have
Code: Select all
@ 1, 1 DCMULTILINE k_txt SIZE lastcol-5, 5 LINELENGTH 150 EXITKEY xbeK_F6 ;
FONT {|| myEditFont(nFontSize, GetList)} WHEN {|| !v_dru } PARENT oGroupReKote
Code: Select all
static function myEditFont(nFontSize, aGetList)
Local nKey := DC_ReadGuiLastKey(aGetList)
IF nKey = xbeK_P_CTRL_PLUS // CTRL und +
IF nFontSize < 16
nFontSize++
ENDIF
ENDIF
IF nKey = xbeK_P_CTRL_MINUS // CTRL und -
IF nFontSize > 8
nFontSize--
ENDIF
ENDIF
return ltrim(str(nFontSize))+".Courier"
Klaus
Tom
Posts: 1234 Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany
#2
Post
by Tom » Wed Dec 05, 2018 1:57 am
Hi, Klaus.
1. Add a custom handler using DCREAD GUI ... HANDLER(BLOCK). Hand the DCMULTILINE object and the current font size* to the handler.
2. In the (addiditional) handler, check keyboard events for xbeK_P_CTRL_PLUS and xbeK_P_CTRL_MINUS - and check whether they occur while the multiline has focus. Increase/decrease the font size like you did in your function.
3. Change the font using oMLE:SetFontCompoundName(<cNewFont>) with font size and name. Don't use a codeblock for the font - this won't work.
* You may extract the font size from oMLE:SetFontCompoundName(), so you don't need to hand it as a parameter.
If you need more help or maybe a small sample, let me know.
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
Posts: 1234 Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany
#3
Post
by Tom » Wed Dec 05, 2018 2:12 am
This works as you want it:
Code: Select all
#pragma Library("Dclipx.lib")
proc AppSys() ; RETURN
FUNCTION Main()
LOCAL GetList := {}, c := 'I love this f*cking bullshit', oMLE, cFont := "12.Tahoma"
@ 1,1 DCMULTILINE c SIZE 100,20 OBJECT oMLE FONT cFont
DCREAD GUI FIT ADDBUTTONS TITLE 'Test' ;
HANDLERBLOCK {|a,b,c,d,e,f|MyHandler(a,b,c,d,e,f,oMLE)}
RETURN NIL
FUNCTION MyHandler(nEvent,mp1,mp2,oXbp,oDlg,GetList,oMLE)
LOCAL cFont := oMLE:SetFontCompoundName(), nFontSize := Val(Left(cFont,At(".",cFont)-1)), cFontName := SubStr(cFont,At(".",cFont)+1), lFontChanged := .F.
IF nEvent == xbeP_Keyboard .AND. oXbp == oMLE
IF mp1 == xbeK_P_CTRL_PLUS .AND. nFontSize < 24
nFontSize ++
lFontChanged := .T.
ELSE
IF mp1 == xbeK_P_CTRL_MINUS .AND. nFontSize > 6
nFontSize --
lFontChanged := .T.
ENDIF
ENDIF
IF lFontChanged
oMLE:SetFontCompoundName(LTrim(Str(nFontSize,2,0))+"."+cFontName)
ENDIF
ENDIF
RETURN DCGUI_NONE
Last edited by
Tom on Wed Dec 05, 2018 3:03 am, edited 1 time in total.
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
Posts: 1234 Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany
#5
Post
by Tom » Wed Dec 05, 2018 3:04 am
A pleasure.
I added a small change (lFontChanged) which will prevent SetFontCompoundName to be executed with every key stroke.
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Koverhage
Posts: 151 Joined: Mon Feb 01, 2010 8:45 am
#6
Post
by Koverhage » Tue Dec 11, 2018 11:39 pm
One more question.
How i can obtain which object is aktive i i can give the correct object to the HANDLERBLOCK ?
I have 2 dcmultiline
Code: Select all
@ 3.2, 1 DCSAY mess257
@ 03, 15 DCMULTILINE m_khin SIZE 65, lastrow-8 LINELENGTH 55 NOHORIZSCROLL ;
OBJECT oMLE FONT cFont ;
MESSAGE mess262
@ 3.2, 97 DCSAY mess1839 ALIGNRIGHT
@ 03, 99 DCMULTILINE m_vtext SIZE 60, lastrow-8 LINELENGTH 50 NOHORIZSCROLL ;
OBJECT oMLE1 FONT cFont ;
MESSAGE mess1840
DCREAD GUI OPTIONS GetOptions TITLE mess195 + " " + Printaz(m_kdnr) + " " + ;
rtrim(m_match) + ' '+mess196 MODAL SETAPPWINDOW to lOk ENTEREXIT ;
HANDLERBLOCK {|a,b,c,d,e,f|MyMultiLineHandler(a,b,c,d,e,f,oMLE)}
Klaus
Wolfgang Ciriack
Posts: 484 Joined: Wed Jan 27, 2010 10:25 pm
Location: Berlin Germany
#7
Post
by Wolfgang Ciriack » Wed Dec 12, 2018 12:00 am
Give your MLEs as parameter to the Handler:
Code: Select all
DCREAD ......
HANDLER MyMultiLineHandler REFERENCE aRef ;
EVAL {|o| aRef[1]:=oMLE, aRef[2]:=oMLE1 }
in the Handler you have now access to the MLEs:
Code: Select all
FUNCTION MyMultiLineHandler( nEvent, mp1, mp2, oXbp, GetList, oDialog, aRef)
local oMLE:=aRef[1], oMLE1:=aRef[2]
_______________________
Best Regards
Wolfgang
Tom
Posts: 1234 Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany
#8
Post
by Tom » Wed Dec 12, 2018 1:31 am
Or, easier: Just check if oXbp is a DCMULTILINE inside the handler:
Code: Select all
IF oXbp:IsDerivedFrom("XbpMLE")
* get font
* act on font resizing
ENDIF
In this situation, you don't have to use oMLE as a parameter for the handler. But you have to move this operations:
Code: Select all
cFont := oMLE:SetFontCompoundName()
nFontSize := Val(Left(cFont,At(".",cFont)-1))
cFontName := SubStr(cFont,At(".",cFont)+1)
from the definition of the local vars to the IF-statement, since not all other Xbparts have font settings. That's it. If you want to have this working for all MLEs, that's the way to do it. No changes to other code necessary, just this handler everywhere you have DCMULTILINES.
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Koverhage
Posts: 151 Joined: Mon Feb 01, 2010 8:45 am
#9
Post
by Koverhage » Wed Dec 12, 2018 4:20 am
Wolfgang, Tom
Thanks
Now i use this:
Code: Select all
FUNCTION MyMultiLineHandler(nEvent,mp1,mp2,oXbp,oDlg,GetList)
LOCAL cFont := "", ;
nFontSize := 0, ;
cFontName := "", ;
lFontChanged := .F.
IF ISOBJECT( oXbp )
IF oXbp:IsDerivedFrom("XbpMLE")
cFont := oXbp:SetFontCompoundName()
nFontSize := Val(Left(cFont,At(".",cFont)-1))
cFontName := SubStr(cFont,At(".",cFont)+1)
ENDIF
IF nEvent == xbeP_Keyboard .AND. oXbp:IsDerivedFrom("XbpMLE")
IF mp1 == xbeK_P_CTRL_PLUS .AND. nFontSize < 16
nFontSize ++
lFontChanged := .T.
ELSE
IF mp1 == xbeK_P_CTRL_MINUS .AND. nFontSize > 8
nFontSize --
lFontChanged := .T.
ENDIF
ENDIF
IF lFontChanged
oXbp:SetFontCompoundName(LTrim(Str(nFontSize,2,0))+"."+cFontName)
ENDIF
ENDIF
ENDIF
RETURN DCGUI_NONE
Klaus