コード例 #1
0
ファイル: StationDlg.cpp プロジェクト: AllegianceZone/ICE
void CStationDlg::OnClickedDecodeh(void)
{
	CEdit *cetodo = (CEdit *) CWnd::GetDlgItem(IDC_TODO1);
	int i,j;
	cetodo->GetSel(i,j);

	// NT SPECIFIC
   HLOCAL h = cetodo->GetHandle();
   LPCTSTR lpszText = (LPCTSTR)LocalLock(h);
	char res[1000];
	strncpy(res,&(lpszText[i]),j-i);
	SetDlgItemText(IDC_DECDEC,res);
	unsigned short f;
	unsigned char *pf;
	unsigned int b1,b2;
	pf = (unsigned char *)&f;
	sscanf(res,"%x %x",&b1,&b2);
	pf[0] = b1;
	pf[1] = b2;
	CString sres;
	sres.Format("%04X = %d",f,f);
	SetDlgItemText(IDC_DECFLOAT,sres);
	
   LocalUnlock(h);
	// END OF NT SPECIFIC
}
コード例 #2
0
ファイル: StationDlg.cpp プロジェクト: AllegianceZone/ICE
void CStationDlg::OnClickedDecodesel(void)
{
	CEdit *cetodo = (CEdit *) CWnd::GetDlgItem(IDC_TODO1);
	int i,j;
	cetodo->GetSel(i,j);

	// NT SPECIFIC
   HLOCAL h = cetodo->GetHandle();
   LPCTSTR lpszText = (LPCTSTR)LocalLock(h);
	char res[1000];
	strncpy(res,&(lpszText[i]),j-i);res[j-i] = 0;
	CString sres = res;
	sres.Replace("\r\n","");
	SetDlgItemText(IDC_DECDEC,sres);
	float f;
	unsigned char *pf;
	unsigned int b1,b2,b3,b4;
	pf = (unsigned char *)&f;
	sscanf(sres,"%x %x %x %x",&b1,&b2,&b3,&b4);
	pf[0] = b1;
	pf[1] = b2;
	pf[2] = b3;
	pf[3] = b4;
	sres.Format("%g",f);
	SetDlgItemText(IDC_DECFLOAT,sres);
	
   LocalUnlock(h);
	// END OF NT SPECIFIC
}
コード例 #3
0
ファイル: FavHubProperties.cpp プロジェクト: strogo/StrongDC
LRESULT FavHubProperties::OnTextChanged(WORD /*wNotifyCode*/, WORD wID, HWND hWndCtl, BOOL& /*bHandled*/)
{
	TCHAR buf[256];

	GetDlgItemText(wID, buf, 256);
	tstring old = buf;

	// Strip '$', '|' and ' ' from text
	TCHAR *b = buf, *f = buf, c;
	while( (c = *b++) != 0 )
	{
		if(c != '$' && c != '|' && (wID == IDC_HUBUSERDESCR || c != ' ') && ( (wID != IDC_HUBNICK) || (c != '<' && c != '>')) )
			*f++ = c;
	}

	*f = '\0';

	if(old != buf)
	{
		// Something changed; update window text without changing cursor pos
		CEdit tmp;
		tmp.Attach(hWndCtl);
		int start, end;
		tmp.GetSel(start, end);
		tmp.SetWindowText(buf);
		if(start > 0) start--;
		if(end > 0) end--;
		tmp.SetSel(start, end);
		tmp.Detach();
	}

	return TRUE;
}
コード例 #4
0
LRESULT GeneralPage::onTextChanged(WORD /*wNotifyCode*/, WORD wID, HWND hWndCtl, BOOL& /*bHandled*/)
{
	tstring buf;
	GET_TEXT(wID, buf);
	tstring old = buf;
	
	// TODO: move to Text and cleanup.
	if (!buf.empty())
	{
		// Strip '$', '|', '<', '>' and ' ' from text
		TCHAR *b = &buf[0], *f = &buf[0], c;
		while ((c = *b++) != '\0')
		{
			if (c != '$' && c != '|' && (wID == IDC_DESCRIPTION || c != ' ') && ((wID != IDC_NICK && wID != IDC_DESCRIPTION && wID != IDC_SETTINGS_EMAIL) || (c != '<' && c != '>')))
				*f++ = c;
		}
		
		*f = '\0';
	}
	if (old != buf)
	{
		// Something changed; update window text without changing cursor pos
		CEdit tmp;
		tmp.Attach(hWndCtl);
		int start, end;
		tmp.GetSel(start, end);
		tmp.SetWindowText(buf.data());
		if (start > 0) start--;
		if (end > 0) end--;
		tmp.SetSel(start, end);
		tmp.Detach();
	}
	
	return TRUE;
}
コード例 #5
0
ファイル: CheckEdit.cpp プロジェクト: jxhot85/counter
//只允许输入数字 小数点
void CCheckEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	//只接受 数字、小数点、退格
	if( (nChar < '0' || nChar > '9') && nChar != '.' && nChar != VK_BACK )
		return ;

	CString strCheck;
	CEdit *pEdit = (CEdit*)GetFocus();
	pEdit->GetWindowTextW(strCheck);
	DWORD dwSel = pEdit->GetSel();

	//光标在最左边  1.不允许输入小数点	2.除了个位为0外,最高位不能为 0
	if(dwSel == 0){
		if(nChar == '.' || (nChar == '0' && !strCheck.IsEmpty()))
			return ;
	}
	//光标不在最左边  1.只允许输入一个小数点	2.只有一个0的情况下,除了小数点外任何数字均覆盖掉0(这里要做的就是清空)
	else{
		if(nChar == '.' && strCheck.Find(_T('.')) != -1)
			return ;
		if(strCheck.Compare(_T("0")) == 0 && (nChar != '.'&& nChar != VK_BACK))
			pEdit->SetWindowTextW(NULL);
	}

	CEdit::OnChar(nChar, nRepCnt, nFlags);
}
コード例 #6
0
ファイル: StringDlg.cpp プロジェクト: Joincheng/lithtech
void CStringDlg::OnChangeEnteredtext() 
{
	CString		sText;
	CString		sNew;
	char		letter[2] = {0,0};
	int			i;

	CEdit		*pEdit = (CEdit*)GetDlgItem( IDC_ENTEREDTEXT );
	int			selStart, selEnd;


	// Validate the string.
	pEdit->GetWindowText( sText );

	for( i=0; i < sText.GetLength(); i++ )
	{
		if( m_bAllowLetters )
		{
			if( isalpha(sText[i]) )
			{
				letter[0] = sText[i];
				sNew += letter;
			}
		}
	
		if( m_bAllowNumbers )
		{
			if( isdigit(sText[i]) )
			{
				letter[0] = sText[i];
				sNew += letter;
			}
		}

		if( m_bAllowOthers )
		{
			if( !isdigit(sText[i]) && !isalpha(sText[i]) )
			{
				letter[0] = sText[i];
				sNew += letter;
			}
		}
	}

	if( (sNew.GetLength() != sText.GetLength()) || (sNew.GetLength() > m_MaxStringLen) )
	{
		if( sNew.GetLength() > m_MaxStringLen )
			sNew = sNew.Left(m_MaxStringLen);

		pEdit->GetSel( selStart, selEnd );
		pEdit->SetWindowText( sNew );
		pEdit->SetSel( selStart-1, selEnd-1 );
	
		if( m_bBeeping )
			MessageBeep(0);
	}

	GetDlgItem(IDOK)->EnableWindow(strlen(sNew) > 0 ? TRUE : FALSE);	
}
コード例 #7
0
ファイル: BibitemView.cpp プロジェクト: stievie/bibedt
void CBibitemView::OnUpdateEditDelete(CCmdUI* pCmdUI) 
{
	CEdit* edit = GetFocusEdit();
	if (edit) {
		int s, e;
		edit->GetSel(s, e);
		pCmdUI->Enable(edit && s != e);
	} else
		pCmdUI->Enable(FALSE);
}
コード例 #8
0
void CGridDlg::setColorCount(int value) {
  if(value >= 2 || (value == 0)) {
    CEdit *e = (CEdit*)GetDlgItem(IDC_EDITCOLORCOUNT);
    const DWORD sel = e->GetSel();
    m_colorCount = value;
    flushData();
    windowToValue();
    e->SetSel(sel);
  }
}
コード例 #9
0
// @pymethod (start, end)|PyCEdit|GetSel|Returns the start and end of the current selection.
static PyObject *PyCEdit_get_sel(PyObject *self, PyObject *args)
{
	CHECK_NO_ARGS(args);
	CEdit *pEdit = GetEditCtrl(self);
	if (!pEdit)
		return NULL;
	int start,end;
	GUI_BGN_SAVE;
	pEdit->GetSel(start,end); // @pyseemfc CEdit|GetSel
	GUI_END_SAVE;
	return Py_BuildValue("(ii)",start,end);
	// @rdesc The return tuple is (the first character in the current selection, first nonselected character past the end of the current selection)
}
コード例 #10
0
ファイル: EditBar.cpp プロジェクト: Liscar/jmc
void CEditBar::DoPaste()
{
    CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT);
    ASSERT(pEdit);
    if ( !OpenClipboard() ) 
        return;
    HANDLE hData = GetClipboardData(CF_TEXT);
    ASSERT(hData);
    if ( hData == NULL ) 
        return;

    CString str = (LPSTR)GlobalLock(hData);
    GlobalUnlock(hData);
    CloseClipboard();
    CString strIns, strAdd;
    pEdit->GetWindowText(strIns);
    char* src = (LPSTR)(LPCSTR)str;
    int StartSel, EndSel;
    pEdit->GetSel(StartSel, EndSel);
    CWnd* pWnd = ((CMainFrame*)AfxGetMainWnd())->GetActiveView();

    do {
        switch (*src ) {
        case '\n':
            strIns = "";
            pEdit->SetWindowText(strAdd);
            if ( pWnd ) 
                pWnd->SendMessage(WM_USER+100 , 0 , 0 );
            strAdd = "";
            break;
        case '\r':
            break;
        case 0:
            break;
        default:
            strAdd += *src;
            break;
        };

    } while (*src++);
    if ( strAdd.GetLength() ) {
        int size = strAdd.GetLength();
        strAdd = strIns.Left(StartSel) + strAdd + strIns.Right(strIns.GetLength() - EndSel);
        
        pEdit->SetWindowText(strAdd);
        pEdit->SetSel(StartSel+ size, StartSel+size, TRUE);
    }
}
コード例 #11
0
ファイル: StringDlg.cpp プロジェクト: Joincheng/lithtech
void CStringDlg::OnChangeEnteredtext() 
{
	CString		sText;
	CString		sNew;
	int			i;

	CEdit		*pEdit = (CEdit*)GetDlgItem( IDC_ENTEREDTEXT );
	int			selStart, selEnd;


	// Validate the string.
	pEdit->GetWindowText( sText );

	for( i=0; i < sText.GetLength(); i++ )
	{
		bool bAddChar = FALSE;

		// Filter out invalid characters based on the flags
		bAddChar |= (m_bAllowLetters) && isalpha(sText[i]);
		bAddChar |= (m_bAllowNumbers) && isdigit(sText[i]);
			// Note : Spaces are not allowed in file names to facilitate command line parsing
		bAddChar |= (m_bAllowFile) && (!strchr("\\/:*?\"<>| ", sText[i]));
		bAddChar |= (m_bAllowOthers) && (!isdigit(sText[i]) && !isalpha(sText[i]));

		if (bAddChar)
			sNew += sText[i];
	}

	if( (sNew.GetLength() != sText.GetLength()) || (sNew.GetLength() > m_MaxStringLen) )
	{
		if( sNew.GetLength() > m_MaxStringLen )
			sNew = sNew.Left(m_MaxStringLen);

		pEdit->GetSel( selStart, selEnd );
		pEdit->SetWindowText( sNew );
		pEdit->SetSel( selStart-1, selEnd-1 );
	
		if( m_bBeeping )
			MessageBeep(0);
	}

	GetDlgItem(IDOK)->EnableWindow(strlen(sNew) > 0 ? TRUE : FALSE);	
}
コード例 #12
0
// This routine updates the directory/file list display using the directory
// name given.  It does this by putting the name in the (hidden) edit control
// and simulating a press of the (hidden) IDOK button.  If the directory is
// invalid in some way the currently displayed list will not be changed and
// some sort of error message may be displayed.
void CDlgWnd::CheckDir(const CString &ss)
{
    // Put the new directory into the old (hidden) edit box
    CEdit *pOld = (CEdit *)GetDlgItem(edt1);
    ASSERT(pOld != NULL);
    pOld->SetWindowText(ss);

    // Save the current text/selection in the edit control
    CString strSaved;                       // Current text in edit box
    int start, end;                         // Current selection in edit box
    CEdit *pEdit = (CEdit *)GetDlgItem(IDC_DIR);
    ASSERT(pEdit != NULL);
    pEdit->GetWindowText(strSaved);
    pEdit->GetSel(start, end);

    CWnd *pOK = GetDlgItem(IDOK);
    pOK->SendMessage(WM_LBUTTONDOWN);
    pOK->SendMessage(WM_LBUTTONUP);

    CString strNew;
    pEdit->GetWindowText(strNew);

    // Usually we want to keep what the user has typed (strSaved) rather than what has been
    // put in the edit control due to OnFolderChange.  One exception is if the user has
    // used "..", "..." etc to change to an ancestor directory in which case we don't want to
    // leave this the same as it will cause repeated changes to ancestor directories whenever
    // the user types backslash (\).  Also don;t set the edit string back to what the user
    // typed if it would be empty or unchanged except for case (as the case probably looks
    // better the way it was filled in).
    if (strSaved.IsEmpty() || strSaved[0] == '.' ||
        strNew.CompareNoCase(strSaved) == 0 || strNew.CompareNoCase(strSaved + '\\') == 0)
    {
        pEdit->SetSel(strNew.GetLength(), -1);
    }
    else
    {
        // Restore the edit control the way the user typed it
        pEdit->SetWindowText(strSaved);
        pEdit->SetSel(start, end);
    }
}
コード例 #13
0
BOOL CValueDescriptionDlg::PreTranslateMessage(MSG* pMsg)
{
    // Do not process non-hexadecimal characters
    // in signal value edit control
    BOOL bSkip = FALSE;
    CEdit* omEditCtrlName   = (CEdit*) GetDlgItem(IDC_EDIT_VAL);
    CEdit* omEditFocusName  = (CEdit*) GetFocus();
    if ( pMsg->message == WM_CHAR )
    {
        if ( omEditCtrlName == omEditFocusName )
        {
            int nStart, nEnd;
            omEditCtrlName->GetSel(nStart, nEnd);
            if (nStart == 0 &&
                    pMsg->wParam == MINUS_SIGN)
            {
                bSkip = FALSE;
            }
            else if ( ( pMsg->wParam >= 0x61 && pMsg->wParam<=0x66 )|| // A-F
                      ( pMsg->wParam >= 0x41 && pMsg->wParam<=0x46 )||// a-f
                      ( pMsg->wParam >= '0' && pMsg->wParam <='9' ) ||// 0-9
                      pMsg->wParam == 0x08 )// BackSpace
            {
                bSkip = FALSE;
            }
            else
            {
                bSkip = TRUE;
            }
        }
    }
    if ( bSkip == FALSE )
    {
        bSkip = CDialog::PreTranslateMessage(pMsg);
    }

    return bSkip;
}
コード例 #14
0
ファイル: DirDialog.cpp プロジェクト: Andrew-Phillips/HexEdit
// This routine updates the directory/file list display using the directory
// name given.  It does this by putting the name in the (hidden) edit control
// and simulating a press of the (hidden) IDOK button.  If the directory is
// invalid in some way the currently displayed list will not be changed and
// some sort of error message may be displayed.
void CDlgWnd::CheckDir(const CString &ss)
{
	// Put the new directory into the old (hidden) edit box
	CWnd *pOld = GetDlgItem(edt1);
	if (pOld == NULL)
		pOld = GetDlgItem(cmb13);    // edit control replaced with combo in newer Windows versions
	ASSERT(pOld != NULL);
	pOld->SetWindowText(ss);

	// Save the current text/selection in the edit control
	CString strSaved;                       // Current text in edit box
	int start, end;                         // Current selection in edit box
	CEdit *pEdit = (CEdit *)GetDlgItem(IDC_DIR);
	ASSERT(pEdit != NULL);
	pEdit->GetWindowText(strSaved);
	pEdit->GetSel(start, end);

	CWnd *pOK = GetDlgItem(IDOK);
	ASSERT(pOK != NULL);
	pOK->SendMessage(WM_LBUTTONDOWN);
	pOK->SendMessage(WM_LBUTTONUP);

	CString strNew;
	pEdit->GetWindowText(strNew);

	if (strSaved.GetLength() >= 1 && strSaved[0] == '\\' ||
		 strSaved.GetLength() >= 3 && strSaved[1] == ':' && strSaved[2] == '\\')
	{
		// Keep the text the way the user typed it if we can
		pEdit->SetWindowText(strSaved);
		pEdit->SetSel(start, end);
	}
	else
	{
		// Move cursor to the end
		pEdit->SetSel(strNew.GetLength(), -1);
	}
}
コード例 #15
0
ファイル: EditBar.cpp プロジェクト: Liscar/jmc
void CEditBar::OnKillFocus()
{
    CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT);
    pEdit->GetSel(m_nCurSelStart , m_nCurSelEnd);
}
コード例 #16
0
long CMUSHclientDoc::SpellCheckCommand(long StartCol, long EndCol) 
{
  if (!App.m_bSpellCheckOK)
    return -1;

  CEdit * pEdit = NULL;
  CWnd * pWnd = NULL;

  // find command window

  for(POSITION pos = GetFirstViewPosition(); pos != NULL; )
	  {
	  CView* pView = GetNextView(pos);
	  
	  if (pView->IsKindOf(RUNTIME_CLASS(CSendView)))
  	  {
		  CSendView* pmyView = (CSendView*)pView;

      // what is the current selection?

      pWnd = pmyView;
      pEdit = & (pmyView->GetEditCtrl());
      break;
      
      }	  // end of being a CSendView
    }   // end of loop through views

  if (pEdit == NULL)
	  return -1;    // couldn't find it

  int nStartChar, 
      nEndChar;

  // get current selection
  pEdit->GetSel (nStartChar, nEndChar); 

  // make wanted selection 1-relative
  if (StartCol > 0)
    StartCol--;

  bool bHaveSelection = EndCol > StartCol &&
                         StartCol >= 0 &&
                         EndCol >= 0;

  // select what the scripter wanted
  if (bHaveSelection)
     pEdit->SetSel (StartCol, EndCol); 

  if (App.m_SpellChecker_Lua)
    {

    lua_settop(App.m_SpellChecker_Lua, 0);   // clear stack

    lua_getglobal (App.m_SpellChecker_Lua, SPELLCHECKFUNCTION);  
    if (!lua_isfunction (App.m_SpellChecker_Lua, -1))
      return true;  // assume ok, what can we do?

    CString strText;
    bool bAll = GetSelection (pEdit, strText);
    
    lua_pushstring (App.m_SpellChecker_Lua, strText);  // string to be checked
    lua_pushboolean (App.m_SpellChecker_Lua, bAll);    // doing all?

    int narg = lua_gettop(App.m_SpellChecker_Lua) - 1;  // all but the function
    int error = CallLuaWithTraceBack (App.m_SpellChecker_Lua, narg, 1);
    
    if (error)
      {
      LuaError (App.m_SpellChecker_Lua, "Run-time error", SPELLCHECKFUNCTION, "Command-line spell-check");
      lua_close (App.m_SpellChecker_Lua);
      App.m_SpellChecker_Lua = NULL;
      App.m_bSpellCheckOK = false;
      return -1;    
      }  

    if (lua_isstring (App.m_SpellChecker_Lua, -1))
      {
      const char * p = lua_tostring (App.m_SpellChecker_Lua, -1);
      if (bAll)
        pEdit->SetSel (0, -1, TRUE);
      pEdit->ReplaceSel (p, true);
      // put original selection back
      pEdit->SetSel (nStartChar, nEndChar); 
      return 1;   // spell checked ok
      }

    // put original selection back
    pEdit->SetSel (nStartChar, nEndChar); 
    return 0;      // they cancelled
    }

  return -1;

} // end of CMUSHclientDoc::SpellCheckCommand
コード例 #17
0
/////////////////////////////////////////////////////////////////////////////
//	OnEditVerifyFloatCell
//		This is a handy utility to keep user entry in floating point number cells valid as they type.
//    The caller should determine that the cell is for percent entry, and if so
//    can pass verification of the input key to this function.
//	Params:
//		col, row	- location of the edit cell
//		edit		-	pointer to the edit control
//		vcKey		- virtual key code of the pressed key
//	Return:
//		TRUE - to accept pressed key
//		FALSE - to do not accept the key
int CDDBaseGrid::OnEditVerifyFloatCell(int col, long row,CWnd *edit,UINT *vcKey)
{
   // Cursor movement keys are okay
   // But these symbols don't work ... ?
   //if (*vcKey == VK_BACK || *vcKey == VK_LEFT || *vcKey == VK_RIGHT || *vcKey == VK_DELETE)
   //   return TRUE;
   if (*vcKey == VK_BACK || *vcKey == 0x7F /*Delete*/)
      return TRUE;

   // Current selection will be replaced, so chars in there don't matter, remove them from
   // consideration during validation tests.
   CString curTxt;
   CEdit *cedit = (CEdit*)edit;
   edit->GetWindowText(curTxt);
   int startIndx = -1, endIndx = -1;
   cedit->GetSel(startIndx, endIndx);
   if (startIndx > -1 && endIndx > startIndx)
      curTxt.Delete(startIndx, endIndx - startIndx);

   int curMinusIndx = curTxt.Find("-");

   // Alpha chars '.' and '-' accepted, but only one per customer
   if (*vcKey == '.' || *vcKey == '-')
   {
      // Possibly okay, make sure no duplicate of percent or decimal pt.

      int curDecimalIndx = curTxt.Find(".");

      // Can only have one of these
      if (*vcKey == '-' && curMinusIndx > -1)
      {
         MessageBeep((UINT)-1);
         return FALSE;
      }
      if (*vcKey == '.' && curDecimalIndx > -1)
      {
         MessageBeep((UINT)-1);
         return FALSE;
      }

      // Can't put decimal before minus
      if (*vcKey == '.' && curMinusIndx > -1 && startIndx <= curMinusIndx)
      {
         MessageBeep((UINT)-1);
         return FALSE;
      }

      // Minus can only go at beginning
      if (*vcKey == '-' && startIndx != 0)
      {
         MessageBeep((UINT)-1);
         return FALSE;
      }

      // Okay, we'll accept the char
      return TRUE;
   }

   // We're accepting digits, but not in front of minus sign
   if (isdigit(*vcKey))
   {
      // Can't put digits in front of minus
      if (curMinusIndx > -1 && startIndx <= curMinusIndx)
      {
         MessageBeep((UINT)-1);
         return FALSE;
      }

      // Okay
      return TRUE;
   }

   // All else
   MessageBeep((UINT)-1);
   return FALSE;
}
コード例 #18
0
/////////////////////////////////////////////////////////////////////////////
//	OnEditVerifyPercentCell
//		This is a handy utility to keep user entry in percent cells valid as they type.
//    The caller should determine that the cell is for percent entry, and if so
//    can pass verification of the input key to this function.
//	Params:
//		col, row	- location of the edit cell
//		edit		-	pointer to the edit control
//		vcKey		- virtual key code of the pressed key
//	Return:
//		TRUE - to accept pressed key
//		FALSE - to do not accept the key
int CDDBaseGrid::OnEditVerifyPercentCell(int col, long row,CWnd *edit,UINT *vcKey)
{
   // Cursor movement keys are okay
   // But these symbols don't work ... ?
   //if (*vcKey == VK_BACK || *vcKey == VK_LEFT || *vcKey == VK_RIGHT || *vcKey == VK_DELETE)
   //   return TRUE;
   if (*vcKey == VK_BACK || *vcKey == 0x7F /*Delete*/ 
      || *vcKey == VK_CANCEL/*Ctrl+C*/ || *vcKey == 0x16/*Ctrl+V*/)
      return TRUE;

   // Current selection will be replaced, so chars in there don't matter, remove them from
   // consideration during validation tests.
   CString curTxt;
   CEdit *cedit = (CEdit*)edit;
   edit->GetWindowText(curTxt);
   int startIndx = -1, endIndx = -1;
   cedit->GetSel(startIndx, endIndx);
   if (startIndx > -1 && endIndx > startIndx)
      curTxt.Delete(startIndx, endIndx - startIndx);

   int curPercentIndx = curTxt.Find("%");

   // Alpha chars '.' and '%' accepted, but only one per customer
   if (*vcKey == '%' || *vcKey == '.')
   {
      // Possibly okay, make sure no duplicate of percent or decimal pt.

      int curDecimalIndx = curTxt.Find(".");

      // Can only have one of these
      if (*vcKey == '%' && curPercentIndx > -1)
      {
         MessageBeep((UINT)-1);
         return FALSE;
      }
      if (*vcKey == '.' && curDecimalIndx > -1)
      {
         MessageBeep((UINT)-1);
         return FALSE;
      }

      // Can't put decimal after percent
      // startIndx is where new char will go
      if (*vcKey == '.' && curPercentIndx > -1 && startIndx > curPercentIndx)
      {
         MessageBeep((UINT)-1);
         return FALSE;
      }

      // Percent can only go at end
      if (*vcKey == '%' && startIndx < curTxt.GetLength())
      {
         MessageBeep((UINT)-1);
         return FALSE;
      }

      // Okay, we'll accept the char
      return TRUE;
   }

   // We're accepting digits, but can't be after percent
   if (isdigit(*vcKey))
   {
      // Can't put digits after percent
      // startIndx is where new char will go
      if (curPercentIndx > -1 && startIndx > curPercentIndx)
      {
         MessageBeep((UINT)-1);
         return FALSE;
      }

      // Okay
      return TRUE;
   }

   // All else
   MessageBeep((UINT)-1);
   return FALSE;
}
コード例 #19
0
BSTR CMUSHclientDoc::Menu(LPCTSTR Items, LPCTSTR Default) 
{
	CString strResult;
  CSendView* pmyView = NULL;


  for(POSITION pos=GetFirstViewPosition();pos!=NULL;)
    {
    CView* pView = GetNextView(pos);

    if (pView->IsKindOf(RUNTIME_CLASS(CSendView)))
      {
      pmyView = (CSendView*)pView;
      break;

      }	  // end of being a CSendView
    }

  if (!pmyView)
    return strResult.AllocSysString();

  CEdit * ctlEdit = & pmyView->GetEditCtrl();

  int nStartChar,
      nEndChar;

  // find the selection range
  ctlEdit->GetSel(nStartChar, nEndChar);

  if (nEndChar < 0)
    nEndChar = nStartChar;

  vector<string> v;

  StringToVector (Items, v, "|");

  int iCount = v.size ();

  // must have at least one item
  if (iCount < 1)
    return strResult.AllocSysString();

  CCompleteWordDlg dlg;
  
  set<string> extraItems;

  for (vector<string>::const_iterator i = v.begin (); i != v.end (); i++)
    extraItems.insert (*i);

  dlg.m_extraItems = &extraItems;
  dlg.m_strDefault = Default;
  dlg.m_bFunctions = false;
  dlg.m_pt = ctlEdit->PosFromChar (nEndChar - 1);  // strangely doesn't work at end of line

  ctlEdit->ClientToScreen(&dlg.m_pt);

  if (dlg.DoModal () == IDOK)
     strResult = dlg.m_strResult;

	return strResult.AllocSysString();
}   // end of CMUSHclientDoc::Menu
コード例 #20
0
ファイル: EditBar.cpp プロジェクト: Liscar/jmc
BOOL CEditBar::PreTranslateMessage(MSG* pMsg) 
{
    CWnd* pWnd;
    CEdit* pEdit;
	if ( pMsg->message == WM_KEYDOWN ) {
        if ( ((CMainFrame*)AfxGetMainWnd())->GetActiveView()->PreTranslateMessage(pMsg) )
            return TRUE;
        switch ( pMsg->wParam ) {
			case VK_RETURN:
			{
				tokenSetup=0;
	 	        if(GetKeyState(VK_SHIFT)&0x1000)  {tokenSetup = 2;}
	 	        if(GetKeyState(VK_CONTROL)&0x1000){tokenSetup = 1;}
     
	            pWnd = ((CMainFrame*)AfxGetMainWnd())->GetActiveView();
		        if ( pWnd ) 
			        pWnd->PostMessage(WM_USER+100 , 0 , 0 );
	            return TRUE;
			}
        case VK_TAB:
            {
                // Check we are in extending mode 
                pEdit = (CEdit*)GetDlgItem(IDC_EDIT);
                if ( m_bExtending ) {
                    // substitute word by new value
                    if ( !m_posCurPos ) 
                        m_posCurPos= m_lstTabWords.GetHeadPosition ();

                    CString strWord = m_lstTabWords.GetNext(m_posCurPos);
                    CString str = m_strStartLine;
                    str += strWord;
                    str+= m_strEndLine;
                    m_bExtendingChange = TRUE;
                    pEdit->SetWindowText (str);
                    pEdit->SetSel (m_strStartLine.GetLength () + strWord.GetLength (), 
                            m_strStartLine.GetLength () + strWord.GetLength ());
                    m_bExtendingChange = FALSE;
                    return TRUE;
                }
                
                // ok, get current line, word etc 
                CString strText;
                pEdit->GetWindowText (strText);

                if ( !strText.GetLength () ) 
                    return TRUE;

                int start, end;
                pEdit->GetSel (start, end);

                if ( end <= 0  || strText[end-1] == ' ') 
                    return TRUE;

                m_strEndLine = strText.Right(strText.GetLength() - end);

                strText = strText.Left(end);

                int cpos = strText.ReverseFind(' ');

                CString strWord;
                if ( cpos < 0 ) {
                    strWord =  strText;
                    m_strStartLine.Empty ();
                } else {
                    strWord = strText.Right(strText.GetLength () - cpos-1);
                    m_strStartLine = strText.Left (cpos +1);
                }
                m_lstTabWords.RemoveAll ();
                // now find all words same as this one 
                CSmcDoc* pDoc = (CSmcDoc*)((CMainFrame*)AfxGetMainWnd())->GetActiveDocument ();
                if ( !pDoc ) 
                    return TRUE;

                m_lstTabWords.AddHead(strWord );
                POSITION pos = pDoc->m_lstTabWords.GetHeadPosition ();
                while ( pos ) {
                    CString str = pDoc->m_lstTabWords.GetNext(pos);
                    if ( !strnicmp(str, strWord, strWord.GetLength()) ) {
                        m_lstTabWords.AddTail (str);
                    }
                }

                if ( m_lstTabWords.GetCount () < 2 ) {
                    m_lstTabWords.RemoveAll ();
                    return TRUE;
                }
                m_bExtending = TRUE;
                m_posCurPos = m_lstTabWords.GetHeadPosition();
                m_lstTabWords.GetNext (m_posCurPos);
                strWord = m_lstTabWords.GetNext (m_posCurPos);
                strText = m_strStartLine + strWord + m_strEndLine;
                m_bExtendingChange = TRUE;
                pEdit ->SetWindowText (strText);
                int selpos = m_strStartLine.GetLength () + strWord.GetLength ();
                pEdit->SetSel (selpos, selpos);
                m_bExtendingChange = FALSE;
                return TRUE;

            }
            break;
        case VK_UP:
            if ( GetKeyState(VK_CONTROL) >= 0 ) {
                PrevLine();
                return TRUE;
            } else 
                return FALSE;
        case VK_DOWN:
            if ( GetKeyState(VK_CONTROL) >= 0 ) {
                NextLine();
                return TRUE;
            } else 
                return FALSE;
        case 'C':
            if ( GetKeyState(VK_CONTROL)&0x1000){
                pEdit = (CEdit*)GetDlgItem(IDC_EDIT);
                pEdit->Copy();
                return TRUE;
            }
            break;
		case VK_DELETE:
            if ( GetKeyState(VK_SHIFT)&0x1000){
                pEdit = (CEdit*)GetDlgItem(IDC_EDIT);
                pEdit->Cut();
                return TRUE;
            }
            break;
        case 'X':
            if ( GetKeyState(VK_CONTROL)&0x1000){
                pEdit = (CEdit*)GetDlgItem(IDC_EDIT);
                pEdit->Cut();
                return TRUE;
            }
            break;
		case VK_INSERT:
            if ( GetKeyState(VK_CONTROL)&0x1000){
                pEdit = (CEdit*)GetDlgItem(IDC_EDIT);
                pEdit->Copy();
                return TRUE;
            }
            if ( GetKeyState(VK_SHIFT)&0x1000){
                /*pEdit = (CEdit*)GetDlgItem(IDC_EDIT);
                pEdit->Paste();*/
                DoPaste();
                return TRUE;
            }
            break;
        case 'V':
            if ( GetKeyState(VK_CONTROL)&0x1000){
                /*pEdit = (CEdit*)GetDlgItem(IDC_EDIT);
                pEdit->Paste();*/
                DoPaste();
                return TRUE;
            }
            break;
        default:
            break;
        };
    }
	if ( pMsg->message == WM_SYSKEYDOWN ) {
        if ( ((CMainFrame*)AfxGetMainWnd())->GetActiveView()->PreTranslateMessage(pMsg) )
            return TRUE;

    }
    
	return CDialogBar::PreTranslateMessage(pMsg);
}
コード例 #21
0
ファイル: functionlist.cpp プロジェクト: RKelson93/mushclient
void FunctionMenu (CEdit & editctrl, const bool bLua, set<string> * extraItems, const bool bFunctions)
  {

  int nStartChar,
      nEndChar;
  CString strWindowContents;

  // find the selection range
  editctrl.GetSel(nStartChar, nEndChar);

  if (nEndChar < 0)
    nEndChar = nStartChar;

  // get window text
  editctrl.GetWindowText (strWindowContents);

  CString strWord = GetSelectedFunction (strWindowContents, nStartChar, nEndChar);

  if (strWord.IsEmpty ())
    return;

  CCompleteWordDlg dlg;

  dlg.m_bLua = bLua;
  dlg.m_extraItems = extraItems;
  dlg.m_bFunctions = bFunctions;
  dlg.m_pt = editctrl.PosFromChar (nEndChar - 1);  // strangely doesn't work at end of line

  dlg.m_pt.x += 10;  // small gap
  dlg.m_pt.y += 10;  // small adjustment lalala

  editctrl.ClientToScreen(&dlg.m_pt);

  dlg.m_strFilter = strWord;     // selected word from dialog/text window

  if (dlg.DoModal () == IDCANCEL || dlg.m_strResult.IsEmpty ())
    return;

  // adjust selection in case we wandered around catching characters around the cursor

  editctrl.SetSel (nStartChar, nEndChar);

  // replace selection with the word they chose
  editctrl.ReplaceSel (dlg.m_strResult, TRUE);
              
  // New in version 4.57 - add the argument list after the function name

  // find the new selection range (ie. where the cursor is after the function name)
  editctrl.GetSel(nStartChar, nEndChar);
  if (nEndChar < 0)
    nEndChar = nStartChar;

  // get window text with function name in it
  editctrl.GetWindowText (strWindowContents);

  nStartChar = nEndChar;
  bool bFoundBracket = false;

  // scan forwards from cursor, looking for bracket (which would have function args in it)
  while (nEndChar < strWindowContents.GetLength () && 
         nEndChar < nStartChar + 30)
    {
    if (strWindowContents [nEndChar] == '(')
      {
      bFoundBracket = true;
      break;
      }
    // non-space means we have skipped the spaces basically, without finding a bracket
    else if (!isspace (strWindowContents [nEndChar]))
      break;
    else
      nEndChar++;
    }

  // if not found, assume a function call at least needs brackets
  // (first check if it *is* a function call and not something like sendto.script)
  if (dlg.m_strArgs.IsEmpty ())
    {
    // see if Lua function
    if (LuaFunctionsSet.find ((LPCTSTR) dlg.m_strResult) != LuaFunctionsSet.end ())
      dlg.m_strArgs = "( )";
    }   // end of no brackets

  // add in arguments if found and no arguments already
  if (!bFoundBracket && !dlg.m_strArgs.IsEmpty ())
    {
    dlg.m_strArgs = " " + dlg.m_strArgs;
    editctrl.ReplaceSel (dlg.m_strArgs, TRUE);
    // put cursor to right of LH bracket (add 2 to skip the space and the bracket)
    editctrl.SetSel (nStartChar + 2, nStartChar + 2);
    }

  // ensure text box has the focus if you click on the 'Complete' button in a dialog box
  // (otherwise the Complete button still has it)

  editctrl.SetFocus ();

  }