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

📄 gvwin.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 5 页
字号:
/* return TRUE if button drawn */
BOOL
draw_button(DRAWITEMSTRUCT FAR *lpdis)
{
HBRUSH hbrush;
HPEN hpen_highlight, hpen_shadow, hpen_old;
HDC hdc = lpdis->hDC;
RECT rect;
HICON hicon;
HBITMAP hbitmap_old, hbitmap;
BITMAP bm;
int i;
TCHAR buf[20];
    rect = lpdis->rcItem;
    if (lpdis->CtlType != ODT_BUTTON)
	return FALSE;
    switch (lpdis->itemAction) {
	case ODA_DRAWENTIRE:
	    if ((hbitmap = LoadBitmap(phInstance,MAKEINTRESOURCE(lpdis->CtlID)))
	      != (HBITMAP)NULL) {
		HDC hdcsrc;
		COLORREF fgColour;
		COLORREF bgColour;
		GetObject(hbitmap, sizeof(BITMAP),&bm);
		if ( (rect.right-rect.left > bm.bmWidth) ||
		     (rect.bottom-rect.top > bm.bmHeight) ) {
		    hbrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
		    FillRect(hdc, &rect, hbrush);
		    DeleteBrush(hbrush);
		}
		/* When painting from monochrome bitmap to a colour DC,
		 * the text foreground and background colours are used
		 */
		hdcsrc = CreateCompatibleDC(hdc);
		fgColour = SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT));
		bgColour = SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
		hbitmap_old = (HBITMAP)SelectObject(hdcsrc,hbitmap);
		BitBlt(hdc, (rect.left+rect.right-bm.bmWidth)/2,
		   (rect.top+rect.bottom-bm.bmHeight)/2,
		   bm.bmWidth,bm.bmHeight,hdcsrc,0,0,SRCCOPY);
		SetTextColor(hdc, fgColour);
		SetBkColor(hdc, bgColour);
		SelectObject(hdcsrc,hbitmap_old);
		DeleteDC(hdcsrc);
		DeleteObject(hbitmap);
	    }
	    else {
		hbrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
		FillRect(hdc, &rect, hbrush);
		DeleteBrush(hbrush);
		if ((i = LoadString(phInstance, lpdis->CtlID, buf, sizeof(buf)))
		    != 0) {
		    COLORREF text_colour;
		    SIZE sz;
		    GetTextExtentPoint(hdc, buf, i, &sz);
		    text_colour = SetTextColor(hdc, GetSysColor(COLOR_MENUTEXT));
		    SetBkMode(hdc, TRANSPARENT);
		    TextOut(hdc, (rect.left+rect.right-sz.cx)/2,
			(rect.top+rect.bottom-sz.cy)/2, buf, i);
		    SetTextColor(hdc, text_colour);
		}
		else if ( (hicon = LoadIcon(phInstance, MAKEINTRESOURCE(lpdis->CtlID)))
		    != (HICON)NULL )  {
		    DrawIcon(hdc, (rect.left+rect.right-32)/2, 
			(rect.top+rect.bottom-32)/2, hicon);
		    DestroyIcon(hicon);
		}
	    }
	    hpen_old = SelectPen(hdc, hpen_btnshadow);
	    MoveTo(hdc, rect.left, rect.top);
	    LineTo(hdc, rect.right-1, rect.top);
	    LineTo(hdc, rect.right-1, rect.bottom-1);
	    LineTo(hdc, rect.left, rect.bottom-1);
	    LineTo(hdc, rect.left, rect.top-1);
	    SelectPen(hdc, hpen_old);
	    /* fall thru */
	case ODA_FOCUS:
	case ODA_SELECT:
	    if (lpdis->itemState & ODS_SELECTED) {
		hpen_highlight = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
		hpen_shadow = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNFACE));
	    }
	    else {
		hpen_highlight = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNHIGHLIGHT));
		hpen_shadow = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
	    }
	    hpen_old = SelectPen(hdc, hpen_highlight);
	    MoveTo(hdc, rect.left+1, rect.bottom-3);
	    LineTo(hdc, rect.left+1, rect.top+1);
	    LineTo(hdc, rect.right-2, rect.top+1);
	    MoveTo(hdc, rect.right-3, rect.top+2);
	    LineTo(hdc, rect.left+2, rect.top+2);
	    LineTo(hdc, rect.left+2, rect.bottom-4);
	    SelectPen(hdc, hpen_shadow);
	    MoveTo(hdc, rect.left+1, rect.bottom-2);
	    LineTo(hdc, rect.right-2, rect.bottom-2);
	    LineTo(hdc, rect.right-2, rect.top+1);
	    MoveTo(hdc, rect.right-3, rect.top+2);
	    LineTo(hdc, rect.right-3, rect.bottom-3);
	    LineTo(hdc, rect.left+2, rect.bottom-3);
	    SelectPen(hdc, hpen_old);
	    DeleteObject(hpen_highlight);
	    DeleteObject(hpen_shadow);
	    return TRUE;
    }
    return FALSE;
}

/* returns true if cursor in client area of Ghostscript image window */
BOOL
in_child_client_area()
{
RECT rect;
POINT pt;
HWND hwnd;
    GetCursorPos(&pt);
    hwnd = WindowFromPoint(pt);
    if ((hwnd != hwndimg) && !IsChild(hwndimg,hwnd))
	    return 0;
    GetClientRect(hwnd_image, &rect);
    ScreenToClient(hwnd_image, &pt);
    return PtInRect(&rect, pt);
}

/* returns true if cursor in client area of GSview window */
BOOL
in_client_area()
{
RECT rect;
POINT pt;
HWND hwnd;
    GetCursorPos(&pt);
    hwnd = WindowFromPoint(pt);
    if ((hwnd != hwndimg) && !IsChild(hwndimg,hwnd))
	    return 0;
    GetClientRect(hwndimg, &rect);
    ScreenToClient(hwndimg, &pt);
    return PtInRect(&rect, pt);
}

/* returns true if cursor in info area or button area of GSview windows */
BOOL
in_info_area()
{
RECT rect;
POINT pt;
HWND hwnd;
    GetCursorPos(&pt);
    hwnd = WindowFromPoint(pt);
    if ((hwnd != hwndimg) && !IsChild(hwndimg,hwnd))
	    return 0;
    ScreenToClient(hwndimg, &pt);

    GetClientRect(hwndimg, &rect);
    rect.bottom = img_offset.y;
    if (PtInRect(&rect, pt))
	    return TRUE;
    GetClientRect(hwndimg, &rect);
    rect.right = img_offset.x;
    return PtInRect(&rect, pt);
}


/* map from a coordinate in points, to a coordinate in pixels */
/* This is the opposite of the transform part of get_cursorpos */
/* Used when showing bbox */
void
map_pt_to_pixel(float *x, float *y)
{
    if (zoom) {
	/* WARNING - this doesn't cope with EPS Clip */
	*x = (float)((*x - display.zoom_xoffset) * option.zoom_xdpi / 72.0);
	*y = (float)((*y - display.zoom_yoffset) * option.zoom_ydpi / 72.0);
	*x = (float)(*x * 72.0 / option.xdpi);
	*y = (float)(*y * 72.0 / option.ydpi);
	itransform_point(x, y);
	*x = (float)((*x * option.xdpi / 72.0) - 
		bitmap.scrollx + display.offset.x);
	*y = (float)(-(*y * option.ydpi / 72.0) 
		+ (image.height-1 - bitmap.scrolly) 
		+ display.offset.y);
    }
    else {
	int xoffset = (int)(display.xoffset / display.xdpi * 72.0 + 0.5);
	int yoffset = (int)(display.yoffset / display.ydpi * 72.0 + 0.5);
	*x = *x - xoffset;
	*y = *y - yoffset;
	itransform_point(x, y);
	*x = (float)(*x * option.xdpi/72.0
	      - bitmap.scrollx + display.offset.x);
	*y = (float)(-(*y * option.ydpi/72.0)
	      + (image.height-1 - bitmap.scrolly) + display.offset.y);
    }
}

BOOL
get_cursorpos(float *x, float *y)
{
RECT rect;
POINT pt;
    if (image.open) {
	GetClientRect(hwnd_image, &rect);
	GetCursorPos(&pt);
	ScreenToClient(hwnd_image, &pt);
	if (PtInRect(&rect, pt)) {
	    *x = (float)(bitmap.scrollx+pt.x - display.offset.x);
	    *y = (float)(image.height-1 - 	
		(bitmap.scrolly+pt.y) + display.offset.y);
	    transform_cursorpos(x, y);
	    return TRUE;
	}
    }
    return FALSE;
}

void
cursorpos_paint(HDC hdc)
{
/* Not Unicode because wsprintf doesn't support floating point */
float x, y;
char buf[32];
char fmt[32];
COLORREF text_colour;
int digits = option.unitfine ? 2 : 0;
    request_mutex();
    SetBkMode(hdc, TRANSPARENT);
    text_colour = SetTextColor(hdc, GetSysColor(COLOR_MENUTEXT));
    FillRect(hdc, &info_coord, hbrush_menu);
    /* show coordinate */
    if (get_cursorpos(&x, &y)) {
	switch(option.unit) {
	   case IDM_UNITPT:   
	      sprintf(fmt, "%%.%df, %%.%dfpt", digits, digits);
	      sprintf(buf, fmt, x, y);
	      break;
	   case IDM_UNITMM:   
	      sprintf(fmt, "%%.%df, %%.%dfmm", digits, digits);
	      sprintf(buf, fmt, x/72*25.4, y/72*25.4);
	      break;
	   case IDM_UNITINCH:   
	      digits += 1;
	      sprintf(fmt, "%%.%df, %%.%dfin", digits, digits);
	      sprintf(buf, fmt, x/72, y/72);
	      break;
	}
	SetTextAlign(hdc, TA_RIGHT);
	TextOutA(hdc, info_coord.right-1, info_coord.top, buf, strlen(buf));
	SetTextColor(hdc, text_colour);
#ifndef VIEWONLY
	measure_paint(x, y);
#endif
    }
    release_mutex();
}

/* paint brief info area */
void
info_paint(HWND hwnd, HDC hdc)
{
RECT rect;
int i;
TCHAR buf[MAXSTR];
TCHAR fmt[MAXSTR];
TCHAR fname[MAXSTR];
HFONT old_hfont;
CDSC *dsc;
COLORREF text_colour;
    request_mutex();
    dsc = psfile.dsc;
    SetBkMode(hdc, TRANSPARENT);
    text_colour = SetTextColor(hdc, GetSysColor(COLOR_MENUTEXT));
    if (info_font)
	old_hfont = (HFONT)SelectObject(hdc, info_font);
    if (info_rect.bottom) {
	GetClientRect(hwnd, &rect);
	rect.top = info_rect.top;
	rect.left = info_rect.left;
	rect.bottom = info_rect.bottom;
	FillRect(hdc, &rect, hbrush_menu);
	SelectPen(hdc, hpen_btnshadow);
	MoveTo(hdc, rect.left, rect.bottom);
	LineTo(hdc, rect.right, rect.bottom);
	if (is_win4) {
	    SelectPen(hdc, hpen_btnshadow);
	    MoveTo(hdc, rect.left, rect.top);
	    LineTo(hdc, rect.right, rect.top);
	    SelectPen(hdc, hpen_btnhighlight);
	    MoveTo(hdc, rect.left, rect.top+1);
	    LineTo(hdc, rect.right, rect.top+1);
	}
    }
    /* write file information */
    if (psfile.name[0] != '\0') {
	i = load_string(IDS_FILE, buf, sizeof(buf)/sizeof(TCHAR));
	convert_multibyte(fname, psfile.name, sizeof(fname)/sizeof(TCHAR));
	i = GetFileTitle(fname, buf+i, (WORD)(sizeof(buf)/sizeof(TCHAR)-i));
	if (lstrlen(buf) > 36) {
	    memmove(buf+3, buf+lstrlen(buf)+1-32, 32*sizeof(TCHAR));
	    buf[0] = buf[1] = buf[2] = '.';
	}
	TextOut(hdc, info_file.x, info_file.y, buf, lstrlen(buf));
	if (szWait[0] != '\0') {
	    wsprintf(buf, szWait, percent_done);
	    TextOut(hdc, info_page.x, info_page.y, buf, lstrlen(buf));
	}
	else {
	  if (dsc!=(CDSC *)NULL) {
	    int n = map_page(psfile.pagenum - 1);
	    load_string(IDS_PAGEINFO, fmt, sizeof(fmt)/sizeof(TCHAR));
	    if (on_link) {
		if ((on_link_page == 0) && on_link_action[0]) {
		    convert_multibyte(buf, on_link_action, 
			    sizeof(buf)/sizeof(TCHAR)-1);
		}
		else {
		    load_string(IDS_LINKPAGE, fmt, sizeof(fmt)/sizeof(TCHAR));
		    wsprintf(buf, fmt, on_link_page);
		}
	    }
	    else {
		TCHAR lbuf[MAXSTR];
		if (dsc->page_count && dsc->page[n].label)
		    convert_multibyte(lbuf, dsc->page[n].label, 
			    sizeof(lbuf)/sizeof(TCHAR)-1);
		else
		    lstrcpy(lbuf, TEXT(" "));
		wsprintf(buf, fmt, lbuf ,psfile.pagenum, dsc->page_count);
	    }
	    if (zoom)
		load_string(IDS_ZOOMED, buf+lstrlen(buf), 
		sizeof(buf)/sizeof(TCHAR)-lstrlen(buf));
	    TextOut(hdc, info_page.x, info_page.y, buf, lstrlen(buf));
	  }
	  else {
	    if (gsdll.state == GS_IDLE)
		load_string(IDS_NOMORE, buf, sizeof(buf)/sizeof(TCHAR));
	    else {
		 load_string(IDS_PAGE, buf, sizeof(buf)/sizeof(TCHAR));
		wsprintf(buf+i, TEXT("%d"), psfile.pagenum);
	    }
	    TextOut(hdc, info_page.x, info_page.y, buf, lstrlen(buf));
	  }
	  /* show coordinate */
	  cursorpos_paint(hdc);
	}
    }
    else {
	load_string(IDS_NOFILE, buf, sizeof(buf)/sizeof(TCHAR));
	TextOut(hdc, info_file.x, info_file.y, buf, lstrlen(buf));
	if (szWait[0] != '\0') {
	    wsprintf(buf, szWait, percent_done);
	    TextOut(hdc, info_page.x, info_page.y, buf, lstrlen(buf));
	}
    }
    if (info_font)
	SelectObject(hdc, old_hfont);
    SetTextColor(hdc, text_colour);
    release_mutex();
}


HWND hbutton_info;

void
end_button_help(void)
{
    if (hbutton_info) {
	ReleaseCapture();
	hbutton_info = (HWND)NULL;
	SetFocus(hwndimg);
	InvalidateRect(hwndimg, &info_rect, FALSE);
	UpdateWindow(hwndimg);
    }
}

/* subclass button WndProc to give focus back to parent window */
LRESULT CALLBACK _export
MenuButtonProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message) {
	case WM_LBUTTONUP:
	    {
	    RECT rect;
	    POINT pt;
	    end_button_help();
	    GetWindowRect(hwnd, &rect);
	    GetCursorPos(&pt);
	    SetFocus(GetParent(hwnd));
	    if (PtInRect(&rect, pt))
		SendMessage(GetParent(hwnd), WM_COMMAND, GetWindowID(hwnd), 0L);
	    }
	    break;
	case WM_MOUSEMOVE:
	    {
		POINT pt;
	        HDC hdc; 
	        HFONT old_hfont;
		RECT rect;
		HWND hwnd_cursor;
		TCHAR buf[MAXSTR];
		if (GetActiveWindow() != hwndimg)
		    break;  /* ignore if GSview not the top window */
		GetCursorPos(&pt);
		hwnd_cursor = WindowFromPoint(pt);
		if (hwnd != hwnd_cursor) {
		    end_button_help();
		}
		else if (hbutton_info != hwnd) {
		    COLORREF text_colour;
		    hbutton_info = hwnd;
		    SetCapture(hwnd);
		    hdc = GetDC(hwndimg);
		    load_string(GetWindowID(hwnd), buf, sizeof(buf)/sizeof(TCHAR));
		    SetBkMode(hdc, TRANSPARENT);
		    text_colour = SetTextColor(hdc, GetSysColor(COLOR_MENUTEXT));
		    if (info_rect.bottom) {
			GetClientRect(hwnd, &rect);
			rect.top = info_rect.top+2;
			rect.left = info_rect.left;
			rect.bottom = info_rect.bottom-1;
			rect.right = info_rect.right;
			FillRect(hdc, &rect, hbrush_menu);
		    }
		    if (info_font)
			old_hfont = (HFONT)SelectObject(hdc, info_font);
		    TextOut(hdc, info_file.x, info_file.y, buf, lstrlen(buf));
		    if (info_font)
			SelectObject(hdc, old_hfon

⌨️ 快捷键说明

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