2003-05-30 17:08:31 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2005-10-27 12:01:45 -04:00
|
|
|
// Name: samples/vscroll/vstest.cpp
|
2004-05-25 07:20:37 -04:00
|
|
|
// Purpose: VScroll wxWidgets sample
|
2003-05-30 17:08:31 -04:00
|
|
|
// Author: Vadim Zeitlin
|
2007-04-07 21:58:16 -04:00
|
|
|
// Modified by: Brad Anderson
|
2003-05-30 17:08:31 -04:00
|
|
|
// Created: 04/01/98
|
2004-05-25 07:20:37 -04:00
|
|
|
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
|
2003-05-30 17:08:31 -04:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
|
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
2004-05-25 07:20:37 -04:00
|
|
|
// need because it includes almost all "standard" wxWidgets headers)
|
2003-05-30 17:08:31 -04:00
|
|
|
#ifndef WX_PRECOMP
|
2003-12-11 06:25:46 -05:00
|
|
|
#include "wx/wx.h"
|
2003-05-30 17:08:31 -04:00
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/frame.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// we need to include the headers not included from wx/wx.h explicitly anyhow
|
|
|
|
#include "wx/vscroll.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// resources
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2015-11-28 17:54:31 -05:00
|
|
|
// the application icon (under Windows it is in resources)
|
2012-03-03 19:28:58 -05:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2005-03-01 12:11:15 -05:00
|
|
|
#include "../sample.xpm"
|
2003-05-30 17:08:31 -04:00
|
|
|
#endif
|
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// definitions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define MAX_LINES 10000
|
|
|
|
|
2003-05-30 17:08:31 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define a new application type, each program should derive a class from wxApp
|
2007-04-07 21:58:16 -04:00
|
|
|
class VarScrollApp : public wxApp
|
2003-05-30 17:08:31 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// create our main window
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool OnInit() wxOVERRIDE;
|
2003-05-30 17:08:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Define a new frame type: this is going to be our main frame
|
2007-04-07 21:58:16 -04:00
|
|
|
class VarScrollFrame : public wxFrame
|
2003-05-30 17:08:31 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor
|
2007-04-07 21:58:16 -04:00
|
|
|
VarScrollFrame();
|
2003-05-30 17:08:31 -04:00
|
|
|
|
|
|
|
// event handlers (these functions should _not_ be virtual)
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
2007-04-07 21:58:16 -04:00
|
|
|
void OnModeVScroll(wxCommandEvent& event);
|
|
|
|
void OnModeHScroll(wxCommandEvent& event);
|
|
|
|
void OnModeHVScroll(wxCommandEvent& event);
|
2003-05-30 17:08:31 -04:00
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnSize(wxSizeEvent& event)
|
|
|
|
{
|
|
|
|
// show current size in the status bar
|
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
if ( m_frameStatusBar )
|
|
|
|
{
|
|
|
|
wxSize sz = GetClientSize();
|
2003-09-09 16:24:34 -04:00
|
|
|
SetStatusText(wxString::Format("%dx%d", sz.x, sz.y), 1);
|
2003-05-30 17:08:31 -04:00
|
|
|
}
|
|
|
|
#endif // wxUSE_STATUSBAR
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2007-04-07 21:58:16 -04:00
|
|
|
// either a wxVScrolledWindow or a wxHVScrolled window, depending on current mode
|
|
|
|
wxPanel *m_scrollWindow;
|
|
|
|
|
2004-05-25 07:20:37 -04:00
|
|
|
// any class wishing to process wxWidgets events must use this macro
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2003-05-30 17:08:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class VScrollWindow : public wxVScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
2004-05-31 06:43:22 -04:00
|
|
|
VScrollWindow(wxFrame *frame) : wxVScrolledWindow(frame, wxID_ANY)
|
2003-05-30 17:08:31 -04:00
|
|
|
{
|
|
|
|
m_frame = frame;
|
|
|
|
|
2007-04-08 09:55:36 -04:00
|
|
|
SetRowCount(MAX_LINES);
|
2007-04-07 21:58:16 -04:00
|
|
|
|
|
|
|
int i;
|
|
|
|
for ( i = 0; i < MAX_LINES; ++i )
|
|
|
|
m_heights[i] = rand()%25+16; // low: 16; high: 40
|
2003-05-30 17:08:31 -04:00
|
|
|
|
|
|
|
m_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnIdle(wxIdleEvent&)
|
|
|
|
{
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2003-05-30 17:08:31 -04:00
|
|
|
m_frame->SetStatusText(wxString::Format
|
|
|
|
(
|
2003-09-09 16:24:34 -04:00
|
|
|
"Page size = %d, pos = %d, max = %d",
|
2003-05-30 17:08:31 -04:00
|
|
|
GetScrollThumb(wxVERTICAL),
|
|
|
|
GetScrollPos(wxVERTICAL),
|
|
|
|
GetScrollRange(wxVERTICAL)
|
|
|
|
));
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2003-05-30 17:08:31 -04:00
|
|
|
m_changed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnPaint(wxPaintEvent&)
|
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
dc.SetPen(*wxBLACK_PEN);
|
2003-05-30 17:08:31 -04:00
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
const size_t lineFirst = GetVisibleBegin(),
|
|
|
|
lineLast = GetVisibleEnd();
|
2003-05-30 17:08:31 -04:00
|
|
|
|
|
|
|
const wxCoord hText = dc.GetCharHeight();
|
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
wxSize clientSize = GetClientSize();
|
|
|
|
|
2003-05-30 17:08:31 -04:00
|
|
|
wxCoord y = 0;
|
2007-04-07 21:58:16 -04:00
|
|
|
for ( size_t line = lineFirst; line < lineLast; line++ )
|
2003-05-30 17:08:31 -04:00
|
|
|
{
|
2007-04-07 21:58:16 -04:00
|
|
|
dc.DrawLine(0, y, clientSize.GetWidth(), y);
|
2003-05-30 17:08:31 -04:00
|
|
|
|
2007-04-08 09:55:36 -04:00
|
|
|
wxCoord hLine = OnGetRowHeight(line);
|
2003-05-30 17:08:31 -04:00
|
|
|
dc.DrawText(wxString::Format("Line %lu", (unsigned long)line),
|
2007-04-07 21:58:16 -04:00
|
|
|
2, y + (hLine - hText) / 2);
|
2003-05-30 17:08:31 -04:00
|
|
|
|
|
|
|
y += hLine;
|
|
|
|
dc.DrawLine(0, y, 1000, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnScroll(wxScrollWinEvent& event)
|
|
|
|
{
|
|
|
|
m_changed = true;
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
void OnMouse(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
if(event.LeftDown())
|
|
|
|
CaptureMouse();
|
|
|
|
else if(event.LeftUp())
|
|
|
|
ReleaseMouse();
|
|
|
|
event.Skip();
|
|
|
|
}
|
2003-05-30 17:08:31 -04:00
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxCoord OnGetRowHeight(size_t n) const wxOVERRIDE
|
2003-05-30 17:08:31 -04:00
|
|
|
{
|
2007-04-08 09:55:36 -04:00
|
|
|
wxASSERT( n < GetRowCount() );
|
2003-05-30 17:08:31 -04:00
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
return m_heights[n];
|
2003-05-30 17:08:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxFrame *m_frame;
|
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
int m_heights[MAX_LINES];
|
|
|
|
|
2003-05-30 17:08:31 -04:00
|
|
|
bool m_changed;
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2003-05-30 17:08:31 -04:00
|
|
|
};
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(VScrollWindow, wxVScrolledWindow)
|
2003-05-30 17:08:31 -04:00
|
|
|
EVT_IDLE(VScrollWindow::OnIdle)
|
|
|
|
EVT_PAINT(VScrollWindow::OnPaint)
|
|
|
|
EVT_SCROLLWIN(VScrollWindow::OnScroll)
|
2007-04-07 21:58:16 -04:00
|
|
|
EVT_MOUSE_EVENTS(VScrollWindow::OnMouse)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2007-04-07 21:58:16 -04:00
|
|
|
|
|
|
|
class HScrollWindow : public wxHScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HScrollWindow(wxFrame *frame) : wxHScrolledWindow(frame, wxID_ANY)
|
|
|
|
{
|
|
|
|
m_frame = frame;
|
|
|
|
|
|
|
|
SetColumnCount(MAX_LINES);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for ( i = 0; i < MAX_LINES; ++i )
|
|
|
|
m_heights[i] = rand()%25+16; // low: 15; high: 40
|
|
|
|
|
|
|
|
m_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnIdle(wxIdleEvent&)
|
|
|
|
{
|
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
m_frame->SetStatusText(wxString::Format
|
|
|
|
(
|
|
|
|
"Page size = %d, pos = %d, max = %d",
|
|
|
|
GetScrollThumb(wxVERTICAL),
|
|
|
|
GetScrollPos(wxVERTICAL),
|
|
|
|
GetScrollRange(wxVERTICAL)
|
|
|
|
));
|
|
|
|
#endif // wxUSE_STATUSBAR
|
|
|
|
m_changed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnPaint(wxPaintEvent&)
|
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
|
|
|
|
dc.SetPen(*wxBLACK_PEN);
|
|
|
|
|
|
|
|
const size_t lineFirst = GetVisibleBegin(),
|
|
|
|
lineLast = GetVisibleEnd();
|
|
|
|
|
|
|
|
const wxCoord hText = dc.GetCharHeight();
|
|
|
|
|
|
|
|
wxSize clientSize = GetClientSize();
|
|
|
|
|
|
|
|
wxCoord x = 0;
|
|
|
|
for ( size_t line = lineFirst; line < lineLast; line++ )
|
|
|
|
{
|
|
|
|
dc.DrawLine(x, 0, x, clientSize.GetHeight());
|
|
|
|
|
|
|
|
wxCoord wLine = OnGetColumnWidth(line);
|
|
|
|
dc.DrawRotatedText(wxString::Format("Line %lu", (unsigned long)line),
|
|
|
|
x + (wLine - hText) / 2, clientSize.GetHeight() - 5, 90);
|
|
|
|
|
|
|
|
x += wLine;
|
|
|
|
dc.DrawLine(x, 0, x, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnScroll(wxScrollWinEvent& event)
|
|
|
|
{
|
|
|
|
m_changed = true;
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnMouse(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
if(event.LeftDown())
|
|
|
|
CaptureMouse();
|
|
|
|
else if(event.LeftUp())
|
|
|
|
ReleaseMouse();
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxCoord OnGetColumnWidth(size_t n) const wxOVERRIDE
|
2007-04-07 21:58:16 -04:00
|
|
|
{
|
|
|
|
wxASSERT( n < GetColumnCount() );
|
|
|
|
|
|
|
|
return m_heights[n];
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxFrame *m_frame;
|
|
|
|
|
|
|
|
int m_heights[MAX_LINES];
|
|
|
|
|
|
|
|
bool m_changed;
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2007-04-07 21:58:16 -04:00
|
|
|
};
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(HScrollWindow, wxHScrolledWindow)
|
2007-04-07 21:58:16 -04:00
|
|
|
EVT_IDLE(HScrollWindow::OnIdle)
|
|
|
|
EVT_PAINT(HScrollWindow::OnPaint)
|
|
|
|
EVT_SCROLLWIN(HScrollWindow::OnScroll)
|
|
|
|
EVT_MOUSE_EVENTS(HScrollWindow::OnMouse)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2007-04-07 21:58:16 -04:00
|
|
|
|
|
|
|
class HVScrollWindow : public wxHVScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HVScrollWindow(wxFrame *frame) : wxHVScrolledWindow(frame, wxID_ANY)
|
|
|
|
{
|
|
|
|
m_frame = frame;
|
|
|
|
|
|
|
|
SetRowColumnCount(MAX_LINES, MAX_LINES);
|
2007-04-08 09:55:36 -04:00
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
int i;
|
|
|
|
for ( i = 0; i < MAX_LINES; ++i )
|
|
|
|
{
|
|
|
|
m_heights[i] = rand()%30+31; // low: 30; high: 60
|
|
|
|
m_widths[i] = rand()%30+61; // low: 60; high: 90
|
|
|
|
}
|
|
|
|
|
|
|
|
m_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnIdle(wxIdleEvent&)
|
|
|
|
{
|
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
m_frame->SetStatusText(wxString::Format
|
|
|
|
(
|
|
|
|
"Page size = %d rows %d columns; pos = row: %d, column: %d; max = %d rows, %d columns",
|
|
|
|
GetScrollThumb(wxVERTICAL),
|
|
|
|
GetScrollThumb(wxHORIZONTAL),
|
|
|
|
GetScrollPos(wxVERTICAL),
|
|
|
|
GetScrollPos(wxHORIZONTAL),
|
|
|
|
GetScrollRange(wxVERTICAL),
|
|
|
|
GetScrollRange(wxHORIZONTAL)
|
|
|
|
));
|
|
|
|
#endif // wxUSE_STATUSBAR
|
|
|
|
m_changed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnPaint(wxPaintEvent&)
|
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
|
|
|
|
dc.SetPen(*wxBLACK_PEN);
|
|
|
|
|
|
|
|
const size_t rowFirst = GetVisibleRowsBegin(),
|
|
|
|
rowLast = GetVisibleRowsEnd();
|
|
|
|
const size_t columnFirst = GetVisibleColumnsBegin(),
|
|
|
|
columnLast = GetVisibleColumnsEnd();
|
2007-04-08 09:55:36 -04:00
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
const wxCoord hText = dc.GetCharHeight();
|
|
|
|
|
|
|
|
wxSize clientSize = GetClientSize();
|
|
|
|
|
|
|
|
wxCoord y = 0;
|
|
|
|
for ( size_t row = rowFirst; row < rowLast; row++ )
|
|
|
|
{
|
|
|
|
wxCoord rowHeight = OnGetRowHeight(row);
|
|
|
|
dc.DrawLine(0, y, clientSize.GetWidth(), y);
|
|
|
|
|
2019-04-05 13:44:02 -04:00
|
|
|
wxCoord x = 0;
|
2007-04-07 21:58:16 -04:00
|
|
|
for ( size_t col = columnFirst; col < columnLast; col++ )
|
|
|
|
{
|
|
|
|
wxCoord colWidth = OnGetColumnWidth(col);
|
|
|
|
|
|
|
|
if ( row == rowFirst )
|
|
|
|
dc.DrawLine(x, 0, x, clientSize.GetHeight());
|
|
|
|
|
|
|
|
dc.DrawText(wxString::Format("Row %lu", (unsigned long)row),
|
|
|
|
x + 2, y + rowHeight / 2 - hText);
|
|
|
|
dc.DrawText(wxString::Format("Col %lu", (unsigned long)col),
|
|
|
|
x + 2, y + rowHeight / 2);
|
2007-04-08 09:55:36 -04:00
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
x += colWidth;
|
|
|
|
if ( row == rowFirst)
|
|
|
|
dc.DrawLine(x, 0, x, clientSize.GetHeight());
|
|
|
|
}
|
2007-04-08 09:55:36 -04:00
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
y += rowHeight;
|
|
|
|
dc.DrawLine(0, y, clientSize.GetWidth(), y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnScroll(wxScrollWinEvent& event)
|
|
|
|
{
|
|
|
|
m_changed = true;
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnMouse(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
if(event.LeftDown())
|
|
|
|
CaptureMouse();
|
|
|
|
else if(event.LeftUp())
|
|
|
|
ReleaseMouse();
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxCoord OnGetRowHeight(size_t n) const wxOVERRIDE
|
2007-04-07 21:58:16 -04:00
|
|
|
{
|
|
|
|
wxASSERT( n < GetRowCount() );
|
|
|
|
|
|
|
|
return m_heights[n];
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxCoord OnGetColumnWidth(size_t n) const wxOVERRIDE
|
2007-04-07 21:58:16 -04:00
|
|
|
{
|
|
|
|
wxASSERT( n < GetColumnCount() );
|
|
|
|
|
|
|
|
return m_widths[n];
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxFrame *m_frame;
|
|
|
|
|
|
|
|
int m_heights[MAX_LINES];
|
|
|
|
int m_widths[MAX_LINES];
|
|
|
|
|
|
|
|
bool m_changed;
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2007-04-07 21:58:16 -04:00
|
|
|
};
|
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(HVScrollWindow, wxHVScrolledWindow)
|
2007-04-07 21:58:16 -04:00
|
|
|
EVT_IDLE(HVScrollWindow::OnIdle)
|
|
|
|
EVT_PAINT(HVScrollWindow::OnPaint)
|
|
|
|
EVT_SCROLLWIN(HVScrollWindow::OnScroll)
|
|
|
|
EVT_MOUSE_EVENTS(HVScrollWindow::OnMouse)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2003-05-30 17:08:31 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// IDs for the controls and the menu commands
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// menu items
|
2005-06-02 08:04:48 -04:00
|
|
|
VScroll_Quit = wxID_EXIT,
|
2003-05-30 17:08:31 -04:00
|
|
|
|
|
|
|
// it is important for the id corresponding to the "About" command to have
|
|
|
|
// this standard value as otherwise it won't be handled properly under Mac
|
|
|
|
// (where it is special and put into the "Apple" menu)
|
2007-04-07 21:58:16 -04:00
|
|
|
VScroll_About = wxID_ABOUT,
|
|
|
|
|
|
|
|
VScroll_VScrollMode = wxID_HIGHEST + 1,
|
|
|
|
VScroll_HScrollMode,
|
|
|
|
VScroll_HVScrollMode
|
2003-05-30 17:08:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-05-25 07:20:37 -04:00
|
|
|
// event tables and other macros for wxWidgets
|
2003-05-30 17:08:31 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-05-25 07:20:37 -04:00
|
|
|
// the event tables connect the wxWidgets events with the functions (event
|
2003-05-30 17:08:31 -04:00
|
|
|
// handlers) which process them. It can be also done at run-time, but for the
|
|
|
|
// simple menu events like this the static method is much simpler.
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(VarScrollFrame, wxFrame)
|
2007-04-07 21:58:16 -04:00
|
|
|
EVT_MENU(VScroll_Quit, VarScrollFrame::OnQuit)
|
|
|
|
EVT_MENU(VScroll_VScrollMode, VarScrollFrame::OnModeVScroll)
|
|
|
|
EVT_MENU(VScroll_HScrollMode, VarScrollFrame::OnModeHScroll)
|
|
|
|
EVT_MENU(VScroll_HVScrollMode, VarScrollFrame::OnModeHVScroll)
|
|
|
|
EVT_MENU(VScroll_About, VarScrollFrame::OnAbout)
|
|
|
|
EVT_SIZE(VarScrollFrame::OnSize)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2003-05-30 17:08:31 -04:00
|
|
|
|
2004-05-25 07:20:37 -04:00
|
|
|
// Create a new application object: this macro will allow wxWidgets to create
|
2003-05-30 17:08:31 -04:00
|
|
|
// the application object during program execution (it's better than using a
|
|
|
|
// static object for many reasons) and also declares the accessor function
|
2007-04-07 21:58:16 -04:00
|
|
|
// wxGetApp() which will return the reference of the right type (i.e. VarScrollApp and
|
2003-05-30 17:08:31 -04:00
|
|
|
// not wxApp)
|
2015-04-23 07:49:01 -04:00
|
|
|
wxIMPLEMENT_APP(VarScrollApp);
|
2003-05-30 17:08:31 -04:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the application class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 'Main program' equivalent: the program execution "starts" here
|
2007-04-07 21:58:16 -04:00
|
|
|
bool VarScrollApp::OnInit()
|
2003-05-30 17:08:31 -04:00
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2003-05-30 17:08:31 -04:00
|
|
|
// create the main application window
|
2007-04-07 21:58:16 -04:00
|
|
|
VarScrollFrame *frame = new VarScrollFrame;
|
2003-05-30 17:08:31 -04:00
|
|
|
|
|
|
|
// and show it (the frames, unlike simple controls, are not shown when
|
|
|
|
// created initially)
|
2004-05-31 06:43:22 -04:00
|
|
|
frame->Show(true);
|
2003-05-30 17:08:31 -04:00
|
|
|
|
|
|
|
// ok
|
2004-05-31 06:43:22 -04:00
|
|
|
return true;
|
2003-05-30 17:08:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// main frame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// frame constructor
|
2007-04-07 21:58:16 -04:00
|
|
|
VarScrollFrame::VarScrollFrame()
|
|
|
|
: wxFrame(NULL,
|
|
|
|
wxID_ANY,
|
|
|
|
"VScroll wxWidgets Sample",
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxSize(400, 350)),
|
|
|
|
m_scrollWindow(NULL)
|
2003-05-30 17:08:31 -04:00
|
|
|
{
|
|
|
|
// set the frame icon
|
2005-03-01 12:11:15 -05:00
|
|
|
SetIcon(wxICON(sample));
|
2003-05-30 17:08:31 -04:00
|
|
|
|
|
|
|
#if wxUSE_MENUS
|
|
|
|
// create a menu bar
|
|
|
|
wxMenu *menuFile = new wxMenu;
|
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
wxMenu *menuMode = new wxMenu;
|
|
|
|
|
2003-05-30 17:08:31 -04:00
|
|
|
// the "About" item should be in the help menu
|
|
|
|
wxMenu *menuHelp = new wxMenu;
|
2012-01-20 11:51:09 -05:00
|
|
|
menuHelp->Append(VScroll_About, "&About\tF1", "Show about dialog");
|
2003-05-30 17:08:31 -04:00
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
#ifdef wxHAS_RADIO_MENU_ITEMS
|
|
|
|
menuMode->AppendRadioItem(VScroll_VScrollMode, "&Vertical\tAlt-V",
|
|
|
|
"Vertical scrolling only");
|
|
|
|
menuMode->AppendRadioItem(VScroll_HScrollMode, "&Horizontal\tAlt-H",
|
|
|
|
"Horizontal scrolling only");
|
|
|
|
menuMode->AppendRadioItem(VScroll_HVScrollMode,
|
|
|
|
"Hori&zontal/Vertical\tAlt-Z",
|
|
|
|
"Horizontal and vertical scrolling");
|
|
|
|
menuMode->Check(VScroll_VScrollMode, true);
|
|
|
|
#else
|
|
|
|
menuMode->Append(VScroll_VScrollMode, "&Vertical\tAlt-V",
|
|
|
|
"Vertical scrolling only");
|
|
|
|
menuMode->Append(VScroll_HScrollMode, "&Horizontal\tAlt-H",
|
|
|
|
"Horizontal scrolling only");
|
|
|
|
menuMode->Append(VScroll_HVScrollMode, "Hori&zontal/Vertical\tAlt-Z",
|
|
|
|
"Horizontal and vertical scrolling");
|
|
|
|
#endif
|
|
|
|
|
2003-05-30 17:08:31 -04:00
|
|
|
menuFile->Append(VScroll_Quit, "E&xit\tAlt-X", "Quit this program");
|
|
|
|
|
|
|
|
// now append the freshly created menu to the menu bar...
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
menuBar->Append(menuFile, "&File");
|
2007-04-07 21:58:16 -04:00
|
|
|
menuBar->Append(menuMode, "&Mode");
|
2003-05-30 17:08:31 -04:00
|
|
|
menuBar->Append(menuHelp, "&Help");
|
|
|
|
|
|
|
|
// ... and attach this menu bar to the frame
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
#endif // wxUSE_MENUS
|
|
|
|
|
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
// create a status bar just for fun (by default with 1 pane only)
|
|
|
|
CreateStatusBar(2);
|
2004-05-25 07:20:37 -04:00
|
|
|
SetStatusText("Welcome to wxWidgets!");
|
2007-04-07 21:58:16 -04:00
|
|
|
int widths[2];
|
|
|
|
widths[0] = -1;
|
|
|
|
widths[1] = 100;
|
|
|
|
SetStatusWidths(2, widths);
|
2003-05-30 17:08:31 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
|
|
|
|
|
|
|
// create our one and only child -- it will take our entire client area
|
2007-04-07 21:58:16 -04:00
|
|
|
if ( menuMode->IsChecked(VScroll_VScrollMode) )
|
|
|
|
m_scrollWindow = new VScrollWindow(this);
|
|
|
|
else if ( menuMode->IsChecked(VScroll_HScrollMode) )
|
|
|
|
m_scrollWindow = new HScrollWindow(this);
|
|
|
|
else
|
|
|
|
m_scrollWindow = new HVScrollWindow(this);
|
2003-05-30 17:08:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event handlers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
void VarScrollFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
2003-05-30 17:08:31 -04:00
|
|
|
{
|
2004-05-31 06:43:22 -04:00
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
2003-05-30 17:08:31 -04:00
|
|
|
}
|
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
void VarScrollFrame::OnModeVScroll(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
if ( m_scrollWindow )
|
|
|
|
m_scrollWindow->Destroy();
|
2007-04-08 09:55:36 -04:00
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
m_scrollWindow = new VScrollWindow(this);
|
|
|
|
SendSizeEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarScrollFrame::OnModeHScroll(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
if ( m_scrollWindow )
|
|
|
|
m_scrollWindow->Destroy();
|
2007-04-08 09:55:36 -04:00
|
|
|
|
2007-04-07 21:58:16 -04:00
|
|
|
m_scrollWindow = new HScrollWindow(this);
|
|
|
|
SendSizeEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarScrollFrame::OnModeHVScroll(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
if ( m_scrollWindow )
|
|
|
|
m_scrollWindow->Destroy();
|
|
|
|
|
|
|
|
m_scrollWindow = new HVScrollWindow(this);
|
|
|
|
SendSizeEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarScrollFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
2003-05-30 17:08:31 -04:00
|
|
|
{
|
|
|
|
wxMessageBox("VScroll shows how to implement scrolling with\n"
|
2007-04-07 21:58:16 -04:00
|
|
|
"variable line widths and heights.\n"
|
2004-10-02 08:36:02 -04:00
|
|
|
"(c) 2003 Vadim Zeitlin",
|
2003-05-30 17:08:31 -04:00
|
|
|
"About VScroll",
|
|
|
|
wxOK | wxICON_INFORMATION,
|
|
|
|
this);
|
|
|
|
}
|