/* $XConsortium: List.c,v 1.39 94/04/17 20:12:15 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.
*/
/*
* List.c - List widget
*
* This is a List widget. It allows the user to select an item in a list and
* notifies the application through a callback function.
*
* Created: 8/13/88
* By: Chris D. Peterson
* MIT X Consortium
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
/* These added so widget knows whether its height, width are user selected.
I also added the freedoms member of the list widget part. */
/*
* Default Translation table.
*/
static char defaultTranslations[] =
"<Btn1Down>: Set()\n\
<Btn1Up>: Notify()";
/****************************************************************
*
* Full class record constant
*
****************************************************************/
/* Private Data */
};
static void Initialize();
static void ChangeSize();
static void Resize();
static void Redisplay();
static void Destroy();
static XtGeometryResult PreferredGeom();
{"Notify", Notify},
{"Set", Set},
{"Unset", Unset},
};
{
/* core_class fields */
/* class_name */ "List",
/* widget_size */ sizeof(ListRec),
/* class_initialize */ XawInitializeWidgetSet,
/* class_part_initialize */ NULL,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ XtInheritRealize,
/* actions */ actions,
/* resources */ resources,
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ FALSE,
/* compress_enterleave */ TRUE,
/* visible_interest */ FALSE,
/* destroy */ Destroy,
/* resize */ Resize,
/* expose */ Redisplay,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ defaultTranslations,
/* query_geometry */ PreferredGeom,
},
/* Simple class fields initialization */
{
/* change_sensitive */ XtInheritChangeSensitive
},
/* List class fields initialization */
{
/* not used */ 0
},
};
/****************************************************************
*
* Private Procedures
*
****************************************************************/
static void GetGCs(w)
Widget w;
{
else
&values);
else
&values);
else
&values);
}
/* CalculatedValues()
*
* does routine checks/computations that must be done after data changes
* but won't hurt if accidently called
*
* These calculations were needed in SetValues. They were in ResetList.
* ResetList called ChangeSize, which made an XtGeometryRequest. You
* MAY NOT change your geometry from within a SetValues. (Xt man,
* sect. 9.7.2) So, I factored these changes out. */
static void CalculatedValues( w )
Widget w;
{
int i, len;
/* If list is NULL then the list will just be the name of the widget. */
}
/* Get number of items. */
/* Get column width. */
if ( LongestFree( lw ) ) {
else
}
}
}
/* Function Name: ResetList
* Description: Resets the new list when important things change.
* Arguments: w - the widget.
* changex, changey - allow the height or width to change?
*
* Returns: TRUE if width or height have been changed
*/
static void
Widget w;
{
CalculatedValues( w );
}
/* Function Name: ChangeSize.
* Description: Laysout the widget.
* Arguments: w - the widget to try change the size of.
* Returns: none.
*/
static void
Widget w;
{
case XtGeometryYes:
break;
case XtGeometryNo:
break;
case XtGeometryAlmost:
case XtGeometryYes:
case XtGeometryNo:
break;
case XtGeometryAlmost:
break;
default:
"List Widget: Unknown geometry return.");
break;
}
break;
default:
"List Widget: Unknown geometry return.");
break;
}
}
/* Function Name: Initialize
* Description: Function that initilizes the widget instance.
* Arguments: junk - NOT USED.
* new - the new widget.
* Returns: none
*/
/* ARGSUSED */
static void
{
/*
* Initialize all private resources.
*/
/* record for posterity if we are free */
/* Set row height. based on font or fontset */
else
} /* Initialize */
/* Function Name: CvtToItem
* Description: Converts Xcoord to item number of item containing that
* point.
* Arguments: w - the list widget.
* xloc, yloc - x location, and y location.
* Returns: the item number.
*/
static int
Widget w;
int *item;
{
/* If out of range, return minimum possible value. */
}
}
else {
/* If in right margin handle things right. */
}
}
return(ret_val);
}
/* Function Name: FindCornerItems.
* Description: Find the corners of the rectangle in item space.
* Arguments: w - the list widget.
* event - the event structure that has the rectangle it it.
* ul_ret, lr_ret - the corners ** RETURNED **.
* Returns: none.
*/
static void
Widget w;
{
}
/* Function Name: ItemInRectangle
* Description: returns TRUE if the item passed is in the given rectangle.
* Arguments: w - the list widget.
* ul, lr - corners of the rectangle in item space.
* item - item to check.
* Returns: TRUE if the item passed is in the given rectangle.
*/
static Boolean
Widget w;
{
int mod_item;
int things;
return(FALSE);
else
return(TRUE);
return(FALSE);
}
/* HighlightBackground()
*
* Paints the color of the background for the given item. It performs
* clipping to the interior of internal_width/height by hand, as its a
* simple calculation and probably much faster than using Xlib and a clip mask.
*
* x, y - ul corner of the area item occupies.
* gc - the gc to use to paint this rectangle */
static void
Widget w;
int x, y;
{
/* easy to clip the rectangle by hand and probably alot faster than Xlib */
/* Clip the rectangle width and height to the edge of the drawable area */
if ( width > frame_limited_width )
if ( height> frame_limited_height)
/* Clip the rectangle x and y to the edge of the drawable area */
}
}
}
/* ClipToShadowInteriorAndLongest()
*
* Converts the passed gc so that any drawing done with that GC will not
* write in the empty margin (specified by internal_width/height) (which also
* prevents erasing the shadow. It also clips against the value longest.
* If the user doesn't set longest, this has no effect (as longest is the
* maximum of all item lengths). If the user does specify, say, 80 pixel
* columns, though, this prevents items from overwriting other items. */
Dimension x;
{
rect.x = x;
}
/* PaintItemName()
*
* paints the name of the item in the appropriate location.
* w - the list widget.
* item - the item to draw.
*
* NOTE: no action taken on an unrealized widget. */
static void
Widget w;
int item;
{
char * str;
int x, y, str_y;
if (!XtIsRealized(w)) return; /* Just in case... */
}
else {
}
else
}
else {
if (XtIsSensitive(w))
else
}
}
else {
}
else {
if (XtIsSensitive(w))
else
}
}
/* List's overall width contains the same number of inter-column
column_space's as columns. There should thus be a half
column_width margin on each side of each column.
The row case is symmetric. */
else
}
/* Redisplay()
*
* Repaints the widget window on expose events.
* w - the list widget.
* event - the expose event for this repaint.
* junk - not used, unless three-d patch enabled. */
/* ARGSUSED */
static void
Widget w;
{
ul_item = 0;
}
else
PaintItemName(w, item);
}
/* PreferredGeom()
*
* This tells the parent what size we would like to be
* given certain constraints.
* w - the widget.
* intended - what the parent intends to do with us.
* requested - what we want to happen. */
static XtGeometryResult
Widget w;
{
if (width_req)
else
if (height_req)
else
requested->request_mode = 0;
/*
* We only care about our height and width.
*/
if ( !width_req && !height_req)
return(XtGeometryYes);
if (change)
return(XtGeometryAlmost);
return(XtGeometryYes);
}
/* Resize()
*
* resizes the widget, by changing the number of rows and columns. */
static void
Resize(w)
Widget w;
{
"List Widget: Size changed when it shouldn't have when resising.");
}
/* Layout()
*
* lays out the item in the list.
* w - the widget.
* xfree, yfree - TRUE if we are free to resize the widget in
* this direction.
* width, height- the is the current width and height that we are going
* we are going to layout the list widget to,
* depending on xfree and yfree of course.
*
* RETURNS: TRUE if width or height have been changed. */
static Boolean
Widget w;
{
/*
* If force columns is set then always use number of columns specified
* by default_cols.
*/
/* 12/3 = 4 and 10/3 = 4, but 9/3 = 3 */
if (xfree) { /* If allowed resize width. */
/* this counts the same number
of inter-column column_space 's as columns. There should thus be a
half column_space margin on each side of each column...*/
}
if (yfree) { /* If allowed resize height. */
}
return(change);
}
/*
* If both width and height are free to change the use default_cols
* to determine the number columns and set new width and height to
* just fit the window.
*/
}
/*
* If the width is fixed then use it to determine the number of columns.
* If the height is free to move (width still fixed) then resize the height
* of the widget to fit the current list exactly.
*/
else if (!xfree) {
if ( yfree ) {
}
}
/*
* The last case is xfree and !yfree we use the height to determine
* the number of rows and then set the width to just fit the resulting
* number of columns.
*/
else if (!yfree) { /* xfree must be TRUE. */
}
return(change);
}
/* Notify() - ACTION
*
* Notifies the user that a button has been pressed, and
* calls the callback; if the XtNpasteBuffer resource is true
* then the name of the item is also put in CUT_BUFFER0. */
/* ARGSUSED */
static void
Widget w;
{
/*
* Find item and if out of range then unhighlight and return.
*
* If the current item is unhighlighted then the user has aborted the
* notify, so unhighlight and return.
*/
return;
}
/*
* Call Callback function.
*/
}
/* Unset() - ACTION
*
* unhighlights the current element. */
/* ARGSUSED */
static void
Widget w;
{
}
/* Set() - ACTION
*
* Highlights the current element. */
/* ARGSUSED */
static void
Widget w;
{
int item;
== OUT_OF_RANGE)
XawListUnhighlight(w); /* Unhighlight current item. */
}
/*
* Set specified arguments into widget
*/
static Boolean
{
/* neither new nor 0, leave it as it was. Not in R5. */
/* _DONT_ check for fontset here - it's not in GC.*/
}
/* ...If the above two font(set) change checkers above both failed, check
if row_space was altered. If one of the above passed, row_height will
already have been re-calculated. */
else
}
/* Equiv. fontsets might have different values, but the same fonts, so the
next comparison is sloppy but not dangerous. */
CalculatedValues( new );
}
}
if (!XtIsRealized(current))
return(FALSE);
return(redraw);
}
static void Destroy(w)
Widget w;
{
}
/* Exported Functions */
/* Function Name: XawListChange.
* Description: Changes the list being used and shown.
* Arguments: w - the list widget.
* list - the new list.
* nitems - the number of items in the list.
* longest - the length (in Pixels) of the longest element
* in the list.
* resize - if TRUE the the list widget will
* try to resize itself.
* Returns: none.
* NOTE: If nitems of longest are <= 0 then they will be calculated.
* If nitems is <= 0 then the list needs to be NULL terminated.
*/
void
int resize_it)
#else
#endif
#else
Widget w;
char ** list;
#endif
{
/* If the user passes 0 meaning "calculate it", it must be free */
if ( longest != 0 )
else /* the user's word is god. */
if ( resize_it )
/* else - still resize if its not locked */
CalculatedValues( w );
&new_width, &new_height ) )
if ( XtIsRealized( w ) )
}
/* Function Name: XawListUnhighlight
* Description: unlights the current highlighted element.
* Arguments: w - the widget.
* Returns: none.
*/
void
#else
Widget w;
#endif
{
}
/* Function Name: XawListHighlight
* Description: Highlights the given item.
* Arguments: w - the list widget.
* item - the item to hightlight.
* Returns: none.
*/
void
#else
XawListHighlight(w, item)
Widget w;
int item;
#endif
{
if (XtIsSensitive(w)) {
}
}
/* Function Name: XawListShowCurrent
* Description: returns the currently highlighted object.
* Arguments: w - the list widget.
* Returns: the info about the currently highlighted object.
*/
#else
Widget w;
#endif
{
ret_val = (XawListReturnStruct *)
else
return(ret_val);
}