Skip to content

Commit

Permalink
+ fix: some CppCheck complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
RaiKoHoff committed Nov 20, 2018
1 parent efdac7d commit d64039c
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 258 deletions.
41 changes: 19 additions & 22 deletions src/ChooseFont/ChooseFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ class ChooseFontDialog
HRESULT OnFontSizeSelect();

HRESULT OnFontFamilyNameEdit(HWND hwndFontFamilies);
HRESULT OnFontFaceNameEdit(HWND hwndFontFaces);
HRESULT OnFontSizeNameEdit(HWND hwndFontSizes);
HRESULT OnFontFaceNameEdit(HWND hwnd);
HRESULT OnFontSizeNameEdit(HWND hwnd);

HRESULT DrawSampleText(HDC sampleDC);

static INT_PTR CALLBACK CFDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
static INT_PTR CALLBACK CFDialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

BOOL OnInitDialog(HWND dialog, HWND hwndFocus, LPARAM lParam);
void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
Expand Down Expand Up @@ -139,13 +139,11 @@ ChooseFontDialog::~ChooseFontDialog()

HRESULT ChooseFontDialog::GetTextFormat(IDWriteTextFormat** textFormat)
{
HRESULT hr = S_OK;

*textFormat = nullptr;

// Default to the system font collection
SafeRelease(&m_fontCollection);
hr = g_dwrite->GetSystemFontCollection(&m_fontCollection);
HRESULT hr = g_dwrite->GetSystemFontCollection(&m_fontCollection);

// Create a default text format
if (SUCCEEDED(hr)) {
Expand Down Expand Up @@ -198,15 +196,13 @@ HRESULT ChooseFontDialog::GetTextFormat(IDWriteTextFormat** textFormat)

HRESULT ChooseFontDialog::GetTextFormat(IDWriteTextFormat* textFormatIn, IDWriteTextFormat** textFormatOut)
{
HRESULT hr = S_OK;

*textFormatOut = nullptr;

SafeSet(&m_currentTextFormat, textFormatIn);

// Pull out the input font attributes
SafeRelease(&m_fontCollection);
hr = m_currentTextFormat->GetFontCollection(&m_fontCollection);
HRESULT hr = m_currentTextFormat->GetFontCollection(&m_fontCollection);

if (SUCCEEDED(hr)) {
hr = m_currentTextFormat->GetLocaleName(&m_localeName[0], _ARRAYSIZE(m_localeName));
Expand Down Expand Up @@ -553,19 +549,20 @@ HRESULT ChooseFontDialog::DrawSampleText(HDC sampleDC)
m_localeName,
&m_currentTextFormat);

// Create the rendering text format object
float dipSize = (pointSize * m_currentDPI.y) / 72.0f;

SafeRelease(&m_renderTextFormat);
hr = g_dwrite->CreateTextFormat(
fontFamilyName,
m_fontCollection,
fontFaceInfo.fontWeight,
fontFaceInfo.fontStyle,
fontFaceInfo.fontStretch,
dipSize,
m_localeName,
&m_renderTextFormat);
if (SUCCEEDED(hr)) {
// Create the rendering text format object
float dipSize = (pointSize * m_currentDPI.y) / 72.0f;
SafeRelease(&m_renderTextFormat);
hr = g_dwrite->CreateTextFormat(
fontFamilyName,
m_fontCollection,
fontFaceInfo.fontWeight,
fontFaceInfo.fontStyle,
fontFaceInfo.fontStretch,
dipSize,
m_localeName,
&m_renderTextFormat);
}
}
// Get the size of the sample box
RECT sampleBounds = {};
Expand Down
12 changes: 3 additions & 9 deletions src/ChooseFont/FontEnumeration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ HRESULT GetLocalizedName(IDWriteLocalizedStrings* names, const WCHAR* locale, OU

HRESULT GetFontFamilyName(IDWriteFontFamily* fontFamily, const WCHAR* locale, OUT std::wstring& familyName)
{
HRESULT hr = S_OK;

IDWriteLocalizedStrings* familyNames = nullptr;

hr = fontFamily->GetFamilyNames(&familyNames);
HRESULT hr = fontFamily->GetFamilyNames(&familyNames);

if (SUCCEEDED(hr))
{
Expand All @@ -101,11 +99,9 @@ HRESULT GetFontFamilyName(IDWriteFontFamily* fontFamily, const WCHAR* locale, OU

HRESULT GetFontFaceName(IDWriteFont* font, const WCHAR* locale, OUT std::wstring& faceName)
{
HRESULT hr = S_OK;

IDWriteLocalizedStrings* faceNames = nullptr;

hr = font->GetFaceNames(&faceNames);
HRESULT hr = font->GetFaceNames(&faceNames);

if (SUCCEEDED(hr))
{
Expand Down Expand Up @@ -157,12 +153,10 @@ HRESULT GetFontFamily(IDWriteFontCollection* fontCollection, const WCHAR* fontFa

HRESULT GetFonts(IDWriteFontCollection* fontCollection, const WCHAR* fontFamilyName, IN OUT std::vector<IDWriteFont*>& fonts)
{
HRESULT hr = S_OK;

IDWriteFontFamily* fontFamily = nullptr;
IDWriteFont* font = nullptr;

hr = GetFontFamily(fontCollection, fontFamilyName, &fontFamily);
HRESULT hr = GetFontFamily(fontCollection, fontFamilyName, &fontFamily);

if (SUCCEEDED(hr))
{
Expand Down
2 changes: 1 addition & 1 deletion src/ChooseFont/FontEnumeration.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct FontFaceInfo
StringCchCopy(this->fontFaceName, ARRAYSIZE(this->fontFaceName), fontFaceName);
}

ULONG PackedFontAttributes()
ULONG const PackedFontAttributes() const
{
return MAKELONG(fontWeight, MAKEWORD(fontStyle, fontStretch));
}
Expand Down
64 changes: 29 additions & 35 deletions src/Dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
#include "Version.h"
#include "Helpers.h"
#include "Encoding.h"
#include "TypeDefs.h"
#include "SciCall.h"
#include "TypeDefs.h"

#include "Dialogs.h"

Expand All @@ -58,15 +58,13 @@ static HHOOK hhkMsgBox = NULL;

static LRESULT CALLBACK _MsgBoxProc(INT nCode, WPARAM wParam, LPARAM lParam)
{
HWND hParentWnd, hChildWnd; // msgbox is "child"
RECT rParent, rChild, rDesktop;

// notification that a window is about to be activated
if (nCode == HCBT_ACTIVATE) {
// set window handles
hParentWnd = GetForegroundWindow();
hChildWnd = (HWND)wParam; // window handle is wParam
HWND hParentWnd = GetForegroundWindow(); // msgbox is "child"
HWND hChildWnd = (HWND)wParam; // window handle is wParam

RECT rParent, rChild, rDesktop;
if ((hParentWnd != NULL) && (hChildWnd != NULL) &&
(GetWindowRect(GetDesktopWindow(), &rDesktop) != 0) &&
(GetWindowRect(hParentWnd, &rParent) != 0) &&
Expand Down Expand Up @@ -501,43 +499,41 @@ static DWORD CALLBACK _LoadRtfCallbackW(
//
INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
WCHAR wch[256] = { L'\0' };
static HFONT hFontTitle;
static HICON hIcon = NULL;

switch (umsg)
{
case WM_INITDIALOG:
{
{
if (!hIcon) {
hIcon = LoadImage(Globals.hInstance, MAKEINTRESOURCE(IDR_MAINWND), IMAGE_ICON, 128, 128, LR_DEFAULTCOLOR);
}
if (!hIcon) {
hIcon = LoadImage(Globals.hInstance, MAKEINTRESOURCE(IDR_MAINWND), IMAGE_ICON, 128, 128, LR_DEFAULTCOLOR);
}

SetDlgItemText(hwnd, IDC_VERSION, MKWCS(VERSION_FILEVERSION_LONG));
SetDlgItemText(hwnd, IDC_VERSION, MKWCS(VERSION_FILEVERSION_LONG));

if (hFontTitle) { DeleteObject(hFontTitle); }
static HFONT hFontTitle;
if (hFontTitle) { DeleteObject(hFontTitle); }

if (NULL == (hFontTitle = (HFONT)SendDlgItemMessage(hwnd, IDC_VERSION, WM_GETFONT, 0, 0))) {
hFontTitle = GetStockObject(DEFAULT_GUI_FONT);
}
if (NULL == (hFontTitle = (HFONT)SendDlgItemMessage(hwnd, IDC_VERSION, WM_GETFONT, 0, 0))) {
hFontTitle = GetStockObject(DEFAULT_GUI_FONT);
}

LOGFONT lf;
GetObject(hFontTitle, sizeof(LOGFONT), &lf);
lf.lfWeight = FW_BOLD;
lf.lfWidth = ScaleIntFontSize(8);
lf.lfHeight = ScaleIntFontSize(22);
// lf.lfQuality = ANTIALIASED_QUALITY;
hFontTitle = CreateFontIndirect(&lf);
LOGFONT lf;
GetObject(hFontTitle, sizeof(LOGFONT), &lf);
lf.lfWeight = FW_BOLD;
lf.lfWidth = ScaleIntFontSize(8);
lf.lfHeight = ScaleIntFontSize(22);
// lf.lfQuality = ANTIALIASED_QUALITY;
hFontTitle = CreateFontIndirect(&lf);

SendDlgItemMessage(hwnd, IDC_VERSION, WM_SETFONT, (WPARAM)hFontTitle, true);
}
SendDlgItemMessage(hwnd, IDC_VERSION, WM_SETFONT, (WPARAM)hFontTitle, true);

SetDlgItemText(hwnd, IDC_SCI_VERSION, VERSION_SCIVERSION);
SetDlgItemText(hwnd, IDC_COPYRIGHT, VERSION_LEGALCOPYRIGHT);
SetDlgItemText(hwnd, IDC_AUTHORNAME, VERSION_AUTHORNAME);
SetDlgItemText(hwnd, IDC_COMPILER, VERSION_COMPILER);

WCHAR wch[256] = { L'\0' };
if (GetDlgItem(hwnd, IDC_WEBPAGE) == NULL) {
SetDlgItemText(hwnd, IDC_WEBPAGE2, VERSION_WEBPAGEDISPLAY);
ShowWindow(GetDlgItem(hwnd, IDC_WEBPAGE2), SW_SHOWNORMAL);
Expand Down Expand Up @@ -1403,10 +1399,9 @@ DWORD WINAPI FileMRUIconThread(LPVOID lpParam) {
SHFILEINFO shfi;
ZeroMemory(&shfi, sizeof(SHFILEINFO));

DWORD dwAttr = 0;

if (ListView_GetItem(hwnd,&lvi)) {

if (ListView_GetItem(hwnd,&lvi))
{
DWORD dwAttr = 0;
if (PathIsUNC(tch) || !PathFileExists(tch)) {
dwFlags |= SHGFI_USEFILEATTRIBUTES;
dwAttr = FILE_ATTRIBUTE_NORMAL;
Expand Down Expand Up @@ -2815,7 +2810,6 @@ WINDOWPLACEMENT WindowPlacementFromInfo(HWND hwnd, const WININFO* pWinInfo)
void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, bool bSetCurFile)
{
WCHAR szModuleName[MAX_PATH] = { L'\0' };
WCHAR szFileName[MAX_PATH] = { L'\0' };
WCHAR szParameters[2 * MAX_PATH + 64] = { L'\0' };
WCHAR tch[64] = { L'\0' };

Expand Down Expand Up @@ -2858,6 +2852,7 @@ void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, bool bSetCurFile)

if (bSetCurFile && StringCchLenW(Globals.CurrentFile, (MAX_PATH+1)))
{
WCHAR szFileName[MAX_PATH] = { L'\0' };
StringCchCopy(szFileName, COUNTOF(szFileName), Globals.CurrentFile);
PathQuoteSpaces(szFileName);
StringCchCat(szParameters, COUNTOF(szParameters), L" ");
Expand Down Expand Up @@ -3008,12 +3003,8 @@ bool SetWindowTitle(HWND hwnd, UINT uIDAppName, bool bIsElevated, UINT uIDUntitl
LPCWSTR lpszFile, int iFormat, bool bModified,
UINT uIDReadOnly, bool bReadOnly, LPCWSTR lpszExcerpt)
{

WCHAR szUntitled[MIDSZ_BUFFER] = { L'\0' };
WCHAR szExcrptQuot[MIDSZ_BUFFER] = { L'\0' };
WCHAR szExcrptFmt[32] = { L'\0' };
WCHAR szAppName[MIDSZ_BUFFER] = { L'\0' };
WCHAR szElevatedAppName[MIDSZ_BUFFER] = { L'\0' };
WCHAR szReadOnly[32] = { L'\0' };
WCHAR szTitle[LARGE_BUFFER] = { L'\0' };

Expand All @@ -3026,6 +3017,7 @@ bool SetWindowTitle(HWND hwnd, UINT uIDAppName, bool bIsElevated, UINT uIDUntitl
}

if (bIsElevated) {
WCHAR szElevatedAppName[MIDSZ_BUFFER] = { L'\0' };
FormatLngStringW(szElevatedAppName, COUNTOF(szElevatedAppName), IDS_MUI_APPTITLE_ELEVATED, szAppName);
StringCchCopyN(szAppName, COUNTOF(szAppName), szElevatedAppName, COUNTOF(szElevatedAppName));
}
Expand All @@ -3036,6 +3028,8 @@ bool SetWindowTitle(HWND hwnd, UINT uIDAppName, bool bIsElevated, UINT uIDUntitl
StringCchCopy(szTitle, COUNTOF(szTitle), L"");

if (StrIsNotEmpty(lpszExcerpt)) {
WCHAR szExcrptFmt[32] = { L'\0' };
WCHAR szExcrptQuot[MIDSZ_BUFFER] = { L'\0' };
GetLngString(IDS_MUI_TITLEEXCERPT, szExcrptFmt, COUNTOF(szExcrptFmt));
StringCchPrintf(szExcrptQuot, COUNTOF(szExcrptQuot), szExcrptFmt, lpszExcerpt);
StringCchCat(szTitle, COUNTOF(szTitle), szExcrptQuot);
Expand Down
Loading

0 comments on commit d64039c

Please sign in to comment.