Page 1 of 1

DCMULTILINE and Fontsize

Posted: Wed Dec 05, 2018 12:00 am
by Koverhage
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"

Re: DCMULTILINE and Fontsize

Posted: Wed Dec 05, 2018 1:57 am
by Tom
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.

Re: DCMULTILINE and Fontsize

Posted: Wed Dec 05, 2018 2:12 am
by Tom
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

Re: DCMULTILINE and Fontsize

Posted: Wed Dec 05, 2018 2:47 am
by Koverhage
Tom,
thank you.

Re: DCMULTILINE and Fontsize

Posted: Wed Dec 05, 2018 3:04 am
by Tom
A pleasure. ;)

I added a small change (lFontChanged) which will prevent SetFontCompoundName to be executed with every key stroke.

Re: DCMULTILINE and Fontsize

Posted: Tue Dec 11, 2018 11:39 pm
by Koverhage
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)}

Re: DCMULTILINE and Fontsize

Posted: Wed Dec 12, 2018 12:00 am
by Wolfgang Ciriack
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]

Re: DCMULTILINE and Fontsize

Posted: Wed Dec 12, 2018 1:31 am
by Tom
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.

Re: DCMULTILINE and Fontsize

Posted: Wed Dec 12, 2018 4:20 am
by Koverhage
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