1 /** \file wxssimplehtmllistbox.cpp
2 *
3 * This file is part of wxSmith plugin for Code::Blocks Studio
4 * Copyright (C) 2006-2010 Gary Harris
5 *
6 * wxSmith is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * wxSmith is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <wx/htmllbox.h>
22 #include "wxssimplehtmllistbox.h"
23
24 namespace
25 {
26 wxsRegisterItem<wxsSimpleHtmlListBox> Reg(_T("SimpleHtmlListBox"), wxsTWidget, _T("Standard"), 120);
27
28 WXS_ST_BEGIN(wxsSimpleHtmlListBoxStyles, wxT("wxHLB_DEFAULT_STYLE"))
29 WXS_ST_CATEGORY("wxSimpleHtmlListBox")
30 WXS_ST(wxHLB_DEFAULT_STYLE)
31 WXS_ST(wxHLB_MULTIPLE)
32 WXS_ST(wxLB_EXTENDED)
33 WXS_ST(wxLB_HSCROLL)
34 WXS_ST_DEFAULTS()
35 WXS_ST_END()
36
37 WXS_EV_BEGIN(wxsSimpleHtmlListBoxEvents)
38 WXS_EVI(EVT_LISTBOX, wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEvent, Select)
39 WXS_EVI(EVT_LISTBOX_DCLICK, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEvent, DClick)
40 WXS_EVI(EVT_HTML_CELL_CLICKED, wxEVT_COMMAND_HTML_CELL_CLICKED, wxHtmlCellEvent, CellClicked)
41 WXS_EVI(EVT_HTML_CELL_HOVER, wxEVT_COMMAND_HTML_CELL_HOVER, wxHtmlCellEvent, CellHover)
42 WXS_EVI(EVT_HTML_LINK_CLICKED, wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEvent, LinkClicked)
43 WXS_EV_END()
44 }
45
46 /*! \brief Ctor
47 *
48 * \param Data wxsItemResData* The control's resource data.
49 *
50 */
wxsSimpleHtmlListBox(wxsItemResData * Data)51 wxsSimpleHtmlListBox::wxsSimpleHtmlListBox(wxsItemResData *Data):
52 wxsWidget(
53 Data,
54 &Reg.Info,
55 wxsSimpleHtmlListBoxEvents,
56 wxsSimpleHtmlListBoxStyles),
57 DefaultSelection(-1)
58 {
59 }
60
61 /*! \brief Create the initial control.
62 *
63 * \return void
64 *
65 */
OnBuildCreatingCode()66 void wxsSimpleHtmlListBox::OnBuildCreatingCode()
67 {
68 switch(GetLanguage())
69 {
70 case wxsCPP:
71 {
72 AddHeader(_T("<wx/htmllbox.h>"), GetInfo().ClassName, hfInPCH);
73 Codef(_T("%C(%W, %I, %P, %S, 0, 0, %T, %V, %N);\n"));
74 for(size_t i = 0; i < ArrayChoices.GetCount(); ++i)
75 {
76 if(DefaultSelection == (int)i)
77 {
78 Codef(_T("%ASetSelection( "));
79 }
80 Codef(_T("%AAppend(%t)"), ArrayChoices[i].wx_str());
81 if(DefaultSelection == (int)i)
82 {
83 Codef(_T(" )"));
84 }
85 Codef(_T(";\n"));
86 }
87
88 BuildSetupWindowCode();
89 return;
90 }
91
92 case wxsUnknownLanguage: // fall-through
93 default:
94 {
95 wxsCodeMarks::Unknown(_T("wxsSimpleHtmlListBox::OnBuildCreatingCode"), GetLanguage());
96 }
97 }
98 }
99
100 /*! \brief Build the control preview.
101 *
102 * \param parent wxWindow* The parent window.
103 * \param flags long The control flags.
104 * \return wxObject* The constructed control.
105 *
106 */
OnBuildPreview(wxWindow * Parent,long Flags)107 wxObject *wxsSimpleHtmlListBox::OnBuildPreview(wxWindow *Parent, long Flags)
108 {
109 wxSimpleHtmlListBox *Preview = new wxSimpleHtmlListBox(Parent, GetId(), Pos(Parent), Size(Parent), 0, 0, Style());
110 for(size_t i = 0; i < ArrayChoices.GetCount(); ++i)
111 {
112 int Val = Preview->Append(ArrayChoices[i]);
113 if((int)i == DefaultSelection)
114 {
115 Preview->SetSelection(Val);
116 }
117 }
118
119 return SetupWindow(Preview, Flags);
120 }
121
122 /*! \brief Enumerate the control's properties.
123 *
124 * \param flags long The control flags.
125 * \return void
126 *
127 */
OnEnumWidgetProperties(cb_unused long Flags)128 void wxsSimpleHtmlListBox::OnEnumWidgetProperties(cb_unused long Flags)
129 {
130 WXS_ARRAYSTRING(wxsSimpleHtmlListBox, ArrayChoices, _("Choices"), _T("content"), _T("item"))
131 WXS_LONG(wxsSimpleHtmlListBox, DefaultSelection, _("Default"), _T("default"), 0)
132 }
133