wxImagePanel Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
hackish
Knows some wx things
Knows some wx things
Posts: 41
Joined: Sat Aug 22, 2009 12:02 pm
Contact:

wxImagePanel

Post by hackish » Wed Nov 02, 2011 4:33 pm

I implemented a wxImagePanel to display and resize images stored as resources. Unfortunately I'm having problems because I don't want this image to be able to accept focus when the user hits tab.

Code: Select all

class wxImagePanel : public wxPanel
{
protected:
   // wxImage image;
    wxBitmap *bitmap;
    // if this is resized then we always own it otherwise it's null
    wxBitmap *resizedbmp;
    wxSize pnlsize;
    // do we delete the bitmap when we're done?
    bool bitmapOwned;
public:
    wxImagePanel(wxWindow* parent, wxBitmap *bmp, bool owned=false);
    virtual ~wxImagePanel();
    void SetBitmap(wxBitmap *bmp);
    void paintEvent(wxPaintEvent & evt);
    void paintNow();
    void OnSize(wxSizeEvent& event);
    void render(wxDC& dc);
    int GetHeight() { if (bitmap) return bitmap->GetHeight(); else return -1; }
    virtual bool AcceptsFocus () const { return false; }
    
    DECLARE_EVENT_TABLE()
};
As you can see I've overridden AcceptsFocus and coded it to return false.

When I hit tab SetFocus gets called. AcceptsFocus does not. Digging in the code there is a function called AcceptsFocusFromKeyboard() but it's not virtual so I can't see how to fix this...

Any ideas?

DerKleineNik
Knows some wx things
Knows some wx things
Posts: 29
Joined: Fri Sep 09, 2011 9:59 am

Re: wxImagePanel

Post by DerKleineNik » Thu Nov 03, 2011 7:14 am

Can you post some code where you use your wxImagePanel?
Have you maybe initialized it with style - wxTAB_TRAVERSAL - ?

hackish
Knows some wx things
Knows some wx things
Posts: 41
Joined: Sat Aug 22, 2009 12:02 pm
Contact:

Re: wxImagePanel

Post by hackish » Thu Nov 03, 2011 12:45 pm

I have managed to solve the problem. It turns out that in the Panel base class the methods were not virtual but when implemented in wxwindow they become vitrual so I was able to override them. Here is the code that shows it.

Code: Select all

class wxImagePanel : public wxPanel
{
protected:
   // wxImage image;
    wxBitmap *bitmap;
		// if this is resized then we always own it otherwise it's null
		wxBitmap *resizedbmp;
		wxSize pnlsize;
		// do we delete the bitmap when we're done?
		bool bitmapOwned;
public:
    wxImagePanel(wxWindow* parent, wxBitmap *bmp, bool owned=false);
		virtual ~wxImagePanel();
		void SetBitmap(wxBitmap *bmp);
    void paintEvent(wxPaintEvent & evt);
    void paintNow();
    void OnSize(wxSizeEvent& event);
    void render(wxDC& dc);
		int GetHeight() { if (bitmap) return bitmap->GetHeight(); else return -1; }
		virtual bool AcceptsFocus () const { return false; }
		virtual bool AcceptsFocusFromKeyboard() const { return false; }
		virtual bool AcceptsFocusRecursively() const { return false; }
    
    DECLARE_EVENT_TABLE()
};

Post Reply