Menu

[r135]: / src / insertpanel.cpp  Maximize  Restore  History

Download this file

267 lines (230 with data), 6.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
* Copyright 2005-2007 Gerald Schmidt.
*
* This file is part of Xml Copy Editor.
*
* Xml Copy Editor is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* Xml Copy Editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xml Copy Editor; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "insertpanel.h"
BEGIN_EVENT_TABLE ( InsertPanel, wxPanel )
EVT_TEXT_ENTER ( wxID_ANY, InsertPanel::OnEnter )
EVT_LISTBOX_DCLICK ( wxID_ANY, InsertPanel::OnDoubleClick )
EVT_LISTBOX ( wxID_ANY, InsertPanel::OnListSelection )
EVT_SIZE ( InsertPanel::OnSize )
END_EVENT_TABLE()
InsertPanel::InsertPanel (
wxWindow *parentWindowParameter,
int id,
int typeParameter ) :
wxPanel ( parentWindowParameter, id ), type ( typeParameter ), edit ( 0 ), list ( 0 )
{
parentWindow = ( MyFrame * ) parentWindowParameter;
doc = lastDoc = NULL;
int width = 150;
SetSize ( wxSize ( width, -1 ) );
sizer = new wxBoxSizer ( wxVERTICAL );
SetSizer ( sizer );
edit = new wxTextCtrl (
this,
wxID_ANY,
wxEmptyString,
wxDefaultPosition,
wxDefaultSize,
wxTE_PROCESS_ENTER );
wxFont normalFont = wxSystemSettings::GetFont ( wxSYS_DEFAULT_GUI_FONT );
wxFont boldFont = normalFont;
boldFont.SetWeight ( wxFONTWEIGHT_BOLD );
edit->SetFont ( boldFont );
list = new wxListBox (
this,
wxID_ANY,
wxDefaultPosition,
wxDefaultSize,
0,
NULL,
wxLB_SORT | wxLB_HSCROLL );
sizer->Add ( edit, 0, wxGROW | wxTOP, 0 );
sizer->Add ( list, 0, wxGROW | wxTOP, 0 );
sizer->Layout();
list->Show ( false );
}
void InsertPanel::update (
XmlDoc *docParameter,
const wxString& parentParameter,
const wxString& grandparentParameter )
{
doc = docParameter;
parent = parentParameter;
grandparent = grandparentParameter;
if ( !doc )
{
if ( lastDoc )
{
lastDoc = NULL;
edit->SetValue ( wxEmptyString );
list->Clear();
list->Show ( false );
}
return;
}
bool refreshEntities = false;
if ( doc != lastDoc )
{
refreshEntities = true;
lastDoc = doc;
}
if ( type == INSERT_PANEL_TYPE_ENTITY && refreshEntities )
{
list->Clear();
lastDoc = doc;
std::set<std::string> entitySet = doc->getEntitySet();
entitySet.insert ( "amp" );
entitySet.insert ( "apos" );
entitySet.insert ( "gt" );
entitySet.insert ( "lt" );
entitySet.insert ( "quot" );
std::set<std::string>::iterator it;
for ( it = entitySet.begin(); it != entitySet.end(); it++ )
list->Append ( wxString ( it->c_str(), wxConvUTF8, it->size() ) );
list->Show ( true );
wxSize clientSize = GetClientSize();
wxSize editSize = edit->GetSize();
wxSize listSize =
wxSize ( clientSize.GetWidth(), clientSize.GetHeight() - editSize.GetHeight() );
list->SetSize ( listSize );
list->Update();
//sizer->Layout();
return;
}
if ( parent == lastParent )
return;
lastParent = parent;
if ( type == INSERT_PANEL_TYPE_CHILD ) // ignore for entity/sibling
{
doc->toggleLineBackground();
}
edit->SetValue ( wxEmptyString );
list->Clear();
if ( parent.empty() || ( ( type == INSERT_PANEL_TYPE_SIBLING ) && grandparent.empty() ) )
{
list->Show ( false );
return;
}
std::set<wxString> elementSet;
elementSet = doc->getChildren ( ( type == INSERT_PANEL_TYPE_SIBLING ) ? grandparent : parent );
if ( elementSet.empty() )
{
list->Show ( false );
return;
}
std::set<wxString>::iterator it;
for ( it = elementSet.begin(); it != elementSet.end(); it++ )
list->Append ( *it );
list->Show ( true );
wxSize clientSize = GetClientSize();
wxSize editSize = edit->GetSize();
wxSize listSize =
wxSize ( clientSize.GetWidth(), clientSize.GetHeight() - editSize.GetHeight() );
if ( clientSize.IsFullySpecified() && editSize.IsFullySpecified() )
list->SetSize ( listSize );
list->Update();
}
void InsertPanel::OnEnter ( wxCommandEvent& event )
{
if ( !doc )
return;
wxString choice = edit->GetValue();
if ( choice.empty() )
doc->SetFocus();
else
handleChoice ( choice );
}
void InsertPanel::OnDoubleClick ( wxCommandEvent& event )
{
if ( !doc )
return;
if ( !doc )
return;
wxString choice = list->GetStringSelection();
handleChoice ( choice );
}
void InsertPanel::handleChoice ( const wxString& choice )
{
if ( !doc || choice.empty() )
return;
if ( parentWindow )
parentWindow->closePane();
switch ( type )
{
case INSERT_PANEL_TYPE_SIBLING:
if ( !parent.empty() )
{
if ( !doc->insertSibling ( choice, parent ) && parentWindow )
{
wxString msg;
msg.Printf ( _T ( "Cannot insert sibling '%s'" ), choice.c_str() );
parentWindow->messagePane ( msg, CONST_STOP );
}
}
break;
case INSERT_PANEL_TYPE_CHILD:
if ( !doc->insertChild ( choice ) && parentWindow )
{
wxString msg;
msg.Printf ( _T ( "Cannot insert child '%s'" ), choice.c_str() );
parentWindow->messagePane ( msg, CONST_STOP );
}
break;
case INSERT_PANEL_TYPE_ENTITY:
if ( !doc->insertEntity ( choice ) && parentWindow )
{
wxString msg;
msg.Printf ( _T ( "Cannot insert entity '%s'" ), choice.c_str() );
parentWindow->messagePane ( msg, CONST_STOP );
}
break;
default:
break;
}
doc->setValidationRequired ( true );
doc->SetFocus();
}
void InsertPanel::setEditFocus()
{
if ( !edit )
return;
edit->SetFocus();
}
void InsertPanel::OnListSelection ( wxCommandEvent& event )
{
edit->SetValue ( list->GetStringSelection() );
}
void InsertPanel::OnSize ( wxSizeEvent& e )
{
adjustSize();
e.Skip();
}
void InsertPanel::adjustSize()
{
if ( !list || !edit )
return;
wxSize clientSize = GetClientSize();
wxSize editSize = edit->GetSize();
if ( !clientSize.IsFullySpecified() || !editSize.IsFullySpecified() )
return;
wxSize listSize =
wxSize ( clientSize.GetWidth(), clientSize.GetHeight() - editSize.GetHeight() );
if ( listSize.IsFullySpecified() )
list->SetSizeHints ( listSize, listSize, listSize );
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.