| 1 |
#include "splitter_window_wrapper.h" |
| 2 |
#include "allocator_mgr.h" |
| 3 |
#include "choice_property.h" |
| 4 |
#include "wxgui_defs.h" |
| 5 |
#include "wxgui_helpers.h" |
| 6 |
#include "xmlutils.h" |
| 7 |
#include <wx/menu.h> |
| 8 |
#include <wx/splitter.h> |
| 9 |
|
| 10 |
SplitterWindowWrapper::SplitterWindowWrapper() |
| 11 |
: wxcWidget(ID_WXSPLITTERWINDOW) |
| 12 |
{ |
| 13 |
wxArrayString options; |
| 14 |
options.Add(wxT("wxSPLIT_VERTICAL")); |
| 15 |
options.Add(wxT("wxSPLIT_HORIZONTAL")); |
| 16 |
|
| 17 |
SetPropertyString(_("Common Settings"), "wxSplitterWindow"); |
| 18 |
AddProperty(new ChoiceProperty(PROP_SPLIT_MODE, options, 0, _("Sets the split mode"))); |
| 19 |
|
| 20 |
wxString tip; |
| 21 |
tip << _("Gravity is real factor which controls position of sash while resizing wxSplitterWindow. \n") |
| 22 |
<< _("Gravity tells wxSplitterWindow how much will left/top window grow while resizing.\n") |
| 23 |
<< _("Example values:\n") << _("0.0 - only the bottom/right window is automatically resized\n") |
| 24 |
<< _("0.5 - both windows grow by equal size\n") << _("1.0 - only left/top window grows\n") |
| 25 |
<< _("(Gravity should be a real value between 0.0 and 1.0)"); |
| 26 |
|
| 27 |
AddProperty(new StringProperty(PROP_SASH_GRAVITY, wxT("0.5"), tip)); |
| 28 |
AddProperty(new StringProperty(PROP_MIN_PANE_SIZE, wxT("10"), _("Sets the minimum pane size"))); |
| 29 |
AddProperty(new StringProperty(PROP_SASH_POS, wxT("0"), _("Sets the sash initial position"))); |
| 30 |
|
| 31 |
PREPEND_STYLE_TRUE(wxSP_3D); |
| 32 |
PREPEND_STYLE_FALSE(wxSP_3DSASH); |
| 33 |
PREPEND_STYLE_FALSE(wxSP_3DBORDER); |
| 34 |
PREPEND_STYLE_FALSE(wxSP_BORDER); |
| 35 |
PREPEND_STYLE_FALSE(wxSP_NOBORDER); |
| 36 |
PREPEND_STYLE_FALSE(wxSP_NO_XP_THEME); |
| 37 |
PREPEND_STYLE_FALSE(wxSP_PERMIT_UNSPLIT); |
| 38 |
PREPEND_STYLE_FALSE(wxSP_LIVE_UPDATE); |
| 39 |
|
| 40 |
RegisterEvent(wxT("wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING"), wxT(" wxSplitterEvent"), |
| 41 |
_("The sash position is in the process of being changed")); |
| 42 |
RegisterEvent(wxT("wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED"), wxT(" wxSplitterEvent"), |
| 43 |
_("The sash position was changed")); |
| 44 |
RegisterEvent(wxT("wxEVT_COMMAND_SPLITTER_UNSPLIT"), wxT(" wxSplitterEvent"), |
| 45 |
_("The splitter has been just unsplit")); |
| 46 |
RegisterEvent(wxT("wxEVT_COMMAND_SPLITTER_DOUBLECLICKED"), wxT(" wxSplitterEvent"), |
| 47 |
_("The sash was double clicked.\nThe default behaviour is to unsplit the window when this " |
| 48 |
"happens\n(unless the minimum pane size has been set to a value greater than zero)")); |
| 49 |
|
| 50 |
m_namePattern = wxT("m_splitter"); |
| 51 |
SetName(GenerateName()); |
| 52 |
} |
| 53 |
|
| 54 |
SplitterWindowWrapper::~SplitterWindowWrapper() {} |
| 55 |
|
| 56 |
wxcWidget* SplitterWindowWrapper::Clone() const { return new SplitterWindowWrapper(); } |
| 57 |
|
| 58 |
wxString SplitterWindowWrapper::CppCtorCode() const |
| 59 |
{ |
| 60 |
wxString code; |
| 61 |
code << CPPStandardWxCtor(wxT("wxSP_3D")); |
| 62 |
code << GetName() << wxT("->SetSashGravity(") |
| 63 |
<< wxCrafter::FloatToCString(wxCrafter::ToFloat(PropertyString(PROP_SASH_GRAVITY), 0.5)) << wxT(");\n"); |
| 64 |
code << GetName() << wxT("->SetMinimumPaneSize(") << wxCrafter::ToNumber(PropertyString(PROP_MIN_PANE_SIZE), 10) |
| 65 |
<< wxT(");\n"); |
| 66 |
return code; |
| 67 |
} |
| 68 |
|
| 69 |
void SplitterWindowWrapper::GetIncludeFile(wxArrayString& headers) const |
| 70 |
{ |
| 71 |
headers.Add(wxT("#include <wx/splitter.h>")); |
| 72 |
} |
| 73 |
|
| 74 |
wxString SplitterWindowWrapper::GetWxClassName() const { return wxT("wxSplitterWindow"); } |
| 75 |
|
| 76 |
void SplitterWindowWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 77 |
{ |
| 78 |
float gravity = wxCrafter::ToFloat(PropertyString(PROP_SASH_GRAVITY), 0.5); |
| 79 |
int minsize = wxCrafter::ToNumber(PropertyString(PROP_MIN_PANE_SIZE), 0); |
| 80 |
int sashpos = wxCrafter::ToNumber(PropertyString(PROP_SASH_POS), 0); |
| 81 |
|
| 82 |
wxString orientation = "vertical"; |
| 83 |
if(!IsSplitVertically()) { orientation = "horizontal"; } |
| 84 |
|
| 85 |
text << XRCPrefix() << XRCSize() << XRCCommonAttributes() << XRCStyle() << wxT("<gravity>") |
| 86 |
<< wxCrafter::FloatToCString(gravity) << wxT("</gravity>") << wxT("<minsize>") << minsize << wxT("</minsize>") |
| 87 |
<< wxT("<sashpos>") << sashpos << wxT("</sashpos>") << wxT("<orientation>") << orientation |
| 88 |
<< wxT("</orientation>"); |
| 89 |
|
| 90 |
ChildrenXRC(text, type); |
| 91 |
|
| 92 |
text << XRCSuffix(); |
| 93 |
} |
| 94 |
|
| 95 |
void SplitterWindowWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 96 |
{ |
| 97 |
// First call the base-class for the standard things |
| 98 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 99 |
|
| 100 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("gravity")); |
| 101 |
if(propertynode) { SetPropertyString(PROP_SASH_GRAVITY, propertynode->GetNodeContent()); } |
| 102 |
|
| 103 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("minsize")); |
| 104 |
if(propertynode) { SetPropertyString(PROP_MIN_PANE_SIZE, propertynode->GetNodeContent()); } |
| 105 |
|
| 106 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("sashpos")); |
| 107 |
if(propertynode) { SetPropertyString(PROP_SASH_POS, propertynode->GetNodeContent()); } |
| 108 |
|
| 109 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("orientation")); |
| 110 |
if(propertynode) { |
| 111 |
SetPropertyString(PROP_SPLIT_MODE, propertynode->GetNodeContent() == "vertical" |
| 112 |
? wxString("wxSPLIT_VERTICAL") |
| 113 |
: wxString("wxSPLIT_HORIZONTAL")); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
void SplitterWindowWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 118 |
{ |
| 119 |
// First call the base-class for the standard things |
| 120 |
wxcWidget::LoadPropertiesFromwxSmith(node); |
| 121 |
|
| 122 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("gravity")); |
| 123 |
if(propertynode) { SetPropertyString(PROP_SASH_GRAVITY, propertynode->GetNodeContent()); } |
| 124 |
|
| 125 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("minsize")); |
| 126 |
if(propertynode) { SetPropertyString(PROP_MIN_PANE_SIZE, propertynode->GetNodeContent()); } |
| 127 |
|
| 128 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("sashpos")); |
| 129 |
if(propertynode) { SetPropertyString(PROP_SASH_POS, propertynode->GetNodeContent()); } |
| 130 |
|
| 131 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("orientation")); |
| 132 |
if(propertynode) { SetPropertyString(PROP_SPLIT_MODE, propertynode->GetNodeContent()); } |
| 133 |
} |
| 134 |
|
| 135 |
void SplitterWindowWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 136 |
{ |
| 137 |
// First call the base-class for the standard things |
| 138 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 139 |
|
| 140 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "sashgravity"); |
| 141 |
if(propertynode) { SetPropertyString(PROP_SASH_GRAVITY, propertynode->GetNodeContent()); } |
| 142 |
|
| 143 |
propertynode = XmlUtils::FindNodeByName(node, "property", "min_pane_size"); |
| 144 |
if(propertynode) { SetPropertyString(PROP_MIN_PANE_SIZE, propertynode->GetNodeContent()); } |
| 145 |
|
| 146 |
propertynode = XmlUtils::FindNodeByName(node, "property", "sashpos"); |
| 147 |
if(propertynode) { SetPropertyString(PROP_SASH_POS, propertynode->GetNodeContent()); } |
| 148 |
|
| 149 |
propertynode = XmlUtils::FindNodeByName(node, "property", "splitmode"); |
| 150 |
if(propertynode) { SetPropertyString(PROP_SPLIT_MODE, propertynode->GetNodeContent()); } |
| 151 |
} |
| 152 |
|
| 153 |
bool SplitterWindowWrapper::IsSplitVertically() const |
| 154 |
{ |
| 155 |
wxString orientation = PropertyString(PROP_SPLIT_MODE); |
| 156 |
return orientation == wxT("wxSPLIT_VERTICAL"); |
| 157 |
} |
| 158 |
|
| 159 |
int SplitterWindowWrapper::GetSashPos() const { return wxCrafter::ToNumber(PropertyString(PROP_SASH_POS), 0); } |