summaryrefslogtreecommitdiff
path: root/plugins/WhenWasIt/src/icons.cpp
blob: d8099345f048cdc1e091d785bbbcaed0cbe0ad6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
WhenWasIt (birthday reminder) plugin for Miranda IM

Copyright © 2006 Cristian Libotean

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "commonheaders.h"
#include "icons.h"

//HICON hiDlg = NULL;
HICON hiMainMenu = NULL;
HICON hiCheckMenu = NULL;
HICON hiListMenu = NULL;
HICON hiAddBirthdayContact = NULL;
HICON hiRefreshUserDetails = NULL;

HICON hiImportBirthdays = NULL;
HICON hiExportBirthdays = NULL;

const int cDTB = 10;
HICON hiDTB[cDTB] = {NULL};
HICON hiDTBMore = NULL;

HANDLE hClistImages[cDTB + 1];

HANDLE hWWIExtraIcons = (HANDLE) -1;

#define GET_DTB_ICON(index) (hiDTB[index] = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DTB ## index)))

int LoadIcons()
{
	//hiDlgIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BIRTHDAYS_DLG));
	hiCheckMenu = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CHECK));
	hiListMenu = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_LIST));
	hiAddBirthdayContact = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ADD));
	hiRefreshUserDetails = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REFRESH_USERDETAILS));
	
	hiImportBirthdays = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_IMPORT_BIRTHDAYS));
	hiExportBirthdays = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_EXPORT_BIRTHDAYS));
	
	GET_DTB_ICON(0);
	GET_DTB_ICON(1);
	GET_DTB_ICON(2);
	GET_DTB_ICON(3);
	GET_DTB_ICON(4);
	GET_DTB_ICON(5);
	GET_DTB_ICON(6);
	GET_DTB_ICON(7);
	GET_DTB_ICON(8);
	GET_DTB_ICON(9);
	hiDTBMore = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DTBMORE));
	
	AddIcons();
	GetIcons();
	
	hWWIExtraIcons = ExtraIcon_Register("WhenWasIt", Translate("WhenWasIt birthday reminder"), "MenuCheck");
	return 0;
}

HANDLE AddIcon(HICON icon, char *name, char *description)
{
	SKINICONDESC sid = {0};
	sid.cbSize = sizeof(sid);
	sid.pszSection = "WhenWasIt";
	sid.cx = sid.cy = 16;
	sid.pszDescription = description;
	sid.pszName = name;
	sid.hDefaultIcon = icon;
	return Skin_AddIcon(&sid);
}

int AddIcons()
{
	AddIcon(hiCheckMenu, "MenuCheck", "Check birthdays menu item");
	AddIcon(hiListMenu, "MenuList", "List birthdays menu item");
	AddIcon(hiAddBirthdayContact, "AddBirthday", "Add/change birthday");
	AddIcon(hiRefreshUserDetails, "RefreshUserDetails", "Refresh user details");

	AddIcon(hiImportBirthdays, "ImportBirthdays", "Import birthdays");
	AddIcon(hiExportBirthdays, "ExportBirthdays", "Export birthdays");

	char name[1024];
	char description[1024];
	AddIcon(hiDTB[0], "DTB0", "Birthday today");
	AddIcon(hiDTB[1], "DTB1", "1 day to birthday");
	for (int i = 2; i < cDTB; i++) {
		sprintf(name, "DTB%d", i);
		sprintf(description, "%d days to birthday", i);
		AddIcon(hiDTB[i], name, description);
	}
	sprintf(description, "More than %d days to birthday", cDTB - 1);
	AddIcon(hiDTBMore, "DTBMore", description);
	return 0;
}

HICON GetIcon(char *name)
{
	return Skin_GetIcon(name);	
}

void FreeIcon(HICON &icon)
{
	DestroyIcon(icon);
	icon = NULL;
}

void FreeIcons()
{
	static int bFreed = 0;
	if ( !bFreed) {
		FreeIcon(hiCheckMenu);
		FreeIcon(hiListMenu);
		FreeIcon(hiAddBirthdayContact);
		FreeIcon(hiRefreshUserDetails);

		FreeIcon(hiImportBirthdays);
		FreeIcon(hiExportBirthdays);

		for (int i = 0; i < cDTB; i++)
			FreeIcon(hiDTB[i]);

		FreeIcon(hiDTBMore);
	}
	bFreed = 1; //only free them once (ours).
}

int GetIcons()
{
	hiCheckMenu = GetIcon("MenuCheck");
	hiListMenu = GetIcon("MenuList");
	hiAddBirthdayContact = GetIcon("AddBirthday");
	hiRefreshUserDetails = GetIcon("RefreshUserDetails");

	hiImportBirthdays = GetIcon("ImportBirthdays");
	hiExportBirthdays = GetIcon("ExportBirthdays");

	char buffer[1024];
	for (int i = 0; i < cDTB; i++)
	{
		sprintf(buffer, "DTB%d", i);
		hiDTB[i] = GetIcon(buffer);
	}
	hiDTBMore = GetIcon("DTBMore");
	return 0;
}

HICON GetDTBIcon(int dtb)
{
	if ((dtb >= cDTB) || (dtb < 0))
		return hiDTBMore;

	return hiDTB[dtb];
}

HICON GetDABIcon(int dab)
{
	return GetDTBIcon(dab);
}

HANDLE GetClistIcon(int dtb)
{
	if (dtb >= cDTB)
		return hClistImages[cDTB];

	return hClistImages[dtb];
}