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

📄 viewfax.c

📁 涉及Fax/Mail/Voice通讯编程的一个程序
💻 C
📖 第 1 页 / 共 3 页
字号:
    Height = Area.h = DisplayHeight(Disp, Default_Screen);#endif    if (Geometry)	Area.v = XParseGeometry(Geometry, &Area.x, &Area.y,				&Area.w, &Area.h);    Area.w = max(64, Area.w);    Area.h = max(64, Area.h);    if (zfactor == 0)	for (zfactor = 1;	     faxw / zfactor > Area.w ||	     faxh / zfactor > Area.h;	     zfactor *= 2)	    ;    Attr.background_pixel = WhitePixel(Disp, Default_Screen);    Attr.border_pixel = BlackPixel(Disp, Default_Screen);    for (size_hints.width = faxw, i = 1; i < zfactor; i *= 2)	size_hints.width = (size_hints.width + 1) /2;    for (size_hints.height = faxh, i = 1; i < zfactor; i *= 2)	size_hints.height = (size_hints.height + 1) /2;    switch (Area.v & (XValue|XNegative)) {    case XValue:	size_hints.x = Area.x + BW;	break;    case XValue|XNegative:	Area.x = Width + Area.x - 2*BW - Area.w;	size_hints.x = Area.x + Area.w - size_hints.width;	break;    default:	size_hints.x = Area.x + (Area.w - size_hints.width)/2;    }    switch (Area.v & (YValue|YNegative)) {    case YValue:	size_hints.y = Area.y + BW;	break;    case YValue|YNegative:	Area.y = Height + Area.y - 2*BW - Area.h;	size_hints.y = Area.y + Area.h - size_hints.height;	break;    default:	size_hints.y = Area.y + (Area.h - size_hints.height)/2;    }    size_hints.max_width = size_hints.width;    size_hints.max_height = size_hints.height;    size_hints.flags = PSize|PMaxSize;    if (Area.v & (XValue|YValue)) size_hints.flags |= USPosition;    if (Area.v & (HeightValue|WidthValue)) size_hints.flags |= USSize;	    Win = XCreateWindow(Disp, Root, size_hints.x, size_hints.y,			size_hints.width, size_hints.height,			BW, 0, InputOutput, CopyFromParent,			CWBackPixel|CWBorderPixel, &Attr);#ifdef PWinGravity{    XWMHints wm_hints;    XClassHint class_hints;    XTextProperty windowName, iconName;    if (!XStringListToTextProperty(&thispage->name, 1, &windowName) ||	!XStringListToTextProperty(&ProgName, 1, &iconName)) {	fprintf(stderr, "%s: can't make window/icon name\n", ProgName);	exit(EXIT_FAILURE);    }    wm_hints.initial_state = NormalState;    wm_hints.input = True;    wm_hints.flags = StateHint|InputHint;    class_hints.res_name = ProgName;    class_hints.res_class = "Faxview";    XSetWMProperties(Disp, Win, &windowName, &iconName, argv, argc,		     &size_hints, &wm_hints, &class_hints);}#else    XSetStandardProperties(Disp, Win, thispage->name, ProgName,			   None, argv, argc, &size_hints);#endif    PaintGC = XCreateGC(Disp, Win, 0L, (XGCValues *) NULL);    XSetForeground(Disp, PaintGC, BlackPixel(Disp, Default_Screen));    XSetBackground(Disp, PaintGC, WhitePixel(Disp, Default_Screen));    XSetFunction(Disp, PaintGC, GXcopy);    WorkCursor = XCreateFontCursor(Disp, XC_watch);    ReadyCursor = XCreateFontCursor(Disp, XC_plus);    MoveCursor = XCreateFontCursor(Disp, XC_fleur);    LRCursor = XCreateFontCursor(Disp, XC_sb_h_double_arrow);    UDCursor = XCreateFontCursor(Disp, XC_sb_v_double_arrow);    XSelectInput(Disp, Win, Button2MotionMask | ButtonPressMask |		 ButtonReleaseMask | ExposureMask | KeyPressMask |		 SubstructureNotifyMask | OwnerGrabButtonMask |#ifdef USE_MOTIONHINT		 PointerMotionHintMask |#endif		 StructureNotifyMask);    wm_protocols = XInternAtom(Disp, "WM_PROTOCOLS", False);    wm_delete_window = XInternAtom(Disp, "WM_DELETE_WINDOW", False);    XChangeProperty(Disp, Win, wm_protocols, XA_ATOM, 32,                    PropModeAppend, (unsigned char * ) &wm_delete_window, 1);    XMapRaised(Disp, Win);}#define MAXZOOM	10/* After requesting a window size change, we throw away key and button presses   until we get the notification that the size has changed.  If for some   reason the notification does not come, we resume processing as normal after   PATIENCE milliseconds */#define PATIENCE 10000static voidShowLoop(void){    XEvent Event;    /* centre of image within window */    int x = 0, ox = 0, offx = 0, nx;	/* x, old x, offset x, new x */    int y = 0, oy = 0, offy = 0, ny;	/* y, old y, offset y, new y */    int oz, Resize = 0, Refresh = 0;	/* old zoom, window size changed,					   needs updating */    int PaneWidth, PaneHeight;		/* current size of our window */    int AbsX, AbsY;		/* absolute position of centre of window */    int FrameWidth, FrameHeight, FrameX, FrameY;/* size/offset of decoration */    int Oversize = 0;		/* window manager insists on oversize window */    int Reparented = 0;    int i;    XImage *Image, *Images[MAXZOOM];    struct pagenode *viewpage = NULL;	/* page viewed when help requested */    XSizeHints size_hints;    Time Lasttime = 0;		/* time of last accepted key/button press */    int ExpectConfNotify = 1;    XDefineCursor(Disp, Win, WorkCursor);    XFlush(Disp);    for (oz = 0; oz < MAXZOOM; oz++)	Images[oz] = NULL;    Image = Images[0] = Pimage(thispage);    for (oz = 0; oz < MAXZOOM && zfactor > (1 << oz); oz++)	Images[oz+1] = ZoomImage(Images[oz]);    Image = Images[oz];    /* some reasonable values,       just in case we do not get a configurenotify first */    AbsX = Area.w/2;    AbsY = Area.h/2;    FrameWidth = FrameHeight = FrameX = FrameY = 0;    PaneWidth = Image->width;    PaneHeight = Image->height;    XDefineCursor(Disp, Win, ReadyCursor);    for (;;) {	XNextEvent(Disp, &Event);	do {	    switch(Event.type) {	    case MappingNotify:		XRefreshKeyboardMapping((XMappingEvent *)(&Event));		break;	    case ClientMessage:		if (Event.xclient.data.l[0] == wm_delete_window) {		    XCloseDisplay(Disp);		    exit(EXIT_FAILURE);		}		break;	    case Expose:	    {		XExposeEvent *p = (XExposeEvent *) &Event;		XPutImage(Disp, Win, PaintGC, Image,			  p->x + x - PaneWidth/2,			  p->y + y - PaneHeight/2,			  p->x, p->y,			  p->width, p->height);	    }		break;	    case ReparentNotify:	    {		Window Myroot = Root;		Window Parent = Event.xreparent.parent;		Window Frame = Parent;	/* I should be so lucky! */		Window *Mykids;		unsigned int Nkids;		XWindowAttributes MyWA, FrameWA;		if (Parent != Root)		    do {			Frame = Parent;			while (!XQueryTree(Disp, Frame, &Myroot,					   &Parent, &Mykids, &Nkids))			    release(1);			if (Mykids) XFree(Mykids);		    } while (Parent != Root);		while (!XGetWindowAttributes(Disp, Win, &MyWA))		    release(1);		while (!XGetWindowAttributes(Disp, Frame, &FrameWA))		    release(1);		/* if area is partly constrained, stay where the WM put you */		if ((Area.v & (XValue|WidthValue)) == WidthValue) {		    Area.v |= XValue;		    Area.x = FrameWA.x;		}		if ((Area.v & (YValue|HeightValue)) == HeightValue) {		    Area.v |= YValue;		    Area.y = FrameWA.y;		}		XTranslateCoordinates(Disp, Win, Frame, 0, 0,				      &FrameX, &FrameY, &Parent);		FrameWidth = FrameWA.width - MyWA.width;		FrameHeight = FrameWA.height - MyWA.height;		Reparented = ExpectConfNotify = 1;	    }		break;	    case ConfigureNotify:	    {		XConfigureEvent *p = (XConfigureEvent *) &Event;		int NewX = AbsX;		int NewY = AbsY;#ifdef REAL_ROOT		if (p->send_event || !Reparented) {		    NewX = p->x + p->width/2;		    NewY = p->y + p->height/2;		}#else		/* support tvtwm */		if (!Reparented) {		    NewX = p->x + p->border_width + p->width/2;		    NewY = p->y + p->border_width + p->height/2;		}		else if (p->send_event) {		    /* the event info is viewport-relative, we need absolute */		    Window w;		    XTranslateCoordinates(Disp, Win, Root, 0, 0,					  &NewX, &NewY, &w);		    NewX += p->width/2;		    NewY += p->height/2;		}#endif		if (!ExpectConfNotify) {		    /* user intervention */		    if (PaneWidth != p->width)			Area.w = p->width + FrameWidth;		    if (PaneHeight != p->height)			Area.h = p->height + FrameHeight;		    if (NewX != AbsX || NewY != AbsY) {			Area.x = NewX - p->width/2 - FrameX;			Area.y = NewY - p->height/2 - FrameY;		    }		}		AbsX = NewX; AbsY = NewY;		PaneWidth = p->width;		PaneHeight = p->height;		Oversize = PaneWidth > Image->width ||		    PaneHeight > Image->height;		ExpectConfNotify = 0;	    }		break;	    case KeyPress:		if (ExpectConfNotify &&		    (Event.xkey.time < (Lasttime + PATIENCE)))		    break;		Lasttime = Event.xkey.time;		ExpectConfNotify = 0;		switch(XKeycodeToKeysym(Disp, Event.xkey.keycode, 0)) {		case XK_Help:		case XK_h:		    if (helppage == NULL) {			if (!notetiff(HELPFILE))			    goto nopage;			else {			    helppage = lastpage;			    lastpage = helppage->prev;			    lastpage->next = helppage->prev = NULL;			}		    }		    viewpage = thispage;		    thispage = helppage;		    goto newpage;		    break;		case XK_m:		    XDefineCursor(Disp, Win, WorkCursor);		    XFlush(Disp);		    thispage->extra = Images[0] = MirrorImage(Images[0]);		    thispage->orient ^= TURN_M;		    for (i = 1; Images[i]; i++) {			FreeImage(Images[i]);			Images[i] = ZoomImage(Images[i-1]);		    }		    Image = Images[oz];		    if (Event.xkey.state & ShiftMask)			TurnFollowing(TURN_M, thispage->next);		    XPutImage(Disp, Win, PaintGC, Image,			      x-PaneWidth/2, y-PaneHeight/2,			      0, 0, PaneWidth, PaneHeight);		    XDefineCursor(Disp, Win, ReadyCursor);		    break;		case XK_z:		    if (Event.xkey.state & ShiftMask)			goto Zoomout;		    else			goto Zoomin;		case XK_Up:		    y -= PaneHeight / 2;		    break;		case XK_Down:		    y += PaneHeight / 2;		    break;		case XK_Left:		    x -= PaneWidth / 2;		    break;		case XK_Right:		    x += PaneWidth / 2;		    break;		case XK_Home:		case XK_R7:		/* sun4 keyboard */		    if (Event.xkey.state & ShiftMask) {			thispage = firstpage;			goto newpage;		    }		    x = 0;		    y = 0;		    break;		case XK_End:		case XK_R13:		    if (Event.xkey.state & ShiftMask) {			thispage = lastpage;			goto newpage;		    }		    x = Image->width;		    y = Image->height;		    break;		case XK_l:		    XDefineCursor(Disp, Win, WorkCursor);		    XFlush(Disp);		    thispage->extra = Image = RotImage(Images[0]);		    thispage->orient ^= TURN_L;		    for (i = 1; Images[i]; i++) {			FreeImage(Images[i]);			Images[i] = NULL;		    }		    Images[0] = Image;		    for (i = 1; i <= oz; i++)			Images[i] = ZoomImage(Images[i-1]);		    Image = Images[oz];		    if (Event.xkey.state & ShiftMask)			TurnFollowing(TURN_L, thispage->next);		{ int t = x; x = y; y = t; }		    Refresh = Resize = 1;		    XDefineCursor(Disp, Win, ReadyCursor);		    break;		case XK_p:		case XK_minus:		case XK_Prior:		case XK_R9:		case XK_BackSpace:		    if (thispage->prev == NULL)			goto nopage;		    thispage = thispage->prev;		    goto newpage;		case XK_n:		case XK_plus:		case XK_space:		case XK_Next:		case XK_R15:		    if (thispage->next == NULL) {		    nopage:			if (abell) {			    putchar('\a');			    fflush(stdout);			}			if (vbell) {			    XAddPixel(Image, 1);			    XPutImage(Disp, Win, PaintGC, Image,				      x-PaneWidth/2, y-PaneHeight/2,				      0, 0, PaneWidth, PaneHeight);			    XSync(Disp, 0);			    (void) usleep(200000);			    XAddPixel(Image, 1);			    XPutImage(Disp, Win, PaintGC, Image,				      x-PaneWidth/2, y-PaneHeight/2,				      0, 0, PaneWidth, PaneHeight);			}			break;		    }		    thispage = thispage->next;		newpage:		    XDefineCursor(Disp, Win, WorkCursor);		    XFlush(Disp);		    /* if old image was not resized by the user, fit new one */		    Resize = ((PaneWidth == Image->width ||			       PaneWidth == Area.w - FrameWidth) &&			      (PaneHeight == Image->height ||			       PaneHeight == Area.h - FrameHeight));		    for (i = 1; Images[i]; i++) {			FreeImage(Images[i]);			Images[i] = NULL;		    }		    if (Pimage(thispage) == NULL)			while (!GetImage(thispage))			    /* try again */;		    Images[0] = Pimage(thispage);		    XStoreName(Disp, Win, thispage->name);		    for (i = 1; i <= oz; i++)			Images[i] = ZoomImage(Images[i-1]);		    Image = Images[oz];		    Refresh = 1;		    XDefineCursor(Disp, Win, ReadyCursor);		    break;		case XK_u:		    XDefineCursor(Disp, Win, WorkCursor);		    XFlush(Disp);		    thispage->extra = Images[0] = FlipImage(Images[0]);		    thispage->orient ^= TURN_U;		    for (i = 1; Images[i]; i++) {			FreeImage(Images[i]);			Images[i] = ZoomImage(Images[i-1]);		    }		    Image = Images[oz];		    if (Event.xkey.state & ShiftMask)			TurnFollowing(TURN_U, thispage->next);		    XPutImage(Disp, Win, PaintGC, Image,			      x-PaneWidth/2, y-PaneHeight/2,			      0, 0, PaneWidth, PaneHeight);		    XDefineCursor(Disp, Win, ReadyCursor);		    break;		case XK_q:		    if (viewpage) {			thispage = viewpage;			viewpage = NULL;			goto newpage;		    }		    XCloseDisplay(Disp);#ifdef xmalloc		    malloc_shutdown();#endif		    exit((Event.xkey.state & ShiftMask) ? EXIT_FAILURE : 0);		}		break;	    case ButtonPress:		if (ExpectConfNotify &&		    (Event.xbutton.time < (Lasttime + PATIENCE)))		    break;		Lasttime = Event.xbutton.time;		ExpectConfNotify = 0;		switch (Event.xbutton.button) {		case Button1:		Zoomout:		    if (oz > 0) {			Image = Images[--oz];			zfactor >>= 1;			x *= 2;			y *= 2;			Resize = Refresh = 1;		    }		    break;		case Button2:		    switch (((Image->width > PaneWidth)<<1) |			    (Image->height > PaneHeight)) {		    case 0:			break;		    case 1:			XDefineCursor(Disp, Win, UDCursor);			break;		    case 2:			XDefineCursor(Disp, Win, LRCursor);			break;

⌨️ 快捷键说明

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