initial draft of wxCollapsiblePane (patch 1577412 by Francesco)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42259 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -948,6 +948,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
|
|||||||
<set var="GTK_SRC" hints="files">
|
<set var="GTK_SRC" hints="files">
|
||||||
<!-- Generic implementations used by wxGTK: -->
|
<!-- Generic implementations used by wxGTK: -->
|
||||||
src/generic/accel.cpp
|
src/generic/accel.cpp
|
||||||
|
src/generic/collpaneg.cpp
|
||||||
src/generic/colrdlgg.cpp
|
src/generic/colrdlgg.cpp
|
||||||
src/generic/dirdlgg.cpp
|
src/generic/dirdlgg.cpp
|
||||||
src/generic/fdrepdlg.cpp
|
src/generic/fdrepdlg.cpp
|
||||||
@@ -968,6 +969,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
|
|||||||
src/gtk/checklst.cpp
|
src/gtk/checklst.cpp
|
||||||
src/gtk/choice.cpp
|
src/gtk/choice.cpp
|
||||||
src/gtk/colordlg.cpp
|
src/gtk/colordlg.cpp
|
||||||
|
src/gtk/collpane.cpp
|
||||||
src/gtk/combobox.cpp
|
src/gtk/combobox.cpp
|
||||||
src/gtk/control.cpp
|
src/gtk/control.cpp
|
||||||
src/gtk/clrpicker.cpp
|
src/gtk/clrpicker.cpp
|
||||||
@@ -1510,6 +1512,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
|
|||||||
</set>
|
</set>
|
||||||
|
|
||||||
<set var="MSW_SRC" hints="files">
|
<set var="MSW_SRC" hints="files">
|
||||||
|
src/generic/collpaneg.cpp
|
||||||
src/generic/statusbr.cpp
|
src/generic/statusbr.cpp
|
||||||
src/generic/prntdlgg.cpp
|
src/generic/prntdlgg.cpp
|
||||||
src/msw/accel.cpp
|
src/msw/accel.cpp
|
||||||
|
@@ -71,6 +71,7 @@ All (GUI):
|
|||||||
- Reverted wxBuffered[Paint]DC to pre 2.7.1 state, added
|
- Reverted wxBuffered[Paint]DC to pre 2.7.1 state, added
|
||||||
wxAutoBufferedPaintDC and wxAutoBufferedPaintDCFactory.
|
wxAutoBufferedPaintDC and wxAutoBufferedPaintDCFactory.
|
||||||
- Renamed wxProgressDialog::UpdatePulse() to just Pulse()
|
- Renamed wxProgressDialog::UpdatePulse() to just Pulse()
|
||||||
|
- Added wxCollapsiblePane (Francesco Montorsi)
|
||||||
- Added wxSimpleHtmlListBox (Francesco Montorsi)
|
- Added wxSimpleHtmlListBox (Francesco Montorsi)
|
||||||
|
|
||||||
Unix Ports:
|
Unix Ports:
|
||||||
|
114
docs/latex/wx/collpane.tex
Normal file
114
docs/latex/wx/collpane.tex
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
%% Name: collpane.tex
|
||||||
|
%% Purpose: wxCollapsiblePane documentation
|
||||||
|
%% Author: Francesco Montorsi
|
||||||
|
%% Created: 2006-10-14
|
||||||
|
%% RCS-ID: $Id$
|
||||||
|
%% Copyright: (c) 2006 Francesco Montorsi
|
||||||
|
%% License: wxWindows license
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\section{\class{wxCollapsiblePane}}\label{wxcollapsiblepane}
|
||||||
|
|
||||||
|
A collapsable panel is a container with an embedded button-like control which can be
|
||||||
|
used by the user to collapse or expand the pane's contents.
|
||||||
|
|
||||||
|
\wxheading{Derived from}
|
||||||
|
|
||||||
|
\helpref{wxControl}{wxcontrol}\\
|
||||||
|
\helpref{wxWindow}{wxwindow}\\
|
||||||
|
\helpref{wxEvtHandler}{wxevthandler}\\
|
||||||
|
\helpref{wxObject}{wxobject}
|
||||||
|
|
||||||
|
\wxheading{Include files}
|
||||||
|
|
||||||
|
<wx/collpane.h>
|
||||||
|
|
||||||
|
\wxheading{Window styles}
|
||||||
|
|
||||||
|
There are no specific styles for this window.
|
||||||
|
|
||||||
|
See also \helpref{window styles overview}{windowstyles}.
|
||||||
|
|
||||||
|
\wxheading{See also}
|
||||||
|
|
||||||
|
\helpref{wxPanel}{wxpanel}
|
||||||
|
|
||||||
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\membersection{wxCollapsiblePane::wxCollapsiblePane}\label{wxcollapsiblepane}
|
||||||
|
|
||||||
|
\func{}{wxCollapsiblePane}{\param{wxWindow *}{parent},\rtfsp
|
||||||
|
\param{wxWindowID}{ id},\rtfsp
|
||||||
|
\param{const wxString\& }{label},\rtfsp
|
||||||
|
\param{const wxPoint\& }{pos = wxDefaultPosition},\rtfsp
|
||||||
|
\param{const wxSize\& }{size = wxDefaultSize},\rtfsp
|
||||||
|
\param{long}{ style = wxCP\_DEFAULT\_STYLE},\rtfsp
|
||||||
|
\param{const wxValidator\& }{validator = wxDefaultValidator},
|
||||||
|
\param{const wxString\& }{name = ``collapsiblePane"}}
|
||||||
|
|
||||||
|
Initializes the object and calls \helpref{Create}{wxcollapsiblepanecreate} with
|
||||||
|
all the parameters.
|
||||||
|
|
||||||
|
|
||||||
|
\membersection{wxCollapsiblePane::Create}\label{wxcollapsiblepanecreate}
|
||||||
|
|
||||||
|
\func{bool}{Create}{\param{wxWindow *}{parent},\rtfsp
|
||||||
|
\param{wxWindowID}{ id},\rtfsp
|
||||||
|
\param{const wxString\& }{label},\rtfsp
|
||||||
|
\param{const wxPoint\& }{pos = wxDefaultPosition},\rtfsp
|
||||||
|
\param{const wxSize\& }{size = wxDefaultSize},\rtfsp
|
||||||
|
\param{long}{ style = wxCP\_DEFAULT\_STYLE},\rtfsp
|
||||||
|
\param{const wxValidator\& }{validator = wxDefaultValidator},
|
||||||
|
\param{const wxString\& }{name = ``colourpickerctrl"}}
|
||||||
|
|
||||||
|
\wxheading{Parameters}
|
||||||
|
|
||||||
|
\docparam{parent}{Parent window, must not be non-\texttt{NULL}.}
|
||||||
|
|
||||||
|
\docparam{id}{The identifier for the control.}
|
||||||
|
|
||||||
|
\docparam{label}{The initial label shown in the button which allows the user to expand or collapse the pane window.}
|
||||||
|
|
||||||
|
\docparam{pos}{Initial position.}
|
||||||
|
|
||||||
|
\docparam{size}{Initial size.}
|
||||||
|
|
||||||
|
\docparam{style}{The window style, see {\tt wxCP\_*} flags.}
|
||||||
|
|
||||||
|
\docparam{validator}{Validator which can be used for additional date checks.}
|
||||||
|
|
||||||
|
\docparam{name}{Control name.}
|
||||||
|
|
||||||
|
\wxheading{Return value}
|
||||||
|
|
||||||
|
\true if the control was successfully created or \false if creation failed.
|
||||||
|
|
||||||
|
|
||||||
|
\membersection{wxCollapsiblePane::IsCollapsed}\label{wxcollapsiblepaneiscollapsed}
|
||||||
|
|
||||||
|
\constfunc{bool}{IsCollapsed}{\void}
|
||||||
|
|
||||||
|
Returns \true if the pane window is currently hidden.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\membersection{wxCollapsiblePane::Collapse}\label{wxcollapsiblepanecollapse}
|
||||||
|
|
||||||
|
\func{void}{Collapse}{\param{bool }{collapse = true}}
|
||||||
|
|
||||||
|
Collapses or expands the pane window.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\membersection{wxCollapsiblePane::Expand}\label{wxcollapsiblepaneexpand}
|
||||||
|
|
||||||
|
\func{void}{Expand}{\void}
|
||||||
|
|
||||||
|
Equivalent to {\tt Collapse(false)}.
|
||||||
|
|
||||||
|
|
94
include/wx/collpane.h
Normal file
94
include/wx/collpane.h
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/collpane.h
|
||||||
|
// Purpose: wxCollapsiblePane
|
||||||
|
// Author: Francesco Montorsi
|
||||||
|
// Modified by:
|
||||||
|
// Created: 8/10/2006
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) Francesco Montorsi
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _WX_COLLAPSABLE_PANE_H_BASE_
|
||||||
|
#define _WX_COLLAPSABLE_PANE_H_BASE_
|
||||||
|
|
||||||
|
#include "wx/control.h"
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxCollapsiblePaneBase: interface for wxCollapsiblePane
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define wxCP_DEFAULT_STYLE (0)
|
||||||
|
|
||||||
|
class WXDLLEXPORT wxCollapsiblePaneBase : public wxControl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxCollapsiblePaneBase() {}
|
||||||
|
|
||||||
|
virtual void Expand()
|
||||||
|
{ Collapse(false); }
|
||||||
|
|
||||||
|
virtual void Collapse(bool collapse = true) = 0;
|
||||||
|
virtual bool IsCollapsed() const = 0;
|
||||||
|
virtual wxWindow *GetPane() const = 0;
|
||||||
|
|
||||||
|
virtual wxString GetLabel() const = 0;
|
||||||
|
virtual void SetLabel(const wxString &label) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// event types and macros
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BEGIN_DECLARE_EVENT_TYPES()
|
||||||
|
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, wxEVT_COMMAND_COLLPANE_CHANGED, 1102)
|
||||||
|
END_DECLARE_EVENT_TYPES()
|
||||||
|
|
||||||
|
class WXDLLIMPEXP_CORE wxCollapsiblePaneEvent : public wxCommandEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxCollapsiblePaneEvent() {}
|
||||||
|
wxCollapsiblePaneEvent(wxObject *generator, int id, bool collapsed)
|
||||||
|
: wxCommandEvent(wxEVT_COMMAND_COLLPANE_CHANGED, id),
|
||||||
|
m_bCollapsed(collapsed)
|
||||||
|
{
|
||||||
|
SetEventObject(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GetCollapsed() const { return m_bCollapsed; }
|
||||||
|
void SetCollapsed(bool c) { m_bCollapsed = c; }
|
||||||
|
|
||||||
|
|
||||||
|
// default copy ctor, assignment operator and dtor are ok
|
||||||
|
virtual wxEvent *Clone() const { return new wxCollapsiblePaneEvent(*this); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_bCollapsed;
|
||||||
|
|
||||||
|
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCollapsiblePaneEvent)
|
||||||
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// event types and macros
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
typedef void (wxEvtHandler::*wxCollapsiblePaneEventFunction)(wxCollapsiblePaneEvent&);
|
||||||
|
|
||||||
|
#define wxCollapsiblePaneEventHandler(func) \
|
||||||
|
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCollapsiblePaneEventFunction, &func)
|
||||||
|
|
||||||
|
#define EVT_COLLAPSIBLEPANE_CHANGED(id, fn) \
|
||||||
|
wx__DECLARE_EVT1(wxEVT_COMMAND_COLLPANE_CHANGED, id, wxCollapsiblePaneEventFunction(fn))
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__WXGTK24__)
|
||||||
|
#include "wx/gtk/collpane.h"
|
||||||
|
#else
|
||||||
|
#include "wx/generic/collpaneg.h"
|
||||||
|
#define wxCollapsiblePane wxGenericCollapsiblePane
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
// _WX_COLLAPSABLE_PANE_H_BASE_
|
115
include/wx/generic/collpaneg.h
Normal file
115
include/wx/generic/collpaneg.h
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/generic/collpaneg.h
|
||||||
|
// Purpose: wxGenericCollapsiblePane
|
||||||
|
// Author: Francesco Montorsi
|
||||||
|
// Modified by:
|
||||||
|
// Created: 8/10/2006
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) Francesco Montorsi
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _WX_COLLAPSABLE_PANE_H_GENERIC_
|
||||||
|
#define _WX_COLLAPSABLE_PANE_H_GENERIC_
|
||||||
|
|
||||||
|
#include "wx/button.h"
|
||||||
|
|
||||||
|
|
||||||
|
// the ID of the wxButton used to collapse/expand the panel
|
||||||
|
#define wxCP_BUTTON_ID 12356
|
||||||
|
|
||||||
|
// the number of pixels to leave between the button and the static line and
|
||||||
|
// between the button and the pane
|
||||||
|
#define wxCP_MARGIN 10
|
||||||
|
|
||||||
|
// forward declared
|
||||||
|
class WXDLLEXPORT wxStaticLine;
|
||||||
|
|
||||||
|
// class name
|
||||||
|
extern WXDLLEXPORT_DATA(const wxChar) wxGenericCollapsiblePaneNameStr[];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxGenericCollapsiblePane
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class WXDLLEXPORT wxGenericCollapsiblePane : public wxCollapsiblePaneBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxGenericCollapsiblePane() { Init(); }
|
||||||
|
|
||||||
|
wxGenericCollapsiblePane(wxWindow *parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& label,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxTAB_TRAVERSAL | wxNO_BORDER,
|
||||||
|
const wxValidator& val = wxDefaultValidator,
|
||||||
|
const wxString& name = wxGenericCollapsiblePaneNameStr)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
|
Create(parent, winid, label, pos, size, style, val, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init()
|
||||||
|
{
|
||||||
|
m_pButton = NULL;
|
||||||
|
m_pStatLine = NULL;
|
||||||
|
m_pPane = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Create(wxWindow *parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& label,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxTAB_TRAVERSAL | wxNO_BORDER,
|
||||||
|
const wxValidator& val = wxDefaultValidator,
|
||||||
|
const wxString& name = wxGenericCollapsiblePaneNameStr);
|
||||||
|
|
||||||
|
|
||||||
|
public: // public API
|
||||||
|
|
||||||
|
void Collapse(bool collapse = true);
|
||||||
|
void SetLabel(const wxString &label);
|
||||||
|
|
||||||
|
bool IsCollapsed() const
|
||||||
|
{ return m_pPane==NULL || !m_pPane->IsShown(); }
|
||||||
|
wxWindow *GetPane() const
|
||||||
|
{ return m_pPane; }
|
||||||
|
wxString GetLabel() const
|
||||||
|
{ return m_strLabel; }
|
||||||
|
|
||||||
|
wxWindow *GetTopLevelParent();
|
||||||
|
|
||||||
|
public: // event handlers
|
||||||
|
|
||||||
|
void OnButton(wxCommandEvent &ev);
|
||||||
|
void OnSize(wxSizeEvent &ev);
|
||||||
|
|
||||||
|
protected: // internal utils
|
||||||
|
|
||||||
|
void LayoutChildren();
|
||||||
|
|
||||||
|
wxString GetBtnLabel() const;
|
||||||
|
virtual wxSize DoGetBestSize() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
wxButton *m_pButton;
|
||||||
|
wxStaticLine *m_pStatLine;
|
||||||
|
wxWindow *m_pPane;
|
||||||
|
|
||||||
|
// the button label without ">>" or "<<"
|
||||||
|
wxString m_strLabel;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxGenericCollapsiblePane)
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
// _WX_COLLAPSABLE_PANE_H_GENERIC_
|
77
include/wx/gtk/collpane.h
Normal file
77
include/wx/gtk/collpane.h
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/gtk/collpane.h
|
||||||
|
// Purpose: wxCollapsiblePane
|
||||||
|
// Author: Francesco Montorsi
|
||||||
|
// Modified by:
|
||||||
|
// Created: 8/10/2006
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) Francesco Montorsi
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _WX_COLLAPSABLE_PANEL_H_GTK_
|
||||||
|
#define _WX_COLLAPSABLE_PANEL_H_GTK_
|
||||||
|
|
||||||
|
#include "wx/generic/collpaneg.h"
|
||||||
|
|
||||||
|
extern WXDLLEXPORT_DATA(const wxChar) wxCollapsiblePaneNameStr[];
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxCollapsiblePane
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class WXDLLEXPORT wxCollapsiblePane : public wxGenericCollapsiblePane
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxCollapsiblePane() { Init(); }
|
||||||
|
|
||||||
|
wxCollapsiblePane(wxWindow *parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& label,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxTAB_TRAVERSAL | wxNO_BORDER,
|
||||||
|
const wxValidator& val = wxDefaultValidator,
|
||||||
|
const wxString& name = wxCollapsiblePaneNameStr)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
|
Create(parent, winid, label, pos, size, style, val, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init()
|
||||||
|
{
|
||||||
|
m_bIgnoreNextChange = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Create(wxWindow *parent,
|
||||||
|
wxWindowID winid,
|
||||||
|
const wxString& label,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxTAB_TRAVERSAL | wxNO_BORDER,
|
||||||
|
const wxValidator& val = wxDefaultValidator,
|
||||||
|
const wxString& name = wxCollapsiblePaneNameStr);
|
||||||
|
|
||||||
|
public: // public API
|
||||||
|
|
||||||
|
wxSize DoGetBestSize() const;
|
||||||
|
void Collapse(bool collapse = true);
|
||||||
|
bool IsCollapsed() const;
|
||||||
|
void SetLabel(const wxString &str);
|
||||||
|
|
||||||
|
void OnSize(wxSizeEvent&);
|
||||||
|
|
||||||
|
public: // used by GTK callbacks
|
||||||
|
|
||||||
|
bool m_bIgnoreNextChange;
|
||||||
|
wxSize m_szCollapsed;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxCollapsiblePane)
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
// _WX_COLLAPSABLE_PANEL_H_GTK_
|
13
samples/collpane/collpane.bkl
Normal file
13
samples/collpane/collpane.bkl
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
<makefile>
|
||||||
|
|
||||||
|
<include file="../../build/bakefiles/common_samples.bkl"/>
|
||||||
|
|
||||||
|
<exe id="collpane" template="wx_sample" template_append="wx_append">
|
||||||
|
<sources>collpane.cpp</sources>
|
||||||
|
<wx-lib>core</wx-lib>
|
||||||
|
<wx-lib>base</wx-lib>
|
||||||
|
<win32-res>../sample.rc</win32-res>
|
||||||
|
</exe>
|
||||||
|
|
||||||
|
</makefile>
|
269
samples/collpane/collpane.cpp
Normal file
269
samples/collpane/collpane.cpp
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: collpane.cpp
|
||||||
|
// Purpose: wxCollapsiblePane sample
|
||||||
|
// Author: Francesco Montorsi
|
||||||
|
// Modified by:
|
||||||
|
// Created: 14/10/06
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) Francesco Montorsi
|
||||||
|
// Licence: wxWindows license
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// declarations
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// headers
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// For compilers that support precompilation, includes "wx/wx.h".
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WX_PRECOMP
|
||||||
|
#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
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/collpane.h"
|
||||||
|
#include "wx/sizer.h"
|
||||||
|
#include "wx/stattext.h"
|
||||||
|
#include "wx/clrpicker.h"
|
||||||
|
#include "wx/filepicker.h"
|
||||||
|
#include "wx/fontpicker.h"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// constants
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// ID for the menu commands
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PANE_COLLAPSE,
|
||||||
|
PANE_EXPAND,
|
||||||
|
PANE_SETLABEL,
|
||||||
|
PANE_SHOWDLG,
|
||||||
|
PANE_QUIT = wxID_EXIT
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// our classes
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class MyApp: public wxApp
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyApp() { }
|
||||||
|
|
||||||
|
virtual bool OnInit();
|
||||||
|
|
||||||
|
DECLARE_NO_COPY_CLASS(MyApp)
|
||||||
|
};
|
||||||
|
|
||||||
|
class MyFrame: public wxFrame
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyFrame();
|
||||||
|
virtual ~MyFrame();
|
||||||
|
|
||||||
|
// Menu commands
|
||||||
|
void OnCollapse(wxCommandEvent& event);
|
||||||
|
void OnExpand(wxCommandEvent& event);
|
||||||
|
void OnSetLabel(wxCommandEvent& event);
|
||||||
|
void OnShowDialog(wxCommandEvent& event);
|
||||||
|
void Quit(wxCommandEvent& event);
|
||||||
|
|
||||||
|
// Menu command update functions
|
||||||
|
void UpdateUI(wxUpdateUIEvent& event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxCollapsiblePane *m_collPane;
|
||||||
|
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
DECLARE_NO_COPY_CLASS(MyFrame)
|
||||||
|
};
|
||||||
|
|
||||||
|
class MyDialog : public wxDialog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyDialog(wxFrame *parent);
|
||||||
|
void OnToggleStatus(wxCommandEvent& WXUNUSED(ev));
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxCollapsiblePane *m_collPane;
|
||||||
|
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
DECLARE_NO_COPY_CLASS(MyDialog)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// implementation
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// MyApp
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_APP(MyApp)
|
||||||
|
|
||||||
|
bool MyApp::OnInit()
|
||||||
|
{
|
||||||
|
// create and show the main frame
|
||||||
|
MyFrame* frame = new MyFrame;
|
||||||
|
|
||||||
|
frame->Show(true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// MyFrame
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
|
EVT_MENU(PANE_COLLAPSE, MyFrame::OnCollapse)
|
||||||
|
EVT_MENU(PANE_EXPAND, MyFrame::OnExpand)
|
||||||
|
EVT_MENU(PANE_SETLABEL, MyFrame::OnSetLabel)
|
||||||
|
EVT_MENU(PANE_SHOWDLG, MyFrame::OnShowDialog)
|
||||||
|
EVT_MENU(PANE_QUIT, MyFrame::Quit)
|
||||||
|
|
||||||
|
EVT_UPDATE_UI(wxID_ANY, MyFrame::UpdateUI)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
// My frame constructor
|
||||||
|
MyFrame::MyFrame()
|
||||||
|
: wxFrame(NULL, wxID_ANY, _T("wxCollapsiblePane sample"),
|
||||||
|
wxDefaultPosition, wxSize(420, 300),
|
||||||
|
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
|
||||||
|
{
|
||||||
|
#if wxUSE_STATUSBAR
|
||||||
|
CreateStatusBar(2);
|
||||||
|
#endif // wxUSE_STATUSBAR
|
||||||
|
|
||||||
|
// Make a menubar
|
||||||
|
wxMenu *paneMenu = new wxMenu;
|
||||||
|
paneMenu->Append(PANE_COLLAPSE, _T("Collapse\tCtrl-C"));
|
||||||
|
paneMenu->Append(PANE_EXPAND, _T("Expand\tCtrl-E"));
|
||||||
|
paneMenu->AppendSeparator();
|
||||||
|
paneMenu->Append(PANE_SETLABEL, _T("Set label...\tCtrl-S"));
|
||||||
|
paneMenu->AppendSeparator();
|
||||||
|
paneMenu->Append(PANE_SHOWDLG, _T("Show dialog...\tCtrl-S"));
|
||||||
|
paneMenu->AppendSeparator();
|
||||||
|
paneMenu->Append(PANE_QUIT);
|
||||||
|
|
||||||
|
wxMenuBar *menuBar = new wxMenuBar;
|
||||||
|
menuBar->Append(paneMenu, _T("&Pane"));
|
||||||
|
SetMenuBar(menuBar);
|
||||||
|
|
||||||
|
m_collPane = new wxCollapsiblePane(this, -1, wxT("test!"));
|
||||||
|
wxWindow *win = m_collPane->GetPane();
|
||||||
|
|
||||||
|
new wxStaticText(win, -1, wxT("Static control with absolute coords"), wxPoint(10,2));
|
||||||
|
new wxStaticText(win, -1, wxT("Yet another one!"), wxPoint(30, 30));
|
||||||
|
new wxTextCtrl(win, -1, wxT("You can place anything you like inside a wxCollapsiblePane"),
|
||||||
|
wxPoint(5, 60), wxSize(300, -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
MyFrame::~MyFrame()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// menu command handlers
|
||||||
|
|
||||||
|
void MyFrame::Quit(wxCommandEvent& WXUNUSED(event) )
|
||||||
|
{
|
||||||
|
Close(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnCollapse(wxCommandEvent& WXUNUSED(event) )
|
||||||
|
{
|
||||||
|
m_collPane->Collapse();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnExpand(wxCommandEvent& WXUNUSED(event) )
|
||||||
|
{
|
||||||
|
m_collPane->Expand();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnSetLabel(wxCommandEvent& WXUNUSED(event) )
|
||||||
|
{
|
||||||
|
wxString text = wxGetTextFromUser(wxT("Input the new label"));
|
||||||
|
m_collPane->SetLabel(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnShowDialog(wxCommandEvent& WXUNUSED(event) )
|
||||||
|
{
|
||||||
|
MyDialog dlg(this);
|
||||||
|
dlg.ShowModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::UpdateUI(wxUpdateUIEvent& event)
|
||||||
|
{
|
||||||
|
GetMenuBar()->Enable(PANE_COLLAPSE, !m_collPane->IsCollapsed());
|
||||||
|
GetMenuBar()->Enable(PANE_EXPAND, m_collPane->IsCollapsed());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// MyDialog
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PANEDLG_TOGGLESTATUS_BTN = wxID_HIGHEST
|
||||||
|
};
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(MyDialog, wxDialog)
|
||||||
|
EVT_BUTTON(PANEDLG_TOGGLESTATUS_BTN, MyDialog::OnToggleStatus)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
MyDialog::MyDialog(wxFrame *parent)
|
||||||
|
: wxDialog(parent, wxID_ANY, wxT("Test dialog"),
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE )
|
||||||
|
{
|
||||||
|
wxSizer *sz = new wxBoxSizer(wxVERTICAL);
|
||||||
|
sz->Add(new wxStaticText(this, -1,
|
||||||
|
wxT("This dialog allows you to test the wxCollapsiblePane control")),
|
||||||
|
0, wxALL, 5);
|
||||||
|
sz->Add(new wxButton(this, PANEDLG_TOGGLESTATUS_BTN, wxT("Change status")),
|
||||||
|
1, wxGROW|wxALL, 5);
|
||||||
|
|
||||||
|
m_collPane = new wxCollapsiblePane(this, -1, wxT("Click here for a surprise"));
|
||||||
|
sz->Add(m_collPane, 1, wxGROW|wxALL, 5);
|
||||||
|
sz->Add(new wxTextCtrl(this, -1, wxT("just a test")), 0, wxGROW|wxALL, 5);
|
||||||
|
sz->AddSpacer(10);
|
||||||
|
sz->Add(new wxButton(this, wxID_OK), 0, wxALIGN_RIGHT|wxALL, 5);
|
||||||
|
|
||||||
|
// now add test controls in the collapsible pane
|
||||||
|
wxWindow *win = m_collPane->GetPane();
|
||||||
|
wxSizer *paneSz = new wxGridSizer(2, 2, 5, 5);
|
||||||
|
paneSz->Add(new wxColourPickerCtrl(win, -1), 1, wxGROW|wxALL, 2);
|
||||||
|
paneSz->Add(new wxFontPickerCtrl(win, -1), 1, wxGROW|wxALL, 2);
|
||||||
|
paneSz->Add(new wxFilePickerCtrl(win, -1), 1, wxALL|wxALIGN_CENTER, 2);
|
||||||
|
paneSz->Add(new wxDirPickerCtrl(win, -1), 1, wxALL|wxALIGN_CENTER, 2);
|
||||||
|
win->SetSizer(paneSz);
|
||||||
|
paneSz->SetSizeHints(win);
|
||||||
|
|
||||||
|
SetSizer(sz);
|
||||||
|
sz->SetSizeHints(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyDialog::OnToggleStatus(wxCommandEvent& WXUNUSED(ev))
|
||||||
|
{
|
||||||
|
m_collPane->Collapse(!m_collPane->IsCollapsed());
|
||||||
|
}
|
||||||
|
|
@@ -36,6 +36,7 @@
|
|||||||
#include "wx/generic/aboutdlgg.h"
|
#include "wx/generic/aboutdlgg.h"
|
||||||
|
|
||||||
#include "wx/hyperlink.h"
|
#include "wx/hyperlink.h"
|
||||||
|
#include "wx/collpane.h"
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// implementation
|
// implementation
|
||||||
@@ -101,7 +102,8 @@ wxIcon wxAboutDialogInfo::GetIcon() const
|
|||||||
bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info)
|
bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info)
|
||||||
{
|
{
|
||||||
// TODO: should we use main frame as parent by default here?
|
// TODO: should we use main frame as parent by default here?
|
||||||
if ( !wxDialog::Create(NULL, wxID_ANY, _("About ") + info.GetName()) )
|
if ( !wxDialog::Create(NULL, wxID_ANY, _("About ") + info.GetName(),
|
||||||
|
wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER|wxDEFAULT_DIALOG_STYLE) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_sizerText = new wxBoxSizer(wxVERTICAL);
|
m_sizerText = new wxBoxSizer(wxVERTICAL);
|
||||||
@@ -131,7 +133,14 @@ bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info)
|
|||||||
#endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
|
#endif // wxUSE_HYPERLINKCTRL/!wxUSE_HYPERLINKCTRL
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add licence
|
// add licence
|
||||||
|
wxCollapsiblePane *licensepnl = new wxCollapsiblePane(this, wxID_ANY, wxT("License"));
|
||||||
|
|
||||||
|
new wxStaticText(licensepnl->GetPane(), wxID_ANY, info.GetLicence(),
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
wxALIGN_CENTRE);
|
||||||
|
|
||||||
|
m_sizerText->Add(licensepnl, wxSizerFlags(1).Expand().Border(wxBOTTOM));
|
||||||
|
|
||||||
// TODO: add credits (developers, artists, doc writers, translators)
|
// TODO: add credits (developers, artists, doc writers, translators)
|
||||||
|
|
||||||
|
213
src/generic/collpaneg.cpp
Normal file
213
src/generic/collpaneg.cpp
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: src/generic/collpaneg.cpp
|
||||||
|
// Purpose: wxGenericCollapsiblePane
|
||||||
|
// Author: Francesco Montorsi
|
||||||
|
// Modified By:
|
||||||
|
// Created: 8/10/2006
|
||||||
|
// Id: $Id$
|
||||||
|
// Copyright: (c) Francesco Montorsi
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// headers
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
#include "wx/collpane.h"
|
||||||
|
#include "wx/statline.h"
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// implementation
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
const wxChar wxGenericCollapsiblePaneNameStr[] = wxT("genericCollapsiblePane");
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxGenericCollapsiblePane
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
DEFINE_EVENT_TYPE(wxEVT_COMMAND_COLLPANE_CHANGED)
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxGenericCollapsiblePane, wxControl)
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxCollapsiblePaneEvent, wxCommandEvent)
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(wxGenericCollapsiblePane, wxControl)
|
||||||
|
EVT_BUTTON(wxCP_BUTTON_ID, wxGenericCollapsiblePane::OnButton)
|
||||||
|
EVT_SIZE(wxGenericCollapsiblePane::OnSize)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
|
||||||
|
bool wxGenericCollapsiblePane::Create( wxWindow *parent, wxWindowID id,
|
||||||
|
const wxString& label,
|
||||||
|
const wxPoint& pos,
|
||||||
|
const wxSize& size,
|
||||||
|
long style,
|
||||||
|
const wxValidator& val,
|
||||||
|
const wxString& name)
|
||||||
|
{
|
||||||
|
if ( !wxControl::Create(parent, id, pos, size, style, val, name) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_strLabel = label;
|
||||||
|
|
||||||
|
// create children; their size & position is set in OnSize()
|
||||||
|
m_pButton = new wxButton(this, wxCP_BUTTON_ID, GetBtnLabel(), wxPoint(0, 0),
|
||||||
|
wxDefaultSize, wxBU_EXACTFIT);
|
||||||
|
m_pStatLine = new wxStaticLine(this, wxID_ANY);
|
||||||
|
m_pPane = new wxWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
|
||||||
|
|
||||||
|
// start as collapsed:
|
||||||
|
m_pPane->Hide();
|
||||||
|
|
||||||
|
//CacheBestSize(GetBestSize());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSize wxGenericCollapsiblePane::DoGetBestSize() const
|
||||||
|
{
|
||||||
|
wxSize sz = m_pButton->GetBestSize();
|
||||||
|
|
||||||
|
// set width
|
||||||
|
sz.SetWidth( sz.GetWidth() + wxCP_MARGIN + m_pStatLine->GetBestSize().GetWidth() );
|
||||||
|
sz.SetWidth( wxMax(sz.GetWidth(), m_pPane->GetBestSize().GetWidth()) );
|
||||||
|
|
||||||
|
// when expanded, we need more vertical space
|
||||||
|
if (!IsCollapsed())
|
||||||
|
sz.SetHeight( sz.GetHeight() + wxCP_MARGIN + m_pPane->GetBestSize().GetHeight() );
|
||||||
|
|
||||||
|
return sz;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxGenericCollapsiblePane::GetBtnLabel() const
|
||||||
|
{
|
||||||
|
if (IsCollapsed())
|
||||||
|
return m_strLabel + wxT(" >>");
|
||||||
|
return m_strLabel + wxT(" <<");
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGenericCollapsiblePane::Collapse(bool collapse)
|
||||||
|
{
|
||||||
|
// optimization
|
||||||
|
if (IsCollapsed() == collapse)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// update our state
|
||||||
|
m_pPane->Show(!collapse);
|
||||||
|
|
||||||
|
// update button label
|
||||||
|
// NB: this must be done after updating our "state"
|
||||||
|
m_pButton->SetLabel(GetBtnLabel());
|
||||||
|
|
||||||
|
// minimal size has priority over the best size so set here our min size
|
||||||
|
wxSize sz = GetBestSize();
|
||||||
|
SetMinSize(sz);
|
||||||
|
SetSize(sz);
|
||||||
|
|
||||||
|
wxWindow *top = GetTopLevelParent();
|
||||||
|
if (top)
|
||||||
|
{
|
||||||
|
// we've changed our size, thus our top level parent needs to relayout itself
|
||||||
|
top->Layout();
|
||||||
|
|
||||||
|
// FIXME: this makes wxGenericCollapsiblePane behave as the user expect but
|
||||||
|
// maybe there are cases where this is unwanted!
|
||||||
|
if (top->GetSizer())
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
// FIXME: the SetSizeHints() call would be required also for GTK+ for the
|
||||||
|
// expanded->collapsed transition.
|
||||||
|
// Unfortunately if we enable this line, then the GTK+ top window
|
||||||
|
// won't always be resized by the SetClientSize() call below!
|
||||||
|
// As a side effect of this dirty fix, the minimal size for the
|
||||||
|
// pane window is not set in GTK+ and the user can hide it shrinking
|
||||||
|
// the "top" window...
|
||||||
|
if (IsCollapsed())
|
||||||
|
#endif
|
||||||
|
top->GetSizer()->SetSizeHints(top);
|
||||||
|
|
||||||
|
if (IsCollapsed())
|
||||||
|
{
|
||||||
|
// NB: we need to use SetClientSize() and not SetSize() otherwise the size for
|
||||||
|
// windows like e.g. wxFrames with wxMenubars won't be correctly set
|
||||||
|
top->SetClientSize(sz);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// force our parent to "fit", i.e. expand so that it can honour
|
||||||
|
// our minimal size
|
||||||
|
top->Fit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wxWindow *wxGenericCollapsiblePane::GetTopLevelParent()
|
||||||
|
{
|
||||||
|
wxWindow *parent = GetParent();
|
||||||
|
while (parent && !parent->IsTopLevel())
|
||||||
|
parent = parent->GetParent();
|
||||||
|
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGenericCollapsiblePane::SetLabel(const wxString &label)
|
||||||
|
{
|
||||||
|
m_strLabel = label;
|
||||||
|
m_pButton->SetLabel(GetBtnLabel());
|
||||||
|
m_pButton->SetBestFittingSize();
|
||||||
|
|
||||||
|
LayoutChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGenericCollapsiblePane::LayoutChildren()
|
||||||
|
{
|
||||||
|
wxSize btnSz = m_pButton->GetSize();
|
||||||
|
|
||||||
|
// the button position & size are always ok...
|
||||||
|
|
||||||
|
// move & resize the static line
|
||||||
|
m_pStatLine->SetSize(btnSz.GetWidth() + wxCP_MARGIN, btnSz.GetHeight()/2,
|
||||||
|
GetSize().GetWidth() - btnSz.GetWidth() - wxCP_MARGIN, -1,
|
||||||
|
wxSIZE_USE_EXISTING);
|
||||||
|
|
||||||
|
// move & resize the container window
|
||||||
|
m_pPane->SetSize(0, btnSz.GetHeight() + wxCP_MARGIN,
|
||||||
|
GetSize().GetWidth(), GetSize().GetHeight() - btnSz.GetHeight() - wxCP_MARGIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxGenericCollapsiblePane - event handlers
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void wxGenericCollapsiblePane::OnButton(wxCommandEvent &WXUNUSED(event))
|
||||||
|
{
|
||||||
|
Collapse(!IsCollapsed());
|
||||||
|
|
||||||
|
// this change was generated by the user - send the event
|
||||||
|
wxCollapsiblePaneEvent ev(this, GetId(), IsCollapsed());
|
||||||
|
GetEventHandler()->ProcessEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGenericCollapsiblePane::OnSize(wxSizeEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
#if 0 // for debug only
|
||||||
|
wxClientDC dc(this);
|
||||||
|
dc.SetPen(*wxBLACK_PEN);
|
||||||
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||||
|
dc.DrawRectangle(wxPoint(0,0), GetSize());
|
||||||
|
dc.SetPen(*wxRED_PEN);
|
||||||
|
dc.DrawRectangle(wxPoint(0,0), GetBestSize());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
if (!m_pButton || !m_pStatLine || !m_pPane)
|
||||||
|
return; // we need to complete the creation first!
|
||||||
|
|
||||||
|
LayoutChildren();
|
||||||
|
|
||||||
|
// this is very important to make the pane window layout show correctly
|
||||||
|
m_pPane->Layout();
|
||||||
|
}
|
||||||
|
|
298
src/gtk/collpane.cpp
Normal file
298
src/gtk/collpane.cpp
Normal file
@@ -0,0 +1,298 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: src/gtk/collpane.cpp
|
||||||
|
// Purpose: wxCollapsiblePane
|
||||||
|
// Author: Francesco Montorsi
|
||||||
|
// Modified By:
|
||||||
|
// Created: 8/10/2006
|
||||||
|
// Id: $Id$
|
||||||
|
// Copyright: (c) Francesco Montorsi
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// headers
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#ifdef __WXGTK24__
|
||||||
|
|
||||||
|
#include "wx/collpane.h"
|
||||||
|
#include <gtk/gtkexpander.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// implementation
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
/* DEBUG TIMER */
|
||||||
|
class myTimer : public wxTimer
|
||||||
|
{
|
||||||
|
wxCollapsiblePane *p;
|
||||||
|
|
||||||
|
public:
|
||||||
|
myTimer(wxCollapsiblePane *pp) {p=pp;}
|
||||||
|
|
||||||
|
void Notify()
|
||||||
|
{
|
||||||
|
//wxLogDebug(wxT("%d"), p->IsCollapsed());
|
||||||
|
|
||||||
|
wxSize sz = p->GetBestSize();
|
||||||
|
wxLogDebug(wxT("our best size is now: %d-%d"), sz.GetWidth(), sz.GetHeight());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const wxChar wxCollapsiblePaneNameStr[] = wxT("CollapsiblePane");
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// "notify::expanded" signal
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
static void gtk_collapsiblepane_expanded_callback (GObject *object,
|
||||||
|
GParamSpec *param_spec,
|
||||||
|
wxCollapsiblePane *p)
|
||||||
|
{
|
||||||
|
// NB: unlike for the "activate" signal, when this callback is called, if we try to
|
||||||
|
// query the "collapsed" status through p->IsCollapsed(), we get the right value.
|
||||||
|
// I.e. here p->IsCollapsed() will return false if this callback has been called
|
||||||
|
// at the end of a collapsed->expanded transition and viceversa.
|
||||||
|
// Inside the "activate" signal callback p->IsCollapsed() would return the wrong value!
|
||||||
|
|
||||||
|
wxLogDebug("gtk_collapsiblepane_expanded_callback - IsCollapsed says %d", p->IsCollapsed());
|
||||||
|
|
||||||
|
wxSize sz;
|
||||||
|
if (!p->IsCollapsed())
|
||||||
|
{
|
||||||
|
// unfortunately there's no clean way to retrieve the minimal size of the expanded pane
|
||||||
|
// in this handler or in other handlers for the signals generated by user clicks on the
|
||||||
|
// GtkExpander button: p->GetBestSize() or p->GetMinSize() would still return the size for
|
||||||
|
// the collapsed expander even if the collapsed->expanded transition has already been
|
||||||
|
// completed (this because GTK+ queues some resize calls which still must be processed).
|
||||||
|
// So, the only solution to correctly set the size hints for this window is to calculate
|
||||||
|
// the expanded size ourselves, without relying on p->Get[Best|Min]Size:
|
||||||
|
sz = p->GetMinSize();
|
||||||
|
sz.SetWidth( wxMax(sz.GetWidth(), p->GetPane()->GetMinSize().GetWidth()) );
|
||||||
|
sz.SetHeight( sz.GetHeight() + p->GetPane()->GetMinSize().GetHeight() + 10 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// same problem described above: using p->Get[Best|Min]Size() here we would get the size
|
||||||
|
// of the control when it is expanded even if the expanded->collapsed transition should be
|
||||||
|
// complete now...
|
||||||
|
// So, we use the size cached at control-creation time...
|
||||||
|
sz = p->m_szCollapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxLogDebug(wxT("gtk_collapsiblepane_expanded_callback - my min size is now: %d-%d"),
|
||||||
|
sz.GetWidth(), sz.GetHeight());
|
||||||
|
|
||||||
|
// minimal size has priority over the best size so set here our min size
|
||||||
|
p->SetMinSize(sz);
|
||||||
|
p->SetSize(sz);
|
||||||
|
|
||||||
|
wxWindow *top = p->GetTopLevelParent();
|
||||||
|
if (top)
|
||||||
|
{
|
||||||
|
// we've changed our size, thus our top level parent needs to relayout itself
|
||||||
|
top->Layout();
|
||||||
|
|
||||||
|
// FIXME: this makes wxGenericCollapsiblePane behave as the user expect but
|
||||||
|
// maybe there are cases where this is unwanted!
|
||||||
|
if (top->GetSizer())
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
// FIXME: the SetSizeHints() call would be required also for GTK+ for the
|
||||||
|
// expanded->collapsed transition.
|
||||||
|
// Unfortunately if we enable this line, then the GTK+ top window
|
||||||
|
// won't always be resized by the SetClientSize() call below!
|
||||||
|
// As a side effect of this dirty fix, the minimal size for the
|
||||||
|
// pane window is not set in GTK+ and the user can hide it shrinking
|
||||||
|
// the "top" window...
|
||||||
|
if (p->IsCollapsed())
|
||||||
|
#endif
|
||||||
|
top->GetSizer()->SetSizeHints(top);
|
||||||
|
|
||||||
|
if (p->IsCollapsed())
|
||||||
|
{
|
||||||
|
// NB: we need to use SetClientSize() and not SetSize() otherwise the size for
|
||||||
|
// windows like e.g. wxFrames with wxMenubars won't be correctly set
|
||||||
|
top->SetClientSize(sz);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// force our parent to "fit", i.e. expand so that it can honour
|
||||||
|
// our minimal size
|
||||||
|
top->Fit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->m_bIgnoreNextChange)
|
||||||
|
{
|
||||||
|
// change generated programmatically - do not send an event!
|
||||||
|
p->m_bIgnoreNextChange = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fire an event
|
||||||
|
wxCollapsiblePaneEvent ev(p, p->GetId(), p->IsCollapsed());
|
||||||
|
p->GetEventHandler()->ProcessEvent(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gtk_collapsiblepane_insert_callback( wxWindowGTK* parent, wxWindowGTK* child )
|
||||||
|
{
|
||||||
|
// this callback should be used only once to insert the "pane" into
|
||||||
|
// the GtkExpander widget. wxGenericCollapsiblePane::DoAddChild() will check
|
||||||
|
// if it has been called only once (and in any case we would get a warning
|
||||||
|
// from the following call as GtkExpander is a GtkBin and can contain only a
|
||||||
|
// single child!).
|
||||||
|
gtk_container_add (GTK_CONTAINER (parent->m_widget), child->m_widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxCollapsiblePane
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxCollapsiblePane, wxGenericCollapsiblePane)
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(wxCollapsiblePane, wxGenericCollapsiblePane)
|
||||||
|
EVT_SIZE(wxCollapsiblePane::OnSize)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
bool wxCollapsiblePane::Create( wxWindow *parent, wxWindowID id,
|
||||||
|
const wxString& label,
|
||||||
|
const wxPoint& pos,
|
||||||
|
const wxSize& size,
|
||||||
|
long style,
|
||||||
|
const wxValidator& val,
|
||||||
|
const wxString& name)
|
||||||
|
{
|
||||||
|
if (gtk_check_version(2,4,0)) {wxASSERT(0);
|
||||||
|
return wxGenericCollapsiblePane::Create(parent, id, label, pos, size, style, val, name);}
|
||||||
|
|
||||||
|
m_needParent = true;
|
||||||
|
m_acceptsFocus = true;
|
||||||
|
m_bIgnoreNextChange = false;
|
||||||
|
|
||||||
|
if (!PreCreation( parent, pos, size ) ||
|
||||||
|
!wxControl::CreateBase(parent, id, pos, size, style, val, name))
|
||||||
|
{
|
||||||
|
wxFAIL_MSG( wxT("wxCollapsiblePane creation failed") );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_widget = gtk_expander_new(label.c_str());
|
||||||
|
|
||||||
|
// see the gtk_collapsiblepane_expanded_callback comments to understand why we connect
|
||||||
|
// to the "notify::expanded" signal instead of the more common "activate" one
|
||||||
|
g_signal_connect(m_widget, "notify::expanded",
|
||||||
|
G_CALLBACK(gtk_collapsiblepane_expanded_callback), this);
|
||||||
|
|
||||||
|
// before creating m_pPane, we need to makesure our own insert callback will be used
|
||||||
|
m_insertCallback = gtk_collapsiblepane_insert_callback;
|
||||||
|
|
||||||
|
// this the real "pane"
|
||||||
|
m_pPane = new wxWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER);
|
||||||
|
|
||||||
|
gtk_widget_show( GTK_WIDGET(m_widget) );
|
||||||
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
|
PostCreation(size);
|
||||||
|
//SetBestSize(size);
|
||||||
|
|
||||||
|
// remember the size of this control when it's collapsed
|
||||||
|
m_szCollapsed = GetBestSize();
|
||||||
|
|
||||||
|
/*
|
||||||
|
myTimer *t = new myTimer(this);
|
||||||
|
t->Start(2000);
|
||||||
|
*/
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSize wxCollapsiblePane::DoGetBestSize() const
|
||||||
|
{
|
||||||
|
if (!gtk_check_version(2,4,0))
|
||||||
|
{
|
||||||
|
//return wxControl::DoGetBestSize(); // need not to cache the best size!
|
||||||
|
|
||||||
|
wxASSERT_MSG( m_widget, wxT("DoGetBestSize called before creation") );
|
||||||
|
|
||||||
|
GtkRequisition req;
|
||||||
|
req.width = 2;
|
||||||
|
req.height = 2;
|
||||||
|
(* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_widget) )->size_request )
|
||||||
|
(m_widget, &req );
|
||||||
|
|
||||||
|
wxSize best(req.width, req.height);
|
||||||
|
//CacheBestSize(best);
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wxGenericCollapsiblePane::DoGetBestSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxCollapsiblePane::Collapse(bool collapse)
|
||||||
|
{
|
||||||
|
if (!gtk_check_version(2,4,0))
|
||||||
|
{
|
||||||
|
// optimization
|
||||||
|
if (IsCollapsed() == collapse)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// do not send event in next signal handler call
|
||||||
|
m_bIgnoreNextChange = true;
|
||||||
|
gtk_expander_set_expanded(GTK_EXPANDER(m_widget), !collapse);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
wxGenericCollapsiblePane::Collapse(collapse);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxCollapsiblePane::IsCollapsed() const
|
||||||
|
{
|
||||||
|
if (!gtk_check_version(2,4,0))
|
||||||
|
return !gtk_expander_get_expanded(GTK_EXPANDER(m_widget));
|
||||||
|
|
||||||
|
return wxGenericCollapsiblePane::IsCollapsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxCollapsiblePane::SetLabel(const wxString &str)
|
||||||
|
{
|
||||||
|
if (!gtk_check_version(2,4,0))
|
||||||
|
gtk_expander_set_label(GTK_EXPANDER(m_widget), str.c_str());
|
||||||
|
else
|
||||||
|
wxGenericCollapsiblePane::SetLabel(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxCollapsiblePane::OnSize(wxSizeEvent &ev)
|
||||||
|
{
|
||||||
|
#if 0 // for debug only
|
||||||
|
wxClientDC dc(this);
|
||||||
|
dc.SetPen(*wxBLACK_PEN);
|
||||||
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||||
|
dc.DrawRectangle(wxPoint(0,0), GetSize());
|
||||||
|
dc.SetPen(*wxRED_PEN);
|
||||||
|
dc.DrawRectangle(wxPoint(0,0), GetBestSize());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//wxLogDebug(wxT("wxCollapsiblePane::OnSize"));
|
||||||
|
|
||||||
|
// here we need to resize the pane window otherwise, even if the GtkExpander container
|
||||||
|
// is expanded or shrinked, the pane window won't be updated!
|
||||||
|
m_pPane->SetSize(ev.GetSize());
|
||||||
|
|
||||||
|
// we need to explicitely call m_pPane->Layout() or else it won't correctly relayout
|
||||||
|
// (even if SetAutoLayout(true) has been called on it!)
|
||||||
|
m_pPane->Layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // __WXGTK24__
|
||||||
|
|
Reference in New Issue
Block a user