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

📄 gtkappbar.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * purple - WinPurple Options Plugin * * File: gtkappbar.c * Date: August 2, 2003 * Description: Appbar functionality for Windows GTK+ applications * * Copyright (C) 2003, Herman Bloggs <hermanator12002@yahoo.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * *//* *  TODO: *  - Move 'App on top' feature from Trans plugin to here *  - Bug: Multiple Show/Hide Desktop calls causes client area to disappear */#include <windows.h>#include <winver.h>#include <stdio.h>#include <gtk/gtk.h>#include <gdk/gdkwin32.h>#include "gtkappbar.h"#include "debug.h"#define APPBAR_CALLBACK 	WM_USER + 1010typedef HMONITOR WINAPI purple_MonitorFromPoint(POINT, DWORD);typedef HMONITOR WINAPI purple_MonitorFromWindow(HWND, DWORD);typedef BOOL WINAPI purple_GetMonitorInfo(HMONITOR, LPMONITORINFO);/* Retrieve the rectangular display area from the specified monitor * Return TRUE if successful, otherwise FALSE */static gbooleanget_rect_from_monitor(HMODULE hmod, HMONITOR monitor, RECT *rect) {	purple_GetMonitorInfo *the_GetMonitorInfo;	MONITORINFO info;	if (!(the_GetMonitorInfo = (purple_GetMonitorInfo*)		GetProcAddress(hmod, "GetMonitorInfoA"))) {		return FALSE;	}	info.cbSize = sizeof(info);	if (!the_GetMonitorInfo(monitor, &info)) {		return FALSE;	}	CopyRect(rect, &(info.rcMonitor));	return TRUE;}/** * This will only work on Win98+ and Win2K+ * Return TRUE if successful, otherwise FALSE */static gbooleanget_rect_at_point_multimonitor(POINT pt, RECT *rect) {	HMODULE hmod;	purple_MonitorFromPoint *the_MonitorFromPoint;	HMONITOR monitor;	if (!(hmod = GetModuleHandle("user32"))) {		return FALSE;	}	if (!(the_MonitorFromPoint = (purple_MonitorFromPoint*)		GetProcAddress(hmod, "MonitorFromPoint"))) {		return FALSE;	}	monitor =		the_MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);	return get_rect_from_monitor(hmod, monitor, rect);}/** * This will only work on Win98+ and Win2K+ * Return TRUE if successful, otherwise FALSE */static gbooleanget_rect_of_window_multimonitor(HWND window, RECT *rect) {	HMODULE hmod;	purple_MonitorFromWindow *the_MonitorFromWindow;	HMONITOR monitor;	if (!(hmod = GetModuleHandle("user32"))) {		return FALSE;	}	if (!(the_MonitorFromWindow = (purple_MonitorFromWindow*)		GetProcAddress(hmod, "MonitorFromWindow"))) {		return FALSE;	}	monitor =		the_MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY);	return get_rect_from_monitor(hmod, monitor, rect);}/* * Fallback if cannot get the RECT from the monitor directly */static void get_default_workarea(RECT *rect) {	if (!SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, FALSE)) {		/* I don't think this will ever happen */		rect->left = 0;		rect->top = 0;		rect->bottom = GetSystemMetrics(SM_CYSCREEN);		rect->right = GetSystemMetrics(SM_CXSCREEN);	}}/* Retrieve the rectangle of the active work area at a point */static void get_rect_at_point(POINT pt, RECT *rc) {	if (!get_rect_at_point_multimonitor(pt, rc)) {		get_default_workarea(rc);	}}/* Retrieve the rectangle of the active work area of a window*/static void get_rect_of_window(HWND window, RECT *rc) {	if (!get_rect_of_window_multimonitor(window, rc)) {		get_default_workarea(rc);	}}static void get_window_normal_rc(HWND hwnd, RECT *rc) {         WINDOWPLACEMENT wplc;         GetWindowPlacement(hwnd, &wplc);         CopyRect(rc, &wplc.rcNormalPosition);}#if 0static void print_rect(RECT *rc) {        purple_debug(PURPLE_DEBUG_INFO, "gtkappbar", "RECT: L:%ld R:%ld T:%ld B:%ld\n",                   rc->left, rc->right, rc->top, rc->bottom);}#endif/** Set the window style to be the "Tool Window" style - small header, no min/max buttons */static void set_toolbar(HWND hwnd, gboolean val) {	LONG style=0;        style = GetWindowLong(hwnd, GWL_EXSTYLE);        if(val && !(style & WS_EX_TOOLWINDOW))                style |= WS_EX_TOOLWINDOW;        else if(!val && style & WS_EX_TOOLWINDOW)                style &= ~WS_EX_TOOLWINDOW;        else                return;        SetWindowLong(hwnd, GWL_EXSTYLE, style);	SetWindowPos(hwnd, 0, 0, 0, 0, 0,		SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);	/*	This really should be the following, but SWP_FRAMECHANGED strangely causes initermittent problems "Show Desktop" done more than once. *	Not having SWP_FRAMECHANGED *should* cause the Style not to be applied, but i haven't noticed any problems *			SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); */}/** Register the window as an appbar */static gboolean gtk_appbar_register(GtkAppBar *ab, HWND hwnd) {	APPBARDATA abd;	abd.cbSize = sizeof(APPBARDATA);	abd.hWnd = hwnd;	abd.uCallbackMessage = APPBAR_CALLBACK;	ab->registered = SHAppBarMessage(ABM_NEW, &abd);	return ab->registered;}/** Unregister the window as an appbar */static gboolean gtk_appbar_unregister(GtkAppBar *ab, HWND hwnd) {	APPBARDATA abd;        if(!ab->registered)                return TRUE;	abd.cbSize = sizeof(APPBARDATA);	abd.hWnd = hwnd;	SHAppBarMessage(ABM_REMOVE, &abd); /** This always returns TRUE */	ab->registered = FALSE;	ab->docked = FALSE;	ab->docking = FALSE;	return TRUE;}static void gtk_appbar_querypos(GtkAppBar *ab, HWND hwnd, RECT rcWorkspace) {	APPBARDATA abd;	guint iWidth = 0;	if(!ab->registered)		gtk_appbar_register(ab, hwnd);	abd.hWnd = hwnd;	abd.cbSize = sizeof(APPBARDATA);	abd.uEdge = ab->side;	iWidth = ab->docked_rect.right - ab->docked_rect.left;	abd.rc.top = rcWorkspace.top;	abd.rc.bottom = rcWorkspace.bottom;	switch (abd.uEdge)	{		case ABE_LEFT:			abd.rc.left = rcWorkspace.left;			abd.rc.right = rcWorkspace.left + iWidth;			break;		case ABE_RIGHT:			abd.rc.right = rcWorkspace.right;			abd.rc.left = rcWorkspace.right - iWidth;			break;	}        /* Ask the system for the screen space */	SHAppBarMessage(ABM_QUERYPOS, &abd);	switch (abd.uEdge)	{		case ABE_LEFT:                        abd.rc.right = abd.rc.left + iWidth;			break;		case ABE_RIGHT:			abd.rc.left = abd.rc.right - iWidth;			break;	}	CopyRect(&(ab->docked_rect), &abd.rc);}/* Actually set the size and screen location of the appbar */static void gtk_appbar_setpos(GtkAppBar *ab, HWND hwnd) {        APPBARDATA abd;        if(!ab->registered)                gtk_appbar_register(ab, hwnd);	abd.hWnd = hwnd;	abd.cbSize = sizeof(APPBARDATA);        CopyRect(&abd.rc, &(ab->docked_rect));	abd.uEdge = ab->side;	SHAppBarMessage(ABM_SETPOS, &abd);}/** Let any callbacks know that we have docked or undocked */static void gtk_appbar_dispatch_dock_cbs(GtkAppBar *ab, gboolean val) {        GList *lst = ab->dock_cbs;        while(lst) {                GtkAppBarDockCB dock_cb = lst->data;                dock_cb(val);                lst = lst->next;        }}static GdkFilterReturn wnd_moving(GtkAppBar *ab, GdkXEvent *xevent) {        MSG *msg = (MSG*)xevent;        POINT cp;        RECT *rc = (RECT*)msg->lParam;	RECT monRect;        int side = -1;	long dockAreaWidth = 0;        purple_debug(PURPLE_DEBUG_INFO, "gtkappbar", "wnd_moving\n");        GetCursorPos(&cp);	get_rect_at_point(cp, &monRect);	dockAreaWidth = (monRect.right - monRect.left) / 10;        /* Which part of the screen are we in ? */	if (cp.x > (monRect.right - dockAreaWidth)) {                side = ABE_RIGHT;	} else if (cp.x < (monRect.left + dockAreaWidth)) {                side = ABE_LEFT;	}        if(!ab->docked) {                if( (side == ABE_RIGHT || side == ABE_LEFT) ) {                        if( !ab->docking ) {                                ab->side = side;                                GetWindowRect(msg->hwnd, &(ab->docked_rect));				gtk_appbar_querypos(ab, msg->hwnd, monRect);                                /* save pre-docking height */                                ab->undocked_height = rc->bottom - rc->top;                                ab->docking = TRUE;                        }                }                else                        ab->docking = FALSE;        }        else if(side < 0) {                gtk_appbar_unregister(ab, msg->hwnd);                rc->bottom = rc->top + ab->undocked_height;        }        /* Switch to toolbar/regular caption*/        if(ab->docking)                set_toolbar(msg->hwnd, TRUE);        else if(!ab->docked)                set_toolbar(msg->hwnd, FALSE);

⌨️ 快捷键说明

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