Example #1
0
int wxSpinCtrl::GetValue() const
{
    wxString val = wxGetWindowText(m_hwndBuddy);

    long n;
    if ( (wxSscanf(val, wxT("%ld"), &n) != 1) )
        n = INT_MIN;

    if ( n < m_min )
        n = m_min;
    if ( n > m_max )
        n = m_max;

    return n;
}
Example #2
0
int wxSpinCtrl::GetValue() const
{
    const wxString val = wxGetWindowText(m_hwndBuddy);

    long n;
    if ( !val.ToLong(&n, GetBase()) )
        n = INT_MIN;

    if ( n < m_min )
        n = m_min;
    if ( n > m_max )
        n = m_max;

    return n;
}
Example #3
0
// process a WM_COMMAND generated by the buddy text control
bool wxSpinCtrl::ProcessTextCommand(WXWORD cmd, WXWORD WXUNUSED(id))
{
    if ( cmd == EN_CHANGE )
    {
        wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
        event.SetEventObject(this);
        wxString val = wxGetWindowText(m_hwndBuddy);
        event.SetString(val);
        event.SetInt(GetValue());
        return GetEventHandler()->ProcessEvent(event);
    }

    // not processed
    return false;
}
Example #4
0
// process a WM_COMMAND generated by the buddy text control
bool wxSpinCtrl::ProcessTextCommand(WXWORD cmd, WXWORD WXUNUSED(id))
{
    if ( (cmd == EN_CHANGE) && (!m_blockEvent ))
    {
        wxCommandEvent event(wxEVT_TEXT, GetId());
        event.SetEventObject(this);
        wxString val = wxGetWindowText(m_hwndBuddy);
        event.SetString(val);
        event.SetInt(GetValue());
        return HandleWindowEvent(event);
    }

    // not processed
    return false;
}
Example #5
0
void wxTextEntry::WriteText(const wxString& text)
{
    wxString newText = wxGetWindowText(GetEditHWND());
    long from, to;
    GetSelection(&from, &to);
    if (from > to){
      long swp = to;
      to = from;
      from = swp;
    }
    // Compose the new Text by replacing the selection of the old text
    newText.replace(from, to - from, text);
    // Set control to the new text
    ::WinSetWindowText(GetEditHwnd(), text.c_str());
}
Example #6
0
wxSize wxStaticBox::DoGetBestSize() const
{
    int cx, cy;
    wxGetCharSize(GetHWND(), &cx, &cy, GetFont());

    int wBox;
    GetTextExtent(GetLabelText(wxGetWindowText(m_hWnd)), &wBox, &cy);

    wBox += 3*cx;
    int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);

    wxSize best(wBox, hBox);
    CacheBestSize(best);
    return best;
}
Example #7
0
wxSize wxButton::DoGetBestSize() const
{
    wxString                        rsLabel = wxGetWindowText(GetHWND());
    int                             nWidthButton;
    int                             nWidthChar;
    int                             nHeightChar;
    wxFont                          vFont = (wxFont)GetFont();

    GetTextExtent( rsLabel
                  ,&nWidthButton
                  ,NULL
                 );

    wxGetCharSize( GetHWND()
                  ,&nWidthChar
                  ,&nHeightChar
                  ,&vFont
                 );

    //
    // Add a margin - the button is wider than just its label
    //
    nWidthButton += 3 * nWidthChar;

    //
    // The button height is proportional to the height of the font used
    //
    int                             nHeightButton = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(nHeightChar);

    //
    // Need a little extra to make it look right
    //
    nHeightButton += (int)(nHeightChar/1.5);

    if (!HasFlag(wxBU_EXACTFIT))
    {
        wxSize                      vSize = GetDefaultSize();

        if (nWidthButton > vSize.x)
            vSize.x = nWidthButton;
        if (nHeightButton > vSize.y)
            vSize.y = nHeightButton;
        return vSize;
    }
    return wxSize( nWidthButton
                  ,nHeightButton
                 );
} // end of wxButton::DoGetBestSize
Example #8
0
void  wxSpinCtrl::SetValue(int val)
{
    wxSpinButton::SetValue(val);

    // normally setting the value of the spin button is enough as it updates
    // its buddy control automatically ...
    if ( wxGetWindowText(m_hwndBuddy).empty() )
    {
        // ... but sometimes it doesn't, notably when the value is 0 and the
        // text control is currently empty, the spin button seems to be happy
        // to leave it like this, while we really want to always show the
        // current value in the control, so do it manually
        ::SetWindowText(GetBuddyHwnd(), wxString::Format(_T("%d"), val));
    }

    m_oldValue = GetValue();
}
Example #9
0
wxString wxTextCtrl::GetValue() const
{
    wxString                        sStr = wxGetWindowText(GetHWND());
    char*                           zStr = (char*)sStr.c_str();

    for ( ; *zStr; zStr++ )
    {
        //
        // this will replace \r\n with just \n
        //
        if (*zStr == '\n')
            *zStr = '\0';
        if (*zStr == '\r')
            *zStr = '\n';
    }
    return sStr;
} // end of wxTextCtrl::GetValue
Example #10
0
void wxSpinCtrl::OnChar (
  wxKeyEvent&                       rEvent
)
{
    switch (rEvent.GetKeyCode())
    {
        case WXK_RETURN:
            {
                wxCommandEvent              vEvent( wxEVT_COMMAND_TEXT_ENTER
                                                   ,m_windowId
                                                  );
                wxString                    sVal = wxGetWindowText(m_hWndBuddy);

                InitCommandEvent(vEvent);
                vEvent.SetString(sVal);
                vEvent.SetInt(GetValue());
                if (HandleWindowEvent(vEvent))
                    return;
                break;
            }

        case WXK_TAB:
            //
            // Always produce navigation event - even if we process TAB
            // ourselves the fact that we got here means that the user code
            // decided to skip processing of this TAB - probably to let it
            // do its default job.
            //
            {
                wxNavigationKeyEvent        vEventNav;

                vEventNav.SetDirection(!rEvent.ShiftDown());
                vEventNav.SetWindowChange(rEvent.ControlDown());
                vEventNav.SetEventObject(this);
                if (GetParent()->HandleWindowEvent(vEventNav))
                    return;
            }
            break;
    }

    //
    // No, we didn't process it
    //
    rEvent.Skip();
} // end of wxSpinCtrl::OnChar
Example #11
0
wxSize wxCheckBox::DoGetBestSize() const
{
    static int                      nCheckSize = 0;

    if (!nCheckSize)
    {
        wxScreenDC                  vDc;

        vDc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));

        //
        // The height of a standard button in the dialog units is 8,
        // translate this to pixels (as one dialog unit is precisely equal to
        // 8 character heights, it's just the char height)
        //
        nCheckSize = vDc.GetCharHeight();
    }

    int                             nWidthCheckbox;
    int                             nHeightCheckbox;
    wxString                        sStr = wxGetWindowText(GetHWND());

    if (!sStr.IsEmpty())
    {
        GetTextExtent( sStr
                      ,&nWidthCheckbox
                      ,&nHeightCheckbox
                     );
        nWidthCheckbox += nCheckSize + GetCharWidth();

        if (nHeightCheckbox < nCheckSize)
            nHeightCheckbox = nCheckSize;
    }
    else
    {
        nWidthCheckbox  = nCheckSize;
        nHeightCheckbox = nCheckSize;
    }

    return wxSize( nWidthCheckbox
                  ,nHeightCheckbox
                 );
} // end of wxCheckBox::DoGetBestSize
Example #12
0
wxSize wxRadioBox::GetMaxButtonSize() const
{
    // calculate the max button size
    int widthMax = 0,
        heightMax = 0;
    const unsigned int count = GetCount();
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
    for ( unsigned int i = 0 ; i < count; i++ )
    {
        int width, height;
        if ( m_radioWidth[i] < 0 )
        {
            GetTextExtent(wxGetWindowText((*m_radioButtons)[i]), &width, &height);

            // adjust the size to take into account the radio box itself
            // FIXME this is totally bogus!
            width += RADIO_SIZE;
            height *= 3;
            height /= 2;
        }
        else
        {
            width = m_radioWidth[i];
            height = m_radioHeight[i];
        }

        if ( widthMax < width )
            widthMax = width;
        if ( heightMax < height )
            heightMax = height;
    }

    return wxSize(widthMax, heightMax);
}
Example #13
0
wxSize wxStaticBox::DoGetBestSize() const
{
    int                             nCx;
    int                             nCy;
    int                             wBox;

    nCx = GetCharWidth();
    nCy = GetCharHeight();
    GetTextExtent( wxGetWindowText(m_hWnd)
                  ,&wBox
                  ,NULL
                 );
    wBox += 3 * nCx;

    int                             hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy);

    return wxSize( wBox
                  ,hBox
                 );
} // end of wxStaticBox::DoGetBestSize
Example #14
0
wxSize wxRadioBox::GetMaxButtonSize() const
{
    int nWidthMax = 0;
    int nHeightMax = 0;

    for (unsigned int i = 0 ; i < m_nNoItems; i++)
    {
        int nWidth;
        int nHeight;

        if (m_pnRadioWidth[i] < 0L)
        {
            GetTextExtent( wxGetWindowText(m_ahRadioButtons[i])
                          ,&nWidth
                          ,&nHeight
                         );

            //
            // Adjust the size to take into account the radio box itself
            // FIXME this is totally bogus!
            //
            nWidth  += RADIO_SIZE;
            nHeight *= 3;
            nHeight /= 2;
        }
        else
        {
            nWidth  = m_pnRadioWidth[i];
            nHeight = m_pnRadioHeight[i];
        }
        if (nWidthMax < nWidth )
            nWidthMax = nWidth;
        if (nHeightMax < nHeight )
            nHeightMax = nHeight;
    }
    wxSize maxsize( nWidthMax, nHeightMax);
    return maxsize;
} // end of wxRadioBox::GetMaxButtonSize
Example #15
0
wxSize wxCheckBox::DoGetBestSize() const
{
    static int s_checkSize = 0;

    if ( !s_checkSize )
    {
        wxScreenDC dc;
        dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));

        s_checkSize = dc.GetCharHeight();
    }

    wxString str = wxGetWindowText(GetHWND());

    int wCheckbox, hCheckbox;
    if ( !str.empty() )
    {
        wxClientDC dc(const_cast<wxCheckBox *>(this));
        dc.SetFont(GetFont());
        dc.GetMultiLineTextExtent(GetLabelText(str), &wCheckbox, &hCheckbox);
        wCheckbox += s_checkSize + GetCharWidth();

        if ( hCheckbox < s_checkSize )
            hCheckbox = s_checkSize;
    }
    else
    {
        wCheckbox = s_checkSize;
        hCheckbox = s_checkSize;
    }
#ifdef __WXWINCE__
    hCheckbox += 1;
#endif

    wxSize best(wCheckbox, hCheckbox);
    CacheBestSize(best);
    return best;
}
Example #16
0
bool wxSpinCtrl::ProcessTextCommand( WXWORD wCmd,
                                     WXWORD WXUNUSED(wId) )
{
    switch (wCmd)
    {
        case SPBN_CHANGE:
        {
            wxCommandEvent vEvent( wxEVT_COMMAND_TEXT_UPDATED, GetId() );
            vEvent.SetEventObject(this);

            wxString sVal = wxGetWindowText(m_hWndBuddy);

            vEvent.SetString(sVal);
            vEvent.SetInt(GetValue());
            return (HandleWindowEvent(vEvent));
        }

        case SPBN_SETFOCUS:
        case SPBN_KILLFOCUS:
        {
            wxFocusEvent vEvent( wCmd == EN_KILLFOCUS ? wxEVT_KILL_FOCUS : wxEVT_SET_FOCUS
                                ,m_windowId
                               );

            vEvent.SetEventObject(this);
            return(HandleWindowEvent(vEvent));
        }
        default:
            break;
    }

    //
    // Not processed
    //
    return false;
} // end of wxSpinCtrl::ProcessTextCommand
Example #17
0
wxString wxRadioBox::GetLabel(int nItem) const
{
    wxCHECK_MSG( IsValid(nItem), wxEmptyString, wxT("invalid radiobox index") );

    return wxGetWindowText(m_ahRadioButtons[nItem]);
} // end of wxRadioBox::GetLabel
Example #18
0
bool wxComboBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
{
    wxString value;
    int sel = -1;
    switch ( param )
    {
        case CBN_SELENDOK:
        case CBN_SELCHANGE:
            sel = GetSelection();

            // we may sometimes get 2 CBN_SELCHANGE events or a CBN_SELENDOK
            // before CBN_SELCHANGE with the same index when the user selects
            // an item in the combobox -- ignore duplicates
            if ( sel > -1 && sel != m_selectionOld )
            {
                m_selectionOld = sel;

                // GetValue() would still return the old value from here but
                // according to the docs we should return the new value if the
                // user calls it in his event handler, so update internal
                // m_value
                m_value = GetString(sel);

                wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, GetId());
                event.SetInt(sel);
                event.SetEventObject(this);
                event.SetString(m_value);
                ProcessCommand(event);
            }
            else // no valid selection
            {
                m_selectionOld = sel;

                // hence no EVT_TEXT neither
                break;
            }

            // fall through: for compability with wxGTK, also send the text
            // update event when the selection changes (this also seems more
            // logical as the text does change)

        case CBN_EDITCHANGE:
            {
                wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());

                // if sel != -1, value was initialized above (and we can't use
                // GetValue() here as it would return the old selection and we
                // want the new one)
                if ( sel == -1 )
                {
                    m_value = wxGetWindowText(GetHwnd());
                    m_selectionOld = -1;
                }
                else // we're synthesizing text updated event from sel change
                {
                    // We need to retrieve the current selection because the
                    // user may have changed it in the previous handler (for
                    // CBN_SELCHANGE above).
                    sel = GetSelection();
                    if ( sel > -1 )
                    {
                        m_value = GetString(sel);
                    }
                }

                event.SetString(m_value);
                event.SetEventObject(this);
                ProcessCommand(event);
            }
            break;
    }

    // there is no return value for the CBN_ notifications, so always return
    // false from here to pass the message to DefWindowProc()
    return false;
}
Example #19
0
wxString wxTextEntry::DoGetValue() const
{
    return wxGetWindowText(GetEditHWND());
}
Example #20
0
// Find string for position
wxString wxRadioBox::GetString(unsigned int nNum) const
{
    wxCHECK_MSG( IsValid(nNum), wxEmptyString, wxT("invalid radiobox index") );
    return wxGetWindowText(m_ahRadioButtons[nNum]);
} // end of wxRadioBox::GetString
Example #21
0
bool wxComboBox::MSWCommand(WXUINT param, WXWORD id)
{
    int sel = -1;
    wxString value;

    switch ( param )
    {
        case CBN_DROPDOWN:
            // remember the last selection, just as wxChoice does
            m_lastAcceptedSelection = GetCurrentSelection();
            {
                wxCommandEvent event(wxEVT_COMBOBOX_DROPDOWN, GetId());
                event.SetEventObject(this);
                ProcessCommand(event);
            }
            break;

        case CBN_CLOSEUP:
            // Do the same thing as in wxChoice but using different event type.
            if ( m_pendingSelection != wxID_NONE )
            {
                SendSelectionChangedEvent(wxEVT_COMBOBOX);
                m_pendingSelection = wxID_NONE;
            }
            {
                wxCommandEvent event(wxEVT_COMBOBOX_CLOSEUP, GetId());
                event.SetEventObject(this);
                ProcessCommand(event);
            }
            break;

        case CBN_SELENDOK:
#ifndef __SMARTPHONE__
            // we need to reset this to prevent the selection from being undone
            // by wxChoice, see wxChoice::MSWCommand() and comments there
            m_lastAcceptedSelection = wxID_NONE;
#endif

            // set these variables so that they could be also fixed in
            // CBN_EDITCHANGE below
            sel = GetSelection();
            value = GetStringSelection();

            // this string is going to become the new combobox value soon but
            // we need it to be done right now, otherwise the event handler
            // could get a wrong value when it calls our GetValue()
            ::SetWindowText(GetHwnd(), value.t_str());

            SendSelectionChangedEvent(wxEVT_COMBOBOX);

            // fall through: for compatibility with wxGTK, also send the text
            // update event when the selection changes (this also seems more
            // logical as the text does change)

        case CBN_EDITCHANGE:
            if ( m_allowTextEvents )
            {
                wxCommandEvent event(wxEVT_TEXT, GetId());

                // if sel != -1, value was already initialized above
                if ( sel == -1 )
                {
                    value = wxGetWindowText(GetHwnd());
                }

                event.SetString(value);
                InitCommandEventWithItems(event, sel);

                ProcessCommand(event);
            }
            break;

        default:
            return wxChoice::MSWCommand(param, id);
    }

    // skip wxChoice version as it would generate its own events for
    // CBN_SELENDOK and also interfere with our handling of CBN_DROPDOWN
    return true;
}
Example #22
0
void wxMessageDialog::ReplaceStaticWithEdit()
{
    // check if the message box fits the display
    int nDisplay = wxDisplay::GetFromWindow(this);
    if ( nDisplay == wxNOT_FOUND )
        nDisplay = 0;
    const wxRect rectDisplay = wxDisplay(nDisplay).GetClientArea();

    if ( rectDisplay.Contains(GetRect()) )
    {
        // nothing to do
        return;
    }


    // find the static control to replace: normally there are two of them, the
    // icon and the text itself so search for all of them and ignore the icon
    // ones
    HWND hwndStatic = ::FindWindowEx(GetHwnd(), NULL, wxT("STATIC"), NULL);
    if ( ::GetWindowLong(hwndStatic, GWL_STYLE) & SS_ICON )
        hwndStatic = ::FindWindowEx(GetHwnd(), hwndStatic, wxT("STATIC"), NULL);

    if ( !hwndStatic )
    {
        wxLogDebug("Failed to find the static text control in message box.");
        return;
    }

    // set the right font for GetCharHeight() call below
    wxWindowBase::SetFont(GetMessageFont());

    // put the new edit control at the same place
    RECT rc = wxGetWindowRect(hwndStatic);
    ScreenRectToClient(GetHwnd(), rc);

    // but make it less tall so that the message box fits on the screen: we try
    // to make the message box take no more than 7/8 of the screen to leave
    // some space above and below it
    const int hText = (7*rectDisplay.height)/8 -
                      (
                         2*::GetSystemMetrics(SM_CYFIXEDFRAME) +
                         ::GetSystemMetrics(SM_CYCAPTION) +
                         5*GetCharHeight() // buttons + margins
                      );
    const int dh = (rc.bottom - rc.top) - hText; // vertical space we save
    rc.bottom -= dh;

    // and it also must be wider as it needs a vertical scrollbar (in order
    // to preserve the word wrap, otherwise the number of lines would change
    // and we want the control to look as similar as possible to the original)
    //
    // NB: you would have thought that 2*SM_CXEDGE would be enough but it
    //     isn't, somehow, and the text control breaks lines differently from
    //     the static one so fudge by adding some extra space
    const int dw = ::GetSystemMetrics(SM_CXVSCROLL) +
                        4*::GetSystemMetrics(SM_CXEDGE);
    rc.right += dw;


    // chop of the trailing new line(s) from the message box text, they are
    // ignored by the static control but result in extra lines and hence extra
    // scrollbar position in the edit one
    wxString text(wxGetWindowText(hwndStatic));
    for ( wxString::reverse_iterator i = text.rbegin(); i != text.rend(); ++i )
    {
        if ( *i != '\n' )
        {
            // found last non-newline char, remove everything after it and stop
            text.erase(i.base() + 1, text.end());
            break;
        }
    }

    // do create the new control
    HWND hwndEdit = ::CreateWindow
                      (
                        wxT("EDIT"),
                        wxTextBuffer::Translate(text).wx_str(),
                        WS_CHILD | WS_VSCROLL | WS_VISIBLE |
                        ES_MULTILINE | ES_READONLY | ES_AUTOVSCROLL,
                        rc.left, rc.top,
                        rc.right - rc.left, rc.bottom - rc.top,
                        GetHwnd(),
                        NULL,
                        wxGetInstance(),
                        NULL
                      );

    if ( !hwndEdit )
    {
        wxLogDebug("Creation of replacement edit control failed in message box");
        return;
    }

    // copy the font from the original control
    LRESULT hfont = ::SendMessage(hwndStatic, WM_GETFONT, 0, 0);
    ::SendMessage(hwndEdit, WM_SETFONT, hfont, 0);

    // and get rid of it
    ::DestroyWindow(hwndStatic);


    // shrink and centre the message box vertically and widen it box to account
    // for the extra scrollbar
    RECT rcBox = wxGetWindowRect(GetHwnd());
    const int hMsgBox = rcBox.bottom - rcBox.top - dh;
    rcBox.top = (rectDisplay.height - hMsgBox)/2;
    rcBox.bottom = rcBox.top + hMsgBox + (rectDisplay.height - hMsgBox)%2;
    rcBox.left -= dw/2;
    rcBox.right += dw - dw/2;
    SetWindowRect(GetHwnd(), rcBox);

    // and adjust all the buttons positions
    for ( unsigned n = 0; n < WXSIZEOF(ms_buttons); n++ )
    {
        const HWND hwndBtn = ::GetDlgItem(GetHwnd(), ms_buttons[n].id);
        if ( !hwndBtn )
            continue;   // it's ok, not all buttons are always present

        RECT rc = wxGetWindowRect(hwndBtn);
        rc.top -= dh;
        rc.bottom -= dh;
        rc.left += dw/2;
        rc.right += dw/2;
        MoveWindowToScreenRect(hwndBtn, rc);
    }
}
Example #23
0
wxSize wxStaticText::DoGetBestSize() const
{
    wxString                        sText(wxGetWindowText(GetHWND()));
    int                             nWidthTextMax = 0;
    int                             nWidthLine = 0;
    int                             nHeightTextTotal = 0;
    int                             nHeightLineDefault = 0;
    int                             nHeightLine = 0;
    wxString                        sCurLine;
    bool                            bLastWasTilde = FALSE;

    for (const wxChar *pc = sText; ; pc++)
    {
        if ( *pc == wxT('\n') || *pc == wxT('\0') )
        {
            if (!sCurLine )
            {
                //
                // We can't use GetTextExtent - it will return 0 for both width
                // and height and an empty line should count in height
                // calculation
                //
                if (!nHeightLineDefault)
                    nHeightLineDefault = nHeightLine;
                if (!nHeightLineDefault)
                    GetTextExtent(_T("W"), NULL, &nHeightLineDefault);
                nHeightTextTotal += nHeightLineDefault;
            }
            else
            {
                GetTextExtent( sCurLine
                              ,&nWidthLine
                              ,&nHeightLine
                             );
                if (nWidthLine > nWidthTextMax)
                    nWidthTextMax = nWidthLine;
                nHeightTextTotal += nHeightLine;
            }

            if ( *pc == wxT('\n') )
            {
                sCurLine.Empty();
            }
            else
            {
               break;
            }
        }
        else
        {
            //
            // We shouldn't take into account the '~' which just introduces the
            // mnemonic characters and so are not shown on the screen -- except
            // when it is preceded by another '~' in which case it stands for a
            // literal tilde
            //
            if (*pc == _T('~'))
            {
                if (!bLastWasTilde)
                {
                    bLastWasTilde = TRUE;

                    //
                    // Skip the statement adding pc to curLine below
                    //
                    continue;
                }

                //
                // It is a literal tilde
                //
                bLastWasTilde = FALSE;
            }
            sCurLine += *pc;
        }
    }
    return wxSize( nWidthTextMax
                  ,nHeightTextTotal
                 );
} // end of wxStaticText::DoGetBestSize
Example #24
0
wxString wxStaticText::DoGetLabel() const
{
    return wxGetWindowText(GetHwnd());
}