SDL dlglib quirk?

Discussions related to the code libraries supplied with BB4W & BBCSDL
Allen_Socket
Posts: 2
Joined: Sat 07 Apr 2018, 18:15

SDL dlglib quirk?

Post by Allen_Socket »

Hi All,

I'm working on a project involving use of 'dlg lib'.
I am loading two values, AutoSave and AutoSort, from a settings file. Each of these values is either TRUE (yes, perform this action) or FALSE (don't perform the action).
I am creating a dialogue after loading these values and I've noticed that if the value is TRUE then the dialogue item does not exist (or at least it is not visible).
Is this a quirk of dlglib or a bug or a feature? If it's a feature then could someone please explain it's purpose?
Or am I just doing things in the wrong order?

Thanks in advance.
Joe.

Test Code:

Code: Select all

      REM * dlglib quirk?

      MODE 8

      INSTALL @lib$+"dlglib"
      PROC_setdialogpalette
      OSCLI "FONT """+@lib$+"DejaVuSans"",10"


      REM *** Test values ***
      AutoSave=TRUE
      AutoSort=FALSE
      REM *******************


      REM Create Dialogue
      DLG_X_CENTRE=&80000000
      DLG_Y_CENTRE=&80000000
      PROCDlgOptions


      dlg%=DlgOptions%
      PROC_registerdlgcallback(dlg%,FNdlgcb())
      PROC_setdialogtitle(dlg%,"Options")
      d%=FN_showdialog(dlg%,DLG_X_CENTRE,DLG_Y_CENTRE)
      REM d% holds index of any button which is pressed
      PROC_closedialog(dlg%)
      CASE d% OF
        WHEN 1
          REM 'OK' pressed
          AutoSave=FN_isdlgitemchecked(dlg%,101)
          AutoSort=FN_isdlgitemchecked(dlg%,102)
        WHEN 2
          REM 'Cancel' pressed - do nothing
      ENDCASE

      PRINT "AutoSave = ";AutoSave
      PRINT "AutoSort = ";AutoSort
      END



      DEFPROCDlgOptions
      LOCAL dlg%
      LOCAL dw,dh,x,y,w_but,w,h
      dw=128:dh=128
      dlg%=FN_newdialog("",dw,dh)
      x=16:y=14
      w=80:h=12
      PROC_checkbox(dlg%,"Auto Save",101,x,  y,w,h,AutoSave)
      PROC_checkbox(dlg%,"Auto Sort",102,x,2*y,w,h,AutoSort)
      x=64:y=112
      w_but=32
      PROC_button(dlg%,"Cancel",2,dw-(2*w_but)-16,y,w_but,h,0)
      PROC_button(dlg%,"OK"    ,1,dw-w_but-8,     y,w_but,h,0)
      DlgOptions%=dlg%
      ENDPROC


      DEFFNdlgcb(D%,K%)
      REM use keypress instead of mouse click; 13 = Enter (OK), 27 = Escape (Cancel)
      IF K%=13 THEN =1
      IF K%=27 THEN =2
      =0

RichardRussell
Posts: 593
Joined: Tue 15 Oct 2019, 09:10

Re: SDL dlglib quirk?

Post by RichardRussell »

Allen_Socket wrote:
Wed 11 Nov 2020, 12:37
Is this a quirk of dlglib or a bug or a feature? If it's a feature then could someone please explain it's purpose?
I think you've misunderstood the use of the final parameter of PROC_checkbox(). As in the equivalent BB4W library, this parameter is a flags or style value, and by setting it to AutoSave (which is TRUE) you have inadvertently set the bit which causes it to be hidden! Try changing the final parameter of your PROC_checkbox() calls to zero:

Code: Select all

      REM * dlglib quirk?

      MODE 8

      INSTALL @lib$+"dlglib"
      PROC_setdialogpalette
      OSCLI "FONT """+@lib$+"DejaVuSans"",10"


      REM *** Test values ***
      AutoSave=TRUE
      AutoSort=FALSE
      REM *******************


      REM Create Dialogue
      DLG_X_CENTRE=&80000000
      DLG_Y_CENTRE=&80000000
      PROCDlgOptions


      dlg%=DlgOptions%
      PROC_registerdlgcallback(dlg%,FNdlgcb())
      PROC_setdialogtitle(dlg%,"Options")
      d%=FN_showdialog(dlg%,DLG_X_CENTRE,DLG_Y_CENTRE)
      REM d% holds index of any button which is pressed
      PROC_closedialog(dlg%)
      CASE d% OF
        WHEN 1
          REM 'OK' pressed
          AutoSave=FN_isdlgitemchecked(dlg%,101)
          AutoSort=FN_isdlgitemchecked(dlg%,102)
        WHEN 2
          REM 'Cancel' pressed - do nothing
      ENDCASE

      PRINT "AutoSave = ";AutoSave
      PRINT "AutoSort = ";AutoSort
      END



      DEFPROCDlgOptions
      LOCAL dlg%
      LOCAL dw,dh,x,y,w_but,w,h
      dw=128:dh=128
      dlg%=FN_newdialog("",dw,dh)
      x=16:y=14
      w=80:h=12
      PROC_checkbox(dlg%,"Auto Save",101,x,  y,w,h,0)
      PROC_checkbox(dlg%,"Auto Sort",102,x,2*y,w,h,0)
      x=64:y=112
      w_but=32
      PROC_button(dlg%,"Cancel",2,dw-(2*w_but)-16,y,w_but,h,0)
      PROC_button(dlg%,"OK"    ,1,dw-w_but-8,     y,w_but,h,0)
      DlgOptions%=dlg%
      ENDPROC


      DEFFNdlgcb(D%,K%)
      REM use keypress instead of mouse click; 13 = Enter (OK), 27 = Escape (Cancel)
      IF K%=13 THEN =1
      IF K%=27 THEN =2
      =0
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.

Allen_Socket
Posts: 2
Joined: Sat 07 Apr 2018, 18:15

Re: SDL dlglib quirk?

Post by Allen_Socket »

Richard,

Thank you for the rapid reply.

I was not aware that setting the style to -1 (TRUE) makes the dialogue item invisible. I may have overlooked it, but I can't see this mentioned in the Help documentation, either online or direct from BB4W. Anyway, I have learned something new!

I was hoping to set the 'style' parameter directly when setting up the dialogue box using TRUE/FALSE but I've been caught out!

I've modified my program to use 0 (active/visible but unchecked) and 1 (active/visible and checked).

And I'll certainly do some more research around the dialogue libraries, both BB4W and BBC_SDL!

Thanks again.
Joe.

RichardRussell
Posts: 593
Joined: Tue 15 Oct 2019, 09:10

Re: SDL dlglib quirk?

Post by RichardRussell »

Allen_Socket wrote:
Wed 11 Nov 2020, 15:08
I was not aware that setting the style to -1 (TRUE) makes the dialogue item invisible. I may have overlooked it, but I can't see this mentioned in the Help documentation, either online or direct from BB4W.
It's a fundamental aspect of all software documentation that you can't deduce a negative. In other words if it says that setting a particular bit has a certain effect, you cannot conclude that setting a different bit - which is not explicitly mentioned - will have no effect. If that were true there would be no possibility of reserving 'spare' bits for future expansion. So if you set a bit that is not mentioned the effect is unpredictable.

In the case of the style parameter of PROC_checkbox() the Help manual mentions the bits that you are most likely to be interested in (for example WS_GROUP which has the value &20000) but there are several other bits that apply to all windows (a full list is here) that are not explicitly mentioned.

The particular style bit that is relevant in your case is WS_VISIBLE (&10000000) which if set will result in the control being invisible, i.e. hidden. By setting the style value to TRUE you are inadvertently setting all 32 style bits at the same time, and because that includes the WS_VISIBLE bit the control ends up being hidden!

It's true that the dlglib library supports significantly fewer style bits than the equivalent BB4W library, but WS_VISIBLE is supported, as is WS_DISABLED (&8000000) and WS_TABSTOP (&10000).
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.