static INT_PTR CALLBACK Window_CalendarColorConfigDlg(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam){ switch(msg){ case WM_INITDIALOG:{ ColorBox colors[6]; HWND calendar = GetDlgItem(hDlg, IDC_CAL_PREVIEW); HWND preset_cb = GetDlgItem(hDlg, IDC_CAL_PRESET); int idx; m_calendar_dirty = 0; for(idx=0; idx<GROUP_CALENDAR_COLOR_NUM; ++idx){ unsigned color_id = GROUP_CALENDAR_COLOR + (idx * 2); colors[idx].hwnd = GetDlgItem(hDlg, color_id); colors[idx].color = api.GetInt(L"Calendar", g_calendar_color[idx].reg, TCOLOR(TCOLOR_DEFAULT)); m_calendar_preset[0].color[idx] = (COLORREF)MonthCal_GetColor(calendar, g_calendar_color[idx].mcsc); if(colors[idx].color != TCOLOR(TCOLOR_DEFAULT)){ m_calendar_dirty |= (1<<idx); MonthCal_SetColor(calendar, g_calendar_color[idx].mcsc, api.GetColor(colors[idx].color,0)); } } ColorBox_Setup(colors, 6); for(idx=0; idx<CALENDAR_PRESETS; ++idx) ComboBox_AddString(preset_cb, m_calendar_preset[idx].name); ComboBox_AddString(preset_cb, L"custom colors"); m_calendar_dirty ^= 1; // toggle bit to force refresh SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDC_CAL_OUTER,CBN_SELCHANGE), (LPARAM)GetDlgItem(hDlg,IDC_CAL_OUTER)); return TRUE;} case WM_MEASUREITEM: return ColorBox_OnMeasureItem(wParam, lParam); case WM_DRAWITEM: return ColorBox_OnDrawItem(wParam, lParam); case WM_COMMAND:{ unsigned control_id = LOWORD(wParam); unsigned control_notify = HIWORD(wParam); switch(control_id){ case IDC_CAL_PREVIEW: break; case IDC_CAL_PRESET:{ HWND calendar = GetDlgItem(hDlg, IDC_CAL_PREVIEW); HWND preset_cb = GetDlgItem(hDlg, IDC_CAL_PRESET); int preset = ComboBox_GetCurSel(preset_cb); int idx; if(preset == CALENDAR_PRESETS) break; for(idx=0; idx<GROUP_CALENDAR_COLOR_NUM; ++idx){ unsigned color_id = GROUP_CALENDAR_COLOR + (idx * 2); HWND color_cb = GetDlgItem(hDlg, color_id); if(preset == 0) ColorBox_SetColor(color_cb, TCOLOR(TCOLOR_DEFAULT)); else ColorBox_SetColor(color_cb, m_calendar_preset[preset].color[idx]); MonthCal_SetColor(calendar, g_calendar_color[idx].mcsc, api.GetColor(m_calendar_preset[preset].color[idx],0)); } if(preset == 0) m_calendar_dirty = 0; else m_calendar_dirty = 0x01|0x02|0x04|0x08|0x10|0x20; SetXPWindowTheme(GetDlgItem(hDlg,IDC_CAL_PREVIEW), NULL, (m_calendar_dirty ? L"" : NULL)); break;} case IDC_CAL_OUTER: case IDC_CAL_FORE: case IDC_CAL_BACK: case IDC_CAL_TITLE: case IDC_CAL_TITLE_BG: case IDC_CAL_TRAIL: if(control_notify == CBN_SELCHANGE){ unsigned id = (control_id - GROUP_CALENDAR_COLOR) / 2; unsigned color = ColorBox_GetColorRaw((HWND)lParam); char dirty = m_calendar_dirty; if(color == TCOLOR(TCOLOR_DEFAULT)) dirty &= ~(1<<id); else dirty |= 1<<id; if(dirty != m_calendar_dirty){ m_calendar_dirty = dirty; SetXPWindowTheme(GetDlgItem(hDlg,IDC_CAL_PREVIEW), NULL, (dirty&~1 ? L"" : NULL)); } ComboBox_SetCurSel(GetDlgItem(hDlg,IDC_CAL_PRESET), (dirty ? CALENDAR_PRESETS : 0)); if(color == TCOLOR(TCOLOR_DEFAULT)) color = m_calendar_preset[0].color[id]; else color = api.GetColor(color, 0); MonthCal_SetColor(GetDlgItem(hDlg,IDC_CAL_PREVIEW), g_calendar_color[id].mcsc, color); } break; case IDOK: {int idx; for(idx=0; idx<GROUP_CALENDAR_COLOR_NUM; ++idx){ unsigned color_id = GROUP_CALENDAR_COLOR + (idx * 2); HWND color_cb = GetDlgItem(hDlg, color_id); api.SetInt(L"Calendar", g_calendar_color[idx].reg, ColorBox_GetColorRaw(color_cb)); }} /* fall through */ case IDCANCEL: EndDialog(hDlg, control_id); break; default: ColorBox_ChooseColor((HWND)lParam); } return TRUE;} } return FALSE; }
/*------------------------------------------------ Dialog procedure --------------------------------------------------*/ INT_PTR CALLBACK Page_Color(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: OnInit(hDlg); return TRUE; case WM_DESTROY:{ HFONT hfontb=(HFONT)SendDlgItemMessage(hDlg,IDC_BOLD,WM_GETFONT,0,0); HFONT hfonti=(HFONT)SendDlgItemMessage(hDlg,IDC_ITALIC,WM_GETFONT,0,0); SendDlgItemMessage(hDlg,IDC_BOLD,WM_SETFONT,0,0); SendDlgItemMessage(hDlg,IDC_ITALIC,WM_SETFONT,0,0); DeleteObject(hfontb); DeleteObject(hfonti); break;} case WM_MEASUREITEM: return ColorBox_OnMeasureItem(wParam, lParam); case WM_DRAWITEM: return ColorBox_OnDrawItem(wParam, lParam); case WM_COMMAND: { WORD id=LOWORD(wParam); switch(HIWORD(wParam)){ case CBN_SELCHANGE: if(id==IDC_COLFORE || id==IDC_COLBACK || id==IDC_FONT || id==IDC_FONTQUAL || id==IDC_FONTSIZE){ if(id==IDC_FONT) SetComboFontSize(hDlg, FALSE); SendPSChanged(hDlg); } break; case CBN_EDITCHANGE: if(id==IDC_FONTSIZE) SendPSChanged(hDlg); break; case EN_CHANGE: if(id==IDC_CLOCKHEIGHT || id==IDC_CLOCKWIDTH || id==IDC_ALPHATB || id==IDC_VERTPOS || id==IDC_LINEHEIGHT || id==IDC_HORIZPOS || id==IDC_ANGLE){ SendPSChanged(hDlg); } break; default: if(id==IDC_COLFORE_BTN || id==IDC_COLBACK_BTN){ ColorBox_ChooseColor((HWND)lParam); }else if(id==IDC_CHOOSEFONT){ HWND hwndCombo; HDC hdc; wchar_t size[8]; LOGFONT lf = {0}; CHOOSEFONT chosenfont = {sizeof(CHOOSEFONT)}; chosenfont.hwndOwner = hDlg; chosenfont.Flags = CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT | CF_PRINTERFONTS | CF_SCREENFONTS; chosenfont.lpLogFont = &lf; hwndCombo = GetDlgItem(hDlg,IDC_FONTSIZE); ComboBox_GetText(hwndCombo, size, _countof(size)); hdc = GetDC(NULL); lf.lfWeight = IsDlgButtonChecked(hDlg, IDC_BOLD) ? FW_BOLD : FW_REGULAR; lf.lfItalic = (BYTE)IsDlgButtonChecked(hDlg, IDC_ITALIC); lf.lfHeight = -MulDiv(_wtoi(size), GetDeviceCaps(hdc,LOGPIXELSY), 72); ReleaseDC(NULL, hdc); hwndCombo = GetDlgItem(hDlg,IDC_FONT); ComboBox_GetText(hwndCombo, lf.lfFaceName, _countof(lf.lfFaceName)); if(ChooseFont(&chosenfont)){ int sel; CheckDlgButton(hDlg, IDC_BOLD, (chosenfont.lpLogFont->lfWeight >= FW_SEMIBOLD)); CheckDlgButton(hDlg, IDC_ITALIC, chosenfont.lpLogFont->lfItalic); ComboBox_SelectString(hwndCombo, -1, chosenfont.lpLogFont->lfFaceName); hwndCombo = GetDlgItem(hDlg,IDC_FONTSIZE); wsprintf(size, FMT("%d"), chosenfont.iPointSize/10); sel = ComboBox_FindStringExact(hwndCombo, -1, size); if(sel != CB_ERR) ComboBox_SetCurSel(hwndCombo, sel); else ComboBox_SetText(hwndCombo, size); SendPSChanged(hDlg); } }else if(id==IDC_BOLD || id==IDC_ITALIC) SendPSChanged(hDlg); } return TRUE;} case WM_NOTIFY:{ PSHNOTIFY* notify=(PSHNOTIFY*)lParam; switch(notify->hdr.code) { case PSN_APPLY: OnApply(hDlg,0); if(notify->lParam) m_transition=-1; break; case PSN_RESET: if(m_transition==1){ SendMessage(g_hwndClock, CLOCKM_REFRESHCLOCK, 0, 0); SendMessage(g_hwndClock, CLOCKM_REFRESHTASKBAR, 0, 0); api.DelKey(L"Preview"); } m_transition=-1; break; } return TRUE;} } return FALSE; }