Page 1 of 1

SubScroll, difference on scrolling

Posted: Thu Jan 29, 2009 6:30 am
by kea_
Hello together,

I'm try to write a component like a grid. But width my own design an less functions. So I created a class column, table and a sheet.
In the sheet I create the column and table. If I scroll the table the column will be repainted (scrolled) very well.
But if I resize the sheet the grid has a difference to the column. How can I fix this?

This is the source:

Code: Select all

#ifndef CO_WORKOUTSHEET_H
#define CO_WORKOUTSHEET_H


#include <wx/panel.h>
#include <wx/scrolwin.h>
#include <wx/event.h>
#include <wx/sizer.h>
#include <wx/dcbuffer.h>


class coWorkoutColumn : public wxScrolledWindow
{
    DECLARE_EVENT_TABLE()

	public:
		// FUNCTIONS
		coWorkoutColumn(wxWindow *wnd, wxWindowID id);
		~coWorkoutColumn();
		void ScrollColumn(int x);

		// PARAMETERS

	protected:
		// FUNCTIONS
		// PARAMETERS

	private:
		// FUNCTIONS
		// PARAMETERS
		int iScrollX;

		// EVENTS
        void OnEraseBackground(wxEraseEvent& event);
        void OnPaint(wxPaintEvent &event);

	enum{
		ID_DUMMY_VALUE_
	};
};


class coWorkoutTable : public wxScrolledWindow
{
    DECLARE_EVENT_TABLE()

	public:
		// FUNCTIONS
		coWorkoutTable(wxWindow *wnd, wxWindowID id, coWorkoutColumn *workoutcolumn);
		~coWorkoutTable();

		// PARAMETERS

	protected:
		// FUNCTIONS
		// PARAMETERS

	private:
		// FUNCTIONS
		// PARAMETERS
		coWorkoutColumn *m_workoutcolumn;
		wxString m_sText;

		// EVENTS
        void OnEraseBackground(wxEraseEvent& event);
        void OnPaint(wxPaintEvent &event);
        void OnScroll(wxScrollWinEvent &event);
        void OnSize(wxSizeEvent& event);

	enum{
		ID_DUMMY_VALUE_
	};
};


class coWorkoutSheet : public wxScrolledWindow
{
	public:
		// FUNCTIONS
		coWorkoutSheet(wxWindow *wnd, wxWindowID id);
		~coWorkoutSheet();

		// PARAMETERS

	protected:
		// FUNCTIONS
		// PARAMETERS

	private:
		// FUNCTIONS
		// PARAMETERS
		coWorkoutColumn *m_workoutcolumn;
		coWorkoutTable *m_workouttable;

		// EVENTS
		void OnSize(wxSizeEvent& event);

	enum{
		ID_DUMMY_VALUE_
	};
};


#endif // CO_WORKOUTSHEET_H

Code: Select all

#include "coWorkoutSheet.h"

// ** coWorkoutColumn ********************************************************************
BEGIN_EVENT_TABLE(coWorkoutColumn, wxScrolledWindow)
    EVT_PAINT(coWorkoutColumn::OnPaint)
    EVT_ERASE_BACKGROUND(coWorkoutColumn::OnEraseBackground)
END_EVENT_TABLE()


coWorkoutColumn::coWorkoutColumn(wxWindow *wnd, wxWindowID id)
               : wxScrolledWindow(wnd, id){
}


coWorkoutColumn::~coWorkoutColumn(){}


void coWorkoutColumn::ScrollColumn(int x){
    iScrollX = -x;
    Refresh();
}


// **  E V E N T S  ***
void coWorkoutColumn::OnEraseBackground(wxEraseEvent& event){}


void coWorkoutColumn::OnPaint(wxPaintEvent &event){
    wxBufferedPaintDC dc(this);
    PrepareDC(dc);

    dc.SetFont(GetFont());
    dc.SetBackground(wxBrush(wxColour("#efefef"), wxSOLID));
    dc.Clear();

    dc.SetDeviceOrigin(iScrollX, 0);

    wxString s;
    int x = 0;
    for(int i = 0; i < 14; i++){
        s.Printf("col.%d", i);
        dc.DrawText(s, x, 1);
        dc.DrawLine(x-2, 0, x-2, 20);
        x += 40;
    }
}


// ** coWorkoutTable **********************************************************************
BEGIN_EVENT_TABLE(coWorkoutTable, wxScrolledWindow)
    EVT_PAINT(coWorkoutTable::OnPaint)
    EVT_ERASE_BACKGROUND(coWorkoutTable::OnEraseBackground)
    EVT_SCROLLWIN(coWorkoutTable::OnScroll)
    EVT_SIZE(coWorkoutTable::OnSize)
END_EVENT_TABLE()


coWorkoutTable::coWorkoutTable(wxWindow *wnd, wxWindowID id, coWorkoutColumn *workoutcolumn)
              : wxScrolledWindow(wnd, id){
    SetScrollRate(1, 1);
    m_workoutcolumn = workoutcolumn;
}


coWorkoutTable::~coWorkoutTable(){}


// **  E V E N T S  ***
void coWorkoutTable::OnEraseBackground(wxEraseEvent& event){}


void coWorkoutTable::OnPaint(wxPaintEvent &event){
    wxBufferedPaintDC dc(this);
    PrepareDC(dc);

    dc.SetFont(GetFont());
    dc.SetBackground(wxBrush(wxColour("#ffffff"), wxSOLID));
    dc.Clear();


    int x = 0;
    for(int i = 0; i < 14; i++){
        m_sText.Printf("cel.%d", i);
        dc.DrawText(m_sText, x, 1);
        dc.DrawLine(x-2, 0, x-2, 20);
        x += 40;
    }

    SetVirtualSize(x, 0);
}


void coWorkoutTable::OnScroll(wxScrollWinEvent &event){
    int x, y;
    GetViewStart(&x, &y);

    if(wxHORIZONTAL == event.GetOrientation()){
        Scroll(event.GetPosition(), y);
        m_workoutcolumn->ScrollColumn(event.GetPosition());
    }else{
        Scroll(x, event.GetPosition());
    }
}


void coWorkoutTable::OnSize(wxSizeEvent& event){
    int x, y;
    GetViewStart(&x, &y);
    m_workoutcolumn->ScrollColumn(x);
}


// ** coWorkoutSheet **********************************************************************
coWorkoutSheet::coWorkoutSheet(wxWindow *wnd, wxWindowID id)
              : wxScrolledWindow(wnd, id){
    wxBoxSizer *szr = new wxBoxSizer(wxVERTICAL);
    SetSizer(szr);

    m_workoutcolumn = new coWorkoutColumn(this, 1);
	m_workouttable = new coWorkoutTable(this, 2, m_workoutcolumn);

    szr->Add(m_workoutcolumn, 0, wxALL | wxEXPAND, 0);
    szr->Add(m_workouttable, 1, wxALL | wxEXPAND, 0);
}


coWorkoutSheet::~coWorkoutSheet(){
    delete m_workoutcolumn;
    delete m_workouttable;
}

Has any body an idea?
Greetings and thanks kea_[/code]

Posted: Thu Jan 29, 2009 1:47 pm
by kea_
Problem solved.