diff options
author | Vadim Dashevskiy <watcherhd@gmail.com> | 2012-07-17 06:57:55 +0000 |
---|---|---|
committer | Vadim Dashevskiy <watcherhd@gmail.com> | 2012-07-17 06:57:55 +0000 |
commit | 1ca120b165c2f2d9f521a04bfc31c7956d2ce422 (patch) | |
tree | f56c88f1ffdb865612a3d1e05f047c17deed68ab /plugins/CountryFlags/src | |
parent | eb146b049b43c6fb09e6f8c7716c1bbc88bf2159 (diff) |
ContactsPlus, CountryFlags, CrashDumper: changed folder structure
git-svn-id: http://svn.miranda-ng.org/main/trunk@1000 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CountryFlags/src')
-rw-r--r-- | plugins/CountryFlags/src/countrylistext.cpp | 345 | ||||
-rw-r--r-- | plugins/CountryFlags/src/extraimg.cpp | 494 | ||||
-rw-r--r-- | plugins/CountryFlags/src/flags.h | 90 | ||||
-rw-r--r-- | plugins/CountryFlags/src/huffman.cpp | 506 | ||||
-rw-r--r-- | plugins/CountryFlags/src/icons.cpp | 282 | ||||
-rw-r--r-- | plugins/CountryFlags/src/ip2country.cpp | 327 | ||||
-rw-r--r-- | plugins/CountryFlags/src/main.cpp | 122 | ||||
-rw-r--r-- | plugins/CountryFlags/src/resource.h | 25 | ||||
-rw-r--r-- | plugins/CountryFlags/src/utils.cpp | 162 | ||||
-rw-r--r-- | plugins/CountryFlags/src/version.h | 31 |
10 files changed, 2384 insertions, 0 deletions
diff --git a/plugins/CountryFlags/src/countrylistext.cpp b/plugins/CountryFlags/src/countrylistext.cpp new file mode 100644 index 0000000000..95f692b30b --- /dev/null +++ b/plugins/CountryFlags/src/countrylistext.cpp @@ -0,0 +1,345 @@ +/*
+Miranda IM Country Flags Plugin
+Copyright (C) 2006-2007 H. Herkenrath
+
+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 (Flags-License.txt); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "flags.h"
+
+static HANDLE hServiceGetList,hServiceGetByNumber;
+
+/************************* Services *******************************/
+
+static struct CountryListEntry countries[]={
+ {0 ,"Unspecified"},
+ {9999,"Other"},
+ {0xFFFF,"Unknown"},
+ {93 ,"Afghanistan"},
+ {355 ,"Albania"},
+ {213 ,"Algeria"},
+ {684 ,"American Samoa"},
+ {376 ,"Andorra"},
+ {244 ,"Angola"},
+ {101 ,"Anguilla"},
+ {102 ,"Antigua and Barbuda"},
+ //{5902,"Antilles"}, /* removed */
+ {54 ,"Argentina"},
+ {374 ,"Armenia"},
+ {297 ,"Aruba"},
+ {247 ,"Ascension Island"},
+ {61 ,"Australia"},
+ {6721,"Australian Antarctic Territory"}, /* was missing */
+ {43 ,"Austria"},
+ {994 ,"Azerbaijan"},
+ {103 ,"Bahamas"},
+ {973 ,"Bahrain"},
+ {880 ,"Bangladesh"},
+ {104 ,"Barbados"},
+ {120 ,"Barbuda"},
+ {375 ,"Belarus"},
+ {32 ,"Belgium"},
+ {501 ,"Belize"},
+ {229 ,"Benin"},
+ {105 ,"Bermuda"},
+ {975 ,"Bhutan"},
+ {591 ,"Bolivia"},
+ {387 ,"Bosnia and Herzegovina"},
+ {267 ,"Botswana"},
+ {55 ,"Brazil"},
+ {106 ,"British Virgin Islands"},
+ {673 ,"Brunei"},
+ {359 ,"Bulgaria"},
+ {226 ,"Burkina Faso"},
+ {257 ,"Burundi"},
+ {855 ,"Cambodia"},
+ {237 ,"Cameroon"},
+ {107 ,"Canada"},
+ {178 ,"Canary Islands"},
+ {238 ,"Cape Verde Islands"},
+ {108 ,"Cayman Islands"},
+ {236 ,"Central African Republic"},
+ {235 ,"Chad"},
+ {56 ,"Chile, Republic of"},
+ {86 ,"China"},
+ {672 ,"Christmas Island"},
+ {6101,"Cocos-Keeling Islands"},
+ //{6102,"Cocos (Keeling) Islands"}, /* removed */
+ {57 ,"Colombia"},
+ {2691,"Comoros"},
+ {243 ,"Congo, Democratic Republic of (Zaire)"},
+ {242 ,"Congo, Republic of the"},
+ {682 ,"Cook Islands"},
+ {506 ,"Costa Rica"},
+ {225 ,"Cote d'Ivoire (Ivory Coast)"},
+ {385 ,"Croatia"},
+ {53 ,"Cuba"},
+ {357 ,"Cyprus"},
+ {420 ,"Czech Republic"},
+ {45 ,"Denmark"},
+ {246 ,"Diego Garcia"},
+ {253 ,"Djibouti"},
+ {109 ,"Dominica"},
+ {110 ,"Dominican Republic"},
+ {593 ,"Ecuador"},
+ {20 ,"Egypt"},
+ {503 ,"El Salvador"},
+ {240 ,"Equatorial Guinea"},
+ {291 ,"Eritrea"},
+ {372 ,"Estonia"},
+ {251 ,"Ethiopia"},
+ {500 ,"Falkland Islands (Malvinas)"}, /* was "Falkland Islands" */
+ {298 ,"Faroe Islands"}, /* was "Faeroe Islands" */
+ {679 ,"Fiji"},
+ {358 ,"Finland"},
+ {33 ,"France"},
+ {5901,"French Antilles"},
+ {594 ,"French Guiana"},
+ {689 ,"French Polynesia"},
+ {241 ,"Gabon"},
+ {220 ,"Gambia"},
+ {995 ,"Georgia"},
+ {49 ,"Germany"},
+ {233 ,"Ghana"},
+ {350 ,"Gibraltar"},
+ {30 ,"Greece"},
+ {299 ,"Greenland"},
+ {111 ,"Grenada"},
+ {590 ,"Guadeloupe"},
+ {671 ,"Guam, US Territory of"},
+ {5399,"Guantanamo Bay"}, /* was missing */
+ {502 ,"Guatemala"},
+ {224 ,"Guinea"},
+ {245 ,"Guinea-Bissau"},
+ {592 ,"Guyana"},
+ {509 ,"Haiti"},
+ {504 ,"Honduras"},
+ {852 ,"Hong Kong"},
+ {36 ,"Hungary"},
+ {354 ,"Iceland"},
+ {91 ,"India"},
+ {62 ,"Indonesia"},
+ {98 ,"Iran (Islamic Republic of)"},
+ {964 ,"Iraq"},
+ {353 ,"Ireland"},
+ {972 ,"Israel"},
+ {39 ,"Italy"},
+ {112 ,"Jamaica"},
+ {81 ,"Japan"},
+ {962 ,"Jordan"},
+ {705 ,"Kazakhstan"},
+ {254 ,"Kenya"},
+ {686 ,"Kiribati"},
+ {850 ,"Korea, North"},
+ {82 ,"Korea, South"},
+ {965 ,"Kuwait"},
+ {706 ,"Kyrgyzstan"},
+ {856 ,"Laos"},
+ {371 ,"Latvia"},
+ {961 ,"Lebanon"},
+ {266 ,"Lesotho"},
+ {231 ,"Liberia"},
+ {218 ,"Libyan Arab Jamahiriya"},
+ {4101,"Liechtenstein"},
+ {370 ,"Lithuania"},
+ {352 ,"Luxembourg"},
+ {853 ,"Macau"},
+ {389 ,"Macedonia (F.Y.R.O.M.)"},
+ {261 ,"Madagascar"},
+ {265 ,"Malawi"},
+ {60 ,"Malaysia"},
+ {960 ,"Maldives"},
+ {223 ,"Mali"},
+ {356 ,"Malta"},
+ {692 ,"Marshall Islands"},
+ {596 ,"Martinique"},
+ {222 ,"Mauritania"},
+ {230 ,"Mauritius"},
+ {269 ,"Mayotte Island"},
+ {52 ,"Mexico"},
+ {691 ,"Micronesia, Federated States of"},
+ {373 ,"Moldova, Republic of"},
+ {377 ,"Monaco"},
+ {976 ,"Mongolia"},
+ {382 ,"Montenegro, Republic of"}, /* was "Yugoslavia - Montenegro" */
+ {113 ,"Montserrat"},
+ {212 ,"Morocco"},
+ {258 ,"Mozambique"},
+ {95 ,"Myanmar"},
+ {264 ,"Namibia"},
+ {674 ,"Nauru"},
+ {977 ,"Nepal"},
+ {31 ,"Netherlands"},
+ {599 ,"Netherlands Antilles"},
+ {114 ,"Nevis"},
+ {687 ,"New Caledonia"},
+ {64 ,"New Zealand"},
+ {505 ,"Nicaragua"},
+ {227 ,"Niger"},
+ {234 ,"Nigeria"},
+ {683 ,"Niue"},
+ {6722,"Norfolk Island"},
+ {47 ,"Norway"},
+ {968 ,"Oman"},
+ {92 ,"Pakistan"},
+ {680 ,"Palau"},
+ {507 ,"Panama"},
+ {675 ,"Papua New Guinea"},
+ {595 ,"Paraguay"},
+ {51 ,"Peru"},
+ {63 ,"Philippines"},
+ {48 ,"Poland"},
+ {351 ,"Portugal"},
+ {121 ,"Puerto Rico"},
+ {974 ,"Qatar"},
+ {262 ,"Reunion Island"},
+ {40 ,"Romania"},
+ {6701,"Rota Island"},
+ {7 ,"Russia"},
+ {250 ,"Rwanda"},
+ {290 ,"Saint Helena"},
+ {115 ,"Saint Kitts"},
+ {1141,"Saint Kitts and Nevis"},
+ {122 ,"Saint Lucia"},
+ {508 ,"Saint Pierre and Miquelon"},
+ {116 ,"Saint Vincent and the Grenadines"},
+ {670 ,"Saipan Island (Northern Mariana Islands)"}, /* was "Saipan Island" */
+ {685 ,"Samoa"}, /* was "Western Samoa" */
+ {378 ,"San Marino"},
+ {239 ,"Sao Tome and Principe"},
+ {966 ,"Saudi Arabia"},
+ {442 ,"Scotland"},
+ {221 ,"Senegal"},
+ {381 ,"Serbia, Republic of"}, /* was "Yugoslavia" */
+ {248 ,"Seychelles"},
+ {232 ,"Sierra Leone"},
+ {65 ,"Singapore"},
+ {421 ,"Slovakia"},
+ {386 ,"Slovenia"},
+ {677 ,"Solomon Islands"},
+ {252 ,"Somalia"},
+ {27 ,"South Africa"},
+ {34 ,"Spain"},
+ {94 ,"Sri Lanka"},
+ {249 ,"Sudan"},
+ {597 ,"Suriname"},
+ {268 ,"Swaziland"},
+ {46 ,"Sweden"},
+ {41 ,"Switzerland"},
+ {963 ,"Syrian Arab Republic"},
+ {886 ,"Taiwan"},
+ {708 ,"Tajikistan"},
+ {255 ,"Tanzania"},
+ {66 ,"Thailand"},
+ {6702,"Tinian Island"},
+ {228 ,"Togo"},
+ {690 ,"Tokelau"},
+ {676 ,"Tonga"},
+ {117 ,"Trinidad and Tobago"},
+ {216 ,"Tunisia"},
+ {90 ,"Turkey"},
+ {709 ,"Turkmenistan"},
+ {118 ,"Turks and Caicos Islands"},
+ {688 ,"Tuvalu"},
+ {256 ,"Uganda"},
+ {380 ,"Ukraine"},
+ {971 ,"United Arab Emirates"},
+ {44 ,"United Kingdom"},
+ {598 ,"Uruguay"},
+ {1 ,"USA"},
+ {711 ,"Uzbekistan"},
+ {678 ,"Vanuatu"},
+ {379 ,"Vatican City"},
+ {58 ,"Venezuela"},
+ {84 ,"Vietnam"},
+ {123 ,"Virgin Islands (USA)"},
+ {441 ,"Wales"},
+ {681 ,"Wallis and Futuna Islands"},
+ {967 ,"Yemen"},
+ //{3811,"Yugoslavia - Serbia"}, /* removed */
+ {260 ,"Zambia"},
+ {263 ,"Zimbabwe"},
+};
+
+static INT_PTR ServiceGetCountryByNumber(WPARAM wParam,LPARAM lParam)
+{
+ int i;
+ UNREFERENCED_PARAMETER(lParam);
+ for(i=0; i<SIZEOF(countries); ++i)
+ if ((int)wParam==countries[i].id)
+ return (int)countries[i].szName;
+ return (int)(char*)NULL;
+}
+
+static INT_PTR ServiceGetCountryList(WPARAM wParam,LPARAM lParam)
+{
+ if ((int*)wParam==NULL || (void*)lParam==NULL) return 1;
+ *(int*)wParam=SIZEOF(countries);
+ *(struct CountryListEntry**)lParam=countries;
+ return 0;
+}
+
+/************************* Misc ***********************************/
+
+static DWORD NameHashFunction(const char *szStr)
+{
+#if defined _M_IX86 && !defined _NUMEGA_BC_FINALCHECK && !defined NOINLINEASM
+ __asm {
+ xor edx,edx
+ xor eax,eax
+ mov esi,szStr
+ mov al,[esi]
+ dec esi
+ xor cl,cl
+ lph_top: //only 4 of 9 instructions in here don't use AL, so optimal pipe use is impossible
+ xor edx,eax
+ inc esi
+ and cl,31
+ movzx eax,byte ptr [esi]
+ add cl,5
+ test al,al
+ rol eax,cl //rol is u-pipe only, but pairable
+ //rol doesn't touch z-flag
+ jnz lph_top //5 clock tick loop. not bad.
+
+ xor eax,edx
+ }
+#else
+ DWORD hash=0;
+ int i;
+ int shift=0;
+ for(i=0;szStr[i];i++) {
+ hash^=szStr[i]<<shift;
+ if (shift>24) hash^=(szStr[i]>>(32-shift))&0x7F;
+ shift=(shift+5)&0x1F;
+ }
+ return hash;
+#endif
+}
+
+void InitCountryListExt(void)
+{
+ /* hack to replace built-in country list */
+ DestroyServiceFunction((HANDLE)NameHashFunction(MS_UTILS_GETCOUNTRYLIST));
+ DestroyServiceFunction((HANDLE)NameHashFunction(MS_UTILS_GETCOUNTRYBYNUMBER));
+ hServiceGetList=CreateServiceFunction(MS_UTILS_GETCOUNTRYLIST,ServiceGetCountryList);
+ hServiceGetByNumber=CreateServiceFunction(MS_UTILS_GETCOUNTRYBYNUMBER,ServiceGetCountryByNumber);
+}
+
+void UninitCountryListExt(void)
+{
+ DestroyServiceFunction(hServiceGetList);
+ DestroyServiceFunction(hServiceGetByNumber);
+}
diff --git a/plugins/CountryFlags/src/extraimg.cpp b/plugins/CountryFlags/src/extraimg.cpp new file mode 100644 index 0000000000..f019827e21 --- /dev/null +++ b/plugins/CountryFlags/src/extraimg.cpp @@ -0,0 +1,494 @@ +/*
+Miranda IM Country Flags Plugin
+Copyright (C) 2006-1007 H. Herkenrath
+
+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 (Flags-License.txt); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "flags.h"
+
+/* Services */
+static HANDLE hServiceDetectContactOrigin;
+/* Extra Image */
+static HANDLE hHookExtraRebuild,hHookExtraApply;
+/* Status Icon */
+static HANDLE hHookMsgWndEvent,hHookIconsChanged;
+/* Options */
+static HANDLE hHookOptInit,hHookSettingChanged;
+/* Misc */
+extern HINSTANCE hInst;
+extern int nCountriesCount;
+extern struct CountryListEntry *countries;
+static HANDLE hHookModulesLoaded;
+
+/************************* Services *******************************/
+
+static INT_PTR ServiceDetectContactOriginCountry(WPARAM wParam,LPARAM lParam)
+{
+ int countryNumber=0xFFFF;
+ char *pszProto;
+ UNREFERENCED_PARAMETER(lParam);
+ pszProto=(char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,wParam,0);
+ /* ip detect */
+ if(DBGetContactSettingByte(NULL,"Flags","UseIpToCountry",SETTING_USEIPTOCOUNTRY_DEFAULT))
+ countryNumber=ServiceIpToCountry(DBGetContactSettingDword((HANDLE)wParam,pszProto,"RealIP",0),0);
+ /* fallback */
+ if(countryNumber==0xFFFF)
+ countryNumber=DBGetContactSettingWord((HANDLE)wParam,pszProto,"Country",0);
+ if(countryNumber==0 || countryNumber==0xFFFF)
+ countryNumber=DBGetContactSettingWord((HANDLE)wParam,pszProto,"CompanyCountry",0);
+ return (countryNumber==0)?0xFFFF:countryNumber;
+}
+
+/************************* Extra Image ****************************/
+
+#define EXTRAIMAGE_REFRESHDELAY 100 /* time for which setting changes are buffered */
+
+static HANDLE *phExtraImages;
+static BYTE idExtraColumn;
+
+static void CALLBACK SetExtraImage(LPARAM lParam)
+{
+ IconExtraColumn iec;
+ int countryNumber,index;
+ if(DBGetContactSettingByte(NULL,"Flags","ShowExtraImgFlag",SETTING_SHOWEXTRAIMGFLAG_DEFAULT)) {
+ /* get contact's country */
+ iec.hImage=INVALID_HANDLE_VALUE;
+ countryNumber=ServiceDetectContactOriginCountry((WPARAM)lParam,0);
+ /* get icon */
+ if(phExtraImages!=NULL) /* too early? */
+ if(countryNumber!=0xFFFF || DBGetContactSettingByte(NULL,"Flags","UseUnknownFlag",SETTING_USEUNKNOWNFLAG_DEFAULT)) {
+ index=CountryNumberToIndex(countryNumber);
+ /* icon not yet loaded? */
+ if(phExtraImages[index]==INVALID_HANDLE_VALUE) {
+ HICON hIcon;
+ hIcon=LoadFlagIcon(countryNumber);
+ if(hIcon!=NULL) phExtraImages[index]=(HANDLE)CallService(MS_CLIST_EXTRA_ADD_ICON,(WPARAM)hIcon,0);
+ CallService(MS_SKIN2_RELEASEICON,(WPARAM)hIcon,0); /* does NULL check */
+ }
+ iec.hImage=phExtraImages[index];
+ }
+ /* choose column */
+ iec.cbSize=sizeof(iec);
+ iec.ColumnType=idExtraColumn;
+ CallService(MS_CLIST_EXTRA_SET_ICON,(WPARAM)lParam,(LPARAM)&iec);
+ }
+}
+
+// always call in context of main thread
+static void RemoveExtraImages(void)
+{
+ IconExtraColumn iec;
+ register HANDLE hContact;
+ /* choose column */
+ iec.cbSize=sizeof(iec);
+ iec.ColumnType=idExtraColumn;
+ iec.hImage=INVALID_HANDLE_VALUE;
+ /* enum all contacts */
+ hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0);
+ while(hContact!=NULL) {
+ /* invalidate icon */
+ CallService(MS_CLIST_EXTRA_SET_ICON,(WPARAM)hContact,(LPARAM)&iec);
+ hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,0);
+ }
+}
+
+// always call in context of main thread
+static void EnsureExtraImages(void)
+{
+ register HANDLE hContact;
+ BYTE idMaxExtraCol,idExtraColumnNew;
+ /* choose column */
+ idMaxExtraCol=(BYTE)CallService(MS_CLUI_GETCAPS,0,CLUIF2_EXTRACOLUMNCOUNT); /* 1-based count */
+ if(idMaxExtraCol==(BYTE)CallService(MS_CLUI_GETCAPS,0,CLUIF2_USEREXTRASTART)) /* same flags if not present */
+ idMaxExtraCol=EXTRA_ICON_ADV2; /* zero if not present */
+ idExtraColumnNew=DBGetContactSettingRangedByte(NULL,"Flags","ExtraImgFlagColumn",SETTING_EXTRAIMGFLAGCOLUMN_DEFAULT,1,idMaxExtraCol);
+ /* clear previous column */
+ if(idExtraColumnNew!=idExtraColumn) RemoveExtraImages();
+ idExtraColumn=idExtraColumnNew;
+ /* enum all contacts */
+ hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0);
+ while(hContact!=NULL) {
+ CallFunctionBuffered(SetExtraImage,(LPARAM)hContact,TRUE,EXTRAIMAGE_REFRESHDELAY);
+ hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,0);
+ }
+}
+
+static void CALLBACK UpdateExtraImages(LPARAM lParam)
+{
+ UNREFERENCED_PARAMETER(lParam);
+ if(DBGetContactSettingByte(NULL,"Flags","ShowExtraImgFlag",SETTING_SHOWEXTRAIMGFLAG_DEFAULT))
+ EnsureExtraImages();
+ else RemoveExtraImages();
+}
+
+static int ExtraListRebuild(WPARAM wParam,LPARAM lParam)
+{
+ BYTE idMaxExtraCol;
+ int i;
+ UNREFERENCED_PARAMETER(wParam);
+ UNREFERENCED_PARAMETER(lParam);
+ OutputDebugStringA("REBUILD EXTRA\n");
+ /* invalidate icons */
+ if(phExtraImages!=NULL)
+ for(i=0;i<nCountriesCount;++i)
+ phExtraImages[i]=INVALID_HANDLE_VALUE;
+ /* choose column */
+ idMaxExtraCol=(BYTE)CallService(MS_CLUI_GETCAPS,0,CLUIF2_EXTRACOLUMNCOUNT); /* 1-based count */
+ if(idMaxExtraCol==(BYTE)CallService(MS_CLUI_GETCAPS,0,CLUIF2_USEREXTRASTART)) /* same flags if not present */
+ idMaxExtraCol=EXTRA_ICON_ADV2; /* zero if not present */
+ idExtraColumn=DBGetContactSettingRangedByte(NULL,"Flags","ExtraImgFlagColumn",SETTING_EXTRAIMGFLAGCOLUMN_DEFAULT,1,idMaxExtraCol);
+ return 0;
+}
+
+static int ExtraImageApply(WPARAM wParam,LPARAM lParam)
+{
+ UNREFERENCED_PARAMETER(lParam);
+ OutputDebugStringA("APPLY EXTRA\n");
+ if(DBGetContactSettingByte(NULL,"Flags","ShowExtraImgFlag",SETTING_SHOWEXTRAIMGFLAG_DEFAULT))
+ SetExtraImage((LPARAM)wParam); /* unbuffered */
+ return 0;
+}
+
+/************************* Status Icon ****************************/
+
+#define STATUSICON_REFRESHDELAY 100 /* time for which setting changes are buffered */
+
+// always call in context of main thread
+static void FASTCALL SetStatusIcon(HANDLE hContact,int countryNumber)
+{
+ int i;
+ HICON hIcon=NULL;
+ StatusIconData sid;
+
+ if(countryNumber!=0xFFFF || DBGetContactSettingByte(NULL,"Flags","UseUnknownFlag",SETTING_USEUNKNOWNFLAG_DEFAULT)) {
+ /* copy icon as status icon API will call DestroyIcon() on it */
+ hIcon=LoadFlagIcon(countryNumber);
+ sid.hIcon=(hIcon!=NULL)?CopyIcon(hIcon):NULL;
+ CallService(MS_SKIN2_RELEASEICON,(WPARAM)hIcon,0); /* does NULL check */
+ hIcon=sid.hIcon;
+ /* ensure status icon is registered */
+ sid.cbSize=sizeof(sid);
+ sid.szModule="Flags";
+ sid.dwId=countryNumber;
+ sid.hIconDisabled=NULL;
+ sid.flags=0;
+ sid.szTooltip=Translate((char*)CallService(MS_UTILS_GETCOUNTRYBYNUMBER,countryNumber,0));
+ if(CallService(MS_MSG_MODIFYICON,0,(LPARAM)&sid)) /* not yet registered? */
+ CallService(MS_MSG_ADDICON,0,(LPARAM)&sid);
+ }
+ /* disable all other flags for this contact */
+ sid.hIcon=NULL;
+ sid.szTooltip=NULL;
+ sid.flags=MBF_HIDDEN;
+ for(i=0;i<nCountriesCount;++i) {
+ sid.dwId=countries[i].id;
+ if(countryNumber==countries[i].id && hIcon!=NULL) sid.flags=0;
+ else sid.flags=MBF_HIDDEN;
+ CallService(MS_MSG_MODIFYICON,(WPARAM)hContact,(LPARAM)&sid);
+ }
+}
+
+// always call in context of main thread
+static void FASTCALL UnsetStatusIcon(HANDLE hContact,int countryNumber)
+{
+ StatusIconData sid;
+ sid.cbSize=sizeof(sid);
+ sid.szModule="Flags";
+ sid.dwId=countryNumber;
+ sid.hIconDisabled=sid.hIcon=NULL;
+ sid.szTooltip=NULL;
+ sid.flags=MBF_HIDDEN;
+ CallService(MS_MSG_MODIFYICON,(WPARAM)hContact,(LPARAM)&sid); /* registered? */
+ /* can't call MS_MSG_REMOVEICON here as the icon might be
+ * in use by other contacts simultanously, removing them all at exit */
+}
+
+static int MsgWndEvent(WPARAM wParam,LPARAM lParam)
+{
+ MessageWindowEventData *msgwe=(MessageWindowEventData*)lParam;
+ UNREFERENCED_PARAMETER(wParam);
+ switch(msgwe->uType) {
+ case MSG_WINDOW_EVT_OPENING:
+ case MSG_WINDOW_EVT_CLOSE:
+ { int countryNumber;
+ if(msgwe->hContact==NULL || !ServiceExists(MS_MSG_ADDICON)) break; /* sanity check */
+ countryNumber=ServiceDetectContactOriginCountry((WPARAM)msgwe->hContact,0);
+ if(DBGetContactSettingByte(NULL,"Flags","ShowStatusIconFlag",SETTING_SHOWSTATUSICONFLAG_DEFAULT)) {
+ if(msgwe->uType==MSG_WINDOW_EVT_OPENING) SetStatusIcon(msgwe->hContact,countryNumber);
+ else UnsetStatusIcon(msgwe->hContact,countryNumber);
+ }
+ /* ensure it is hidden, RemoveStatusIcons() only enums currently opened ones */
+ else UnsetStatusIcon(msgwe->hContact,countryNumber);
+ }
+ }
+ return 0;
+}
+
+static void CALLBACK UpdateStatusIcons(LPARAM lParam)
+{
+ MessageWindowInputData msgwi; /* input */
+ MessageWindowData msgw; /* output */
+ BOOL fShow;
+ int countryNumber;
+ UNREFERENCED_PARAMETER(lParam);
+
+ msgwi.cbSize=sizeof(msgwi);
+ msgw.cbSize=sizeof(msgw);
+ msgwi.uFlags=MSG_WINDOW_UFLAG_MSG_BOTH;
+ /* enum all opened message windows */
+ fShow=DBGetContactSettingByte(NULL,"Flags","ShowStatusIconFlag",SETTING_SHOWSTATUSICONFLAG_DEFAULT);
+ msgwi.hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0);
+ while(msgwi.hContact!=NULL) {
+ /* is a message window opened for this contact? */
+ if (!CallService(MS_MSG_GETWINDOWDATA,(WPARAM)&msgwi,(LPARAM)&msgw) && msgw.uState&MSG_WINDOW_STATE_EXISTS) {
+ countryNumber=ServiceDetectContactOriginCountry((WPARAM)msgwi.hContact,0);
+ if(fShow) SetStatusIcon(msgwi.hContact,countryNumber);
+ else UnsetStatusIcon(msgwi.hContact,countryNumber);
+ }
+ msgwi.hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)msgw.hContact,0);
+ }
+}
+
+static int StatusIconsChanged(WPARAM wParam,LPARAM lParam)
+{
+ UNREFERENCED_PARAMETER(wParam);
+ UNREFERENCED_PARAMETER(lParam);
+ if(ServiceExists(MS_MSG_ADDICON))
+ if(DBGetContactSettingByte(NULL,"Flags","ShowStatusIconFlag",SETTING_SHOWSTATUSICONFLAG_DEFAULT))
+ CallFunctionBuffered(UpdateStatusIcons,0,FALSE,STATUSICON_REFRESHDELAY);
+ return 0;
+}
+
+/************************* Options ************************************/
+
+#define M_ENABLE_SUBCTLS (WM_APP+1)
+
+static INT_PTR CALLBACK ExtraImgOptDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
+{
+ UNREFERENCED_PARAMETER(wParam);
+ switch(msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ /* init checkboxes */
+ { BOOL val;
+ /* Status Icon */
+ if(ServiceExists(MS_MSG_ADDICON)) val=DBGetContactSettingByte(NULL,"Flags","ShowStatusIconFlag",SETTING_SHOWSTATUSICONFLAG_DEFAULT)!=0;
+ else EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_SHOWSTATUSICONFLAG),val=FALSE);
+ CheckDlgButton(hwndDlg,IDC_CHECK_SHOWSTATUSICONFLAG,val);
+ /* Extra Image */
+ if(ServiceExists(MS_CLIST_EXTRA_ADD_ICON)) val=DBGetContactSettingByte(NULL,"Flags","ShowExtraImgFlag",SETTING_SHOWEXTRAIMGFLAG_DEFAULT)!=0;
+ else EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_SHOWEXTRAIMGFLAG),val=FALSE);
+ CheckDlgButton(hwndDlg,IDC_CHECK_SHOWEXTRAIMGFLAG,val);
+ /* Unknown Flag */
+ val=DBGetContactSettingByte(NULL,"Flags","UseUnknownFlag",SETTING_USEUNKNOWNFLAG_DEFAULT)!=0;
+ CheckDlgButton(hwndDlg,IDC_CHECK_USEUNKNOWNFLAG,val);
+ /* IP-to-country */
+ val=DBGetContactSettingByte(NULL,"Flags","UseIpToCountry",SETTING_USEIPTOCOUNTRY_DEFAULT)!=0;
+ CheckDlgButton(hwndDlg,IDC_CHECK_USEIPTOCOUNTRY,val);
+ }
+ /* init combobox */
+ { HWND hwndCombo;
+ TCHAR szItem[64];
+ BYTE idColumn,idSavedColumn;
+ BYTE idMaxExtraCol,idAdvExtraColStart;
+ int index;
+ hwndCombo=GetDlgItem(hwndDlg,IDC_COMBO_EXTRAIMGFLAGCOLUMN);
+ idSavedColumn=DBGetContactSettingByte(NULL,"Flags","ExtraImgFlagColumn",SETTING_EXTRAIMGFLAGCOLUMN_DEFAULT);
+ idMaxExtraCol=(BYTE)CallService(MS_CLUI_GETCAPS,0,CLUIF2_EXTRACOLUMNCOUNT); /* 1-based count */
+ idAdvExtraColStart=(BYTE)CallService(MS_CLUI_GETCAPS,0,CLUIF2_USEREXTRASTART); /* 1-based id */
+ /* init */
+ SendMessage(hwndCombo,CB_SETLOCALE,(LCID)CallService(MS_LANGPACK_GETLOCALE,0,0),0); /* for sort order */
+ SendMessage(hwndCombo,CB_INITSTORAGE,idMaxExtraCol-idAdvExtraColStart+3,(idMaxExtraCol-idAdvExtraColStart+3)*SIZEOF(szItem));
+ /* Advanced #1,#2 */
+ { const BYTE columnIds[]={EXTRA_ICON_ADV1,EXTRA_ICON_ADV2};
+ for(idColumn=0;idColumn<SIZEOF(columnIds);++idColumn) {
+ mir_sntprintf(szItem,SIZEOF(szItem),TranslateT("Advanced #%u"),idColumn+1); /* buffer safe */
+ index=SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)szItem);
+ if(index!=LB_ERR) {
+ SendMessage(hwndCombo,CB_SETITEMDATA,index,columnIds[idColumn]);
+ if(idColumn==0 || columnIds[idColumn]==idSavedColumn) SendMessage(hwndCombo,CB_SETCURSEL,index,0);
+ }
+ }
+ }
+ /* Advanced #3+: clist_modern */
+ if(idMaxExtraCol!=idAdvExtraColStart) /* same flags if not present */
+ for(idColumn=idAdvExtraColStart;idColumn<=idMaxExtraCol;++idColumn) {
+ mir_sntprintf(szItem,SIZEOF(szItem),TranslateT("Advanced #%u"),idColumn-idAdvExtraColStart+3); /* buffer safe */
+ index=SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)szItem);
+ if(index!=LB_ERR) {
+ SendMessage(hwndCombo,CB_SETITEMDATA,index,idColumn);
+ if(idColumn==idSavedColumn) SendMessage(hwndCombo,CB_SETCURSEL,index,0);
+ }
+ }
+ }
+ SendMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
+ return TRUE; /* default focus */
+ case M_ENABLE_SUBCTLS:
+ { BOOL checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_SHOWEXTRAIMGFLAG);
+ EnableWindow(GetDlgItem(hwndDlg,IDC_TEXT_EXTRAIMGFLAGCOLUMN),checked);
+ EnableWindow(GetDlgItem(hwndDlg,IDC_COMBO_EXTRAIMGFLAGCOLUMN),checked);
+ if (!checked) checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_SHOWSTATUSICONFLAG);
+ EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_USEUNKNOWNFLAG),checked);
+ EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_USEIPTOCOUNTRY),checked);
+ return TRUE;
+ }
+ case WM_COMMAND:
+ PostMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
+ PostMessage(GetParent(hwndDlg),PSM_CHANGED,0,0); /* enable apply */
+ return FALSE;
+ case WM_NOTIFY:
+ switch(((NMHDR*)lParam)->code) {
+ case PSN_APPLY: /* setting change hook will pick these up */
+ DBWriteContactSettingByte(NULL,"Flags","UseUnknownFlag",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_USEUNKNOWNFLAG)!=0));
+ DBWriteContactSettingByte(NULL,"Flags","UseIpToCountry",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_USEIPTOCOUNTRY)!=0));
+ /* Status Icon */
+ if(IsWindowEnabled(GetDlgItem(hwndDlg,IDC_CHECK_SHOWSTATUSICONFLAG)))
+ DBWriteContactSettingByte(NULL,"Flags","ShowStatusIconFlag",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SHOWSTATUSICONFLAG)!=0));
+ /* Extra Image */
+ if(IsWindowEnabled(GetDlgItem(hwndDlg,IDC_CHECK_SHOWEXTRAIMGFLAG)))
+ DBWriteContactSettingByte(NULL,"Flags","ShowExtraImgFlag",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SHOWEXTRAIMGFLAG)!=0));
+ { int index;
+ index=SendDlgItemMessage(hwndDlg,IDC_COMBO_EXTRAIMGFLAGCOLUMN,CB_GETCURSEL,0,0);
+ if(index!=LB_ERR) DBWriteContactSettingByte(NULL,"Flags","ExtraImgFlagColumn",(BYTE)SendDlgItemMessage(hwndDlg,IDC_COMBO_EXTRAIMGFLAGCOLUMN,CB_GETITEMDATA,index,0));
+ }
+ return TRUE;
+ }
+ break;
+ }
+ return FALSE;
+}
+
+static UINT expertOnlyControls[]={IDC_CHECK_USEIPTOCOUNTRY};
+static int ExtraImgOptInit(WPARAM wParam,LPARAM lParam)
+{
+ OPTIONSDIALOGPAGE odp = { 0 };
+ UNREFERENCED_PARAMETER(lParam);
+ odp.cbSize = sizeof(odp);
+ odp.hInstance = hInst;
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_EXTRAIMG);
+ odp.position = 900000002;
+ odp.pszGroup = LPGEN("Contact List"); /* autotranslated */
+ odp.pszTitle = LPGEN("Country Flags"); /* autotranslated */
+ odp.pszTab = LPGEN("Country Flags"); /* autotranslated, can be made a tab */
+ odp.flags = ODPF_BOLDGROUPS;
+ odp.pfnDlgProc = ExtraImgOptDlgProc;
+ odp.expertOnlyControls = expertOnlyControls;
+ odp.nExpertOnlyControls = SIZEOF(expertOnlyControls);
+ Options_AddPage(wParam, &odp);
+ return 0;
+}
+
+static int ExtraImgSettingChanged(WPARAM wParam,LPARAM lParam)
+{
+ DBCONTACTWRITESETTING *dbcws=(DBCONTACTWRITESETTING*)lParam;
+ if ((HANDLE)wParam==NULL) {
+ if (!lstrcmpA(dbcws->szModule,"Flags")) {
+ /* Extra Image */
+ if (!lstrcmpA(dbcws->szSetting,"ShowExtraImgFlag") ||
+ !lstrcmpA(dbcws->szSetting,"ExtraImgFlagColumn") ||
+ !lstrcmpA(dbcws->szSetting,"UseUnknownFlag") ||
+ !lstrcmpA(dbcws->szSetting,"UseIpToCountry"))
+ if(ServiceExists(MS_CLIST_EXTRA_SET_ICON))
+ CallFunctionBuffered(UpdateExtraImages,0,FALSE,EXTRAIMAGE_REFRESHDELAY);
+ /* Status Icon */
+ if (!lstrcmpA(dbcws->szSetting,"ShowStatusIconFlag") ||
+ !lstrcmpA(dbcws->szSetting,"UseUnknownFlag") ||
+ !lstrcmpA(dbcws->szSetting,"UseIpToCountry"))
+ if(ServiceExists(MS_MSG_ADDICON))
+ CallFunctionBuffered(UpdateStatusIcons,0,FALSE,STATUSICON_REFRESHDELAY);
+ }
+ }
+ /* user details update */
+ else if (!lstrcmpA(dbcws->szSetting,"RealIP") ||
+ !lstrcmpA(dbcws->szSetting,"Country") ||
+ !lstrcmpA(dbcws->szSetting,"CompanyCountry")) {
+ /* Extra Image */
+ if(ServiceExists(MS_CLIST_EXTRA_SET_ICON))
+ CallFunctionBuffered(SetExtraImage,(LPARAM)wParam,TRUE,EXTRAIMAGE_REFRESHDELAY);
+ /* Status Icon */
+ if(ServiceExists(MS_MSG_ADDICON))
+ CallFunctionBuffered(UpdateStatusIcons,0,FALSE,STATUSICON_REFRESHDELAY);
+ }
+ return 0;
+}
+
+/************************* Misc ***********************************/
+
+static int ExtraImgModulesLoaded(WPARAM wParam,LPARAM lParam)
+{
+ UNREFERENCED_PARAMETER(wParam);
+ UNREFERENCED_PARAMETER(lParam);
+ /* Options */
+ if(ServiceExists("DBEditorpp/RegisterSingleModule"))
+ CallService("DBEditorpp/RegisterSingleModule",(WPARAM)"Flags",0);
+ /* Extra Image */
+ if(ServiceExists(MS_CLIST_EXTRA_SET_ICON)) {
+ int i;
+ BYTE idMaxExtraCol;
+ phExtraImages=(HANDLE*)mir_alloc(nCountriesCount*sizeof(HANDLE));
+ /* invalidate icons */
+ if(phExtraImages!=NULL)
+ for(i=0;i<nCountriesCount;++i)
+ phExtraImages[i]=INVALID_HANDLE_VALUE;
+ /* choose column */
+ idMaxExtraCol=(BYTE)CallService(MS_CLUI_GETCAPS,0,CLUIF2_EXTRACOLUMNCOUNT); /* 1-based count */
+ if(idMaxExtraCol==(BYTE)CallService(MS_CLUI_GETCAPS,0,CLUIF2_USEREXTRASTART)) /* same flags if not present */
+ idMaxExtraCol=EXTRA_ICON_ADV2; /* zero if not present */
+ idExtraColumn=DBGetContactSettingRangedByte(NULL,"Flags","ExtraImgFlagColumn",SETTING_EXTRAIMGFLAGCOLUMN_DEFAULT,1,idMaxExtraCol);
+ /* hook */
+ hHookExtraRebuild=HookEvent(ME_CLIST_EXTRA_LIST_REBUILD,ExtraListRebuild);
+ hHookExtraApply=HookEvent(ME_CLIST_EXTRA_IMAGE_APPLY,ExtraImageApply);
+ }
+ /* Status Icon */
+ hHookMsgWndEvent=HookEvent(ME_MSG_WINDOWEVENT,MsgWndEvent);
+ return 0;
+}
+
+void InitExtraImg(void)
+{
+ /* Services */
+ hServiceDetectContactOrigin=CreateServiceFunction(MS_FLAGS_DETECTCONTACTORIGINCOUNTRY,ServiceDetectContactOriginCountry);
+ /* Misc */
+ hHookModulesLoaded=HookEvent(ME_SYSTEM_MODULESLOADED,ExtraImgModulesLoaded);
+ /* Extra Image */
+ phExtraImages=NULL;
+ hHookExtraRebuild=hHookExtraApply=NULL;
+ /* Status icon */
+ hHookMsgWndEvent=NULL;
+ hHookIconsChanged=HookEvent(ME_SKIN2_ICONSCHANGED,StatusIconsChanged);
+ /* Options */
+ hHookOptInit=HookEvent(ME_OPT_INITIALISE,ExtraImgOptInit);
+ hHookSettingChanged=HookEvent(ME_DB_CONTACT_SETTINGCHANGED,ExtraImgSettingChanged);
+}
+
+void UninitExtraImg(void)
+{
+ /* Services */
+ DestroyServiceFunction(hServiceDetectContactOrigin);
+ /* Misc */
+ UnhookEvent(hHookModulesLoaded);
+ /* Extra Image */
+ UnhookEvent(hHookSettingChanged);
+ UnhookEvent(hHookExtraRebuild);
+ UnhookEvent(hHookExtraApply);
+ mir_free(phExtraImages); /* does NULL check */
+ /* Status icon */
+ UnhookEvent(hHookMsgWndEvent);
+ UnhookEvent(hHookIconsChanged);
+ /* Options */
+ UnhookEvent(hHookOptInit);
+ UnhookEvent(hHookSettingChanged);
+}
diff --git a/plugins/CountryFlags/src/flags.h b/plugins/CountryFlags/src/flags.h new file mode 100644 index 0000000000..c91876bd97 --- /dev/null +++ b/plugins/CountryFlags/src/flags.h @@ -0,0 +1,90 @@ +/*
+Miranda IM Country Flags Plugin
+Copyright (C) 2006-2007 H. Herkenrath
+
+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 (Flags-License.txt); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#define _CRT_SECURE_NO_WARNINGS
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#define NONAMELESSUNION
+#include <commctrl.h> /* for ImageList functions */
+#define NOWIN2K
+#include <win2k.h>
+#define MIRANDA_VER 0x0A00
+#include <stdio.h>
+#include <newpluginapi.h>
+#include <m_system.h>
+#include <m_utils.h>
+#include <m_langpack.h>
+#include <m_icolib.h>
+#include <m_clui.h>
+#include <m_cluiframes.h>
+#include <m_message.h>
+#include <m_database.h>
+#include <m_options.h>
+#include <m_contacts.h>
+#include <m_protocols.h>
+#define FLAGS_NOHELPERFUNCTIONS
+#include "m_flags.h"
+#include "resource.h"
+
+#if defined(_MSC_VER) && !defined(FASTCALL)
+ #define FASTCALL __fastcall
+#else
+ #define FASTCALL
+#endif
+#if defined(_DEBUG)
+ #undef FASTCALL
+ #define FASTCALL
+#endif
+
+/* countrylistext.c */
+void InitCountryListExt(void);
+void UninitCountryListExt(void);
+
+/* huffman.c */
+#ifdef HUFFMAN_ENCODE
+ int Huffman_Compress(unsigned char *in,unsigned char *out,unsigned int insize );
+#endif
+void Huffman_Uncompress(unsigned char *in,unsigned char *out,unsigned int insize,unsigned int outsize);
+
+/* icons.c */
+HICON FASTCALL LoadFlagIcon(int countryNumber);
+int FASTCALL CountryNumberToIndex(int countryNumber);
+void InitIcons(void);
+void UninitIcons(void);
+
+/* ip2country.c */
+INT_PTR ServiceIpToCountry(WPARAM wParam,LPARAM lParam);
+void InitIpToCountry(void);
+void UninitIpToCountry(void);
+
+/* extraimg.c */
+void InitExtraImg(void);
+void UninitExtraImg(void);
+
+/* utils.c */
+typedef void (CALLBACK *BUFFEREDPROC)(LPARAM lParam);
+#ifdef _DEBUG
+ void _CallFunctionBuffered(BUFFEREDPROC pfnBuffProc,const char *pszProcName,LPARAM lParam,BOOL fAccumulateSameParam,UINT uElapse);
+ #define CallFunctionBuffered(proc,param,acc,elapse) _CallFunctionBuffered(proc,#proc,param,acc,elapse)
+#else
+ void _CallFunctionBuffered(BUFFEREDPROC pfnBuffProc,LPARAM lParam,BOOL fAccumulateSameParam,UINT uElapse);
+ #define CallFunctionBuffered(proc,param,acc,elapse) _CallFunctionBuffered(proc,param,acc,elapse)
+#endif
+void PrepareBufferedFunctions(void);
+void KillBufferedFunctions(void);
diff --git a/plugins/CountryFlags/src/huffman.cpp b/plugins/CountryFlags/src/huffman.cpp new file mode 100644 index 0000000000..c460e9a66e --- /dev/null +++ b/plugins/CountryFlags/src/huffman.cpp @@ -0,0 +1,506 @@ +/*************************************************************************
+* Name: huffman.c
+* Author: Marcus Geelnard
+* Description: Huffman coder/decoder implementation.
+* Reentrant: Yes
+*
+* This is a very straight forward implementation of a Huffman coder and
+* decoder.
+*
+* Primary flaws with this primitive implementation are:
+* - Slow bit stream implementation
+* - Maximum tree depth of 32 (the coder aborts if any code exceeds a
+* size of 32 bits). If I'm not mistaking, this should not be possible
+* unless the input buffer is larger than 2^32 bytes, which is not
+* supported by the coder anyway (max 2^32-1 bytes can be specified with
+* an unsigned 32-bit integer).
+*
+* On the other hand, there are a few advantages of this implementation:
+* - The Huffman tree is stored in a very compact form, requiring only
+* 10 bits per symbol (for 8 bit symbols), meaning a maximum of 320
+* bytes overhead.
+* - The code should be fairly easy to follow, if you are familiar with
+* how the Huffman compression algorithm works.
+*
+* Possible improvements (probably not worth it):
+* - Partition the input data stream into blocks, where each block has
+* its own Huffman tree. With variable block sizes, it should be
+* possible to find locally optimal Huffman trees, which in turn could
+* reduce the total size.
+* - Allow for a few different predefined Huffman trees, which could
+* reduce the size of a block even further.
+*-------------------------------------------------------------------------
+* Copyright (c) 2003-2006 Marcus Geelnard
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+*
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would
+* be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not
+* be misrepresented as being the original software.
+*
+* 3. This notice may not be removed or altered from any source
+* distribution.
+*
+* Marcus Geelnard
+* marcus.geelnard at home.se
+*************************************************************************/
+
+
+/*************************************************************************
+* Types used for Huffman coding
+*************************************************************************/
+
+typedef struct {
+ unsigned char *BytePtr;
+ unsigned int BitPos;
+} huff_bitstream_t;
+
+typedef struct {
+ int Symbol;
+ unsigned int Count;
+ unsigned int Code;
+ unsigned int Bits;
+} huff_sym_t;
+
+typedef struct huff_encodenode_struct huff_encodenode_t;
+
+struct huff_encodenode_struct {
+ huff_encodenode_t *ChildA, *ChildB;
+ int Count;
+ int Symbol;
+};
+
+typedef struct huff_decodenode_struct huff_decodenode_t;
+
+struct huff_decodenode_struct {
+ huff_decodenode_t *ChildA, *ChildB;
+ int Symbol;
+};
+
+
+/*************************************************************************
+* Constants for Huffman decoding
+*************************************************************************/
+
+/* The maximum number of nodes in the Huffman tree is 2^(8+1)-1 = 511 */
+#define MAX_TREE_NODES 511
+
+
+/*************************************************************************
+* _Huffman_InitBitstream() - Initialize a bitstream.
+*************************************************************************/
+
+static void _Huffman_InitBitstream( huff_bitstream_t *stream,
+ unsigned char *buf )
+{
+ stream->BytePtr = buf;
+ stream->BitPos = 0;
+}
+
+
+/*************************************************************************
+* _Huffman_ReadBit() - Read one bit from a bitstream.
+*************************************************************************/
+
+static unsigned int _Huffman_ReadBit( huff_bitstream_t *stream )
+{
+ unsigned int x, bit;
+ unsigned char *buf;
+
+ /* Get current stream state */
+ buf = stream->BytePtr;
+ bit = stream->BitPos;
+
+ /* Extract bit */
+ x = (*buf & (1<<(7-bit))) ? 1 : 0;
+ bit = (bit+1) & 7;
+ if ( !bit )
+ {
+ ++ buf;
+ }
+
+ /* Store new stream state */
+ stream->BitPos = bit;
+ stream->BytePtr = buf;
+
+ return x;
+}
+
+
+/*************************************************************************
+* _Huffman_Read8Bits() - Read eight bits from a bitstream.
+*************************************************************************/
+
+static unsigned int _Huffman_Read8Bits( huff_bitstream_t *stream )
+{
+ unsigned int x, bit;
+ unsigned char *buf;
+
+ /* Get current stream state */
+ buf = stream->BytePtr;
+ bit = stream->BitPos;
+
+ /* Extract byte */
+ x = (*buf << bit) | (buf[1] >> (8-bit));
+ ++ buf;
+
+ /* Store new stream state */
+ stream->BytePtr = buf;
+
+ return x;
+}
+
+
+/*************************************************************************
+* _Huffman_WriteBits() - Write bits to a bitstream.
+*************************************************************************/
+
+#ifdef HUFFMAN_ENCODE
+static void _Huffman_WriteBits( huff_bitstream_t *stream, unsigned int x,
+ unsigned int bits )
+{
+ unsigned int bit, count;
+ unsigned char *buf;
+ unsigned int mask;
+
+ /* Get current stream state */
+ buf = stream->BytePtr;
+ bit = stream->BitPos;
+
+ /* Append bits */
+ mask = 1 << (bits-1);
+ for ( count = 0; count < bits; ++ count )
+ {
+ *buf = (unsigned char)((*buf & (0xff^(1<<(7-bit)))) +
+ ((x & mask ? 1 : 0) << (7-bit)));
+ x <<= 1;
+ bit = (bit+1) & 7;
+ if ( !bit )
+ {
+ ++ buf;
+ }
+ }
+
+ /* Store new stream state */
+ stream->BytePtr = buf;
+ stream->BitPos = bit;
+}
+#endif
+
+
+/*************************************************************************
+* _Huffman_Hist() - Calculate (sorted) histogram for a block of data.
+*************************************************************************/
+
+#ifdef HUFFMAN_ENCODE
+static void _Huffman_Hist( unsigned char *in, huff_sym_t *sym,
+ unsigned int size )
+{
+ int k;
+
+ /* Clear/init histogram */
+ for ( k = 0; k < 256; ++ k )
+ {
+ sym[k].Symbol = k;
+ sym[k].Count = 0;
+ sym[k].Code = 0;
+ sym[k].Bits = 0;
+ }
+
+ /* Build histogram */
+ for ( k = size; k; -- k )
+ {
+ sym[*in ++].Count ++;
+ }
+}
+#endif
+
+
+/*************************************************************************
+* _Huffman_StoreTree() - Store a Huffman tree in the output stream and
+* in a look-up-table (a symbol array).
+*************************************************************************/
+
+#ifdef HUFFMAN_ENCODE
+static void _Huffman_StoreTree( huff_encodenode_t *node, huff_sym_t *sym,
+ huff_bitstream_t *stream, unsigned int code, unsigned int bits )
+{
+ unsigned int sym_idx;
+
+ /* Is this a leaf node? */
+ if ( node->Symbol >= 0 )
+ {
+ /* Append symbol to tree description */
+ _Huffman_WriteBits( stream, 1, 1 );
+ _Huffman_WriteBits( stream, node->Symbol, 8 );
+
+ /* Find symbol index */
+ for ( sym_idx = 0; sym_idx < 256; ++ sym_idx )
+ {
+ if ( sym[sym_idx].Symbol == node->Symbol ) break;
+ }
+
+ /* Store code info in symbol array */
+ sym[sym_idx].Code = code;
+ sym[sym_idx].Bits = bits;
+ return;
+ }
+ else
+ {
+ /* This was not a leaf node */
+ _Huffman_WriteBits( stream, 0, 1 );
+ }
+
+ /* Branch A */
+ _Huffman_StoreTree( node->ChildA, sym, stream, (code<<1)+0, bits+1 );
+
+ /* Branch B */
+ _Huffman_StoreTree( node->ChildB, sym, stream, (code<<1)+1, bits+1 );
+}
+#endif
+
+
+/*************************************************************************
+* _Huffman_MakeTree() - Generate a Huffman tree.
+*************************************************************************/
+
+#ifdef HUFFMAN_ENCODE
+static void _Huffman_MakeTree( huff_sym_t *sym, huff_bitstream_t *stream )
+{
+ huff_encodenode_t nodes[MAX_TREE_NODES], *node_1, *node_2, *root;
+ unsigned int k, num_symbols, nodes_left, next_idx;
+
+ /* Initialize all leaf nodes */
+ num_symbols = 0;
+ for ( k = 0; k < 256; ++ k )
+ {
+ if ( sym[k].Count > 0 )
+ {
+ nodes[num_symbols].Symbol = sym[k].Symbol;
+ nodes[num_symbols].Count = sym[k].Count;
+ nodes[num_symbols].ChildA = (huff_encodenode_t *) 0;
+ nodes[num_symbols].ChildB = (huff_encodenode_t *) 0;
+ ++ num_symbols;
+ }
+ }
+
+ /* Build tree by joining the lightest nodes until there is only
+ one node left (the root node). */
+ root = (huff_encodenode_t *) 0;
+ nodes_left = num_symbols;
+ next_idx = num_symbols;
+ while( nodes_left > 1 )
+ {
+ /* Find the two lightest nodes */
+ node_1 = (huff_encodenode_t *) 0;
+ node_2 = (huff_encodenode_t *) 0;
+ for ( k = 0; k < next_idx; ++ k )
+ {
+ if ( nodes[k].Count > 0 )
+ {
+ if ( !node_1 || (nodes[k].Count <= node_1->Count))
+ {
+ node_2 = node_1;
+ node_1 = &nodes[k];
+ }
+ else if ( !node_2 || (nodes[k].Count <= node_2->Count))
+ {
+ node_2 = &nodes[k];
+ }
+ }
+ }
+
+ /* Join the two nodes into a new parent node */
+ root = &nodes[next_idx];
+ root->ChildA = node_1;
+ root->ChildB = node_2;
+ root->Count = node_1->Count + node_2->Count;
+ root->Symbol = -1;
+ node_1->Count = 0;
+ node_2->Count = 0;
+ ++ next_idx;
+ -- nodes_left;
+ }
+
+ /* Store the tree in the output stream, and in the sym[] array (the
+ latter is used as a look-up-table for faster encoding) */
+ if ( root )
+ {
+ _Huffman_StoreTree( root, sym, stream, 0, 0 );
+ }
+ else
+ {
+ /* Special case: only one symbol => no binary tree */
+ root = &nodes[0];
+ _Huffman_StoreTree( root, sym, stream, 0, 1 );
+ }
+}
+#endif
+
+
+/*************************************************************************
+* _Huffman_RecoverTree() - Recover a Huffman tree from a bitstream.
+*************************************************************************/
+
+static huff_decodenode_t * _Huffman_RecoverTree( huff_decodenode_t *nodes,
+ huff_bitstream_t *stream, unsigned int *nodenum )
+{
+ huff_decodenode_t * this_node;
+
+ /* Pick a node from the node array */
+ this_node = &nodes[*nodenum];
+ *nodenum = *nodenum + 1;
+
+ /* Clear the node */
+ this_node->Symbol = -1;
+ this_node->ChildA = (huff_decodenode_t *) 0;
+ this_node->ChildB = (huff_decodenode_t *) 0;
+
+ /* Is this a leaf node? */
+ if ( _Huffman_ReadBit( stream ))
+ {
+ /* Get symbol from tree description and store in lead node */
+ this_node->Symbol = _Huffman_Read8Bits( stream );
+
+ return this_node;
+ }
+
+ /* Get branch A */
+ this_node->ChildA = _Huffman_RecoverTree( nodes, stream, nodenum );
+
+ /* Get branch B */
+ this_node->ChildB = _Huffman_RecoverTree( nodes, stream, nodenum );
+
+ return this_node;
+}
+
+
+
+/*************************************************************************
+* PUBLIC FUNCTIONS *
+*************************************************************************/
+
+
+/*************************************************************************
+* Huffman_Compress() - Compress a block of data using a Huffman coder.
+* in - Input (uncompressed) buffer.
+* out - Output (compressed) buffer. This buffer must be 384 bytes
+* larger than the input buffer.
+* insize - Number of input bytes.
+* The function returns the size of the compressed data.
+*************************************************************************/
+
+#ifdef HUFFMAN_ENCODE
+int Huffman_Compress( unsigned char *in, unsigned char *out,
+ unsigned int insize )
+{
+ huff_sym_t sym[256], tmp;
+ huff_bitstream_t stream;
+ unsigned int k, total_bytes, swaps, symbol;
+
+ /* Do we have anything to compress? */
+ if ( insize < 1 ) return 0;
+
+ /* Initialize bitstream */
+ _Huffman_InitBitstream( &stream, out );
+
+ /* Calculate and sort histogram for input data */
+ _Huffman_Hist( in, sym, insize );
+
+ /* Build Huffman tree */
+ _Huffman_MakeTree( sym, &stream );
+
+ /* Sort histogram - first symbol first (bubble sort) */
+ do
+ {
+ swaps = 0;
+ for ( k = 0; k < 255; ++ k )
+ {
+ if ( sym[k].Symbol > sym[k+1].Symbol )
+ {
+ tmp = sym[k];
+ sym[k] = sym[k+1];
+ sym[k+1] = tmp;
+ swaps = 1;
+ }
+ }
+ }
+ while( swaps );
+
+ /* Encode input stream */
+ for ( k = 0; k < insize; ++ k )
+ {
+ symbol = in[k];
+ _Huffman_WriteBits( &stream, sym[symbol].Code,
+ sym[symbol].Bits );
+ }
+
+ /* Calculate size of output data */
+ total_bytes = (int)(stream.BytePtr - out);
+ if ( stream.BitPos > 0 )
+ {
+ ++ total_bytes;
+ }
+
+ return total_bytes;
+}
+#endif
+
+
+/*************************************************************************
+* Huffman_Uncompress() - Uncompress a block of data using a Huffman
+* decoder.
+* in - Input (compressed) buffer.
+* out - Output (uncompressed) buffer. This buffer must be large
+* enough to hold the uncompressed data.
+* insize - Number of input bytes.
+* outsize - Number of output bytes.
+*************************************************************************/
+
+void Huffman_Uncompress( unsigned char *in, unsigned char *out,
+ unsigned int insize, unsigned int outsize )
+{
+ huff_decodenode_t nodes[MAX_TREE_NODES], *root, *node;
+ huff_bitstream_t stream;
+ unsigned int k, node_count;
+ unsigned char *buf;
+
+ /* Do we have anything to decompress? */
+ if ( insize < 1 ) return;
+
+ /* Initialize bitstream */
+ _Huffman_InitBitstream( &stream, in );
+
+ /* Recover Huffman tree */
+ node_count = 0;
+ root = _Huffman_RecoverTree( nodes, &stream, &node_count );
+
+ /* Decode input stream */
+ buf = out;
+ for ( k = 0; k < outsize; ++ k )
+ {
+ /* Traverse tree until we find a matching leaf node */
+ node = root;
+ while( node->Symbol < 0 )
+ {
+ /* Get next node */
+ if ( _Huffman_ReadBit( &stream ))
+ node = node->ChildB;
+ else
+ node = node->ChildA;
+ }
+
+ /* We found the matching leaf node and have the symbol */
+ *buf ++ = (unsigned char) node->Symbol;
+ }
+}
diff --git a/plugins/CountryFlags/src/icons.cpp b/plugins/CountryFlags/src/icons.cpp new file mode 100644 index 0000000000..3b456a4d11 --- /dev/null +++ b/plugins/CountryFlags/src/icons.cpp @@ -0,0 +1,282 @@ +/*
+Miranda IM Country Flags Plugin
+Copyright (C) 2006-1007 H. Herkenrath
+
+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 (Flags-License.txt); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "flags.h"
+
+extern HINSTANCE hInst;
+extern int nCountriesCount;
+extern struct CountryListEntry *countries;
+static HANDLE hServiceLoadIcon,hServiceCreateMergedIcon;
+
+/************************* Bitmap Access **************************/
+
+static HANDLE *phIconHandles;
+
+static int FASTCALL CountryNumberToBitmapIndex(int countryNumber)
+{
+ /* country number indices (same order as in flags.bmp) */
+ const int BitmapIndexMap[232]={
+ 0, 1, 7, 20, 27, 30, 31, 32, 33, 34, 36, 39, 40, 41, 43, 44, 45, 46, 47, 48,
+ 49, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 81, 82, 84, 86,
+ 90, 91, 92, 93, 94, 95, 98, 101, 102, 103, 104, 105, 106, 107, 178, 108, 109, 110, 111, 112,
+ 113, 116, 117, 118, 121, 122, 123, 212, 213, 216, 218, 220, 221, 222, 223, 224, 225, 226, 227, 228,
+ 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 248, 249,
+ 250, 251, 252, 253, 254, 255, 256, 257, 258, 260, 261, 263, 264, 265, 266, 267, 268, 269, 290, 291,
+ 297, 298, 299, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 370, 371, 372, 373, 374, 375, 376,
+ 377, 378, 379, 380, 381, 382, 385, 386, 387, 389, 420, 421, 441, 442, 500, 501, 502, 503, 504, 505,
+ 506, 507, 508, 509, 590, 591, 592, 593, 595, 596, 597, 598, 599, 670, 671, 672, 673, 674, 675, 676,
+ 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 705, 706, 708, 709,
+ 711, 850, 852, 853, 855, 856, 880, 886, 960, 961, 962, 963, 964, 965, 966, 967, 968, 971, 972, 973,
+ 974, 975, 976, 977, 994, 995,1141,2691,3811,4101,6101,6722
+ };
+ /* shared flags by multiple countries */
+ switch(countryNumber) {
+ case 262: /* Reunion Island */
+ case 594: /* French Guiana */
+ case 5901: /* French Antilles */
+ countryNumber=33; /* France */
+ break;
+ case 120: /* Barbuda */
+ countryNumber=102; /* Antigua and Barbuda */
+ break;
+ case 6702: /* Tinian Island */
+ case 6701: /* Rota Island */
+ countryNumber=670; /* Saipan Island (Northern Mariana Islands) */
+ break;
+ case 115: /* Saint Kitts */
+ case 114: /* Nevis */
+ countryNumber=1141; /* Saint Kitts and Nevis */
+ break;
+ case 247: /* Ascension Island */
+ countryNumber=44; /* United Kingdom */
+ break;
+ case 6721: /* Australian Antarctic Territory */
+ countryNumber=61; /* Australia */
+ break;
+ case 5399: /* Guantanamo Bay */
+ countryNumber=1; /* USA */
+ }
+ /* binary search in index array */
+ { int low=0,i,high;
+ high=SIZEOF(BitmapIndexMap)-1;
+ if(countryNumber<=BitmapIndexMap[high])
+ while(low<=high) {
+ i=low+((high-low)/2);
+ /* never happens */
+ if(i<0 || i>=SIZEOF(BitmapIndexMap)) DebugBreak();
+ if(BitmapIndexMap[i]==countryNumber) return i;
+ if(countryNumber>BitmapIndexMap[i]) low=i+1;
+ else high=i-1;
+ }
+ }
+ /* Other,Unknown,Unspecified */
+ return 0;
+}
+
+// return value needs to be released using DestroyIcon()
+// only operates on color icons, which isn't a problem here
+static HICON FASTCALL ResizeIconCentered(HICON hIcon,int cx,int cy)
+{
+ HICON hResIcon=NULL;
+ ICONINFO icoi;
+ BITMAP bm;
+ register HDC hdc;
+ HBITMAP hbmPrev,hbm;
+ POINT pt;
+ hdc=CreateCompatibleDC(NULL);
+ if(hdc!=NULL) {
+ if(GetIconInfo(hIcon,&icoi)) {
+ if(GetObject(icoi.hbmColor,sizeof(bm),&bm) && bm.bmWidth<=cx && bm.bmHeight<=cy) {
+ pt.x=(cx-bm.bmWidth)/2;
+ pt.y=(cy-bm.bmHeight)/2;
+ hbmPrev = (HBITMAP)SelectObject(hdc, icoi.hbmColor);
+ if(hbmPrev!=NULL) { /* error on select? */
+ hbm=icoi.hbmColor;
+ icoi.hbmColor=CreateCompatibleBitmap(hdc,cx,cy);
+ if(icoi.hbmColor!=NULL)
+ if(SelectObject(hdc,icoi.hbmColor)!=NULL) { /* error on select? */
+ DeleteObject(hbm); /* delete prev color (XOR) */
+ if(BitBlt(hdc,0,0,cx,cy,NULL,0,0,BLACKNESS)) /* transparency: AND=0, XOR=1 */
+ if(DrawIconEx(hdc,pt.x,pt.y,hIcon,bm.bmWidth,bm.bmHeight,0,NULL,DI_IMAGE|DI_NOMIRROR)) {
+ if(SelectObject(hdc,icoi.hbmMask)!=NULL) { /* error on select? */
+ hbm=icoi.hbmMask;
+ icoi.hbmMask=CreateBitmap(cx,cy,1,1,NULL); /* mono */
+ if(icoi.hbmMask!=NULL)
+ if(SelectObject(hdc,icoi.hbmMask)!=NULL) { /* error on select? */
+ DeleteObject(hbm); /* delete prev mask (AND) */
+ if(BitBlt(hdc,0,0,cx,cy,NULL,0,0,WHITENESS)) /* transparency: AND=0, XOR=1 */
+ if(DrawIconEx(hdc,pt.x,pt.y,hIcon,0,0,0,NULL,DI_MASK|DI_NOMIRROR)) {
+ SelectObject(hdc,hbmPrev);
+ hResIcon=CreateIconIndirect(&icoi); /* bitmaps must not be selected */
+ }
+ }
+ }
+ }
+ }
+ SelectObject(hdc,hbmPrev);
+ }
+ }
+ DeleteObject(icoi.hbmColor);
+ DeleteObject(icoi.hbmMask);
+ }
+ DeleteDC(hdc);
+ }
+ return hResIcon;
+}
+
+/************************* Utils **********************************/
+
+HICON FASTCALL LoadFlagIcon(int countryNumber)
+{
+ char szId[20],*szCountry;
+ /* create identifier */
+ szCountry=(char*)CallService(MS_UTILS_GETCOUNTRYBYNUMBER,countryNumber,0);
+ if(szCountry==NULL) szCountry=(char*)CallService(MS_UTILS_GETCOUNTRYBYNUMBER,countryNumber=0xFFFF,0);
+ wsprintfA(szId,(countryNumber==0xFFFF)?"%s0x%X":"%s%i","flags_",countryNumber); /* buffer safe */
+ return (HICON)CallService(MS_SKIN2_GETICON,0,(LPARAM)szId);
+}
+
+int FASTCALL CountryNumberToIndex(int countryNumber)
+{
+ int i,nf=0;
+ for(i=0;i<nCountriesCount;++i) {
+ if(countries[i].id==countryNumber) return i;
+ if(countries[i].id==0xFFFF) nf=i;
+ }
+ return nf; /* Unknown */
+
+}
+
+/************************* Services *******************************/
+
+static INT_PTR ServiceLoadFlagIcon(WPARAM wParam,LPARAM lParam)
+{
+ /* return handle */
+ if ((BOOL)lParam) {
+ if(phIconHandles==NULL) return (int)(HANDLE)NULL;
+ return (int)phIconHandles[CountryNumberToIndex((int)wParam)];
+ }
+ /* return icon */
+ return (int)LoadFlagIcon(wParam);
+}
+
+static INT_PTR ServiceCreateMergedFlagIcon(WPARAM wParam,LPARAM lParam)
+{
+ HICON hUpperIcon,hLowerIcon;
+ ICONINFO icoi;
+ BITMAP bm;
+ HDC hdc;
+ POINT aptTriangle[3];
+ HICON hIcon=NULL;
+ HRGN hrgn;
+ HBITMAP hbmPrev;
+ /* load both icons */
+ hLowerIcon=(HICON)ServiceLoadFlagIcon((WPARAM)lParam,0);
+ if(hLowerIcon==NULL) return (int)(HICON)NULL;
+ hUpperIcon=(HICON)ServiceLoadFlagIcon(wParam,0);
+ /* merge them */
+ if(GetIconInfo(hLowerIcon,&icoi)) {
+ if(hUpperIcon!=NULL && GetObject(icoi.hbmColor,sizeof(bm),&bm)) {
+ hdc=CreateCompatibleDC(NULL);
+ if(hdc!=NULL) {
+ ZeroMemory(&aptTriangle,sizeof(aptTriangle));
+ aptTriangle[1].y=bm.bmHeight-1;
+ aptTriangle[2].x=bm.bmWidth-1;
+ hrgn=CreatePolygonRgn(aptTriangle,SIZEOF(aptTriangle),WINDING);
+ if(hrgn!=NULL) {
+ SelectClipRgn(hdc,hrgn);
+ DeleteObject(hrgn);
+ hbmPrev = (HBITMAP)SelectObject(hdc, icoi.hbmColor);
+ if(hbmPrev!=NULL) { /* error on select? */
+ if(DrawIconEx(hdc,0,0,hUpperIcon,bm.bmWidth,bm.bmHeight,0,NULL,DI_NOMIRROR|DI_IMAGE))
+ if(SelectObject(hdc,icoi.hbmMask)!=NULL) /* error on select? */
+ DrawIconEx(hdc,0,0,hUpperIcon,bm.bmWidth,bm.bmHeight,0,NULL,DI_NOMIRROR|DI_MASK);
+ SelectObject(hdc,hbmPrev);
+ }
+ DeleteObject(hrgn);
+ }
+ DeleteDC(hdc);
+ }
+ }
+ /* create icon */
+ hIcon=CreateIconIndirect(&icoi);
+ DeleteObject(icoi.hbmColor);
+ DeleteObject(icoi.hbmMask);
+ }
+ return (int)hIcon;
+}
+
+/************************* Misc ***********************************/
+
+void InitIcons(void)
+{
+ HIMAGELIST himl;
+ SKINICONDESC sid;
+ char szId[20];
+ int i,index;
+ HICON hIcon;
+
+ WCHAR szName[64];
+ LCID locale;
+ locale=(LCID)CallService(MS_LANGPACK_GETLOCALE,0,0);
+
+
+ /* register icons */
+ ZeroMemory(&sid,sizeof(sid));
+ sid.cbSize=sizeof(sid);
+ sid.pszName=szId;
+ sid.cx=GetSystemMetrics(SM_CXSMICON);
+ sid.cy=GetSystemMetrics(SM_CYSMICON);
+ sid.flags=SIDF_SORTED|SIDF_TCHAR;
+ sid.ptszSection=TranslateT("Country Flags");
+ /* all those flag icons do not need any transparency mask (flags are always opaque),
+ * storing them in a large bitmap to reduce file size */
+ himl=ImageList_LoadImage(hInst,MAKEINTRESOURCE(IDB_FLAGS),sid.cx,0,CLR_NONE,IMAGE_BITMAP,LR_CREATEDIBSECTION);
+ if(himl!=NULL) {
+ phIconHandles=(HANDLE*)mir_alloc(nCountriesCount*sizeof(HANDLE));
+ if(phIconHandles!=NULL)
+ for(i=0;i<nCountriesCount;++i) {
+
+ MultiByteToWideChar(locale,0,countries[i].szName,-1,szName,SIZEOF(szName));
+ szName[SIZEOF(szName)-1]=L'\0';
+ sid.pwszDescription=TranslateW(szName);
+
+ /* create identifier */
+ wsprintfA(szId,(countries[i].id==0xFFFF)?"%s0x%X":"%s%i","flags_",countries[i].id); /* buffer safe */
+ index=CountryNumberToBitmapIndex(countries[i].id);
+ /* create icon */
+ hIcon=ImageList_GetIcon(himl,index,ILD_NORMAL);
+ sid.hDefaultIcon=(hIcon!=NULL)?ResizeIconCentered(hIcon,sid.cx,sid.cy):NULL;
+ if(hIcon!=NULL) DestroyIcon(hIcon);
+ index=CountryNumberToIndex(countries[i].id);
+ phIconHandles[index] = Skin_AddIcon(&sid);
+ if(sid.hDefaultIcon!=NULL) DestroyIcon(sid.hDefaultIcon);
+ }
+ ImageList_Destroy(himl);
+ }
+ /* create services */
+ hServiceLoadIcon=CreateServiceFunction(MS_FLAGS_LOADFLAGICON,ServiceLoadFlagIcon);
+ hServiceCreateMergedIcon=CreateServiceFunction(MS_FLAGS_CREATEMERGEDFLAGICON,ServiceCreateMergedFlagIcon);
+}
+
+void UninitIcons(void)
+{
+ DestroyServiceFunction(hServiceLoadIcon);
+ DestroyServiceFunction(hServiceCreateMergedIcon);
+}
diff --git a/plugins/CountryFlags/src/ip2country.cpp b/plugins/CountryFlags/src/ip2country.cpp new file mode 100644 index 0000000000..12f3406a11 --- /dev/null +++ b/plugins/CountryFlags/src/ip2country.cpp @@ -0,0 +1,327 @@ +/*
+Miranda IM Country Flags Plugin
+Copyright (C) 2006-2007 H. Herkenrath
+
+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 (Flags-License.txt); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "flags.h"
+
+extern HINSTANCE hInst;
+extern int nCountriesCount;
+extern struct CountryListEntry *countries;
+static HANDLE hServiceIpToCountry;
+
+/************************* Bin Records ****************************/
+
+#define DATARECORD_SIZE (sizeof(DWORD)+sizeof(DWORD)+sizeof(WORD))
+
+// mir_free() the return value
+static BYTE* GetDataHeader(BYTE *data,DWORD cbDataSize,DWORD *pnDataRecordCount)
+{
+ BYTE *recordData;
+ /* uncompressed size stored in first DWORD */
+ *pnDataRecordCount=(*(DWORD*)data)/DATARECORD_SIZE;
+ recordData=(BYTE*)mir_alloc(*(DWORD*)data);
+ if(recordData!=NULL)
+ Huffman_Uncompress(data+sizeof(DWORD),recordData,cbDataSize-sizeof(DWORD),*(DWORD*)data);
+ return recordData;
+}
+
+static int GetDataRecord(BYTE *data,DWORD index,DWORD *pdwFrom,DWORD *pdwTo)
+{
+ data+=index*DATARECORD_SIZE;
+ *pdwFrom=*(DWORD*)data;
+ data+=sizeof(DWORD);
+ if(pdwTo!=NULL) *pdwTo=*(DWORD*)data;
+ data+=sizeof(DWORD);
+ return (int)*(WORD*)data;
+}
+
+/************************* Record Cache ***************************/
+
+static CRITICAL_SECTION csRecordCache;
+static DWORD nDataRecordsCount; /* protected by csRecordCache */
+static BYTE *dataRecords; /* protected by csRecordCache */
+
+#define UNLOADDELAY 30*1000 /* time after which the data records are being unloaded */
+
+static void CALLBACK UnloadRecordCache(LPARAM lParam)
+{
+ UNREFERENCED_PARAMETER(lParam);
+ EnterCriticalSection(&csRecordCache);
+ mir_free(dataRecords);
+ dataRecords=NULL;
+ LeaveCriticalSection(&csRecordCache);
+}
+
+// function assumes it has got the csRecordCache mutex
+static BOOL EnsureRecordCacheLoaded(BYTE **pdata,DWORD *pcount)
+{
+ HRSRC hrsrc;
+ DWORD cb;
+ EnterCriticalSection(&csRecordCache);
+ if(dataRecords==NULL) {
+ /* load record data list from resources */
+ hrsrc=FindResource(hInst,MAKEINTRESOURCE(IDR_IPTOCOUNTRY),_T("BIN"));
+ cb=SizeofResource(hInst,hrsrc);
+ dataRecords=(BYTE*)LockResource(LoadResource(hInst,hrsrc));
+ if(cb<=sizeof(DWORD) || dataRecords==NULL) { LeaveCriticalSection(&csRecordCache); return FALSE; }
+ /* uncompress record data */
+ dataRecords=GetDataHeader(dataRecords,cb,&nDataRecordsCount);
+ if(dataRecords==NULL || !nDataRecordsCount) { LeaveCriticalSection(&csRecordCache); return FALSE; }
+ }
+ *pdata=dataRecords;
+ *pcount=nDataRecordsCount;
+ return TRUE;
+}
+
+static void LeaveRecordCache(void)
+{
+ /* mark for unload */
+ CallFunctionBuffered(UnloadRecordCache,0,FALSE,UNLOADDELAY);
+ LeaveCriticalSection(&csRecordCache);
+}
+
+/************************* Services *******************************/
+
+
+INT_PTR ServiceIpToCountry(WPARAM wParam,LPARAM lParam)
+{
+ BYTE *data;
+ DWORD dwFrom,dwTo;
+ DWORD low=0,i,high;
+ int id;
+ UNREFERENCED_PARAMETER(lParam);
+ if(EnsureRecordCacheLoaded(&data,&high)) {
+ /* binary search in record data */
+ GetDataRecord(data,low,&dwFrom,NULL);
+ --high;
+ if(wParam>=dwFrom) /* only search if wParam valid */
+ while(low<=high) {
+ i=low+((high-low)/2);
+ /* never happens */
+ if(i<0) DebugBreak();
+ /* analyze record */
+ id=GetDataRecord(data,i,&dwFrom,&dwTo);
+ if(dwFrom<=wParam && dwTo>=wParam) { LeaveRecordCache(); return id; }
+ if(wParam>dwTo) low=i+1;
+ else high=i-1;
+ }
+ LeaveRecordCache();
+ }
+ return 0xFFFF; /* Unknown */
+}
+
+/************************* Bin Converter **************************/
+
+#ifdef BINCONV
+#include <stdio.h>
+#include <stdlib.h>
+
+struct {
+ const char *szMir;
+ const char *szCSV;
+} static const differentCountryNames[]={
+ {"British Virgin Islands","VIRGIN ISLANDS, BRITISH"},
+ {"Brunei","BRUNEI DARUSSALAM"},
+ {"Cape Verde Islands","CAPE VERDE"},
+ {"Cocos-Keeling Islands","COCOS (KEELING) ISLANDS"},
+ {"Chile, Republic of","CHILE"},
+ {"Congo, Democratic Republic of (Zaire)","THE DEMOCRATIC REPUBLIC OF THE CONGO"},
+ {"Congo, Republic of the","CONGO"},
+ {"Cote d'Ivoire (Ivory Coast)","COTE D'IVOIRE"},
+ {"Diego Garcia","BRITISH INDIAN OCEAN TERRITORY"},
+ {"Guam, US Territory of","GUAM"},
+ {"Iran (Islamic Republic of)","ISLAMIC REPUBLIC OF IRAN"},
+ {"Korea, North","REPUBLIC OF KOREA"},
+ {"Laos","LAO PEOPLE'S DEMOCRATIC REPUBLIC"},
+ {"Reunion Island","REUNION"},
+ {"Russia","RUSSIAN FEDERATION"},
+ {"Saipan Island (Northern Mariana Islands)","NORTHERN MARIANA ISLANDS"},
+ {"Tanzania","UNITED REPUBLIC OF TANZANIA"},
+ {"USA","UNITED STATES"},
+ {"Macau","MACAO"},
+ {"Macedonia (F.Y.R.O.M.)","THE FORMER YUGOSLAV REPUBLIC OF MACEDONIA"},
+ {"Micronesia, Federated States of","FEDERATED STATES OF MICRONESIA"},
+ {"Mayotte Island","MAYOTTE"},
+ {"Moldova, Republic of","REPUBLIC OF MOLDOVA"},
+ {"Vietnam","VIET NAM"},
+ {"Virgin Islands (USA)","VIRGIN ISLANDS, U.S."},
+ {"Vatican City","HOLY SEE (VATICAN CITY STATE)"},
+ {"Serbia, Republic of","SERBIA"},
+ {"Montenegro, Republic of","MONTENEGRO"},
+};
+
+#define ALLOC_STEP (800*1024) /* approx. size of data output */
+
+struct ResizableByteBuffer {
+ BYTE *buf;
+ DWORD cbLength,cbAlloced;
+};
+
+static void AppendToByteBuffer(struct ResizableByteBuffer *buffer,const void *append,DWORD cbAppendSize)
+{
+ if(buffer->cbAlloced<=buffer->cbLength+cbAppendSize) {
+ BYTE* buf=(BYTE*)mir_realloc(buffer->buf,buffer->cbAlloced+ALLOC_STEP+cbAppendSize);
+ if(buf==NULL) return;
+ buffer->buf=buf;
+ buffer->cbAlloced+=ALLOC_STEP+cbAppendSize;
+ OutputDebugStringA("reallocating memory...\n"); /* all ascii */
+ }
+ CopyMemory(&buffer->buf[buffer->cbLength],append,cbAppendSize);
+ buffer->cbLength+=cbAppendSize;
+}
+
+static int EnumIpDataLines(const char *pszFileCSV,const char *pszFileOut)
+{
+ FILE *fp;
+ char line[1024],out[512],*pszFrom,*pszTo,*pszTwo,*pszCountry,*buf;
+ int i,j;
+ DWORD dwOut;
+ WORD wOut;
+ struct ResizableByteBuffer buffer;
+
+ ZeroMemory(&buffer,sizeof(buffer));
+ fp=fopen(pszFileCSV,"rt");
+ if(fp!=NULL) {
+ OutputDebugStringA("Running IP data convert...\n"); /* all ascii */
+ while(!feof(fp)) {
+ if(fgets(line,sizeof(line),fp)==NULL) break;
+ /* get line data */
+ pszFrom=line+1;
+ pszTo=strchr(pszFrom,',');
+ *(pszTo-1)='\0'; pszTo+=2;
+ pszTwo=strchr(pszTo,',');
+ *(pszTwo-1)='\0'; pszTwo+=2;
+ pszCountry=strchr(pszTwo,',')+1;
+ pszCountry=strchr(pszCountry,',')+2;
+ buf=strchr(pszCountry,'"');
+ *buf=pszTwo[2]='\0';
+ /* corrections */
+ if (!lstrcmpi(pszCountry,"ANTARCTICA")) continue;
+ if (!lstrcmpi(pszCountry,"TIMOR-LESTE")) continue;
+ if (!lstrcmpi(pszCountry,"PALESTINIAN TERRITORY, OCCUPIED"))
+ lstrcpy(pszCountry,"ISRAEL");
+ else if (!lstrcmpi(pszCountry,"UNITED STATES MINOR OUTLYING ISLANDS"))
+ lstrcpy(pszCountry,"UNITED STATES");
+ else if (!lstrcmpi(pszCountry,"SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS"))
+ lstrcpy(pszCountry,"UNITED KINGDOM");
+ else if (!lstrcmpi(pszTwo,"JE")) /* map error */
+ lstrcpy(pszCountry,"UNITED KINGDOM");
+ else if (!lstrcmpi(pszTwo,"AX")) /* Åland Island belongs to Finland */
+ lstrcpy(pszCountry,"FINLAND");
+ else if (!lstrcmpi(pszTwo,"ME"))
+ lstrcpy(pszCountry,"MONTENEGRO");
+ else if (!lstrcmpi(pszTwo,"RS") || !lstrcmpi(pszTwo,"CS"))
+ lstrcpy(pszCountry,"SERBIA");
+ /* convert */
+ for(i=0;i<nCountriesCount;i++) {
+ /* map different writings */
+ for(j=0;j<SIZEOF(differentCountryNames);j++)
+ if (!lstrcmpi(countries[i].szName,differentCountryNames[j].szMir)) {
+ buf=(char*)differentCountryNames[j].szCSV;
+ break;
+ }
+ if(j==SIZEOF(differentCountryNames))
+ buf=(char*)countries[i].szName;
+ /* check country */
+ if (!lstrcmpiA(pszCountry,buf)) {
+ dwOut=(DWORD)atoi(pszFrom);
+ AppendToByteBuffer(&buffer,(void*)&dwOut,sizeof(DWORD));
+ dwOut=(DWORD)atoi(pszTo);
+ AppendToByteBuffer(&buffer,(void*)&dwOut,sizeof(DWORD));
+ wOut=(WORD)countries[i].id;
+ AppendToByteBuffer(&buffer,(void*)&wOut,sizeof(WORD));
+ break;
+ }
+ }
+ /* not in list */
+ if(i==nCountriesCount) {
+ wsprintfA(out,"Unknown: %s-%s [%s, %s]\n",pszFrom,pszTo,pszTwo,pszCountry);
+ OutputDebugStringA(out); /* all ascii */
+ }
+ }
+ fclose(fp);
+ OutputDebugStringA("Done!\n"); /* all ascii */
+ if(buffer.buf!=NULL) {
+ HANDLE hFileOut;
+ DWORD cbWritten=0;
+ BYTE *compressed;
+ DWORD cbCompressed;
+ /* compress whole data */
+ OutputDebugStringA("Compressing...\n"); /* all ascii */
+ compressed=(BYTE*)mir_alloc(buffer.cbAlloced+384);
+ if(compressed!=NULL) {
+ cbCompressed=Huffman_Compress(buffer.buf,compressed,buffer.cbLength);
+ OutputDebugStringA("Done!\n"); /* all ascii */
+ OutputDebugStringA("Writing to file...\n"); /* all ascii */
+ hFileOut=CreateFile(pszFileOut,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
+ if(hFileOut!=INVALID_HANDLE_VALUE) {
+ /* store data length count at beginning */
+ dwOut=buffer.cbLength;
+ WriteFile(hFileOut,&dwOut,sizeof(DWORD),&cbWritten,NULL);
+ /* store compressed data records */
+ WriteFile(hFileOut,compressed,cbCompressed,&cbWritten,NULL);
+ CloseHandle(hFileOut);
+ }
+ OutputDebugStringA("Done!\n"); /* all ascii */
+ mir_free(compressed);
+ }
+ mir_free(buffer.buf);
+ }
+ return 0;
+ }
+ return 1;
+}
+
+static void BinConvThread(void *unused)
+{
+ UNREFERENCED_PARAMETER(unused);
+ /* debug version only */
+ if(MessageBox(NULL,_T("Looking for 'ip-to-country.csv' in current directory.\n"
+ "It will be converted into 'ip-to-country.bin'.\n"
+ "See debug output for more details.\n"
+ "This process may take very long."),_T("Bin Converter"),MB_OKCANCEL|MB_ICONINFORMATION|MB_SETFOREGROUND|MB_TOPMOST|MB_TASKMODAL)==IDOK) {
+ EnumIpDataLines("ip-to-country.csv","ip-to-country.bin");
+ MessageBox(NULL,_T("Done!\n'ip-to-country.bin' has been created in current directory."),_T("Bin Converter"),MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND|MB_TOPMOST|MB_TASKMODAL);
+ }
+}
+
+#endif // BINCONV
+
+/************************* Misc ***********************************/
+
+void InitIpToCountry(void)
+{
+ /* Record Cache */
+ InitializeCriticalSection(&csRecordCache);
+ nDataRecordsCount=0;
+ dataRecords=NULL;
+ /* Services */
+ hServiceIpToCountry=CreateServiceFunction(MS_FLAGS_IPTOCOUNTRY,ServiceIpToCountry);
+#ifdef BINCONV
+ mir_forkthread(BinConvThread,NULL);
+#endif
+}
+
+void UninitIpToCountry(void)
+{
+ /* Record Cache */
+ DeleteCriticalSection(&csRecordCache);
+ mir_free(dataRecords); /* does NULL check */
+ /* Servcies */
+ DestroyServiceFunction(hServiceIpToCountry);
+}
diff --git a/plugins/CountryFlags/src/main.cpp b/plugins/CountryFlags/src/main.cpp new file mode 100644 index 0000000000..462672292a --- /dev/null +++ b/plugins/CountryFlags/src/main.cpp @@ -0,0 +1,122 @@ +/*
+Miranda IM Country Flags Plugin
+Copyright (C) 2006-2007 H. Herkenrath
+
+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 (Flags-License.txt); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "flags.h"
+#include "version.h"
+
+HINSTANCE hInst;
+int nCountriesCount;
+struct CountryListEntry *countries;
+int hLangpack;
+
+static PLUGININFOEX pluginInfo={
+ sizeof(PLUGININFOEX),
+ "Country Flags",
+ PLUGIN_VERSION,
+ "Service offering misc country utilities as flag icons and a IP-to-Country database.", /* autotranslated */
+ "H. Herkenrath",
+ "hrathh@users.sourceforge.net",
+ "© 2006-2007 H. Herkenrath",
+ PLUGIN_WEBSITE,
+ UNICODE_AWARE,
+ // {68C36842-3D95-4f4a-AB81-014D6593863B}
+ {0x68c36842,0x3d95,0x4f4a,{0xab,0x81,0x1,0x4d,0x65,0x93,0x86,0x3b}}
+};
+
+extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[]={MIID_FLAGS,MIID_LAST};
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+ hInst = hinstDLL;
+ return TRUE;
+}
+
+static void InstallFile(const TCHAR *pszFileName,const TCHAR *pszDestSubDir)
+{
+ TCHAR szFileFrom[MAX_PATH+1],szFileTo[MAX_PATH+1],*p;
+ HANDLE hFile;
+
+ if (!GetModuleFileName(hInst,szFileFrom,SIZEOF(szFileFrom)-lstrlen(pszFileName)))
+ return;
+ p=_tcsrchr(szFileFrom,_T('\\'));
+ if(p!=NULL) *(++p)=0;
+ lstrcat(szFileFrom,pszFileName); /* buffer safe */
+
+ hFile=CreateFile(szFileFrom,0,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
+ if(hFile==INVALID_HANDLE_VALUE) return;
+ CloseHandle(hFile);
+
+ if (!GetModuleFileName(NULL,szFileTo,SIZEOF(szFileTo)-lstrlen(pszDestSubDir)-lstrlen(pszFileName)))
+ return;
+ p=_tcsrchr(szFileTo,_T('\\'));
+ if(p!=NULL) *(++p)=0;
+ lstrcat(szFileTo,pszDestSubDir); /* buffer safe */
+ CreateDirectory(szFileTo,NULL);
+ lstrcat(szFileTo,pszFileName); /* buffer safe */
+
+ if (!MoveFile(szFileFrom,szFileTo) && GetLastError()==ERROR_ALREADY_EXISTS) {
+ DeleteFile(szFileTo);
+ MoveFile(szFileFrom,szFileTo);
+ }
+}
+
+extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+{
+ return &pluginInfo;
+}
+
+extern "C" __declspec(dllexport) int Load(void)
+{
+ mir_getLP(&pluginInfo);
+
+ /* existance of MS_SYSTEM_GETVERSION and MS_LANGPACK_TRANSLATESTRING
+ * is checked in MirandaPluginInfo().
+ * Not placed in MirandaPluginInfo() to avoid MessageBoxes on plugin options.
+ * Using ANSI as LANG_UNICODE might not be supported. */
+ if(CallService(MS_SYSTEM_GETVERSION,0,0)<NEEDED_MIRANDA_VERSION) {
+ char szText[256];
+ mir_snprintf(szText,SIZEOF(szText),Translate("The Country Flags Plugin can not be loaded. It requires Miranda IM %hs or later."),NEEDED_MIRANDA_VERSION_STR);
+ MessageBoxA(NULL,szText,Translate("Country Flags Plugin"),MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND|MB_TOPMOST|MB_TASKMODAL);
+ return 1;
+ }
+
+ PrepareBufferedFunctions();
+ InitCountryListExt();
+ if(CallService(MS_UTILS_GETCOUNTRYLIST,(WPARAM)&nCountriesCount,(LPARAM)&countries))
+ nCountriesCount=0;
+ InitIcons();
+ InitIpToCountry();
+ InitExtraImg();
+
+ /* installation */
+ InstallFile(_T("Flags-Readme.txt"),_T("Docs\\"));
+ InstallFile(_T("Flags-License.txt"),_T("Docs\\"));
+ InstallFile(_T("Flags-SDK.zip"),_T("Docs\\"));
+ return 0;
+}
+
+extern "C" __declspec(dllexport) int Unload(void)
+{
+ KillBufferedFunctions();
+ UninitExtraImg();
+ UninitIpToCountry();
+ UninitIcons();
+ UninitCountryListExt();
+ return 0;
+}
\ No newline at end of file diff --git a/plugins/CountryFlags/src/resource.h b/plugins/CountryFlags/src/resource.h new file mode 100644 index 0000000000..a2cd0496d8 --- /dev/null +++ b/plugins/CountryFlags/src/resource.h @@ -0,0 +1,25 @@ +//{{NO_DEPENDENCIES}}
+// Microsoft Developer Studio generated include file.
+// Used by resource.rc
+//
+#define IDB_FLAGS 101
+#define IDR_IPTOCOUNTRY 102
+#define IDD_OPT_EXTRAIMG 103
+#define IDC_CHECK_SHOWSTATUSICONFLAG 1001
+#define IDC_CHECK_SHOWEXTRAIMGFLAG 1002
+#define IDC_TEXT_EXTRAIMGFLAGCOLUMN 1003
+#define IDC_COMBO_EXTRAIMGFLAGCOLUMN 1004
+#define IDC_CHECK_USEUNKNOWNFLAG 1005
+#define IDC_CHECK_USEIPTOCOUNTRY 1006
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NO_MFC 1
+#define _APS_NEXT_RESOURCE_VALUE 104
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1007
+#define _APS_NEXT_SYMED_VALUE 2001
+#endif
+#endif
diff --git a/plugins/CountryFlags/src/utils.cpp b/plugins/CountryFlags/src/utils.cpp new file mode 100644 index 0000000000..b55e52e5cf --- /dev/null +++ b/plugins/CountryFlags/src/utils.cpp @@ -0,0 +1,162 @@ +/*
+Miranda IM Country Flags Plugin
+Copyright (C) 2006-1007 H. Herkenrath
+
+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 (Flags-License.txt); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "flags.h"
+
+/************************* Buffered Functions *********************/
+
+struct BufferedCallData {
+ DWORD startTick;
+ UINT uElapse;
+ BUFFEREDPROC pfnBuffProc;
+ LPARAM lParam;
+ #ifdef _DEBUG
+ const char *pszProcName;
+ #endif
+};
+
+static UINT idBufferedTimer;
+static struct BufferedCallData *callList;
+static int nCallListCount;
+
+// always gets called in main message loop
+static void CALLBACK BufferedProcTimer(HWND hwnd,UINT msg,UINT_PTR idTimer,DWORD currentTick)
+{
+ int i;
+ struct BufferedCallData *buf;
+ UINT uElapsed,uElapseNext=USER_TIMER_MAXIMUM;
+ BUFFEREDPROC pfnBuffProc;
+ LPARAM lParam;
+ #ifdef _DEBUG
+ char szDbgLine[256];
+ const char *pszProcName;
+ #endif
+ UNREFERENCED_PARAMETER(msg);
+
+ for(i=0;i<nCallListCount;++i) {
+ /* find elapsed procs */
+ uElapsed=currentTick-callList[i].startTick; /* wraparound works */
+ if ((uElapsed+USER_TIMER_MINIMUM)>=callList[i].uElapse) {
+ /* call elapsed proc */
+ pfnBuffProc=callList[i].pfnBuffProc;
+ lParam=callList[i].lParam;
+ #ifdef _DEBUG
+ pszProcName=callList[i].pszProcName;
+ #endif
+ /* resize storage array */
+ if ((i+1)<nCallListCount)
+ MoveMemory(&callList[i],&callList[i+1],((nCallListCount-i-1)*sizeof(struct BufferedCallData)));
+ --nCallListCount;
+ --i; /* reiterate current */
+ if(nCallListCount) {
+ buf=(struct BufferedCallData*)mir_realloc(callList,nCallListCount*sizeof(struct BufferedCallData));
+ if(buf!=NULL) callList=buf;
+ } else {
+ mir_free(callList);
+ callList=NULL;
+ }
+ #ifdef _DEBUG
+ mir_snprintf(szDbgLine,sizeof(szDbgLine),"buffered call: %s(0x%X)\n",pszProcName,lParam); /* all ascii */
+ OutputDebugStringA(szDbgLine);
+ #endif
+ CallFunctionAsync((void (CALLBACK *)(void*))pfnBuffProc,(void*)lParam); /* compatible */
+ }
+ /* find next timer delay */
+ else if ((callList[i].uElapse-uElapsed)<uElapseNext)
+ uElapseNext=callList[i].uElapse-uElapsed;
+ }
+
+ /* set next timer */
+ if(nCallListCount) {
+ #ifdef _DEBUG
+ mir_snprintf(szDbgLine,sizeof(szDbgLine),"next buffered timeout: %ums\n",uElapseNext); /* all ascii */
+ OutputDebugStringA(szDbgLine);
+ #endif
+ idBufferedTimer=SetTimer(hwnd,idBufferedTimer,uElapseNext,BufferedProcTimer); /* will be reset */
+ } else {
+ KillTimer(hwnd,idTimer);
+ idBufferedTimer=0;
+ #ifdef _DEBUG
+ OutputDebugStringA("empty buffered queue\n");
+ #endif
+ }
+}
+
+// assumes to be called in context of main thread
+#ifdef _DEBUG
+void _CallFunctionBuffered(BUFFEREDPROC pfnBuffProc,const char *pszProcName,LPARAM lParam,BOOL fAccumulateSameParam,UINT uElapse)
+#else
+void _CallFunctionBuffered(BUFFEREDPROC pfnBuffProc,LPARAM lParam,BOOL fAccumulateSameParam,UINT uElapse)
+#endif
+{
+ struct BufferedCallData *data=NULL;
+ int i;
+
+ /* find existing */
+ for(i=0;i<nCallListCount;++i)
+ if(callList[i].pfnBuffProc==pfnBuffProc)
+ if (!fAccumulateSameParam || callList[i].lParam==lParam) {
+ data=&callList[i];
+ break;
+ }
+ /* append new */
+ if(data==NULL) {
+ /* resize storage array */
+ data=(struct BufferedCallData*)mir_realloc(callList,(nCallListCount+1)*sizeof(struct BufferedCallData));
+ if(data==NULL) return;
+ callList=data;
+ data=&callList[nCallListCount];
+ ++nCallListCount;
+ }
+ /* set delay */
+ data->startTick=GetTickCount();
+ data->uElapse=uElapse;
+ data->lParam=lParam;
+ data->pfnBuffProc=pfnBuffProc;
+ #ifdef _DEBUG
+ { char szDbgLine[256];
+ data->pszProcName=pszProcName;
+ mir_snprintf(szDbgLine,sizeof(szDbgLine),"buffered queue: %s(0x%X)\n",pszProcName,lParam); /* all ascii */
+ OutputDebugStringA(szDbgLine);
+ if (!idBufferedTimer) {
+ mir_snprintf(szDbgLine,sizeof(szDbgLine),"next buffered timeout: %ums\n",uElapse); /* all ascii */
+ OutputDebugStringA(szDbgLine);
+ }
+ }
+ #endif
+ /* set next timer */
+ if(idBufferedTimer) uElapse=USER_TIMER_MINIMUM; /* will get recalculated */
+ idBufferedTimer=SetTimer(NULL,idBufferedTimer,uElapse,BufferedProcTimer);
+}
+
+// assumes to be called in context of main thread
+void PrepareBufferedFunctions(void)
+{
+ idBufferedTimer=0;
+ nCallListCount=0;
+ callList=NULL;
+}
+
+// assumes to be called in context of main thread
+void KillBufferedFunctions(void)
+{
+ if(idBufferedTimer) KillTimer(NULL,idBufferedTimer);
+ nCallListCount=0;
+ mir_free(callList); /* does NULL check */
+}
diff --git a/plugins/CountryFlags/src/version.h b/plugins/CountryFlags/src/version.h new file mode 100644 index 0000000000..a778ed0026 --- /dev/null +++ b/plugins/CountryFlags/src/version.h @@ -0,0 +1,31 @@ +/*
+Miranda IM Country Flags Plugin
+Copyright (C) 2006-2007 H. Herkenrath
+
+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 (Flags-License.txt); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#define NEEDED_MIRANDA_VERSION PLUGIN_MAKE_VERSION(0,7,0,10)
+#define NEEDED_MIRANDA_VERSION_STR "0.7 alpha build #10"
+#define PLUGIN_VERSION PLUGIN_MAKE_VERSION(0,1,0,3)
+#define FILE_VERSION 0,1,0,3
+
+#ifdef _DEBUG
+ #define FILE_VERSION_STR "0.1.0.4 alpha"
+#else
+ #define FILE_VERSION_STR "0.1.0.3"
+#endif
+
+#define PLUGIN_WEBSITE "http://addons.miranda-im.org/details.php?action=viewfile&id=3463"
|