List.c revision 749
68N/A/* $XConsortium: List.c,v 1.39 94/04/17 20:12:15 kaleb Exp $ */ 68N/ACopyright (c) 1989, 1994 X Consortium 68N/APermission is hereby granted, free of charge, to any person obtaining a copy 68N/Aof this software and associated documentation files (the "Software"), to deal 919N/Ain the Software without restriction, including without limitation the rights 919N/Ato use, copy, modify, merge, publish, distribute, sublicense, and/or sell 919N/Acopies of the Software, and to permit persons to whom the Software is 919N/Afurnished to do so, subject to the following conditions: 919N/AThe above copyright notice and this permission notice shall be included in 919N/Aall copies or substantial portions of the Software. 919N/ATHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 919N/AIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 919N/AFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 919N/AX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 919N/AAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 919N/ACONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 919N/AExcept as contained in this notice, the name of the X Consortium shall not be 919N/Aused in advertising or otherwise to promote the sale, use or other dealings 68N/Ain this Software without prior written authorization from the X Consortium. 68N/A * This is a List widget. It allows the user to select an item in a list and 962N/A * notifies the application through a callback function. 962N/A * By: Chris D. Peterson 970N/A/* These added so widget knows whether its height, width are user selected. 970N/AI also added the freedoms member of the list widget part. */ 68N/A * Default Translation table. 68N/A "<Btn1Down>: Set()\n\ /**************************************************************** * Full class record constant ****************************************************************/ /* class_part_initialize */ NULL,
/* class_inited */ FALSE,
/* initialize_hook */ NULL,
/* compress_motion */ TRUE,
/* compress_exposure */ FALSE,
/* compress_enterleave */ TRUE,
/* visible_interest */ FALSE,
/* set_values_hook */ NULL,
/* get_values_hook */ NULL,
/* callback_private */ NULL,
/* Simple class fields initialization */ /* List class fields initialization */ /**************************************************************** ****************************************************************/ * 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. */ /* If list is NULL then the list will just be the name of the widget. */ /* Get number of items. */ lw->
list.
longest = 0;
/* so it will accumulate real longest below */ /* 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 /* Function Name: ChangeSize. * Description: Laysout the widget. * Arguments: w - the widget to try change the size of. "List Widget: Unknown geometry return.");
"List Widget: Unknown geometry return.");
/* Function Name: Initialize * Description: Function that initilizes the widget instance. * Arguments: junk - NOT USED. * Initialize all private resources. /* record for posterity if we are free */ /* Set row height. based on font or fontset */ /* Function Name: CvtToItem * Description: Converts Xcoord to item number of item containing that * Arguments: w - the list widget. * xloc, yloc - x location, and y location. * Returns: the item number. /* If out of range, return minimum possible value. */ /* If in right margin handle things right. */ /* 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 **. /* 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. * Returns: TRUE if the item passed is in the given rectangle. * Paints the color of the background for the given item. It performs * 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 */ /* 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 */ /* 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 * 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. */ * paints the name of the item in the appropriate location. * item - the item to draw. * NOTE: no action taken on an unrealized widget. */ /* 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. */ * Repaints the widget window on expose events. * event - the expose event for this repaint. * junk - not used, unless three-d patch enabled. */ int item;
/* an item to work with. */ * This tells the parent what size we would like to be * given certain constraints. * intended - what the parent intends to do with us. * requested - what we want to happen. */ * We only care about our height and width. * resizes the widget, by changing the number of rows and columns. */ "List Widget: Size changed when it shouldn't have when resising.");
* lays out the item in the list. * xfree, yfree - TRUE if we are free to resize the widget in * 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. */ * If force columns is set then always use number of columns specified /* 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. */ * 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 * 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. * 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 else if (!
yfree) {
/* xfree must be TRUE. */ * 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. */ * 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. if (
lw->
list.
paste )
/* if XtNpasteBuffer set then paste it. */ * Call Callback function. * unhighlights the current element. */ * Highlights the current element. */ * Set specified arguments into widget /* If the request height/width is different, lock it. Unless its 0. If */ /* 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. */ /* Equiv. fontsets might have different values, but the same fonts, so the next comparison is sloppy but not dangerous. */ /* Function Name: XawListChange. * Description: Changes the list being used and shown. * Arguments: w - the list widget. * nitems - the number of items in the list. * longest - the length (in Pixels) of the longest element * resize - if TRUE the the list widget will * NOTE: If nitems of longest are <= 0 then they will be calculated. * If nitems is <= 0 then the list needs to be NULL terminated. /* If the user passes 0 meaning "calculate it", it must be free */ else /* the user's word is god. */ /* else - still resize if its not locked */ /* Function Name: XawListUnhighlight * Description: unlights the current highlighted element. * Arguments: w - the widget. /* Function Name: XawListHighlight * Description: Highlights the given item. * Arguments: w - the list widget. * item - the item to hightlight. /* Function Name: XawListShowCurrent * Description: returns the currently highlighted object. * Arguments: w - the list widget. * Returns: the info about the currently highlighted object.