Page 1 of 1

wxImagePanel

Posted: Wed Nov 02, 2011 4:33 pm
by hackish
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?

Re: wxImagePanel

Posted: Thu Nov 03, 2011 7:14 am
by DerKleineNik
Can you post some code where you use your wxImagePanel?
Have you maybe initialized it with style - wxTAB_TRAVERSAL - ?

Re: wxImagePanel

Posted: Thu Nov 03, 2011 12:45 pm
by hackish
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()
};