3#include <wx/renderer.h>
11#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)
15 using wxDataViewCustomRenderer::wxDataViewCustomRenderer;
18 wxDataViewModel* model,
19 const wxDataViewItem& item,
21 const wxMouseEvent* mouseEvent)
final
23 if(mouseEvent ==
nullptr)
25 wxCHECK(GetView(),
false);
29 value = !value.GetBool();
31 wxDataViewItemArray sel;
32 GetView()->GetSelections(sel);
35 for(
const auto& other : sel)
41 #if wxUSE_ACCESSIBILITY
44 wxAccessible::NotifyEvent(
45 wxACC_EVENT_OBJECT_NAMECHANGE,
48 ctrl->GetRowByItem(item) + 1);
58 wxDataViewModel* model,
59 const wxDataViewItem& item,
61 const wxMouseEvent* mouseEvent)
80 mText = value.GetString();
89 bool Render(wxRect cell, wxDC* dc,
int state)
override
92 RenderText(
mText, 0, cell, dc, state);
99 return GetTextExtent(
mText);
100 return GetView()->FromDIP(wxSize(wxDVC_DEFAULT_RENDERER_SIZE,
101 wxDVC_DEFAULT_RENDERER_SIZE));
104#if wxUSE_ACCESSIBILITY
105 wxString GetAccessibleDescription()
const override
131 bool Render(wxRect cell, wxDC* dc,
int state)
override
138 flags |= wxCONTROL_CHECKED;
139 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE ||
140 !(GetOwner()->GetOwner()->IsEnabled() && GetEnabled()))
142 flags |= wxCONTROL_DISABLED;
144 wxSize
size = cell.GetSize();
149 wxWindow*
const win = GetOwner()->GetOwner();
150 renderer.DrawCheckBox(win, *dc, cell, flags);
159#if wxUSE_ACCESSIBILITY
160 wxString GetAccessibleDescription()
const override
163 return mValue.GetBool() ?
_(
"Enabled") :
_(
"Disabled");
170 wxDataViewModel* model,
171 const wxDataViewItem& item,
173 const wxMouseEvent*)
override
177 model->ChangeValue(!
mValue.GetBool(), item, col);
188 : wxDataViewToggleRenderer(GetDefaultType(), wxDATAVIEW_CELL_ACTIVATABLE, wxDVR_DEFAULT_ALIGNMENT)
196 : wxDataViewTextRenderer(GetDefaultType(), wxDATAVIEW_CELL_INERT, wxDVR_DEFAULT_ALIGNMENT)
202#if defined(wxHAS_GENERIC_DATAVIEWCTRL) && wxUSE_ACCESSIBILITY
203class PluginsDataViewCtrlAx final :
public wxAccessible
207 : wxAccessible(parent)
211 wxAccStatus GetChild(
int childId, wxAccessible** accessible)
override
213 *accessible = childId == wxACC_SELF ? this :
nullptr;
217 wxAccStatus GetChildCount(
int* count)
override
219 if(
const auto model = GetModel())
220 *count = model->GetRowCount();
227 wxAccStatus GetName(
int childId, wxString*
name)
override
229 const auto ctrl = GetCtrl();
230 wxCHECK(ctrl, wxACC_FAIL);
234 if(childId == wxACC_SELF)
236 *
name = ctrl->GetName();
240 const auto model = GetModel();
242 return wxACC_INVALID_ARG;
244 const auto item = ctrl->GetItemByRow(childId - 1);
246 return wxACC_INVALID_ARG;
248 const auto plugin = model->GetPlugin(item);
249 if(plugin ==
nullptr)
250 return wxACC_INVALID_ARG;
257 *
name = wxString::Format(
"%s %s %s, %s",
259 ? plugin->GetSymbol().Translation()
260 : wxFileName(plugin->GetPath()).GetName(),
264 plugin->GetEffectFamily(),
270 wxAccStatus GetFocus(
int* childId, wxAccessible** accessible)
override
272 const auto ctrl = GetCtrl();
273 wxCHECK(ctrl, wxACC_FAIL);
275 *childId = wxACC_SELF;
276 *accessible =
nullptr;
278 const auto currentItem = ctrl->GetCurrentItem();
279 if(!currentItem.IsOk())
282 *childId = ctrl->GetRowByItem(currentItem) + 1;
287 wxAccStatus GetLocation(wxRect& rect,
int childId)
override
289 const auto ctrl = GetCtrl();
290 wxCHECK(ctrl, wxACC_FAIL);
292 if(childId == wxACC_SELF)
294 rect = ctrl->GetScreenRect();
298 const auto item = ctrl->GetItemByRow(childId - 1);
300 return wxACC_INVALID_ARG;
302 rect = ctrl->GetItemRect(item,
nullptr);
305 rect.width += rect.x;
307 rect.SetPosition(ctrl->ClientToScreen(rect.GetPosition()));
312 wxAccStatus GetDefaultAction(
int childId, wxString* action)
override
314 const auto ctrl = GetCtrl();
315 wxCHECK(ctrl, wxACC_FAIL);
319 if(childId == wxACC_SELF)
322 const auto model = GetModel();
324 return wxACC_INVALID_ARG;
326 const auto item = ctrl->GetItemByRow(childId - 1);
329 return wxACC_INVALID_ARG;
333 *action = enabled.GetBool()
340 wxAccStatus DoDefaultAction(
int childId)
override
342 const auto ctrl = GetCtrl();
343 wxCHECK(ctrl, wxACC_FAIL);
345 if(childId == wxACC_SELF)
346 return wxACC_NOT_SUPPORTED;
348 const auto model = GetModel();
350 return wxACC_NOT_SUPPORTED;
352 const auto item = ctrl->GetItemByRow(childId - 1);
354 return wxACC_INVALID_ARG;
363 wxAccStatus GetSelections(wxVariant* selections)
override
365 const auto ctrl = GetCtrl();
366 wxCHECK(ctrl, wxACC_FAIL);
368 wxDataViewItemArray sel;
369 ctrl->GetSelections(sel);
373 selections->MakeNull();
379 const auto row = ctrl->GetRowByItem(sel[0]);
380 *selections =
static_cast<wxLongLong
>(row + 1);
384 wxVariant list(wxVariantList{});
385 for(
size_t i = 0; i < sel.GetCount(); ++i)
387 const auto row = ctrl->GetRowByItem(sel[i]);
388 list.Append(wxVariant(
static_cast<wxLongLong
>(row + 1)));
395 wxAccStatus GetState(
int childId,
long* state)
override
397 const auto ctrl = GetCtrl();
398 wxCHECK(ctrl, wxACC_FAIL);
400 if(childId == wxACC_SELF)
402 *state = wxACC_STATE_SYSTEM_FOCUSABLE;
406 const auto model = GetModel();
408 return wxACC_INVALID_ARG;
410 *state = wxACC_STATE_SYSTEM_FOCUSABLE | wxACC_STATE_SYSTEM_SELECTABLE
411 | wxACC_STATE_SYSTEM_MULTISELECTABLE | wxACC_STATE_SYSTEM_EXTSELECTABLE;
413 const auto row = childId - 1;
414 if(row < ctrl->GetFirstVisibleRow() || row > ctrl->GetLastVisibleRow())
415 *state |= wxACC_STATE_SYSTEM_OFFSCREEN;
417 if(ctrl->IsSelected(ctrl->GetCurrentItem()))
418 *state |= wxACC_STATE_SYSTEM_FOCUSED;
419 if(ctrl->IsSelected(ctrl->GetItemByRow(row)))
420 *state |= wxACC_STATE_SYSTEM_SELECTED;
425 wxAccStatus GetRole(
int childId, wxAccRole* role)
override
427 *role = childId == wxACC_SELF
429 : wxROLE_SYSTEM_LISTITEM;
442 if(
const auto ctrl = GetCtrl())
452#if defined(wxHAS_GENERIC_DATAVIEWCTRL)
454 GetChildren()[0]->Bind(wxEVT_CHAR_HOOK, &PluginDataViewCtrl::OnTableCharHook,
this);
455#elif defined(__WXOSX__)
458 Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [=](wxDataViewEvent& evt) {
460 const auto item = evt.GetItem();
464 const auto model = GetModel();
473 value = !value.GetBool();
475 wxDataViewItemArray sel;
479 for(const auto& item : sel)
480 model->ChangeValue(value, item, PluginDataModel::ColumnState);
487 AppendColumn(
safenew wxDataViewColumn(
492 wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE)
494 AppendColumn(
safenew wxDataViewColumn(
499 wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE)
501 AppendColumn(
safenew wxDataViewColumn(
506 wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE)
508 AppendColumn(
safenew wxDataViewColumn(
514 wxDATAVIEW_COL_SORTABLE
521#if defined(wxHAS_GENERIC_DATAVIEWCTRL)
523 if(evt.GetKeyCode() == WXK_CONTROL_A &&
524 evt.GetModifiers() | WXK_COMMAND)
530 if(evt.GetKeyCode() == WXK_SPACE ||
531 evt.GetKeyCode() == WXK_RETURN ||
532 evt.GetKeyCode() == WXK_NUMPAD_ENTER)
537 const auto ch = evt.GetUnicodeKey();
541 auto item = GetCurrentItem();
546 const auto searchStartRow = GetRowByItem(item);
547 auto row = searchStartRow + 1;
550 item = GetItemByRow(row);
554 if(row > searchStartRow)
566 const auto name = data.GetString();
567 if(!
name.empty() &&
name.Left(1).IsSameAs(ch,
false))
569 wxDataViewItemArray sel;
572 SetCurrentItem(sel[0]);
576 if(row == searchStartRow)
586#if defined(wxHAS_GENERIC_DATAVIEWCTRL)
588int PluginDataViewCtrl::GetFirstVisibleRow()
const
590 return GetRowAt({0, 0});
593int PluginDataViewCtrl::GetLastVisibleRow()
const
595 const auto size = GetClientSize();
596 return GetRowAt({ 0,
size.y - 1 });
599int PluginDataViewCtrl::GetRowAt(
const wxPoint& point)
const
602 wxDataViewColumn* column;
610#if wxUSE_ACCESSIBILITY
611wxAccessible* PluginDataViewCtrl::CreateAccessible()
613#if defined(wxHAS_GENERIC_DATAVIEWCTRL)
616 return wxDataViewCtrl::CreateAccessible();
621#if defined(wxHAS_GENERIC_DATAVIEWCTRL)
622void PluginDataViewCtrl::OnTableCharHook(wxKeyEvent& evt)
624 if(evt.GetKeyCode() == WXK_TAB)
625 GetParent()->NavigateIn((evt.GetModifiers() & WXK_COMMAND) == 0);
627 evt.Skip(evt.GetKeyCode() != WXK_RIGHT && evt.GetKeyCode() != WXK_LEFT);
632 if(!GetCurrentItem().IsOk())
634 wxDataViewItemArray sel;
635 sel.push_back(GetItemByRow(0));
638 SetCurrentItem(sel[0]);
643#if wxUSE_ACCESSIBILITY
644 if(GetCurrentItem().IsOk())
646 wxAccessible::NotifyEvent(
647 wxACC_EVENT_OBJECT_FOCUS,
650 GetRowByItem(GetCurrentItem()) + 1
652 wxAccessible::NotifyEvent(
653 wxACC_EVENT_OBJECT_SELECTIONWITHIN,
!brief A plugins list model that can be attached to wxDataViewCtrl
void OnCharEvent(wxKeyEvent &evt)
friend class PluginsDataViewCtrlAx
virtual bool OnCellClicked(const wxRect &cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned col, const wxMouseEvent *mouseEvent)
bool ActivateCell(const wxRect &cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned col, const wxMouseEvent *mouseEvent) final
wxSize GetSize() const override
bool SetValue(const wxVariant &value) override
bool OnCellClicked(const wxRect &, wxDataViewModel *model, const wxDataViewItem &item, unsigned col, const wxMouseEvent *) override
bool Render(wxRect cell, wxDC *dc, int state) override
bool GetValue(wxVariant &) const override
PluginDataViewStateRenderer()
bool Render(wxRect cell, wxDC *dc, int state) override
PluginDataViewTextRenderer()
bool GetValue(wxVariant &) const override
bool SetValue(const wxVariant &value) override
wxSize GetSize() const override
void SetFocus(const WindowPlacement &focus)
Set the window that accepts keyboard input.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.