From 0999d9f9a1654c4fcbd1fc4f4fcf27080dd979e2 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 21 Oct 2012 14:14:22 +0000 Subject: - 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 --- plugins/CountryFlags/src/countrylistext.cpp | 13 +- plugins/CountryFlags/src/extraimg.cpp | 226 +++++++++++------------- plugins/CountryFlags/src/huffman.cpp | 6 +- plugins/CountryFlags/src/icons.cpp | 260 ++++++++++++++-------------- plugins/CountryFlags/src/ip2country.cpp | 49 +++--- plugins/CountryFlags/src/main.cpp | 49 +----- plugins/CountryFlags/src/utils.cpp | 22 ++- 7 files changed, 279 insertions(+), 346 deletions(-) (limited to 'plugins/CountryFlags') 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; iuType) { 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;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)); + 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 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=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)=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