Opened 5 years ago

Last modified 3 years ago

#17392 new defect

wxSearchCtrl not re-render the bitmaps when the background changes

Reported by: snong Owned by:
Priority: normal Milestone:
Component: wxMSW Version: dev-latest
Keywords: wxSearchCtrl Cc: jeff.hanna@…
Blocked By: Blocking:
Patch: no

Description (last modified by vadz)

wxSearchCtrl not re-render the bitmaps when call SetBackgroundColour() after wxSearchCtrl::Create()

Refer: [wxWidgets/src/generic/srchctlg.cpp]

@Line 811

bool wxSearchCtrl::SetBackgroundColour(const wxColour& colour)
{
    if ( !wxSearchCtrlBase::SetBackgroundColour(colour) )
        return false;

    // When the background changes, re-render the bitmaps so that the correct
    // colour shows in their "transparent" area.
    RecalcBitmaps();

    return true;
}

@Line 1128
void wxSearchCtrl::RecalcBitmaps()
{
    if ( !m_text )
    {
        return;
    }
    wxSize sizeText = m_text->GetBestSize();

    int bitmapHeight = sizeText.y - 4;
    int bitmapWidth  = sizeText.y * 20 / 14;

    if ( !m_searchBitmapUser )
    {
        if (
            !m_searchBitmap.IsOk() ||
            m_searchBitmap.GetHeight() != bitmapHeight ||
            m_searchBitmap.GetWidth() != bitmapWidth
            )
        {
            m_searchBitmap = RenderSearchBitmap(bitmapWidth,bitmapHeight,false);
            if ( !HasMenu() )
            {
                m_searchButton->SetBitmapLabel(m_searchBitmap);
            }
        }
        // else this bitmap was set by user, don't alter
    }

#if wxUSE_MENUS
    if ( !m_searchMenuBitmapUser )
    {
        if (
            !m_searchMenuBitmap.IsOk() ||
            m_searchMenuBitmap.GetHeight() != bitmapHeight ||
            m_searchMenuBitmap.GetWidth() != bitmapWidth
            )
        {
            m_searchMenuBitmap = RenderSearchBitmap(bitmapWidth,bitmapHeight,true);
            if ( m_menu )
            {
                m_searchButton->SetBitmapLabel(m_searchMenuBitmap);
            }
        }
        // else this bitmap was set by user, don't alter
    }
#endif // wxUSE_MENUS

    if ( !m_cancelBitmapUser )
    {
        if (
            !m_cancelBitmap.IsOk() ||
            m_cancelBitmap.GetHeight() != bitmapHeight ||
            m_cancelBitmap.GetWidth() != bitmapHeight
            )
        {
            m_cancelBitmap = RenderCancelBitmap(bitmapHeight,bitmapHeight); // square
            m_cancelButton->SetBitmapLabel(m_cancelBitmap);
        }
        // else this bitmap was set by user, don't alter
    }
}

Attachments (1)

wxSearchCtrl-bgr.png download (14.4 KB) - added by snong 5 years ago.
i fixed problem by add SetForegroundColour( m_text->GetForegroundColour() ); before SetBackgroundColour( m_text->GetBackgroundColour() ); in wxSearchCtrl::Create()

Download all attachments as: .zip

Change History (5)

comment:1 Changed 5 years ago by vadz

  • Milestone 3.1.0 deleted
  • Priority changed from normal to low

Please don't set milestone as explained in patch submission guidelines.

Please do use WikiFormatting to make your text more usable.

And, most importantly, please explain more clearly what the problem is and how can it be reproduced and, if you propose a solution to it (I am not even sure if you do or not), please submit a patch with it.

Thanks in advance!

comment:2 follow-up: Changed 5 years ago by vadz

  • Description modified (diff)

Just fixing formatting to avoid having all text in this ticket in italics.

Changed 5 years ago by snong

i fixed problem by add SetForegroundColour( m_text->GetForegroundColour() ); before SetBackgroundColour( m_text->GetBackgroundColour() ); in wxSearchCtrl::Create()

comment:3 in reply to: ↑ 2 Changed 5 years ago by snong

Replying to vadz:

Just fixing formatting to avoid having all text in this ticket in italics.

Thank you.

comment:4 Changed 3 years ago by jeff_hanna

  • Cc jeff.hanna@… added
  • Priority changed from low to normal

I was about to open a new ticket, but I believe my concern is the same as is described in this defect. Here is a bit more information and some sample Python code that demonstrates the error. This is using wx.Python 4.0.0b1. I did post this defect over on GitHub. Robin Dunn replied and said it would need to be addressed in wxWidgets and redirected me back over to this site.

The grey-circle-with-white-'x' bitmap used for the cancel button in wx.SearchCtrl does not have a transparent background. If the color of the text entry field in a wx.SearchCtrl is changed from white the bitmap no longer looks acceptable, showing as a white square with an image inside of it. Please make the background pixels of that image transparent.

# -*- coding: utf-8 -*-
"""
Sample Python/wxPython app to demonstrate that when the background color of a
SearchCtrl is set to anything other than White the cancel bitmap appears 
incorrect - with an opaque white background.
"""

import wx

class Test_Frame( wx.Frame ):
    def __init__( self ):
       super( Test_Frame, self ).__init__( None, title = 'wx.SearchCtrl Test' )
       main_sizer = wx.BoxSizer( wx.HORIZONTAL )

       search_ctrl = wx.SearchCtrl( self )
       search_ctrl.ShowCancelButton( True )
       search_ctrl.SetBackgroundColour( wx.GREEN )
       main_sizer.Add( search_ctrl, 1, wx.ALL | wx.EXPAND, 5 )

       self.SetSizer( main_sizer )
       self.Fit( )
       self.CenterOnScreen( )



app = wx.App( )
frame = Test_Frame( )
frame.Show( )
app.MainLoop( )
Note: See TracTickets for help on using tickets.