Exemplo n.º 1
0
//-----------------------------------------------------------
//return no of times function key {xx y} will be pressed
//strip out count charcters
int GetFunctionKeyCount(CString &fk)
{
	int rv=1;

	int numstart=fk.LastDelimiter(" ");

	if (numstart!=0 && numstart<fk.GetLength())
	{
		//extract count
		rv=StrToIntDef(fk.SubString(numstart,999),-1);

		//valid numeric characters?
		if (rv>=0)
		{
			//strip out count characters
			fk=fk.SubString(1,numstart-1);
		}
		else
		{
			rv=1;
		}
	}

	return rv;
}
Exemplo n.º 2
0
void CHttpParameter::Parse(const CString& val)
{
	int pos = val.FindFirstOf('=');
	//check validity here
	if(pos == -1)
	{
		_name.Clear();
		_value.Clear();
		return;
	}

	_name = val.SubString(0,pos);
	_value = val.SubString(pos + 1,val.GetLength() - pos - 1);
}
Exemplo n.º 3
0
			const CString	GetDirectory(const CString& strPath){
				if(strPath.IsEmpty()){
					return L"";
				}
				CString strNewPath = RepairDirectorySlashes(strPath);

				if(strNewPath[strNewPath.GetLength()-1] == L'/'){
					if(strNewPath.GetLength() == 1){
						return L"/";
					}
					else{
						return strNewPath;
					}
				}

				unsigned uPos = 0;
				if(!strNewPath.FindLast(L"/", uPos)){
					return L"";
				}

				if(uPos == 0){
					return L"/";
				}

				return strNewPath.SubString(0, uPos) + L"/";
			}
Exemplo n.º 4
0
			const CString	GetDirectoryBase(const CString& strPath){
				CString strDirectory = GetDirectory(strPath);
				if(strDirectory.IsEmpty() || strDirectory == L"/"){
					return L"";
				}

				unsigned uPos = 0;
				if(!strDirectory.FindLast(L"/", strDirectory.GetLength() - 2, uPos)){
					return strDirectory.SubString(0, strDirectory.GetLength() - 1);
				}

				return strDirectory.SubStringIndexed(uPos + 1, strDirectory.GetLength() - 1);
			}
Exemplo n.º 5
0
			const CString	GetFilenameBase(const CString& strPath){
				CString strFilename = GetFilename(strPath);

				unsigned uDotPos = 0;
				if(!strFilename.FindLast(L".", uDotPos)){
					return strFilename;
				}

				if(uDotPos == 0){
					return L"";
				}

				return strFilename.SubString(0, uDotPos);
			}
Exemplo n.º 6
0
			const CString	GetFilenameExt(const CString& strPath){
				CString strFilename = GetFilename(strPath);

				unsigned uDotPos = 0;
				if(!strFilename.FindLast(L".", uDotPos)){
					return L"";
				}

				if(uDotPos + 1 == strFilename.GetLength()){
					return L"";
				}

				return strFilename.SubString(uDotPos + 1);
			}
Exemplo n.º 7
0
			const CString	GetFilename(const CString& strPath){
				if(strPath.IsEmpty()){
					return L"";
				}
				CString strNewPath = RepairDirectorySlashes(strPath);

				unsigned uPos = 0;
				if(!strNewPath.FindLast(L"/", uPos)){
					return strNewPath;
				}

				if(uPos == 0 && strNewPath.GetLength() == 1){
					return L"";
				}

				if(uPos + 1 == strNewPath.GetLength()){
					return L"";
				}

				return strNewPath.SubString(uPos + 1);
			}
Exemplo n.º 8
0
			const CString	CombineFilename(const CString& strName, const CString& strExt){
				if(strName.IsEmpty() || strExt.IsEmpty()){
					return L"";
				}
				CString strFilename = strName;
				if(strFilename[strFilename.GetLength() - 1] == L'.'){
					if(strFilename.GetLength() == 1){
						strFilename = L"";
					}
					else{
						strFilename = strFilename.SubString(0, strFilename.GetLength() - 1);
					}
				}

				if(strExt[0] == L'.'){
					return strFilename + strExt;
				}
				else{
					return strFilename + L'.' + strExt;
				}
			}
Exemplo n.º 9
0
//-----------------------------------------------------------
//friend of TPK on key handler
//extract key string and pass to handler
//process keypushes etc on return
void OnKeyHandler(bool IsFnKey,CString Key)
{
	CString k=Key;
	CString uk=k.UpperCase();

	int count;
	bool CallKeyHandler=false;

	//delay
	bool IsSleep=uk.Pos("SLEEP")==1;

	//*********************
	//clear clipboard
	bool IsClearClip=uk.Pos("EMPTYCLIP")==1;

	//run
	bool IsRun=uk.Pos("RUN ")==1;

	//{\0xxx}
	bool IsDirect=k.Pos("\\")==1 && k.GetLength()>1;

	if (k=="\\")
	{
		IsDirect=false;
		IsFnKey=false;
	}

	//function key? or clear clipboard or run
	if(IsFnKey || IsSleep || IsDirect  || IsClearClip || IsRun)
	{
		//get count value & strip out count characters
		if (!IsRun)
		{
			count=GetFunctionKeyCount(k);
		}

		if(IsAFunctionKey(uk) || IsDirect)
		{
			//not a control key?
			if (GetControlKey(uk)==(byte)-1)
				k="{"+uk+"}";

			CallKeyHandler=true;

		}

		//sleep or clear clipboard or run
		if (IsSleep || IsClearClip || IsRun)
		{
			k="{"+Key.UpperCase()+"}";
			CallKeyHandler=true;
		}
	}
	else
	{
		if (k.GetLength()==1)
		{
			CallKeyHandler=true;

		}
	}

	if (!CallKeyHandler)
		return;


	//set up shiftstate to pass here
	//**************************
	TShiftState KeyState,CopyOfKeyState;
	if (ShiftOn)
		KeyState<<ssShift;

	if (ControlOn)
		KeyState<<ssCtrl;

	if (AltOn)
		KeyState<<ssAlt;

	//keep a copy
	CopyOfKeyState=KeyState;

	//pass to onkey & delay handler
	//************************
	GTPK->HandleOnKeyEvent(k,KeyState);

	//returned keys
	//************************
	CString returned=k;
	int rl=returned.GetLength();
	uk=returned.UpperCase();

	if (rl==0)
		return;

	//process returned shiftstate
	//**************
	//changed?
	if (KeyState!=CopyOfKeyState)
	{
		//set key states
		SetKeyStates(KeyState);
	}

	//process keys returned
	//***************************
	IsSleep=uk.Pos("{SLEEP")==1;

	//clear clipboard
	IsClearClip=uk.Pos("{EMPTYCLIP")==1;

	//run
	IsRun=uk.Pos("{RUN ")==1;

	//single key(s)?
	if (rl<3)
	{
		PushAString(returned);
	}
	else
	{
		if (returned[1]=='{' && returned[rl]=='}')
		{
			//strip out braces
			CString fk=returned.SubString(2,rl-2).UpperCase();

			bool IsNL=k=="{NEWLINE}" || uk=="{NL}";

			//is it a function key?
			if(IsAFunctionKey(fk) && !IsNL)
			{
				PushFnKey(fk);
			}
			//CRLF
			else if (IsNL)
			{
				// New line = Carriage return & Line Feed = ^M^J
				for (int i=0;i<count;i++)
				{
					if (DOSKey)//ANSI equivalent
					{
						PushCTRLKey('M');
						PushCTRLKey('J');
					}
					else
					{
						UINT ScanKey = MapVirtualKey(VK_RETURN, 0);
						PressKey(VK_RETURN,ScanKey);
						ScanKey = MapVirtualKey(VK_LINEFEED, 0);
						PressKey(VK_LINEFEED,ScanKey);
					}
				}
			}
			//direct {\xxxx}
			else if(fk.Pos("\\")==1 && fk.GetLength()>1)
			{
				if (fk.GetLength()>1)
				{
					//start key presses
					ALTOn();

					//step along numbers
					for (int numpointer=2;numpointer<=fk.GetLength();numpointer++)
					{
						char number=fk[numpointer];

						if (number>='0' && number<='9')
						{
							//get numpad key
							byte npk[]={VK_NUMPAD0,VK_NUMPAD1,VK_NUMPAD2,VK_NUMPAD3,VK_NUMPAD4
								,VK_NUMPAD5,VK_NUMPAD6,VK_NUMPAD7,VK_NUMPAD8,VK_NUMPAD9};

							byte numpadkey=npk[number-'0'];

							//press key
							PressKey(numpadkey,MapVirtualKey(numpadkey,0));
						}

					}

					//all done
					ALTOff();
				}
			}
			//delay
			else if(IsSleep)//sleep
			{
				int count=GetFunctionKeyCount(fk);
				DoDelay(count);
			}
			//clear clipboard
			else if (IsClearClip)
			{
				int count=GetFunctionKeyCount(fk);
				for (int c=0;c<count;c++)
				{
					if (OpenClipboard(NULL))
					{
						EmptyClipboard();
						CloseClipboard();
					}
				}
			}
			else if (IsRun)//run
			{
				CString runcmd=Key.SubString(4,fk.GetLength());
				WinExec(runcmd.c_str(),SW_SHOWNORMAL);
			}

			else //do single keys
			{
				PushAString(returned);
			}
		}
		else
		{
			PushAString(returned);
		}
	}

	//reset changed shiftstate
	//**************
	//changed?
	if (KeyState!=CopyOfKeyState)
	{
		//reset key states
		SetKeyStates(CopyOfKeyState);
	}

	//do inter-key delay if not a sleep command
	if(!IsSleep)
	{
		GTPK->DoKeyDelay();
	}
}