| 1 |
#include "generic_dir_ctrl_wrapper.h" |
| 2 |
#include "allocator_mgr.h" |
| 3 |
#include "bool_property.h" |
| 4 |
#include "wxgui_defs.h" |
| 5 |
#include "wxgui_helpers.h" |
| 6 |
#include "xmlutils.h" |
| 7 |
#include <wx/dirctrl.h> |
| 8 |
|
| 9 |
GenericDirCtrlWrapper::GenericDirCtrlWrapper() |
| 10 |
: wxcWidget(ID_WXGENERICDIRCTRL) |
| 11 |
{ |
| 12 |
SetPropertyString(_("Common Settings"), "wxGenericDirCtrl"); |
| 13 |
AddProperty(new StringProperty(PROP_DEFAULT_FOLDER, wxT(""), _("Sets the default path"))); |
| 14 |
AddProperty(new StringProperty(PROP_FILTER, wxT(""), |
| 15 |
_("Sets the filter string. The syntax is similar to the one used in wxFileDialog"))); |
| 16 |
AddProperty(new StringProperty(PROP_DEFAULT_FILTER, wxT(""), _("Sets the current filter index (zero-based)."))); |
| 17 |
AddProperty(new BoolProperty(PROP_SHOW_HIDDEN, false, _("Show hidden files"))); |
| 18 |
|
| 19 |
PREPEND_STYLE_FALSE(wxDIRCTRL_DIR_ONLY); |
| 20 |
PREPEND_STYLE_TRUE(wxDIRCTRL_3D_INTERNAL); |
| 21 |
PREPEND_STYLE_FALSE(wxDIRCTRL_SELECT_FIRST); |
| 22 |
PREPEND_STYLE_FALSE(wxDIRCTRL_SHOW_FILTERS); |
| 23 |
PREPEND_STYLE_FALSE(wxDIRCTRL_EDIT_LABELS); |
| 24 |
|
| 25 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_BEGIN_DRAG"), wxT("wxTreeEvent"), |
| 26 |
_("The user has started dragging an item with the left mouse button.\nThe event handler must call " |
| 27 |
"wxTreeEvent::Allow() for the drag operation to continue.")); |
| 28 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_BEGIN_RDRAG"), wxT("wxTreeEvent"), |
| 29 |
_("The user has started dragging an item with the right mouse button.\nThe event handler must call " |
| 30 |
"wxTreeEvent::Allow() for the drag operation to continue.")); |
| 31 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_END_DRAG"), wxT("wxTreeEvent"), |
| 32 |
_("The user has released the mouse after dragging an item.")); |
| 33 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT"), wxT("wxTreeEvent"), |
| 34 |
_("Begin editing a label. This can be prevented by calling Veto().")); |
| 35 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_END_LABEL_EDIT"), wxT("wxTreeEvent"), |
| 36 |
_("The user has finished editing a label. This can be prevented by calling Veto().")); |
| 37 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_DELETE_ITEM"), wxT("wxTreeEvent"), _("A tree item has been deleted.")); |
| 38 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_ITEM_EXPANDED"), wxT("wxTreeEvent"), _("The item has been expanded.")); |
| 39 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_ITEM_EXPANDING"), wxT("wxTreeEvent"), |
| 40 |
_("The item is being expanded. This can be prevented by calling Veto().")); |
| 41 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_ITEM_COLLAPSED"), wxT("wxTreeEvent"), _("The item has been collapsed.")); |
| 42 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_ITEM_COLLAPSING"), wxT("wxTreeEvent"), |
| 43 |
_("The item is being collapsed. This can be prevented by calling Veto().")); |
| 44 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_SEL_CHANGED"), wxT("wxTreeEvent"), _("Selection has changed.")); |
| 45 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_SEL_CHANGING"), wxT("wxTreeEvent"), |
| 46 |
_("Selection is changing. This can be prevented by calling Veto().")); |
| 47 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_KEY_DOWN"), wxT("wxTreeEvent"), _("A key has been pressed.")); |
| 48 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_ITEM_ACTIVATED"), wxT("wxTreeEvent"), |
| 49 |
_("An item has been activated (e.g. double clicked).")); |
| 50 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK"), wxT("wxTreeEvent"), |
| 51 |
_("The user has clicked the item with the right mouse button.")); |
| 52 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK"), wxT("wxTreeEvent"), |
| 53 |
_("The user has clicked the item with the middle mouse button.")); |
| 54 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK"), wxT("wxTreeEvent"), |
| 55 |
_("The state image has been clicked. Windows only.")); |
| 56 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP"), wxT("wxTreeEvent"), |
| 57 |
_("The opportunity to set the item tooltip is being given to the application\n (call " |
| 58 |
"wxTreeEvent::SetToolTip). Windows only.")); |
| 59 |
RegisterEvent(wxT("wxEVT_COMMAND_TREE_ITEM_MENU"), wxT("wxTreeEvent"), |
| 60 |
_("The context menu for the selected item has been requested,\neither by a right click or by using " |
| 61 |
"the menu key.")); |
| 62 |
|
| 63 |
m_namePattern = wxT("m_genericDirCtrl"); |
| 64 |
SetName(GenerateName()); |
| 65 |
} |
| 66 |
|
| 67 |
GenericDirCtrlWrapper::~GenericDirCtrlWrapper() {} |
| 68 |
|
| 69 |
wxcWidget* GenericDirCtrlWrapper::Clone() const { return new GenericDirCtrlWrapper(); } |
| 70 |
|
| 71 |
wxString GenericDirCtrlWrapper::CppCtorCode() const |
| 72 |
{ |
| 73 |
// wxGenericDirCtrl(wxWindow* parent, const wxWindowID id = -1, const wxString& dir = wxDirDialogDefaultFolderStr, |
| 74 |
// const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = |
| 75 |
// wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER, const wxString& filter = wxEmptyString, int defaultFilter = 0, const |
| 76 |
// wxString& name = wxTreeCtrlNameStr) |
| 77 |
wxString code; |
| 78 |
code << GetName() << wxT(" = new ") << GetRealClassName() << wxT("(") << GetWindowParent() << wxT(", ") |
| 79 |
<< WindowID() << wxT(", ") << wxCrafter::WXT(PropertyString(PROP_DEFAULT_FOLDER)) << wxT(", ") |
| 80 |
<< wxT("wxDefaultPosition, ") << SizeAsString() << wxT(", ") |
| 81 |
<< StyleFlags(wxT("wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER")) << wxT(");\n"); |
| 82 |
|
| 83 |
code << CPPCommonAttributes(); |
| 84 |
|
| 85 |
// Set the default path |
| 86 |
wxString path = PropertyString(PROP_DEFAULT_FOLDER); |
| 87 |
|
| 88 |
path.Trim().Trim(false); |
| 89 |
if(path.IsEmpty() == false) { |
| 90 |
code << GetName() << wxT("->SetDefaultPath(") << wxCrafter::WXT(path) << wxT(");\n"); |
| 91 |
} |
| 92 |
|
| 93 |
// Set the filter string |
| 94 |
wxString filter = PropertyString(PROP_FILTER); |
| 95 |
filter.Trim().Trim(false); |
| 96 |
|
| 97 |
if(filter.IsEmpty() == false) { code << GetName() << wxT("->SetFilter(") << wxCrafter::WXT(filter) << wxT(");\n"); } |
| 98 |
|
| 99 |
// Set the filter index |
| 100 |
wxString filterIndex = PropertyString(PROP_DEFAULT_FILTER); |
| 101 |
filterIndex.Trim().Trim(false); |
| 102 |
|
| 103 |
int index = wxCrafter::ToNumber(filterIndex, -1); |
| 104 |
if(-1 != index) { code << GetName() << wxT("->SetFilterIndex(") << index << wxT(");\n"); } |
| 105 |
|
| 106 |
// Show hidden files? |
| 107 |
wxString show = PropertyBool(PROP_SHOW_HIDDEN); |
| 108 |
code << GetName() << wxT("->ShowHidden(") << show << wxT(");\n"); |
| 109 |
|
| 110 |
return code; |
| 111 |
} |
| 112 |
|
| 113 |
void GenericDirCtrlWrapper::GetIncludeFile(wxArrayString& headers) const |
| 114 |
{ |
| 115 |
headers.Add(wxT("#include <wx/dirctrl.h>")); |
| 116 |
} |
| 117 |
|
| 118 |
wxString GenericDirCtrlWrapper::GetWxClassName() const { return wxT("wxGenericDirCtrl"); } |
| 119 |
|
| 120 |
void GenericDirCtrlWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 121 |
{ |
| 122 |
text << XRCPrefix() << XRCCommonAttributes() << XRCSize() << XRCStyle() << wxT("<defaultfolder>") |
| 123 |
<< wxCrafter::CDATA(PropertyString(PROP_DEFAULT_FOLDER)) << wxT("</defaultfolder>") << wxT("<defaultfilter>") |
| 124 |
<< PropertyString(PROP_DEFAULT_FILTER) << wxT("</defaultfilter>") << wxT("<filter>") |
| 125 |
<< wxCrafter::CDATA(PropertyString(PROP_FILTER)) << wxT("</filter>") << XRCSuffix(); |
| 126 |
} |
| 127 |
|
| 128 |
void GenericDirCtrlWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 129 |
{ |
| 130 |
// First call the base-class for the standard things |
| 131 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 132 |
|
| 133 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("defaultfolder")); |
| 134 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_FOLDER, propertynode->GetNodeContent()); } |
| 135 |
|
| 136 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("filter")); |
| 137 |
if(propertynode) { SetPropertyString(PROP_FILTER, propertynode->GetNodeContent()); } |
| 138 |
|
| 139 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("defaultfilter")); |
| 140 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_FILTER, propertynode->GetNodeContent()); } |
| 141 |
} |
| 142 |
|
| 143 |
void GenericDirCtrlWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 144 |
{ |
| 145 |
// First call the base-class for the standard things |
| 146 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 147 |
|
| 148 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("defaultfolder")); |
| 149 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_FOLDER, propertynode->GetNodeContent()); } |
| 150 |
|
| 151 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("filter")); |
| 152 |
if(propertynode) { SetPropertyString(PROP_FILTER, propertynode->GetNodeContent()); } |
| 153 |
|
| 154 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("defaultfilter")); |
| 155 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_FILTER, propertynode->GetNodeContent()); } |
| 156 |
} |
| 157 |
|
| 158 |
void GenericDirCtrlWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 159 |
{ |
| 160 |
// First call the base-class for the standard things |
| 161 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 162 |
|
| 163 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "defaultfolder"); |
| 164 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_FOLDER, propertynode->GetNodeContent()); } |
| 165 |
|
| 166 |
propertynode = XmlUtils::FindNodeByName(node, "property", "filter"); |
| 167 |
if(propertynode) { SetPropertyString(PROP_FILTER, propertynode->GetNodeContent()); } |
| 168 |
|
| 169 |
propertynode = XmlUtils::FindNodeByName(node, "property", "defaultfilter"); |
| 170 |
if(propertynode) { SetPropertyString(PROP_DEFAULT_FILTER, propertynode->GetNodeContent()); } |
| 171 |
|
| 172 |
propertynode = XmlUtils::FindNodeByName(node, "property", "show_hidden"); |
| 173 |
if(propertynode) { |
| 174 |
PropertyBase* prop = GetProperty(PROP_SHOW_HIDDEN); |
| 175 |
if(prop) { prop->SetValue(propertynode->GetNodeContent()); } |
| 176 |
} |
| 177 |
} |