In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Show PopMenu on SplitButton:onClick()

Xailer professional forum in English
Responder
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Show PopMenu on SplitButton:onClick()

Mensaje por emeasoft »

Hello Xailers,
I would like to know how to show the popupmenu on the onclick event from the SplitButton.
For example, when I create an onclick event on a splitbutton that has a popmenu, it automatically create a separator on the button, what I need to do is to show the popmenu when I click on the TSplitButton:onClick(), because there I will add a condition.
Thanks,
Juliano

Attached files TPopUpMenu Example.zip (5.1 KB)Â
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Show PopMenu on SplitButton:onClick()

Mensaje por jlalin »

Juliano,
> I would like to know how to show the popupmenu on the
> onclick event from the SplitButton.
METHOD SB1Click( oSender ) CLASS TForm1
LOCAL aPos := ClientToScreen( ::Handle, oSender:nLeft + oSender:nWidth,
oSender:nTop )
LOCAL nOption
nOption := TrackPopupMenu( ::oPM1:Handle, TPM_RETURNCMD, aPos[1],
aPos[2], ::Handle )
IF nOption > 0
::oPM1:DoAction( nOption )
ENDIF
RETURN Nil
Saludos,
José Lalí­n
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Show PopMenu on SplitButton:onClick()

Mensaje por emeasoft »

Thanks José, it worked as we wanted.
Now we need to know a way to open the popupmenu and set the focus on the option with the lchecked:=.T., that would be the default option.
E.g.: when the popupmenu opens with a click or enter, it shows one of the 3 option checked as lchecked:=.T.(the default), but the user could choose another option if he wants. But if he wants to use the default, he needs to use the arrows keys to set the focus and then press enter again to execute the action.
If we could put the focus automatically on the default item, the users will only need to press enter to execute the default action.
If you need an example, just let me know.
Thanks again,
Juliano
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Show PopMenu on SplitButton:onClick()

Mensaje por jlalin »

Juliano,
> If you need an example, just let me know.
Yes, please.
Regards,
José Lalí­n
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Show PopMenu on SplitButton:onClick()

Mensaje por emeasoft »

Hello José,
Here goes the example.
Thanks,
Juliano

Attached files TPopUpMenu.zip (5 KB)Â
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Show PopMenu on SplitButton:onClick()

Mensaje por jlalin »

Juliano,
I'm affraid you can't do it that way. Anyhow I changed the example to
another approach just in case it helps you.
Regards,
José Lalí­n
--

Attached files TPopUpMenu-1-0-0-0.zip (2.3 KB)Â
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Show PopMenu on SplitButton:onClick()

Mensaje por emeasoft »

Thanks José,
I can do the way you showed when only one option is enabled, but when I have more options enabled, the user should be able to choose other than the default, if he wants.
One good example of what I want is to open the notepad and press Alt + F (TopMenu File) or ALT + A (Menu arquivo), you will see that the focus will be set on the first item of the popup menu.
Thanks,
Juliano
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Show PopMenu on SplitButton:onClick()

Mensaje por jlalin »

Juliano,
> I can do the way you showed when only one option is enabled,
> but when I have more options enabled, the user should be
> able to choose other than the default, if he wants.
I don't understand what are you trying to do... With my changes, when the
users clicks or presses Space/Enter the button executes the default menu
action but if the user needs another option he can show the menu and select
whatever action he wants.
Regards,
José Lalí­n
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Show PopMenu on SplitButton:onClick()

Mensaje por emeasoft »

Hello José,
My fault I didn't have mentioned that we are trying to use the mouse the minimum as possible, because the users are used to the keyboard.
Thats why we are trying to use the [enter] click to open the popupmenu and set the focus on the first item, not needing to use the arrows to navigate to the default item and click [enter] again to execute the action.
So what we need is that the user click [enter] on the button, then the popup menu opens with the focus on the predefined default item, and if he wishes, he could press another [enter] to execute the action or use the arrow keys to navigate and choose other option.
All this using only the keyboard.
Thanks again,
Juliano
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Show PopMenu on SplitButton:onClick()

Mensaje por jlalin »

Juliano,
now I understood what you need.
This works with both TButton and TSplitButton, just put it in the button's
OnClick event:
METHOD Button1Click( oSender ) CLASS TForm1
LOCAL aPos := ClientToScreen( ::Handle, oSender:nLeft + oSender:nWidth,
oSender:nTop )
LOCAL nOption
// Zero based. 0 -> First option, 1 -> Second option, etc.
HiliteMenuItem( ::Handle, ::oPM1:Handle, 0, nOr( MF_BYPOSITION,
MF_HILITE ) )
nOption := TrackPopupMenu( ::oPM1:Handle, TPM_RETURNCMD, aPos[1],
aPos[2], ::Handle )
IF nOption > 0
::oPM1:DoAction( nOption )
ENDIF
RETURN Nil
Regards,
José Lalí­n
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Show PopMenu on SplitButton:onClick()

Mensaje por emeasoft »

José Lalin,
We thank a lot for your attention.
It is almost right!
First we want to note that:
nOption := TrackPopupMenu( ::oPM1:Handle, TPM_RETURNCMD, aPos[1], aPos[2], ::Handle )
This way it deforms the tPopupMenu, but when we invert the ::Handle, it got corrected:
nOption := TrackPopupMenu( ::Handle, TPM_RETURNCMD, aPos[1], aPos[2], ::oPM1:Handle )
The hiliteMenuItem works perfectly, it puts the focus on the default option, clicking on the option works too.


But if we type [Enter], it does not execute the action. We still need to use the arrows or the mouse to execute the action.
As we develop with the option to the user use the [Enter] instead the mouse. So thats the only thing that it is still needed to be perfect, in other words, the TSplitButton receives the focus, type [Enter], opens the TPopupMenu with the option already checked(by the HiliteMenuItem) and type another [Enter] to execute the checked action, without using the mouse.
If possible, many thanks for your attention!

Attached files
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Show PopMenu on SplitButton:onClick()

Mensaje por jlalin »

Juliano,
> First we want to note that:
>
> nOption := TrackPopupMenu( ::oPM1:Handle, TPM_RETURNCMD,
> aPos[1], aPos[2], ::Handle )
> This way it deforms the tPopupMenu, but when we invert the
> ::Handle, it got corrected:
>
> nOption := TrackPopupMenu( ::Handle, TPM_RETURNCMD, aPos[1],
> aPos[2], ::oPM1:Handle )
Thats is false. TrackPopupMenu first param must be the popup handle and the
last is the parent's handle.
> As we develop with the option to the user use the [Enter]
> instead the mouse. So thats the only thing that it is still
> needed to be perfect, in other words, the TSplitButton
> receives the focus, type [Enter], opens the TPopupMenu with
> the option already checked(by the HiliteMenuItem) and type
> another [Enter] to execute the checked action, without using
> the mouse.
I have been reading the MSDN and I don't find any docs related with this so
I guess it is not.
BTW, you can avoid the menu and show a panel with as many flat TBtnBmp
buttons you need to reach the same effect. This way you can make it work as
you want.
Regards,
José Lalí­n
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Show PopMenu on SplitButton:onClick()

Mensaje por jlalin »

Juliano,
> Thanks for all the help José.
You are welcome!
BTW, did you solved the problem?
> We owe you a beer sometime. :d
;-)
Regards,
José Lalí­n
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Show PopMenu on SplitButton:onClick()

Mensaje por emeasoft »

So, we did not solved the problem, but we are going to let it the way it is now.
In the future, we may search and use alternatives just like the one you suggested.
Regards,
Juliano
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Show PopMenu on SplitButton:onClick()

Mensaje por jlalin »

Juliano,
> In the future, we may search and use alternatives just like
> the one you suggested.
It is very easy to implement. Just follow this steps:
* Drop a TButton in a form
* Drop a TPanel in the form and set lVisible to .F.
* Move the panel to the right of the button
* Add as many buttons to the panel as options you need
* Select the main TButton (the one that is outside the panel)
* In the button's OnClick event:
::oPanel1:Show()
* And finally add this code:
CLASS TPanel FROM XPanel
PUBLIC:
METHOD WMKeyDown( nKey, nFlags )
ENDCLASS
METHOD WMKeyDown( nKey, nFlags ) CLASS TPanel
IF nKey == 27 // VK_ESCAPE
::Hide()
RETURN 0
ENDIF
RETURN Super:WMKeyDown( nKey, nFlags )
NOTE: remember to hide the panel when the users presses one button on the
panel and you are done.
I haven't tested the code but it should be very near to work as you need
with little adjustments. If you need further help just let me know.
Regards,
José Lalí­n
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Show PopMenu on SplitButton:onClick()

Mensaje por emeasoft »

Hello José,
Sorry for the late answer, I've tested and it works well, the only thing is the style of the popupmenu, that I could not do the same on the flat buttons(the highlight, the checked), is there any way to do that? When I mouse over and when I navigate throught it using the arrows?

Thanks,
Juliano

Attached files
jlalin
Mensajes: 926
Registrado: Sab Dic 25, 2010 11:10 pm

Show PopMenu on SplitButton:onClick()

Mensaje por jlalin »

Juliano,
> Sorry for the late answer, I've tested and it works well,
> the only thing is the style of the popupmenu, that I could
> not do the same on the flat buttons(the highlight, the
> checked), is there any way to do that? When I mouse over and
> when I navigate throught it using the arrows?
For the default style you can set TButton:oFont:lBold to .T. or use the
lDefault property to draw the border.
To paint the checked style you can add a TLabel before the buttons with
cText := "A" and oFont := Marlet to draw the check mark.
As for the highlight you would need a custom draw button.
Saludos,
José Lalí­n
Avatar de Usuario
emeasoft
Mensajes: 1094
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

Show PopMenu on SplitButton:onClick()

Mensaje por emeasoft »

Hello José,
Thanks for the tips, it helped us solving our problems.
Regards,
Juliano
Responder