Size of MENUITEM

Size of MENUITEM

Postby byte-one » Fri Oct 18, 2013 9:58 am

If the text from a menuitem has changed to a longer text, the width from the menu should also be widther! (vis versa on a shorter text!)
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Size of MENUITEM

Postby Antonio Linares » Fri Oct 18, 2013 12:59 pm

Günther,

Unfortunately it is not that simple with the Windows API...

When a MENU is going to be created Windows send us a WM_MEASUREITEM so we report the desired width of the menu:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775925(v=vs.85).aspx

Later on, when we change the text of a menuitem we use the Windows API function ModifyMenu():
http://msdn.microsoft.com/en-us/library/windows/desktop/ms647993(v=vs.85).aspx
in fact Microsoft suggests to use SetMenuItemInfo() as "The ModifyMenu function has been superseded by the SetMenuItemInfo function" but reviewing the params used by SetMenuItemInfo() I don't see any param related to the width of the new text.

And when the menuitem text is changed then Windows sends us a WM_DRAWITEM message:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775923(v=vs.85).aspx
in FiveWin we route that message to METHOD DrawItem( nIdCtl, pItemStruct ) CLASS TWindow.

continues...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Size of MENUITEM

Postby Antonio Linares » Fri Oct 18, 2013 1:08 pm

From METHOD DrawItem( nIdCtl, pItemStruct ) CLASS TWindow we call MenuDrawItem() and we supply the pItemStruct that we receive from Windows.

In such structure there is a value for the right coordinate of the menuitem:
lpdis->rcItem.right

so there we could try to modify it and see if it expands the whole menu size, in example:
lpdis->rcItem.right + 200;
in fact this should be calculated regarding the length of the new text and also the used font.

Will the whole menu repaint just because we modify the size of an item ? I have never tested it.

continues...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Size of MENUITEM

Postby Antonio Linares » Fri Oct 18, 2013 1:11 pm

Günther,

And what it should had been my first answer to you:

How are you changing the text of the menuitem ? Could you provide a small example ? thanks :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Size of MENUITEM

Postby byte-one » Fri Oct 18, 2013 3:24 pm

Antonio, thanks for your explanation! I use ::SetPrompt( cPrompt ). The text is changed, but the lenght are the same as before! Should i use refresh()?
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Size of MENUITEM

Postby Antonio Linares » Fri Oct 18, 2013 3:30 pm

Günther,

Do you want that the menu width changes meanwhile the menu is shown ? Or next time is shown ?

Have you considered to provide the menu items an initial longer width so the next text will fit in ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Size of MENUITEM

Postby byte-one » Fri Oct 18, 2013 4:08 pm

Antonio,
Do you want that the menu width changes meanwhile the menu is shown ?

If i set the initial size longer, this shows ugly and also the text become shorter.
Yes on runtime without leaving the window.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Size of MENUITEM

Postby James Bott » Mon Oct 21, 2013 5:55 pm

Günther

I am thinking that changing the menu text is not a good user interface design. Users get used to menu items and changing them would be confusing--it would be to me.

I don't recall ever having seen this on an off-the-shelf program before.

Perhaps it would be better to have two menu items where one item is always disabled? Or, some similar approach rather than changing the text.

Just a thought.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Size of MENUITEM

Postby Antonio Linares » Mon Oct 21, 2013 7:16 pm

Günther,

Could you provide a small PRG example to show how you are doing it ? thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Size of MENUITEM

Postby byte-one » Wed Oct 23, 2013 10:10 am

Antonio, please try this example:

Code: Select all  Expand view

local cName := cName1 := "Test" , cName2 := "Long Long Long Long Long Long Long Long Long Test"
    MENU oMenu POPUP 2007
    MENUITEM "Wettbewerb auswählen" ;
        ACTION (cName := if(cName==cName1,cName2,cName1) , oMenu:aMenuItems[2]:setprompt(cName))
 
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Size of MENUITEM

Postby Antonio Linares » Wed Oct 23, 2013 4:21 pm

Günther,

Could you provide a complete PRG ?

Because in your code you are changing the text of a menuitem, but that menuitem is only "alive" meanwhile the popup is in use.

Are you using ACTIVATE POPUP ... SAVE ?

Where are you using such popup from ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Size of MENUITEM

Postby cnavarro » Wed Oct 23, 2013 7:24 pm

Gunther

Este ejemplo funciona correcto para mi
He entendido bien su problema?

This example works right for me
I understand your problem?

Code: Select all  Expand view

#include "Fivewin.ch"

Static cName1


FUNCTION MAIN()

    LOCAL oWnd

    cName1 := "Test"


    DEFINE WINDOW oWnd


    oWnd:bRClicked  := { |nRow, nCol, nFlags| MiMenu( oWnd, nRow, nCol ) }

    ACTIVATE WINDOW oWnd

    RETURN NIL

//----------------------------------------------------------------------------//

Function MiMenu( oWnd, nRow, nCol )
Local oMenu
Local oItem1
Local oItem2
Local oItem3
local cName := "Test"
Local cName2 := "Long Long Long Long Long Long Long Long Long Test"
   
    MENU oMenu POPUP //2007

    MENUITEM oItem1 PROMPT "Wettbewerb auswählen" ;
        ACTION ( cName1 := if( cName == cName1, cName2, cName ) ,;
                oItem2:SetPrompt( cName1 ) ) //oMenu:aMenuItems[2]:setprompt(cName)  )
    MENUITEM oItem2 PROMPT cName1
    SEPARATOR
    MENUITEM oITem3 PROMPT "Y OTRO" ACTION MsgInfo( Len( oMenu:aMenuItems ) )
    ENDMENU

    ACTIVATE POPUP oMenu WINDOW oWnd  AT 140, 10
Return oMenu

//----------------------------------------------------------------------------//

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Size of MENUITEM

Postby byte-one » Wed Oct 23, 2013 9:17 pm

Antonio,
Where are you using such popup from ?

This popup-menu i use from a button in ribbonbar! And the text from one of the items are changed in accordance of the last selection.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 46 guests