📄 dialog.cc
字号:
//**************************************************************//* filename: dialog.cc *//* *//**************************************************************//* programmed by: Thomas Wagner *//* last change: 15-05-95 *//**************************************************************#include <stdio.h>#include <stdlib.h>#include <string.h>#include "dialog.h"extern unsigned long buttonpix, blackpix, whitepix, shadowpix, lightpix;extern Cursor maincursor;Dialog::Dialog (Display * initdisplay, GC initgc, BigWindow * parent, XFontStruct * fontstruct, int initx, int inity, int initwidth, int initheight, char *inittext, unsigned short initoptions, int Actionnumber):BigWindow (initdisplay, initgc, DefaultRootWindow (initdisplay), fontstruct, initx, inity, initwidth, initheight, inittext, DEFAULT_BDWIDTH){ Parent = parent; actionnumber = Actionnumber; width = MAX (XTextWidth (fontstruct, text, strlen (text)) + 2 * DIALOGBORDER, width); short allbuttonswidth = 2 * DIALOGBORDER, buttonnumber = 0, buttonwidth = 40; if (initoptions & DISPLAY_YES) { Yes = new ActionIcon (display, gc, this, fontstruct, 35, 40, buttonwidth, 30, "Yes", NULL, 0, 0, DIALOG_YES_ACTION, ICON_SELECTABLE); buttonnumber++; } else Yes = NULL; if (initoptions & DISPLAY_NO) { No = new ActionIcon (display, gc, this, fontstruct, 105, 40, buttonwidth, 30, "No", NULL, 0, 0, DIALOG_NO_ACTION, ICON_SELECTABLE); buttonnumber++; } else No = NULL; if (initoptions & DISPLAY_CANCEL) { Cancel = new ActionIcon (display, gc, this, fontstruct, 105, 40, buttonwidth, 30, "Cancel", NULL, 0, 0, DIALOG_CANCEL_ACTION, ICON_SELECTABLE); buttonnumber++; } else Cancel = NULL; allbuttonswidth += ((buttonnumber * 2) - 1) * buttonwidth; width = MAX (width, allbuttonswidth); SizeMe (width, height); short depth, textx, texty; textx = (int) ((width - XTextWidth (fontstruct, text, strlen (text))) * .5); texty = fontstruct->max_bounds.ascent + fontstruct->max_bounds.descent + 10; depth = DefaultDepth (display, DefaultScreen (display)); pixmap = XCreatePixmap (display, window, width, height, depth); XSetForeground (display, gc, buttonpix); XFillRectangle (display, pixmap, gc, 0, 0, width, height); DrawBorder (pixmap, HIGH); XSetForeground (display, gc, blackpix); XDrawString (display, pixmap, gc, textx, texty, text, strlen (text)); FixMySize ();// last place all icons short leftpos = (width - allbuttonswidth) / 2; if (Yes != NULL) { Yes->PlaceMe (leftpos, Yes->Gety ()); leftpos += 2 * buttonwidth; } if (No != NULL) { No->PlaceMe (leftpos, No->Gety ()); leftpos += 2 * buttonwidth; } if (Cancel != NULL) Cancel->PlaceMe (leftpos, Cancel->Gety ()); SetSelectedInput (ExposureMask | StructureNotifyMask);}void Dialog::Action (int Actionnumber, int value){ UnmapMe (); Parent->Action (actionnumber, Actionnumber);#if 0 /* XXX: would you believe this ??? */ delete this;#endif}void Dialog::HandleEvent (XEvent * Event){ switch (Event->type) { case Expose: if (Event->xexpose.count == 0) XCopyArea (display, pixmap, window, gc, 0, 0, width, height, 0, 0); break; }}Dialog::~Dialog (){ UnmapMe (); if (Yes != NULL) delete Yes; if (No != NULL) delete No; if (Cancel != NULL) delete Cancel; XFreePixmap (display, pixmap);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -