📄 colordlg16.c
字号:
/*
* COMMDLG - Color Dialog
*
* Copyright 1994 Martin Ayotte
* Copyright 1996 Albrecht Kleine
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* BUGS : still seems to not refresh correctly
sometimes, especially when 2 instances of the
dialog are loaded at the same time */
#include <ctype.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "wine/winbase16.h"
#include "wine/winuser16.h"
#include "winuser.h"
#include "commdlg.h"
#include "dlgs.h"
#include "wine/debug.h"
#include "cderr.h"
#include "cdlg.h"
#include "cdlg16.h"
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
/* Chose Color PRIVATE Structure:
*
* This is a duplicate of the 32bit code with
* an extra member
*/
typedef struct CCPRIVATE
{
LPCHOOSECOLORW lpcc; /* points to public known data structure */
LPCHOOSECOLOR16 lpcc16; /* save the 16 bits pointer */
int nextuserdef; /* next free place in user defined color array */
HDC hdcMem; /* color graph used for BitBlt() */
HBITMAP hbmMem; /* color graph bitmap */
RECT fullsize; /* original dialog window size */
UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
RECT old3angle; /* last position of l-marker */
RECT oldcross; /* last position of color/satuation marker */
BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
int h;
int s;
int l; /* for temporary storing of hue,sat,lum */
int capturedGraph; /* control mouse captured */
RECT focusRect; /* rectangle last focused item */
HWND hwndFocus; /* handle last focused item */
} *LCCPRIV;
/***********************************************************************
* CC_WMInitDialog16 [internal]
*/
static LONG CC_WMInitDialog16( HWND hDlg, WPARAM wParam, LPARAM lParam )
{
int i, res;
int r, g, b;
HWND hwnd;
RECT rect;
POINT point;
LCCPRIV lpp;
CHOOSECOLORW *ch32;
CHOOSECOLOR16 *ch16 = (CHOOSECOLOR16 *) lParam;
TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
lpp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct CCPRIVATE) );
if (ch16->lStructSize != sizeof(CHOOSECOLOR16) )
{
HeapFree(GetProcessHeap(), 0, lpp);
EndDialog (hDlg, 0) ;
return FALSE;
}
ch32 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CHOOSECOLORW) );
lpp->lpcc = ch32;
lpp->lpcc16 = ch16;
ch32->lStructSize = sizeof(CHOOSECOLORW);
ch32->hwndOwner = HWND_32(ch16->hwndOwner);
/* Should be an HINSTANCE but MS made a typo */
ch32->hInstance = HWND_32(ch16->hInstance);
ch32->lpCustColors = MapSL(ch16->lpCustColors);
ch32->lpfnHook = (LPCCHOOKPROC) ch16->lpfnHook; /* only used as flag */
ch32->Flags = ch16->Flags;
SetWindowLongPtrW(hDlg, DWLP_USER, (LONG_PTR)lpp);
if (!(lpp->lpcc->Flags & CC_SHOWHELP))
ShowWindow( GetDlgItem(hDlg,0x40e), SW_HIDE);
lpp->msetrgb = RegisterWindowMessageA(SETRGBSTRINGA);
#if 0
cpos = MAKELONG(5,7); /* init */
if (lpp->lpcc->Flags & CC_RGBINIT)
{
for (i = 0; i < 6; i++)
for (j = 0; j < 8; j++)
if (predefcolors[i][j] == lpp->lpcc->rgbResult)
{
cpos = MAKELONG(i,j);
goto found;
}
}
found:
/* FIXME: Draw_a_focus_rect & set_init_values */
#endif
GetWindowRect(hDlg, &lpp->fullsize);
if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
{
hwnd = GetDlgItem(hDlg, 0x2cf);
EnableWindow(hwnd, FALSE);
}
if (!(lpp->lpcc->Flags & CC_FULLOPEN ) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
{
rect = lpp->fullsize;
res = rect.bottom - rect.top;
hwnd = GetDlgItem(hDlg, 0x2c6); /* cut at left border */
point.x = point.y = 0;
ClientToScreen(hwnd, &point);
ScreenToClient(hDlg,&point);
GetClientRect(hDlg, &rect);
point.x += GetSystemMetrics(SM_CXDLGFRAME);
SetWindowPos(hDlg, 0, 0, 0, point.x, res, SWP_NOMOVE|SWP_NOZORDER);
for (i = 0x2bf; i < 0x2c5; i++)
ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
for (i = 0x2d3; i < 0x2d9; i++)
ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_HIDE);
ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_HIDE);
ShowWindow( GetDlgItem(hDlg, 0x2c6), SW_HIDE);
ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_HIDE);
ShowWindow( GetDlgItem(hDlg, 1090 ), SW_HIDE);
}
else
CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, NULL);
res = TRUE;
for (i = 0x2bf; i < 0x2c5; i++)
SendMessageA( GetDlgItem(hDlg, i), EM_LIMITTEXT, 3, 0); /* max 3 digits: xyz */
if (CC_HookCallChk(lpp->lpcc))
{
res = CallWindowProc16( (WNDPROC16)lpp->lpcc16->lpfnHook,
HWND_16(hDlg), WM_INITDIALOG, wParam, lParam);
}
/* Set the initial values of the color chooser dialog */
r = GetRValue(lpp->lpcc->rgbResult);
g = GetGValue(lpp->lpcc->rgbResult);
b = GetBValue(lpp->lpcc->rgbResult);
CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
lpp->h = CC_RGBtoHSL('H', r, g, b);
lpp->s = CC_RGBtoHSL('S', r, g, b);
lpp->l = CC_RGBtoHSL('L', r, g, b);
/* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
SetDlgItemInt(hDlg, 703, lpp->h, TRUE);
SetDlgItemInt(hDlg, 704, lpp->s, TRUE);
SetDlgItemInt(hDlg, 705, lpp->l, TRUE);
SetDlgItemInt(hDlg, 706, r, TRUE);
SetDlgItemInt(hDlg, 707, g, TRUE);
SetDlgItemInt(hDlg, 708, b, TRUE);
CC_PaintCross(hDlg, lpp->h, lpp->s);
CC_PaintTriangle(hDlg, lpp->l);
return res;
}
/***********************************************************************
* CC_WMCommand16 [internal]
*/
static LRESULT CC_WMCommand16( HWND hDlg, WPARAM wParam, LPARAM lParam, WORD notifyCode, HWND hwndCtl )
{
int r, g, b, i, xx;
UINT cokmsg;
HDC hdc;
COLORREF *cr;
LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
TRACE("CC_WMCommand wParam=%lx lParam=%lx\n", wParam, lParam);
switch (wParam)
{
case 0x2c2: /* edit notify RGB */
case 0x2c3:
case 0x2c4:
if (notifyCode == EN_UPDATE && !lpp->updating)
{
i = CC_CheckDigitsInEdit(hwndCtl, 255);
r = GetRValue(lpp->lpcc->rgbResult);
g = GetGValue(lpp->lpcc->rgbResult);
b= GetBValue(lpp->lpcc->rgbResult);
xx = 0;
switch (wParam)
{
case 0x2c2: if ((xx = (i != r))) r = i; break;
case 0x2c3: if ((xx = (i != g))) g = i; break;
case 0x2c4: if ((xx = (i != b))) b = i; break;
}
if (xx) /* something has changed */
{
lpp->lpcc->rgbResult = RGB(r, g, b);
CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
lpp->h = CC_RGBtoHSL('H', r, g, b);
lpp->s = CC_RGBtoHSL('S', r, g, b);
lpp->l = CC_RGBtoHSL('L', r, g, b);
CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
CC_PaintCross(hDlg, lpp->h, lpp->s);
CC_PaintTriangle(hDlg, lpp->l);
}
}
break;
case 0x2bf: /* edit notify HSL */
case 0x2c0:
case 0x2c1:
if (notifyCode == EN_UPDATE && !lpp->updating)
{
i = CC_CheckDigitsInEdit(hwndCtl , wParam == 0x2bf ? 239:240);
xx = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -