[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

1423.0. "How to build accelerators ???" by BALZAC::CHALUMEAU () Tue Sep 12 1989 10:26

Hi,

I have written the following program to test accelerators.

I did it on a VMS 5.2 system and I don't understand why 
accelerators don't run.

Thank's in advance for your help
Fran�ois

------------------------------------------------------------

	C Program

------------------------------------------------------------
#include <stdio.h>
#include <decw$include:DwtAppl.h>    

#define k_boite		0
#define k_b1		1
#define k_b2		2
#define k_texte		3

static DRMHierarchy	s_DRMHierarchy;		
static char		*vec[]={"accel_2.uid"};
static DRMCode		class ;

static void button_activate();
static void create_proc();

static DRMCount		regnum = 2 ;
static DRMRegisterArg	regvec[] = {
	{"button_activate",(caddr_t)button_activate},
        {"create_proc",(caddr_t)create_proc}
	};
        
static Widget toplevel, main_wd, tab[4];

/*
 *  Main program
 */
int main(argc, argv)
    unsigned int argc;
    char **argv;
{
    DwtInitializeDRM ();
    toplevel = XtInitialize("TITRE","class", NULL, 0,&argc, argv);
    DwtOpenHierarchy (1,vec,NULL,&s_DRMHierarchy);
    DwtRegisterDRMNames (regvec, regnum) ;
    DwtFetchWidget (s_DRMHierarchy,"main_wd",toplevel,&main_wd,&class);
    XtManageChild(main_wd);
    XtRealizeWidget(toplevel);

    XtInstallAllAccelerators (main_wd, main_wd);

    XtMainLoop();
}


static void create_proc(widget, tag, list)
	Widget	widget;
	int     *tag;
        DwtAnyCallbackStruct *list;
{
        tab[*tag] = widget;
}


static void button_activate( widget, tag, callback_data )
	Widget	widget;
	int     *tag;
	DwtAnyCallbackStruct *callback_data;
{
    switch ( *tag )
        {
        case k_b1:
	    printf ("s�lection : %s\n",DwtSTextGetString (tab[k_texte]));
            break ;
        case k_b2:
            exit(1);
            break ;
        }
}

------------------------------------------------------------

	UIL program

------------------------------------------------------------
module exo
    version = 'v1.0'
    names = case_sensitive

include file 'decw$include:DwtAppl.uil';

procedure
    button_activate(integer);
    create_proc(integer);

value
    accel_1     : compound_string ("^a");
    cle_1       : "Ctrl<KeyPress>a:";
    accel_2     : compound_string ("^s");
    cle_2       : "Ctrl<KeyPress>s:";


    k_boite 	: 0;
    k_b1	: 1;
    k_b2	: 2;
    k_texte	: 3;

object
    main_wd  : main_window {
	arguments {
	    accept_focus = true;
	    width = 200;
	    height = 110;
	};
	controls {
            menu_bar menu;
            dialog_box boite;
	};
    };

object
    boite : dialog_box {
	arguments { 
	   	width = 100;
		height = 100;
	};
	controls { 
	  	simple_text texte;
	};
	callbacks {
		create = procedure create_proc(k_boite);
        };
    };

object
    texte : simple_text {
	arguments { 
		x = 20;
		y = 10;
		width = 100;
		max_length = 20;
	};
	callbacks {
		create = procedure create_proc(k_texte);
        };
    };

object
    menu : menu_bar {
	arguments { 
           	orientation = DwtOrientationHorizontal;
	   	width = 100;
	};
	controls { 
	  	pulldown_entry fichier;
	};
    };

object
    fichier : pulldown_entry {
	arguments {
		label_label = "FILE";
	};
	controls {
		pulldown_menu fichier_menu;
	};
    };

object
    fichier_menu : pulldown_menu {
	controls {
	    push_button	button_1;
	    push_button	button_2;
	};
    };


object
    button_1 : push_button {
	arguments { 
	    label_label = 'Afficher';
 	    accelerator_text = accel_1;
	    button_accelerator = cle_1;
	};
	callbacks { 
	    activate = procedure button_activate(k_b1);
	};
    };

object
    button_2 : push_button {
	arguments {
	    label_label = 'Sortie ';
 	    accelerator_text = accel_2;
	    button_accelerator = cle_2;
	};
	callbacks { 
	    activate = procedure button_activate(k_b2);
	};
    };

end module;


T.RTitleUserPersonal
Name
DateLines
1423.1Where to install acceleratorsLEOVAX::TREGGIARITue Sep 12 1989 12:4711
Accelerators need to be installed on all of the widgets which may take the
input focus.  In your test application it is the text widget, not the main
window widget, which takes the input focus.  If you change your call to
XtInstallAllAccelerators to:

    XtInstallAllAccelerators (tab[k_texte], main_wd);

it will work.

Leo

1423.2Thank'sBALZAC::CHALUMEAUTue Sep 12 1989 13:295
    Thank you VERY much
    
    Fran�ois
    

1423.3But without simple_text ?BALZAC::CHALUMEAUWed Sep 13 1989 08:3927
    Hi,
    
    In my application, I have no simple_text managed in the main window.
    
    The hierarchy is 
    			------------------
    			I   main_window  I    -> accept_focus = true
    			------------------
    				
    	---------------                     ----------------
    	I dialog_box  I			    I    menu_bar  I
    	---------------			    ----------------
                                
	will be a GKS window		    ----------------
    					    I pulldown_menuI
    					    ----------------
    
       					    ----------------
    					    I push_buttons I
    					    ----------------
    					    with accelerators
           
    
    How can I do to take input_focus to the main_window ?
    
    Fran�ois

1423.4LEOVAX::TREGGIARIWed Sep 13 1989 09:0419
    In that hierarchy, the main window will get input focus, so you should
    install the accelerators on the main window.  This assumes that the
    GKS window DOESN'T take input focus (I don't know if it will...).
    
    You also need to do something with the Dialog box.  The server
    delivers keyboard events to the focus window BUT to one of its
    descendents, IF the pointer is in the descendent AND the descendent
    has requested keyboard events.  By default, the dialog box does
    request keyboard events for handling of the TAB and RETURN keys.  
    So, you need to either:
    
      o  Install the accelerators on the dialog box as well
    
      o  Keep the dialog box from requesting keyboard events.
         This can be done, but means changing the dialog box's
         translation table.  I'd recommend the first alternative.

    Leo

1423.5main window doesn't take input focusBALZAC::CHALUMEAUWed Sep 13 1989 11:027
    I have installed accelerators (by Xtinstallallaccelerators routine)
    in the dialog box, but main window doesn't take input_focus.
    	How can I realease the second way ? or did I forget something
    in the first ?
    
    Fran�ois

1423.6Did you click on the title bar?LEOVAX::TREGGIARIWed Sep 13 1989 13:026
The main window window should take focus when you click on the title
bar.  That's the only way to get it to take focus without some additional
work on the applications part.

Leo

1423.7Yes ...BALZAC::CHALUMEAUWed Sep 13 1989 13:27254
	Yes I did ...

	This my example without simple_text 
	(I replaced the GKS window by an Xlib window)

----------------------------------------------------------------

	C program

----------------------------------------------------------------
#include <stdio.h>
#include <decw$include:DwtAppl.h>    

#define k_boite		0
#define k_b1		1
#define k_b2		2
#define k_b3		3

static DRMHierarchy	s_DRMHierarchy;		
static char		*vec[]={"draw.uid"};
static DRMCode		class ;

static void button_activate();
static void create_proc();
static XtEventHandler button_down();

static DRMCount		regnum = 2 ;
static DRMRegisterArg	regvec[] = {
	{"button_activate",(caddr_t)button_activate},
        {"create_proc",(caddr_t)create_proc}
	};
        
static Widget toplevel, main_wd, tab[4];
static Display *dis;
static Window win;
static GC gc;
static int x1,x2,y1,y2,count;

/*
 *  Main program
 */
int main(argc, argv)
    unsigned int argc;
    char **argv;
{
    Arg arglist [2];

    DwtInitializeDRM ();
    toplevel = XtInitialize("DRAW","class", NULL, 0,&argc, argv);
    DwtOpenHierarchy (1,vec,NULL,&s_DRMHierarchy);
    DwtRegisterDRMNames (regvec, regnum) ;
    DwtFetchWidget (s_DRMHierarchy,"main_wd",toplevel,&main_wd,&class);

    XtSetArg (arglist[0], DwtNacceptFocus, TRUE);
    XtSetValues (main_wd, arglist, 1);
    XtManageChild(main_wd);

    XtSetArg (arglist[0], DwtNx, 100);
    XtSetArg (arglist[1], DwtNy, 400);
    XtSetValues (toplevel, arglist, 2);
    XtRealizeWidget(toplevel);

>>>>>>>>>>>>
>>>>    XtInstallAllAccelerators (main_wd, main_wd);
>>>>    XtInstallAllAccelerators (tab[k_boite], main_wd);
>>>>>>>>>>>>

    dis = XtDisplay (tab[k_boite]);
    win = XtWindow (tab[k_boite]);
    gc = DefaultGC (dis,DefaultScreen(dis));
    count=0;

    XtAddEventHandler (tab[k_boite], ButtonPressMask, 0, button_down, 0);

    XtMainLoop();
}


static void create_proc(widget, tag, list)
	Widget	widget;
	int     *tag;
        DwtAnyCallbackStruct *list;
{
        tab[*tag] = widget;
}

static void button_activate( widget, tag, callback_data )
	Widget	widget;
	int     *tag;
	DwtAnyCallbackStruct *callback_data;
{
    switch ( *tag )
        {
        case k_b1:
	    count=0;
            break ;
        case k_b2:
	    XClearWindow (dis,win);
	    count=0;
            break ;
        case k_b3:
            exit(1);
            break ;
        }
}

static XtEventHandler button_down( widget, data, event )
	Widget	widget;
	int     data;
	XEvent  *event;
{
	count += 1;
	if (event->xbutton.button == Button1 ) {
	if ( count == 1) {
			x2 = event->xbutton.x;
			y2 = event->xbutton.y;
			}
	if ( count > 1) {
			x1 = x2;
			y1 = y2;
			x2 = event->xbutton.x;
			y2 = event->xbutton.y;
			XDrawLine(dis,win,gc,x1,y1,x2,y2);
			}
        }
}

-------------------------------------------------------------------------

	UIL  program

-------------------------------------------------------------------------
module exo
    version = 'v1.0'
    names = case_sensitive

include file 'decw$include:DwtAppl.uil';

procedure
    button_activate(integer);
    create_proc(integer);

value
    accel_1     : compound_string ("^l");
    cle_1       : "Ctrl<KeyPress>l:";
    accel_2     : compound_string ("^c");
    cle_2       : "Ctrl<KeyPress>c:";
    accel_3     : compound_string ("^q");
    cle_3       : "Ctrl<KeyPress>q:";


    k_boite 	: 0;
    k_b1	: 1;
    k_b2	: 2;
    k_b3	: 3;

object
    main_wd  : main_window {
	arguments {
	    accept_focus = true;
	    width = 300;
	    height = 200;
	};
	controls {
            menu_bar menu;
            dialog_box boite;
	};
    };

object
    boite : dialog_box {
	arguments { 
	   	width = 200;
		height = 200;
	};
	callbacks {
		create = procedure create_proc(k_boite);
        };
    };

object
    menu : menu_bar {
	arguments { 
           	orientation = DwtOrientationHorizontal;
	   	width = 100;
	};
	controls { 
	  	pulldown_entry fichier;
	};
    };

object
    fichier : pulldown_entry {
	arguments {
		label_label = "FILE";
	};
	controls {
		pulldown_menu fichier_menu;
	};
    };

object
    fichier_menu : pulldown_menu {
	controls {
	    push_button	button_1;
	    push_button	button_2;
	    push_button	button_3;
	};
    };


object
    button_1 : push_button {
	arguments { 
	    label_label = 'Lines...';
 	    accelerator_text = accel_1;
	    button_accelerator = cle_1;
	};
	callbacks { 
	    activate = procedure button_activate(k_b1);
	    create = procedure create_proc(k_b1);
	};
    };

object
    button_2 : push_button {
	arguments {
	    label_label = 'Clear';
 	    accelerator_text = accel_2;
	    button_accelerator = cle_2;
	};
	callbacks { 
	    activate = procedure button_activate(k_b2);
            create = procedure create_proc(k_b2);
	};
    };

object
    button_3 : push_button {
	arguments {
	    label_label = 'Quit';
 	    accelerator_text = accel_3;
	    button_accelerator = cle_3;
	};
	callbacks { 
	    activate = procedure button_activate(k_b3);
            create = procedure create_proc(k_b3);
	};
    };

end module;
 


1423.8It works for me...LEOVAX::TREGGIARIWed Sep 13 1989 15:016
I'm running DECwindows V2 IFT2 (including the DECwindows Window Manager).
But, even if you are running V1, I don't know of anything that got fixed
in this functionality.  

Leo

1423.9what GKS doesPOBOX::CHALTASCome with me to the Cash BarWed Sep 13 1989 17:549
    If that GKS window is really a window (e.g. you create a WindowWidget,
    and pass its window to GKS, worksation type 212) then it won't take
    input focus.  If, on the other hand, it's a GKS Widget (workstation
    type 213 -- you create a Dialog Box and pass its widget ID to GKS) it
    *will* take focus whenever a GKS string device is active, and whenever
    GKS choice devices 2 or 3 are active.
    
    		George 

1423.10It is OKBALZAC::CHALUMEAUFri Sep 15 1989 11:584
    Thank you very much for your help
    Fran�ois
    

1423.11MOre accelerator woesRABBET::FARRELLMoney, there is no substitute!Wed Jan 31 1990 15:0825
I have a main window.  It has two children, a pop-up dialog box, and a menu
bar.

This dialog box, has another dialog box and and graphic window as children.

I am trying to install accelerators on the pushbuttons of the pulldown menus
of the menu bar.

This works when I XtInstallAllAccelerators on the toplevel widget, but only 
when the pointer is over the title bar, or the menu bar of the window.  
The largest part of the window, is the graphic window, which doesn't appear 
to have the accelerators installed.

If I try to also install the accelerators on the graphics window widget, I
get an access violation and the program dumps.

What do I have to do to get the graphic window to have these accelerators
active?

thanks,


	$$$$ ted $$$$

1423.12one way...MINNIE::DOUGjust sing it like you feel itThu Feb 01 1990 08:218
    this has been in here before.  what you have to do is install all
    accelerators on all the widgets which might have input focus (in your
    app. : main window and dialogue boxes, as i recall).  
    
    the way i do this is have the dialog box create proc put a work
    procedure in the queue.  the work proc then does the
    XtInstallAllAccelerators. (pass the dialog box's widget id as the work
    procedure's parameter). 
1423.13not only, but alsoMINNIE::DOUGjust sing it like you feel itThu Feb 01 1990 08:246
    oh, and when you say your main window has a popup dialog box as
    child:  do you mean statically, or do you really "popup" the popup.
    if the popup dialog box is just sitting there inside the main window,
    why not use a dialog box instead?
    
    		just an extra thought -- dd
1423.14I know I have to install them, but how?RABBET::FARRELLMoney, there is no substitute!Thu Feb 01 1990 13:5610
RE: .-1 - The dialog box is just a dialog box, not a popup.

RE: .-2 - I tried to install the accelerators on the window, but I received
	  and access violation.  This is what is screwing me up.

The only other valid point I can think of is that I have an EventHandler
installed on this window.  Could this be messing me up?

	$$$$ ted $$$$
1423.15MINNIE::DOUGjust sing it like you feel itThu Feb 01 1990 14:553
    did you do the install in the widget creation routine?  if so, it's
    too early.  must do it later, which is why i suggested a work
    procedure.	--dd
1423.16A guessLEOVAX::TREGGIARITue Feb 06 1990 07:118
    Does your graphic window ever take input focus?  If it doesn't you
    don't need to install the accelerators on it.  If it does, then
    here is a wild guess; put at least one translation on the window
    widget before installing the accelerators.  There have been some
    bugs in the Intrinsics when doing things like this to a widget
    with a NULL translation table.
    
    Leo