iconlist.cpp (1678B)
1 /* ReaPack: Package manager for REAPER 2 * Copyright (C) 2015-2025 Christian Fillion 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #include "iconlist.hpp" 19 20 #ifdef _WIN32 21 # define DEFINE_ICON(icon, rc, _) IconList::Icon IconList::icon = MAKEINTRESOURCE(rc) 22 #else 23 # define DEFINE_ICON(icon, _, name) IconList::Icon IconList::icon = name 24 #endif 25 26 DEFINE_ICON(CheckedIcon, 141, "checked"); 27 DEFINE_ICON(UncheckedIcon, 142, "unchecke"); 28 29 IconList::IconList(const std::initializer_list<const Win32::char_type *> &icons) 30 { 31 m_list = ImageList_Create(16, 16, 1, 32 static_cast<int>(icons.size()), static_cast<int>(icons.size())); 33 34 for(const auto *icon : icons) 35 loadIcon(icon); 36 } 37 38 void IconList::loadIcon(const Win32::char_type *name) 39 { 40 #ifdef _WIN32 41 HINSTANCE reaper = GetModuleHandle(nullptr); 42 HICON icon = LoadIcon(reaper, name); 43 ImageList_AddIcon(m_list, icon); 44 #else 45 HICON icon = LoadNamedImage(name, true); 46 ImageList_Add(m_list, icon, 0); // v5.20 47 #endif 48 DestroyIcon(icon); 49 } 50 51 IconList::~IconList() 52 { 53 ImageList_Destroy(m_list); 54 }