RadioGroup can be MULTILINE

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

RadioGroup can be MULTILINE

Post by Pablo César »

Hi all, there is a way to increase (but not long, only two lines).
 
Screen79.png
Screen79.png (11.61 KiB) Viewed 4416 times
 
This is by the reason that in c_radio.c is fixed value to 28 of height item... :|

Here's the code to become MULTILINE in RadioGroup:
 

Code: Select all

#include <hmg.ch>

#define BS_MULTILINE         8192

Function Main()
Load Window Demo1
Demo1.Center
Demo1.Activate
Return Nil

Function ChngRadios()
HMG_ChangeWindowStyle ( GetControlHandle("RadioGroup_2","Demo1"), BS_MULTILINE, NIL, .F. )
Demo1.RadioGroup_2.Caption(3) := "Text will be in multiline and NOT at third line when is longer"
Return Nil
 
@ Claudio

Is it possible to increase height of item programmatically ? May you teach us how to do it, please ?
As you can in third item in red marked, it is not display for complete.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: RadioGroup can be MULTILINE

Post by srvet_claudio »

Usar:

SetWindowPos(
hWnd,
cx,
cy,
SWP_DRAWFRAME + SWP_NOMOVE + SWP_NOZORDER
)

También hay una función interna llamada _SetWindowHeight o algo parecido.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: RadioGroup can be MULTILINE

Post by Pablo César »

Usar:

SetWindowPos(
hWnd,
cx,
cy,
SWP_DRAWFRAME + SWP_NOMOVE + SWP_NOZORDER
)
Antes del cx y cy existen dos parametros más. No es cierto ?
Esta función iria cambiar el ancho de los items de un RadioGroup ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: RadioGroup can be MULTILINE

Post by KDJ »

Pablo

Maybe in this way:

Code: Select all

#include "hmg.ch"

FUNCTION Main()

  SET FONT TO 'MS Shell Dlg', 8

  DEFINE WINDOW MainWA;
    MAIN;
    ROW    100;
    COL    100;
    WIDTH  190;
    TITLE  "RadioGroup multiline";
    NOSIZE;
    NOMAXIMIZE;
    NOMINIMIZE

    DEFINE FRAME RadioFR
      ROW      10
      COL      50
      WIDTH    80
      CAPTION "RadioGroup"
    END FRAME

    DEFINE RADIOGROUP RadioRG
      ROW      30
      COL      60
      WIDTH    60
      VALUE     2
      OPTIONS {"Radio 1", e"Radio 2\ntwo lines", e"Radio 3\nthree\nlines"}
    END RADIOGROUP

    DEFINE BUTTON HeightBU
      COL      40
      WIDTH   100
      HEIGHT   25
      CAPTION ""
      ACTION  ChangeHeightRG()
    END BUTTON

    ON KEY ESCAPE ACTION MainWA.RELEASE
  END WINDOW

  ChangeHeightRG()

  MainWA.CENTER
  MainWA.ACTIVATE

RETURN NIL


FUNCTION ChangeHeightRG()
  STATIC lFixedH := .T.
  LOCAL nHeight

  lFixedH := ! lFixedH
  nHeight := RadioGroup_Format("RadioRG", "MainWA", 7, lFixedH)

  MainWA.RadioFR.HEIGHT := nHeight + 30
  MainWA.HeightBU.ROW   := MainWA.RadioFR.HEIGHT + 25

  MainWA.HEIGHT := (MainWA.HEIGHT - MainWA.CLIENTAREAHEIGHT) + MainWA.HeightBU.ROW + MainWA.HeightBU.HEIGHT + 10

  MainWA.HeightBU.CAPTION := If(lFixedH, "&Set variable height", "&Set fixed height")

RETURN NIL


FUNCTION RadioGroup_Format(cControl, cForm, nGap, lFixedHeight) //for vertical RadioGroup
  LOCAL nTotalH := 0
  LOCAL nFixedH := 0
  LOCAL nCount
  LOCAL aHandle
  LOCAL aHeight
  LOCAL cText
  LOCAL nLines
  LOCAL nRow, nCol, nWidth
  LOCAL nValue
  LOCAL n

  IF _IsControlDefined(cControl, cForm)
    IF (! HB_IsNumeric(nGap)) .or. (nGap < 0)
      nGap := 10
    ENDIF
    IF ! HB_IsLogical(lFixedHeight)
      lFixedHeight := .F.
    ENDIF

    nRow    := GetProperty(cForm, cControl, "ROW")
    nCol    := GetProperty(cForm, cControl, "COL")
    nWidth  := GetProperty(cForm, cControl, "WIDTH")
    nValue  := GetProperty(cForm, cControl, "VALUE")
    aHandle := GetControlHandle(cControl, cForm)
    nCount  := Len(aHandle)
    aHeight := Array(nCount)

    FOR n := 1 TO nCount
      cText      := GetWindowText(aHandle[n])
      nLines     := HB_TokenCount(cText, .T. /*lEOL*/)
      aHeight[n] := GetTextHeight(0, cText, GetWindowFont(aHandle[n])) * nLines
      nFixedH    := Max(nFixedH, aHeight[n])

      IF nLines > 1
        HMG_ChangeWindowStyle(aHandle[n], 0x2000 /*BS_MULTILINE*/, NIL, .F.)
      ENDIF

      IF nValue > 0
        IF nValue == n
          HMG_ChangeWindowStyle(aHandle[n], WS_TABSTOP, NIL, .F.)
        ELSE
          HMG_ChangeWindowStyle(aHandle[n], NIL, WS_TABSTOP, .F.)
        ENDIF
      ENDIF
    NEXT

    IF lFixedHeight
      FOR n := 1 TO nCount
        SetWindowPos(aHandle[n], 0, nCol, nRow, nWidth, nFixedH, 0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/)
        nRow += nGap + nFixedH
      NEXT

      nTotalH += nFixedH * nCount + nGap * (nCount - 1)
    ELSE
      FOR n := 1 TO nCount
        SetWindowPos(aHandle[n], 0, nCol, nRow, nWidth, aHeight[n], 0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/)
        nRow    += nGap + aHeight[n]
        nTotalH += aHeight[n]
      NEXT

      nTotalH += nGap * (nCount - 1)
    ENDIF
  ENDIF

RETURN nTotalH
Attachments
RadioGroup.png
RadioGroup.png (10.1 KiB) Viewed 4356 times
Last edited by KDJ on Sun Feb 05, 2017 10:05 pm, edited 1 time in total.
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: RadioGroup can be MULTILINE

Post by srvet_claudio »

Pablo César wrote: Sun Feb 05, 2017 6:45 pm
Usar:

SetWindowPos(
hWnd,
cx,
cy,
SWP_DRAWFRAME + SWP_NOMOVE + SWP_NOZORDER
)
Antes del cx y cy existen dos parametros más. No es cierto ?
Esta función iria cambiar el ancho de los items de un RadioGroup ?
Si los parámetros son col y row
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

RadioGroup can be MULTILINE

Post by Pablo César »

KDJ wrote: Sun Feb 05, 2017 7:50 pm Pablo

Maybe in this way:
Screen82.png
Screen82.png (19.78 KiB) Viewed 4317 times
Nice, nice NICE !! Always you Krzysztof surprising us. How nice ! I liked it !

Sometimes it doesn't seem so simple... much less so that when we have very little knowledge in C language... :oops:

I got something different. I did this a couple of hours ago and I was late to post on time while having my afternoon coffee ... sorry Krzysztof hopefully if this my message seems redundant but still think it is never late to show other ways to do. Do not you think ?
 
Screen80.png
Screen80.png (21.3 KiB) Viewed 4333 times
 
I really liked the way you do it, Krzysztof. Very creative by the way.

I did it this way I can work with RadioGroup horizontally as well. However, changing the spacing between the items and changing height and width has its consequences. The way I do it requires the user to discern all factors involved. Otherwise everything is weird and unfeasible.

The important thing to succeed in the result, attached what I had achieved:
 
RadioGroupMultiLine.rar
Source files
(1.8 KiB) Downloaded 213 times
 
My code is not finished. I know it can be done better.

Many thanks Krzysztof for your excellent and impeccable work.
Image
I loved the use of ClientAreaHeight based on the size of the Frame in it.
Awesome !
 
Screen81.png
Screen81.png (14.79 KiB) Viewed 4259 times
 
Dziękuję za nauczenie nas :geek:
(Sorry for my poor Polish language)
Last edited by Pablo César on Mon Feb 06, 2017 11:01 am, edited 1 time in total.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
serge_girard
Posts: 3167
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: RadioGroup can be MULTILINE

Post by serge_girard »

Thx Pablo & Krzysztof and others: DreamTeam...?

Serge
There's nothing you can do that can't be done...
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

RadioGroup can be MULTILINE

Post by Pablo César »

Hahaha not so much Serge... (at least I speak for myself, I'm a continuous student)

Thanks Serge but, I believe we each of us can do part of the HMG Dream Team when we collaborating, participating and we spreading to others our work tools. As the same you do too. :)

I ended up forgetting to mention about the 9th optional parameter which is the number to which you want to change only.
 
Screen84.png
Screen84.png (16.32 KiB) Viewed 4272 times
 
Re-remembering that the 8th parameter should also must be changed.
Because the combination of these factors changes the layout of RadioGroup in a sometimes radical way.
 
Screen85.png
Screen85.png (19.8 KiB) Viewed 4272 times
Here's the little changed code:
 
RadioGroupMultiLine.rar
Source files
(1.85 KiB) Downloaded 203 times
 
I think this code is only useful in cases where the text size of RadioGroup items does not change at all times. I mean that even if of different sizes, they are always of the fixed size. Not the same as OptionBox, for example.

I hope it's educational and funny... :D

PS: The gray backcolor of RadioGroups is just to duly denote size and position of each item.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: RadioGroup can be MULTILINE

Post by KDJ »

Pablo, probably there is something missing in this code.
It did not succeed to me to get such effect like on your picture.
Attachments
RadioGroupMultiLine.png
RadioGroupMultiLine.png (13.76 KiB) Viewed 4218 times
EduardoLuis
Posts: 683
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina

Re: RadioGroup can be MULTILINE

Post by EduardoLuis »

Hi Pablo:

I agree with Krzysztof, compiled you sample differs with your posted picture.-
May be something is missing.-
With regards.
Eduardo
Post Reply