Ejemplo n.º 1
0
unsigned __int64 ConvertFileSizeString(const wchar_t *FileSizeStr)
{
	if (!CheckFileSizeStringFormat(FileSizeStr))
		return 0;

	unsigned __int64 n = _wtoi64(FileSizeStr);
	wchar_t c = Upper(FileSizeStr[StrLength(FileSizeStr)-1]);

	// http://en.wikipedia.org/wiki/SI_prefix
	switch (c)
	{
		case L'K':		// kilo 10x3
			n <<= 10;
			break;
		case L'M':		// mega 10x6
			n <<= 20;
			break;
		case L'G':		// giga 10x9
			n <<= 30;
			break;
		case L'T':		// tera 10x12
			n <<= 40;
			break;
		case L'P':		// peta 10x15
			n <<= 50;
			break;
		case L'E':		// exa  10x18
			n <<= 60;
			break;
			// Z - zetta 10x21
			// Y - yotta 10x24
	}

	return n;
}
Ejemplo n.º 2
0
intptr_t WINAPI FileFilterConfigDlgProc(HANDLE hDlg,intptr_t Msg,intptr_t Param1,void* Param2)
{
    switch (Msg)
    {
    case DN_INITDIALOG:
    {
        FilterDlgRelativeDateItemsUpdate(hDlg, false);
        return TRUE;
    }
    case DN_BTNCLICK:
    {
        if (Param1==ID_FF_CURRENT || Param1==ID_FF_BLANK) //Current и Blank
        {
            FILETIME ft;
            string strDate, strTime;

            if (Param1==ID_FF_CURRENT)
            {
                GetSystemTimeAsFileTime(&ft);
                ConvertDate(ft,strDate,strTime,12,FALSE,FALSE,2);
            }
            else
            {
                strDate.Clear();
                strTime.Clear();
            }

            SendDlgMessage(hDlg,DM_ENABLEREDRAW,FALSE,0);
            int relative = (int)SendDlgMessage(hDlg,DM_GETCHECK,ID_FF_DATERELATIVE,0);
            int db = relative ? ID_FF_DAYSBEFOREEDIT : ID_FF_DATEBEFOREEDIT;
            int da = relative ? ID_FF_DAYSAFTEREDIT  : ID_FF_DATEAFTEREDIT;
            SendDlgMessage(hDlg,DM_SETTEXTPTR,da,const_cast<wchar_t*>(strDate.CPtr()));
            SendDlgMessage(hDlg,DM_SETTEXTPTR,ID_FF_TIMEAFTEREDIT,const_cast<wchar_t*>(strTime.CPtr()));
            SendDlgMessage(hDlg,DM_SETTEXTPTR,db,const_cast<wchar_t*>(strDate.CPtr()));
            SendDlgMessage(hDlg,DM_SETTEXTPTR,ID_FF_TIMEBEFOREEDIT,const_cast<wchar_t*>(strTime.CPtr()));
            SendDlgMessage(hDlg,DM_SETFOCUS,da,0);
            COORD r;
            r.X=r.Y=0;
            SendDlgMessage(hDlg,DM_SETCURSORPOS,da,&r);
            SendDlgMessage(hDlg,DM_ENABLEREDRAW,TRUE,0);
            break;
        }
        else if (Param1==ID_FF_RESET) // Reset
        {
            SendDlgMessage(hDlg,DM_ENABLEREDRAW,FALSE,0);
            intptr_t ColorConfig = SendDlgMessage(hDlg, DM_GETDLGDATA, 0, 0);
            SendDlgMessage(hDlg,DM_SETTEXTPTR,ID_FF_MASKEDIT,const_cast<wchar_t*>(L"*"));
            SendDlgMessage(hDlg,DM_SETTEXTPTR,ID_FF_SIZEFROMEDIT,nullptr);
            SendDlgMessage(hDlg,DM_SETTEXTPTR,ID_FF_SIZETOEDIT,nullptr);

            for (int I=ID_FF_READONLY; I <= ID_FF_VIRTUAL; ++I)
            {
                SendDlgMessage(hDlg,DM_SETCHECK,I,ToPtr(BSTATE_3STATE));
            }

            if (!ColorConfig)
                SendDlgMessage(hDlg,DM_SETCHECK,ID_FF_DIRECTORY,ToPtr(BSTATE_UNCHECKED));

            FarListPos LPos= {sizeof(FarListPos)};
            SendDlgMessage(hDlg,DM_LISTSETCURPOS,ID_FF_DATETYPE,&LPos);
            SendDlgMessage(hDlg,DM_SETCHECK,ID_FF_MATCHMASK,ToPtr(BSTATE_CHECKED));
            SendDlgMessage(hDlg,DM_SETCHECK,ID_FF_MATCHSIZE,ToPtr(BSTATE_UNCHECKED));
            SendDlgMessage(hDlg,DM_SETCHECK,ID_FF_HARDLINKS,ToPtr(BSTATE_UNCHECKED));
            SendDlgMessage(hDlg,DM_SETCHECK,ID_FF_MATCHDATE,ToPtr(BSTATE_UNCHECKED));
            SendDlgMessage(hDlg,DM_SETCHECK,ID_FF_DATERELATIVE,ToPtr(BSTATE_UNCHECKED));
            FilterDlgRelativeDateItemsUpdate(hDlg, true);
            SendDlgMessage(hDlg,DM_SETCHECK,ID_FF_MATCHATTRIBUTES,ToPtr(ColorConfig?BSTATE_UNCHECKED:BSTATE_CHECKED));
            SendDlgMessage(hDlg,DM_ENABLEREDRAW,TRUE,0);
            break;
        }
        else if (Param1==ID_FF_MAKETRANSPARENT)
        {
            HighlightDataColor *Colors = (HighlightDataColor *) SendDlgMessage(hDlg, DM_GETDLGDATA, 0, 0);

            for (int i=0; i<2; i++)
                for (int j=0; j<4; j++)
                {
                    MAKE_TRANSPARENT(Colors->Color[i][j].ForegroundColor);
                    MAKE_TRANSPARENT(Colors->Color[i][j].BackgroundColor);
                }

            SendDlgMessage(hDlg,DM_SETCHECK,ID_HER_MARKTRANSPARENT,ToPtr(BSTATE_CHECKED));
            break;
        }
        else if (Param1==ID_FF_DATERELATIVE)
        {
            FilterDlgRelativeDateItemsUpdate(hDlg, true);
            break;
        }
    }
    case DN_CONTROLINPUT:

        if ((Msg==DN_BTNCLICK && Param1 >= ID_HER_NORMALFILE && Param1 <= ID_HER_SELECTEDCURSORMARKING)
                || (Msg==DN_CONTROLINPUT && Param1==ID_HER_COLOREXAMPLE && ((INPUT_RECORD *)Param2)->EventType == MOUSE_EVENT && ((INPUT_RECORD *)Param2)->Event.MouseEvent.dwButtonState==FROM_LEFT_1ST_BUTTON_PRESSED))
        {
            HighlightDataColor *EditData = (HighlightDataColor *) SendDlgMessage(hDlg, DM_GETDLGDATA, 0, 0);

            if (Msg==DN_CONTROLINPUT)
            {
                Param1 = ID_HER_NORMALFILE + ((INPUT_RECORD *)Param2)->Event.MouseEvent.dwMousePosition.Y*2;

                if (((INPUT_RECORD *)Param2)->Event.MouseEvent.dwMousePosition.X==1 && (EditData->MarkChar&0x0000FFFF))
                    Param1 = ID_HER_NORMALMARKING + ((INPUT_RECORD *)Param2)->Event.MouseEvent.dwMousePosition.Y*2;
            }

            //Color[0=file, 1=mark][0=normal,1=selected,2=undercursor,3=selectedundercursor]
            FarColor Color=EditData->Color[(Param1-ID_HER_NORMALFILE)&1][(Param1-ID_HER_NORMALFILE)/2];
            Global->Console->GetColorDialog(Color,true,true);
            EditData->Color[(Param1-ID_HER_NORMALFILE)&1][(Param1-ID_HER_NORMALFILE)/2]=Color;

            size_t Size = SendDlgMessage(hDlg,DM_GETDLGITEM,ID_HER_COLOREXAMPLE,0);
            FarGetDialogItem gdi = {sizeof(FarGetDialogItem), Size, static_cast<FarDialogItem*>(xf_malloc(Size))};
            SendDlgMessage(hDlg,DM_GETDLGITEM,ID_HER_COLOREXAMPLE,&gdi);
            //MarkChar это FIXEDIT размером в 1 символ
            wchar_t MarkChar[2];
            FarDialogItemData item= {sizeof(FarDialogItemData),1,MarkChar};
            SendDlgMessage(hDlg,DM_GETTEXT,ID_HER_MARKEDIT,&item);
            EditData->MarkChar=*MarkChar;
            HighlightDlgUpdateUserControl(gdi.Item->VBuf,*EditData);
            SendDlgMessage(hDlg,DM_SETDLGITEM,ID_HER_COLOREXAMPLE,gdi.Item);
            xf_free(gdi.Item);
            return TRUE;
        }

        break;
    case DN_EDITCHANGE:

        if (Param1 == ID_HER_MARKEDIT)
        {
            HighlightDataColor *EditData = (HighlightDataColor *) SendDlgMessage(hDlg, DM_GETDLGDATA, 0, 0);
            size_t Size = SendDlgMessage(hDlg,DM_GETDLGITEM,ID_HER_COLOREXAMPLE,0);
            FarGetDialogItem gdi = {sizeof(FarGetDialogItem), Size, static_cast<FarDialogItem*>(xf_malloc(Size))};
            SendDlgMessage(hDlg,DM_GETDLGITEM,ID_HER_COLOREXAMPLE,&gdi);
            //MarkChar это FIXEDIT размером в 1 символ
            wchar_t MarkChar[2];
            FarDialogItemData item= {sizeof(FarDialogItemData),1,MarkChar};
            SendDlgMessage(hDlg,DM_GETTEXT,ID_HER_MARKEDIT,&item);
            EditData->MarkChar=*MarkChar;
            HighlightDlgUpdateUserControl(gdi.Item->VBuf,*EditData);
            SendDlgMessage(hDlg,DM_SETDLGITEM,ID_HER_COLOREXAMPLE,gdi.Item);
            xf_free(gdi.Item);
            return TRUE;
        }

        break;
    case DN_CLOSE:

        if (Param1 == ID_FF_OK && SendDlgMessage(hDlg,DM_GETCHECK,ID_FF_MATCHSIZE,0))
        {
            string strTemp;
            FarDialogItemData item = {sizeof(FarDialogItemData)};
            item.PtrLength = SendDlgMessage(hDlg,DM_GETTEXT,ID_FF_SIZEFROMEDIT,0);
            item.PtrData = strTemp.GetBuffer(item.PtrLength+1);
            SendDlgMessage(hDlg,DM_GETTEXT,ID_FF_SIZEFROMEDIT,&item);
            bool bTemp = !*item.PtrData || CheckFileSizeStringFormat(item.PtrData);
            item.PtrLength = SendDlgMessage(hDlg,DM_GETTEXT,ID_FF_SIZETOEDIT,0);
            item.PtrData = strTemp.GetBuffer(item.PtrLength+1);
            SendDlgMessage(hDlg,DM_GETTEXT,ID_FF_SIZETOEDIT,&item);
            bTemp = bTemp && (!*item.PtrData || CheckFileSizeStringFormat(item.PtrData));

            if (!bTemp)
            {
                intptr_t ColorConfig = SendDlgMessage(hDlg, DM_GETDLGDATA, 0, 0);
                Message(MSG_WARNING,1,ColorConfig?MSG(MFileHilightTitle):MSG(MFileFilterTitle),MSG(MBadFileSizeFormat),MSG(MOk));
                return FALSE;
            }
        }

        break;
    default:
        break;
    }

    return DefDlgProc(hDlg,Msg,Param1,Param2);
}