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$
|
2003-03-17 06:55:54 -05:00
|
|
|
// Copyright: (c) Julian Smart
|
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-07-12 09:23:53 -04:00
|
|
|
#include "wx/log.h"
|
|
|
|
|
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/frame.h"
|
|
|
|
|
|
|
|
#include "wx/scrolwin.h"
|
|
|
|
#include "wx/menu.h"
|
|
|
|
|
|
|
|
#include "wx/textdlg.h" // for wxGetTextFromUser
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/splitter.h"
|
2003-09-27 11:30:41 -04:00
|
|
|
#include "wx/dcmirror.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// ID for the menu commands
|
|
|
|
enum
|
|
|
|
{
|
2005-02-20 10:35:13 -05:00
|
|
|
SPLIT_QUIT = 1,
|
2002-01-07 13:33:30 -05:00
|
|
|
SPLIT_HORIZONTAL,
|
|
|
|
SPLIT_VERTICAL,
|
|
|
|
SPLIT_UNSPLIT,
|
2002-02-22 10:09:45 -05:00
|
|
|
SPLIT_LIVE,
|
2002-07-12 09:23:53 -04:00
|
|
|
SPLIT_SETPOSITION,
|
2004-12-12 06:19:36 -05:00
|
|
|
SPLIT_SETMINSIZE,
|
2005-03-30 10:36:15 -05:00
|
|
|
SPLIT_SETGRAVITY,
|
|
|
|
SPLIT_REPLACE
|
2002-01-07 13:33:30 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// our classes
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
class MyApp: public wxApp
|
|
|
|
{
|
|
|
|
public:
|
2003-09-27 11:30:41 -04:00
|
|
|
MyApp() { }
|
|
|
|
|
|
|
|
virtual bool OnInit();
|
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(MyApp)
|
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();
|
2005-03-30 10:36:15 -05:00
|
|
|
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-07-12 09:23:53 -04:00
|
|
|
void SetPosition(wxCommandEvent& event);
|
2002-01-07 13:33:30 -05:00
|
|
|
void SetMinSize(wxCommandEvent& event);
|
2004-12-12 06:19:36 -05:00
|
|
|
void SetGravity(wxCommandEvent& event);
|
2005-03-30 10:36:15 -05:00
|
|
|
void Replace(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;
|
2005-03-30 10:36:15 -05:00
|
|
|
wxWindow *m_replacewindow;
|
2002-01-07 13:33:30 -05:00
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
2003-09-27 11:30:41 -04:00
|
|
|
DECLARE_NO_COPY_CLASS(MyFrame)
|
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);
|
2004-03-23 16:50:16 -05:00
|
|
|
void OnUnsplitEvent(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()
|
2003-09-27 11:30:41 -04:00
|
|
|
DECLARE_NO_COPY_CLASS(MySplitterWindow)
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class MyCanvas: public wxScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
2003-09-27 11:30:41 -04:00
|
|
|
MyCanvas(wxWindow* parent, bool mirror);
|
2004-10-06 16:54:57 -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);
|
2003-09-27 11:30:41 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_mirror;
|
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(MyCanvas)
|
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
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
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
|
|
|
|
2004-03-23 16:50:16 -05:00
|
|
|
frame->Show(true);
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-03-23 16:50:16 -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-07-12 09:23:53 -04:00
|
|
|
EVT_MENU(SPLIT_SETPOSITION, MyFrame::SetPosition)
|
2002-01-07 13:33:30 -05:00
|
|
|
EVT_MENU(SPLIT_SETMINSIZE, MyFrame::SetMinSize)
|
2004-12-12 06:19:36 -05:00
|
|
|
EVT_MENU(SPLIT_SETGRAVITY, MyFrame::SetGravity)
|
2005-03-30 10:36:15 -05:00
|
|
|
EVT_MENU(SPLIT_REPLACE, MyFrame::Replace)
|
2002-01-07 13:33:30 -05:00
|
|
|
|
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()
|
2004-03-23 16:50:16 -05:00
|
|
|
: wxFrame(NULL, wxID_ANY, _T("wxSplitterWindow sample"),
|
2002-01-07 13:33:30 -05:00
|
|
|
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
|
|
|
{
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-01-07 13:33:30 -05:00
|
|
|
CreateStatusBar(2);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1998-07-08 09:21:23 -04:00
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
// Make a menubar
|
2002-07-12 09:23:53 -04:00
|
|
|
wxMenu *splitMenu = new wxMenu;
|
|
|
|
splitMenu->Append(SPLIT_VERTICAL,
|
|
|
|
_T("Split &Vertically\tCtrl-V"),
|
|
|
|
_T("Split vertically"));
|
|
|
|
splitMenu->Append(SPLIT_HORIZONTAL,
|
|
|
|
_T("Split &Horizontally\tCtrl-H"),
|
|
|
|
_T("Split horizontally"));
|
|
|
|
splitMenu->Append(SPLIT_UNSPLIT,
|
|
|
|
_T("&Unsplit\tCtrl-U"),
|
|
|
|
_T("Unsplit"));
|
|
|
|
splitMenu->AppendSeparator();
|
|
|
|
|
|
|
|
splitMenu->AppendCheckItem(SPLIT_LIVE,
|
|
|
|
_T("&Live update\tCtrl-L"),
|
|
|
|
_T("Toggle live update mode"));
|
|
|
|
splitMenu->Append(SPLIT_SETPOSITION,
|
|
|
|
_T("Set splitter &position\tCtrl-P"),
|
|
|
|
_T("Set the splitter position"));
|
|
|
|
splitMenu->Append(SPLIT_SETMINSIZE,
|
|
|
|
_T("Set &min size\tCtrl-M"),
|
|
|
|
_T("Set minimum pane size"));
|
2004-12-12 06:19:36 -05:00
|
|
|
splitMenu->Append(SPLIT_SETGRAVITY,
|
|
|
|
_T("Set &gravity\tCtrl-G"),
|
|
|
|
_T("Set gravity of sash"));
|
2002-07-12 09:23:53 -04:00
|
|
|
splitMenu->AppendSeparator();
|
|
|
|
|
2005-03-30 10:36:15 -05:00
|
|
|
splitMenu->Append(SPLIT_REPLACE,
|
|
|
|
_T("&Replace right window"),
|
|
|
|
_T("Replace right window"));
|
|
|
|
splitMenu->AppendSeparator();
|
|
|
|
|
2002-07-12 09:23:53 -04:00
|
|
|
splitMenu->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;
|
2002-07-12 09:23:53 -04:00
|
|
|
menuBar->Append(splitMenu, _T("&Splitter"));
|
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
|
|
|
|
2004-03-23 16:50:16 -05:00
|
|
|
menuBar->Check(SPLIT_LIVE, true);
|
2002-01-07 13:33:30 -05:00
|
|
|
m_splitter = new MySplitterWindow(this);
|
2004-12-12 06:19:36 -05:00
|
|
|
|
|
|
|
m_splitter->SetSashGravity(1.0);
|
2001-06-14 13:44:24 -04:00
|
|
|
|
2001-08-06 08:55:04 -04:00
|
|
|
#if 1
|
2003-09-27 11:30:41 -04:00
|
|
|
m_left = new MyCanvas(m_splitter, true);
|
2002-01-07 13:33:30 -05:00
|
|
|
m_left->SetBackgroundColour(*wxRED);
|
2003-09-27 11:30:41 -04:00
|
|
|
m_left->SetScrollbars(20, 20, 5, 5);
|
2002-01-07 13:33:30 -05:00
|
|
|
m_left->SetCursor(wxCursor(wxCURSOR_MAGNIFIER));
|
|
|
|
|
2003-09-27 11:30:41 -04:00
|
|
|
m_right = new MyCanvas(m_splitter, false);
|
2002-01-07 13:33:30 -05:00
|
|
|
m_right->SetBackgroundColour(*wxCYAN);
|
2003-09-27 11:30:41 -04:00
|
|
|
m_right->SetScrollbars(20, 20, 5, 5);
|
2001-08-06 08:55:04 -04:00
|
|
|
#else // for testing kbd navigation inside the splitter
|
2004-03-23 16:50:16 -05:00
|
|
|
m_left = new wxTextCtrl(m_splitter, wxID_ANY, _T("first text"));
|
|
|
|
m_right = new wxTextCtrl(m_splitter, wxID_ANY, _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
|
2004-03-23 16:50:16 -05:00
|
|
|
m_right->Show(false);
|
2002-01-07 13:33:30 -05:00
|
|
|
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
|
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-01-07 13:33:30 -05:00
|
|
|
SetStatusText(_T("Min pane size = 0"), 1);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2005-03-30 10:36:15 -05:00
|
|
|
|
|
|
|
m_replacewindow = (wxWindow *)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
|
|
|
if (m_replacewindow) {
|
|
|
|
m_replacewindow->Destroy();
|
|
|
|
m_replacewindow = (wxWindow *)0;
|
|
|
|
}
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2004-03-23 16:50:16 -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();
|
2004-03-23 16:50:16 -05:00
|
|
|
m_left->Show(true);
|
|
|
|
m_right->Show(true);
|
2002-01-07 13:33:30 -05:00
|
|
|
m_splitter->SplitHorizontally( m_left, m_right );
|
2002-02-21 19:48:02 -05:00
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-02-21 19:48:02 -05:00
|
|
|
SetStatusText(_T("Splitter split horizontally"), 1);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
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();
|
2004-03-23 16:50:16 -05:00
|
|
|
m_left->Show(true);
|
|
|
|
m_right->Show(true);
|
2002-01-07 13:33:30 -05:00
|
|
|
m_splitter->SplitVertically( m_left, m_right );
|
2002-02-21 19:48:02 -05:00
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-02-21 19:48:02 -05:00
|
|
|
SetStatusText(_T("Splitter split vertically"), 1);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
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();
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-01-07 13:33:30 -05:00
|
|
|
SetStatusText(_T("No splitter"));
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
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);
|
|
|
|
}
|
|
|
|
|
2002-07-12 09:23:53 -04:00
|
|
|
void MyFrame::SetPosition(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
wxString str;
|
|
|
|
str.Printf( wxT("%d"), m_splitter->GetSashPosition());
|
|
|
|
str = wxGetTextFromUser(_T("Enter splitter position:"), _T(""), str, this);
|
|
|
|
if ( str.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
long pos;
|
|
|
|
if ( !str.ToLong(&pos) )
|
|
|
|
{
|
|
|
|
wxLogError(_T("The splitter position should be an integer."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_splitter->SetSashPosition(pos);
|
|
|
|
|
|
|
|
wxLogStatus(this, _T("Splitter position set to %ld"), pos);
|
|
|
|
}
|
|
|
|
|
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);
|
2002-07-12 09:23:53 -04:00
|
|
|
if ( str.empty() )
|
2002-01-07 13:33:30 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
int minsize = wxStrtol( str, (wxChar**)NULL, 10 );
|
|
|
|
m_splitter->SetMinimumPaneSize(minsize);
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
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);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
2004-12-12 06:19:36 -05:00
|
|
|
void MyFrame::SetGravity(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
wxString str;
|
|
|
|
str.Printf( wxT("%g"), m_splitter->GetSashGravity());
|
|
|
|
str = wxGetTextFromUser(_T("Enter sash gravity (0,1):"), _T(""), str, this);
|
|
|
|
if ( str.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
double gravity = wxStrtod( str, (wxChar**)NULL);
|
|
|
|
m_splitter->SetSashGravity(gravity);
|
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
str.Printf( wxT("Gravity = %g"), gravity);
|
|
|
|
SetStatusText(str, 1);
|
|
|
|
#endif // wxUSE_STATUSBAR
|
|
|
|
}
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2005-03-30 10:36:15 -05:00
|
|
|
void MyFrame::Replace(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
if (m_replacewindow == 0) {
|
|
|
|
m_replacewindow = m_splitter->GetWindow2();
|
|
|
|
m_splitter->ReplaceWindow(m_replacewindow, new wxPanel(m_splitter, wxID_ANY));
|
|
|
|
m_replacewindow->Hide();
|
|
|
|
} else {
|
|
|
|
wxWindow *empty = m_splitter->GetWindow2();
|
|
|
|
m_splitter->ReplaceWindow(empty, m_replacewindow);
|
|
|
|
m_replacewindow->Show();
|
|
|
|
m_replacewindow = 0;
|
|
|
|
empty->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
2004-03-23 16:50:16 -05:00
|
|
|
EVT_SPLITTER_SASH_POS_CHANGED(wxID_ANY, MySplitterWindow::OnPositionChanged)
|
|
|
|
EVT_SPLITTER_SASH_POS_CHANGING(wxID_ANY, MySplitterWindow::OnPositionChanging)
|
2002-01-07 13:33:30 -05:00
|
|
|
|
2004-03-23 16:50:16 -05:00
|
|
|
EVT_SPLITTER_DCLICK(wxID_ANY, MySplitterWindow::OnDClick)
|
2002-01-07 13:33:30 -05:00
|
|
|
|
2004-03-23 16:50:16 -05:00
|
|
|
EVT_SPLITTER_UNSPLIT(wxID_ANY, MySplitterWindow::OnUnsplitEvent)
|
2002-01-07 13:33:30 -05:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
MySplitterWindow::MySplitterWindow(wxFrame *parent)
|
2004-03-23 16:50:16 -05:00
|
|
|
: wxSplitterWindow(parent, wxID_ANY,
|
2002-01-07 13:33:30 -05:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2004-03-03 15:44:37 -05:00
|
|
|
wxSP_3D | wxSP_LIVE_UPDATE |
|
|
|
|
wxCLIP_CHILDREN /* | wxSP_NO_XP_THEME */ )
|
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)
|
|
|
|
{
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-01-07 13:33:30 -05:00
|
|
|
m_frame->SetStatusText(_T("Splitter double clicked"), 1);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2002-01-07 13:33:30 -05:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2004-03-23 16:50:16 -05:00
|
|
|
void MySplitterWindow::OnUnsplitEvent(wxSplitterEvent& event)
|
2002-01-07 13:33:30 -05:00
|
|
|
{
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-01-07 13:33:30 -05:00
|
|
|
m_frame->SetStatusText(_T("Splitter unsplit"), 1);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2002-01-07 13:33:30 -05:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyCanvas
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-09-27 11:30:41 -04:00
|
|
|
MyCanvas::MyCanvas(wxWindow* parent, bool mirror)
|
2004-03-23 16:50:16 -05:00
|
|
|
: wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
2003-09-27 11:30:41 -04:00
|
|
|
wxHSCROLL | wxVSCROLL | wxNO_FULL_REPAINT_ON_RESIZE)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2003-09-27 11:30:41 -04:00
|
|
|
m_mirror = mirror;
|
1998-05-20 10:01:55 -04:00
|
|
|
}
|
|
|
|
|
2003-09-27 11:30:41 -04:00
|
|
|
void MyCanvas::OnDraw(wxDC& dcOrig)
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
2003-09-27 11:30:41 -04:00
|
|
|
wxMirrorDC dc(dcOrig, m_mirror);
|
|
|
|
|
2002-01-07 13:33:30 -05:00
|
|
|
dc.SetPen(*wxBLACK_PEN);
|
2003-09-27 11:30:41 -04:00
|
|
|
dc.DrawLine(0, 0, 100, 200);
|
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
|
|
|
|