Custom control always paints background in Linux only

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Tony0945
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 21, 2009 4:02 pm

Custom control always paints background in Linux only

Post by Tony0945 » Tue Nov 05, 2013 12:10 pm

My custom control paints a grey background on wxGTK 2.9.3 but has no background (correct) on wxMSW 2.9.3. It worked the same on both platforms in 2.8.4, but the application is now using other features that are not available in 2.8. Code for a test app demonstrating the problem is attached as test.zip as are screen shots in Windows (XP) and Linux (Gentoo running Gnome2) both on a desktop PC. Here is the custom control rendering code:

Code: Select all

#include <wx/event.h>
#include <wx/process.h>
#include "MyControl.h"
#include "TestApp.h"
#include <wx/dnd.h>
#include <wx/sizer.h>

#include <wx/app.h>

DECLARE_APP(TestFrmApp);

                        
BEGIN_EVENT_TABLE(MyControl,wxPanel)
    EVT_LEFT_DOWN(MyControl::LeftDown)
    EVT_LEFT_UP(MyControl::LeftUp)
    EVT_MOTION(MyControl::Moving)
    EVT_MOUSE_CAPTURE_LOST(MyControl::MouseCaptureLost)
 
// catch paint events
    EVT_PAINT(MyControl::paintEvent)
 
END_EVENT_TABLE()

MyControl::MyControl(wxWindow * parent,wxBitmap *map, wxString &Label, wxPoint pos,const wxSize& size) : wxPanel(parent,wxID_ANY,pos,size)
{
    mymap = *map;  // make a local copy

    SetForegroundColour(*wxWHITE);

    SetSize(mymap.GetWidth()+50,mymap.GetHeight()+50);

    paintNow();
       
	Move(pos);

//    SetOwnBackgroundColour(*wxLIGHT_GREY);
    
    dragging = false;
    LabelText = Label;
}

MyControl::~MyControl()
{
}

void MyControl::paintEvent(wxPaintEvent & evt)
{   
    wxPaintDC dc(this);
    render(dc);
}

void MyControl::paintNow()
{    
    wxClientDC dc(this);
    render(dc);
}

void MyControl::render(wxDC& dc)
{
    dc.DrawBitmap( mymap, 0, 0, true );
    dc.DrawText(LabelText,0,mymap.GetHeight());
}


void MyControl::LeftDown(wxMouseEvent& event)
{ 
    CaptureMouse();
    dragging = true;
    Xpos = event.GetX();
    Ypos = event.GetY();
}

void MyControl::Moving(wxMouseEvent& event)
{
    if (dragging)
    {
        wxPoint mouseOnScreen = wxGetMousePosition();
        int newx = mouseOnScreen.x - Xpos;
        int newy = mouseOnScreen.y - Ypos;
        this->Move( this->GetParent()->ScreenToClient( wxPoint(newx, newy) ));
    } 
}

void MyControl::LeftUp(wxMouseEvent& event)
{
    // TODO Need code to prevent moving on top of another MyControl
    ReleaseMouse();
    dragging=false;
    Hide();
    Show();
}

void MyControl::MouseCaptureLost(wxMouseCaptureLostEvent& event)
{
    // don't call event.skip
    wxMessageBox("Lost Mouse");
}

Attachments
Windows snapshot.jpg
Windows snapshot
Windows snapshot.jpg (10.29 KiB) Viewed 1478 times
Linux snapshot.jpg
Linux snapshot
Linux snapshot.jpg (15.59 KiB) Viewed 1478 times
test.zip
complete test app without executable
(77.83 KiB) Downloaded 55 times

User avatar
doublemax
Moderator
Moderator
Posts: 15069
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Custom control always paints background in Linux only

Post by doublemax » Tue Nov 05, 2013 2:03 pm

Try adding this to the ctor of the control:

Code: Select all

SetBackgroundStyle( wxBG_STYLE_PAINT );
Use the source, Luke!

Tony0945
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 21, 2009 4:02 pm

Re: Custom control always paints background in Linux only

Post by Tony0945 » Tue Nov 05, 2013 5:15 pm

Unfortunately, that rips a hole through not only the Custom Control but through the underlaying Frame into the application beneath. I want the frame's background to show, but not the Panel's. i.e. the panel should be transparent. I tried calling SetBackgroundColour(wx*TRANSPARENT) but that had no effect on wxGTK.

User avatar
doublemax
Moderator
Moderator
Posts: 15069
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Custom control always paints background in Linux only

Post by doublemax » Tue Nov 05, 2013 5:28 pm

As i don't work under Linux, i can't help any further. If you don't find a solution, try asking on the mailing list.
Use the source, Luke!

Post Reply