Main Menu ToolBar

This forum is for eXpress++ general support.
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4775
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Main Menu ToolBar

#11 Post by rdonnay »

Then I suggest that you use a Get-Set function instead of a STATIC.

Code: Select all

#INCLUDE "dcdialog.CH"
#INCLUDE "appevent.CH"

#DEFINE EVENT_DATABASE_TOP        xbeP_User + 1
#DEFINE EVENT_DATABASE_PREVIOUS   xbeP_User + 2
#DEFINE EVENT_DATABASE_NEXT       xbeP_User + 3
#DEFINE EVENT_DATABASE_BOTTOM     xbeP_User + 4

#DEFINE NAVIGATE_TOP     1
#DEFINE NAVIGATE_BOTTOM  2

#define COLOR_YELLOW     GraMakeRGBColor( { 255, 255,   0 } )
#define COLOR_BROWN      GraMakeRGBColor( { 127, 127,   0 } )
#define COLOR_WHITE      GraMakeRGBColor( { 255, 255, 255 } )
#define COLOR_BLACK      GraMakeRGBColor( {   0,   0,   0 } )
#define COLOR_ORANGE     GraMakeRGBColor( { 253, 120,  41 } )

FUNCTION Main()

LOCAL GetList[0], oMenuBar, oSubMenu, oDlg, oStatTop, GetOptions, oToolbar, oConfig

DC_LoadRdds()

DC_PushButtonStyle(1)

oConfig := DC_XbpPushButtonXPConfig():new()
oConfig:bitmapOffset := 5
oConfig:fgColorMouse := COLOR_BLACK
oConfig:bgColorMouse := COLOR_ORANGE
oConfig:fgColor := COLOR_BLACK
oConfig:bgColor := COLOR_BROWN
oConfig:gradientStep := 10
oConfig:gradientReverse := .t.
oConfig:radius := 5
oConfig:bgColorClick := COLOR_YELLOW

DCSTATUSBAR oStatTop ALIGN DCGUI_ALIGN_TOP HEIGHT 24

@ 0,0 DCTOOLBAR oToolBar PARENT oStatTop SIZE 400,24 PIXEL BUTTONSIZE 80,24 TYPE XBPSTATIC_TYPE_TEXT SPACE 5

DCADDBUTTONXP CAPTION '~Top' PARENT oToolBar ACTION {||PostAppEvent(EVENT_DATABASE_TOP,,,SetDisplayFocus())} ;
   WHEN {||!Navigate() $ {NAVIGATE_TOP,0}} CONFIG oConfig

DCADDBUTTONXP CAPTION '~Previous' PARENT oToolBar ACTION {||PostAppEvent(EVENT_DATABASE_PREVIOUS,,,SetDisplayFocus())} ;
   WHEN {||!Navigate() $ {NAVIGATE_TOP,0}} CONFIG oConfig

DCADDBUTTONXP CAPTION '~Next' PARENT oToolBar ACTION {||PostAppEvent(EVENT_DATABASE_NEXT,,,SetDisplayFocus())} ;
   WHEN {||!Navigate() $ {NAVIGATE_BOTTOM,0}} CONFIG oConfig

DCADDBUTTONXP CAPTION '~Bottom' PARENT oToolBar ACTION {||PostAppEvent(EVENT_DATABASE_BOTTOM,,,SetDisplayFocus())} ;
   WHEN {||!Navigate() $ {NAVIGATE_BOTTOM,0}} CONFIG oConfig

DCMENUBAR oMenuBar

DCSUBMENU oSubMenu PROMPT 'File' PARENT oMenuBar

DCMENUITEM 'Browse Xtest' PARENT oSubMenu ;
   ACTION {|o|o := Thread():new(), Sleep(5), o:start({||BrowseXtest(oDlg,GetList)})}

DCGETOPTIONS WINDOWWIDTH 800 WINDOWHEIGHT 600

DCREAD GUI TITLE 'Test Program' OPTIONS GetOptions PARENT @oDlg

RETURN nil

* -----------

PROC Appsys ; RETURN

* -----------

FUNCTION SetDisplayFocus( oDlg )

STATIC soDlg

IF Valtype(oDlg) == 'O'
  soDlg := oDlg
ENDIF

RETURN soDlg

* -----------

FUNCTION BrowseXTest( oMainDlg, aMainGetList )

LOCAL GetList[0], oBrowse, oDlg

USE XTest INDEX XTest VIA 'DBFCDX'

DCUSEREVENT EVENT_DATABASE_TOP ACTION {||Xtest->(dbGoTop()),oBrowse:refreshAll()}
DCUSEREVENT EVENT_DATABASE_PREVIOUS ACTION {||Xtest->(dbSkip(-1)),oBrowse:refreshAll()}
DCUSEREVENT EVENT_DATABASE_NEXT ACTION {||Xtest->(dbSkip()),oBrowse:refreshAll()}
DCUSEREVENT EVENT_DATABASE_BOTTOM ACTION {||Xtest->(dbGoBottom()),oBrowse:refreshAll()}

@ 0,0 DCBROWSE oBrowse ALIAS 'Xtest' SIZE 80,20 ;
      ITEMMARKED {||TestNavigate(Alias(),aMainGetList)}

DCBROWSECOL FIELD Xtest->areacode HEADER 'Area' WIDTH 4 PARENT oBrowse
DCBROWSECOL FIELD Xtest->exchange HEADER 'Exchange' WIDTH 4 PARENT oBrowse
DCBROWSECOL FIELD Xtest->number HEADER 'Number' WIDTH 4 PARENT oBrowse

DCREAD GUI FIT TITLE 'Browsing XTest' APPWINDOW oMainDlg:drawingArea ;
   EVAL {|o|oDlg := o, o:setDisplayFocus := {||SetDisplayFocus(oDlg),TestNavigate(Alias(),aMainGetList)}, SetDisplayFocus(oDlg)}

Navigate(0)

RETURN nil

* ------------

FUNCTION TestNavigate( cAlias, aMainGetList )

IF (cAlias)->(DC_TestBof())
  Navigate(NAVIGATE_TOP)
ELSEIF (cAlias)->(DC_TestEof())
  Navigate(NAVIGATE_BOTTOM)
ELSE
  Navigate(-1)
ENDIF

DC_GetWhen(aMainGetList)

RETURN nil

* -----------

GETSETFUNCTION Navigate DEFAULT 0
The eXpress train is coming - and it has more cars.

User avatar
unixkd
Posts: 575
Joined: Thu Feb 11, 2010 1:39 pm

Re: Main Menu ToolBar

#12 Post by unixkd »

Hi Roger

Your solution worked well. Accept my candid appreciation !!!

One more thing. One of the buttons of my ToolBar is 'Close'. When clicked, I want the topmost active dialog be closed.
I tried using PostAppEvent(xbeP_Close,,,Set_MainWindow():drawingArea:childList()[1]) but it closed the first opened window which is not what I want.
I want to close the currently active window.

Thanks

Joseph

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

Re: Main Menu ToolBar

#13 Post by rdonnay »

This will do it.

Code: Select all

DCADDBUTTONXP CAPTION '~Close' PARENT oToolBar ACTION {||PostAppEvent(xbeP_Close,,,SetDisplayFocus())} ;
   WHEN {||!Empty(oDlg:drawingArea:childList())} CONFIG oConfig
The eXpress train is coming - and it has more cars.

User avatar
unixkd
Posts: 575
Joined: Thu Feb 11, 2010 1:39 pm

Re: Main Menu ToolBar

#14 Post by unixkd »

Hi Roger

I have two issues to resolve:

1. I could ge the Accelerated key of the DCADDBUTTON to work e.g ACCELKEY xbeK_CTRL_S to activate save routine

2. I also have OBJECT oNext for the Next button and would like to access it in the various MDI dialogs. Should it be declared PUBLIC ?

Thanks.

Joseph

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

Re: Main Menu ToolBar

#15 Post by rdonnay »

The ACCELKEY clause of DC* commands are thread-safe, so they don't interfere with dialogs in other threads.

I tried to use the SetAppEvent() function of Xbase++ to do what you want but it didn't work.
This can be done with a custom global handler. See the below code.

You can declare oNext as public, or you can create an array of pushbutton objects (as in the below code) and declare the array as public. You could also use a public Get-Set function to point to the array if you don't like public vars.

Code: Select all

#INCLUDE "dcdialog.CH"
#INCLUDE "appevent.CH"

#DEFINE EVENT_DATABASE_TOP        xbeP_User + 1
#DEFINE EVENT_DATABASE_PREVIOUS   xbeP_User + 2
#DEFINE EVENT_DATABASE_NEXT       xbeP_User + 3
#DEFINE EVENT_DATABASE_BOTTOM     xbeP_User + 4

#DEFINE NAVIGATE_TOP     1
#DEFINE NAVIGATE_BOTTOM  2

#define COLOR_YELLOW     GraMakeRGBColor( { 255, 255,   0 } )
#define COLOR_BROWN      GraMakeRGBColor( { 127, 127,   0 } )
#define COLOR_WHITE      GraMakeRGBColor( { 255, 255, 255 } )
#define COLOR_BLACK      GraMakeRGBColor( {   0,   0,   0 } )
#define COLOR_ORANGE     GraMakeRGBColor( { 253, 120,  41 } )

FUNCTION Main()

LOCAL GetList[0], oMenuBar, oSubMenu, oDlg, oStatTop, GetOptions, oToolbar, oConfig, ;
      aButtons[5]

DC_LoadRdds()

DC_PushButtonStyle(1)

oConfig := DC_XbpPushButtonXPConfig():new()
oConfig:bitmapOffset := 5
oConfig:fgColorMouse := COLOR_BLACK
oConfig:bgColorMouse := COLOR_ORANGE
oConfig:fgColor := COLOR_BLACK
oConfig:bgColor := COLOR_BROWN
oConfig:gradientStep := 10
oConfig:gradientReverse := .t.
oConfig:radius := 5
oConfig:bgColorClick := COLOR_YELLOW

// Install global handler.
DC_ReadGuiHandler({|a,b,c,d,e|MyCustomHandler(a,b,c,d,oDlg,GetList,aButtons)})

DCSTATUSBAR oStatTop ALIGN DCGUI_ALIGN_TOP HEIGHT 24

@ 0,0 DCTOOLBAR oToolBar PARENT oStatTop SIZE 400,24 PIXEL BUTTONSIZE 80,24 TYPE XBPSTATIC_TYPE_TEXT SPACE 5

DCADDBUTTONXP CAPTION '~Top' PARENT oToolBar ACTION {||PostAppEvent(EVENT_DATABASE_TOP,,,SetDisplayFocus())} ;
   WHEN {||!Navigate() $ {NAVIGATE_TOP,0}} CONFIG oConfig OBJECT aButtons[1]

DCADDBUTTONXP CAPTION '~Previous' PARENT oToolBar ACTION {||PostAppEvent(EVENT_DATABASE_PREVIOUS,,,SetDisplayFocus())} ;
   WHEN {||!Navigate() $ {NAVIGATE_TOP,0}} CONFIG oConfig OBJECT aButtons[2]

DCADDBUTTONXP CAPTION '~Next' PARENT oToolBar ACTION {||PostAppEvent(EVENT_DATABASE_NEXT,,,SetDisplayFocus())} ;
   WHEN {||!Navigate() $ {NAVIGATE_BOTTOM,0}} CONFIG oConfig OBJECT aButtons[3]

DCADDBUTTONXP CAPTION '~Bottom' PARENT oToolBar ACTION {||PostAppEvent(EVENT_DATABASE_BOTTOM,,,SetDisplayFocus())} ;
   WHEN {||!Navigate() $ {NAVIGATE_BOTTOM,0}} CONFIG oConfig OBJECT aButtons[4]

DCADDBUTTONXP CAPTION '~Close' PARENT oToolBar ACTION {||PostAppEvent(xbeP_Close,,,SetDisplayFocus())} ;
   WHEN {||!Empty(oDlg:drawingArea:childList())} CONFIG oConfig OBJECT aButtons[5]

DCMENUBAR oMenuBar

DCSUBMENU oSubMenu PROMPT 'File' PARENT oMenuBar

DCMENUITEM 'Browse Xtest' PARENT oSubMenu ;
   ACTION {|o|o := Thread():new(), Sleep(5), o:start({||BrowseXtest(oDlg,GetList)})}

DCGETOPTIONS WINDOWWIDTH 800 WINDOWHEIGHT 600

DCREAD GUI TITLE 'Test Program' OPTIONS GetOptions PARENT @oDlg

RETURN nil

* -----------

STATIC FUNCTION MyCustomHandler( nEvent, mp1, mp2, oXbp, oDlg, GetList, aButtons )

IF nEvent == xbeP_Keyboard
  IF mp1 == xbeK_ALT_T
    PostAppEvent(xbeP_Activate,,,aButtons[1])
  ELSEIF mp1 == xbeK_ALT_P
    PostAppEvent(xbeP_Activate,,,aButtons[2])
  ELSEIF mp1 == xbeK_ALT_N
    PostAppEvent(xbeP_Activate,,,aButtons[3])
  ELSEIF mp1 == xbeK_ALT_B
    PostAppEvent(xbeP_Activate,,,aButtons[4])
  ENDIF
ENDIF

RETURN nil

* -----------

PROC Appsys ; RETURN

* -----------

FUNCTION SetDisplayFocus( oDlg )

STATIC soDlg

IF Valtype(oDlg) == 'O'
  soDlg := oDlg
ENDIF

RETURN soDlg

* -----------

FUNCTION BrowseXTest( oMainDlg, aMainGetList )

LOCAL GetList[0], oBrowse, oDlg

USE XTest INDEX XTest VIA 'DBFCDX'

DCUSEREVENT EVENT_DATABASE_TOP ACTION {||Xtest->(dbGoTop()),oBrowse:refreshAll()}
DCUSEREVENT EVENT_DATABASE_PREVIOUS ACTION {||Xtest->(dbSkip(-1)),oBrowse:refreshAll()}
DCUSEREVENT EVENT_DATABASE_NEXT ACTION {||Xtest->(dbSkip()),oBrowse:refreshAll()}
DCUSEREVENT EVENT_DATABASE_BOTTOM ACTION {||Xtest->(dbGoBottom()),oBrowse:refreshAll()}

@ 0,0 DCBROWSE oBrowse ALIAS 'Xtest' SIZE 80,20 ;
      ITEMMARKED {||TestNavigate(Alias(),aMainGetList)}

DCBROWSECOL FIELD Xtest->areacode HEADER 'Area' WIDTH 4 PARENT oBrowse
DCBROWSECOL FIELD Xtest->exchange HEADER 'Exchange' WIDTH 4 PARENT oBrowse
DCBROWSECOL FIELD Xtest->number HEADER 'Number' WIDTH 4 PARENT oBrowse

DCREAD GUI FIT TITLE 'Browsing XTest' APPWINDOW oMainDlg:drawingArea ;
   EVAL {|o|oDlg := o, o:setDisplayFocus := {||SetDisplayFocus(oDlg),TestNavigate(Alias(),aMainGetList)}, SetDisplayFocus(oDlg)}

Navigate(0)

RETURN nil

* ------------

FUNCTION TestNavigate( cAlias, aMainGetList )

IF (cAlias)->(DC_TestBof())
  Navigate(NAVIGATE_TOP)
ELSEIF (cAlias)->(DC_TestEof())
  Navigate(NAVIGATE_BOTTOM)
ELSE
  Navigate(-1)
ENDIF

DC_GetWhen(aMainGetList)

RETURN nil

* -----------

GETSETFUNCTION Navigate DEFAULT 0
The eXpress train is coming - and it has more cars.

John Hohensee
Posts: 26
Joined: Fri Mar 04, 2011 7:35 am
Location: San Bernardino, CA USA
Contact:

Re: Main Menu ToolBar

#16 Post by John Hohensee »

If this is in the same program. The answer is simple.
at the beginning of the program, right below all of the #define statements do the following.

static snNavigate

Wala you snNavigate is visible through out this program.

If this is in more then one program it needs to be in the .CH file the same way.

Post Reply