示例#1
0
	UIEditBox::UIEditBox(uint32_t type, UIDialogPtr const & dialog)
					: UIControl(type, dialog),
						border_(5),	// Default border width
						spacing_(4),	// Default spacing
#ifdef KLAYGE_PLATFORM_WINDOWS
#ifdef KLAYGE_PLATFORM_WINDOWS_DESKTOP
						blink_time_(GetCaretBlinkTime() * 0.001f),
#else
						blink_time_(1),
#endif
#else
						blink_time_(1),
#endif
						last_blink_time_(timer_.current_time()),
						caret_on_(true),
						caret_pos_(0),
						insert_mode_(true),
						sel_start_(0),
						first_visible_(0),
						text_color_(16.0f / 255, 16.0f / 255, 16.0f / 255, 1),
						sel_text_color_(1, 1, 1, 1),
						sel_bk_color_(40.0f / 255, 50.0f / 255, 92.0f / 255, 1),
						caret_color_(0, 0, 0, 1),
						mouse_drag_(false)
	{
		hide_caret_ = false;

		this->InitDefaultElements();
	}
QVariant QWindowsIntegration::styleHint(QPlatformIntegration::StyleHint hint) const
{
    switch (hint) {
    case QPlatformIntegration::CursorFlashTime:
        if (const unsigned timeMS = GetCaretBlinkTime())
            return QVariant(int(timeMS));
        break;
#ifdef SPI_GETKEYBOARDSPEED
    case KeyboardAutoRepeatRate:
        return QVariant(keyBoardAutoRepeatRateMS());
#endif
    case QPlatformIntegration::StartDragTime:
    case QPlatformIntegration::StartDragDistance:
    case QPlatformIntegration::KeyboardInputInterval:
    case QPlatformIntegration::ShowIsFullScreen:
    case QPlatformIntegration::PasswordMaskDelay:
    case QPlatformIntegration::StartDragVelocity:
        break; // Not implemented
    case QPlatformIntegration::FontSmoothingGamma:
        return QVariant(QWindowsFontDatabase::fontSmoothingGamma());
    case QPlatformIntegration::MouseDoubleClickInterval:
        if (const int ms = GetDoubleClickTime())
            return QVariant(ms);
        break;
    case QPlatformIntegration::UseRtlExtensions:
        return QVariant(d->m_context.useRTLExtensions());
    }
    return QPlatformIntegration::styleHint(hint);
}
示例#3
0
/*
 * NewCursor - create a new cursor for a window
 */
void NewCursor( window_id id, cursor_type ct )
{
    window      *w;
    int         height;
    int         width;

    if( BAD_ID( id ) ) {
        return;
    }
    w = WINDOW_FROM_ID( id );
    height = FontHeight( WIN_FONT( w ) );
    width = FontAverageWidth( WIN_FONT( w ) );
    height = (long) height * ct.height / 100L;
    width = (long) width * ct.width / 100L;
    MyHideCaret( id );
    DestroyCaret();
    cursorHeight = height;
    cursorWidth = width;
    if( !haveOldBlinkTime ) {
        oldBlinkTime = GetCaretBlinkTime();
        haveOldBlinkTime = TRUE;
    }
    CreateCaret( id, (HBITMAP)NULLHANDLE, cursorWidth, cursorHeight );
    SetCursorBlinkRate( EditVars.CursorBlinkRate );
    MyShowCaret( id );
    cursorType = ct;

} /* NewCursor */
示例#4
0
CUIEdit::CUIEdit(CBGame *inGame): CUIObject(inGame) {
	m_Type = UI_EDIT;

	m_FontSelected = NULL;

	m_SelStart = m_SelEnd = 10000;
	m_ScrollOffset = 0;

	m_CursorChar = NULL;
	SetCursorChar("|");

#ifdef __WIN32__
	m_CursorBlinkRate = GetCaretBlinkTime();
#else
	m_CursorBlinkRate = 600;
#endif
	m_FrameWidth = 0;

	SetText("");

	m_LastBlinkTime = 0;
	m_CursorVisible = true;

	m_MaxLength = -1;

	m_CanFocus = true;
}
示例#5
0
文件: Win32Wnd.cpp 项目: koz4k/soccer
void  Ctrl::AnimateCaret()
{
	GuiLock __;
	bool v = !(((GetTickCount() - WndCaretTime) / GetCaretBlinkTime()) & 1);
	if(v != WndCaretVisible) {
		WndCaretVisible = v;
		RefreshCaret();
	}
}
static double querySystemBlinkInterval(double defaultInterval)
{
    UINT blinkTime = GetCaretBlinkTime();
    if (blinkTime == 0)
        return defaultInterval;
    if (blinkTime == INFINITE)
        return 0;
    return blinkTime / 1000.0;
}
示例#7
0
Editor::Editor( EditorListener *l ):
listener(l),sizing(false),
fmtBusy(false),findOnly(false),found(false),
finder(0),selStart(0),selEnd(0),
findFlags(0),lineToFmt(-1){
	findBuff[0]=replaceBuff[0]=0;
	if( !blink ) blink=GetCaretBlinkTime();
	funcList.setListener( this );
	typeList.setListener( this );
	labsList.setListener( this );
	tabber_width=170*GetDPIScaleX();
}
示例#8
0
CUIEditBox::CUIEditBox()
{
    m_Type = UI_CONTROL_EDITBOX;

    m_bCaretOn = true;
    m_dfBlink = GetCaretBlinkTime() * 0.001f;
    m_dfLastBlink = GetTickCount()*0.001f;
    s_bHideCaret = false;
    m_nFirstVisible = 0;
    m_nCaret = m_nSelStart = 0;
    m_bInsertMode = true;

    m_bEditEnabled=true;
    m_bPassword=false;
}
示例#9
0
QVariant QWindowsIntegration::styleHint(QPlatformIntegration::StyleHint hint) const
{
    switch (hint) {
    case QPlatformIntegration::CursorFlashTime:
        if (const unsigned timeMS = GetCaretBlinkTime())
            return QVariant(int(timeMS));
        break;
    case KeyboardAutoRepeatRate:
        return QVariant(keyBoardAutoRepeatRateMS());
    case QPlatformIntegration::StartDragTime:
    case QPlatformIntegration::StartDragDistance:
    case QPlatformIntegration::MouseDoubleClickInterval:
    case QPlatformIntegration::KeyboardInputInterval:
        break; // Not implemented
    }
    return QPlatformIntegration::styleHint(hint);
}
示例#10
0
void CTEKWindow::OnTimer(UINT nIDEvent)
{
	UINT T;

	if (nIDEvent==IdCaretTimer) {
		if (ts.NonblinkingCursor!=0) {
			T = GetCaretBlinkTime();
			SetCaretBlinkTime(T);
		}
		else {
			::KillTimer(HTEKWin,IdCaretTimer);
		}
		return;
	}
	else {
		::KillTimer(HTEKWin,nIDEvent);
	}
}
示例#11
0
Cursor::Cursor(void) {
   _cursorTexture = NULL;

   _requestedCursorChange = false;

#ifdef _WIN32
   _blinkTime = GetCaretBlinkTime();
#else
   _blinkTime = 700;
#endif // _WIN32

   _timebase = _time = (int)(glfwGetTime() / 1000.0);				// Glut used milliseconds but GLFW uses senconds.
   _isShowingCursor = true;
   _cursorInMovement = false;

   _insert = false;

   genTexture();
}
QVariant QWindowsIntegration::styleHint(QPlatformIntegration::StyleHint hint) const
{
    switch (hint) {
    case QPlatformIntegration::CursorFlashTime:
        if (const unsigned timeMS = GetCaretBlinkTime())
            return QVariant(int(timeMS) * 2);
        break;
#ifdef SPI_GETKEYBOARDSPEED
    case KeyboardAutoRepeatRate:
        return QVariant(keyBoardAutoRepeatRateMS());
#endif
    case QPlatformIntegration::StartDragTime:
    case QPlatformIntegration::StartDragDistance:
    case QPlatformIntegration::KeyboardInputInterval:
    case QPlatformIntegration::ShowIsFullScreen:
    case QPlatformIntegration::PasswordMaskDelay:
    case QPlatformIntegration::StartDragVelocity:
        break; // Not implemented
    case QPlatformIntegration::FontSmoothingGamma:
        return QVariant(QWindowsFontDatabase::fontSmoothingGamma());
    case QPlatformIntegration::MouseDoubleClickInterval:
        if (const int ms = GetDoubleClickTime())
            return QVariant(ms);
        break;
    case QPlatformIntegration::UseRtlExtensions:
        return QVariant(d->m_context.useRTLExtensions());
    case QPlatformIntegration::SynthesizeMouseFromTouchEvents:
#ifdef Q_OS_WINCE
        // We do not want Qt to synthesize mouse events as Windows also does that.
       return false;
#else // Q_OS_WINCE
       return QVariant(bool(d->m_options & DontPassOsMouseEventsSynthesizedFromTouch));
#endif // !Q_OS_WINCE
    default:
        break;
    }
    return QPlatformIntegration::styleHint(hint);
}
示例#13
0
	UIEditBox::UIEditBox(UIDialogPtr const & dialog, int ID, std::wstring const & strText, int4 const & coord_size, bool bIsDefault)
					: UIControl(UIEditBox::Type, dialog),
						border_(5),	// Default border width
						spacing_(4),	// Default spacing
#ifdef KLAYGE_PLATFORM_WINDOWS
#ifdef KLAYGE_PLATFORM_WINDOWS_DESKTOP
						blink_time_(GetCaretBlinkTime() * 0.001f),
#else
						blink_time_(1),
#endif
#else
						blink_time_(1),
#endif
						last_blink_time_(timer_.current_time()),
						caret_on_(true),
						caret_pos_(0),
						insert_mode_(true),
						sel_start_(0),
						first_visible_(0),
						text_color_(16.0f / 255, 16.0f / 255, 16.0f / 255, 1),
						sel_text_color_(1, 1, 1, 1),
						sel_bk_color_(40.0f / 255, 50.0f / 255, 92.0f / 255, 1),
						caret_color_(0, 0, 0, 1),
						mouse_drag_(false)
	{
		hide_caret_ = false;

		this->InitDefaultElements();

		// Set the ID and position
		this->SetID(ID);
		this->SetLocation(coord_size.x(), coord_size.y());
		this->SetSize(coord_size.z(), coord_size.w());
		this->SetIsDefault(bIsDefault);

		this->SetText(strText);
	}
/* a simple edit window */
static int MyeditWindowProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    int w = 0;
    SIZE Size;
    static char *pBuffer = NULL;
    static int pos = 0, len = 0;
    HDC hdc;

    switch (message) {
        case MSG_CREATE:
            SetWindowFont(hWnd, GetSystemFont(SYSLOGFONT_DEFAULT));
            if (!CreateCaret (hWnd, NULL, 1, GetSysCharHeight())) {
                return -1;
            }
            pBuffer = (char *) calloc(1, 11);
            *pBuffer = 0;
            break;

        case MSG_SETFOCUS:
            hdc = GetClientDC(hWnd);
            w = GetTextExtent (hdc, pBuffer, pos, &Size);
            SetCaretPos(hWnd, w, 0);
            //SetCaretPos(hWnd, pos*GetSysCharWidth(), 0);
            ShowCaret(hWnd);
            ReleaseDC(hdc);
            break;

        case MSG_KILLFOCUS:
            HideCaret(hWnd);
            break;

        case MSG_CHAR:
            switch (wParam) {
                case '\t':
                case '\b':
                case '\n':
                    SetCaretBlinkTime(hWnd, GetCaretBlinkTime(hWnd)-100);
                    break;

                default:
                    {
                        char ch, buf[11];
                        char *tmp;
                        ch = wParam;
                        if (!isalpha(ch) && !isdigit(ch))
                            break;
                        if (len == 10)
                            break;
                        tmp = pBuffer+pos;
                        if (*tmp != 0) {
                            strcpy(buf, tmp);
                            strcpy(tmp+1, buf);
                        }
                        *tmp = ch;
                        pos++;
                        len++;

                        hdc = GetClientDC(hWnd);
                        InvalidateRect(hWnd, NULL, TRUE);
                        w = GetTextExtent (hdc, pBuffer, pos, &Size);
                        SetCaretPos(hWnd, w, 0);
                        //SetCaretPos(hWnd, pos*GetSysCharWidth(), 0);
                        ShowCaret(hWnd);
                        ReleaseDC(hdc);
                    }
                    break;
            }
            break;

        case MSG_KEYDOWN:
            switch (wParam) {
                case SCANCODE_CURSORBLOCKLEFT:
                    pos = MAX(pos-1, 0);
                    break;
                case SCANCODE_CURSORBLOCKRIGHT:
                    pos = MIN(pos+1, len);
                    break;
                case SCANCODE_BACKSPACE:
                    {
                        char buf[11];
                        char *tmp;
                        if (len == 0 || pos == 0)
                            break;
                        tmp = pBuffer+pos;
                        strcpy(buf, tmp);
                        strcpy(tmp-1, buf);
                        pos--;
                        len--;
                        break;
                    }
            }
            if (wParam == SCANCODE_CURSORBLOCKLEFT || wParam == SCANCODE_CURSORBLOCKRIGHT ||
                    wParam == SCANCODE_BACKSPACE) {
                hdc = GetClientDC(hWnd);
                InvalidateRect(hWnd, NULL, TRUE);
                w = GetTextExtent (hdc, pBuffer, pos, &Size);
                //SetCaretPos(hWnd, pos*GetSysCharWidth(), 0);
                SetCaretPos(hWnd, w, 0);
                ReleaseDC(hdc);
            }
            break;

        case MSG_PAINT:
            hdc = BeginPaint(hWnd);
            TextOut(hdc, 0, 0, pBuffer);
            EndPaint(hWnd, hdc);
            return 0;

        case MSG_DESTROY:
            DestroyCaret (hWnd);
            if (pBuffer)
                free(pBuffer);
            return 0;
    }

    return DefaultControlProc(hWnd, message, wParam, lParam);
}
LRESULT CALLBACK CTextInputCtrl::s_WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    HIMC himc;
    CTextInputCtrl *ptic;

    switch (message)
    {
        case WM_CREATE:
            SetThis(hwnd, ((CREATESTRUCT *)lParam)->lpCreateParams);
            SetTimer(hwnd, TIMERID_CARET, GetCaretBlinkTime(), NULL);
            GetThis(hwnd)->OnCreate(hwnd, wParam, lParam);
            break;


        case WM_PAINT:
            ptic = GetThis(hwnd);
            hdc = BeginPaint(hwnd, &ps);
            if (ptic)
                ptic->OnPaint(hdc);
            EndPaint(hwnd, &ps);
            break;

        case WM_KEYDOWN:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnKeyDown(wParam, lParam);
            break;

        case WM_LBUTTONDOWN:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnLButtonDown(wParam, lParam);
            break;

        case WM_LBUTTONUP:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnLButtonUp(wParam, lParam);
            break;

        case WM_RBUTTONDOWN:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnRButtonDown(wParam, lParam);
            break;

        case WM_RBUTTONUP:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnRButtonUp(wParam, lParam);
            break;

        case WM_MOUSEMOVE:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnMouseMove(wParam, lParam);
            break;

        case WM_SETFOCUS:
            //
            // Level 2 Support
            //
            ptic = GetThis(hwnd);
            if (ptic)
            {
                ptic->_editor.SetCompositionForm();
                ptic->SetCompositionFont();
            }
            break;

        case WM_IME_STARTCOMPOSITION:
            //
            // Level 2 Support
            //
            ptic = GetThis(hwnd);
            if (ptic)
            {
                ptic->_editor.OnStartComposition();
                ptic->_editor.SetCompositionForm();
                ptic->SetCompositionFont();
            }

            // If it is a near caret IME, we should keep Level 2 path.
            if (IsNearCaretIME())
            {
                return DefWindowProc(hwnd, message, wParam, lParam);
            }

            break;

        case WM_IME_COMPOSITION:
            himc = ImmGetContext(hwnd);

            if (himc)
            {
                BOOL fNearCaret = IsNearCaretIME();

                if (lParam & GCS_RESULTSTR)
                {
                    LONG nSize = ImmGetCompositionString(himc, GCS_RESULTSTR, NULL, 0);
                    if (nSize)
                    {
                        LPWSTR psz = (LPWSTR)LocalAlloc(LPTR, nSize + sizeof(WCHAR));
                        if (psz)
                        {
                            ImmGetCompositionString(himc, GCS_RESULTSTR, psz, nSize);
                            ptic = GetThis(hwnd);
                            if (ptic)
                            {
                                ptic->_editor.InsertResultAtComposition(psz);
                                ptic->_editor.UpdateLayout(&ptic->_lfCurrentFont);
                                ptic->_editor.SetCompositionForm();
                                ptic->_editor.SetInterimCaret(FALSE);
                                InvalidateRect(hwnd, NULL, TRUE);
                            }
                            LocalFree(psz);
                        }
                    }
                }

                if ((lParam & GCS_COMPSTR) && !fNearCaret)
                {
                    LONG lDeltaStart = ImmGetCompositionString(himc, GCS_DELTASTART, NULL, 0);
                    LONG lCursorPos = ImmGetCompositionString(himc, GCS_CURSORPOS, NULL, 0);
                    LONG lSize = ImmGetCompositionString(himc, GCS_COMPSTR, NULL, 0);
                    LONG lAttrSize = ImmGetCompositionString(himc, GCS_COMPATTR, NULL, 0);
                    LONG lClauseInfoSize = ImmGetCompositionString(himc, GCS_COMPCLAUSE, NULL, 0);

                    if (lSize)
                    {
                        BYTE *prgAttr = NULL;
                        LONG *prgClauseInfo = NULL;
                        LPWSTR psz = (LPWSTR)LocalAlloc(LPTR, lSize + sizeof(WCHAR));

                        if (lAttrSize)
                            prgAttr = (BYTE *)LocalAlloc(LPTR, lAttrSize + sizeof(BYTE));

                        if (lClauseInfoSize)
                            prgClauseInfo = (LONG *)LocalAlloc(LPTR, lClauseInfoSize + sizeof(LONG));

                        if (psz)
                        {
                            if (ImmGetCompositionString(himc, GCS_COMPSTR, psz, lSize))
                            {
                                if (prgAttr)
                                {
                                    if (!ImmGetCompositionString(himc, GCS_COMPATTR, prgAttr, lAttrSize))
                                    {
                                        prgAttr = NULL;
                                        lAttrSize = 0;
                                    }
                                }
    
                                if (prgClauseInfo)
                                {
                                    if (!ImmGetCompositionString(himc, GCS_COMPCLAUSE, prgClauseInfo, lClauseInfoSize))
                                    {
                                        prgClauseInfo = NULL;
                                        lClauseInfoSize = 0;
                                    }
                                }
    
                                ptic = GetThis(hwnd);
                                if (ptic)
                                {
                                    ptic->_editor.UpdateComposition(psz, lDeltaStart, lCursorPos,
                                                                    prgAttr, lAttrSize, prgClauseInfo, lClauseInfoSize);
                                    ptic->_editor.UpdateLayout(&ptic->_lfCurrentFont);
                                    ptic->_editor.SetCompositionForm();
                                    InvalidateRect(hwnd, NULL, TRUE);
                                }
                            }
                            LocalFree(psz);
                        }
                        if (prgAttr)
                            LocalFree(prgAttr);
                        if (prgClauseInfo)
                            LocalFree(prgClauseInfo);
                    }
                    if (lParam & CS_INSERTCHAR)
                    {
                        WCHAR sz[2];
                        sz[0] = (WCHAR)wParam;
                        sz[1] = L'\0';
                        ptic->_editor.SetInterimCaret(TRUE);
                        ptic->_editor.UpdateComposition(sz, 0, 0, NULL, 0, NULL, 0);
                        ptic->_editor.MoveSelectionToComposition();
                        ptic->_editor.UpdateLayout(&ptic->_lfCurrentFont);
                        ptic->_editor.SetCompositionForm();
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                }
                ImmReleaseContext(hwnd, himc);

                // If it is a near caret IME, we should keep Level 2 path.
                if ((lParam & GCS_COMPSTR) && fNearCaret)
                {
                    lParam &= ~(GCS_RESULTCLAUSE |
                                GCS_RESULTREADCLAUSE |
                                GCS_RESULTREADSTR |
                                GCS_RESULTSTR);

                    return DefWindowProc(hwnd, message, wParam, lParam);
                }

                
            }
            break;

        case WM_IME_ENDCOMPOSITION:

            // The composition ends. 
            ptic = GetThis(hwnd);
            if (ptic)
            {
                // We need to clear the attributes.
                // There is a case that the composition string is canceled and it did not 
                // completed (GCS_RESULTSTR did not come).
                ptic->_editor.ClearAttrAndClauseInfo();
                ptic->_editor.UpdateLayout(&ptic->_lfCurrentFont);
                InvalidateRect(hwnd, NULL, TRUE);
            }

            // If it is a near caret IME, we should keep Level 2 path.
            if (IsNearCaretIME())
            {
                return DefWindowProc(hwnd, message, wParam, lParam);
            }
            break;

        case WM_IME_NOTIFY:
            if (wParam == IMN_OPENCANDIDATE)
            {
                ptic = GetThis(hwnd);
                if (ptic)
                {
                    ptic->_editor.SetCandidateForm();
                }
            }
            return DefWindowProc(hwnd, message, wParam, lParam);

        case WM_IME_SETCONTEXT:
            return DefWindowProc(hwnd, message, wParam, lParam & ~ISC_SHOWUICOMPOSITIONWINDOW);

        case WM_IME_REQUEST:
            switch (wParam)
            {
                case IMR_QUERYCHARPOSITION:
                {
                    ptic = GetThis(hwnd);
                    if (ptic)
                    {
                        ptic->_editor.QueryCharPosition((IMECHARPOSITION *)lParam);
                        return 1;
                    }
                }

                case IMR_DOCUMENTFEED:
                {
                    ptic = GetThis(hwnd);
                    if (ptic)
                    {
                        return ptic->_editor.OnDocumentFeed((RECONVERTSTRING *)lParam);
                    }
                }

                case IMR_RECONVERTSTRING:
                {
                    ptic = GetThis(hwnd);
                    if (ptic)
                    {
                        return ptic->_editor.OnReconvertString((RECONVERTSTRING *)lParam);
                    }
                }

                case IMR_CONFIRMRECONVERTSTRING:
                {
                    ptic = GetThis(hwnd);
                    if (ptic)
                    {
                        return ptic->_editor.OnConfirmReconvertString((RECONVERTSTRING *)lParam);
                    }
                }
            }
            break;

        case WM_IME_CHAR:
            //
            // wParam is a character of the result string. 
            // if we don't want to receive WM_CHAR message for this character,
            // we should not call DefWindowProc().
            //
            return DefWindowProc(hwnd, message, wParam, lParam);

        case WM_CHAR:
            //
            // wParam is a character of the result string. 
            //
            
            switch ((WCHAR)wParam)
            {
                case 0x08:
                case 0x0a:
                    return 0;
                default:
                    break;
            }

            ptic = GetThis(hwnd);
            if (ptic)
            {
                WCHAR wc[2];
                wc[0] = (WCHAR)wParam;
                wc[1] = L'\0';
                ptic->_editor.InsertAtSelection(wc);
                InvalidateRect(hwnd, NULL, TRUE);
            }
            break;

        case WM_TIMER:
            if (wParam == TIMERID_CARET)
            {
                ptic = GetThis(hwnd);
                if (ptic)
                {
                    HDC hdc = GetDC(hwnd);
                    ptic->_editor.BlinkCaret(hdc);
                    ReleaseDC(hwnd, hdc);
                }
            }

            break;
    
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}
示例#16
0
static int editTextField(float x, float y, char* editString, bool isFocused, int editType, unsigned int maxLength = 32)
{
	//r3dColor clr(0, 86, 159);
  r3dColor clr(156, 156, 156);

  char stars[512];
  for(size_t i=0; i<strlen(editString); i++)
    stars[i] = '*';
  stars[strlen(editString)] = 0;
     
  char* msg = (editType == 1) ? stars : editString;
  g_font1->PrintF(x, y + ((editType == 1) ? 4 : 0), clr, "%s", msg); // '*' in font is way up, adjust it to center
  if(!isFocused)
    return 0;
    
  // blinking 
  static float blinkRate = (float)GetCaretBlinkTime() / 1000.0f;
  static float nextBlink = r3dGetTime();
  static int   caretOn   = 0;
  
  if(r3dGetTime() > nextBlink) {
    nextBlink += blinkRate;
    caretOn = !caretOn;
  }

  // by some weird reason GetTextExtent ignoring last spaces in string.
  char sizemsg[512];
  sprintf(sizemsg, "%s.", msg);
  SIZE ts1 = GetTextExtent(g_font1, sizemsg);
  SIZE ts2 = GetTextExtent(g_font1, ".");
  if(caretOn) {
    r3dDrawBox2D(x + (float)(ts1.cx - ts2.cx), y+2, 1, 16, r3dColor(0, 0, 0));
  }

  // some wierd Control-V logic, as we can't detect it - it's eated inside WMKEYDOWN
  static bool btnVPressed = false;
  if(::GetFocus() == win::hWnd && (GetKeyState('V') & 0x80) && !btnVPressed) {
    btnVPressed = true;
    if(GetKeyState(VK_CONTROL) & 0x80) {
      if(OpenClipboard(NULL)) 
      {
        HANDLE clip = GetClipboardData(CF_TEXT);
        const char* ptr = (LPSTR)GlobalLock(clip);
        if(ptr)
        {
          std::string text = ptr;
          text = trim(text);
          r3dscpy_s(editString, maxLength, text.c_str());
        }
        GlobalUnlock(clip);
        CloseClipboard();
      }
    }
  }
  else btnVPressed = false;
  
  // do input
  int ch = win32_getch();
  if(ch == 0)
    return 0;
    
  // backspace
  if(ch == 8 && *editString != 0)
    editString[strlen(editString)-1] = 0;

  // check for max length
  if(strlen(editString) >= maxLength)
    return 0;
    
  if(editType == 2)
  {
    // special case for serial entry
    int len = strlen(editString);
    if(len >= 19) // max length
      return 0;
    if(len == 4 || len == 9 || len == 14) { // '-' in serial
      if(ch == '-') {
        sprintf(editString + strlen(editString), "%c", ch);
      }
      return 0;
    }
    if(ch >= '0' && ch <= '9')
      sprintf(editString + strlen(editString), "%c", ch);
    else if(ch >= 'a' && ch <= 'z')
      sprintf(editString + strlen(editString), "%c", ch - 0x20);
    else if(ch >= 'A' && ch <= 'Z')
      sprintf(editString + strlen(editString), "%c", ch);
    else if(ch == 9 || ch == 13)
      return ch;

    return 0;
  }
    
  // normal key
  if(ch >= 0x20 && ch < 0x80) {
    sprintf(editString + strlen(editString), "%c", ch);
  }
  
  return ch;
}
示例#17
0
文件: wince.c 项目: TellarHK/wwiv
void fastPoll( void )
	{
	static BOOLEAN addedFixedItems = FALSE, hasHardwareRNG = FALSE;
	static CEGENRANDOM pCeGenRandom = NULL;
	static GETSYSTEMPOWERSTATUS pGetSystemPowerStatusEx2 = NULL;
	FILETIME  creationTime, exitTime, kernelTime, userTime;
	LARGE_INTEGER performanceCount;
	SYSTEM_POWER_STATUS_EX2 powerStatus;
	MEMORYSTATUS memoryStatus;
	HANDLE handle;
	POINT point;
	RANDOM_STATE randomState;
	BYTE buffer[ RANDOM_BUFSIZE ];
	int length;

	if( krnlIsExiting() )
		return;

	/* Initialize the native function pointers if necessary.  CeGetRandom()
	   is only available in relatively new versions of WinCE, so we have to
	   link it dynamically */
	if( pCeGenRandom == NULL )
		{
		HANDLE hCoreDLL;

		if( ( hCoreDLL = GetModuleHandle( TEXT( "Coredll.dll" ) ) ) != NULL )
			pCeGenRandom = ( CEGENRANDOM ) GetProcAddress( hCoreDLL, TEXT( "CeGenRandom" ) );
		}
	if( pGetSystemPowerStatusEx2 == NULL )
		{
		HANDLE hGetpower;

		if( ( hGetpower = GetModuleHandle( TEXT( "Getpower.dll" ) ) ) != NULL )
			pGetSystemPowerStatusEx2 = ( GETSYSTEMPOWERSTATUS ) \
							GetProcAddress( hGetpower, TEXT( "GetSystemPowerStatusEx2" ) );
		}

	initRandomData( randomState, buffer, RANDOM_BUFSIZE );

	/* Get various basic pieces of system information: Handle of active
	   window, handle of window with mouse capture, handle of clipboard owner
	   handle of start of clpboard viewer list, pseudohandle of current
	   process, current process ID, pseudohandle of current thread, current
	   thread ID, handle of desktop window, handle  of window with keyboard
	   focus, whether system queue has any events, cursor position for last
	   message, 1 ms time for last message, handle of window with clipboard
	   open, handle of process heap, handle of procs window station, types of
	   events in input queue, and milliseconds since Windows was started */
	addRandomValue( randomState, GetActiveWindow() );
	addRandomValue( randomState, GetCapture() );
	addRandomValue( randomState, GetCaretBlinkTime() );
	addRandomValue( randomState, GetClipboardOwner() );
	addRandomValue( randomState, GetCurrentProcess() );
	addRandomValue( randomState, GetCurrentProcessId() );
	addRandomValue( randomState, GetCurrentThread() );
	addRandomValue( randomState, GetCurrentThreadId() );
	addRandomValue( randomState, GetDesktopWindow() );
	addRandomValue( randomState, GetDC( NULL ) );
	addRandomValue( randomState, GetDoubleClickTime() );
	addRandomValue( randomState, GetFocus() );
	addRandomValue( randomState, GetForegroundWindow() );
	addRandomValue( randomState, GetMessagePos() );
	addRandomValue( randomState, GetOpenClipboardWindow() );
	addRandomValue( randomState, GetProcessHeap() );
	addRandomValue( randomState, GetQueueStatus( QS_ALLINPUT ) );
	addRandomValue( randomState, GetTickCount() );
	if( krnlIsExiting() )
		return;

	/* Get multiword system information: Current caret position, current
	   mouse cursor position */
	GetCaretPos( &point );
	addRandomData( randomState, &point, sizeof( POINT ) );
	GetCursorPos( &point );
	addRandomData( randomState, &point, sizeof( POINT ) );

	/* Get percent of memory in use, bytes of physical memory, bytes of free
	   physical memory, bytes in paging file, free bytes in paging file, user
	   bytes of address space, and free user bytes */
	memoryStatus.dwLength = sizeof( MEMORYSTATUS );
	GlobalMemoryStatus( &memoryStatus );
	addRandomData( randomState, &memoryStatus, sizeof( MEMORYSTATUS ) );

	/* Get thread and process creation time, exit time, time in kernel mode,
	   and time in user mode in 100ns intervals */
	handle = GetCurrentThread();
	GetThreadTimes( handle, &creationTime, &exitTime, &kernelTime, &userTime );
	addRandomData( randomState, &creationTime, sizeof( FILETIME ) );
	addRandomData( randomState, &exitTime, sizeof( FILETIME ) );
	addRandomData( randomState, &kernelTime, sizeof( FILETIME ) );
	addRandomData( randomState, &userTime, sizeof( FILETIME ) );

	/* Get extended battery/power status information.  We set the fUpdate
	   flag to force a re-read of fresh data rather than a re-use of cached
	   information */
	if( pGetSystemPowerStatusEx2 != NULL && \
		( length = \
				pGetSystemPowerStatusEx2( &powerStatus,
										  sizeof( SYSTEM_POWER_STATUS_EX2 ),
										  TRUE ) ) > 0 )
		addRandomData( randomState, &powerStatus, length );

	/* Get random data provided by the OS.  Since this is expected to be
	   provided by the system vendor, it's quite likely to be the usual
	   process ID + time */
	if( pCeGenRandom != NULL )
		{
		BYTE randomBuffer[ 32 ];

		if( pCeGenRandom( 32, randomBuffer ) )
			addRandomData( randomState, randomBuffer, 32 );
		}

	/* The following are fixed for the lifetime of the process so we only
	   add them once */
	if( !addedFixedItems )
		{
		SYSTEM_INFO systemInfo;

		GetSystemInfo( &systemInfo );
		addRandomData( randomState, &systemInfo, sizeof( SYSTEM_INFO ) );
		addedFixedItems = TRUE;
		}

	/* The performance of QPC varies depending on the architecture it's
	   running on, and is completely platform-dependant.  If there's no
	   hardware performance counter available, it uses the 1ms system timer,
	   although usually there's some form of hardware timer available.
	   Since there may be no correlation, or only a weak correlation,
	   between the performance counter and the system clock, we get the
	   time from both sources */
	if( QueryPerformanceCounter( &performanceCount ) )
		addRandomData( randomState, &performanceCount,
					   sizeof( LARGE_INTEGER ) );
	addRandomValue( randomState, GetTickCount() );

	/* Flush any remaining data through.  Quality = int( 33 1/3 % ) */
	endRandomData( randomState, 34 );
	}
示例#18
0
static BOOL
ReadSettings(PGLOBAL_DATA pGlobalData)
{
    DWORD dwDisposition;
    DWORD dwLength;
    HKEY hKey;
    LONG lError;

    /* Get sticky keys information */
    pGlobalData->stickyKeys.cbSize = sizeof(STICKYKEYS);
    if (!SystemParametersInfo(SPI_GETSTICKYKEYS,
                              sizeof(STICKYKEYS),
                              &pGlobalData->stickyKeys,
                              0))
        return FALSE;

    /* Get filter keys information */
    pGlobalData->filterKeys.cbSize = sizeof(FILTERKEYS);
    if (!SystemParametersInfo(SPI_GETFILTERKEYS,
                              sizeof(FILTERKEYS),
                              &pGlobalData->filterKeys,
                              0))
        return FALSE;

    /* Get toggle keys information */
    pGlobalData->toggleKeys.cbSize = sizeof(TOGGLEKEYS);
    if (!SystemParametersInfo(SPI_GETTOGGLEKEYS,
                              sizeof(TOGGLEKEYS),
                              &pGlobalData->toggleKeys,
                              0))
        return FALSE;

    /* Get keyboard preference information */
    if (!SystemParametersInfo(SPI_GETKEYBOARDPREF,
                              0,
                              &pGlobalData->bKeyboardPref,
                              0))
        return FALSE;

    /* Get high contrast information */
    pGlobalData->highContrast.cbSize = sizeof(HIGHCONTRAST);
    SystemParametersInfo(SPI_GETHIGHCONTRAST,
                         sizeof(HIGHCONTRAST),
                         &pGlobalData->highContrast,
                         0);

    SystemParametersInfo(SPI_GETCARETWIDTH,
                         0,
                         &pGlobalData->uCaretWidth,
                         0);

    pGlobalData->uCaretBlinkTime = GetCaretBlinkTime();

    /* get sound settings */
    pGlobalData->ssSoundSentry.cbSize = sizeof(SOUNDSENTRY);
    SystemParametersInfo(SPI_GETSOUNDSENTRY,
                         sizeof(SOUNDSENTRY),
                         &pGlobalData->ssSoundSentry,
                         0);

    SystemParametersInfo(SPI_GETSHOWSOUNDS,
                         0,
                         &pGlobalData->bShowSounds,
                         0);

    /* Get mouse keys information */
    pGlobalData->mouseKeys.cbSize = sizeof(MOUSEKEYS);
    SystemParametersInfo(SPI_GETMOUSEKEYS,
                         sizeof(MOUSEKEYS),
                         &pGlobalData->mouseKeys,
                         0);

    /* Get access timeout information */
    pGlobalData->accessTimeout.cbSize = sizeof(ACCESSTIMEOUT);
    SystemParametersInfo(SPI_GETACCESSTIMEOUT,
                         sizeof(ACCESSTIMEOUT),
                         &pGlobalData->accessTimeout,
                         0);

    /* Get serial keys information */
    pGlobalData->serialKeys.cbSize = sizeof(SERIALKEYS);
    pGlobalData->serialKeys.lpszActivePort = pGlobalData->szActivePort;
    pGlobalData->serialKeys.lpszPort = pGlobalData->szPort;
    SystemParametersInfo(SPI_GETSERIALKEYS,
                         sizeof(SERIALKEYS),
                         &pGlobalData->serialKeys,
                         0);

    pGlobalData->bWarningSounds = TRUE;
    pGlobalData->bSoundOnActivation = TRUE;

    lError = RegCreateKeyEx(HKEY_CURRENT_USER,
                            _T("Control Panel\\Accessibility"),
                            0,
                            NULL,
                            REG_OPTION_NON_VOLATILE,
                            KEY_EXECUTE | KEY_QUERY_VALUE,
                            NULL,
                            &hKey,
                            &dwDisposition);
    if (lError != ERROR_SUCCESS)
        return TRUE;

    dwLength = sizeof(BOOL);
    lError = RegQueryValueEx(hKey,
                             _T("Warning Sounds"),
                             NULL,
                             NULL,
                             (LPBYTE)&pGlobalData->bWarningSounds,
                             &dwLength);
    if (lError != ERROR_SUCCESS)
        pGlobalData->bWarningSounds = TRUE;

    dwLength = sizeof(BOOL);
    lError = RegQueryValueEx(hKey,
                             _T("Sound On Activation"),
                             NULL,
                             NULL,
                             (LPBYTE)&pGlobalData->bSoundOnActivation,
                             &dwLength);
    if (lError != ERROR_SUCCESS)
        pGlobalData->bSoundOnActivation = TRUE;

    RegCloseKey(hKey);

    return TRUE;
}
LRESULT CALLBACK CTextInputCtrl::s_WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    CTextInputCtrl *ptic;
    switch (message)
    {
        case WM_CREATE:
            SetThis(hwnd, ((CREATESTRUCT *)lParam)->lpCreateParams);
            SetTimer(hwnd, TIMERID_CARET, GetCaretBlinkTime(), NULL);
            GetThis(hwnd)->OnCreate(hwnd, wParam, lParam);
            break;

        case WM_DESTROY:
            ptic = GetThis(hwnd);
            if (ptic)
            {
                ptic->OnDestroy();
            }
            break;

        case WM_SETFOCUS:
            ptic = GetThis(hwnd);
            if (ptic)
            {
                ptic->OnSetFocus(wParam, lParam);
            }
            break;

        case WM_PAINT:
            ptic = GetThis(hwnd);
            hdc = BeginPaint(hwnd, &ps);
            if (ptic)
                ptic->OnPaint(hdc);
            EndPaint(hwnd, &ps);
            break;

        case WM_KEYDOWN:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnKeyDown(wParam, lParam);
            break;

        case WM_LBUTTONDOWN:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnLButtonDown(wParam, lParam);
            break;

        case WM_LBUTTONUP:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnLButtonUp(wParam, lParam);
            break;

        case WM_RBUTTONDOWN:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnRButtonDown(wParam, lParam);
            break;

        case WM_RBUTTONUP:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnRButtonUp(wParam, lParam);
            break;

        case WM_MOUSEMOVE:
            ptic = GetThis(hwnd);
            if (ptic)
                ptic->OnMouseMove(wParam, lParam);
            break;


        case WM_IME_COMPOSITION:
            if (lParam & GCS_RESULTSTR)
            {
                HIMC himc = ImmGetContext(hwnd);

                if (himc)
                {
                    LONG nSize = ImmGetCompositionString(himc, GCS_RESULTSTR, NULL, 0);
                    if (nSize)
                    {
                        LPWSTR psz = (LPWSTR)LocalAlloc(LPTR, nSize + sizeof(WCHAR));
                        if (psz)
                        {
                            ImmGetCompositionString(himc, GCS_RESULTSTR, psz, nSize);
                            LocalFree(psz);
                        }
                    }
                }
                ImmReleaseContext(hwnd, himc);

                //
                // If we don't want to receive WM_IME_CHAR or WM_CHAR with
                // this result string, we should not call DefWindowProc()
                // with GCS_RESULTSTR, GCS_RESULTREADSTR, GCS_RESULTCLAUSE and
                // GCS_RESULTREADCLAUSE flags. 
                //
                // lParam &= ~(GCS_RESULTCLAUSE |
                //             GCS_RESULTREADCLAUSE |
                //             GCS_RESULTREADSTR |
                //             GCS_RESULTSTR);
                // if (!lParam)
                //     break;
                //
            }
            return DefWindowProc(hwnd, message, wParam, lParam);

        case WM_IME_CHAR:
            //
            // wParam is a character of the result string. 
            // if we don't want to receive WM_CHAR message for this character,
            // we should not call DefWindowProc().
            //
            return DefWindowProc(hwnd, message, wParam, lParam);

        case WM_CHAR:
            //
            // wParam is a character of the result string. 
            //
            
            switch ((WCHAR)wParam)
            {
                case 0x08:
                case 0x0a:
                    return 0;
                default:
                    break;
            }

            ptic = GetThis(hwnd);
            if (ptic)
            {
                WCHAR wc[2];
                wc[0] = (WCHAR)wParam;
                wc[1] = L'\0';
                ptic->_editor.InsertAtSelection(wc);
                InvalidateRect(hwnd, NULL, TRUE);
            }
            break;

        case WM_TIMER:
            if (wParam == TIMERID_CARET)
            {
                ptic = GetThis(hwnd);
                if (ptic)
                {
                    HDC hdc = GetDC(hwnd);
                    ptic->_editor.BlinkCaret(hdc);
                    ReleaseDC(hwnd, hdc);
                }
            }

            break;
    
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}