SizeI GetIdealSize(LabelWithCloseWnd *w) { WCHAR *s = win::GetText(w->hwnd); SizeI size = TextSizeInHwnd(w->hwnd, s); free(s); int btnDx = DpiScaleX(w->hwnd, CLOSE_BTN_DX); int btnDy = DpiScaleY(w->hwnd, CLOSE_BTN_DY); size.dx += btnDx; size.dx += DpiScaleX(w->hwnd, LABEL_BUTTON_SPACE_DX); size.dx += 2 * DpiScaleX(w->hwnd, w->padX); if (size.dy < btnDy) { size.dy = btnDy; } size.dy += 2 * DpiScaleY(w->hwnd, w->padY); return size; }
SizeI GetIdealSize(LabelWithCloseWnd* w) { WCHAR *s = win::GetText(w->hwnd); SizeI size = TextSizeInHwnd(w->hwnd, s); free(s); int btnDx = win::DpiAdjust(w->hwnd, CLOSE_BTN_DX); int btnDy = win::DpiAdjust(w->hwnd, CLOSE_BTN_DY); size.dx += btnDx; size.dx += win::DpiAdjust(w->hwnd, LABEL_BUTTON_SPACE_DX); size.dx += win::DpiAdjust(w->hwnd, w->padL) + win::DpiAdjust(w->hwnd, w->padR); if (size.dy < btnDy) { size.dy = btnDy; } size.dy += win::DpiAdjust(w->hwnd, w->padT) + win::DpiAdjust(w->hwnd, w->padB); return size; }
static SIZE GetIdealSize(FrameRateWnd *w) { WCHAR *txt = str::Format(L"%d", w->frameRate); SizeI s = TextSizeInHwnd(w->hwnd, txt); // add padding s.dy += 4; s.dx += 8; // we wan't to avoid the window to grow/shrink when the number changes // so we keep the largest size so far, since the difference isn't big if (s.dx > w->maxSizeSoFar.cx) { w->maxSizeSoFar.cx = s.dx; } if (s.dy > w->maxSizeSoFar.cy) { w->maxSizeSoFar.cy = s.dy; } free(txt); return w->maxSizeSoFar; }
SIZE GetIdealSize(EditCtrl *w) { // force sending WM_NCCALCSIZE SetWindowPos(w->hwnd, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE); WCHAR *txt = GetTextW(w); if (str::Len(txt) == 0) { free(txt); txt = str::Dup(L"Sample"); } SizeI s = TextSizeInHwnd(w->hwnd, txt); free(txt); SIZE res; res.cx = s.dx + w->ncDx; res.cy = s.dy + w->ncDy; if (w->hasBorder) { res.cx += 4; res.cy += 4; } return res; }
//[ ACCESSKEY_GROUP Installer void OnCreateWindow(HWND hwnd) { ClientRect r(hwnd); gHwndButtonInstUninst = CreateDefaultButton(hwnd, _TR("Install SumatraPDF"), IDOK); SIZE btnSize; gHwndButtonOptions = CreateButton(hwnd, _TR("&Options"), ID_BUTTON_OPTIONS, BS_PUSHBUTTON, btnSize); int x = WINDOW_MARGIN; int y = r.dy - btnSize.cy - WINDOW_MARGIN; SetWindowPos(gHwndButtonOptions, nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW); gButtonDy = btnSize.cy; gBottomPartDy = gButtonDy + (WINDOW_MARGIN * 2); SizeI size = TextSizeInHwnd(hwnd, L"Foo"); int staticDy = size.dy + dpiAdjust(4); y = r.dy - gBottomPartDy; int dx = r.dx - (WINDOW_MARGIN * 2) - dpiAdjust(2); x += dpiAdjust(2); // build options controls going from the bottom y -= (staticDy + WINDOW_MARGIN); ScopedMem<WCHAR> defaultViewer(GetDefaultPdfViewer()); BOOL hasOtherViewer = !str::EqI(defaultViewer, APP_NAME_STR); BOOL isSumatraDefaultViewer = defaultViewer && !hasOtherViewer; // only show this checkbox if the CPU arch of DLL and OS match // (assuming that the installer has the same CPU arch as its content!) if (IsProcessAndOsArchSame()) { // only show this checkbox if the browser plugin has been installed before if (IsBrowserPluginInstalled()) { gHwndCheckboxKeepBrowserPlugin = CreateWindowExW( 0, WC_BUTTON, _TR("Keep the PDF &browser plugin installed (no longer supported)"), WS_CHILD | BS_AUTOCHECKBOX | WS_TABSTOP, x, y, dx, staticDy, hwnd, (HMENU) ID_CHECKBOX_BROWSER_PLUGIN, GetModuleHandle(nullptr), nullptr); SetWindowFont(gHwndCheckboxKeepBrowserPlugin, gFontDefault, TRUE); Button_SetCheck(gHwndCheckboxKeepBrowserPlugin, gGlobalData.keepBrowserPlugin); y -= staticDy; } // for Windows XP, this means only basic thumbnail support gHwndCheckboxRegisterPdfPreviewer = CreateWindowExW( 0, WC_BUTTON, _TR("Let Windows show &previews of PDF documents"), WS_CHILD | BS_AUTOCHECKBOX | WS_TABSTOP, x, y, dx, staticDy, hwnd, (HMENU) ID_CHECKBOX_PDF_PREVIEWER, GetModuleHandle(nullptr), nullptr); SetWindowFont(gHwndCheckboxRegisterPdfPreviewer, gFontDefault, TRUE); Button_SetCheck(gHwndCheckboxRegisterPdfPreviewer, gGlobalData.installPdfPreviewer || IsPdfPreviewerInstalled()); y -= staticDy; gHwndCheckboxRegisterPdfFilter = CreateWindowEx( 0, WC_BUTTON, _TR("Let Windows Desktop Search &search PDF documents"), WS_CHILD | BS_AUTOCHECKBOX | WS_TABSTOP, x, y, dx, staticDy, hwnd, (HMENU) ID_CHECKBOX_PDF_FILTER, GetModuleHandle(nullptr), nullptr); SetWindowFont(gHwndCheckboxRegisterPdfFilter, gFontDefault, TRUE); Button_SetCheck(gHwndCheckboxRegisterPdfFilter, gGlobalData.installPdfFilter || IsPdfFilterInstalled()); y -= staticDy; } // only show the checbox if Sumatra is not already a default viewer. // the alternative (disabling the checkbox) is more confusing if (!isSumatraDefaultViewer) { gHwndCheckboxRegisterDefault = CreateWindowExW( 0, WC_BUTTON, _TR("Use SumatraPDF as the &default PDF reader"), WS_CHILD | BS_AUTOCHECKBOX | WS_TABSTOP, x, y, dx, staticDy, hwnd, (HMENU) ID_CHECKBOX_MAKE_DEFAULT, GetModuleHandle(nullptr), nullptr); SetWindowFont(gHwndCheckboxRegisterDefault, gFontDefault, TRUE); // only check the "Use as default" checkbox when no other PDF viewer // is currently selected (not going to intrude) Button_SetCheck(gHwndCheckboxRegisterDefault, !hasOtherViewer || gGlobalData.registerAsDefault); y -= staticDy; } // a bit more space between text box and checkboxes y -= (dpiAdjust(4) + WINDOW_MARGIN); const WCHAR *s = L"&..."; SizeI btnSize2 = TextSizeInHwnd(hwnd, s); btnSize.cx += dpiAdjust(4); gHwndButtonBrowseDir = CreateButton(hwnd, s, ID_BUTTON_BROWSE, BS_PUSHBUTTON, btnSize); x = r.dx - WINDOW_MARGIN - btnSize2.dx; SetWindowPos(gHwndButtonBrowseDir, nullptr, x, y, btnSize2.dx, staticDy, SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_FRAMECHANGED); x = WINDOW_MARGIN; dx = r.dx - (2 * WINDOW_MARGIN) - btnSize2.dx - dpiAdjust(4); gHwndTextboxInstDir = CreateWindowExW(0, WC_EDIT, gGlobalData.installDir, WS_CHILD | WS_TABSTOP | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL, x, y, dx, staticDy, hwnd, nullptr, GetModuleHandle(nullptr), nullptr); SetWindowFont(gHwndTextboxInstDir, gFontDefault, TRUE); y -= staticDy; gHwndStaticInstDir = CreateWindowExW( 0, WC_STATIC, _TR("Install SumatraPDF in &folder:"),WS_CHILD, x, y, r.dx, staticDy, hwnd, nullptr, GetModuleHandle(nullptr), nullptr); SetWindowFont(gHwndStaticInstDir, gFontDefault, TRUE); gShowOptions = !gShowOptions; OnButtonOptions(); SetFocus(gHwndButtonInstUninst); if (gGlobalData.autoUpdate) { // click the Install button PostMessage(hwnd, WM_COMMAND, IDOK, 0); } }