From 1ca120b165c2f2d9f521a04bfc31c7956d2ce422 Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Tue, 17 Jul 2012 06:57:55 +0000 Subject: ContactsPlus, CountryFlags, CrashDumper: changed folder structure git-svn-id: http://svn.miranda-ng.org/main/trunk@1000 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/CountryFlags/src/countrylistext.cpp | 345 +++++++++++++++++++ plugins/CountryFlags/src/extraimg.cpp | 494 +++++++++++++++++++++++++++ plugins/CountryFlags/src/flags.h | 90 +++++ plugins/CountryFlags/src/huffman.cpp | 506 ++++++++++++++++++++++++++++ plugins/CountryFlags/src/icons.cpp | 282 ++++++++++++++++ plugins/CountryFlags/src/ip2country.cpp | 327 ++++++++++++++++++ plugins/CountryFlags/src/main.cpp | 122 +++++++ plugins/CountryFlags/src/resource.h | 25 ++ plugins/CountryFlags/src/utils.cpp | 162 +++++++++ plugins/CountryFlags/src/version.h | 31 ++ 10 files changed, 2384 insertions(+) create mode 100644 plugins/CountryFlags/src/countrylistext.cpp create mode 100644 plugins/CountryFlags/src/extraimg.cpp create mode 100644 plugins/CountryFlags/src/flags.h create mode 100644 plugins/CountryFlags/src/huffman.cpp create mode 100644 plugins/CountryFlags/src/icons.cpp create mode 100644 plugins/CountryFlags/src/ip2country.cpp create mode 100644 plugins/CountryFlags/src/main.cpp create mode 100644 plugins/CountryFlags/src/resource.h create mode 100644 plugins/CountryFlags/src/utils.cpp create mode 100644 plugins/CountryFlags/src/version.h (limited to 'plugins/CountryFlags/src') 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; i24) 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;iuType) { + 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;idColumncode) { + 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 +#define NONAMELESSUNION +#include /* for ImageList functions */ +#define NOWIN2K +#include +#define MIRANDA_VER 0x0A00 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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=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 +#include + +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=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)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" -- cgit v1.2.3