]> git.saurik.com Git - wxWidgets.git/blame - utils/configtool/src/propeditor.cpp
Added first cut wxWindows Configuration Tool
[wxWidgets.git] / utils / configtool / src / propeditor.cpp
CommitLineData
d7463f75
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: propeditor.cpp
3// Purpose: wxWindows Configuration Tool property editor
4// Author: Julian Smart
5// Modified by:
6// Created: 2003-06-03
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence:
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "propeditor.h"
14#endif
15
16#include <wx/wx.h>
17
18#ifdef __BORLANDC__
19#pragma hdrstop
20#endif
21
22#include "wx/html/htmlwin.h"
23#include "wx/grid.h"
24#include "wx/filedlg.h"
25#include "wx/tokenzr.h"
26#include "wx/valgen.h"
27
28#include "propeditor.h"
29#include "symbols.h"
30#include "utils.h"
31#include "configtooldoc.h"
32#include "configitemselector.h"
33#include "bitmaps/ellipsis.xpm"
34
35
36/*!
37 * A container window for the property editor.
38 * and attribute editor.
39 */
40
41IMPLEMENT_CLASS(ctPropertyEditor, wxPanel)
42
43BEGIN_EVENT_TABLE(ctPropertyEditor, wxPanel)
44 EVT_BUTTON(ctID_ATTRIBUTE_EDITOR_EDIT_DETAILS, ctPropertyEditor::OnEditDetails)
45 EVT_GRID_SELECT_CELL(ctPropertyEditor::OnSelectCell)
46 EVT_GRID_CELL_CHANGE(ctPropertyEditor::OnChangeCell)
47 EVT_GRID_CELL_LEFT_DCLICK(ctPropertyEditor::OnDClickCell)
48 EVT_UPDATE_UI(ctID_ATTRIBUTE_EDITOR_EDIT_DETAILS, ctPropertyEditor::OnUpdateEditDetails)
49END_EVENT_TABLE()
50
51ctPropertyEditor::ctPropertyEditor(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
52 wxPanel(parent, id, pos, size, style)
53{
54 m_splitterWindow = NULL;
55 m_attributeEditorGrid = NULL;
56 m_propertyDescriptionWindow = NULL;
57 m_elementTitleTextCtrl = NULL;
58
59 CreateControls(this);
60}
61
62ctPropertyEditor::~ctPropertyEditor()
63{
64}
65
66void ctPropertyEditor::CreateControls(wxWindow* parent)
67{
68 m_elementTitleTextCtrl = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
69 wxBitmap detailsIcon(ellipsis_xpm);
70
71 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
72
73 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
74
75 wxTextCtrl *item2 = m_elementTitleTextCtrl;
76 item1->Add( item2, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
77
78 wxButton *item3a = new wxButton( parent, ctID_ATTRIBUTE_EDITOR_EDIT_DETAILS, wxT("Edit..."), wxDefaultPosition, wxSize(-1, -1));
79 item1->Add( item3a, 0, wxALIGN_CENTRE|wxRIGHT|wxTOP|wxBOTTOM, 5 );
80
81 item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5 );
82
83 // TODO: find sash pos from last time
84 int sashPos = 100;
85
86 m_splitterWindow = new wxSplitterWindow(parent, ctID_PROPERTY_EDITOR_SPLITTER, wxDefaultPosition, wxSize(500, 400), wxSP_3DSASH|wxSP_FULLSASH/*|wxCLIP_CHILDREN*/ |wxBORDER_NONE|wxNO_FULL_REPAINT_ON_RESIZE);
87 m_splitterWindow->SetMinimumPaneSize(10);
88
89 m_propertyDescriptionWindow = new wxHtmlWindow(m_splitterWindow, ctID_ATTRIBUTE_EDITOR_DESCRIPTION, wxDefaultPosition, wxSize(200, 60), wxSUNKEN_BORDER);
90 m_propertyDescriptionWindow->SetBackgroundColour(ctDESCRIPTION_BACKGROUND_COLOUR);
91 m_propertyDescriptionWindow->SetBorders(4);
92 m_attributeEditorGrid = new ctPropertyEditorGrid(m_splitterWindow, ctID_ATTRIBUTE_EDITOR_GRID , wxPoint(0, 0), wxSize(200, 100), wxBORDER_SUNKEN | wxWANTS_CHARS);
93
94 m_splitterWindow->SplitHorizontally(m_propertyDescriptionWindow, m_attributeEditorGrid, sashPos);
95
96 // TODO: show or hide description window
97// if (some-setting)
98// ShowDescriptionWindow(FALSE);
99
100 item0->Add( m_splitterWindow, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
101
102 this->SetAutoLayout( TRUE );
103 this->SetSizer( item0 );
104
105 /// Add help text
106 m_elementTitleTextCtrl->SetHelpText(_("The title of the property being edited."));
107 FindWindow(ctID_ATTRIBUTE_EDITOR_EDIT_DETAILS)->SetHelpText(_("Click to use an appropriate editor for the selected property (if any)."));
108 FindWindow(ctID_ATTRIBUTE_EDITOR_GRID)->SetHelpText(_("Shows the properties of the selected item."));
109 FindWindow(ctID_ATTRIBUTE_EDITOR_DESCRIPTION)->SetHelpText(_("Shows a description of the selected property, or a summary of the whole item."));
110
111 /// Set up the grid to display properties
112 m_attributeEditorGrid->RegisterDataType(ctGRID_VALUE_STRING,
113 new wxGridCellStringRenderer,
114 new ctGridCellTextEditor);
115
116 m_attributeEditorGrid->CreateGrid( 0, 2, wxGrid::wxGridSelectRows );
117 m_attributeEditorGrid->SetRowLabelSize(0);
118 m_attributeEditorGrid->SetColLabelSize(0 /* 18 */);
119
120 wxArrayString columns;
121 columns.Add(_T("Name"));
122 columns.Add(_T("Value"));
123
124 m_attributeEditorGrid->SetColSize(0, 140);
125 m_attributeEditorGrid->SetColSize(1, 80);
126
127 m_attributeEditorGrid->SetColumnsToDisplay(columns);
128 m_attributeEditorGrid->DisplayLabels();
129
130 m_attributeEditorGrid->SetStretchableColumn(1);
131
132 m_attributeEditorGrid->SetDefaultCellBackgroundColour(ctCELL_BACKGROUND_COLOUR);
133
134 UpdateDescription();
135}
136
137/// Show/hide the description control
138void ctPropertyEditor::ShowDescriptionWindow(bool show)
139{
140 if (!show)
141 {
142 if (m_splitterWindow->IsSplit())
143 m_splitterWindow->Unsplit(m_propertyDescriptionWindow);
144 }
145 else
146 {
147 // TODO
148 int pos = 100;
149 m_propertyDescriptionWindow->Show(TRUE);
150 if (!m_splitterWindow->IsSplit())
151 {
152 m_splitterWindow->SplitHorizontally(m_propertyDescriptionWindow, m_attributeEditorGrid, pos);
153 }
154 }
155}
156
157/// Clear grid editor
158void ctPropertyEditor::ClearEditor()
159{
160 m_attributeEditorGrid->ClearAttributes();
161 m_propertyDescriptionWindow->SetPage(WrapDescription(wxEmptyString));
162 m_elementTitleTextCtrl->SetValue(_T(""));
163}
164
165/// Handles detailed editing event.
166void ctPropertyEditor::OnEditDetails(wxCommandEvent& event)
167{
168 wxWindow* parentFrame = this;
169 while (parentFrame && !parentFrame->IsKindOf(CLASSINFO(wxFrame)))
170 parentFrame = parentFrame->GetParent();
171
172 EditDetails(parentFrame);
173}
174
175/// Handles detailed editing update event.
176void ctPropertyEditor::OnUpdateEditDetails(wxUpdateUIEvent& event)
177{
178 event.Enable(CanEditDetails());
179}
180
181/// Can we edit the details of the selected property?
182bool ctPropertyEditor::CanEditDetails()
183{
184 if (!m_item)
185 return FALSE;
186
187 int row;
188 ctProperty* prop = FindSelectedProperty(row);
189 if (!prop || prop->GetEditorType().IsEmpty())
190 return FALSE;
191 return TRUE;
192}
193
194/// Shows the item
195void ctPropertyEditor::ShowItem(ctConfigItem* item)
196{
197 if (m_attributeEditorGrid->IsCellEditControlEnabled())
198 m_attributeEditorGrid->SaveEditControlValue();
199
200 ClearEditor();
201 if (item)
202 {
203 m_item = item;
204
205 UpdateTitle();
206
207 m_attributeEditorGrid->AppendRows(m_item->GetProperties().GetCount());
208
209 wxNode* node = m_item->GetProperties().GetList().GetFirst();
210 int i = 0;
211 while (node)
212 {
213 ctProperty* prop = (ctProperty*) node->GetData();
214 DisplayProperty(i, prop);
215
216 i ++;
217 node = node->GetNext();
218 }
219 // Make sure scrollbars are up-to-date, etc.
220 wxSizeEvent event(m_attributeEditorGrid->GetSize(), m_attributeEditorGrid->GetId());
221 m_attributeEditorGrid->GetEventHandler()->ProcessEvent(event);
222
223 DisplayDefaultProperty();
224 }
225 else
226 {
227 m_item = NULL;
228 }
229}
230
231/// Determine background colour for this property.
232void ctPropertyEditor::DeterminePropertyColour(ctProperty* prop, wxColour& colour)
233{
234 if (prop->IsCustom())
235 colour = ctCUSTOM_CELL_BACKGROUND_COLOUR;
236 else
237 colour = ctCELL_BACKGROUND_COLOUR;
238}
239
240/// Update the title at the top of the property editor
241void ctPropertyEditor::UpdateTitle()
242{
243 if (m_item)
244 {
245 wxString name(m_item->GetTitle());
246 m_elementTitleTextCtrl->SetValue(name);
247 }
248}
249
250/// Updates the item display, assuming it was already displayed.
251void ctPropertyEditor::UpdateItem()
252{
253 if (m_attributeEditorGrid->IsCellEditControlEnabled())
254 m_attributeEditorGrid->SaveEditControlValue();
255 if (m_item)
256 {
257 UpdateTitle();
258
259 wxNode* node = m_item->GetProperties().GetList().GetFirst();
260 int i = 0;
261 while (node)
262 {
263 ctProperty* prop = (ctProperty*) node->GetData();
264 DisplayProperty(i, prop, TRUE);
265
266 i ++;
267 node = node->GetNext();
268 }
269 // Make sure scrollbars are up-to-date, etc.
270 wxSizeEvent event(m_attributeEditorGrid->GetSize(), this->GetId());
271 m_attributeEditorGrid->GetEventHandler()->ProcessEvent(event);
272 }
273}
274
275/// Display attribute at given row
276bool ctPropertyEditor::DisplayProperty(int row, ctProperty* prop, bool valueOnly)
277{
278 wxColour backgroundColour;
279
280 DeterminePropertyColour(prop, backgroundColour);
281
282 if (!valueOnly)
283 {
284 m_attributeEditorGrid->SetCellBackgroundColour(row, 0, backgroundColour);
285 m_attributeEditorGrid->SetCellBackgroundColour(row, 1, backgroundColour);
286
287 m_attributeEditorGrid->SetCellValue(row, 0, prop->GetName());
288
289 m_attributeEditorGrid->SetReadOnly(row, 0);
290 // Set the alignment
291 m_attributeEditorGrid->SetCellAlignment(row, 1, wxALIGN_LEFT, wxALIGN_CENTER);
292 }
293
294 if (!m_item->CanEditProperty(prop->GetName()))
295 {
296 m_attributeEditorGrid->SetReadOnly(row, 1);
297
298 wxColour col(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
299 m_attributeEditorGrid->SetCellTextColour(row, 1, col);
300 }
301 else
302 {
303 m_attributeEditorGrid->SetReadOnly(row, 1, FALSE);
304 m_attributeEditorGrid->SetCellTextColour(row, 1, * wxBLACK);
305 }
306
307 // Set the value
308 m_attributeEditorGrid->SetCellValue(row, 1, ctConvertToSingleText(prop->GetValue()));
309
310 if (valueOnly)
311 return TRUE;
312
313 // Set the value type
314 if (prop->GetEditorType() == _T("choice"))
315 {
316 wxString* strArr = prop->GetChoices().GetStringArray();
317
318 m_attributeEditorGrid->SetCellEditor(row, 1,
319 new wxGridCellChoiceEditor(prop->GetChoices().GetCount(), strArr));
320
321 delete[] strArr;
322 }
323 else if (prop->GetEditorType() == _T("integer") || prop->GetVariant().GetType() == _T("long"))
324 {
325 m_attributeEditorGrid->SetCellEditor(row, 1,
326 new wxGridCellNumberEditor);
327 }
328 else if (prop->GetEditorType() == _T("float") || prop->GetVariant().GetType() == _T("double"))
329 {
330 m_attributeEditorGrid->SetCellEditor(row, 1,
331 new wxGridCellFloatEditor);
332 }
333 else if (prop->GetEditorType() == _T("bool") || prop->GetVariant().GetType() == _T("bool"))
334 {
335 m_attributeEditorGrid->SetCellValue(row, 1, prop->GetVariant().GetBool() ? _T("1") : _T("0"));
336 m_attributeEditorGrid->SetCellEditor(row, 1,
337 new wxGridCellBoolEditor);
338 m_attributeEditorGrid->SetCellRenderer(row, 1, new wxGridCellBoolRenderer);
339 }
340 else
341 {
342 m_attributeEditorGrid->SetCellEditor(row, 1,
343 new ctGridCellTextEditor);
344 }
345
346 return TRUE;
347}
348
349/// Display attribute value
350bool ctPropertyEditor::DisplayProperty(ctProperty* prop)
351{
352 if (!m_item)
353 return FALSE;
354
355 int index = m_item->GetProperties().GetList().IndexOf(prop);
356 return DisplayProperty(index, prop, TRUE);
357}
358
359/// Display the default property
360bool ctPropertyEditor::DisplayDefaultProperty()
361{
362 if (!m_item)
363 return FALSE;
364
365 wxString str = m_item->GetDefaultProperty();
366
367 ctProperty* prop = m_item->GetProperties().FindProperty(str);
368 if (prop)
369 {
370 int index = m_item->GetProperties().GetList().IndexOf(prop);
371 this->m_attributeEditorGrid->SelectRow(index);
372 this->m_attributeEditorGrid->SetGridCursor(index, 1);
373 }
374 return TRUE;
375}
376
377/// Edit the default property
378bool ctPropertyEditor::EditDefaultProperty(ctConfigItem* item)
379{
380 wxString defaultPropertyName = item->GetDefaultProperty();
381 if (!defaultPropertyName.IsEmpty())
382 {
383 ctProperty* prop = item->GetProperties().FindProperty(defaultPropertyName);
384 if (prop)
385 {
386 int index = item->GetProperties().GetList().IndexOf(prop);
387 if (index >= 0)
388 {
389 this->m_attributeEditorGrid->SelectRow(index);
390 this->m_attributeEditorGrid->SetGridCursor(index, 1);
391 EditDetails(wxTheApp->GetTopWindow());
392 return TRUE;
393 }
394 }
395
396 }
397 return FALSE;
398}
399
400/// Find the selected property
401ctProperty* ctPropertyEditor::FindSelectedProperty(int& row)
402{
403 if (!m_item)
404 return NULL;
405
406 int selRow = m_attributeEditorGrid->GetCursorRow();
407 if (selRow > -1)
408 {
409 row = selRow;
410
411 if (selRow < (int) m_item->GetProperties().GetCount())
412 {
413 ctProperty* prop = m_item->GetProperties().GetNth(selRow);
414 return prop;
415 }
416 }
417 return NULL;
418}
419
420/// Find the property
421ctProperty* ctPropertyEditor::FindProperty(int row)
422{
423 if (!m_item)
424 return NULL;
425
426 if (row > -1)
427 {
428 if (row < (int) m_item->GetProperties().GetCount())
429 {
430 ctProperty* prop = m_item->GetProperties().GetNth(row);
431 return prop;
432 }
433 }
434 return NULL;
435}
436
437/// Edit the details of this cell appropriately.
438bool ctPropertyEditor::EditDetails(wxWindow* parent)
439{
440 if (CanEditDetails())
441 {
442 int row;
443 ctProperty* prop = FindSelectedProperty(row);
444 if (!prop)
445 return FALSE;
446
447 wxString type(prop->GetEditorType());
448 wxString value = m_attributeEditorGrid->GetCellValue(row, 1);
449
450 if (type == _T("multiline"))
451 {
452 value = ctConvertToMultilineText(value);
453 wxString msg;
454 msg.Printf(wxT("Edit %s:"), (const wxChar*) prop->GetName());
455 ctMultiLineTextEditor dialog(wxTheApp->GetTopWindow(),
456 -1, wxT("Edit Text Property"), msg, value);
457 if (dialog.ShowModal() == wxID_OK)
458 {
459 value = ctConvertToSingleText(dialog.GetText());
460 m_attributeEditorGrid->SetCellValue(row, 1, value);
461 ApplyCellValueToProperty(row, 1);
462 return TRUE;
463 }
464 else
465 return FALSE;
466 }
467 else if (type == _T("filename"))
468 {
469 wxString fullPath = value;
470 wxString defaultDir ;
471 wxString defaultFilename = wxFileNameFromPath(fullPath);
472
473 defaultDir = wxPathOnly(value);
474
475 wxString msg = wxT("Choose a filename");
476 wxFileDialog dialog(wxTheApp->GetTopWindow(),
477 msg, defaultDir, defaultFilename, wxT("*.*"));
478 if (dialog.ShowModal() == wxID_OK)
479 {
480 fullPath = dialog.GetPath();
481 value = fullPath;
482
483 m_attributeEditorGrid->SetCellValue(row, 1, value);
484 ApplyCellValueToProperty(row, 1);
485 return TRUE;
486 }
487 else
488 return FALSE;
489 }
490 else if (type == _T("configitems"))
491 {
492 wxArrayString items;
493 ctConfigItem::StringToArray(value, items);
494
495 ctConfigItemsSelector dialog(wxTheApp->GetTopWindow(),
496 -1, wxT("Select Configuration Items"));
497 dialog.SetConfigList(items);
498 if (dialog.ShowModal() == wxID_OK)
499 {
500 wxString newValue;
501 items = dialog.GetConfigList();
502 ctConfigItem::ArrayToString(items, newValue);
503
504 m_attributeEditorGrid->SetCellValue(row, 1, newValue);
505 ApplyCellValueToProperty(row, 1);
506 return TRUE;
507 }
508 else
509 return FALSE;
510 }
511 }
512
513 return FALSE;
514}
515
516/// Intercept selection event.
517void ctPropertyEditor::OnSelectCell(wxGridEvent& event)
518{
519 int row = event.GetRow();
520
521 UpdateDescription(row);
522
523 event.Skip();
524}
525
526/// Update the description
527void ctPropertyEditor::UpdateDescription(int row)
528{
529 if (row == -1)
530 {
531 row = m_attributeEditorGrid->GetCursorRow();
532 }
533 if (row == -1)
534 {
535 wxString str = WrapDescription(wxEmptyString);
536 m_propertyDescriptionWindow->SetPage(str);
537 }
538 else
539 {
540 ctProperty* prop = FindProperty(row);
541 if (prop)
542 {
543 wxString str = WrapDescription(m_item->GetDescription(prop));
544 m_propertyDescriptionWindow->SetPage(str);
545 }
546 }
547}
548
549/// Wraps a description string in HTML
550wxString ctPropertyEditor::WrapDescription(const wxString& s)
551{
552 /// Convert a colour to a 6-digit hex string
553 wxColour col = ctDESCRIPTION_BACKGROUND_COLOUR;
554 wxString colStr = apColourToHexString(col);
555 colStr = wxT("#") + colStr;
556
557 wxString str;
558 str << _T("<HTML><BODY BGCOLOR=\"") << colStr << wxT("\"><FONT SIZE=-1>") ;
559 str << s;
560 str << _T("</FONT></BODY></HTML>");
561
562 return str;
563}
564
565/// Intercept cell data change event.
566void ctPropertyEditor::OnChangeCell(wxGridEvent& event)
567{
568 int row = event.GetRow();
569 int col = event.GetCol();
570
571 ApplyCellValueToProperty(row, col);
572}
573
574/// Double-click to show specialised editor.
575void ctPropertyEditor::OnDClickCell(wxGridEvent& event)
576{
577 wxWindow* parentFrame = this;
578 while (parentFrame && !parentFrame->IsKindOf(CLASSINFO(wxFrame)))
579 parentFrame = parentFrame->GetParent();
580
581 EditDetails(parentFrame);
582}
583
584/// Apply the cell value to the property, and notify the
585/// item object.
586void ctPropertyEditor::ApplyCellValueToProperty(int row, int col)
587{
588 static bool s_Applying = FALSE;
589
590 if (s_Applying)
591 return;
592
593 s_Applying = TRUE;
594 if (col == 1 && m_item)
595 {
596 ctProperty* prop = m_item->GetProperties().GetNth(row);
597
598 wxString value = m_attributeEditorGrid->GetCellValue(row, col);
599 if (prop->GetEditorType() == wxT("multiline"))
600 value = ctConvertToMultilineText(value);
601
602 wxVariant variant = prop->GetVariant();
603
604 if (prop->GetVariant().GetType() == _T("bool"))
605 {
606 if (value == _T("1"))
607 variant = (bool) TRUE;
608 else
609 variant = (bool) FALSE;
610 }
611 else if (prop->GetVariant().GetType() == _T("long"))
612 {
613 long l;
614 value.ToLong(& l);
615 variant = l;
616 }
617 else if (prop->GetVariant().GetType() == _T("double"))
618 {
619 double d;
620 value.ToDouble(& d);
621 variant = d;
622 }
623 else
624 {
625 variant = value;
626 }
627
628 ApplyPropertyValue(m_item, prop, variant);
629
630 if (prop->GetName() == _T("description"))
631 UpdateDescription(row);
632 }
633 s_Applying = FALSE;
634}
635
636/// Apply the cell value to the property, and notify the
637/// item object.
638void ctPropertyEditor::ApplyPropertyValue(ctConfigItem* item, ctProperty* property, const wxVariant& variant)
639{
640 static bool s_Applying = FALSE;
641
642 if (s_Applying)
643 return;
644
645 s_Applying = TRUE;
646
647 // Save the old values
648 ctProperties* oldProperties = new ctProperties(item->GetProperties());
649
650 wxVariant oldValue = property->GetVariant();
651
652 // Apply the new value
653 property->GetVariant() = variant;
654 item->ApplyProperty(property, oldValue);
655 item->Modify();
656
657 UpdateItem();
658
659 wxString menuLabel(_T("Change ") + property->GetName());
660
661 // This won't do anything first time Do is applied,
662 // since we've already done the action for this property.
663 // But when we Undo or Redo, the changed properties will be applied.
664 item->GetDocument()->GetCommandProcessor()->Submit(
665 new ctConfigCommand(menuLabel, ctCMD_APPLY_PROPERTY,
666 item, oldProperties, TRUE));
667
668 s_Applying = FALSE;
669}
670
671/*!
672 * Attribute editor grid
673 */
674
675IMPLEMENT_CLASS(ctPropertyEditorGrid, wxGrid)
676
677BEGIN_EVENT_TABLE(ctPropertyEditorGrid, wxGrid)
678 EVT_SIZE(ctPropertyEditorGrid::OnSize)
679END_EVENT_TABLE()
680
681ctPropertyEditorGrid::ctPropertyEditorGrid(wxWindow* parent, wxWindowID id,
682 const wxPoint& pos,
683 const wxSize& sz, long style):
684 wxGrid(parent, id, pos, sz, style)
685
686{
687 m_stretchableColumn = -1;
688}
689
690void ctPropertyEditorGrid::OnSize(wxSizeEvent& event)
691{
692 if (m_stretchableColumn != -1)
693 {
694 // This window's client size = the internal window's
695 // client size if it has no borders
696 wxSize sz = GetClientSize();
697
698 int totalSize = 0;
699 int i;
700 for (i = 0; i < GetNumberCols(); i ++)
701 {
702 if (i != m_stretchableColumn)
703 {
704 totalSize += GetColSize(i);
705 }
706 }
707
708 // Allow for grid lines
709 totalSize += 1;
710
711 int stretchSize = wxMax(5, sz.x - totalSize);
712 SetColSize(m_stretchableColumn, stretchSize);
713 }
714
715 event.Skip();
716}
717
718/// Use m_columnsToDisplay to set the label strings
719void ctPropertyEditorGrid::DisplayLabels()
720{
721 size_t i;
722 for (i = 0; i < m_columnsToDisplay.GetCount(); i++)
723 {
724 SetColLabelValue(i, m_columnsToDisplay[i]);
725 }
726}
727
728/// Clear attributes
729bool ctPropertyEditorGrid::ClearAttributes()
730{
731 if (GetNumberRows() > 0)
732 DeleteRows(0, GetNumberRows());
733 return TRUE;
734}
735
736/*!
737 * Use a single-line text control.
738 */
739
740void ctGridCellTextEditor::Create(wxWindow* parent, wxWindowID id,
741 wxEvtHandler* evtHandler)
742{
743 m_control = new wxTextCtrl(parent, id, wxEmptyString,
744 wxDefaultPosition, wxDefaultSize
745 );
746
747 wxGridCellEditor::Create(parent, id, evtHandler);
748}
749
750
751/// Translate the value to one which can be edited in a single-line
752/// text control
753wxString ctConvertToSingleText(const wxString& value)
754{
755 wxString value1(value);
756 value1.Replace(wxT("\n"), wxT("\\n"));
757 value1.Replace(wxT("\t"), wxT("\\t"));
758 return value1;
759}
760
761/// Translate back to 'real' characters, i.e. newlines are real
762/// newlines.
763wxString ctConvertToMultilineText(const wxString& value)
764{
765 wxString value1(value);
766 value1.Replace(wxT("\\n"), wxT("\n"));
767 value1.Replace(wxT("\\t"), wxT("\t"));
768 return value1;
769}
770
771//----------------------------------------------------------------------------
772// ctMultiLineTextEditor
773//----------------------------------------------------------------------------
774
775BEGIN_EVENT_TABLE(ctMultiLineTextEditor, wxDialog)
776END_EVENT_TABLE()
777
778ctMultiLineTextEditor::ctMultiLineTextEditor( wxWindow *parent, wxWindowID id, const wxString &title,
779 const wxString& msg,
780 const wxString& value,
781 const wxPoint& pos,
782 const wxSize& size,
783 long style):
784 wxDialog(parent, id, title, pos, size, style)
785{
786 m_text = value;
787 AddControls(this, msg);
788 Centre();
789}
790
791bool ctMultiLineTextEditor::AddControls(wxWindow* parent, const wxString& msg)
792{
793 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
794
795 wxBoxSizer *item1 = new wxBoxSizer( wxVERTICAL );
796
797 wxStaticText *item2 = new wxStaticText( parent, wxID_STATIC, msg, wxDefaultPosition, wxDefaultSize, 0 );
798 item1->Add( item2, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT, 5 );
799
800 wxTextCtrl *item3 = new wxTextCtrl( parent, -1, wxT(""), wxDefaultPosition, wxSize(330,180), wxTE_MULTILINE|wxTE_RICH );
801 item1->Add( item3, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
802
803 wxBoxSizer *item4 = new wxBoxSizer( wxHORIZONTAL );
804
805 item4->Add( 5, 5, 1, wxALIGN_CENTRE|wxALL, 5 );
806
807 wxButton *item5 = new wxButton( parent, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
808 item5->SetDefault();
809 item4->Add( item5, 0, wxALIGN_CENTRE|wxALL, 5 );
810
811 wxButton *item6 = new wxButton( parent, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
812 item4->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
813
814 item1->Add( item4, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5 );
815
816 item0->Add( item1, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
817
818 item3->SetValue(m_text);
819 item3->SetValidator(wxGenericValidator(& m_text));
820
821
822 item3->SetFocus();
823 ((wxButton*) FindWindow(wxID_OK))->SetDefault();
824
825 parent->SetAutoLayout( TRUE );
826 parent->SetSizer(item0);
827 item0->Fit(parent);
828
829 return TRUE;
830}
831
832/*
833 * Special-purpose splitter window for changing sash look and
834 * also saving sash width
835 */
836
837BEGIN_EVENT_TABLE(ctSplitterWindow, wxSplitterWindow)
838 EVT_SPLITTER_SASH_POS_CHANGED(-1, ctSplitterWindow::OnChangeSash)
839END_EVENT_TABLE()
840
841ctSplitterWindow::ctSplitterWindow(wxWindow* parent, wxWindowID id,
842 const wxPoint& pos, const wxSize& size, long style):
843 wxSplitterWindow(parent, id, pos, size, style)
844{
845 m_updateSettings = FALSE;
846 m_position = 0;
847}
848
849void ctSplitterWindow::OnChangeSash(wxSplitterEvent& event)
850{
851 if (!m_updateSettings)
852 return;
853
854 m_position = event.GetSashPosition();
855}