PtMenu positioning

Hi,

I’m trying to position a menu beneath of a menu button. It works when the button is a child of PtMenu widget, but if the button is placed on a PtMenuBar the menu is always appears at the top of the screen. No matter whether I set Pt_MENU_RIGHT, Pt_MENU_UP or Pt_MENU_DOWN. Am I doing something wrong or Pt_ARG_BUTTON_TYPE works only for PtMenu children?

Thanks,

Serge

/*

  • cc -g -w6 -l ph -o PtMenu PtMenu.c
    */

#include <Pt.h>

int menu_post( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo )
{
PtRealizeWidget( (PtWidget_t *) data );
return( Pt_CONTINUE );
}


int main( int argc, char *argv[] )
{
PtArg_t arg[ 3 ];
PhArea_t area = {{ 0, 0 }, { 300, 100 }};
PtWidget_t *window, *mbar, *button, *menu;
int n;

if( -1 == PtInit( NULL )) {
perror( “PtInit()” );
PtExit( EXIT_FAILURE );
}

n = 0;
PtSetArg( &arg[ n++ ], Pt_ARG_WINDOW_TITLE, “PtMenu Test”, 0 );
PtSetArg( &arg[ n++ ], Pt_ARG_DIM, &area.size, 0 );

if( NULL == ( window = PtCreateWidget( PtWindow, Pt_NO_PARENT, n, arg ))) {
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

area.size.h = 25;

n = 0;
PtSetArg( &arg[ n++ ], Pt_ARG_AREA, &area, 0 );
PtSetArg( &arg[ n++ ], Pt_ARG_ANCHOR_FLAGS, Pt_LEFT_ANCHORED_LEFT |
Pt_RIGHT_ANCHORED_RIGHT |
Pt_TOP_ANCHORED_TOP |
Pt_BOTTOM_ANCHORED_TOP,
Pt_LEFT_ANCHORED_LEFT |
Pt_RIGHT_ANCHORED_RIGHT |
Pt_TOP_ANCHORED_TOP |
Pt_BOTTOM_ANCHORED_TOP );

if( NULL == ( mbar = PtCreateWidget( PtMenuBar, window, n, arg ))) {
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

n = 0;
PtSetArg( &arg[ n++ ], Pt_ARG_TEXT_STRING, “Menu”, 0 );
PtSetArg( &arg[ n++ ], Pt_ARG_BUTTON_TYPE, Pt_MENU_DOWN, Pt_MENU_DOWN );

if( NULL == ( button = PtCreateWidget( PtMenuButton, mbar, n, arg ))) {
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

PtRealizeWidget( window );

if( NULL == ( menu = PtCreateWidget( PtMenu, button, 0, NULL ))) {
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

PtAddCallback( button, Pt_CB_ACTIVATE, menu_post, (void *) menu );

n = 0;
PtSetArg( &arg[ n++ ], Pt_ARG_TEXT_STRING, “Item 1”, 0 );

if( NULL == PtCreateWidget( PtMenuButton, menu, n, arg )) {
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

n = 0;
PtSetArg( &arg[ n++ ], Pt_ARG_TEXT_STRING, “Item 2”, 0 );

if( NULL == PtCreateWidget( PtMenuButton, menu, n, arg )) {
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

PtMainLoop();

return( EXIT_SUCCESS );
}

Add the following line into the menu_post() before the PtRealizeWidget():
PtPositionMenu( (PtWidget_t*)data, NULL );
-Misha.
“Serge Yuschenko” <nospam@forums.openqnx.com> wrote in message
news:25380515.1042224988725.JavaMail.fliu@tiger…

Hi,

I’m trying to position a menu beneath of a menu button. It works when the
button is a child of PtMenu widget, but if the button is placed on a

PtMenuBar the menu is always appears at the top of the screen. No matter
whether I set Pt_MENU_RIGHT, Pt_MENU_UP or Pt_MENU_DOWN. Am I doing
something wrong or Pt_ARG_BUTTON_TYPE works only for PtMenu children?

Thanks,

Serge

/*

  • cc -g -w6 -l ph -o PtMenu PtMenu.c
    */

#include <Pt.h

int menu_post( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo )
{
PtRealizeWidget( (PtWidget_t *) data );
return( Pt_CONTINUE );
}


int main( int argc, char *argv[] )
{
PtArg_t arg[ 3 ];
PhArea_t area = {{ 0, 0 }, { 300, 100 }};
PtWidget_t *window, *mbar, *button, *menu;
int n;

if( -1 == PtInit( NULL )) {
perror( “PtInit()” );
PtExit( EXIT_FAILURE );
}

n = 0;
PtSetArg( &arg[ n++ ], Pt_ARG_WINDOW_TITLE, “PtMenu Test”, 0 );
PtSetArg( &arg[ n++ ], Pt_ARG_DIM, &area.size, 0 );

if( NULL == ( window = PtCreateWidget( PtWindow, Pt_NO_PARENT, n, arg )))
{
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

area.size.h = 25;

n = 0;
PtSetArg( &arg[ n++ ], Pt_ARG_AREA, &area, 0 );
PtSetArg( &arg[ n++ ], Pt_ARG_ANCHOR_FLAGS, Pt_LEFT_ANCHORED_LEFT |
Pt_RIGHT_ANCHORED_RIGHT |
Pt_TOP_ANCHORED_TOP |
Pt_BOTTOM_ANCHORED_TOP,
Pt_LEFT_ANCHORED_LEFT |
Pt_RIGHT_ANCHORED_RIGHT |
Pt_TOP_ANCHORED_TOP |
Pt_BOTTOM_ANCHORED_TOP );

if( NULL == ( mbar = PtCreateWidget( PtMenuBar, window, n, arg ))) {
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

n = 0;
PtSetArg( &arg[ n++ ], Pt_ARG_TEXT_STRING, “Menu”, 0 );
PtSetArg( &arg[ n++ ], Pt_ARG_BUTTON_TYPE, Pt_MENU_DOWN, Pt_MENU_DOWN );

if( NULL == ( button = PtCreateWidget( PtMenuButton, mbar, n, arg ))) {
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

PtRealizeWidget( window );

if( NULL == ( menu = PtCreateWidget( PtMenu, button, 0, NULL ))) {
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

PtAddCallback( button, Pt_CB_ACTIVATE, menu_post, (void *) menu );

n = 0;
PtSetArg( &arg[ n++ ], Pt_ARG_TEXT_STRING, “Item 1”, 0 );

if( NULL == PtCreateWidget( PtMenuButton, menu, n, arg )) {
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

n = 0;
PtSetArg( &arg[ n++ ], Pt_ARG_TEXT_STRING, “Item 2”, 0 );

if( NULL == PtCreateWidget( PtMenuButton, menu, n, arg )) {
perror( “PtCreateWidget()” );
PtExit( EXIT_FAILURE );
}

PtMainLoop();

return( EXIT_SUCCESS );
}

Add the following line into the menu_post() before
the PtRealizeWidget():
PtPositionMenu( (PtWidget_t*)data, NULL );
-Misha.

Thank you Misha. Just did. What misled me at first is the proper positioning of submenus.

Serge