1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2000-03-14 14:30:04 -05:00
|
|
|
// Name: splitter.cpp
|
1998-05-20 10:01:55 -04:00
|
|
|
// Purpose: wxSplitterWindow sample
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart and Markus Holzem
|
1998-10-23 09:15:15 -04:00
|
|
|
// Licence: wxWindows license
|
1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
2002-01-07 13:33:30 -05:00
|
|
|
#pragma hdrstop
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
2002-01-07 13:33:30 -05:00
|
|
|
#include "wx/wx.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/splitter.h"
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// ID for the menu commands
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SPLIT_QUIT,
|
|
|
|
SPLIT_HORIZONTAL,
|
|
|
|
SPLIT_VERTICAL,
|
|
|
|
SPLIT_UNSPLIT,
|
2002-02-22 10:09:45 -05:00
|
|
|
SPLIT_LIVE,
|
2002-01-07 13:33:30 -05:00
|
|
|
SPLIT_SETMINSIZE
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// our classes
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
class MyApp: public wxApp
|
|
|
|
{
|
|
|
|
public:
|
2002-01-07 13:33:30 -05:00
|
|
|
bool OnInit();
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
class MyFrame: public wxFrame
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
|
|
|
public:
|
2002-01-07 13:33:30 -05:00
|
|
|
MyFrame();
|
|
|
|
virtual ~MyFrame();
|
1998-10-23 09:15:15 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// Menu commands
|
|
|
|
void SplitHorizontal(wxCommandEvent& event);
|
|
|
|
void SplitVertical(wxCommandEvent& event);
|
|
|
|
void Unsplit(wxCommandEvent& event);
|
2002-02-22 10:09:45 -05:00
|
|
|
void ToggleLive(wxCommandEvent& event);
|
2002-01-07 13:33:30 -05:00
|
|
|
void SetMinSize(wxCommandEvent& event);
|
2002-02-22 10:09:45 -05:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
void Quit(wxCommandEvent& event);
|
2001-06-14 13:44:24 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// Menu command update functions
|
|
|
|
void UpdateUIHorizontal(wxUpdateUIEvent& event);
|
|
|
|
void UpdateUIVertical(wxUpdateUIEvent& event);
|
|
|
|
void UpdateUIUnsplit(wxUpdateUIEvent& event);
|
2001-06-14 13:44:24 -04:00
|
|
|
|
1998-10-23 09:15:15 -04:00
|
|
|
private:
|
2002-01-07 13:33:30 -05:00
|
|
|
wxScrolledWindow *m_left, *m_right;
|
|
|
|
|
|
|
|
wxSplitterWindow* m_splitter;
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
1998-10-23 09:15:15 -04:00
|
|
|
};
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
class MySplitterWindow : public wxSplitterWindow
|
1998-10-23 09:15:15 -04:00
|
|
|
{
|
|
|
|
public:
|
2002-01-07 13:33:30 -05:00
|
|
|
MySplitterWindow(wxFrame *parent);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// event handlers
|
|
|
|
void OnPositionChanged(wxSplitterEvent& event);
|
|
|
|
void OnPositionChanging(wxSplitterEvent& event);
|
|
|
|
void OnDClick(wxSplitterEvent& event);
|
|
|
|
void OnUnsplit(wxSplitterEvent& event);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
private:
|
2002-01-07 13:33:30 -05:00
|
|
|
wxFrame *m_frame;
|
1998-10-23 09:15:15 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class MyCanvas: public wxScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
2002-01-07 13:33:30 -05:00
|
|
|
MyCanvas(wxWindow* parent);
|
2001-06-11 16:03:00 -04:00
|
|
|
virtual ~MyCanvas();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
virtual void OnDraw(wxDC& dc);
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-10-21 17:43:20 -04:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
bool MyApp::OnInit()
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
// create and show the main frame
|
|
|
|
MyFrame* frame = new MyFrame;
|
2001-06-14 13:44:24 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
frame->Show(TRUE);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
return TRUE;
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
2002-01-07 13:33:30 -05:00
|
|
|
EVT_MENU(SPLIT_VERTICAL, MyFrame::SplitVertical)
|
|
|
|
EVT_MENU(SPLIT_HORIZONTAL, MyFrame::SplitHorizontal)
|
|
|
|
EVT_MENU(SPLIT_UNSPLIT, MyFrame::Unsplit)
|
2002-02-22 10:09:45 -05:00
|
|
|
EVT_MENU(SPLIT_LIVE, MyFrame::ToggleLive)
|
2002-01-07 13:33:30 -05:00
|
|
|
EVT_MENU(SPLIT_SETMINSIZE, MyFrame::SetMinSize)
|
|
|
|
|
2002-02-22 10:09:45 -05:00
|
|
|
EVT_MENU(SPLIT_QUIT, MyFrame::Quit)
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
EVT_UPDATE_UI(SPLIT_VERTICAL, MyFrame::UpdateUIVertical)
|
|
|
|
EVT_UPDATE_UI(SPLIT_HORIZONTAL, MyFrame::UpdateUIHorizontal)
|
|
|
|
EVT_UPDATE_UI(SPLIT_UNSPLIT, MyFrame::UpdateUIUnsplit)
|
1998-05-20 10:01:55 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// My frame constructor
|
2002-01-07 13:33:30 -05:00
|
|
|
MyFrame::MyFrame()
|
|
|
|
: wxFrame(NULL, -1, _T("wxSplitterWindow sample"),
|
|
|
|
wxDefaultPosition, wxSize(420, 300),
|
2001-06-15 21:09:30 -04:00
|
|
|
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
CreateStatusBar(2);
|
1998-07-08 09:21:23 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// Make a menubar
|
|
|
|
wxMenu *fileMenu = new wxMenu;
|
|
|
|
fileMenu->Append(SPLIT_VERTICAL, _T("Split &Vertically\tCtrl-V"), _T("Split vertically"));
|
|
|
|
fileMenu->Append(SPLIT_HORIZONTAL, _T("Split &Horizontally\tCtrl-H"), _T("Split horizontally"));
|
|
|
|
fileMenu->Append(SPLIT_UNSPLIT, _T("&Unsplit\tCtrl-U"), _T("Unsplit"));
|
|
|
|
fileMenu->AppendSeparator();
|
2002-02-22 10:09:45 -05:00
|
|
|
fileMenu->Append(SPLIT_LIVE, _T("&Live update"), _T("Toggle live update mode"), TRUE);
|
2002-01-07 13:33:30 -05:00
|
|
|
fileMenu->Append(SPLIT_SETMINSIZE, _T("Set &min size"), _T("Set minimum pane size"));
|
|
|
|
fileMenu->AppendSeparator();
|
|
|
|
fileMenu->Append(SPLIT_QUIT, _T("E&xit\tAlt-X"), _T("Exit"));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
menuBar->Append(fileMenu, _T("&File"));
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
SetMenuBar(menuBar);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-02-22 10:09:45 -05:00
|
|
|
menuBar->Check(SPLIT_LIVE, TRUE);
|
2002-01-07 13:33:30 -05:00
|
|
|
m_splitter = new MySplitterWindow(this);
|
2001-06-14 13:44:24 -04:00
|
|
|
|
2001-08-06 08:55:04 -04:00
|
|
|
#if 1
|
2002-01-07 13:33:30 -05:00
|
|
|
m_left = new MyCanvas(m_splitter);
|
|
|
|
m_left->SetBackgroundColour(*wxRED);
|
|
|
|
m_left->SetScrollbars(20, 20, 50, 50);
|
|
|
|
m_left->SetCursor(wxCursor(wxCURSOR_MAGNIFIER));
|
|
|
|
|
|
|
|
m_right = new MyCanvas(m_splitter);
|
|
|
|
m_right->SetBackgroundColour(*wxCYAN);
|
|
|
|
m_right->SetScrollbars(20, 20, 50, 50);
|
2001-08-06 08:55:04 -04:00
|
|
|
#else // for testing kbd navigation inside the splitter
|
2002-01-07 13:33:30 -05:00
|
|
|
m_left = new wxTextCtrl(m_splitter, -1, _T("first text"));
|
|
|
|
m_right = new wxTextCtrl(m_splitter, -1, _T("second text"));
|
2001-08-06 08:55:04 -04:00
|
|
|
#endif
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// you can also do this to start with a single window
|
2001-06-14 13:44:24 -04:00
|
|
|
#if 0
|
2002-01-07 13:33:30 -05:00
|
|
|
m_right->Show(FALSE);
|
|
|
|
m_splitter->Initialize(m_left);
|
2001-06-14 13:44:24 -04:00
|
|
|
#else
|
2002-02-21 19:48:02 -05:00
|
|
|
// you can also try -100
|
2002-01-07 13:33:30 -05:00
|
|
|
m_splitter->SplitVertically(m_left, m_right, 100);
|
2001-06-14 13:44:24 -04:00
|
|
|
#endif
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
SetStatusText(_T("Min pane size = 0"), 1);
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// menu command handlers
|
|
|
|
|
1998-07-27 16:50:48 -04:00
|
|
|
void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
Close(TRUE);
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
1998-07-27 16:50:48 -04:00
|
|
|
void MyFrame::SplitHorizontal(wxCommandEvent& WXUNUSED(event) )
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
if ( m_splitter->IsSplit() )
|
|
|
|
m_splitter->Unsplit();
|
|
|
|
m_left->Show(TRUE);
|
|
|
|
m_right->Show(TRUE);
|
|
|
|
m_splitter->SplitHorizontally( m_left, m_right );
|
2002-02-21 19:48:02 -05:00
|
|
|
|
|
|
|
SetStatusText(_T("Splitter split horizontally"), 1);
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
1998-07-27 16:50:48 -04:00
|
|
|
void MyFrame::SplitVertical(wxCommandEvent& WXUNUSED(event) )
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
if ( m_splitter->IsSplit() )
|
|
|
|
m_splitter->Unsplit();
|
|
|
|
m_left->Show(TRUE);
|
|
|
|
m_right->Show(TRUE);
|
|
|
|
m_splitter->SplitVertically( m_left, m_right );
|
2002-02-21 19:48:02 -05:00
|
|
|
|
|
|
|
SetStatusText(_T("Splitter split vertically"), 1);
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
1998-07-27 16:50:48 -04:00
|
|
|
void MyFrame::Unsplit(wxCommandEvent& WXUNUSED(event) )
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
if ( m_splitter->IsSplit() )
|
|
|
|
m_splitter->Unsplit();
|
|
|
|
SetStatusText(_T("No splitter"));
|
1998-10-23 09:15:15 -04:00
|
|
|
}
|
|
|
|
|
2002-02-22 10:09:45 -05:00
|
|
|
void MyFrame::ToggleLive(wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
long style = m_splitter->GetWindowStyleFlag();
|
|
|
|
if ( event.IsChecked() )
|
|
|
|
style |= wxSP_LIVE_UPDATE;
|
|
|
|
else
|
|
|
|
style &= ~wxSP_LIVE_UPDATE;
|
|
|
|
|
|
|
|
m_splitter->SetWindowStyleFlag(style);
|
|
|
|
}
|
|
|
|
|
1998-10-23 09:15:15 -04:00
|
|
|
void MyFrame::SetMinSize(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
wxString str;
|
2002-03-27 13:45:20 -05:00
|
|
|
str.Printf( wxT("%d"), m_splitter->GetMinimumPaneSize());
|
2002-01-07 13:33:30 -05:00
|
|
|
str = wxGetTextFromUser(_T("Enter minimal size for panes:"), _T(""), str, this);
|
|
|
|
if ( str.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int minsize = wxStrtol( str, (wxChar**)NULL, 10 );
|
|
|
|
m_splitter->SetMinimumPaneSize(minsize);
|
2002-03-27 13:45:20 -05:00
|
|
|
str.Printf( wxT("Min pane size = %d"), minsize);
|
2002-01-07 13:33:30 -05:00
|
|
|
SetStatusText(str, 1);
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// Update UI handlers
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent& event)
|
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
event.Enable( (!m_splitter->IsSplit()) || (m_splitter->GetSplitMode() != wxSPLIT_HORIZONTAL) );
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::UpdateUIVertical(wxUpdateUIEvent& event)
|
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
event.Enable( ( (!m_splitter->IsSplit()) || (m_splitter->GetSplitMode() != wxSPLIT_VERTICAL) ) );
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent& event)
|
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
event.Enable( m_splitter->IsSplit() );
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MySplitterWindow
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MySplitterWindow, wxSplitterWindow)
|
|
|
|
EVT_SPLITTER_SASH_POS_CHANGED(-1, MySplitterWindow::OnPositionChanged)
|
|
|
|
EVT_SPLITTER_SASH_POS_CHANGING(-1, MySplitterWindow::OnPositionChanging)
|
|
|
|
|
|
|
|
EVT_SPLITTER_DCLICK(-1, MySplitterWindow::OnDClick)
|
|
|
|
|
|
|
|
EVT_SPLITTER_UNSPLIT(-1, MySplitterWindow::OnUnsplit)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
MySplitterWindow::MySplitterWindow(wxFrame *parent)
|
|
|
|
: wxSplitterWindow(parent, -1,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxSP_3D | wxSP_LIVE_UPDATE | wxCLIP_CHILDREN)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
m_frame = parent;
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
void MySplitterWindow::OnPositionChanged(wxSplitterEvent& event)
|
|
|
|
{
|
|
|
|
wxLogStatus(m_frame, _T("Position has changed, now = %d (or %d)"),
|
|
|
|
event.GetSashPosition(), GetSashPosition());
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySplitterWindow::OnPositionChanging(wxSplitterEvent& event)
|
|
|
|
{
|
|
|
|
wxLogStatus(m_frame, _T("Position is changing, now = %d (or %d)"),
|
|
|
|
event.GetSashPosition(), GetSashPosition());
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySplitterWindow::OnDClick(wxSplitterEvent& event)
|
|
|
|
{
|
|
|
|
m_frame->SetStatusText(_T("Splitter double clicked"), 1);
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MySplitterWindow::OnUnsplit(wxSplitterEvent& event)
|
|
|
|
{
|
|
|
|
m_frame->SetStatusText(_T("Splitter unsplit"), 1);
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyCanvas
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MyCanvas::MyCanvas(wxWindow* parent)
|
|
|
|
: wxScrolledWindow(parent, -1)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MyCanvas::~MyCanvas()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyCanvas::OnDraw(wxDC& dc)
|
|
|
|
{
|
2002-01-07 13:33:30 -05:00
|
|
|
dc.SetPen(*wxBLACK_PEN);
|
|
|
|
dc.DrawLine(0, 0, 100, 100);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
dc.SetBackgroundMode(wxTRANSPARENT);
|
|
|
|
dc.DrawText(_T("Testing"), 50, 50);
|
1998-07-08 09:21:23 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
dc.SetPen(*wxRED_PEN);
|
|
|
|
dc.SetBrush(*wxGREEN_BRUSH);
|
|
|
|
dc.DrawRectangle(120, 120, 100, 80);
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
2002-01-07 13:33:30 -05:00
|
|
|
|