예제 #1
0
wxSize wxStaticBox::DoGetBestSize() const
{
    wxSize best;

    // Calculate the size needed by the label
    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);

    // If there is a sizer then the base best size is the sizer's minimum
    if (GetSizer() != NULL)
    {
        wxSize cm(GetSizer()->CalcMin());
        best = ClientToWindowSize(cm);
        // adjust for a long label if needed
        best.x = wxMax(best.x, wBox);
    }
    // otherwise the best size falls back to the label size
    else
    {
        best = wxSize(wBox, hBox);
    }
    return best;
}
예제 #2
0
wxSize wxStaticText::DoGetBestClientSize() const
{
    wxClientDC dc(const_cast<wxStaticText *>(this));
    wxFont font(GetFont());
    if (!font.IsOk())
        font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);

    dc.SetFont(font);

    wxCoord widthTextMax, heightTextTotal;
    dc.GetMultiLineTextExtent(GetLabelText(), &widthTextMax, &heightTextTotal);

    // This extra pixel is a hack we use to ensure that a wxStaticText
    // vertically centered around the same position as a wxTextCtrl shows its
    // text on exactly the same baseline. It is not clear why is this needed
    // nor even whether this works in all cases, but it does work, at least
    // with the default fonts, under Windows XP, 7 and 8, so just use it for
    // now.
    //
    // In the future we really ought to provide a way for each of the controls
    // to provide information about the position of the baseline for the text
    // it shows and use this information in the sizer code when centering the
    // controls vertically, otherwise we simply can't ensure that the text is
    // always on the same line, e.g. even with this hack wxComboBox text is
    // still not aligned to the same position.
    heightTextTotal += 1;

    return wxSize(widthTextMax, heightTextTotal);
}
예제 #3
0
파일: tglbtn.cpp 프로젝트: 252525fb/rpcs3
wxSize wxToggleButton::DoGetBestSize() const
{
   wxString label = wxGetWindowText(GetHWND());
   int wBtn;
   GetTextExtent(GetLabelText(label), &wBtn, NULL);

   int wChar, hChar;
   wxGetCharSize(GetHWND(), &wChar, &hChar, GetFont());

   // add a margin - the button is wider than just its label
   wBtn += 3*wChar;

   // the button height is proportional to the height of the font used
   int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);

#if wxUSE_BUTTON
   // make all buttons of at least standard size unless wxBU_EXACTFIT is given
   if ( !HasFlag(wxBU_EXACTFIT) )
   {
       const wxSize szMin = wxButton::GetDefaultSize();
       if ( wBtn < szMin.x )
           wBtn = szMin.x;
       if ( hBtn < szMin.y )
           hBtn = szMin.y;
   }
#endif // wxUSE_BUTTON

   wxSize sz(wBtn, hBtn);

   CacheBestSize(sz);
   return sz;
}
예제 #4
0
wxSize wxStaticText::DoGetBestSize() const
{
    int w, h;
    GetTextExtent(GetLabelText(), &w, &h, NULL, NULL, NULL);

    return wxSize(w, h);
}
예제 #5
0
wxSize wxRadioButton::DoGetBestSize() const
{
    static int s_radioSize = 0;

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

        s_radioSize = dc.GetCharHeight();
    }

    wxString str = GetLabel();

    int wRadio, hRadio;
    if ( !str.empty() )
    {
        GetTextExtent(GetLabelText(str), &wRadio, &hRadio);
        wRadio += s_radioSize + GetCharWidth();

        if ( hRadio < s_radioSize )
            hRadio = s_radioSize;
    }
    else
    {
        wRadio = s_radioSize;
        hRadio = s_radioSize;
    }

    wxSize best(wRadio, hRadio);
    CacheBestSize(best);
    return best;
}
예제 #6
0
bool wxRadioBox::Create( wxWindow *parent,
    wxWindowID id, const wxString& label,
    const wxPoint& pos, const wxSize& size,
    int n, const wxString choices[],
    int majorDim, long style,
    const wxValidator& val, const wxString& name )
{    
    DontCreatePeer();
    
    if ( !wxControl::Create( parent, id, pos, size, style, val, name ) )
        return false;

    // during construction we must keep this at 0, otherwise GetBestSize fails
    m_noItems = 0;
    m_noRowsOrCols = majorDim;
    m_radioButtonCycle = NULL;

    SetMajorDim( majorDim == 0 ? n : majorDim, style );

    m_labelOrig = m_label = label;

    SetPeer(wxWidgetImpl::CreateGroupBox( this, parent, id, label, pos, size, style, GetExtraStyle() ));

#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 (int i = 0; i < n; i++)
    {
        wxRadioButton *radBtn = new wxRadioButton(
            this,
            wxID_ANY,
            GetLabelText(choices[i]),
            wxPoint( 5, 20 * i + 10 ),
            wxDefaultSize,
            i == 0 ? wxRB_GROUP : 0 );

        if ( i == 0 )
            m_radioButtonCycle = radBtn;
//        m_radioButtonCycle = radBtn->AddInCycle( m_radioButtonCycle );
    }

    // as all radiobuttons have been set-up, set the correct dimensions
    m_noItems = (unsigned int)n;
    SetMajorDim( majorDim == 0 ? n : majorDim, style );

    SetSelection( 0 );
    InvalidateBestSize();
    SetInitialSize( size );
    MacPostControlCreate( pos, size );

    return true;
}
예제 #7
0
파일: choice.cpp 프로젝트: 3v1n0/wxWidgets
// TODO auto-sorting is not supported by the code
int wxChoice::DoInsertItems(const wxArrayStringsAdapter& items,
                            unsigned int pos,
                            void **clientData, wxClientDataType type)
{
#ifndef XmNpositionIndex
    wxCHECK_MSG( pos == GetCount(), -1, wxT("insert not implemented"));
#endif

    const unsigned int numItems = items.GetCount();
    AllocClientData(numItems);
    for( unsigned int i = 0; i < numItems; ++i, ++pos )
    {
        Widget w = XtVaCreateManagedWidget (GetLabelText(items[i]),
#if wxUSE_GADGETS
            xmPushButtonGadgetClass, (Widget) m_menuWidget,
#else
            xmPushButtonWidgetClass, (Widget) m_menuWidget,
#endif
#ifdef XmNpositionIndex
            XmNpositionIndex, pos,
#endif
            NULL);

        wxDoChangeBackgroundColour((WXWidget) w, m_backgroundColour);

        if( m_font.IsOk() )
            wxDoChangeFont( w, m_font );

        m_widgetArray.Insert(w, pos);

        char mnem = wxFindMnemonic (items[i]);
        if (mnem != 0)
            XtVaSetValues (w, XmNmnemonic, mnem, NULL);

        XtAddCallback (w, XmNactivateCallback,
                       (XtCallbackProc) wxChoiceCallback,
                       (XtPointer) this);

        if (m_stringArray.GetCount() == 0 && m_buttonWidget)
        {
            XtVaSetValues ((Widget) m_buttonWidget, XmNmenuHistory, w, NULL);
            Widget label = XmOptionButtonGadget ((Widget) m_buttonWidget);
            wxXmString text( items[i] );
            XtVaSetValues (label,
                XmNlabelString, text(),
                NULL);
        }

        m_stringArray.Insert(items[i], pos);

        InsertNewItemClientData(pos, clientData, i, type);
    }

    return pos - 1;
}
예제 #8
0
wxSize wxStaticText::DoGetBestSize() const
{
    wxClientDC dc(const_cast<wxStaticText *>(this));
    wxFont font(GetFont());
    if (!font.Ok())
        font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);

    dc.SetFont(font);

    wxCoord widthTextMax, heightTextTotal;
    dc.GetMultiLineTextExtent(GetLabelText(), &widthTextMax, &heightTextTotal);

#ifdef __WXWINCE__
    if ( widthTextMax )
        widthTextMax += 2;
#endif // __WXWINCE__

    // border takes extra space
    //
    // TODO: this is probably not wxStaticText-specific and should be moved
    wxCoord border;
    switch ( GetBorder() )
    {
        case wxBORDER_STATIC:
        case wxBORDER_SIMPLE:
            border = 1;
            break;

        case wxBORDER_SUNKEN:
            border = 2;
            break;

        case wxBORDER_RAISED:
        case wxBORDER_DOUBLE:
            border = 3;
            break;

        default:
            wxFAIL_MSG( _T("unknown border style") );
            // fall through

        case wxBORDER_NONE:
            border = 0;
    }

    widthTextMax += 2*border;
    heightTextTotal += 2*border;

    wxSize best(widthTextMax, heightTextTotal);
    CacheBestSize(best);
    return best;
}
예제 #9
0
void wxControl::SetLabel(const wxString& label)
{
    Widget widget = (Widget) GetLabelWidget() ;
    if (!widget)
        return;

    wxXmString label_str(GetLabelText(label));

    XtVaSetValues (widget,
        XmNlabelString, label_str(),
        XmNlabelType, XmSTRING,
        NULL);
}
예제 #10
0
wxSize wxCheckBox::DoGetBestClientSize() 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 ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & BS_MULTILINE )
        {
            // We need to make the checkbox even wider in this case because
            // otherwise it wraps lines automatically and not only on "\n"s as
            // we need and this makes the size computed here wrong resulting in
            // checkbox contents being truncated when it's actually displayed.
            // Without this hack simple checkbox with "Some thing\n and more"
            // label appears on 3 lines, not 2, under Windows 2003 using
            // classic look and feel (although it works fine under Windows 7,
            // with or without themes).
            wCheckbox += s_checkSize;
        }

        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;
}
예제 #11
0
파일: button.cpp 프로젝트: hgwells/tive
bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& lbl,
                      const wxPoint& pos,
                      const wxSize& size, long style,
                      const wxValidator& validator,
                      const wxString& name)
{
    wxString label(lbl);
    if (label.empty() && wxIsStockID(id))
        label = wxGetStockLabel(id);

    if( !CreateControl( parent, id, pos, size, style, validator, name ) )
        return false;

    wxXmString text( GetLabelText(label) );

    Widget parentWidget = (Widget) parent->GetClientWidget();

    /*
    * Patch Note (important)
    * There is no major reason to put a defaultButtonThickness here.
    * Not requesting it give the ability to put wxButton with a spacing
    * as small as requested. However, if some button become a DefaultButton,
    * other buttons are no more aligned -- This is why we set
    * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
    * in the ::SetDefaultButton method.
    */
    m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("button",
        xmPushButtonWidgetClass,
        parentWidget,
        wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay(parentWidget)),
        XmNlabelString, text(),
        XmNrecomputeSize, False,
        // See comment for wxButton::SetDefault
        // XmNdefaultButtonShadowThickness, 1,
        NULL);

    XtAddCallback ((Widget) m_mainWidget,
                   XmNactivateCallback, (XtCallbackProc) wxButtonCallback,
                   (XtPointer) this);

    wxSize best = GetBestSize();
    if( size.x != -1 ) best.x = size.x;
    if( size.y != -1 ) best.y = size.y;

    AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
                  pos.x, pos.y, best.x, best.y);

    ChangeBackgroundColour();

    return true;
}
예제 #12
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;
}
예제 #13
0
파일: choice.cpp 프로젝트: EdgarTx/wx
int wxChoice::DoInsert(const wxString& item, unsigned int pos)
{
#ifndef XmNpositionIndex
    wxCHECK_MSG( pos == GetCount(), -1, wxT("insert not implemented"));
#endif
    Widget w = XtVaCreateManagedWidget (GetLabelText(item),
#if wxUSE_GADGETS
        xmPushButtonGadgetClass, (Widget) m_menuWidget,
#else
        xmPushButtonWidgetClass, (Widget) m_menuWidget,
#endif
#ifdef XmNpositionIndex
        XmNpositionIndex, pos,
#endif
        NULL);

    wxDoChangeBackgroundColour((WXWidget) w, m_backgroundColour);

    if( m_font.Ok() )
        wxDoChangeFont( w, m_font );

    m_widgetArray.Insert(w, pos);

    char mnem = wxFindMnemonic (item);
    if (mnem != 0)
        XtVaSetValues (w, XmNmnemonic, mnem, NULL);

    XtAddCallback (w, XmNactivateCallback,
                   (XtCallbackProc) wxChoiceCallback,
                   (XtPointer) this);

    if (m_noStrings == 0 && m_buttonWidget)
    {
        XtVaSetValues ((Widget) m_buttonWidget, XmNmenuHistory, w, NULL);
        Widget label = XmOptionButtonGadget ((Widget) m_buttonWidget);
        wxXmString text( item );
        XtVaSetValues (label,
            XmNlabelString, text(),
            NULL);
    }
    // need to ditch wxStringList for wxArrayString
    m_stringList.Insert(pos, MYcopystring(item));
    m_noStrings ++;

    return pos;
}
예제 #14
0
void wxRadioBox::SetString(unsigned int item, const wxString& label)
{
    if (!IsValid(item))
        return;

    Widget widget = (Widget)m_radioButtons[item];
    if (!label.empty())
    {
        wxString label1(GetLabelText(label));
        wxXmString text( label1 );
        m_radioButtonLabels[item] = label1;
        XtVaSetValues (widget,
                       XmNlabelString, text(),
                       XmNlabelType, XmSTRING,
                       NULL);
    }
}
예제 #15
0
파일: statbox.cpp 프로젝트: beanhome/dev
bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
           const wxString& label,
           const wxPoint& pos,
           const wxSize& size,
           long style,
           const wxString& name)
{
    if( !CreateControl( parent, id, pos, size, style,
                        wxDefaultValidator, name ) )
        return false;
    m_labelWidget = (WXWidget) 0;
    PreCreation();

    Widget parentWidget = (Widget) parent->GetClientWidget();

    m_mainWidget = XtVaCreateManagedWidget ("staticboxframe",
            xmFrameWidgetClass, parentWidget,
            // MBN: why override default?
            // XmNshadowType, XmSHADOW_IN,
            NULL);

    if (!label.empty())
    {
        wxString label1(GetLabelText(label));
        wxXmString text(label1);
        Display* dpy = XtDisplay( parentWidget );

        m_labelWidget = (WXWidget) XtVaCreateManagedWidget ("staticboxlabel",
                xmLabelWidgetClass, (Widget)m_mainWidget,
                wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
                XmNlabelString, text(),
#if wxCHECK_MOTIF_VERSION( 2, 0 )
                XmNframeChildType, XmFRAME_TITLE_CHILD,
#else
                XmNchildType, XmFRAME_TITLE_CHILD,
#endif
                NULL);
    }

    PostCreation();
    AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);

    return true;
}
예제 #16
0
bool wxRadioBox::Create( wxWindow *parent,
    wxWindowID id, const wxString& label,
    const wxPoint& pos, const wxSize& size,
    int n, const wxString choices[],
    int majorDim, long style,
    const wxValidator& val, const wxString& name )
{
    m_macIsUserPane = false ;

    if ( !wxControl::Create( parent, id, pos, size, style, val, name ) )
        return false;

    int i;

    m_noItems = (unsigned int)n;
    m_noRowsOrCols = majorDim;
    m_radioButtonCycle = NULL;

    SetMajorDim( majorDim == 0 ? n : majorDim, style );

    m_labelOrig = m_label = label;

    m_peer = wxWidgetImpl::CreateGroupBox( this, parent, id, label, pos, size, style, GetExtraStyle() );

    for (i = 0; i < n; i++)
    {
        wxRadioButton *radBtn = new wxRadioButton(
            this,
            wxID_ANY,
            GetLabelText(choices[i]),
            wxPoint( 5, 20 * i + 10 ),
            wxDefaultSize,
            i == 0 ? wxRB_GROUP : 0 );

        if ( i == 0 )
            m_radioButtonCycle = radBtn;
//        m_radioButtonCycle = radBtn->AddInCycle( m_radioButtonCycle );
    }

    SetSelection( 0 );
    MacPostControlCreate( pos, size );

    return true;
}
예제 #17
0
파일: stattext.cpp 프로젝트: hgwells/tive
void wxStaticText::SetLabel( const wxString& st )
{
    m_label =  st;

    wxMacCFStringHolder str( GetLabelText(m_label), m_font.GetEncoding() );
    CFStringRef ref = str;
    OSStatus err = m_peer->SetData<CFStringRef>(kControlEntireControl, kControlStaticTextCFStringTag, ref );
    verify_noerr( err );

    if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
    {
        InvalidateBestSize();
        SetSize( GetBestSize() );
    }

    Refresh();

    // we shouldn't need forced updates
    // Update();
}
예제 #18
0
wxSize wxRadioButton::DoGetBestSize() const
{
    static int s_radioSize = 0;

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

        s_radioSize = dc.GetCharHeight();

        // radio button bitmap size under CE is bigger than the font height,
        // adding just one pixel seems to work fine for the default font but it
        // would be nice to find some better way to find the correct height
#ifdef __WXWINCE__
        s_radioSize++;
#endif // __WXWINCE__
    }

    wxString str = GetLabel();

    int wRadio, hRadio;
    if ( !str.empty() )
    {
        GetTextExtent(GetLabelText(str), &wRadio, &hRadio);
        wRadio += s_radioSize + GetCharWidth();

        if ( hRadio < s_radioSize )
            hRadio = s_radioSize;
    }
    else
    {
        wRadio = s_radioSize;
        hRadio = s_radioSize;
    }

    wxSize best(wRadio, hRadio);
    CacheBestSize(best);
    return best;
}
예제 #19
0
파일: checkbox.cpp 프로젝트: beanhome/dev
// Single check box item
bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
                        const wxPoint& pos,
                        const wxSize& size, long style,
                        const wxValidator& validator,
                        const wxString& name)
{
    if( !wxControl::CreateControl( parent, id, pos, size, style, validator,
                                   name ) )
        return false;
    PreCreation();

    wxXmString text( GetLabelText(label) );

    Widget parentWidget = (Widget) parent->GetClientWidget();

    m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
        xmToggleButtonWidgetClass, parentWidget,
        wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay(parentWidget)),
        XmNlabelString, text(),
        XmNrecomputeSize, False,
        // XmNindicatorOn, XmINDICATOR_CHECK_BOX,
        // XmNfillOnSelect, False,
#if wxHAS_3STATE
        XmNtoggleMode, Is3State() ? XmTOGGLE_INDETERMINATE : XmTOGGLE_BOOLEAN,
#endif
        NULL);

    XtAddCallback( (Widget)m_mainWidget,
                   XmNvalueChangedCallback, (XtCallbackProc)wxCheckBoxCallback,
                   (XtPointer)this );

    XmToggleButtonSetState ((Widget) m_mainWidget, False, True);

    PostCreation();
    AttachWidget( parent, m_mainWidget, (WXWidget)NULL,
                  pos.x, pos.y, size.x, size.y );

    return true;
}
예제 #20
0
파일: stattext.cpp 프로젝트: hgwells/tive
bool wxStaticText::Create( wxWindow *parent,
    wxWindowID id,
    const wxString& label,
    const wxPoint& pos,
    const wxSize& size,
    long style,
    const wxString& name )
{
    m_macIsUserPane = false;

    m_label = GetLabelText( label );

    if ( !wxControl::Create( parent, id, pos, size, style, wxDefaultValidator, name ) )
        return false;

    Rect bounds = wxMacGetBoundsForControl( this, pos, size );
    wxMacCFStringHolder str( m_label, m_font.GetEncoding() );

    m_peer = new wxMacControl( this );
    OSStatus err = CreateStaticTextControl(
        MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
        &bounds, str, NULL, m_peer->GetControlRefAddr() );
    verify_noerr( err );

    if ( ( style & wxST_DOTS_END ) || ( style & wxST_DOTS_MIDDLE ) )
    {
        TruncCode tCode = truncEnd;
        if ( style & wxST_DOTS_MIDDLE )
            tCode = truncMiddle;

        err = m_peer->SetData( kControlStaticTextTruncTag, tCode );
        err = m_peer->SetData( kControlStaticTextIsMultilineTag, (Boolean)0 );
    }

    MacPostControlCreate( pos, size );

    return true;
}
예제 #21
0
파일: checkbox.cpp 프로젝트: mark711/Cafu
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;
}
예제 #22
0
wxSize wxStaticText::DoGetBestClientSize() const
{
    wxClientDC dc(const_cast<wxStaticText *>(this));
    wxFont font(GetFont());
    if (!font.IsOk())
        font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);

    dc.SetFont(font);

    wxCoord widthTextMax, heightTextTotal;
    dc.GetMultiLineTextExtent(GetLabelText(), &widthTextMax, &heightTextTotal);

#ifdef __WXWINCE__
    if ( widthTextMax )
        widthTextMax += 2;
#endif // __WXWINCE__

    // It looks like the static control needs "slightly" more vertical space
    // than the character height and while the text isn't actually truncated if
    // we use just the minimal height, it is positioned differently than when
    // the control has enough space and this result in the text in edit and
    // static controls not being aligned when the controls themselves are. As
    // this is something you really should be able to count on, increase the
    // space allocated for the control so that the base lines do align
    // correctly. Notice that while the above is true at least for the single
    // line controls, there doesn't seem to do any harm to allocate two extra
    // pixels in multi-line case neither so do it always for consistency.
    //
    // I still have no idea why exactly is this needed nor why should we use 2
    // and not something else. This seems to work in all the configurations
    // though (small/large fonts, different OS versions, ...) so just hard code
    // it for now. If we need something better later it might be worth looking
    // at the height of the text control returned by ::GetComboBoxInfo() as it
    // seems to be the "minimal acceptable" height.
    heightTextTotal += 2;

    return wxSize(widthTextMax, heightTextTotal);
}
예제 #23
0
wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
{
    // the radiobox should be big enough for its buttons
    int cx1, cy1;
    wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont());

    int extraHeight = cy1;

    int height = GetRowCount() * sizeBtn.y + cy1/2 + extraHeight;
    int width  = GetColumnCount() * (sizeBtn.x + cx1) + cx1;

    // Add extra space under the label, if it exists.
    if (!wxControl::GetLabel().empty())
        height += cy1/2;

    // and also wide enough for its label
    int widthLabel;
    GetTextExtent(GetLabelText(), &widthLabel, NULL);
    widthLabel += RADIO_SIZE; // FIXME this is bogus too
    if ( widthLabel > width )
        width = widthLabel;

    return wxSize(width, height);
}
예제 #24
0
wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
{
    // the radiobox should be big enough for its buttons
    int cx1, cy1;
    wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont());

    int extraHeight = cy1;

    int height = GetRowCount() * sizeBtn.y + cy1/2 + extraHeight;
    int width  = GetColumnCount() * (sizeBtn.x + cx1) + cx1;

    // Add extra space under the label, if it exists.
    if (!wxControl::GetLabel().empty())
        height += wxRendererNative::Get().GetCheckBoxSize(
            reinterpret_cast<wxWindow*>(const_cast<wxRadioBox*>(this))).y / 2;

    // and also wide enough for its label
    int widthLabel;
    GetTextExtent(GetLabelText(), &widthLabel, NULL);
    if ( widthLabel > width )
        width = widthLabel;

    return wxSize(width, height);
}
예제 #25
0
	/** Constructs this widget with InArgs */
	void Construct( const FArguments& InArgs )
	{
		Style = InArgs._Style;
		HighlightedText = InArgs._HighlightedText;
		Label = InArgs._Label;
		HintColorAndOpacity = InArgs._HintColorAndOpacity;
		AllowHintText = InArgs._AllowHintText;
		ShowClassBackground = InArgs._ShowClassBackground;

		AssetThumbnail = InArgs._AssetThumbnail;
		bHasRenderedThumbnail = false;
		WidthLastFrame = 0;
		GenericThumbnailBorderPadding = 2.f;

		AssetThumbnail->OnAssetDataChanged().AddSP(this, &SAssetThumbnail::OnAssetDataChanged);

		const FAssetData& AssetData = AssetThumbnail->GetAssetData();

		UClass* Class = FindObject<UClass>(ANY_PACKAGE, *AssetData.AssetClass.ToString());
		FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>(TEXT("AssetTools"));
		TWeakPtr<IAssetTypeActions> AssetTypeActions;
		if ( Class != NULL )
		{
			AssetTypeActions = AssetToolsModule.Get().GetAssetTypeActionsForClass(Class);
		}

		AssetColor = FLinearColor::White;
		if ( AssetTypeActions.IsValid() )
		{
			AssetColor = AssetTypeActions.Pin()->GetTypeColor();
		}

		TSharedRef<SOverlay> OverlayWidget = SNew(SOverlay);

		FName Substyle;
		if ( Class == UClass::StaticClass() )
		{
			Substyle = FName(".ClassBackground");
			ClassAssetClass = FindObject<UClass>(ANY_PACKAGE, *AssetData.AssetName.ToString());
		}
		else if(AssetTypeActions.IsValid())
		{
			Substyle = FName(".AssetBackground");
		}
		const FName BackgroundBrushName( *(Style.ToString() + Substyle.ToString()) );

		ClassThumbnailBrushOverride = InArgs._ClassThumbnailBrushOverride;

		OverlayWidget->AddSlot()
		[
			SNew(SBorder)
			.BorderImage( this, &SAssetThumbnail::GetBackgroundBrush )
			.BorderBackgroundColor( this, &SAssetThumbnail::GetAssetColor )
			.Padding( GenericThumbnailBorderPadding )
			.VAlign(VAlign_Center)
			.HAlign(HAlign_Center)
			.Visibility(this, &SAssetThumbnail::GetClassThumbnailVisibility)
			[
				SNew( SImage )
				.Image( this, &SAssetThumbnail::GetClassThumbnailBrush )
			]
		];

		// The generic representation of the thumbnail, for use before the rendered version, if it exists
		OverlayWidget->AddSlot()
		[
			SNew(SBorder)
			.BorderImage( this, &SAssetThumbnail::GetBackgroundBrush )
			.BorderBackgroundColor( this, &SAssetThumbnail::GetAssetColor )
			.Padding( GenericThumbnailBorderPadding )
			.VAlign(VAlign_Center) .HAlign(HAlign_Center)
			.Visibility(this, &SAssetThumbnail::GetGenericThumbnailVisibility)
			[
				SAssignNew(LabelTextBlock, STextBlock)
				.Text( GetLabelText() )
				.Font( GetTextFont() )
				.ColorAndOpacity( FEditorStyle::GetColor(Style, ".ColorAndOpacity") )
				.ShadowOffset( FEditorStyle::GetVector(Style, ".ShadowOffset") )
				.ShadowColorAndOpacity( FEditorStyle::GetColor(Style, ".ShadowColorAndOpacity") )
				.WrapTextAt(this, &SAssetThumbnail::GetTextWrapWidth)
				.HighlightText( HighlightedText )
			]
		];

		if ( InArgs._ThumbnailPool.IsValid() && !InArgs._ForceGenericThumbnail && Class != UClass::StaticClass() )
		{
			ViewportFadeAnimation = FCurveSequence();
			ViewportFadeCurve = ViewportFadeAnimation.AddCurve(0.f, 0.25f, ECurveEaseFunction::QuadOut);

			TSharedPtr<SViewport> Viewport = 
				SNew( SViewport )
				.EnableGammaCorrection(false);

			Viewport->SetViewportInterface( AssetThumbnail.ToSharedRef() );
			AssetThumbnail->GetViewportRenderTargetTexture(); // Access the render texture to push it on the stack if it isnt already rendered

			InArgs._ThumbnailPool->OnThumbnailRendered().AddSP(this, &SAssetThumbnail::OnThumbnailRendered);
			InArgs._ThumbnailPool->OnThumbnailRenderFailed().AddSP(this, &SAssetThumbnail::OnThumbnailRenderFailed);

			if ( ShouldRender() && (!InArgs._AllowFadeIn || InArgs._ThumbnailPool->IsRendered(AssetThumbnail)) )
			{
				bHasRenderedThumbnail = true;
				ViewportFadeAnimation.JumpToEnd();
			}

			// The viewport for the rendered thumbnail, if it exists
			OverlayWidget->AddSlot()
			[
				SNew(SBorder)
				.Padding(0)
				.BorderImage(FEditorStyle::GetBrush("NoBrush"))
				.ColorAndOpacity(this, &SAssetThumbnail::GetViewportColorAndOpacity)
				.Visibility(this, &SAssetThumbnail::GetViewportVisibility)
				[
					Viewport.ToSharedRef()
				]
			];
		}

		OverlayWidget->AddSlot()
		.HAlign( HAlign_Center )
		.VAlign( VAlign_Top )
		.Padding(FMargin(2,2,2,2))
		[
			SNew(SBorder)
			.BorderImage( FEditorStyle::GetBrush( Style, ".HintBackground" ) )
			.BorderBackgroundColor( this, &SAssetThumbnail::GetHintBackgroundColor) //Adjust the opacity of the border itself
			.ColorAndOpacity( HintColorAndOpacity ) //adjusts the opacity of the contents of the border
			.Visibility( this, &SAssetThumbnail::GetHintTextVisibility )
			.Padding(0)
			[
				SAssignNew( HintTextBlock, STextBlock )
				.Text( GetLabelText() )
				.Font( GetHintTextFont() )
				.ColorAndOpacity( FEditorStyle::GetColor( Style, ".HintColorAndOpacity" ) )
				.ShadowOffset( FEditorStyle::GetVector( Style, ".HintShadowOffset" ) )
				.ShadowColorAndOpacity( FEditorStyle::GetColor( Style, ".HintShadowColorAndOpacity" ) )
				.WrapTextAt(this, &SAssetThumbnail::GetTextWrapWidth)
				.HighlightText( HighlightedText )
			]
		];

		// The asset color strip, only visible when the rendered viewport is
		OverlayWidget->AddSlot()
		.HAlign(HAlign_Fill)
		.VAlign(VAlign_Bottom)
		[
			SNew(SBorder)
			.BorderImage(FEditorStyle::GetBrush("WhiteBrush"))
			.BorderBackgroundColor(AssetColor)
			.Visibility(this, &SAssetThumbnail::GetViewportVisibility)
			.Padding(this, &SAssetThumbnail::GetAssetColorStripPadding)
		];

		ChildSlot
		[
			OverlayWidget
		];
	}
예제 #26
0
void    wxSpeedButton::Paint( wxDC &dc ) {
int         n;
int         w,h;
wxColour    cf;                     // foreground color
wxColour    cb;                     // background color
wxColour    cg;                     // gray text
wxColour    cy;                     // yellow
wxBrush     bb;                     // background brush
wxPen       pp;                     // line-drawing pen
wxBitmap    bmp;
wxString    s;
wxRect      rr;

// get size and layout

    if (! mCalcBusy) CalcLayout(false);

    w = mCurrentSize.GetWidth();
    h = mCurrentSize.GetHeight();

// get colors

    cf = GetForegroundColour();
    cb = GetBackgroundColour();
    cg = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT );
    cy = wxTheColourDatabase->Find(_("YELLOW"));

// use wxWidgets to draw the basic button

    rr.SetX(0);
    rr.SetY(0);
    rr.SetWidth(w);
    rr.SetHeight(h);

    n = 0;
    if (mMouseDown || mButtonDown) n = n | wxCONTROL_PRESSED;
    if (mButtonFocused) n = n | wxCONTROL_ISDEFAULT;

    wxRendererNative::Get().DrawPushButton(this, dc, rr, n);

// track mouse movements with mMouseOver using a dotted yellow line

    pp = *wxBLACK_PEN;
    pp.SetColour(cy);
//  pp.SetStyle(wxDOT);
    dc.SetPen(pp);
    if (mMouseOver) {
        n = 2;
        dc.DrawLine(  n,   n, w-n,   n);
        dc.DrawLine(w-n,   n, w-n, h-n);
        dc.DrawLine(w-n, h-n,   n, h-n);
        dc.DrawLine(  n, h-n,   n,   n);
    };

// select the bitmap to draw

    if      (! IsEnabled())             bmp = mGlyphDisabled;
    else if (mMouseDown || mButtonDown) bmp = mGlyphDown;
    else                                bmp = mGlyphUp;

    if (bmp.IsOk()) dc.DrawBitmap(bmp, mGlyphPos.x, mGlyphPos.y, true );

// the text label

    s = GetLabelText();
    if (! s.IsEmpty()) {
        dc.SetFont(GetFont());
        dc.SetBackgroundMode(wxTRANSPARENT);
        if (! IsEnabled()) dc.SetTextForeground(cg);
        else               dc.SetTextForeground(cf);
        dc.DrawText(s, mLabelPos.x, mLabelPos.y);
    };
}
예제 #27
0
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
{
    return GetLabelText(text);
}
예제 #28
0
wxSize wxCommandLinkButton::DoGetBestSize() const
{
    wxSize size;

    // account for the text part if we have it or if we don't have any image at
    // all (buttons initially created with empty label should still have a non
    // zero size)
    if ( ShowsLabel() || !m_imageData )
    {
        int flags = 0;
        if ( GetAuthNeeded() )
            flags |= wxMSWButton::Size_AuthNeeded;

        wxCommandLinkButton *thisButton =
            const_cast<wxCommandLinkButton *>(this);
        wxClientDC dc(thisButton);

        wxFont noteFont = dc.GetFont();

        // 4/3 is the relationship between main label and note font sizes.
        dc.SetFont(noteFont.Scaled(4.0f/3.0f));
        size = dc.GetMultiLineTextExtent(GetLabelText(GetMainLabel()));

        dc.SetFont(noteFont);
        wxSize noteSize = dc.GetMultiLineTextExtent(GetLabelText(GetNote()));

        if ( noteSize.x > size.x )
            size.x = noteSize.x;
        size.y += noteSize.y;

        size = wxMSWButton::GetFittingSize(thisButton,
                                           size,
                                           flags);

        // The height of a standard command link button is 25 and 35 DLUs for
        // single lines and two lines respectively. Width is not accounted for.
        int heightDef = GetNote().AfterFirst('\n').empty() ? 25 : 35;
        wxSize sizeDef = thisButton->ConvertDialogToPixels(wxSize(50,
                                                                  heightDef));

        if ( size.y < sizeDef.y )
            size.y = sizeDef.y;
    }

    if ( m_imageData )
    {
        AdjustForBitmapSize(size);
    }
    else
    {
        // The default image size is 16x16.
        size.x += 16;
        if ( size.y < 16 )
            size.y = 16;
    }

    size.x += MAINLABEL_NOTE_LEFT_MARGIN;
    size.y += MAINLABEL_TOP_MARGIN + NOTE_BOTTOM_MARGIN;
    if ( !GetNote().empty() )
        size.y += MAINLABEL_NOTE_MARGIN;

    CacheBestSize(size);

    return size;
}
예제 #29
0
	/** Constructs this widget with InArgs */
	void Construct( const FArguments& InArgs )
	{
		Style = InArgs._Style;
		HighlightedText = InArgs._HighlightedText;
		Label = InArgs._Label;
		HintColorAndOpacity = InArgs._HintColorAndOpacity;
		bAllowHintText = InArgs._AllowHintText;

		AssetThumbnail = InArgs._AssetThumbnail;
		bHasRenderedThumbnail = false;
		WidthLastFrame = 0;
		GenericThumbnailBorderPadding = 2.f;

		AssetThumbnail->OnAssetDataChanged().AddSP(this, &SAssetThumbnail::OnAssetDataChanged);

		const FAssetData& AssetData = AssetThumbnail->GetAssetData();

		UClass* Class = FindObject<UClass>(ANY_PACKAGE, *AssetData.AssetClass.ToString());
		FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>(TEXT("AssetTools"));
		TSharedPtr<IAssetTypeActions> AssetTypeActions;
		if ( Class != NULL )
		{
			AssetTypeActions = AssetToolsModule.Get().GetAssetTypeActionsForClass(Class).Pin();
		}

		AssetColor = FLinearColor::White;
		if( InArgs._AssetTypeColorOverride.IsSet() )
		{
			AssetColor = InArgs._AssetTypeColorOverride.GetValue();
		}
		else if ( AssetTypeActions.IsValid() )
		{
			AssetColor = AssetTypeActions->GetTypeColor();
		}

		TSharedRef<SOverlay> OverlayWidget = SNew(SOverlay);

		UpdateThumbnailClass(AssetData.AssetName, Class);

		ClassThumbnailBrushOverride = InArgs._ClassThumbnailBrushOverride;

		// The generic representation of the thumbnail, for use before the rendered version, if it exists
		OverlayWidget->AddSlot()
		[
			SNew(SBorder)
			.BorderImage(GetAssetBackgroundBrush())
			.BorderBackgroundColor(AssetColor.CopyWithNewOpacity(0.3f))
			.Padding(GenericThumbnailBorderPadding)
			.VAlign(VAlign_Center)
			.HAlign(HAlign_Center)
			.Visibility(this, &SAssetThumbnail::GetGenericThumbnailVisibility)
			[
				SNew(SOverlay)

				+SOverlay::Slot()
				[
					SAssignNew(GenericLabelTextBlock, STextBlock)
					.Text(GetLabelText())
					.Font(GetTextFont())
					.Justification(ETextJustify::Center)
					.ColorAndOpacity(FEditorStyle::GetColor(Style, ".ColorAndOpacity"))
					.ShadowOffset(FEditorStyle::GetVector(Style, ".ShadowOffset"))
					.ShadowColorAndOpacity( FEditorStyle::GetColor(Style, ".ShadowColorAndOpacity"))
					.HighlightText(HighlightedText)
				]

				+SOverlay::Slot()
				[
					SAssignNew(GenericThumbnailImage, SImage)
					.Image(this, &SAssetThumbnail::GetClassThumbnailBrush)
				]
			]
		];

		if ( InArgs._ThumbnailPool.IsValid() && !InArgs._ForceGenericThumbnail )
		{
			ViewportFadeAnimation = FCurveSequence();
			ViewportFadeCurve = ViewportFadeAnimation.AddCurve(0.f, 0.25f, ECurveEaseFunction::QuadOut);

			TSharedPtr<SViewport> Viewport = 
				SNew( SViewport )
				.EnableGammaCorrection(false);

			Viewport->SetViewportInterface( AssetThumbnail.ToSharedRef() );
			AssetThumbnail->GetViewportRenderTargetTexture(); // Access the render texture to push it on the stack if it isnt already rendered

			InArgs._ThumbnailPool->OnThumbnailRendered().AddSP(this, &SAssetThumbnail::OnThumbnailRendered);
			InArgs._ThumbnailPool->OnThumbnailRenderFailed().AddSP(this, &SAssetThumbnail::OnThumbnailRenderFailed);

			if ( ShouldRender() && (!InArgs._AllowFadeIn || InArgs._ThumbnailPool->IsRendered(AssetThumbnail)) )
			{
				bHasRenderedThumbnail = true;
				ViewportFadeAnimation.JumpToEnd();
			}

			// The viewport for the rendered thumbnail, if it exists
			OverlayWidget->AddSlot()
			[
				SAssignNew(RenderedThumbnailWidget, SBorder)
				.Padding(0)
				.BorderImage(FEditorStyle::GetBrush("NoBrush"))
				.ColorAndOpacity(this, &SAssetThumbnail::GetViewportColorAndOpacity)
				[
					Viewport.ToSharedRef()
				]
			];
		}

		if( ThumbnailClass.Get() && bIsClassType )
		{
			OverlayWidget->AddSlot()
			.VAlign(VAlign_Bottom)
			.HAlign(HAlign_Right)
			.Padding(TAttribute<FMargin>(this, &SAssetThumbnail::GetClassIconPadding))
			[
				SAssignNew(ClassIconWidget, SBorder)
				.BorderImage(FEditorStyle::GetNoBrush())
				[
					SNew(SImage)
					.Image(this, &SAssetThumbnail::GetClassIconBrush)
				]
			];
		}

		if( bAllowHintText )
		{
			OverlayWidget->AddSlot()
				.HAlign(HAlign_Center)
				.VAlign(VAlign_Top)
				.Padding(FMargin(2, 2, 2, 2))
				[
					SNew(SBorder)
					.BorderImage(FEditorStyle::GetBrush(Style, ".HintBackground"))
					.BorderBackgroundColor(this, &SAssetThumbnail::GetHintBackgroundColor) //Adjust the opacity of the border itself
					.ColorAndOpacity(HintColorAndOpacity) //adjusts the opacity of the contents of the border
					.Visibility(this, &SAssetThumbnail::GetHintTextVisibility)
					.Padding(0)
					[
						SAssignNew(HintTextBlock, STextBlock)
						.Text(GetLabelText())
						.Font(GetHintTextFont())
						.ColorAndOpacity(FEditorStyle::GetColor(Style, ".HintColorAndOpacity"))
						.ShadowOffset(FEditorStyle::GetVector(Style, ".HintShadowOffset"))
						.ShadowColorAndOpacity(FEditorStyle::GetColor(Style, ".HintShadowColorAndOpacity"))
						.HighlightText(HighlightedText)
					]
				];
		}

		// The asset color strip
		OverlayWidget->AddSlot()
		.HAlign(HAlign_Fill)
		.VAlign(VAlign_Bottom)
		[
			SAssignNew(AssetColorStripWidget, SBorder)
			.BorderImage(FEditorStyle::GetBrush("WhiteBrush"))
			.BorderBackgroundColor(AssetColor)
			.Padding(this, &SAssetThumbnail::GetAssetColorStripPadding)
		];

		if( InArgs._AllowAssetSpecificThumbnailOverlay && AssetTypeActions.IsValid() )
		{
			// Does the asset provide an additional thumbnail overlay?
			TSharedPtr<SWidget> AssetSpecificThumbnailOverlay = AssetTypeActions->GetThumbnailOverlay(AssetData);
			if( AssetSpecificThumbnailOverlay.IsValid() )
			{
				OverlayWidget->AddSlot()
				[
					AssetSpecificThumbnailOverlay.ToSharedRef()
				];
			}
		}

		ChildSlot
		[
			OverlayWidget
		];

		UpdateThumbnailVisibilities();

	}
예제 #30
0
파일: button.cpp 프로젝트: hgwells/tive
    return msStyle;
}

// ----------------------------------------------------------------------------
// size management including autosizing
// ----------------------------------------------------------------------------

wxSize wxButton::DoGetBestSize() const
{
    wxClientDC dc(wx_const_cast(wxButton *, this));
    dc.SetFont(GetFont());

    wxCoord wBtn,
            hBtn;
    dc.GetMultiLineTextExtent(GetLabelText(), &wBtn, &hBtn);

    // add a margin -- the button is wider than just its label
    wBtn += 3*GetCharWidth();
    hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hBtn);

    // all buttons have at least the standard size unless the user explicitly
    // wants them to be of smaller size and used wxBU_EXACTFIT style when
    // creating the button
    if ( !HasFlag(wxBU_EXACTFIT) )
    {
        wxSize sz = GetDefaultSize();
        if (wBtn > sz.x)
            sz.x = wBtn;
        if (hBtn > sz.y)
            sz.y = hBtn;