| 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 "wxsSTEditor.h" |
| 21 |
|
| 22 |
//------------------------------------------------------------------------------ |
| 23 |
|
| 24 |
namespace |
| 25 |
{ |
| 26 |
|
| 27 |
// Loading images from xpm files |
| 28 |
|
| 29 |
#include "STE16.xpm" |
| 30 |
#include "STE32.xpm" |
| 31 |
|
| 32 |
wxsRegisterItem<wxsSTEditor> Reg( |
| 33 |
_T("wxSTEditor"), // Class name |
| 34 |
wxsTWidget, // Item type |
| 35 |
_T("wxWindows"), // License |
| 36 |
_T("Ron Collins"), // Author |
| 37 |
_T("[email protected]"), // Author's email |
| 38 |
_T(""), // Item's homepage |
| 39 |
_T("Styled Text"), // Category in palette |
| 40 |
55, // Priority in palette |
| 41 |
_T("STE"), // Base part of names for new items |
| 42 |
wxsCPP, // List of coding languages supported by this item |
| 43 |
1, 0, // Version |
| 44 |
wxBitmap(STE32_xpm), // 32x32 bitmap |
| 45 |
wxBitmap(STE16_xpm), // 16x16 bitmap |
| 46 |
false); // We do not allow this item inside XRC files |
| 47 |
|
| 48 |
|
| 49 |
WXS_ST_BEGIN(wxsSTEditorStyles,_T("wxRE_MULTILINE|wxRAISED_BORDER|wxWANTS_CHARS")) |
| 50 |
WXS_ST_CATEGORY("wxSTEditor") |
| 51 |
|
| 52 |
WXS_ST_DEFAULTS() |
| 53 |
WXS_ST_END() |
| 54 |
|
| 55 |
WXS_EV_BEGIN(wxsSTEditorEvents) |
| 56 |
|
| 57 |
WXS_EVI(EVT_TEXT_ENTER, wxEVT_COMMAND_TEXT_ENTER, wxCommandEvent, EvTextEnter) |
| 58 |
WXS_EVI(EVT_TEXT, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEvent, EvTextUpdated) |
| 59 |
WXS_EVI(EVT_TEXT_URL, wxEVT_COMMAND_TEXT_URL, wxTextUrlEvent, EvTextURL) |
| 60 |
|
| 61 |
WXS_EV_DEFAULTS() |
| 62 |
WXS_EV_END() |
| 63 |
} |
| 64 |
|
| 65 |
//------------------------------------------------------------------------------ |
| 66 |
|
| 67 |
wxsSTEditor::wxsSTEditor(wxsItemResData* Data): |
| 68 |
wxsWidget( |
| 69 |
Data, |
| 70 |
&Reg.Info, |
| 71 |
wxsSTEditorEvents, |
| 72 |
wxsSTEditorStyles) |
| 73 |
{ |
| 74 |
mSize.Set(32, 32); |
| 75 |
mText.Clear(); |
| 76 |
mVirtualSize.IsDefault = true; |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
//------------------------------------------------------------------------------ |
| 81 |
|
| 82 |
void wxsSTEditor::OnBuildCreatingCode() { |
| 83 |
wxString vname; |
| 84 |
wxString aname; |
| 85 |
wxString ss, tt; |
| 86 |
wxColour fg; |
| 87 |
|
| 88 |
// valid language? |
| 89 |
|
| 90 |
if (GetLanguage() != wxsCPP) wxsCodeMarks::Unknown(_T("wxsSTEditor::OnBuildCreatingCode"),GetLanguage()); |
| 91 |
|
| 92 |
// who we are |
| 93 |
|
| 94 |
vname = GetVarName(); |
| 95 |
aname = vname + _T("_Attr"); |
| 96 |
|
| 97 |
// include files |
| 98 |
|
| 99 |
AddHeader(_("\"stedit.h\""), GetInfo().ClassName, 0); |
| 100 |
|
| 101 |
// make our own size specifier with our default values |
| 102 |
|
| 103 |
mSize.SetDefaults(wxSize(32, 32)); |
| 104 |
ss.Printf(_T("wxSize(%d, %d)"), mSize.GetWidth(), mSize.GetHeight()); |
| 105 |
|
| 106 |
// create the panel |
| 107 |
|
| 108 |
Codef(_T("%C(%W, %I, %P, %s, %T, %N);\n"), ss.c_str()); |
| 109 |
|
| 110 |
// other declarations |
| 111 |
|
| 112 |
BuildSetupWindowCode(); |
| 113 |
|
| 114 |
// a virtual size |
| 115 |
|
| 116 |
if (! mVirtualSize.IsDefault) { |
| 117 |
ss = mVirtualSize.GetSizeCode(GetCoderContext()); |
| 118 |
Codef(_T("%ASetVirtualSize(%s);\n"), ss.c_str()); |
| 119 |
}; |
| 120 |
|
| 121 |
// initial text |
| 122 |
|
| 123 |
for(size_t i=0; i<mText.GetCount(); i++) { |
| 124 |
ss = mText.Item(i); |
| 125 |
ss += _T("\n"); |
| 126 |
Codef(_T("%AAppendText(%t);\n"), ss.c_str()); |
| 127 |
}; |
| 128 |
} |
| 129 |
|
| 130 |
//------------------------------------------------------------------------------ |
| 131 |
|
| 132 |
wxObject* wxsSTEditor::OnBuildPreview(wxWindow* Parent, long Flags) { |
| 133 |
wxSTEditor *ste; |
| 134 |
wxColour fg; |
| 135 |
wxString ss; |
| 136 |
wxSize zz; |
| 137 |
|
| 138 |
// the default size of this widget is microscopic |
| 139 |
// use this to make a reasonable default size |
| 140 |
|
| 141 |
mSize = Size(Parent); |
| 142 |
mSize.SetDefaults(wxSize(32, 32)); |
| 143 |
|
| 144 |
// make the basic widget |
| 145 |
|
| 146 |
ste = new wxSTEditor(Parent, GetId(), Pos(Parent), mSize, Style()); |
| 147 |
|
| 148 |
// the rest of the attributtes |
| 149 |
|
| 150 |
SetupWindow(ste, Flags); |
| 151 |
|
| 152 |
// a virtual size |
| 153 |
|
| 154 |
if (! mVirtualSize.IsDefault) { |
| 155 |
zz = mVirtualSize.GetSize(Parent); |
| 156 |
ste->SetVirtualSize(zz); |
| 157 |
}; |
| 158 |
|
| 159 |
// add in initial text |
| 160 |
|
| 161 |
for(size_t i=0; i<mText.GetCount(); i++) { |
| 162 |
ss = mText.Item(i); |
| 163 |
ss += _T("\n"); |
| 164 |
ste->AppendText(ss); |
| 165 |
}; |
| 166 |
|
| 167 |
// done |
| 168 |
|
| 169 |
return ste; |
| 170 |
} |
| 171 |
|
| 172 |
//------------------------------------------------------------------------------ |
| 173 |
|
| 174 |
void wxsSTEditor::OnEnumWidgetProperties(long Flags) { |
| 175 |
|
| 176 |
// initial text contents |
| 177 |
|
| 178 |
WXS_ARRAYSTRING(wxsSTEditor, mText, _("Text"), _("mText"), _("text")); |
| 179 |
WXS_SIZE( wxsSTEditor, mVirtualSize, _T("Default Virtual Size?"), _T("Virtual Width"), _T("Virtual Height"), _T("Use Dialog Units?"), _T("mVirtualSize")); |
| 180 |
|
| 181 |
}; |