/* $XConsortium: SimpleMenu.c,v 1.44 94/04/17 20:12:45 kaleb Exp $ */
/*
Copyright (c) 1989, 1994 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
*/
/*
* SimpleMenu.c - Source code file for SimpleMenu widget.
*
* Date: April 3, 1989
*
* By: Chris D. Peterson
* MIT X Consortium
* kit@expo.lcs.mit.edu
*/
#include <stdio.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
/*
* Label Resources.
*/
/*
* Layout Resources.
*/
/*
* Misc. Resources
*/
};
static char defaultTranslations[] =
"<EnterWindow>: highlight() \n\
<LeaveWindow>: unhighlight() \n\
<BtnMotion>: highlight() \n\
<BtnUp>: MenuPopdown() notify() unhighlight()";
/*
* Semi Public function definitions.
*/
static XtGeometryResult GeometryManager();
/*
* Action Routine Definitions
*/
/*
* Private Function Definitions.
*/
static SmeObject GetEventEntry();
static void MoveMenu();
{
{"notify", Notify},
{"highlight", Highlight},
{"unhighlight", Unhighlight},
};
/* next_extension */ NULL,
/* record_type */ NULLQUARK,
/* version */ XtCompositeExtensionVersion,
/* record_size */ sizeof(CompositeClassExtensionRec),
/* accepts_objects */ TRUE,
};
{
/* class_name */ "SimpleMenu",
/* size */ sizeof(SimpleMenuRec),
/* class_initialize */ ClassInitialize,
/* class_part_initialize*/ ClassPartInitialize,
/* Class init'ed */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ Realize,
/* actions */ actionsList,
/* resources */ resources,
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterleave*/ TRUE,
/* visible_interest */ FALSE,
/* destroy */ NULL,
/* resize */ Resize,
/* expose */ Redisplay,
/* set_values */ SetValues,
/* set_values_hook */ SetValuesHook,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* intrinsics version */ XtVersion,
/* callback offsets */ NULL,
/* tm_table */ defaultTranslations,
/* query_geometry */ NULL,
/* display_accelerator*/ NULL,
/* extension */ NULL
},{
/* geometry_manager */ GeometryManager,
/* change_managed */ ChangeManaged,
/* insert_child */ XtInheritInsertChild,
/* delete_child */ XtInheritDeleteChild,
/* extension */ NULL
},{
/* Shell extension */ NULL
},{
/* Override extension */ NULL
},{
/* Simple Menu extension*/ NULL
}
};
(childP)++ )
/************************************************************
*
* Semi-Public Functions.
*
************************************************************/
/* Function Name: ClassInitialize
* Description: Class Initialize routine, called only once.
* Arguments: none.
* Returns: none.
*/
static void
{
}
/* Function Name: ClassInitialize
* Description: Class Part Initialize routine, called for every
* subclass. Makes sure that the subclasses pick up
* the extension record.
* Arguments: wc - the widget class of the subclass.
* Returns: none.
*/
static void
{
/*
* Make sure that our subclass gets the extension rec too.
*/
}
/* Function Name: Initialize
* Description: Initializes the simple menu widget
* Arguments: request - the widget requested by the argument list.
* new - the new widget with both resource and non
* resource values.
* Returns: none.
*/
/* ARGSUSED */
static void
{
}
}
/*
* Add a popup_callback routine for changing the cursor.
*/
}
/* Function Name: Redisplay
* Description: Redisplays the contents of the widget.
* Arguments: w - the simple menu widget.
* event - the X event that caused this redisplay.
* region - the region the needs to be repainted.
* Returns: none.
*/
/* ARGSUSED */
static void
Widget w;
{
/*
* Check and Paint each of the entries - including the label.
*/
case RectangleIn:
case RectanglePart:
break;
default:
continue;
}
}
}
/* Function Name: Realize
* Description: Realizes the widget.
* Arguments: w - the simple menu widget.
* mask - value mask for the window to create.
* attrs - attributes for the window to create.
* Returns: none
*/
static void
Widget w;
XtValueMask * mask;
{
*mask |= CWBackingStore;
}
else
*mask &= ~CWBackingStore;
}
/* Function Name: Resize
* Description: Handle the menu being resized bigger.
* Arguments: w - the simple menu widget.
* Returns: none.
*/
static void
Resize(w)
Widget w;
{
if ( !XtIsRealized(w) ) return;
}
/* Function Name: SetValues
* Description: Relayout the menu when one of the resources is changed.
* Arguments: current - current state of the widget.
* request - what was requested.
* new - what the widget will become.
* Returns: none
*/
/* ARGSUSED */
static Boolean
{
}
}
}
else { /* Change. */
}
"No Dynamic class change of the SimpleMenu Label.");
}
if (layout)
return(ret_val);
}
/* Function Name: SetValuesHook
* Description: To handle a special case, this is passed the
* actual arguments.
* Arguments: w - the menu widget.
* arglist - the argument list passed to XtSetValues.
* num_args - the number of args.
* Returns: none
*/
/*
* If the user actually passed a width and height to the widget
* then this MUST be used, rather than our newly calculated width and
* height.
*/
static Boolean
Widget w;
{
Cardinal i;
for ( i = 0 ; i < *num_args ; i++) {
}
return(FALSE);
}
/************************************************************
*
* Geometry Management routines.
*
************************************************************/
/* Function Name: GeometryManager
* Description: This is the SimpleMenu Widget's Geometry Manager.
* Arguments: w - the Menu Entry making the request.
* request - requested new geometry.
* reply - the allowed geometry.
* Returns: XtGeometry{Yes, No, Almost}.
*/
static XtGeometryResult
Widget w;
{
return(XtGeometryNo);
/*
* Since we are an override shell and have no parent there is no one to
* ask to see if this geom change is okay, so I am just going to assume
* we can do whatever we want. If you subclass be very careful with this
* assumption, it could bite you.
*
* Chris D. Peterson - Sept. 1989.
*/
}
else {
}
}
else {
else {
reply->request_mode = 0;
}
}
return(answer);
}
/* Function Name: ChangeManaged
* Description: called whenever a new child is managed.
* Arguments: w - the simple menu widget.
* Returns: none.
*/
static void
Widget w;
{
}
/************************************************************
*
* Global Action Routines.
*
* These actions routines will be added to the application's
* global action list.
*
************************************************************/
/* Function Name: PositionMenuAction
* Description: Positions the simple menu widget.
* Arguments: w - a widget (no the simple menu widget.)
* event - the event that caused this action.
* params, num_params - parameters passed to the routine.
* we expect the name of the menu here.
* Returns: none
*/
/* ARGSUSED */
static void
Widget w;
{
char* ebp;
int len;
if (*num_params != 1) {
"Xaw - SimpleMenuWidget: position menu action expects only one",
"parameter which is the name of the menu.");
"Xaw - SimpleMenuWidget: position menu action expects only one parameter which is the name of the menu.");
return;
}
else
} else
return;
}
case ButtonPress:
case ButtonRelease:
break;
case EnterNotify:
case LeaveNotify:
break;
case MotionNotify:
break;
default:
break;
}
}
/************************************************************
*
* Widget Action Routines.
*
************************************************************/
/* Function Name: Unhighlight
* Description: Unhighlights current entry.
* Arguments: w - the simple menu widget.
* event - the event that caused this action.
* params, num_params - ** NOT USED **
* Returns: none
*/
/* ARGSUSED */
static void
Widget w;
{
}
/* Function Name: Highlight
* Description: Highlights current entry.
* Arguments: w - the simple menu widget.
* event - the event that caused this action.
* params, num_params - ** NOT USED **
* Returns: none
*/
/* ARGSUSED */
static void
Widget w;
{
if ( !XtIsSensitive(w) ) return;
return;
}
}
/* Function Name: Notify
* Description: Notify user of current entry.
* Arguments: w - the simple menu widget.
* event - the event that caused this action.
* params, num_params - ** NOT USED **
* Returns: none
*/
/* ARGSUSED */
static void
Widget w;
{
}
/************************************************************
*
* Public Functions.
*
************************************************************/
/* Function Name: XawSimpleMenuAddGlobalActions
* Description: adds the global actions to the simple menu widget.
* Arguments: app_con - the appcontext.
* Returns: none.
*/
void
#else
#endif
{
}
/* Function Name: XawSimpleMenuGetActiveEntry
* Description: Gets the currently active (set) entry.
* Arguments: w - the smw widget.
* Returns: the currently set entry or NULL if none is set.
*/
#else
Widget w;
#endif
{
}
/* Function Name: XawSimpleMenuClearActiveEntry
* Description: Unsets the currently active (set) entry.
* Arguments: w - the smw widget.
* Returns: none.
*/
void
#else
Widget w;
#endif
{
}
/************************************************************
*
* Private Functions.
*
************************************************************/
/* Function Name: CreateLabel
* Description: Creates a the menu label.
* Arguments: w - the smw widget.
* Returns: none.
*
* Creates the label object and makes sure it is the first child in
* in the list.
*/
static void
CreateLabel(w)
Widget w;
{
int i;
"label string is NULL", "label already exists",
"no label is being created.");
return;
}
XtCreateManagedWidget("menuLabel",
next_child = NULL;
if (next_child != NULL)
*next_child = *child;
next_child = child;
}
}
/* Function Name: Layout
* Description: lays the menu entries out all nice and neat.
* Arguments: w - See below (+++)
* width_ret, height_ret - The returned width and
* height values.
* Returns: none.
*
* if width == NULL || height == NULL then it assumes the you do not care
* about the return values, and just want a relayout.
*
* if this is not the case then it will set width_ret and height_ret
* to be width and height that the child would get if it were layed out
* at this time.
*
* +++ "w" can be the simple menu widget or any of its object children.
*/
static void
Widget w;
{
height = 0;
if ( XtIsSubclass(w, simpleMenuWidgetClass) ) {
smw = (SimpleMenuWidget) w;
}
else {
current_entry = (SmeObject) w;
}
else
if (do_layout) {
}
}
else {
}
else if ( allow_change_size )
else
if (do_layout) {
if (allow_change_size)
}
else {
if (height != 0)
*height_ret = height;
}
}
/* Function Name: AddPositionAction
* Description: Adds the XawPositionSimpleMenu action to the global
* action list for this appcon.
* Arguments: app_con - the application context for this app.
* data - NOT USED.
* Returns: none.
*/
/* ARGSUSED */
static void
{
{ "XawPositionSimpleMenu", PositionMenuAction },
};
}
/* Function Name: FindMenu
* Description: Find the menu give a name and reference widget.
* Arguments: widget - reference widget.
* name - the menu widget's name.
* Returns: the menu widget or NULL.
*/
static Widget
{
return(menu);
return(NULL);
}
/* Function Name: PositionMenu
* Description: Places the menu
* Arguments: w - the simple menu widget.
* location - a pointer the the position or NULL.
* Returns: none.
*/
static void
Widget w;
{
unsigned int junkM;
"Could not find location of mouse pointer");
return;
}
}
/*
* The width will not be correct unless it is realized.
*/
XtRealizeWidget(w);
else
}
/* Function Name: MoveMenu
* Description: Actually moves the menu, may force it to
* to be fully visable if menu_on_screen is TRUE.
* Arguments: w - the simple menu widget.
* x, y - the current location of the widget.
* Returns: none
*/
static void
MoveMenu(w, x, y)
Widget w;
Position x, y;
{
if (x >= 0) {
}
if (x < 0)
x = 0;
if (y >= 0) {
if (y + height > scr_height)
y = scr_height - height;
}
if (y < 0)
y = 0;
}
}
/* Function Name: ChangeCursorOnGrab
* Description: Changes the cursor on the active grab to the one
* specified in out resource list.
* Arguments: w - the widget.
* junk, garbage - ** NOT USED **.
* Returns: None.
*/
/* ARGSUSED */
static void
Widget w;
{
/*
* The event mask here is what is currently in the MIT implementation.
* There really needs to be a way to get the value of the mask out
* of the toolkit (CDP 5/26/89).
*/
}
/* Function Name: MakeSetValuesRequest
* Description: Makes a (possibly recursive) call to SetValues,
* I take great pains to not go into an infinite loop.
* Arguments: w - the simple menu widget.
* width, height - the size of the ask for.
* Returns: none
*/
static void
Widget w;
{
}
}
}
/* Function Name: GetMenuWidth
* Description: Sets the length of the widest entry in pixels.
* Arguments: w - the simple menu widget.
* Returns: width of menu.
*/
static Dimension
{
else
}
else
}
return(widest);
}
/* Function Name: GetMenuHeight
* Description: Sets the length of the widest entry in pixels.
* Arguments: w - the simple menu widget.
* Returns: width of menu.
*/
static Dimension
Widget w;
{
} else
return(height);
}
/* Function Name: GetEventEntry
* Description: Gets an entry given an event that has X and Y coords.
* Arguments: w - the simple menu widget.
* event - the event.
* Returns: the entry that this point is in.
*/
static SmeObject
Widget w;
{
case MotionNotify:
break;
case EnterNotify:
case LeaveNotify:
break;
case ButtonPress:
case ButtonRelease:
break;
default:
"Unknown event type in GetEventEntry().");
break;
}
return(NULL);
return(NULL); /* cannot select the label. */
else
return(*entry);
}
return(NULL);
}