cobasystems DCPUSHBUTTONXP tips-and-tricks

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
cobasystems
Posts: 15
Joined: Wed Nov 12, 2014 4:44 pm

cobasystems DCPUSHBUTTONXP tips-and-tricks

#1 Post by cobasystems »

Roger,
whether there is another, more beautiful and elegant solution for
RadioButtons effect in command DCPUSHBUTTONXP, when using the keyboard
F1, F2, F3, F4, of the solutions that I managed to do, and that is pretty rough ?

Image

Code: Select all

#include "Appevent.ch"
#include "Common.ch"
#include "Xbp.ch"
#include "Font.ch"
#include "Gra.ch"
#include "Xbtsys.ch"

#INCLUDE "DCDIALOG.CH"
#INCLUDE "DCGRA.CH"
#PRAGMA Library( "DCLIPX.LIB" )

PROCEDURE APPSYS()
RETURN NIL
PROCEDURE MAIN()
TEST()
RETURN NIL
*************************************************************************
FUNCTION TEST()
*************************************************************************
LOCAL GetList := {}, GetOptions,  oDlg

 LOCAL ;
 x1 := 0.6       ,;
 y1 := 0.6       ,;
 du := 15-0.2    ,;
 bb := 3-0.1     ,;
 bmpOkvir := nil ,;
 CUR := {"user32.dll",114}

 LOCAL ;
 co1 := GRA_CLR_WHITE,   co2 := GRA_CLR_DARKGREEN, ;
 co3 := GRA_CLR_BLACK,   co4 := GRA_CLR_YELLOW,    ;
 co5 := GRA_CLR_DARKRED, fo1 := "12.Arial Bold"

 PUBLIC o1,o2,o3,o4,oEnd // dcpushbutton objects

 SET CHARSET TO ANSI


 @ 0,0.5 ;
 DCSTATIC TYPE XBPSTATIC_TYPE_GROUPBOX;
                              SIZE 61.5, 4 ;
                              OBJECT bmpOkvir ;
                              COLOR GRA_CLR_RED

//--- F1 keyboard
 @ x1,y1 ;
   DCPUSHBUTTONXP CAPTION "GROUP1;F1" ;
   PARENT bmpOkvir SIZE du,bb ACCELKEY xbeK_F1 ;
   ACTION {|a,b,o| ;
           selectcolorbutton(o,GetList), SetAppFocus(oEnd)} ;
   CURSOR CUR SELECTENABLE SELECTCOLOR co1,co5 SELECTED ; // INIT SELECTED
   OUTLINE COLOR co1,co2 CLICKCOLOR co3,co4 FONT fo1 OBJECT o1

//--- F2 keyboard
 @ x1,y1+15 ;
   DCPUSHBUTTONXP CAPTION "GROUP2;F2" ;
   PARENT bmpOkvir SIZE du,bb ACCELKEY xbeK_F2 ;
   ACTION {|a,b,o| ;
           selectcolorbutton(o,GetList), SetAppFocus(oEnd)} ;
   CURSOR CUR SELECTENABLE SELECTCOLOR co1,co5 ;
   OUTLINE COLOR co1,co2 CLICKCOLOR co3,co4 FONT fo1 OBJECT o2

//--- F3 keyboard
 @ x1,y1+15+15 ;
   DCPUSHBUTTONXP CAPTION "GROUP3;F3" ;
   PARENT bmpOkvir SIZE du,bb ACCELKEY xbeK_F3 ;
   ACTION {|a,b,o| ;
           selectcolorbutton(o,GetList), SetAppFocus(oEnd)} ;
   CURSOR CUR SELECTENABLE SELECTCOLOR co1,co5 ;
   OUTLINE COLOR co1,co2 CLICKCOLOR co3,co4 FONT fo1 OBJECT o3

//--- F4 keyboard
 @ x1,y1+15+15+15 ;
   DCPUSHBUTTONXP CAPTION "GROUP4;F4" ;
   PARENT bmpOkvir SIZE du,bb ACCELKEY xbeK_F4 ;
   ACTION {|a,b,o| ;
           selectcolorbutton(o,GetList), SetAppFocus(oEnd)} ;
   CURSOR CUR SELECTENABLE SELECTCOLOR co1,co5 ;
   OUTLINE COLOR co1,co2 CLICKCOLOR co3,co4 FONT fo1 OBJECT o4

//--- End
 @ 4,0 ;
   DCPUSHBUTTON CAPTION "The;End" ;
   SIZE du/2,bb ALIGNCAPTION BS_MULTILINE;
   ACTION {|a,b,o| DC_ReadGuiEvent(DCGUI_EXIT_OK,GetList) } CURSOR CUR OBJECT oEnd

  @ 4.2,9 DCSAY "The group is activated with mouse LbClick on the green commandbutton (Ok)"      SAYSIZE 0
  @ 5.0,9 DCSAY "The group is activated by clicking on a keyboard button F1,  F2,  F3,  F4 (??)" SAYSIZE 0
  @ 5.8,9 DCSAY "Note: Activated group must be red and the other groups are green"               SAYSIZE 0
  @ 6.6,9 DCSAY "         It must be with the keyboard F1, F2, F3, F4 get RadioButtons effect"   SAYSIZE 0

 DCGETOPTIONS AUTORESIZE // WINDOWWIDTH 500 WINDOWHEIGHT 300

 DCREAD GUI TITLE "TEST :: DCPUSHBUTTONXP Tips-And-Tricks Roger Donnay" OPTIONS GetOptions FIT ;
 SETFOCUS @oEnd PARENT @oDlg MODAL EVAL {|o| SetAppWindow(o) }

RETURN NIL


*************************************************************************
STATIC FUNCTION selectcolorbutton(o,getlist)
*************************************************************************
o1:SELECTED := .F. ; setappfocus(o1) ; dc_getrefresh(o1)
o2:SELECTED := .F. ; setappfocus(o2) ; dc_getrefresh(o2)
o3:SELECTED := .F. ; setappfocus(o3) ; dc_getrefresh(o3)
o4:SELECTED := .F. ; setappfocus(o4) ; dc_getrefresh(o4)

setappfocus(o)
o:SELECTED := .T.
dc_getrefresh(o)
setappfocus(o)

RETURN NIL


User avatar
rdonnay
Site Admin
Posts: 4775
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: cobasystems DCPUSHBUTTONXP tips-and-tricks

#2 Post by rdonnay »

Your solution is very nice.
I like using DCPUSHBUTTONXP buttons to emulate a radio group.

You mentioned the word "elegant" and so I think we should see if we can make the code a bit more elegant while still giving the exact same look and functionality.

Below is an update to your code.

1. I removed your PUBLIC variables. They are not necessary and should not be used if you intend to make this into a recursive and/or thread-safe function. Should only use LOCAL variables.

2. I used an array to hold the buttons objects instead of a set of variables.

3. I created all the buttons in a FOR..NEXT loop to reduce code and give the ability to create anywhere from 2 buttons to 12 buttons just by calling the program with the number of buttons required. This reduces the number of lines of code, eliminates redundancy and ambiguity, and makes the code more maintainable. If you decide you want to change the look of all the buttons, that can be done now by changing only one line of code.

4. I removed many of the #include statements because they were not needed. Only appvent.ch and dcdialog.ch were required.

Your posting is valuable to all eXpress++ users. I like your willingness to experiment and to discover the capabilities of eXpress++.
buttons.jpg
buttons.jpg (47.85 KiB) Viewed 9194 times

Code: Select all

#include "Appevent.ch"
#INCLUDE "DCDIALOG.CH"

#PRAGMA Library( "DCLIPX.LIB" )

PROCEDURE APPSYS()
RETURN

PROCEDURE MAIN( cButtons )
DEFAULT cButtons := '4'
TEST( Val(cButtons) )
RETURN

*************************************************************************
FUNCTION TEST( nButtons )
*************************************************************************
LOCAL GetList := {}, GetOptions,  oDlg

 LOCAL ;
 x1 := 0.6       ,;
 y1 := 0.6       ,;
 du := 15-0.2    ,;
 bb := 3-0.1     ,;
 bmpOkvir := nil ,;
 CUR := {"user32.dll",114}

 LOCAL ;
 co1 := GRA_CLR_WHITE,   co2 := GRA_CLR_DARKGREEN, ;
 co3 := GRA_CLR_BLACK,   co4 := GRA_CLR_YELLOW,    ;
 co5 := GRA_CLR_DARKRED, fo1 := "12.Arial Bold"

 LOCAL bAction, i, aButtons[nButtons], oEnd // dcpushbutton objects

 SET CHARSET TO ANSI

 bAction := {|a,b,o|AEval(aButtons,{|o|o:selected := .f.}), ;
                    o:selected := .t., ;
                    bmpOkvir:invalidateRect(), ;
                    SetAppFocus(oEnd)}

 @ 0,0.5 ;
 DCSTATIC TYPE XBPSTATIC_TYPE_GROUPBOX;
                              SIZE nButtons*15 + 1.5, 4 ;
                              OBJECT bmpOkvir ;
                              COLOR GRA_CLR_RED

FOR i := 1 TO Len(aButtons)

   @ x1,y1 ;
     DCPUSHBUTTONXP CAPTION "GROUP" + Alltrim(Str(i)) + ";F" + Alltrim(Str(i)) ;
     PARENT bmpOkvir SIZE du,bb ACCELKEY xbeK_F1 + (i-1) ;
     ACTION bAction ;
     CURSOR CUR SELECTENABLE SELECTCOLOR co1,co5 SELECTED ; // INIT SELECTED
     OUTLINE COLOR co1,co2 CLICKCOLOR co3,co4 FONT fo1 OBJECT aButtons[i]

   y1 += 15

NEXT

//--- End
 @ 4,0 ;
   DCPUSHBUTTON CAPTION "The;End" ;
   SIZE du/2,bb ALIGNCAPTION BS_MULTILINE;
   ACTION {|a,b,o| DC_ReadGuiEvent(DCGUI_EXIT_OK,GetList) } CURSOR CUR OBJECT oEnd

  @ 4.2,9 DCSAY "The group is activated with mouse LbClick on the green commandbutton (Ok)"      SAYSIZE 0
  @ 5.0,9 DCSAY "The group is activated by clicking on a keyboard button F1 - Fn (??)" SAYSIZE 0
  @ 5.8,9 DCSAY "Note: Activated group must be red and the other groups are green"               SAYSIZE 0
  @ 6.6,9 DCSAY "         It must be with the keyboard F1 - Fn get RadioButtons effect"   SAYSIZE 0

 DCGETOPTIONS AUTORESIZE // WINDOWWIDTH 500 WINDOWHEIGHT 300

 DCREAD GUI TITLE "TEST :: DCPUSHBUTTONXP Tips-And-Tricks Roger Donnay" OPTIONS GetOptions FIT ;
 SETFOCUS @oEnd PARENT @oDlg MODAL ;
 EVAL {|o| Eval(bAction,nil,nil,aButtons[1]), SetAppWindow(o) }

RETURN NIL
The eXpress train is coming - and it has more cars.

User avatar
cobasystems
Posts: 15
Joined: Wed Nov 12, 2014 4:44 pm

Re: cobasystems DCPUSHBUTTONXP tips-and-tricks

#3 Post by cobasystems »

A respected O 'Sensei Roger
Your solution is extraordinary.
For such a solution you have to be a top master Software arts eXpress ++
I'm just your disciple and follower, and from time to time I need help.
Thank masters!

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: cobasystems DCPUSHBUTTONXP tips-and-tricks

#4 Post by Eugene Lutsenko »

Yes, thank you, Roger, for the highest professionalism and generosity. Let's use it!
Just a thought about that something like that is necessary for the drop-down menu

Post Reply