| 1 |
#include "styles_sheet_list_view.h" |
| 2 |
#include "wxc_widget.h" |
| 3 |
#include "wxgui_defs.h" |
| 4 |
#include "wxguicraft_main_view.h" |
| 5 |
#include <event_notifier.h> |
| 6 |
#include <wx/wupdlock.h> |
| 7 |
|
| 8 |
StylesSheetListView::StylesSheetListView() |
| 9 |
: m_wxcWidget(NULL) |
| 10 |
, m_controlFlags(NULL) |
| 11 |
, m_windowFlags(NULL) |
| 12 |
{ |
| 13 |
} |
| 14 |
|
| 15 |
StylesSheetListView::~StylesSheetListView() {} |
| 16 |
|
| 17 |
void StylesSheetListView::Construct(wxPropertyGrid* pg, wxcWidget* wb) |
| 18 |
{ |
| 19 |
#ifdef __WXMSW__ |
| 20 |
wxWindowUpdateLocker locker(pg); |
| 21 |
#endif |
| 22 |
|
| 23 |
pg->Clear(); |
| 24 |
m_wxcWidget = wb; |
| 25 |
|
| 26 |
CHECK_POINTER(wb); |
| 27 |
|
| 28 |
wxArrayString windowStyles, controlStyles; |
| 29 |
wxArrayInt windowStylesInt, controlStylesInt; |
| 30 |
size_t windowStylesValue, controlStylesValue; |
| 31 |
size_t count = 0; |
| 32 |
|
| 33 |
windowStylesValue = 0; |
| 34 |
controlStylesValue = 0; |
| 35 |
|
| 36 |
wxcWidget::MapStyles_t flags = wb->GetStyles(); |
| 37 |
wxcWidget::MapStyles_t::ConstIterator iter = flags.Begin(); |
| 38 |
|
| 39 |
// The control specific flags will show up first |
| 40 |
for(; iter != flags.End(); ++iter) { |
| 41 |
if(iter->first == "0") { |
| 42 |
iter++; |
| 43 |
// We found the terminator |
| 44 |
break; |
| 45 |
} |
| 46 |
controlStyles.Add(iter->first); // Add the style name |
| 47 |
// Rather than using the real bitvalue of the style flag, create our own fake one |
| 48 |
// This is to avoid clashes between e.g. the composite wxDEFAULT_DIALOG_STYLE and its constituents e.g. |
| 49 |
// wxCAPTION |
| 50 |
size_t flag_fake_value = (1 << count++); |
| 51 |
controlStylesInt.Add(flag_fake_value); // Add the value |
| 52 |
if(iter->second.is_set) { controlStylesValue |= flag_fake_value; } |
| 53 |
} |
| 54 |
|
| 55 |
// From this point on, everything is belonged to the |
| 56 |
// wxWindow styles |
| 57 |
for(; iter != flags.End(); ++iter) { |
| 58 |
|
| 59 |
windowStyles.Add(iter->first); // Add the style name |
| 60 |
windowStylesInt.Add(iter->second.style_bit); // Add the value |
| 61 |
if(iter->second.is_set) { windowStylesValue |= iter->second.style_bit; } |
| 62 |
} |
| 63 |
|
| 64 |
m_controlFlags = NULL; |
| 65 |
m_windowFlags = NULL; |
| 66 |
if(controlStyles.IsEmpty() == false) { |
| 67 |
m_controlFlags = (wxFlagsProperty*)pg->Append( |
| 68 |
new wxFlagsProperty(wb->GetWxClassName(), wxPG_LABEL, controlStyles, controlStylesInt, controlStylesValue)); |
| 69 |
pg->SetPropertyAttribute(m_controlFlags, wxPG_BOOL_USE_CHECKBOX, true); |
| 70 |
pg->Expand(m_controlFlags); |
| 71 |
} |
| 72 |
|
| 73 |
if(windowStyles.IsEmpty() == false) { |
| 74 |
m_windowFlags = (wxFlagsProperty*)pg->Append( |
| 75 |
new wxFlagsProperty(_("wxWindow"), wxPG_LABEL, windowStyles, windowStylesInt, windowStylesValue)); |
| 76 |
pg->SetPropertyAttribute(m_windowFlags, wxPG_BOOL_USE_CHECKBOX, true); |
| 77 |
pg->Expand(m_windowFlags); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
void StylesSheetListView::Clear(wxPropertyGrid* pg) |
| 82 |
{ |
| 83 |
pg->Clear(); |
| 84 |
m_controlFlags = NULL; |
| 85 |
m_windowFlags = NULL; |
| 86 |
} |
| 87 |
|
| 88 |
void StylesSheetListView::Changed(wxPropertyGrid* pg, wxPropertyGridEvent& e) |
| 89 |
{ |
| 90 |
// We used fake flags in controlStyles to avoid clashes, so we can't just retrieve the value as integer |
| 91 |
// Translating back into the real values won't work either: it just produces the clashes again. So use the strings |
| 92 |
if(m_wxcWidget) { |
| 93 |
wxString controlStyles; |
| 94 |
wxString windowStyles; |
| 95 |
if(m_windowFlags) { windowStyles = m_windowFlags->GetValueAsString(); } |
| 96 |
|
| 97 |
if(m_controlFlags) { controlStyles = m_controlFlags->GetValueAsString(); } |
| 98 |
|
| 99 |
// joint flags |
| 100 |
if(!controlStyles.empty() && !windowStyles.empty()) { controlStyles << ','; } |
| 101 |
wxArrayString arr = ::wxStringTokenize(controlStyles + windowStyles, ",", wxTOKEN_STRTOK); |
| 102 |
// Reset the styles |
| 103 |
m_wxcWidget->ClearStyles(); |
| 104 |
for(size_t i = 0; i < arr.GetCount(); ++i) { |
| 105 |
m_wxcWidget->EnableStyle(arr.Item(i).Trim().Trim(false), true); |
| 106 |
} |
| 107 |
|
| 108 |
// Notify about modifications |
| 109 |
wxCommandEvent evt(wxEVT_PROPERTIES_MODIFIED); |
| 110 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 111 |
} |
| 112 |
} |