static void sttPreviewSkin(MODERNOPTOBJECT *obj, TCHAR *fn, LPDRAWITEMSTRUCT lps) { if (!fn) return; if (ProtoServiceExists(obj->lpzThemeModuleName, TS_SKIN_PREVIEW)) { CallProtoService(obj->lpzThemeModuleName, TS_SKIN_PREVIEW, (WPARAM)lps, (LPARAM)fn); return; } HBITMAP hbmPreview = Bitmap_Load(CMString(fn) + _T(".png")); if (!hbmPreview) return; BITMAP bmp; GetObject(hbmPreview, sizeof(bmp), &bmp); SIZE szDst = { abs(bmp.bmWidth), abs(bmp.bmHeight) }; if ((szDst.cx > lps->rcItem.right - lps->rcItem.left) || (szDst.cy > lps->rcItem.bottom - lps->rcItem.top)) { float q = min( float(lps->rcItem.right - lps->rcItem.left) / szDst.cx, float(lps->rcItem.bottom - lps->rcItem.top) / szDst.cy); szDst.cx *= q; szDst.cy *= q; } POINT ptDst = { (lps->rcItem.left + lps->rcItem.right - szDst.cx) / 2, (lps->rcItem.top + lps->rcItem.bottom - szDst.cy) / 2 }; HDC hdc = CreateCompatibleDC(lps->hDC); SelectObject(hdc, hbmPreview); SetStretchBltMode(hdc, HALFTONE); StretchBlt(lps->hDC, ptDst.x, ptDst.y, szDst.cx, szDst.cy, hdc, 0, 0, abs(bmp.bmWidth), abs(bmp.bmHeight), SRCCOPY); DeleteDC(hdc); DeleteObject(hbmPreview); }
static void CreateBackgroundBrush() { bkColor = db_get_dw(NULL, MODULE, "BkColor", FLT_DEFAULT_BKGNDCOLOR); if (NULL != hLTEdgesPen) { DeleteObject(hLTEdgesPen); hLTEdgesPen = NULL; } if (NULL != hRBEdgesPen) { DeleteObject(hRBEdgesPen); hRBEdgesPen = NULL; } if (NULL != hBmpBackground) { DeleteObject(hBmpBackground); hBmpBackground = NULL; } if (NULL != hBkBrush) { SetClassLong((HWND)WND_CLASS, GCLP_HBRBACKGROUND, (LONG)NULL); DeleteObject(hBkBrush); hBkBrush = NULL; } if (db_get_b(NULL, MODULE, "DrawBorder", FLT_DEFAULT_DRAWBORDER)) { COLORREF cr = (COLORREF)db_get_dw(NULL, MODULE, "LTEdgesColor", FLT_DEFAULT_LTEDGESCOLOR); hLTEdgesPen = CreatePen(PS_SOLID, 1, cr); cr = (COLORREF)db_get_dw(NULL, MODULE, "RBEdgesColor", FLT_DEFAULT_RBEDGESCOLOR); hRBEdgesPen = CreatePen(PS_SOLID, 1, cr); } if (db_get_b(NULL, MODULE, "BkUseBitmap", FLT_DEFAULT_BKGNDUSEBITMAP)) { ptrT tszBitmapName(db_get_tsa(NULL, MODULE, "BkBitmap")); if (tszBitmapName != NULL) hBmpBackground = Bitmap_Load(tszBitmapName); } nBackgroundBmpUse = (WORD)db_get_w(NULL, MODULE, "BkBitmapOpt", FLT_DEFAULT_BKGNDBITMAPOPT); // Create brush hBkBrush = CreateSolidBrush(bkColor); // Attach brush to the window SetClassLongPtr((HWND)WND_CLASS, GCLP_HBRBACKGROUND, (LONG_PTR)hBkBrush); }
static int ehhEventAreaBackgroundSettingsChanged(WPARAM, LPARAM) { if (event_area.hBmpBackground) { DeleteObject(event_area.hBmpBackground); event_area.hBmpBackground = nullptr; } if (g_CluiData.fDisableSkinEngine) { event_area.bkColour = cliGetColor("EventArea", "BkColour", CLCDEFAULT_BKCOLOUR); if (db_get_b(0, "EventArea", "UseBitmap", CLCDEFAULT_USEBITMAP)) { ptrW tszBitmap(db_get_wsa(0, "EventArea", "BkBitmap")); if (tszBitmap != nullptr) event_area.hBmpBackground = Bitmap_Load(tszBitmap); } event_area.useWinColors = db_get_b(0, "EventArea", "UseWinColours", CLCDEFAULT_USEWINDOWSCOLOURS); event_area.backgroundBmpUse = db_get_w(0, "EventArea", "BkBmpUse", CLCDEFAULT_BKBMPUSE); } PostMessage(g_clistApi.hwndContactList, WM_SIZE, 0, 0); return 0; }
int LoadBackgroundOptions() { bkColour = db_get_dw(NULL, TTB_OPTDIR, "BkColour", TTBDEFAULT_BKCOLOUR); if (hBmpBackground) { DeleteObject(hBmpBackground); hBmpBackground = NULL; } if (db_get_b(NULL, TTB_OPTDIR, "UseBitmap", TTBDEFAULT_USEBITMAP)) { ptrT tszBitmapName(db_get_tsa(NULL, TTB_OPTDIR, "BkBitmap")); if (tszBitmapName != NULL) hBmpBackground = Bitmap_Load(tszBitmapName); } backgroundBmpUse = db_get_w(NULL, TTB_OPTDIR, "BkBmpUse", TTBDEFAULT_BKBMPUSE); RECT rc; GetClientRect(g_ctrl->hWnd, &rc); InvalidateRect(g_ctrl->hWnd, &rc, TRUE); UpdateWindow(g_ctrl->hWnd); return 0; }
void LoadCLCOptions(HWND hwnd, ClcData *dat, BOOL bFirst) { g_CluiData.fDisableSkinEngine = db_get_b(NULL, "ModernData", "DisableEngine", SETTING_DISABLESKIN_DEFAULT); LoadCLCFonts(hwnd, dat); g_CluiData.bSortByOrder[0] = db_get_b(NULL, "CList", "SortBy1", SETTING_SORTBY1_DEFAULT); g_CluiData.bSortByOrder[1] = db_get_b(NULL, "CList", "SortBy2", SETTING_SORTBY2_DEFAULT); g_CluiData.bSortByOrder[2] = db_get_b(NULL, "CList", "SortBy3", SETTING_SORTBY3_DEFAULT); g_CluiData.fSortNoOfflineBottom = db_get_b(NULL, "CList", "NoOfflineBottom", SETTING_NOOFFLINEBOTTOM_DEFAULT); // Row dat->row_min_heigh = db_get_w(NULL, "CList", "MinRowHeight", CLCDEFAULT_ROWHEIGHT); dat->row_border = db_get_w(NULL, "CList", "RowBorder", SETTING_ROWBORDER_DEFAULT); dat->row_before_group_space = ((hwnd != pcli->hwndContactTree && pcli->hwndContactTree != NULL) || !db_get_b(NULL, "ModernData", "UseAdvancedRowLayout", SETTING_ROW_ADVANCEDLAYOUT_DEFAULT)) ? 0 : db_get_w(NULL, "ModernSkin", "SpaceBeforeGroup", SKIN_SPACEBEFOREGROUP_DEFAULT); dat->row_variable_height = db_get_b(NULL, "CList", "VariableRowHeight", SETTING_VARIABLEROWHEIGHT_DEFAULT); dat->row_align_left_items_to_left = db_get_b(NULL, "CList", "AlignLeftItemsToLeft", SETTING_ALIGNLEFTTOLEFT_DEFAULT); dat->row_hide_group_icon = db_get_b(NULL, "CList", "HideGroupsIcon", SETTING_HIDEGROUPSICON_DEFAULT); dat->row_align_right_items_to_right = db_get_b(NULL, "CList", "AlignRightItemsToRight", SETTING_ALIGNRIGHTORIGHT_DEFAULT); //TODO: Add to settings dat->row_align_group_mode = db_get_b(NULL, "CList", "AlignGroupCaptions", SETTING_ALIGNGROPCAPTION_DEFAULT); if (pcli->hwndContactTree == NULL || dat->hWnd == pcli->hwndContactTree) { int defItemsOrder[NUM_ITEM_TYPE] = SETTINS_ROWITEMORDER_DEFAULT; for (int i = 0; i < NUM_ITEM_TYPE; i++) { char tmp[128]; mir_snprintf(tmp, "RowPos%d", i); dat->row_items[i] = db_get_w(NULL, "CList", tmp, defItemsOrder[i]); } } else { int defItems[] = { ITEM_ICON, ITEM_TEXT, ITEM_EXTRA_ICONS, }; for (int i = 0; i < NUM_ITEM_TYPE; i++) dat->row_items[i] = (i < _countof(defItems)) ? defItems[i] : -1; } // Avatar if (pcli->hwndContactTree == hwnd || pcli->hwndContactTree == NULL) { dat->avatars_show = db_get_b(NULL, "CList", "AvatarsShow", SETTINGS_SHOWAVATARS_DEFAULT); dat->avatars_draw_border = db_get_b(NULL, "CList", "AvatarsDrawBorders", SETTINGS_AVATARDRAWBORDER_DEFAULT); dat->avatars_border_color = (COLORREF)db_get_dw(NULL, "CList", "AvatarsBorderColor", SETTINGS_AVATARBORDERCOLOR_DEFAULT); dat->avatars_round_corners = db_get_b(NULL, "CList", "AvatarsRoundCorners", SETTINGS_AVATARROUNDCORNERS_DEFAULT); dat->avatars_use_custom_corner_size = db_get_b(NULL, "CList", "AvatarsUseCustomCornerSize", SETTINGS_AVATARUSECUTOMCORNERSIZE_DEFAULT); dat->avatars_custom_corner_size = db_get_w(NULL, "CList", "AvatarsCustomCornerSize", SETTINGS_AVATARCORNERSIZE_DEFAULT); dat->avatars_ignore_size_for_row_height = db_get_b(NULL, "CList", "AvatarsIgnoreSizeForRow", SETTINGS_AVATARIGNORESIZEFORROW_DEFAULT); dat->avatars_draw_overlay = db_get_b(NULL, "CList", "AvatarsDrawOverlay", SETTINGS_AVATARDRAWOVERLAY_DEFAULT); dat->avatars_overlay_type = db_get_b(NULL, "CList", "AvatarsOverlayType", SETTINGS_AVATAROVERLAYTYPE_DEFAULT); dat->avatars_maxheight_size = db_get_w(NULL, "CList", "AvatarsSize", SETTING_AVATARHEIGHT_DEFAULT); dat->avatars_maxwidth_size = db_get_w(NULL, "CList", "AvatarsWidth", SETTING_AVATARWIDTH_DEFAULT); } else { dat->avatars_show = 0; dat->avatars_draw_border = 0; dat->avatars_border_color = 0; dat->avatars_round_corners = 0; dat->avatars_use_custom_corner_size = 0; dat->avatars_custom_corner_size = 4; dat->avatars_ignore_size_for_row_height = 0; dat->avatars_draw_overlay = 0; dat->avatars_overlay_type = SETTING_AVATAR_OVERLAY_TYPE_NORMAL; dat->avatars_maxheight_size = 30; dat->avatars_maxwidth_size = 0; } // Icon if (pcli->hwndContactTree == hwnd || pcli->hwndContactTree == NULL) { dat->icon_hide_on_avatar = db_get_b(NULL, "CList", "IconHideOnAvatar", SETTING_HIDEICONONAVATAR_DEFAULT); dat->icon_draw_on_avatar_space = db_get_b(NULL, "CList", "IconDrawOnAvatarSpace", SETTING_ICONONAVATARPLACE_DEFAULT); dat->icon_ignore_size_for_row_height = db_get_b(NULL, "CList", "IconIgnoreSizeForRownHeight", SETTING_ICONIGNORESIZE_DEFAULT); } else { dat->icon_hide_on_avatar = 0; dat->icon_draw_on_avatar_space = 0; dat->icon_ignore_size_for_row_height = 0; } // Contact time if (pcli->hwndContactTree == hwnd || pcli->hwndContactTree == NULL) { dat->contact_time_show = db_get_b(NULL, "CList", "ContactTimeShow", SETTING_SHOWTIME_DEFAULT); dat->contact_time_show_only_if_different = db_get_b(NULL, "CList", "ContactTimeShowOnlyIfDifferent", SETTING_SHOWTIMEIFDIFF_DEFAULT); } else { dat->contact_time_show = 0; dat->contact_time_show_only_if_different = 0; } // Text dat->text_rtl = db_get_b(NULL, "CList", "TextRTL", SETTING_TEXT_RTL_DEFAULT); dat->text_align_right = db_get_b(NULL, "CList", "TextAlignToRight", SETTING_TEXT_RIGHTALIGN_DEFAULT); dat->text_replace_smileys = db_get_b(NULL, "CList", "TextReplaceSmileys", SETTING_TEXT_SMILEY_DEFAULT); dat->text_resize_smileys = db_get_b(NULL, "CList", "TextResizeSmileys", SETTING_TEXT_RESIZESMILEY_DEFAULT); dat->text_smiley_height = 0; dat->text_use_protocol_smileys = db_get_b(NULL, "CList", "TextUseProtocolSmileys", SETTING_TEXT_PROTOSMILEY_DEFAULT); if (pcli->hwndContactTree == hwnd || pcli->hwndContactTree == NULL) dat->text_ignore_size_for_row_height = db_get_b(NULL, "CList", "TextIgnoreSizeForRownHeight", SETTING_TEXT_IGNORESIZE_DEFAULT); else dat->text_ignore_size_for_row_height = 0; // First line dat->first_line_draw_smileys = db_get_b(NULL, "CList", "FirstLineDrawSmileys", SETTING_FIRSTLINE_SMILEYS_DEFAULT); dat->first_line_append_nick = db_get_b(NULL, "CList", "FirstLineAppendNick", SETTING_FIRSTLINE_APPENDNICK_DEFAULT); gl_TrimText = db_get_b(NULL, "CList", "TrimText", SETTING_FIRSTLINE_TRIMTEXT_DEFAULT); // Second line if (pcli->hwndContactTree == hwnd || pcli->hwndContactTree == NULL) { dat->second_line_show = db_get_b(NULL, "CList", "SecondLineShow", SETTING_SECONDLINE_SHOW_DEFAULT); dat->second_line_top_space = db_get_w(NULL, "CList", "SecondLineTopSpace", SETTING_SECONDLINE_TOPSPACE_DEFAULT); dat->second_line_draw_smileys = db_get_b(NULL, "CList", "SecondLineDrawSmileys", SETTING_SECONDLINE_SMILEYS_DEFAULT); dat->second_line_type = db_get_w(NULL, "CList", "SecondLineType", SETTING_SECONDLINE_TYPE_DEFAULT); ptrT tszLineText(db_get_tsa(NULL, "CList", "SecondLineText")); if (tszLineText) mir_tstrncpy(dat->second_line_text, tszLineText, _countof(dat->second_line_text)); else dat->second_line_text[0] = _T('\0'); dat->second_line_xstatus_has_priority = db_get_b(NULL, "CList", "SecondLineXStatusHasPriority", SETTING_SECONDLINE_XSTATUS_DEFAULT); dat->second_line_show_status_if_no_away = db_get_b(NULL, "CList", "SecondLineShowStatusIfNoAway", SETTING_SECONDLINE_STATUSIFNOAWAY_DEFAULT); dat->second_line_show_listening_if_no_away = db_get_b(NULL, "CList", "SecondLineShowListeningIfNoAway", SETTING_SECONDLINE_LISTENINGIFNOAWAY_DEFAULT); dat->second_line_use_name_and_message_for_xstatus = db_get_b(NULL, "CList", "SecondLineUseNameAndMessageForXStatus", SETTING_SECONDLINE_XSTATUSNAMETEXT_DEFAULT); } else { dat->second_line_show = 0; dat->second_line_top_space = 0; dat->second_line_draw_smileys = 0; dat->second_line_type = 0; dat->second_line_text[0] = _T('\0'); dat->second_line_xstatus_has_priority = 0; dat->second_line_use_name_and_message_for_xstatus = 0; } // Third line if (pcli->hwndContactTree == hwnd || pcli->hwndContactTree == NULL) { dat->third_line_show = db_get_b(NULL, "CList", "ThirdLineShow", SETTING_THIRDLINE_SHOW_DEFAULT); dat->third_line_top_space = db_get_w(NULL, "CList", "ThirdLineTopSpace", SETTING_THIRDLINE_TOPSPACE_DEFAULT); dat->third_line_draw_smileys = db_get_b(NULL, "CList", "ThirdLineDrawSmileys", SETTING_THIRDLINE_SMILEYS_DEFAULT); dat->third_line_type = db_get_w(NULL, "CList", "ThirdLineType", SETTING_THIRDLINE_TYPE_DEFAULT); ptrT tszLineText(db_get_tsa(NULL, "CList", "ThirdLineText")); if (tszLineText) mir_tstrncpy(dat->third_line_text, tszLineText, _countof(dat->third_line_text)); else dat->third_line_text[0] = _T('\0'); dat->third_line_xstatus_has_priority = db_get_b(NULL, "CList", "ThirdLineXStatusHasPriority", SETTING_THIRDLINE_XSTATUS_DEFAULT); dat->third_line_show_status_if_no_away = db_get_b(NULL, "CList", "ThirdLineShowStatusIfNoAway", SETTING_THIRDLINE_STATUSIFNOAWAY_DEFAULT); dat->third_line_show_listening_if_no_away = db_get_b(NULL, "CList", "ThirdLineShowListeningIfNoAway", SETTING_THIRDLINE_LISTENINGIFNOAWAY_DEFAULT); dat->third_line_use_name_and_message_for_xstatus = db_get_b(NULL, "CList", "ThirdLineUseNameAndMessageForXStatus", SETTING_THIRDLINE_XSTATUSNAMETEXT_DEFAULT); } else { dat->third_line_show = 0; dat->third_line_top_space = 0; dat->third_line_draw_smileys = 0; dat->third_line_type = TEXT_STATUS_MESSAGE; dat->third_line_text[0] = _T('\0'); dat->third_line_xstatus_has_priority = 1; dat->third_line_use_name_and_message_for_xstatus = 0; } dat->rightMargin = db_get_b(NULL, "CLC", "RightMargin", CLCDEFAULT_RIGHTMARGIN); dat->force_in_dialog = (pcli->hwndContactTree) ? (hwnd != pcli->hwndContactTree) : 0; dat->subIndent = db_get_b(NULL, "CLC", "SubIndent", CLCDEFAULT_GROUPINDENT); if (dat->hBmpBackground) { DeleteObject(dat->hBmpBackground); dat->hBmpBackground = NULL; } if (dat->hMenuBackground) { DeleteObject(dat->hMenuBackground); dat->hMenuBackground = NULL; } if (g_CluiData.fDisableSkinEngine) { dat->MenuBkColor = sttGetColor("Menu", "BkColour", CLCDEFAULT_BKCOLOUR); dat->MenuBkHiColor = sttGetColor("Menu", "SelBkColour", CLCDEFAULT_SELBKCOLOUR); dat->MenuTextColor = sttGetColor("Menu", "TextColour", CLCDEFAULT_TEXTCOLOUR); dat->MenuTextHiColor = sttGetColor("Menu", "SelTextColour", CLCDEFAULT_MODERN_SELTEXTCOLOUR); if (db_get_b(NULL, "Menu", "UseBitmap", CLCDEFAULT_USEBITMAP)) { ptrT tszBitmap(db_get_tsa(NULL, "Menu", "BkBitmap")); if (tszBitmap != NULL) dat->hMenuBackground = Bitmap_Load(tszBitmap); } dat->MenuBmpUse = db_get_w(NULL, "Menu", "BkBmpUse", CLCDEFAULT_BKBMPUSE); } dat->IsMetaContactsEnabled = (!(GetWindowLongPtr(hwnd, GWL_STYLE)&CLS_MANUALUPDATE)) && db_get_b(NULL, META_PROTO, "Enabled", 1); if (pcli->hwndContactTree == NULL || dat->hWnd == pcli->hwndContactTree) dat->MetaIgnoreEmptyExtra = db_get_b(NULL, "CLC", "MetaIgnoreEmptyExtra", SETTING_METAIGNOREEMPTYEXTRA_DEFAULT); else dat->MetaIgnoreEmptyExtra = FALSE; dat->expandMeta = db_get_b(NULL, "CLC", "MetaExpanding", SETTING_METAEXPANDING_DEFAULT); dat->useMetaIcon = db_get_b(NULL, "CLC", "Meta", SETTING_USEMETAICON_DEFAULT); dat->drawOverlayedStatus = db_get_b(NULL, "CLC", "DrawOverlayedStatus", SETTING_DRAWOVERLAYEDSTATUS_DEFAULT); dat->dbbMetaHideExtra = db_get_b(NULL, "CLC", "MetaHideExtra", SETTING_METAHIDEEXTRA_DEFAULT); dat->dbbBlendInActiveState = db_get_b(NULL, "CLC", "BlendInActiveState", SETTING_BLENDINACTIVESTATE_DEFAULT); dat->dbbBlend25 = db_get_b(NULL, "CLC", "Blend25%", SETTING_BLENDINACTIVESTATE_DEFAULT); dat->bCompactMode = db_get_b(NULL, "CLC", "CompactMode", SETTING_COMPACTMODE_DEFAULT); if ((pcli->hwndContactTree == hwnd || pcli->hwndContactTree == NULL)) IvalidateDisplayNameCache(16); corecli.pfnLoadClcOptions(hwnd, dat, bFirst); dat->selTextColour = db_get_dw(NULL, "CLC", "SelTextColour", CLCDEFAULT_MODERN_SELTEXTCOLOUR); dat->hotTextColour = db_get_dw(NULL, "CLC", "HotTextColour", CLCDEFAULT_MODERN_HOTTEXTCOLOUR); dat->quickSearchColour = db_get_dw(NULL, "CLC", "QuickSearchColour", CLCDEFAULT_MODERN_QUICKSEARCHCOLOUR); dat->useWindowsColours = false; // because it's missing in the options }
static INT_PTR CALLBACK PhotoDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { const unsigned long iPageId = 3; TCHAR szAvatarFileName[MAX_PATH], szTempPath[MAX_PATH], szTempFileName[MAX_PATH]; PhotoDlgProcData* dat = (PhotoDlgProcData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: if (!lParam) break; // Launched from userinfo TranslateDialogDefault(hwndDlg); SendDlgItemMessage(hwndDlg, IDC_LOAD, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_OPEN), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)); SendDlgItemMessage(hwndDlg, IDC_LOAD, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hwndDlg, IDC_DELETE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DELETE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)); SendDlgItemMessage(hwndDlg, IDC_DELETE, BUTTONSETASFLATBTN, TRUE, 0); ShowWindow(GetDlgItem(hwndDlg, IDC_SAVE), SW_HIDE); { dat = new PhotoDlgProcData; dat->ppro = (CJabberProto*)lParam; dat->hBitmap = NULL; dat->ppro->m_bPhotoChanged = FALSE; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); dat->ppro->WindowSubscribe(hwndDlg); } SendMessage(hwndDlg, WM_JABBER_REFRESH_VCARD, 0, 0); break; case WM_JABBER_REFRESH_VCARD: if (dat->hBitmap) { DeleteObject(dat->hBitmap); dat->hBitmap = NULL; DeleteFile(dat->ppro->m_szPhotoFileName); dat->ppro->m_szPhotoFileName[0] = '\0'; } EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), FALSE); dat->ppro->GetAvatarFileName(NULL, szAvatarFileName, _countof(szAvatarFileName)); if (_taccess(szAvatarFileName, 0) == 0) { if (GetTempPath(_countof(szTempPath), szTempPath) <= 0) mir_tstrcpy(szTempPath, _T(".\\")); if (GetTempFileName(szTempPath, _T("jab"), 0, szTempFileName) > 0) { dat->ppro->debugLog(_T("Temp file = %s"), szTempFileName); if (CopyFile(szAvatarFileName, szTempFileName, FALSE) == TRUE) { if ((dat->hBitmap = Bitmap_Load(szTempFileName)) != NULL) { FIP->FI_Premultiply(dat->hBitmap); mir_tstrcpy(dat->ppro->m_szPhotoFileName, szTempFileName); EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), TRUE); } else DeleteFile(szTempFileName); } else DeleteFile(szTempFileName); } } dat->ppro->m_bPhotoChanged = FALSE; InvalidateRect(hwndDlg, NULL, TRUE); UpdateWindow(hwndDlg); break; case WM_JABBER_CHANGED: dat->ppro->SetServerVcard(dat->ppro->m_bPhotoChanged, dat->ppro->m_szPhotoFileName); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_DELETE: if (dat->hBitmap) { DeleteObject(dat->hBitmap); dat->hBitmap = NULL; DeleteFile(dat->ppro->m_szPhotoFileName); dat->ppro->m_szPhotoFileName[0] = '\0'; dat->ppro->m_bPhotoChanged = TRUE; EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), FALSE); InvalidateRect(hwndDlg, NULL, TRUE); UpdateWindow(hwndDlg); dat->ppro->m_vCardUpdates |= (1UL << iPageId); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } break; case IDC_LOAD: TCHAR szFilter[512], szFileName[MAX_PATH]; Bitmap_GetFilter(szFilter, _countof(szFilter)); OPENFILENAME ofn = { 0 }; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwndDlg; ofn.lpstrFilter = szFilter; ofn.lpstrCustomFilter = NULL; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_FILEMUSTEXIST | OFN_DONTADDTORECENT; szFileName[0] = '\0'; if (GetOpenFileName(&ofn)) { struct _stat st; HBITMAP hNewBitmap; dat->ppro->debugLog(_T("File selected is %s"), szFileName); if (_tstat(szFileName, &st) < 0 || st.st_size > 40 * 1024) { MessageBox(hwndDlg, TranslateT("Only JPG, GIF, and BMP image files smaller than 40 KB are supported."), TranslateT("Jabber vCard"), MB_OK | MB_SETFOREGROUND); break; } if (GetTempPath(_countof(szTempPath), szTempPath) <= 0) mir_tstrcpy(szTempPath, _T(".\\")); if (GetTempFileName(szTempPath, _T("jab"), 0, szTempFileName) > 0) { dat->ppro->debugLog(_T("Temp file = %s"), szTempFileName); if (CopyFile(szFileName, szTempFileName, FALSE) == TRUE) { if ((hNewBitmap = Bitmap_Load(szTempFileName)) != NULL) { if (dat->hBitmap) { DeleteObject(dat->hBitmap); DeleteFile(dat->ppro->m_szPhotoFileName); } dat->hBitmap = hNewBitmap; mir_tstrcpy(dat->ppro->m_szPhotoFileName, szTempFileName); dat->ppro->m_bPhotoChanged = TRUE; EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), TRUE); InvalidateRect(hwndDlg, NULL, TRUE); UpdateWindow(hwndDlg); dat->ppro->m_vCardUpdates |= (1UL << iPageId); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } else DeleteFile(szTempFileName); } else DeleteFile(szTempFileName); } } break; } break; case WM_PAINT: if (dat->hBitmap) { BITMAP bm; POINT ptSize, ptOrg, pt, ptFitSize; RECT rect; HWND hwndCanvas = GetDlgItem(hwndDlg, IDC_CANVAS); HDC hdcCanvas = GetDC(hwndCanvas); HDC hdcMem = CreateCompatibleDC(hdcCanvas); SelectObject(hdcMem, dat->hBitmap); SetMapMode(hdcMem, GetMapMode(hdcCanvas)); GetObject(dat->hBitmap, sizeof(BITMAP), (LPVOID)&bm); ptSize.x = bm.bmWidth; ptSize.y = bm.bmHeight; DPtoLP(hdcCanvas, &ptSize, 1); ptOrg.x = ptOrg.y = 0; DPtoLP(hdcMem, &ptOrg, 1); GetClientRect(hwndCanvas, &rect); InvalidateRect(hwndCanvas, NULL, TRUE); UpdateWindow(hwndCanvas); if (ptSize.x <= rect.right && ptSize.y <= rect.bottom) { pt.x = (rect.right - ptSize.x) / 2; pt.y = (rect.bottom - ptSize.y) / 2; ptFitSize = ptSize; } else { if (((float)(ptSize.x - rect.right)) / ptSize.x > ((float)(ptSize.y - rect.bottom)) / ptSize.y) { ptFitSize.x = rect.right; ptFitSize.y = (ptSize.y*rect.right) / ptSize.x; pt.x = 0; pt.y = (rect.bottom - ptFitSize.y) / 2; } else { ptFitSize.x = (ptSize.x*rect.bottom) / ptSize.y; ptFitSize.y = rect.bottom; pt.x = (rect.right - ptFitSize.x) / 2; pt.y = 0; } } RECT rc; GetClientRect(hwndCanvas, &rc); if (IsThemeActive()) DrawThemeParentBackground(hwndCanvas, hdcCanvas, &rc); else FillRect(hdcCanvas, &rc, (HBRUSH)GetSysColorBrush(COLOR_BTNFACE)); if (bm.bmBitsPixel == 32) { BLENDFUNCTION bf = { 0 }; bf.AlphaFormat = AC_SRC_ALPHA; bf.BlendOp = AC_SRC_OVER; bf.SourceConstantAlpha = 255; GdiAlphaBlend(hdcCanvas, pt.x, pt.y, ptFitSize.x, ptFitSize.y, hdcMem, ptOrg.x, ptOrg.y, ptSize.x, ptSize.y, bf); } else { SetStretchBltMode(hdcCanvas, COLORONCOLOR); StretchBlt(hdcCanvas, pt.x, pt.y, ptFitSize.x, ptFitSize.y, hdcMem, ptOrg.x, ptOrg.y, ptSize.x, ptSize.y, SRCCOPY); } DeleteDC(hdcMem); } break; case WM_NOTIFY: if (((LPNMHDR)lParam)->idFrom == 0) { switch (((LPNMHDR)lParam)->code) { case PSN_PARAMCHANGED: SendMessage(hwndDlg, WM_INITDIALOG, 0, ((PSHNOTIFY*)lParam)->lParam); break; case PSN_APPLY: dat->ppro->m_vCardUpdates &= ~(1UL << iPageId); dat->ppro->SaveVcardToDB(hwndDlg, iPageId); if (!dat->ppro->m_vCardUpdates) dat->ppro->SetServerVcard(dat->ppro->m_bPhotoChanged, dat->ppro->m_szPhotoFileName); break; } } break; case WM_DESTROY: DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_LOAD, BM_SETIMAGE, IMAGE_ICON, 0)); DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_DELETE, BM_SETIMAGE, IMAGE_ICON, 0)); dat->ppro->WindowUnsubscribe(hwndDlg); if (dat->hBitmap) { dat->ppro->debugLogA("Delete bitmap"); DeleteObject(dat->hBitmap); DeleteFile(dat->ppro->m_szPhotoFileName); } delete dat; break; } return FALSE; }