⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buttonbox.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 3 页
字号:
ChangeManaged(	Widget bbw){   Boolean		anyChanged = False;   Dimension		wd = 0;   Dimension		ht = 0;   int			i;/* * Update the "was_managed" flag in the child constraint record and see if *    there are any changes. */   for (i=0; i<BB_numChildren(bbw); i++) {      Widget	w = BB_children(bbw)[i];      if ( BB_wasManaged(w) != XtIsManaged(w) ) {	 anyChanged = TRUE;	 BB_wasManaged(w) = XtIsManaged(w);      }   }   if ( !anyChanged ) return;   SortChildren(bbw);   if ( BB_exposed(bbw) )      Refresh(bbw);   _XmNavigChangeManaged(bbw);} /* End ChangeManaged *//*--------------------------------------------------------------- * Put children in the order specified by their positionIndex resources */static voidSortChildren(	Widget bbw){   int		i;   short	minIndex, curIndex;   int		count;   int		wpos;   Widget	*child;   Boolean	sorted;   WidgetList	wlist;   if ( debuglev > 2 ) printf("ButtonBox(%s):SortChildren\n", XtName(bbw));/* * See if any are out of place */   count  = BB_numChildren(bbw);   child  = BB_children(bbw);   sorted = True;   for (i=0; sorted && i<count; i++) {      int	index = BB_posIndex(*child) - 1;      if ( index != i ) sorted = False;      child++;   }   if ( sorted ) return;/* * Create a parallel array for the sorted list */   wlist = (WidgetList)XtMalloc(count*sizeof(Widget));   wpos = 0;/* * Loop until the list is sorted */   curIndex = -1;   while ( !sorted ) {/* * Find the minimum index greater than the current index */      child    = BB_children(bbw);      minIndex = 9999;      for (i=0; i<count; i++) {	 int	index = BB_posIndex(*child) - 1;	 if ( index > curIndex && index < minIndex ) minIndex = index;	 child++;      }      if ( minIndex < 9999 ) {/* * Copy all widgets equal to the min index */	 child = BB_children(bbw);	 for (i=0; i<count; i++) {	    int	index = BB_posIndex(*child) - 1;	    if ( index == minIndex ) wlist[wpos++] = *child;	    child++;	 }	 curIndex = minIndex;      }      else	 sorted = True;   } /* End while not sorted *//* * Copy new list to original and update position index */   child = BB_children(bbw);   for (i=0; i<count; i++) {      *child = wlist[i];      BB_posIndex(*child) = i+1;      child++;   }/* * Return allocated memory */   XtFree((char*)wlist);} /* End SortChildren *//*--------------------------------------------------------------- * Recalculate child positions */static voidRefresh(	Widget bbw){   Dimension	wd, ht;   if ( debuglev > 2 ) printf("ButtonBox(%s):Refresh\n", XtName(bbw));/* * Calculate our preferred size */   GetPreferredSize(bbw, &wd, &ht);/* * See if there is a size change */   if ( wd != XtWidth(bbw) || ht != XtHeight(bbw) ) {      XtWidgetGeometry	desired;      XtWidgetGeometry	allowed;      XtGeometryResult	answer;      desired.width  = wd;      desired.height = ht;      desired.request_mode = CWWidth | CWHeight;      answer = XtMakeGeometryRequest(bbw, &desired, &allowed);/* * On an Almost, accept the returned value and make a second request to get *    a Yes returned. */      if ( answer == XtGeometryAlmost ) {	 desired = allowed;	 answer = XtMakeGeometryRequest(bbw, &desired, &allowed);      }      wd = desired.width;      ht = desired.height;   } /* End if there is a size change *//* * Now place the widgets */   PlaceChildren(bbw, wd, ht);} /* End Refresh *//*--------------------------------------------------------------- * Count the number of managed children */static intManagedChildCount(	Widget		bbw){   int		i;   int		count = 0;   Widget	*p    = BB_children(bbw);   for (i=0; i<BB_numChildren(bbw); i++) {      if ( XtIsManaged(*p) ) count++;      p++;   }   return count;} /* End ManagedChildCount *//*--------------------------------------------------------------- * Figure out what size we'd like to be */static voidGetPreferredSize(	Widget		bbw,	Dimension	*wd,	Dimension	*ht){   int			rows, cols;   Boolean		found = False;   int			count = ManagedChildCount(bbw);   if ( debuglev > 2 ) printf("ButtonBox(%s):GetPreferredSize\n", XtName(bbw));/* * If we can't be resized, do nothing. */   if ( !BB_resizeWidth(bbw) && !BB_resizeHeight(bbw) ) {      *wd = XtWidth(bbw);      *ht = XtHeight(bbw);   }/* * If we're completely resizable, use one row or column */   else if ( BB_resizeWidth(bbw) && BB_resizeHeight(bbw) ) {      *wd = 9999;      *ht = 9999;      if ( BB_orient(bbw) == XmHORIZONTAL )	 TrySize(bbw, 1, count, wd, ht);      else	 TrySize(bbw, count, 1, wd, ht);   }/* * If the width is fixed, increase the number of rows until we have a fit */   else if ( !BB_resizeWidth(bbw) ) {      *wd = XtWidth(bbw);      *ht = 9999;/* * Increase the number of rows until we have a fit */      for (rows=1; !found && rows <= count; ) {	 cols = count / rows;	 if ( count % rows > 0 ) cols++;	 found = TrySize(bbw, rows, cols, wd, ht);	 if ( !found ) rows++;      }      if ( !found )	 TrySize(bbw, count, 1, wd, ht);   } /* End if width if fixed */   else { /* height fixed */      *wd = 9999;      *ht = XtHeight(bbw);/* * Increase the number of columns until we have a fit */      for (cols=1; !found && cols <= count; ) {	 rows = count / cols;	 if ( count % cols > 0 ) rows++;	 found = TrySize(bbw, rows, cols, wd, ht);	 if ( !found ) cols++;      }      if ( !found )	 TrySize(bbw, 1, count, wd, ht);   } /* End if height is fixed */   if ( debuglev > 2 ) printf("   preferred size is %d by %d\n", *wd, *ht);   return;} /* End GetPreferredSize *//*----------------------------------------------------------------------- * Function to see if a given number of rows and columns will fit */static BooleanTrySize(	Widget		bbw,	int		rows,	int		cols,	Dimension	*wd,	Dimension	*ht){   Dimension	needWd, needHt;   int		i, r, c;   Boolean	wdFits, htFits;   int		count;   Dimension	*rowSizes, *colSizes;   if ( debuglev > 2 ) printf("   trying %d rows and %d cols\n", rows, cols);/* * Calculate the size of each row and column */   rowSizes = (Dimension*)XtMalloc(rows*sizeof(Dimension));   colSizes = (Dimension*)XtMalloc(cols*sizeof(Dimension));   GetCellSizes(bbw, rows, cols, rowSizes, colSizes);/* * Now that we know the sizes of all rows and columns, see if they will fit *    in the available space */   needWd = (Dimension)((BB_marginWd(bbw)*2) + (BB_colSpacing(bbw) * (cols-1)));   needHt = (Dimension)((BB_marginHt(bbw)*2) + (BB_rowSpacing(bbw) * (rows-1)));   for (c=0; c<cols; c++) needWd += (Dimension)colSizes[c];   for (r=0; r<rows; r++) needHt += (Dimension)rowSizes[r];   wdFits = (BB_resizeWidth(bbw)  || needWd <= *wd);   htFits = (BB_resizeHeight(bbw) || needHt <= *ht);/* * If we've got a fit, apply it. */   if ( wdFits && BB_resizeWidth(bbw)  ) *wd = needWd;   if ( htFits && BB_resizeHeight(bbw) ) *ht = needHt;/* * Return allocated memory */   XtFree((char*)rowSizes);   XtFree((char*)colSizes);   return (wdFits && htFits);} /* End TrySize *//*--------------------------------------------------------------- * Get the sizes need for each cell using the specified number of rows and *    columns */static voidGetCellSizes(	Widget		bbw,	int		rows,	int		cols,	Dimension	*rowSizes,	Dimension	*colSizes){   int	r, c, i, count;   int	num;   for (r=0; r<rows; r++) rowSizes[r] = 0;   for (c=0; c<cols; c++) colSizes[c] = 0;/* * Loop through widgets */   count = BB_numChildren(bbw);   num   = 0;   for (i=0; i<count; i++) {      Dimension		*rowSize, *colSize;      int		index;      Widget		w = BB_children(bbw)[i];      if ( !XtIsManaged(w) ) continue;/* * Calculate row and column number */      if ( BB_orient(bbw) == XmHORIZONTAL ) {	 r = num / cols;	 c = num % cols;      }      else {	 r = num % rows;	 c = num / rows;      }      rowSize = &rowSizes[r];      colSize = &colSizes[c];/* * Compare widget size to known size */      GetChildSize(w);      if ( BB_prefWd(w) > *colSize ) *colSize = BB_prefWd(w);      if ( BB_prefHt(w) > *rowSize ) *rowSize = BB_prefHt(w);      num++;   } /* End for each child *//* *  Make rows the same size if necessary */   if ( BB_uniformRows(bbw) ) {/* * Find maximum row size */      Dimension	maxSize = 0;      Dimension	*rowSize = rowSizes;      for (r=0; r<rows; r++, rowSize++) {	 if ( *rowSize > maxSize ) maxSize = *rowSize;      }/* * Set all row sizes to the max */      rowSize = rowSizes;      for (r=0; r<rows; r++, rowSize++) *rowSize = maxSize;   } /* End if we need uniform rows *//* *  Make columns the same size if necessary */   if ( BB_uniformCols(bbw) ) {/* * Find maximum column size */      Dimension	maxSize = 0;      Dimension	*colSize = colSizes;      for (c=0; c<cols; c++, colSize++) {	 if ( *colSize > maxSize ) maxSize = *colSize;      }/* * Set all column sizes to the max */      colSize = colSizes;      for (c=0; c<cols; c++, colSize++) *colSize = maxSize;   } /* End if we need uniform cols */} /* End GetCellSizes *//*--------------------------------------------------------------- * Ask what size a child would like to be */static voidGetChildSize(	Widget			w){   XtWidgetGeometry	pref;   XtQueryGeometry(w, NULL, &pref);   BB_prefWd(w) = (pref.request_mode & CWWidth ) ? pref.width  : XtWidth(w);   BB_prefHt(w) = (pref.request_mode & CWHeight) ? pref.height : XtHeight(w);} /* End GetChildSize *//*----------------------------------------------------------------------- * Function to set the positions and sizes of our children */static void

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -