summaryrefslogtreecommitdiff
path: root/plugins/CountryFlags
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-10-21 14:14:22 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-10-21 14:14:22 +0000
commit0999d9f9a1654c4fcbd1fc4f4fcf27080dd979e2 (patch)
tree5ab8420935b0ee704430e9659a857411148ff621 /plugins/CountryFlags
parentd8eb1ed0d9f8a694629af5251840e9c6347c9eb3 (diff)
- a bit less crazy implementation of flags;
- fix for icons' names in icolib git-svn-id: http://svn.miranda-ng.org/main/trunk@2023 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CountryFlags')
-rw-r--r--plugins/CountryFlags/src/countrylistext.cpp13
-rw-r--r--plugins/CountryFlags/src/extraimg.cpp226
-rw-r--r--plugins/CountryFlags/src/huffman.cpp6
-rw-r--r--plugins/CountryFlags/src/icons.cpp260
-rw-r--r--plugins/CountryFlags/src/ip2country.cpp49
-rw-r--r--plugins/CountryFlags/src/main.cpp49
-rw-r--r--plugins/CountryFlags/src/utils.cpp22
7 files changed, 279 insertions, 346 deletions
diff --git a/plugins/CountryFlags/src/countrylistext.cpp b/plugins/CountryFlags/src/countrylistext.cpp
index 95f692b30b..d6d12d9dc3 100644
--- a/plugins/CountryFlags/src/countrylistext.cpp
+++ b/plugins/CountryFlags/src/countrylistext.cpp
@@ -275,17 +275,16 @@ static struct CountryListEntry countries[]={
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;
+ for (int i=0; i < SIZEOF(countries); ++i)
+ if ((int)wParam == countries[i].id)
+ return (INT_PTR)countries[i].szName;
+
+ return NULL;
}
static INT_PTR ServiceGetCountryList(WPARAM wParam,LPARAM lParam)
{
- if ((int*)wParam==NULL || (void*)lParam==NULL) return 1;
+ if ((int*)wParam == NULL || (void*)lParam == NULL) return 1;
*(int*)wParam=SIZEOF(countries);
*(struct CountryListEntry**)lParam=countries;
return 0;
diff --git a/plugins/CountryFlags/src/extraimg.cpp b/plugins/CountryFlags/src/extraimg.cpp
index ccf26b517e..7a31ae8175 100644
--- a/plugins/CountryFlags/src/extraimg.cpp
+++ b/plugins/CountryFlags/src/extraimg.cpp
@@ -39,17 +39,16 @@ 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))
+ if ( db_get_b(NULL,"Flags","UseIpToCountry",SETTING_USEIPTOCOUNTRY_DEFAULT))
countryNumber=ServiceIpToCountry(DBGetContactSettingDword((HANDLE)wParam,pszProto,"RealIP",0),0);
/* fallback */
- if(countryNumber==0xFFFF)
+ if (countryNumber == 0xFFFF)
countryNumber=DBGetContactSettingWord((HANDLE)wParam,pszProto,"Country",0);
- if(countryNumber==0 || countryNumber==0xFFFF)
+ if (countryNumber == 0 || countryNumber == 0xFFFF)
countryNumber=DBGetContactSettingWord((HANDLE)wParam,pszProto,"CompanyCountry",0);
- return (countryNumber==0)?0xFFFF:countryNumber;
+ return (countryNumber == 0)?0xFFFF:countryNumber;
}
/************************* Extra Image ****************************/
@@ -61,103 +60,96 @@ static BYTE idExtraColumn;
static void CALLBACK SetExtraImage(LPARAM lParam)
{
+ if ( !db_get_b(NULL, "Flags", "ShowExtraImgFlag", SETTING_SHOWEXTRAIMGFLAG_DEFAULT))
+ return;
+
+ /* get contact's country */
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);
+ iec.hImage = INVALID_HANDLE_VALUE;
+ int countryNumber = ServiceDetectContactOriginCountry((WPARAM)lParam,0);
+ /* get icon */
+ if (phExtraImages != NULL) /* too early? */
+ if (countryNumber != 0xFFFF || db_get_b(NULL,"Flags","UseUnknownFlag",SETTING_USEUNKNOWNFLAG_DEFAULT)) {
+ int index=CountryNumberToIndex(countryNumber);
+ /* icon not yet loaded? */
+ if (phExtraImages[index] == INVALID_HANDLE_VALUE) {
+ 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;
+ IconExtraColumn iec;
+ iec.cbSize = sizeof(iec);
+ iec.ColumnType = idExtraColumn;
+ iec.hImage = INVALID_HANDLE_VALUE;
/* enum all contacts */
- hContact=db_find_first();
- while(hContact!=NULL) {
+ HANDLE hContact = db_find_first();
+ while (hContact != NULL) {
/* invalidate icon */
CallService(MS_CLIST_EXTRA_SET_ICON,(WPARAM)hContact,(LPARAM)&iec);
- hContact=db_find_next(hContact);
+ hContact = db_find_next(hContact);
}
}
// 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 */
+ 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();
+ if (idExtraColumnNew != idExtraColumn) RemoveExtraImages();
idExtraColumn=idExtraColumnNew;
/* enum all contacts */
- hContact=db_find_first();
- while(hContact!=NULL) {
+ HANDLE hContact = db_find_first();
+ while (hContact != NULL) {
CallFunctionBuffered(SetExtraImage,(LPARAM)hContact,TRUE,EXTRAIMAGE_REFRESHDELAY);
- hContact=db_find_next(hContact);
+ hContact = db_find_next(hContact);
}
}
static void CALLBACK UpdateExtraImages(LPARAM lParam)
{
- UNREFERENCED_PARAMETER(lParam);
- if(DBGetContactSettingByte(NULL,"Flags","ShowExtraImgFlag",SETTING_SHOWEXTRAIMGFLAG_DEFAULT))
+ if ( db_get_b(NULL,"Flags","ShowExtraImgFlag",SETTING_SHOWEXTRAIMGFLAG_DEFAULT))
EnsureExtraImages();
- else RemoveExtraImages();
+ 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;
+ if (phExtraImages != NULL)
+ for(int 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 */
+ BYTE 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);
+ 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))
+ if ( db_get_b(NULL,"Flags","ShowExtraImgFlag",SETTING_SHOWEXTRAIMGFLAG_DEFAULT))
SetExtraImage((LPARAM)wParam); /* unbuffered */
return 0;
}
@@ -169,35 +161,35 @@ static int ExtraImageApply(WPARAM wParam,LPARAM lParam)
// always call in context of main thread
static void FASTCALL SetStatusIcon(HANDLE hContact,int countryNumber)
{
- int i;
- HICON hIcon=NULL;
- StatusIconData sid;
+ HICON hIcon = NULL;
+
+ StatusIconData sid = { sizeof(sid) };
+ sid.szModule = "Flags";
- if(countryNumber!=0xFFFF || DBGetContactSettingByte(NULL,"Flags","UseUnknownFlag",SETTING_USEUNKNOWNFLAG_DEFAULT)) {
+ if (countryNumber != 0xFFFF || db_get_b(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;
+ hIcon = LoadFlagIcon(countryNumber);
+ sid.hIcon = (hIcon != NULL) ? CopyIcon(hIcon) : NULL;
CallService(MS_SKIN2_RELEASEICON,(WPARAM)hIcon,0); /* does NULL check */
- hIcon=sid.hIcon;
+ 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);
+ sid.dwId = countryNumber;
+ 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);
+ sid.hIcon = NULL;
+ sid.szTooltip = NULL;
+ sid.flags = MBF_HIDDEN;
+ for (int 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);
}
}
@@ -219,15 +211,14 @@ static void FASTCALL UnsetStatusIcon(HANDLE hContact,int countryNumber)
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 */
+ 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);
+ if ( db_get_b(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 */
@@ -243,19 +234,18 @@ static void CALLBACK UpdateStatusIcons(LPARAM lParam)
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);
+ fShow=db_get_b(NULL,"Flags","ShowStatusIconFlag",SETTING_SHOWSTATUSICONFLAG_DEFAULT);
msgwi.hContact=db_find_first();
- while(msgwi.hContact!=NULL) {
+ 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);
+ if (fShow) SetStatusIcon(msgwi.hContact,countryNumber);
else UnsetStatusIcon(msgwi.hContact,countryNumber);
}
msgwi.hContact = db_find_next(msgw.hContact);
@@ -264,10 +254,8 @@ static void CALLBACK UpdateStatusIcons(LPARAM lParam)
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))
+ if (ServiceExists(MS_MSG_ADDICON))
+ if ( db_get_b(NULL,"Flags","ShowStatusIconFlag",SETTING_SHOWSTATUSICONFLAG_DEFAULT))
CallFunctionBuffered(UpdateStatusIcons,0,FALSE,STATUSICON_REFRESHDELAY);
return 0;
}
@@ -278,25 +266,24 @@ static int StatusIconsChanged(WPARAM wParam,LPARAM lParam)
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;
+ if (ServiceExists(MS_MSG_ADDICON)) val=db_get_b(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;
+ if (ServiceExists(MS_CLIST_EXTRA_ADD_ICON)) val=db_get_b(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;
+ val=db_get_b(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;
+ val=db_get_b(NULL,"Flags","UseIpToCountry",SETTING_USEIPTOCOUNTRY_DEFAULT) != 0;
CheckDlgButton(hwndDlg,IDC_CHECK_USEIPTOCOUNTRY,val);
}
/* init combobox */
@@ -306,7 +293,7 @@ static INT_PTR CALLBACK ExtraImgOptDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,L
BYTE idMaxExtraCol,idAdvExtraColStart;
int index;
hwndCombo=GetDlgItem(hwndDlg,IDC_COMBO_EXTRAIMGFLAGCOLUMN);
- idSavedColumn=DBGetContactSettingByte(NULL,"Flags","ExtraImgFlagColumn",SETTING_EXTRAIMGFLAGCOLUMN_DEFAULT);
+ idSavedColumn=db_get_b(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 */
@@ -317,20 +304,20 @@ static INT_PTR CALLBACK ExtraImgOptDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,L
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) {
+ if (index != LB_ERR) {
SendMessage(hwndCombo,CB_SETITEMDATA,index,columnIds[idColumn]);
- if(idColumn==0 || columnIds[idColumn]==idSavedColumn) SendMessage(hwndCombo,CB_SETCURSEL,index,0);
+ if (idColumn == 0 || columnIds[idColumn] == idSavedColumn) SendMessage(hwndCombo,CB_SETCURSEL,index,0);
}
}
}
/* Advanced #3+: clist_modern */
- if(idMaxExtraCol!=idAdvExtraColStart) /* same flags if not present */
+ 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) {
+ if (index != LB_ERR) {
SendMessage(hwndCombo,CB_SETITEMDATA,index,idColumn);
- if(idColumn==idSavedColumn) SendMessage(hwndCombo,CB_SETCURSEL,index,0);
+ if (idColumn == idSavedColumn) SendMessage(hwndCombo,CB_SETCURSEL,index,0);
}
}
}
@@ -352,17 +339,17 @@ static INT_PTR CALLBACK ExtraImgOptDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,L
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));
+ 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));
+ 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));
+ 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));
+ if (index != LB_ERR) DBWriteContactSettingByte(NULL,"Flags","ExtraImgFlagColumn",(BYTE)SendDlgItemMessage(hwndDlg,IDC_COMBO_EXTRAIMGFLAGCOLUMN,CB_GETITEMDATA,index,0));
}
return TRUE;
}
@@ -375,7 +362,6 @@ 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);
@@ -394,20 +380,20 @@ static int ExtraImgOptInit(WPARAM wParam,LPARAM lParam)
static int ExtraImgSettingChanged(WPARAM wParam,LPARAM lParam)
{
DBCONTACTWRITESETTING *dbcws=(DBCONTACTWRITESETTING*)lParam;
- if ((HANDLE)wParam==NULL) {
+ 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))
+ 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))
+ if (ServiceExists(MS_MSG_ADDICON))
CallFunctionBuffered(UpdateStatusIcons,0,FALSE,STATUSICON_REFRESHDELAY);
}
}
@@ -416,10 +402,10 @@ static int ExtraImgSettingChanged(WPARAM wParam,LPARAM lParam)
!lstrcmpA(dbcws->szSetting,"Country") ||
!lstrcmpA(dbcws->szSetting,"CompanyCountry")) {
/* Extra Image */
- if(ServiceExists(MS_CLIST_EXTRA_SET_ICON))
+ if (ServiceExists(MS_CLIST_EXTRA_SET_ICON))
CallFunctionBuffered(SetExtraImage,(LPARAM)wParam,TRUE,EXTRAIMAGE_REFRESHDELAY);
/* Status Icon */
- if(ServiceExists(MS_MSG_ADDICON))
+ if (ServiceExists(MS_MSG_ADDICON))
CallFunctionBuffered(UpdateStatusIcons,0,FALSE,STATUSICON_REFRESHDELAY);
}
return 0;
@@ -429,23 +415,21 @@ static int ExtraImgSettingChanged(WPARAM wParam,LPARAM lParam)
static int ExtraImgModulesLoaded(WPARAM wParam,LPARAM lParam)
{
- UNREFERENCED_PARAMETER(wParam);
- UNREFERENCED_PARAMETER(lParam);
/* Options */
- if(ServiceExists("DBEditorpp/RegisterSingleModule"))
+ if (ServiceExists("DBEditorpp/RegisterSingleModule"))
CallService("DBEditorpp/RegisterSingleModule",(WPARAM)"Flags",0);
/* Extra Image */
- if(ServiceExists(MS_CLIST_EXTRA_SET_ICON)) {
+ if (ServiceExists(MS_CLIST_EXTRA_SET_ICON)) {
int i;
BYTE idMaxExtraCol;
phExtraImages=(HANDLE*)mir_alloc(nCountriesCount*sizeof(HANDLE));
/* invalidate icons */
- if(phExtraImages!=NULL)
+ 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 */
+ 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 */
diff --git a/plugins/CountryFlags/src/huffman.cpp b/plugins/CountryFlags/src/huffman.cpp
index c460e9a66e..ee8680f558 100644
--- a/plugins/CountryFlags/src/huffman.cpp
+++ b/plugins/CountryFlags/src/huffman.cpp
@@ -299,7 +299,7 @@ static void _Huffman_MakeTree( huff_sym_t *sym, huff_bitstream_t *stream )
root = (huff_encodenode_t *) 0;
nodes_left = num_symbols;
next_idx = num_symbols;
- while( nodes_left > 1 )
+ while ( nodes_left > 1 )
{
/* Find the two lightest nodes */
node_1 = (huff_encodenode_t *) 0;
@@ -435,7 +435,7 @@ int Huffman_Compress( unsigned char *in, unsigned char *out,
}
}
}
- while( swaps );
+ while ( swaps );
/* Encode input stream */
for ( k = 0; k < insize; ++ k )
@@ -491,7 +491,7 @@ void Huffman_Uncompress( unsigned char *in, unsigned char *out,
{
/* Traverse tree until we find a matching leaf node */
node = root;
- while( node->Symbol < 0 )
+ while ( node->Symbol < 0 )
{
/* Get next node */
if ( _Huffman_ReadBit( &stream ))
diff --git a/plugins/CountryFlags/src/icons.cpp b/plugins/CountryFlags/src/icons.cpp
index cde97ff74e..2bb8bf4a58 100644
--- a/plugins/CountryFlags/src/icons.cpp
+++ b/plugins/CountryFlags/src/icons.cpp
@@ -28,63 +28,66 @@ static HANDLE hServiceLoadIcon,hServiceCreateMergedIcon;
static HANDLE *phIconHandles;
+/* 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
+};
+
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 */
+ 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;
- }
- }
+ int low = 0, i, high = SIZEOF(BitmapIndexMap)-1;
+ if (countryNumber <= BitmapIndexMap[high])
+ while (low <= high) {
+ i = low+((high-low)/2);
+ if (BitmapIndexMap[i] == countryNumber)
+ return i;
+
+ if (countryNumber >BitmapIndexMap[i])
+ low=i+1;
+ else
+ high=i-1;
+ }
+
/* Other,Unknown,Unspecified */
return 0;
}
@@ -94,42 +97,40 @@ static int FASTCALL CountryNumberToBitmapIndex(int countryNumber)
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? */
+ HDC hdc = CreateCompatibleDC(NULL);
+ if (hdc != NULL) {
+ ICONINFO icoi;
+ if ( GetIconInfo(hIcon,&icoi)) {
+ BITMAP bm;
+ if (GetObject(icoi.hbmColor,sizeof(bm),&bm) && bm.bmWidth<=cx && bm.bmHeight<=cy) {
+ POINT pt;
+ pt.x = (cx-bm.bmWidth)/2;
+ pt.y = (cy-bm.bmHeight)/2;
+ HBITMAP hbmPrev = (HBITMAP)SelectObject(hdc, icoi.hbmColor);
+ if (hbmPrev != NULL) { /* error on select? */
+ HBITMAP 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? */
+ 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)) {
+ 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 */
+ hResIcon = CreateIconIndirect(&icoi); /* bitmaps must not be selected */
}
- }
+ }
}
}
}
- SelectObject(hdc,hbmPrev);
+ SelectObject(hdc,hbmPrev);
}
}
DeleteObject(icoi.hbmColor);
@@ -144,23 +145,26 @@ static HICON FASTCALL ResizeIconCentered(HICON hIcon,int cx,int cy)
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);
+ char *szCountry = (char*)CallService(MS_UTILS_GETCOUNTRYBYNUMBER, countryNumber, 0);
+ if (szCountry == NULL)
+ szCountry = (char*)CallService(MS_UTILS_GETCOUNTRYBYNUMBER, countryNumber=0xFFFF, 0);
+
+ char szId[20];
+ 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;
+ int nf=0;
+ for(int i=0; i < nCountriesCount; ++i) {
+ if (countries[i].id == countryNumber)
+ return i;
+ if (countries[i].id == 0xFFFF)
+ nf = i;
}
return nf; /* Unknown */
-
}
/************************* Services *******************************/
@@ -169,43 +173,43 @@ 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)];
+ if (phIconHandles == NULL)
+ return 0;
+
+ return (INT_PTR)phIconHandles[CountryNumberToIndex((int)wParam)];
}
/* return icon */
- return (int)LoadFlagIcon(wParam);
+ return (INT_PTR)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);
+ HICON hLowerIcon = (HICON)ServiceLoadFlagIcon((WPARAM)lParam,0);
+ if (hLowerIcon == NULL)
+ return 0;
+
+ HICON 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) {
+ ICONINFO icoi;
+ if (GetIconInfo(hLowerIcon,&icoi)) {
+ BITMAP bm;
+ if (hUpperIcon != NULL && GetObject(icoi.hbmColor,sizeof(bm),&bm)) {
+ HDC hdc = CreateCompatibleDC(NULL);
+ if (hdc != NULL) {
+ POINT aptTriangle[3] = { 0 };
+ aptTriangle[1].y = bm.bmHeight-1;
+ aptTriangle[2].x = bm.bmWidth-1;
+ HRGN 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? */
+ HBITMAP 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);
}
@@ -215,11 +219,11 @@ static INT_PTR ServiceCreateMergedFlagIcon(WPARAM wParam,LPARAM lParam)
}
}
/* create icon */
- hIcon=CreateIconIndirect(&icoi);
+ hIcon = CreateIconIndirect(&icoi);
DeleteObject(icoi.hbmColor);
DeleteObject(icoi.hbmMask);
}
- return (int)hIcon;
+ return (INT_PTR)hIcon;
}
/************************* Misc ***********************************/
@@ -228,17 +232,13 @@ void InitIcons(void)
{
char szId[20];
- WCHAR szName[64];
- LCID locale = (LCID)CallService(MS_LANGPACK_GETLOCALE,0,0);
-
/* register icons */
- SKINICONDESC sid = { 0 };
- sid.cbSize = sizeof(sid);
+ SKINICONDESC sid = { 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");
+ sid.flags = SIDF_SORTED;
+ sid.pszSection = "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 */
@@ -247,18 +247,18 @@ void InitIcons(void)
phIconHandles = (HANDLE*)mir_alloc(nCountriesCount*sizeof(HANDLE));
if (phIconHandles != NULL) {
for (int 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);
+ sid.pszDescription = countries[i].szName;
/* create identifier */
wsprintfA(szId,(countries[i].id == 0xFFFF) ? "%s0x%X" : "%s%i","flags_", countries[i].id); /* buffer safe */
int index = CountryNumberToBitmapIndex(countries[i].id);
/* create icon */
HICON hIcon = ImageList_GetIcon(himl,index,ILD_NORMAL);
- sid.hDefaultIcon = (hIcon != NULL) ? ResizeIconCentered(hIcon,sid.cx,sid.cy) : NULL;
- if (hIcon != NULL)
+ if (hIcon) {
+ sid.hDefaultIcon = ResizeIconCentered(hIcon,sid.cx,sid.cy);
DestroyIcon(hIcon);
+ }
+ else sid.hDefaultIcon = NULL;
index = CountryNumberToIndex(countries[i].id);
phIconHandles[index] = Skin_AddIcon(&sid);
if (sid.hDefaultIcon != NULL)
diff --git a/plugins/CountryFlags/src/ip2country.cpp b/plugins/CountryFlags/src/ip2country.cpp
index 12f3406a11..e11195c521 100644
--- a/plugins/CountryFlags/src/ip2country.cpp
+++ b/plugins/CountryFlags/src/ip2country.cpp
@@ -35,7 +35,7 @@ static BYTE* GetDataHeader(BYTE *data,DWORD cbDataSize,DWORD *pnDataRecordCount)
/* uncompressed size stored in first DWORD */
*pnDataRecordCount=(*(DWORD*)data)/DATARECORD_SIZE;
recordData=(BYTE*)mir_alloc(*(DWORD*)data);
- if(recordData!=NULL)
+ if (recordData != NULL)
Huffman_Uncompress(data+sizeof(DWORD),recordData,cbDataSize-sizeof(DWORD),*(DWORD*)data);
return recordData;
}
@@ -45,7 +45,7 @@ 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;
+ if (pdwTo != NULL) *pdwTo=*(DWORD*)data;
data+=sizeof(DWORD);
return (int)*(WORD*)data;
}
@@ -60,7 +60,6 @@ static BYTE *dataRecords; /* protected by csRecordCache */
static void CALLBACK UnloadRecordCache(LPARAM lParam)
{
- UNREFERENCED_PARAMETER(lParam);
EnterCriticalSection(&csRecordCache);
mir_free(dataRecords);
dataRecords=NULL;
@@ -73,15 +72,15 @@ static BOOL EnsureRecordCacheLoaded(BYTE **pdata,DWORD *pcount)
HRSRC hrsrc;
DWORD cb;
EnterCriticalSection(&csRecordCache);
- if(dataRecords==NULL) {
+ 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; }
+ 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; }
+ if (dataRecords == NULL || !nDataRecordsCount) { LeaveCriticalSection(&csRecordCache); return FALSE; }
}
*pdata=dataRecords;
*pcount=nDataRecordsCount;
@@ -104,20 +103,19 @@ INT_PTR ServiceIpToCountry(WPARAM wParam,LPARAM lParam)
DWORD dwFrom,dwTo;
DWORD low=0,i,high;
int id;
- UNREFERENCED_PARAMETER(lParam);
- if(EnsureRecordCacheLoaded(&data,&high)) {
+ 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) {
+ if (wParam>=dwFrom) /* only search if wParam valid */
+ while (low<=high) {
i=low+((high-low)/2);
/* never happens */
- if(i<0) DebugBreak();
+ 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;
+ if (dwFrom<=wParam && dwTo>=wParam) { LeaveRecordCache(); return id; }
+ if (wParam>dwTo) low=i+1;
else high=i-1;
}
LeaveRecordCache();
@@ -174,9 +172,9 @@ struct ResizableByteBuffer {
static void AppendToByteBuffer(struct ResizableByteBuffer *buffer,const void *append,DWORD cbAppendSize)
{
- if(buffer->cbAlloced<=buffer->cbLength+cbAppendSize) {
+ if (buffer->cbAlloced<=buffer->cbLength+cbAppendSize) {
BYTE* buf=(BYTE*)mir_realloc(buffer->buf,buffer->cbAlloced+ALLOC_STEP+cbAppendSize);
- if(buf==NULL) return;
+ if (buf == NULL) return;
buffer->buf=buf;
buffer->cbAlloced+=ALLOC_STEP+cbAppendSize;
OutputDebugStringA("reallocating memory...\n"); /* all ascii */
@@ -196,10 +194,10 @@ static int EnumIpDataLines(const char *pszFileCSV,const char *pszFileOut)
ZeroMemory(&buffer,sizeof(buffer));
fp=fopen(pszFileCSV,"rt");
- if(fp!=NULL) {
+ if (fp != NULL) {
OutputDebugStringA("Running IP data convert...\n"); /* all ascii */
- while(!feof(fp)) {
- if(fgets(line,sizeof(line),fp)==NULL) break;
+ while (!feof(fp)) {
+ if (fgets(line,sizeof(line),fp) == NULL) break;
/* get line data */
pszFrom=line+1;
pszTo=strchr(pszFrom,',');
@@ -235,7 +233,7 @@ static int EnumIpDataLines(const char *pszFileCSV,const char *pszFileOut)
buf=(char*)differentCountryNames[j].szCSV;
break;
}
- if(j==SIZEOF(differentCountryNames))
+ if (j == SIZEOF(differentCountryNames))
buf=(char*)countries[i].szName;
/* check country */
if (!lstrcmpiA(pszCountry,buf)) {
@@ -249,14 +247,14 @@ static int EnumIpDataLines(const char *pszFileCSV,const char *pszFileOut)
}
}
/* not in list */
- if(i==nCountriesCount) {
+ 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) {
+ if (buffer.buf != NULL) {
HANDLE hFileOut;
DWORD cbWritten=0;
BYTE *compressed;
@@ -264,12 +262,12 @@ static int EnumIpDataLines(const char *pszFileCSV,const char *pszFileOut)
/* compress whole data */
OutputDebugStringA("Compressing...\n"); /* all ascii */
compressed=(BYTE*)mir_alloc(buffer.cbAlloced+384);
- if(compressed!=NULL) {
+ 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) {
+ if (hFileOut != INVALID_HANDLE_VALUE) {
/* store data length count at beginning */
dwOut=buffer.cbLength;
WriteFile(hFileOut,&dwOut,sizeof(DWORD),&cbWritten,NULL);
@@ -289,12 +287,11 @@ static int EnumIpDataLines(const char *pszFileCSV,const char *pszFileOut)
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"
+ 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) {
+ "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);
}
diff --git a/plugins/CountryFlags/src/main.cpp b/plugins/CountryFlags/src/main.cpp
index 462672292a..d63d302bd9 100644
--- a/plugins/CountryFlags/src/main.cpp
+++ b/plugins/CountryFlags/src/main.cpp
@@ -47,35 +47,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
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;
@@ -85,29 +56,13 @@ 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;
+ 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;
}
diff --git a/plugins/CountryFlags/src/utils.cpp b/plugins/CountryFlags/src/utils.cpp
index b55e52e5cf..ed6e455364 100644
--- a/plugins/CountryFlags/src/utils.cpp
+++ b/plugins/CountryFlags/src/utils.cpp
@@ -38,7 +38,6 @@ 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;
@@ -47,9 +46,8 @@ static void CALLBACK BufferedProcTimer(HWND hwnd,UINT msg,UINT_PTR idTimer,DWORD
char szDbgLine[256];
const char *pszProcName;
#endif
- UNREFERENCED_PARAMETER(msg);
- for(i=0;i<nCallListCount;++i) {
+ for(int i=0; i < nCallListCount; ++i) {
/* find elapsed procs */
uElapsed=currentTick-callList[i].startTick; /* wraparound works */
if ((uElapsed+USER_TIMER_MINIMUM)>=callList[i].uElapse) {
@@ -64,9 +62,9 @@ static void CALLBACK BufferedProcTimer(HWND hwnd,UINT msg,UINT_PTR idTimer,DWORD
MoveMemory(&callList[i],&callList[i+1],((nCallListCount-i-1)*sizeof(struct BufferedCallData)));
--nCallListCount;
--i; /* reiterate current */
- if(nCallListCount) {
+ if (nCallListCount) {
buf=(struct BufferedCallData*)mir_realloc(callList,nCallListCount*sizeof(struct BufferedCallData));
- if(buf!=NULL) callList=buf;
+ if (buf != NULL) callList=buf;
} else {
mir_free(callList);
callList=NULL;
@@ -83,7 +81,7 @@ static void CALLBACK BufferedProcTimer(HWND hwnd,UINT msg,UINT_PTR idTimer,DWORD
}
/* set next timer */
- if(nCallListCount) {
+ if (nCallListCount) {
#ifdef _DEBUG
mir_snprintf(szDbgLine,sizeof(szDbgLine),"next buffered timeout: %ums\n",uElapseNext); /* all ascii */
OutputDebugStringA(szDbgLine);
@@ -110,16 +108,16 @@ void _CallFunctionBuffered(BUFFEREDPROC pfnBuffProc,LPARAM lParam,BOOL fAccumula
/* find existing */
for(i=0;i<nCallListCount;++i)
- if(callList[i].pfnBuffProc==pfnBuffProc)
- if (!fAccumulateSameParam || callList[i].lParam==lParam) {
+ if (callList[i].pfnBuffProc == pfnBuffProc)
+ if (!fAccumulateSameParam || callList[i].lParam == lParam) {
data=&callList[i];
break;
}
/* append new */
- if(data==NULL) {
+ if (data == NULL) {
/* resize storage array */
data=(struct BufferedCallData*)mir_realloc(callList,(nCallListCount+1)*sizeof(struct BufferedCallData));
- if(data==NULL) return;
+ if (data == NULL) return;
callList=data;
data=&callList[nCallListCount];
++nCallListCount;
@@ -141,7 +139,7 @@ void _CallFunctionBuffered(BUFFEREDPROC pfnBuffProc,LPARAM lParam,BOOL fAccumula
}
#endif
/* set next timer */
- if(idBufferedTimer) uElapse=USER_TIMER_MINIMUM; /* will get recalculated */
+ if (idBufferedTimer) uElapse=USER_TIMER_MINIMUM; /* will get recalculated */
idBufferedTimer=SetTimer(NULL,idBufferedTimer,uElapse,BufferedProcTimer);
}
@@ -156,7 +154,7 @@ void PrepareBufferedFunctions(void)
// assumes to be called in context of main thread
void KillBufferedFunctions(void)
{
- if(idBufferedTimer) KillTimer(NULL,idBufferedTimer);
+ if (idBufferedTimer) KillTimer(NULL,idBufferedTimer);
nCallListCount=0;
mir_free(callList); /* does NULL check */
}