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

📄 tkwinmenu.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 5 页
字号:
    int y,				/* right edge */    int width,				/* width of entry */    int height)				/* height of entry */{    int baseline;    int indicatorSpace =  mePtr->indicatorSpace;    int leftEdge = x + indicatorSpace + menuPtr->activeBorderWidth;    int imageHeight, imageWidth;    /*     * Draw label or bitmap or image for entry.     */    baseline = y + (height + fmPtr->ascent - fmPtr->descent) / 2;    if (mePtr->image != NULL) {    	Tk_SizeOfImage(mePtr->image, &imageWidth, &imageHeight);    	if ((mePtr->selectImage != NULL)	    	&& (mePtr->entryFlags & ENTRY_SELECTED)) {	    Tk_RedrawImage(mePtr->selectImage, 0, 0,		    imageWidth, imageHeight, d, leftEdge,	            (int) (y + (mePtr->height - imageHeight)/2));    	} else {	    Tk_RedrawImage(mePtr->image, 0, 0, imageWidth,		    imageHeight, d, leftEdge,		    (int) (y + (mePtr->height - imageHeight)/2));    	}    } else if (mePtr->bitmap != None) {    	int width, height;        Tk_SizeOfBitmap(menuPtr->display,	        mePtr->bitmap, &width, &height);    	XCopyPlane(menuPtr->display,	    	mePtr->bitmap, d,	    	gc, 0, 0, (unsigned) width, (unsigned) height, leftEdge,	    	(int) (y + (mePtr->height - height)/2), 1);    } else {    	if (mePtr->labelLength > 0) {	    Tk_DrawChars(menuPtr->display, d, gc,		    tkfont, mePtr->label, mePtr->labelLength,		    leftEdge, baseline);	    DrawMenuUnderline(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y,		    width, height);    	}    }    if (mePtr->state == tkDisabledUid) {	if (menuPtr->disabledFg == NULL) {	    XFillRectangle(menuPtr->display, d, menuPtr->disabledGC, x, y,		    (unsigned) width, (unsigned) height);	} else if ((mePtr->image != NULL) 		&& (menuPtr->disabledImageGC != None)) {	    XFillRectangle(menuPtr->display, d, menuPtr->disabledImageGC,		    leftEdge,		    (int) (y + (mePtr->height - imageHeight)/2),		    (unsigned) imageWidth, (unsigned) imageHeight);	}    }}/* *-------------------------------------------------------------- * * TkpComputeMenubarGeometry -- * *	This procedure is invoked to recompute the size and *	layout of a menu that is a menubar clone. * * Results: *	None. * * Side effects: *	Fields of menu entries are changed to reflect their *	current positions, and the size of the menu window *	itself may be changed. * *-------------------------------------------------------------- */voidTkpComputeMenubarGeometry(menuPtr)    TkMenu *menuPtr;		/* Structure describing menu. */{    TkpComputeStandardMenuGeometry(menuPtr);}/* *---------------------------------------------------------------------- * * DrawTearoffEntry -- * *	This procedure draws the background part of a menu. * * Results: *	None. * * Side effects: *	Commands are output to X to display the menu in its *	current mode. * *---------------------------------------------------------------------- */voidDrawTearoffEntry(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, y, width, height)    TkMenu *menuPtr;			/* The menu we are drawing */    TkMenuEntry *mePtr;			/* The entry we are drawing */    Drawable d;				/* The drawable we are drawing into */    GC gc;				/* The gc we are drawing with */    Tk_Font tkfont;			/* The font we are drawing with */    CONST Tk_FontMetrics *fmPtr;	/* The metrics we are drawing with */    int x;    int y;    int width;    int height;{    XPoint points[2];    int segmentWidth, maxX;    if (menuPtr->menuType != MASTER_MENU) {	return;    }        points[0].x = x;    points[0].y = y + height/2;    points[1].y = points[0].y;    segmentWidth = 6;    maxX  = width - 1;    while (points[0].x < maxX) {	points[1].x = points[0].x + segmentWidth;	if (points[1].x > maxX) {	    points[1].x = maxX;	}	Tk_Draw3DPolygon(menuPtr->tkwin, d, menuPtr->border, points, 2, 1,		TK_RELIEF_RAISED);	points[0].x += 2*segmentWidth;    }}/* *---------------------------------------------------------------------- * * TkpConfigureMenuEntry -- * *	Processes configurations for menu entries. * * Results: *	Returns standard TCL result. If TCL_ERROR is returned, then *	interp->result contains an error message. * * Side effects: *	Configuration information get set for mePtr; old resources *	get freed, if any need it. * *---------------------------------------------------------------------- */intTkpConfigureMenuEntry(mePtr)    register TkMenuEntry *mePtr;	/* Information about menu entry;  may					 * or may not already have values for					 * some fields. */{    TkMenu *menuPtr = mePtr->menuPtr;    if (!(menuPtr->menuFlags & MENU_RECONFIGURE_PENDING)) {	menuPtr->menuFlags |= MENU_RECONFIGURE_PENDING;	Tcl_DoWhenIdle(ReconfigureWindowsMenu, (ClientData) menuPtr);    }    return TCL_OK;}/* *---------------------------------------------------------------------- * * TkpDrawMenuEntry -- * *	Draws the given menu entry at the given coordinates with the *	given attributes. * * Results: *	None. * * Side effects: *	X Server commands are executed to display the menu entry. * *---------------------------------------------------------------------- */voidTkpDrawMenuEntry(mePtr, d, tkfont, menuMetricsPtr, x, y, width, height, 	strictMotif, drawArrow)    TkMenuEntry *mePtr;		    /* The entry to draw */    Drawable d;			    /* What to draw into */    Tk_Font tkfont;		    /* Precalculated font for menu */    CONST Tk_FontMetrics *menuMetricsPtr;				    /* Precalculated metrics for menu */    int x;			    /* X-coordinate of topleft of entry */    int y;			    /* Y-coordinate of topleft of entry */    int width;			    /* Width of the entry rectangle */    int height;			    /* Height of the current rectangle */    int strictMotif;		    /* Boolean flag */    int drawArrow;		    /* Whether or not to draw the cascade				     * arrow for cascade items. Only applies				     * to Windows. */{    GC gc, indicatorGC;    TkMenu *menuPtr = mePtr->menuPtr;    Tk_3DBorder bgBorder, activeBorder;    CONST Tk_FontMetrics *fmPtr;    Tk_FontMetrics entryMetrics;    int padY = (menuPtr->menuType == MENUBAR) ? 3 : 0;    int adjustedY = y + padY;    int adjustedHeight = height - 2 * padY;    /*     * Choose the gc for drawing the foreground part of the entry.     */    if ((mePtr->state == tkActiveUid)	    && !strictMotif) {	gc = mePtr->activeGC;	if (gc == NULL) {	    gc = menuPtr->activeGC;	}    } else {    	TkMenuEntry *cascadeEntryPtr;    	int parentDisabled = 0;    	    	for (cascadeEntryPtr = menuPtr->menuRefPtr->parentEntryPtr;    		cascadeEntryPtr != NULL;    		cascadeEntryPtr = cascadeEntryPtr->nextCascadePtr) {    	    if (strcmp(cascadeEntryPtr->name,     	    	    Tk_PathName(menuPtr->tkwin)) == 0) {    	    	if (cascadeEntryPtr->state == tkDisabledUid) {    	    	    parentDisabled = 1;    	    	}    	    	break;    	    }    	}	if (((parentDisabled || (mePtr->state == tkDisabledUid)))		&& (menuPtr->disabledFg != NULL)) {	    gc = mePtr->disabledGC;	    if (gc == NULL) {		gc = menuPtr->disabledGC;	    }	} else {	    gc = mePtr->textGC;	    if (gc == NULL) {		gc = menuPtr->textGC;	    }	}    }    indicatorGC = mePtr->indicatorGC;    if (indicatorGC == NULL) {	indicatorGC = menuPtr->indicatorGC;    }	        bgBorder = mePtr->border;    if (bgBorder == NULL) {	bgBorder = menuPtr->border;    }    if (strictMotif) {	activeBorder = bgBorder;    } else {	activeBorder = mePtr->activeBorder;	if (activeBorder == NULL) {	    activeBorder = menuPtr->activeBorder;	}    }    if (mePtr->tkfont == NULL) {	fmPtr = menuMetricsPtr;    } else {	tkfont = mePtr->tkfont;	Tk_GetFontMetrics(tkfont, &entryMetrics);	fmPtr = &entryMetrics;    }    /*     * Need to draw the entire background, including padding. On Unix,     * for menubars, we have to draw the rest of the entry taking     * into account the padding.     */        DrawMenuEntryBackground(menuPtr, mePtr, d, activeBorder, 	    bgBorder, x, y, width, height);        if (mePtr->type == SEPARATOR_ENTRY) {	DrawMenuSeparator(menuPtr, mePtr, d, gc, tkfont, 		fmPtr, x, adjustedY, width, adjustedHeight);    } else if (mePtr->type == TEAROFF_ENTRY) {	DrawTearoffEntry(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, adjustedY,		width, adjustedHeight);    } else {	DrawMenuEntryLabel(menuPtr, mePtr, d, gc, tkfont, fmPtr, x, adjustedY,		width, adjustedHeight);	DrawMenuEntryAccelerator(menuPtr, mePtr, d, gc, tkfont, fmPtr,		activeBorder, x, adjustedY, width, adjustedHeight, drawArrow);	if (!mePtr->hideMargin) {	    DrawMenuEntryIndicator(menuPtr, mePtr, d, gc, indicatorGC, tkfont,		    fmPtr, x, adjustedY, width, adjustedHeight);	}    }}/* *---------------------------------------------------------------------- * * GetMenuLabelGeometry -- * *	Figures out the size of the label portion of a menu item. * * Results: *	widthPtr and heightPtr are filled in with the correct geometry *	information. * * Side effects: *	None. * *---------------------------------------------------------------------- */static voidGetMenuLabelGeometry(mePtr, tkfont, fmPtr, widthPtr, heightPtr)    TkMenuEntry *mePtr;			/* The entry we are computing */    Tk_Font tkfont;			/* The precalculated font */    CONST Tk_FontMetrics *fmPtr;	/* The precalculated metrics */    int *widthPtr;			/* The resulting width of the label					 * portion */    int *heightPtr;			/* The resulting height of the label					 * portion */{    TkMenu *menuPtr = mePtr->menuPtr;     if (mePtr->image != NULL) {    	Tk_SizeOfImage(mePtr->image, widthPtr, heightPtr);    } else if (mePtr->bitmap != (Pixmap) NULL) {    	Tk_SizeOfBitmap(menuPtr->display, mePtr->bitmap, widthPtr, heightPtr);    } else {    	*heightPtr = fmPtr->linespace;    	    	if (mePtr->label != NULL) {    	    *widthPtr = Tk_TextWidth(tkfont, mePtr->label, mePtr->labelLength);    	} else {    	    *widthPtr = 0;    	}    }    *heightPtr += 1;}/* *---------------------------------------------------------------------- * * DrawMenuEntryBackground -- * *	This procedure draws the background part of a menu. * * Results: *	None. * * Side effects: *	Commands are output to X to display the menu in its *	current mode. * *---------------------------------------------------------------------- */static voidDrawMenuEntryBackground(    TkMenu *menuPtr,			/* The menu we are drawing. */    TkMenuEntry *mePtr,			/* The entry we are drawing. */    Drawable d,				/* What we are drawing into */    Tk_3DBorder activeBorder,		/* Border for active items */    Tk_3DBorder bgBorder,		/* Border for the background */    int x,				/* left edge */    int y,				/* top edge */    int width,				/* width of rectangle to draw */    int height)				/* height of rectangle to draw */{    if (mePtr->state == tkActiveUid) {	bgBorder = activeBorder;    }    Tk_Fill3DRectangle(menuPtr->tkwin, d, bgBorder,    	    x, y, width, height, 0, TK_RELIEF_FLAT);}/* *-------------------------------------------------------------- * * TkpComputeStandardMenuGeometry -- * *	This procedure is invoked to recompute the size and *	layout of a menu that is not a menubar clone. * * Results: *	None. * * Side effects: *	Fields of menu entries are changed to reflect their *	current positions, and the size of the menu window *	itself may be changed. * *-------------------------------------------------------------- */voidTkpComputeStandardMenuGeometry(    TkMenu *menuPtr)		/* Structure describing menu. */{    Tk_Font tkfont;    Tk_FontMetrics menuMetrics, entryMetrics, *fmPtr;    int x, y, height, width, indicatorSpace, labelWidth, accelWidth;    int windowWidth, windowHeight, accelSpace;    int i, j, lastColumnBreak = 0;        if (menuPtr->tkwin == NULL) {	return;    }    x = y = menuPtr->borderWidth;    indicatorSpace = labelWidth = accelWidth = 0;    windowHeight = 0;    /*     * On the Mac especially, getting font metrics can be quite slow,     * so we want to do it intelligently. We are going to precalculate     * them and pass them down to all of the measuring and drawing     * routines. We will measure the font metrics of the menu once.     * If an entry does not have its own font set, then we give     * the geometry/drawing routines the menu's font and metrics.     * If an entry has its own font, we will measure that font and     * give all of the geometry/drawing the entry's font and metrics.     */    Tk_GetFontMetrics(menuPtr->tkfont, &menuMetrics);    accelSpace = Tk_TextWidth(menuPtr->tkfont, "M", 1);    for (i = 0; i < menuPtr->numEntries; i++) {    	tkfont = menuPtr->entries[i]->tkfont;    	if (tkfont == NULL) {    	    tkfont = menuPtr->tkfont;    	    fmPtr = &menuMetrics;    	} else {    	    Tk_GetFontMetrics(tkfont, &entryMetrics);    	    fmPtr = &entryMetrics;    	}    		if ((i > 0) && menuPtr->entries[i]->columnBreak) {	    if (accelWidth != 0) {		labelWidth += accelSpace;	    }	    for (j = lastColumnBreak; j < i; j++) {		menuPtr->entries[j]->indicatorSpace = indicatorSpace;		menuPtr->entries[j]->labelWidth = labelWidth;		menuPtr->entries[j]->width = indicatorSpace + labelWidth			+ accelWidth + 2 * menuPtr->activeBorderWidth;		menuPtr->entries[j]->x = x;		menuPtr->entries[j]->entryFlags &= ~ENTRY_LAST_COLUMN;	    }	    x += indicatorSpace + labelWidth + accelWidth		    + 2 * m

⌨️ 快捷键说明

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