Mouse click events with XbpMenu()

This forum is for general support of Xbase++
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4728
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Mouse click events with XbpMenu()

#1 Post by rdonnay »

Xbase++ does not generate any events when the right mouse button is clicked on a menu or when the left mouse button is clicked on the menu item that points to a sub menu.

This is a real problem because I have customers who want to create desktop shortcuts from a menu by right-clicking a menu item.
I have never been able to get this to work, so my workaround has been to intercept a Shift-Left Click and use that info to create the shortcut.

Does anyone know how to get Xbase++ to generate RbClick or RbDown events on an XbpMenu() ?
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1406
Joined: Wed Feb 24, 2010 3:44 pm

Re: Mouse click events with XbpMenu()

#2 Post by Auge_Ohr »

i think it is not possible with pure Xbase++

when activate Menu WM_INITMENU Message is send.
when a DropDown or Submenu is activate WM_INITMENUPOPUP Message is send
when User use Keyboard for Menu Hotkey WM_COMMAND Message is send
when User use Keyboard but does not match Hotkey WM_MENUCHAR Message is send

when User select a Menuitem WM_MENUSELECT Message is send

when User press right Mousebutton WM_RBUTTONUP or WM_NCRBUTTONUP is send -> WM_CONTEXTMENU Message is send -> PopUp

with "pure" Xbase++ you have no Access to those Events so i guess you can`t use right Mousebutton "in" a Menu
greetings by OHR
Jimmy

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

Re: Mouse click events with XbpMenu()

#3 Post by rdonnay »

I sent an email to Alaska Software about this.
I doubt that I will get a positive answer but it's worth a try.
The eXpress train is coming - and it has more cars.

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

Re: Mouse click events with XbpMenu()

#4 Post by rdonnay »

I didn't get the response I wanted from Alaska so I wrote a menu system in eXpress++ code.
This is functionally equivalent to DCSUBMENU and DCMENUITEM but each menu item is a DCPUSHBUTTONXP.

This provides a better look and better function because now all mouse click events can be used as callbacks.

Code: Select all

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

FUNCTION Main()

LOCAL GetList[0], aMenu[0], aSubMenu[0], oConfig, aSubSubMenu[0], ;
      oButton, oDlg

oConfig := DC_XbpPushButtonXPConfig():new()

oConfig:font := '10.Arial'
oConfig:bgColor := GraMakeRGBColor( { 220,230,200 } )

AAdd( aMenu, { 'Menu Item 1', {||MsgBox('Item 1')} } )
AAdd( aMenu, { 'Menu Item 2', {||MsgBox('Item 2')} } )
AAdd( aMenu, { 'Menu Item 3', {||MsgBox('Item 3')} } )

AAdd( aSubMenu, { 'SubMenu Item 1', {||MsgBox('Sub Item 1')} } )
AAdd( aSubMenu, { 'SubMenu Item 2', {||MsgBox('Sub Item 2')} } )
AAdd( aSubMenu, { 'SubMenu Item 3', {||MsgBox('Sub Item 3')} } )
AAdd( aMenu, {'This is a Sub Menu', aSubMenu } )

AAdd( aSubSubMenu, { 'SubSubMenu Item 1', {||MsgBox('Sub Sub Item 1')} } )
AAdd( aSubSubMenu, { 'SubSubMenu Item 2', {||MsgBox('Sub Sub Item 2')} } )
AAdd( aSubSubMenu, { 'SubSubMenu Item 3', {||MsgBox('Sub Sub Item 3')} } )
AAdd( aSubMenu, {'This is a Sub Sub Menu', aSubSubMenu } )

AAdd( aMenu, { 'Menu Item 4', {||MsgBox('Item 4')} } )
AAdd( aMenu, { 'This is Menu Item 5', {||MsgBox('Item 5')} } )

@ 3,10 DCPUSHBUTTONXP CAPTION 'Menu' SIZE 12,2 CONFIG oConfig ;
       ACTION {|a,b,o|DC_SubMenu( aMenu, oConfig,,,,oDlg, oButton )} ;
       OBJECT oButton

DCREAD GUI TITLE 'Menu Test' SETAPPWINDOW PARENT @oDlg

RETURN nil

* ---------

PROC appsys ; RETURN

* ---------

FUNCTION DC_SubMenu( aMenu, oConfig, aPos, aDialog, bAction, oOwner, oButton )

LOCAL GetOptions, bEval, i, aQuery, aSize, nXSize, nYSize, cFont, ;
      aCaptionArray, nOffset, lSubMenu := .f., nTotalYSize := 0, ;
      oStatic, oAppWindow := AppDeskTop(), Getlist[0], ;
      oDlg, lSubCall, aFont, cArrowFont

IF Valtype(oButton) == 'O' .AND. Empty(aPos)
  aPos := DC_CalcAbsolutePosition({0,0},oButton)
  aPos[1]+=10
  aPos[2]-=10
ENDIF

IF Valtype(oConfig) == 'O'
  cFont := oConfig:font
ELSE
  cFont := '9.Arial'
ENDIF

DEFAULT aPos := { 200,600 }, ;
        aDialog := {}

aFont := DC_TokenArray(cFont,'.')
cArrowFont := aFont[1] + '.Webdings'

aSize := DC_GraQueryTextBox('Testing',cFont)

nYSize := aSize[2]
nXSize := 0

FOR i := 1 TO Len(aMenu)
  aSize := DC_GraQueryTextBox(' ' + aMenu[i,1] + ' ',cFont)
  nTotalYSize += aSize[2] + 2
  nXSize := Max(nXSize,aSize[1])
  IF Valtype(aMenu[i,2]) == 'A'
    lSubMenu := .t.
  ENDIF
NEXT

IF lSubMenu
  nOffset := DC_GraQueryTextBox( ' ' + Chr(52) + ' ', cArrowFont )[1]
  nXSize += nOffset
ENDIF

nYSize += 2

@ 0,0 DCSTATIC TYPE XBPSTATIC_TYPE_TEXT COLOR nil, GRA_CLR_DARKGRAY ;
   SIZE nXSize + 6, nTotalYSize + 6 OBJECT oStatic

FOR i := 1 TO Len(aMenu)

  aCaptionArray := { {' '+aMenu[i,1]+' ',,0,0,nYSize,nXSize,XBPALIGN_LEFT,cFont} }

  bEval := aMenu[i,2]
  IF Valtype(bEval) == 'B'
    @ (i-1)*nYSize+3,3 DCPUSHBUTTONXP CAPTIONARRAY aCaptionArray ;
            ACTION ActionBlock(bEval,@aDialog,@bAction) ;
            SIZE nXSize, nYSize CONFIG oConfig PARENT oStatic
  ELSE
    AAdd( aCaptionArray, { ' ' + Chr(52) + ' ',,1,0,nYSize,nXSize,XBPALIGN_RIGHT, ;
          cArrowFont} )

    @ (i-1)*nYSize+3,3 DCPUSHBUTTONXP CAPTIONARRAY aCaptionArray ;
            ACTION SubMenuActionBlock( aMenu[i,2], aDialog, oConfig, @bAction ) ;
            SIZE nXSize, nYSize CONFIG oConfig PARENT oStatic ;
            EVAL {|o|o:mouseOverFont := nil}
  ENDIF

NEXT

lSubCall := !Empty(aDialog)

IF lSubCall
  oOwner := ATail(aDialog)
ENDIF

DCGETOPTIONS PIXEL NOTITLEBAR BORDER XBPDLG_NO_BORDER FITPAD 0

DCREAD GUI FIT OPTIONS GetOptions PARENT @oDlg ;
   OWNER oOwner ;
   EVAL {|o|o:setSize({nXSize+6,nTotalYSize+6}), ;
            o:setPos({aPos[1],nYSize+aPos[2]-o:currentSize()[2]}), ;
            AAdd(aDialog,o)} ;
   HANDLER SubMenuHandler REFERENCE @aDialog  ;
   _EXIT lSubCall

IF !lSubCall
  FOR i := 1 TO Len(aDialog)
    aDialog[i]:destroy()
  NEXT
  IF Valtype(bAction) == 'B'
    Eval(bAction)
  ENDIF
ENDIF

RETURN nil

* ----------

STATIC FUNCTION ActionBlock( bEval, aDialog, bAction )

RETURN {||bAction := bEval, PostAppEvent(xbeP_Close,,,aDialog[1])}

* ----------

STATIC FUNCTION SubMenuActionBlock( aMenu, aDialog, oConfig, bAction )

RETURN {|a,b,o|CallSubMenu( aMenu, oConfig, aDialog, @bAction, o ) }

* ----------

STATIC FUNCTION CallSubMenu( aMenu, oConfig, aDialog, bAction, oButton )

LOCAL oDlg := oButton:parent:parent:parent

LOCAL aPos := { oDlg:currentPos()[1] + oButton:currentSize()[1], ;
                oDlg:currentPos()[2] + oButton:currentPos()[2] }

RETURN DC_SubMenu( aMenu, oConfig, aPos, aDialog, @bAction )

* ----------

STATIC FUNCTION SubMenuHandler( nEvent, mp1, mp2, oXbp, oDlg, GetList, aDialog )

LOCAL i

IF nEvent == xbeM_LbClick
  IF !oXbp:isDerivedFrom("DC_XbpPushButtonXP")
    DC_ClearEvents()
    PostAppEvent(xbeP_Close,,,oDlg)
  ELSE
    FOR i := Len(aDialog) TO 2 STEP -1
      IF AScan( aDialog[i]:drawingArea:childList()[1]:childList(), oXbp ) == 0
        DC_ClearEvents()
        aDialog[i]:destroy()
        aRemove(aDialog,i)
      ELSE
        EXIT
      ENDIF
    NEXT
  ENDIF
ENDIF

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

Wolfgang Ciriack
Posts: 479
Joined: Wed Jan 27, 2010 10:25 pm
Location: Berlin Germany

Re: Mouse click events with XbpMenu()

#5 Post by Wolfgang Ciriack »

Hi Roger,
did you see the postings in alaska forum for your request ?
_______________________
Best Regards
Wolfgang

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

Re: Mouse click events with XbpMenu()

#6 Post by rdonnay »

did you see the postings in alaska forum for your request ?
I didn't know there were any replies.
I set the flag to send me emails on replies and never received any.
I will go check. Thanks.
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1406
Joined: Wed Feb 24, 2010 3:44 pm

Re: Mouse click events with XbpMenu()

#7 Post by Auge_Ohr »

Wolfgang Ciriack wrote:did you see the postings in alaska forum for your request ?
did the Sample work on your PC ?

i have ask Diego about ::subscribeOSEvent( WM_MENURBUTTONUP ) ... i never got into

Code: Select all

INLINE METHOD HandleOSEvent( nMsg, nPar1, nPar2, bHandled )
***********************************************************
LOCAL oMenu, nIndex
   // never reach here ??? 
   tone(1234)
   IF nMsg == WM_MENURBUTTONUP    // .AND. ( oMenu:= ::getMenu( nPar2 ) ) # nil
greetings by OHR
Jimmy

Post Reply