1 /*
2 * This file is part of wxSmith plugin for Code::Blocks Studio
3 * Copyright (C) 2006-2007  Bartlomiej Swiecki
4 *
5 * wxSmith is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * wxSmith is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19 
20 #include "wxsText.h"
21 #include <wxwidgets/wxsitemresdata.h>
22 
23 //------------------------------------------------------------------------------
24 
25 namespace
26 {
27 
28 // Loading images from xpm files
29 
30     #include "images/text16.xpm"
31     #include "images/text32.xpm"
32 
33     wxsRegisterItem<wxsText> Reg(
34         _T("mpText"),                 // Class name
35         wxsTWidget,                     // Item type
36         _T("wxWindows"),                // License
37         _T("Ron Collins"),              // Author
38         _T("rcoll@theriver.com"),       // Author's email
39         _T(""),                         // Item's homepage
40         _T("MathPlot"),                 // Category in palette
41         60,                             // Priority in palette
42         _T("Marker"),                   // Base part of names for new items
43         wxsCPP,                         // List of coding languages supported by this item
44         1, 0,                           // Version
45         wxBitmap(text32_xpm),         // 32x32 bitmap
46         wxBitmap(text16_xpm),         // 16x16 bitmap
47         false);                         // We do not allow this item inside XRC files
48 
49 
50     WXS_ST_BEGIN(wxsTextStyles,_T(""))
51         WXS_ST_CATEGORY("mpText")
52         WXS_ST(wxST_NO_AUTORESIZE)
53         WXS_ST(wxALIGN_LEFT)
54         WXS_ST(wxALIGN_RIGHT)
55         WXS_ST(wxALIGN_CENTRE)
56         WXS_ST_DEFAULTS()
57     WXS_ST_END()
58 
59     WXS_EV_BEGIN(wxsTextEvents)
60     WXS_EV_END()
61 
62 }
63 
64 //------------------------------------------------------------------------------
65 
wxsText(wxsItemResData * Data)66 wxsText::wxsText(wxsItemResData* Data):
67     wxsWidget(
68         Data,
69         &Reg.Info,
70         wxsTextEvents,
71         wxsTextStyles)
72 {
73     mLabel = _("*");
74     mXpos  = _("0.0");
75     mYpos  = _("0.0");
76 }
77 
78 //------------------------------------------------------------------------------
79 //
80 // need to set line color and style
81 
OnBuildCreatingCode()82 void wxsText::OnBuildCreatingCode() {
83 wxString    vname;
84 wxString    pname;
85 wxString    cname;
86 wxString    fname;
87 wxString    xname;
88 wxString    yname;
89 wxString    dtext;
90 wxString    s;
91 
92 // we only know C++ language
93 
94     if (GetLanguage() != wxsCPP) wxsCodeMarks::Unknown(_T("wxsText::OnBuildCreatingCode"),GetLanguage());
95 
96 // usefull names
97 
98     vname = GetVarName();
99     pname = GetParent()->GetVarName();
100     cname = vname + _("_PEN");
101     fname = vname + _("_FONT");
102 
103 // the header for mathplot
104 
105     AddHeader(_T("<mathplot.h>"),GetInfo().ClassName,hfInPCH);
106 
107 // create the vector -- but not the setup code
108 
109     Codef(_T("%s = new mpText(%t, %s, %s);\n"), vname.wx_str(), mLabel.wx_str(), mXpos.wx_str(), mYpos.wx_str());
110 //  BuildSetupWindowCode();
111 
112 // assign a pen to the layer
113 
114     dtext = mPenColour.BuildCode(GetCoderContext());
115     if (dtext.Len() > 0) {
116         Codef(_T("wxPen   %s(%s);\n"), cname.wx_str(), dtext.wx_str());
117         Codef(_T("%s->SetPen(%s);\n"), vname.wx_str(), cname.wx_str());
118     };
119 
120 // assign a font to the layer
121 
122     dtext = mPenFont.BuildFontCode(fname, GetCoderContext());
123     if (dtext.Len() > 0) {
124         Codef(_T("%s"), dtext.wx_str());
125         Codef(_T("%s->SetFont(%s);\n"), vname.wx_str(), fname.wx_str());
126     };
127 
128 // add to parent window -- should be a mpWindow
129 
130     if ((GetPropertiesFlags() & flHidden) && GetBaseProps()->m_Hidden)
131         ; // do nothing
132     else
133         Codef(_T("%s->AddLayer(%s);\n"), pname.wx_str(), vname.wx_str());
134 
135 
136 }
137 
138 //------------------------------------------------------------------------------
139 
OnBuildPreview(wxWindow * Parent,long Flags)140 wxObject* wxsText::OnBuildPreview(wxWindow* Parent, long Flags) {
141 wxStaticText    *Preview;
142 mpText        *mk;
143 mpWindow        *mp;
144 wxPen           pen;
145 wxColour        cc;
146 wxFont          ff;
147 bool            hide;
148 double          xp, yp;
149 
150 // if parent is not an mpWindow, then exit out
151 
152     if (! Parent->IsKindOf(CLASSINFO(mpWindow))) return NULL;
153     mp = (mpWindow *) Parent;
154 
155 // hide this marker
156 
157     hide = ((Flags & pfExact) && (GetPropertiesFlags() & flHidden) && GetBaseProps()->m_Hidden);
158 
159 // make the place-holder
160 
161     Preview = new wxStaticText(Parent, GetId(), mLabel, Pos(Parent), Size(Parent), (wxSUNKEN_BORDER|Style()));
162     Preview->SetForegroundColour(wxColour(255,255,255));
163     Preview->SetBackgroundColour(wxColour(0,128,0));
164     SetupWindow(Preview,Flags);
165     if (Flags & pfExact) Preview->Hide();
166 
167 // pen color
168 
169     cc = mPenColour.GetColour();
170     if (cc.IsOk()) pen.SetColour(cc);
171 
172 // text font
173 
174     ff = mPenFont.BuildFont();
175 
176 // update the place-holder
177 
178     if (cc.IsOk()) Preview->SetBackgroundColour(cc);
179     Preview->SetFont(ff);
180 
181 // X & Y position
182 
183     if (! mXpos.ToDouble(&xp)) {
184         xp = 0.0;
185         mXpos = _("0.0");
186     };
187     if (! mYpos.ToDouble(&yp)) {
188         yp = 0.0;
189         mYpos = _("0.0");
190     };
191 
192 // the actual marker
193 
194     mk = new mpText(mLabel, xp, yp);
195     mk->SetPen(pen);
196     mk->SetFont(ff);
197 
198 // and add layer to parent
199 
200     if (! hide) mp->AddLayer(mk);
201 
202 // done
203 
204     return Preview;
205 }
206 
207 //------------------------------------------------------------------------------
208 // declare the var as a simple wxPanel
209 
OnBuildDeclarationsCode()210 void wxsText::OnBuildDeclarationsCode() {
211 
212     if (GetLanguage() == wxsCPP) {
213         AddDeclaration(_T("mpText   *") + GetVarName() + _T(";"));
214     }
215     else {
216         wxsCodeMarks::Unknown(_T("wxsText::OnBuildDeclarationsCode"),GetLanguage());
217     };
218 }
219 
220 
221 
222 
223 //------------------------------------------------------------------------------
224 
OnEnumWidgetProperties(cb_unused long Flags)225 void wxsText::OnEnumWidgetProperties(cb_unused long Flags) {
226 
227     WXS_SHORT_STRING(wxsText, mLabel,      _("Marker Text"),     _("mLabelText"),  _("*"), true);
228     WXS_SHORT_STRING(wxsText, mXpos,       _("X Position"),      _("mXpos"),       _("0.0"), true);
229     WXS_SHORT_STRING(wxsText, mYpos,       _("Y Position"),      _("mYpos"),       _("0.0"), true);
230     WXS_COLOUR(      wxsText, mPenColour,  _("Pen Colour"),      _("mPenColour"));
231     WXS_FONT(        wxsText, mPenFont,    _("Pen Font"),        _("mPenFont"));
232 }
233