Skip to content

Commit

Permalink
Dialogs: Properly destroy image lists. Closes rainmeter#208
Browse files Browse the repository at this point in the history
  • Loading branch information
brianferguson committed Nov 5, 2019
1 parent 7225d40 commit e76628b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
20 changes: 19 additions & 1 deletion Library/DialogAbout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,16 @@ DialogAbout::TabLog::TabLog() : Tab(),
m_Error(true),
m_Warning(true),
m_Notice(true),
m_Debug(true)
m_Debug(true),
m_ImageList(nullptr)
{
}

DialogAbout::TabLog::~TabLog()
{
DestroyImageList();
}

void DialogAbout::TabLog::Create(HWND owner)
{
Tab::CreateTabWindow(15, 30, 570, 188, owner);
Expand Down Expand Up @@ -430,9 +436,21 @@ void DialogAbout::TabLog::Initialize()
item = GetControl(Id_DebugCheckBox);
Button_SetCheck(item, BST_CHECKED);

DestroyImageList();
m_ImageList = hImageList;

m_Initialized = true;
}

void DialogAbout::TabLog::DestroyImageList()
{
if (m_ImageList)
{
ImageList_Destroy(m_ImageList);
m_ImageList = nullptr;
}
}

/*
** Resizes window and repositions controls.
**
Expand Down
5 changes: 5 additions & 0 deletions Library/DialogAbout.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class DialogAbout : public Dialog
};

TabLog();
~TabLog();

void Create(HWND owner);
virtual void Initialize();
Expand All @@ -68,10 +69,14 @@ class DialogAbout : public Dialog
INT_PTR OnNotify(WPARAM wParam, LPARAM lParam);

private:
void DestroyImageList();

bool m_Error;
bool m_Warning;
bool m_Notice;
bool m_Debug;

HIMAGELIST m_ImageList;
};

// Skins tab
Expand Down
17 changes: 16 additions & 1 deletion Library/DialogManage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ COLORREF DialogManage::TabSkins::s_NewSkinBkColor = RGB(229, 241, 251); // defau
DialogManage::TabSkins::TabSkins() : Tab(),
m_SkinWindow(),
m_HandleCommands(false),
m_IgnoreUpdate(false)
m_IgnoreUpdate(false),
m_ImageListHandle(nullptr)
{
}

Expand All @@ -397,6 +398,8 @@ DialogManage::TabSkins::~TabSkins()
item = GetControl(Id_SkinsTreeView);
RemoveWindowSubclass(item, &SkinsTreeViewSubclass, 1);

DestroyImageList();

if (s_NewSkinBkBrush)
{
DeleteObject(s_NewSkinBkBrush);
Expand Down Expand Up @@ -621,10 +624,22 @@ void DialogManage::TabSkins::Initialize()
ComboBox_AddString(item, GetString(ID_STR_FADEIN));
ComboBox_AddString(item, GetString(ID_STR_FADEOUT));

DestroyImageList();
m_ImageListHandle = hImageList;

m_Initialized = true;
m_HandleCommands = true;
}

void DialogManage::TabSkins::DestroyImageList()
{
if (m_ImageListHandle)
{
ImageList_Destroy(m_ImageListHandle);
m_ImageListHandle = nullptr;
}
}

void DialogManage::TabSkins::UpdateSelected(Skin* skin)
{
if (m_SkinWindow && m_SkinWindow == skin)
Expand Down
3 changes: 3 additions & 0 deletions Library/DialogManage.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class DialogManage : public Dialog
void SetControls();
void DisableControls(bool clear = false);
void ReadSkin();
void DestroyImageList();

static LRESULT CALLBACK NewSkinButtonSubclass(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam, UINT_PTR uId, DWORD_PTR data);
Expand All @@ -116,6 +117,8 @@ class DialogManage : public Dialog
bool m_HandleCommands;
bool m_IgnoreUpdate;

HIMAGELIST m_ImageListHandle;

static HBRUSH s_NewSkinBkBrush;
static COLORREF s_NewSkinBkColor;
};
Expand Down
20 changes: 19 additions & 1 deletion Library/DialogNewSkin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,16 @@ std::vector<DialogNewSkin::TabNew::SortInfo> DialogNewSkin::TabNew::s_SortInfo;
DialogNewSkin::TabNew::TabNew() : Tab(),
m_IsRoot(true),
m_CanAddResourcesFolder(false),
m_InRenameMode(false)
m_InRenameMode(false),
m_ImageList(nullptr)
{
}

DialogNewSkin::TabNew::~TabNew()
{
DestroyImageList();
}

void DialogNewSkin::TabNew::Create(HWND owner)
{
Tab::CreateTabWindow(15, 30, 270, 188, owner);
Expand Down Expand Up @@ -472,9 +478,21 @@ void DialogNewSkin::TabNew::Initialize()
item = GetControl(Id_ItemsTreeView);
TreeView_SetImageList(item, hImageList, TVSIL_NORMAL);

DestroyImageList();
m_ImageList = hImageList;

m_Initialized = true;
}

void DialogNewSkin::TabNew::DestroyImageList()
{
if (m_ImageList)
{
ImageList_Destroy(m_ImageList);
m_ImageList = nullptr;
}
}

INT_PTR DialogNewSkin::TabNew::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
Expand Down
4 changes: 4 additions & 0 deletions Library/DialogNewSkin.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class DialogNewSkin : public Dialog
};

TabNew();
~TabNew();

void Create(HWND owner);
virtual void Initialize();
Expand All @@ -77,6 +78,7 @@ class DialogNewSkin : public Dialog
SortInfo(bool t, std::wstring n) : type(t), name(n) {}
};

void DestroyImageList();
void UpdateParentPathLabel();
void UpdateParentPathTT(bool update);
void AddTreeItem(bool isFolder);
Expand All @@ -97,6 +99,8 @@ class DialogNewSkin : public Dialog
HWND m_TreeEdit;
HWND m_ParentPathTT;

HIMAGELIST m_ImageList;

static std::vector<SortInfo> s_SortInfo;
};

Expand Down

0 comments on commit e76628b

Please sign in to comment.