[Motiftools-xmt-cvs] CVS: xmt/Xmt ExtToggle.c,1.7,1.8
Brought to you by:
motiftools
From: Grant M. <grm...@us...> - 2004-12-10 01:47:10
|
Update of /cvsroot/motiftools/xmt/Xmt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3884 Modified Files: ExtToggle.c Log Message: This contains two fixes for ExtToggle: * The indicator should be centered according to the first line of text. * In Motif 2.x, the indicator appearance is now correctly selected, using proper Motif rules. Index: ExtToggle.c =================================================================== RCS file: /cvsroot/motiftools/xmt/Xmt/ExtToggle.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** ExtToggle.c 15 Aug 2002 01:27:25 -0000 1.7 --- ExtToggle.c 10 Dec 2004 01:47:00 -0000 1.8 *************** *** 10,13 **** --- 10,19 ---- * * $Log$ + * Revision 1.8 2004/12/10 01:47:00 grmcdorman + * This contains two fixes for ExtToggle: + * * The indicator should be centered according to the first line of text. + * * In Motif 2.x, the indicator appearance is now correctly selected, using + * proper Motif rules. + * * Revision 1.7 2002/08/15 01:27:25 grmcdorman * Correct error in resources *************** *** 702,705 **** --- 708,770 ---- /* Toggle Drawing Support */ + + /**************************************************************** + * IndicatorType + * On Motif 1.x, the only supported indicator type is the square + * (N of Many) or the diamond (1 of N). + * + * On Motif 2.x, the appearance is controlled by a combination of + * the indicatorOn, indicatorType, and XmDisplay enableToggleVisual + * resources. + * + * Fortunately, the choice between N of the set and one of the set + * doesn't change. + * + * So this function returns the indicator appearance as follows: + * For an N_OF_MANY, the value of indicatorOn is returned, + * adjusted according to XmDisplay.enableVisual if appropriate. + * + * For the others - all one of a set, i.e. radio-button style - + * the value of indicatorType is returned, adjusted according + * to XmDisplay.enableVisual if appropriate. + * + ****************************************************************/ + #if NeedFunctionPrototypes + static int GetIndicatorType(XmtExtToggleWidget lw) + #else + static int GetIndicatorType(lw) + XmtExtToggleWidget lw; + #endif + { + int indicator = lw->toggle.ind_on; + int type = lw->toggle.ind_type; + + #if defined(XmNenableToggleVisual) + Widget xmDisplay = XmGetXmDisplay(XtDisplay( (Widget) lw ) ); + Boolean enableToggleVisual; + XtVaGetValues(xmDisplay, XmNenableToggleVisual, &enableToggleVisual, NULL); + + switch (type) { + case XmONE_OF_MANY: + type = enableToggleVisual ? XmONE_OF_MANY_ROUND : XmONE_OF_MANY_DIAMOND; + break; + case XmN_OF_MANY: + if (indicator == XmINDICATOR_FILL) { + type = enableToggleVisual ? XmINDICATOR_CHECK_BOX : XmINDICATOR_BOX; + } else { + type = indicator; + } + break; + /* default: type as is */ + } + #else + /* Motif 1.x: no fancy stuff */ + if (type == XmN_OF_MANY) { + type = indicator + } + #endif + return type; + } + /**************************************************************** * DrawToggle *************** *** 716,719 **** --- 781,788 ---- int size = lw->toggle.indicator_dim; int x, y; + #if XmVersion >= 2000 + Dimension text_height; + int line_count; + #endif if (lw->label.string_direction == XmSTRING_DIRECTION_R_TO_L) { *************** *** 736,739 **** --- 805,826 ---- } else { y = lw->ext_toggle.label_y; + #if XmVersion >= 2000 + /* + * Center vertically to first line of text (as done in later Motif + * versions). ... note that this is broken if the text contains + * different height lines. (Yes, I did look at the Motif source.) + * + * A non-broken version would extract the XmString substring to the + * first separator, and use that for the height. + */ + + text_height = XmStringHeight(lw->label.font, lw->label._label); + line_count = XmStringLineCount(lw->label._label); + if (line_count < 1) line_count = 1; + /* single line height */ + text_height /= line_count; + + y += (text_height - size) / 2; + #endif } *************** *** 744,752 **** DrawToggleNOfMany(lw, draw_set, x, y, size); #if XmVersion >= 2000 ! } else if (lw->toggle.ind_type == XmONE_OF_MANY_ROUND) { DrawToggleOneOfManyRound(lw, draw_set, x, y, size); #endif ! } else /* lw->toggle.ind_type == XmONE_OF_MANY || ! lw->toggle.ind_type == XmONE_OF_MANY_DIAMOND*/ { DrawToggleOneOfManyDiamond(lw, draw_set, x, y, size); } --- 831,838 ---- DrawToggleNOfMany(lw, draw_set, x, y, size); #if XmVersion >= 2000 ! } else if (GetIndicatorType(lw) == XmONE_OF_MANY_ROUND) { DrawToggleOneOfManyRound(lw, draw_set, x, y, size); #endif ! } else /* GetIndicatorType(lw) == XmONE_OF_MANY_DIAMOND */ { DrawToggleOneOfManyDiamond(lw, draw_set, x, y, size); } *************** *** 770,773 **** --- 856,860 ---- int inside_x, inside_y, inside_size; int shadow = DETAIL_SHADOW_THICKNESS(lw); + int type = GetIndicatorType(lw); /* Motif adjusts square toggle size to look similar to rectangular */ *************** *** 783,787 **** #if XmVersion >= 2000 ! if (lw->toggle.ind_on & XmINDICATOR_3D_BOX) { XmeDrawShadows(lw->core.screen->display, lw->ext_toggle.buffer_pixmap, lw->primitive.top_shadow_GC, lw->primitive.bottom_shadow_GC, --- 870,874 ---- #if XmVersion >= 2000 ! if (type & XmINDICATOR_3D_BOX) { XmeDrawShadows(lw->core.screen->display, lw->ext_toggle.buffer_pixmap, lw->primitive.top_shadow_GC, lw->primitive.bottom_shadow_GC, *************** *** 815,821 **** } #if XmVersion >= 2000 ! if (lw->toggle.ind_on != XmINDICATOR_BOX && ! (lw->toggle.ind_on & (XmINDICATOR_CHECK | XmINDICATOR_CROSS)) && draw_set) { ! /* FIXME: this may not be right in all circumstances. */ XSetClipMask(lw->core.screen->display, lw->label.normal_GC, None); XmeDrawIndicator(lw->core.screen->display, lw->ext_toggle.buffer_pixmap, --- 902,911 ---- } #if XmVersion >= 2000 ! /* Draw the marker (cross, check) as indicated */ ! if (type != XmINDICATOR_BOX && ! (type & (XmINDICATOR_CHECK | XmINDICATOR_CROSS)) && draw_set) { ! /* FIXME: this may not be right in all circumstances. ! * To date it has worked, though. ! */ XSetClipMask(lw->core.screen->display, lw->label.normal_GC, None); XmeDrawIndicator(lw->core.screen->display, lw->ext_toggle.buffer_pixmap, *************** *** 824,828 **** inside_size, inside_size, 0, ! lw->toggle.ind_on); } #endif --- 914,918 ---- inside_size, inside_size, 0, ! type); } #endif *************** *** 830,834 **** /**************************************************************** ! * DrawToggleOneOfManyDiamond - does not work in Motif 1.x ****************************************************************/ #if NeedFunctionPrototypes --- 920,924 ---- /**************************************************************** ! * DrawToggleOneOfManyDiamond - may not work in Motif 1.x ****************************************************************/ #if NeedFunctionPrototypes |