Commit Graph

372 Commits

Author SHA1 Message Date
Vadim Zeitlin
03a13591b9 Add wxDataViewToggleRenderer::ShowAsRadio()
This allows showing radio buttons in wxDataViewCtrl easily and natively.

Notice that this approach, adding an extra function to the existing
renderer class instead of creating some new wxDataViewRadioRenderer (see
https://github.com/wxWidgets/wxWidgets/pull/809), was finally chosen
because it is simpler to implement and, more importantly, because it
will be more natural to generalize if/when we also add a 3-state
check/radio renderer.

Closes https://github.com/wxWidgets/wxWidgets/pull/853
2018-07-11 23:48:14 +02:00
Tim S
bc92ed9d85 Replace wxUSE_GENERICDATAVIEWCTRL with wxHAS_GENERIC_DATAVIEWCTRL
The former symbol is inconsistent with all the other wxUSE_XXX ones and
hence confusing and kept only for compatibility reasons.

Closes https://github.com/wxWidgets/wxWidgets/pull/827
2018-06-04 18:26:34 +02:00
Vadim Zeitlin
c0b0562533 Avoid many -Wparentheses warnings from gtk/gtk.h with gcc8
Add wx/gtk/private/wrapgtk.h wrapping gtk/gtk.h in pragmas disabling
these warnings and include it everywhere instead of directly including
gtk/gtk.h.

Also include wx/gtk/private/gtk2-compat.h from this wrapper header as it
was included by 90% of the files including gtk/gtk.h itself and it seems
to be better and simpler to just always include it.
2018-05-21 12:34:04 +02:00
Jan Niklas Hasse
496da2e550 Remove trailing whitespace from several files
No real changes.

See https://github.com/wxWidgets/wxWidgets/pull/787
2018-04-18 15:45:42 +02:00
Vadim Zeitlin
33cbefd739 Send wxEVT_DATAVIEW_ITEM_EDITING_DONE for all renderers in wxGTK
Previously this event was not sent for the standard renderers, such as
wxDataViewTextRenderer, at all in wxGTK because the base class
FinishEditing() class didn't do anything if m_editorCtrl was null, as it
was always the case for non-custom renderers.

Fix this by refactoring the base class code in yet another way and
extracting the part which can be reused by both the generic and GTK
implementation in a new DoHandleEditingDone() function and call it from
wxGTK code.

Finally, check "editing-canceled" property to also correctly generate
the event with IsEditCancelled() returning true when editing is canceled
by e.g. pressing Esc in a standard renderer too.

And, as a final bonus, this makes the (just introduced) slightly
artificial DoFinishOrCancelEditing() unnecessary, so it can be removed,
without reintroducing any code duplication.

See #17835.
2018-02-05 01:05:16 +01:00
Vadim Zeitlin
a00b8dec8b Reduce code duplication in wxGTK wxDataViewRenderer classes
The code was more complicated than necessary, with the base class
providing both virtual GtkOnCellChanged() and GtkOnTextEdited() that
were both overridden to achieve the same thing, namely customizing how
the value entered by user is converted to wxVariant, in different
derived classes.

Make GtkOnTextEdited() non-virtual and remove GtkOnCellChanged()
completely and add a new simple GtkGetValueFromString() which is called
from GtkOnTextEdited() to do the conversion.

This removes the existing code duplication and will make it simpler to
modify this code in the future, without changing the behaviour.
2018-02-05 00:01:52 +01:00
Paul Cornett
e2a04e1fd7 Use signal blocking rather than disconnection to temporarily disable events 2018-02-03 22:30:36 -08:00
Vadim Zeitlin
e1d8137e70 Use wxGtkTreePath instead of calling gtk_tree_path_free()
Use RAII helper class instead of freeing the object manually.

Also add a couple of "const"s and other minor style fixes.

No real changes.
2018-01-24 23:09:30 +01:00
Vadim Zeitlin
27f705686d Avoid using the already deleted model items when clearing it
There is an impedance mismatch between wxDataViewCtrl API, which allows
deleting all items of the model at once, and GtkTreeView, which only
allows deleting them one by one, so bad things happen when we start
deleting the items from the GTK+ model after already having deleted them
from the wxDataViewModel, due to dereferencing the already freed
pointers.

Work around this by explicitly marking the model as being "temporarily
unsafe to use" by setting the stamp, uniquely identifying it, to 0 (and
ensuring that it's never 0 during the normal operation), and checking
for it in all functions that are called by GTK+ from inside
gtk_tree_model_row_deleted() that we call from Cleared().

The fix is not ideal, as the list of these functions was determined
empirically and could change in the future GTK+ versions, and also ugly,
but there doesn't seem to be any other way around this and at least now
Valgrind doesn't report invalid memory reads after calling
wxTreeListCtrl::DeleteAllItems() as it did before.
2018-01-24 23:09:30 +01:00
Vadim Zeitlin
0cea0a67f1 Use RAII SelectionEventsSuppressor in wxGTK wxDataViewCtrl code
This is simpler and safer than always remembering to call
GtkDisableSelectionEvents() and GtkEnableSelectionEvents() in pairs.

No real changes.
2018-01-24 23:09:29 +01:00
Paul Cornett
b02df5ea33 Remove unneeded init function
GObject instances are already zero-initialized
2018-01-03 09:26:12 -08:00
Paul Cornett
da186a0713 Avoid trying to override non-existent property with GTK+ < 2.20 2018-01-03 09:16:06 -08:00
Vadim Zeitlin
827e90e8de Use GtkHBox as GtkWxCellEditorBin parent with GTK+ < 4
Using GtkBin as widget parent didn't work without overriding its
size-related vfuncs until GTK+ 3.8 and, in particular, resulted in the
editor (which was the child of the bin) not being visible at all with
GTK+ 2.

Switch to using GtkHBox as parent, which does work with both GTK+ 2 and
any GTK+ 3 version, but keep using GtkBin with GTK+ 4 as GtkHBox is
removed in it.

This fixes bug introduced in c2821dcea0
since which custom wxDataViewCtrl editors were not visible any more.

Closes #17686.
2018-01-03 00:57:46 +01:00
Vadim Zeitlin
bde62ce981 Get rid of unused renderer rect in gtk_wx_cell_renderer_new()
No real changes, just don't call gtk_wx_cell_renderer_get_size()
unnecessarily as we never use its result: the code using the returned
rectangle was commented out ever since it was added (more than 10 years
ago) in 1e510b1e2d
2018-01-02 16:34:54 +01:00
Vadim Zeitlin
bf09ff2320 Remove unused GTK_IS_WX_CELL_EDITOR_BIN* macros
No real changes, just don't define macros that we never use and don't
plan on using it (why would we need to test whether something is of this
type when we already know it).
2017-12-31 02:27:19 +01:00
Paul Cornett
54bcf1b9b6 Avoid gtk_widget_get_pointer() with GTK+4 2017-12-19 10:46:37 -08:00
Paul Cornett
96befc88c0 Avoid gtk_tree_view_set_rules_hint() with GTK+4 2017-12-19 09:56:23 -08:00
Paul Cornett
2f19014d71 Avoid deprecated GdkColor with GTK3 2017-12-06 22:08:25 -08:00
Vadim Zeitlin
d6af0236c5 Simplify GTK+ 2 version checks with a helper function
Use wx_is_at_least_gtk2(minor) instead of gtk_check_version(2, minor)
because it is more clear and also works as expected (i.e. returns true)
when using GTK+ 3 instead of creating difficult to notice bugs in the
code by failing the version check in this case.

See #18004.
2017-11-23 13:15:31 +01:00
Paul Cornett
c1c9c2c5e5 Fix build with GTK+ 2.6 2017-11-15 10:52:21 -08:00
Andreas Falkenhahn
eb035485d7 Add wxDataViewCtrl::GetTopItem() and GetCountPerPage()
Add methods doing the same thing for wxDataViewCtrl as the existing wxListBox
methods.

Closes #17498.
2017-10-21 22:10:35 +02:00
Paul Cornett
fd33fcf191 Use static linkage for various local names 2017-09-22 10:45:56 -07:00
Paul Cornett
18edcfab00 Fix memory leak when wxDataViewCtrl is deleted (wxGTK)
Need to delete wxGtkTreeModelNode structure
2017-09-22 10:29:52 -07:00
Vadim Zeitlin
81d9952dfe Really fix spurious asserts in wxGTK wxDataViewCtrl::EditItem()
This replaces the changes of 24c0401e81
which, for some reason, used a global variable for storing whether the
selection function had been already set or not, when this clearly is a
per-control (or per-selection, but this seems one and the same) bit of
information.

Replace global ms_firstTime with a wxDataViewCtrlInternal field to avoid
asserts as soon as EditItem() is called on more than one wxDataViewCtrl.

Closes #17946.
2017-09-13 17:25:48 +02:00
Vadim Zeitlin
fad33800dc Don't crash if the model is badly defined in wxGTK wxDVC
Asserting before dereferencing a null pointer (in BuildBranch(), called
immediately after the asserts in question) is useless, as usual. Use wxCHECK
to complain and avoid crashing instead.

Closes #17776.
2017-01-15 17:16:04 +01:00
Václav Slavík
ff1dba498e Add wxDataViewValueAdjuster
Add wxDataViewRenderer:: SetValueAdjuster() and a
wxDataViewValueAdjuster class. This can be used to customize rendering
of values depending on whether they are highlighted (selection) or not,
without having to implement an entire new custom renderer.
2016-12-11 15:20:42 +01:00
Paul Cornett
3b27f7cebc Fix memory leaks of cairo_t caused by ca7670d2fc, see #17697 2016-10-24 14:20:13 -07:00
Václav Slavík
a6be5bdae3 Fix wxGTK wxDataViewRenderers' alignment handling
Don't apply alignment to native controls in SetAlignment() method, where
it may not be known yet due to column-to-renderer inheritance if
wxDVR_DEFAULT_ALIGNMENT is used (the default). Move such code to
GtkUpdateAlignment() (which was made virtual) in all renderers.

This fixes unintended right-aligning of columns with GTK+ 2 when default
alignment was used.
2016-10-21 17:50:34 +02:00
Václav Slavík
f3b8dac3b7 Fix wxNullVariant handling in wxDataViewBitmapRenderer
In both the generic and GTK+ implementations, setting the value of a
bitmap column to wxNullVariant resulted in the bitmap, if set for some
rows, being repeated on the rows with null value.
2016-10-19 16:46:54 +02:00
Václav Slavík
ae93a83e76 wxGTK: Handle null bitmaps in wxDataViewBitmapRenderer
Consistently with other implementations, accept wxNullBitmap and
wxNullIcon in wxDataViewBitmapRenderer if the column shouldn't show any
icon.
2016-10-08 16:58:52 +02:00
Václav Slavík
f4445caba3 Fix wrong type used for PangoAlignment 2016-10-08 16:58:52 +02:00
Vadim Zeitlin
74c0462c84 Add wxDataViewTextRenderer::EnableMarkup()
Implement the new method to all the implementations (generic, GTK, OS X), show
it in the sample and update the documentation.
2016-06-16 00:06:23 +02:00
Vadim Zeitlin
716dace3d6 Make wxDataViewCtrl::Expand() expand ancestors in native ports too
Expand() called ExpandAncestors() in the generic wxDataViewCtrl implementation
but not in the native ones, resulting in observable difference in the
behaviour: for example, the wxDataViewTreeCtrl in the dataview sample appeared
initially expanded under MSW, using the generic version, but collapsed under
GTK and OSX.

Harmonize this among all ports. This also has a nice side effect of making
Expand() less horribly inefficient as it is not recursively called by
ExpandAncestors() which it itself used to call: now ExpandAncestors() only
calls DoExpand() which is a simple function that only expands the item passed
to it and does nothing else.

Closes #14803.
2016-03-22 21:22:36 +01:00
Vadim Zeitlin
1bbc44daff Support background colour in wxDataViewItemAttr in wxGTK
The code handling background colour was commented out for some reason, simply
enable it as it seems to be working just fine -- and update the sample to show
that it does.
2016-03-22 17:49:49 +01:00
Vadim Zeitlin
9829446755 Refactor wxDataViewEvent constructors
Take care of all the common stuff such as setting the event object and the
model, which is used for all events, in the ctor. Also set both the column
pointer and the column index at once instead of having two separate setters
for them which could result in inconsistent event objects (and did, as
sometimes only one or only the other field was set).

This makes the code shorter (we save 160 lines) and more clear and ensures
that everything is always initialized.

Closes #12649.
2016-03-19 00:16:51 +01:00
Vadim Zeitlin
e5507c27a1 Stop using GTK_TREE_VIEW_COLUMN_AUTOSIZE in wxDataViewCtrl
Using this column type made the control even slower for a big number of items
and also prevented the user from resizing the column which was unexpected.

See #16680.
2016-02-28 20:36:03 +01:00
Vadim Zeitlin
c2821dcea0 Allow using arbitrary windows as wxDataViewCtrl editors in wxGTK
Previously the editor created by wxDataViewRenderer::CreateEditorCtrl() had to
be a native GTK+ widget implementing GtkCellEditable interface which prevented
using composite windows (e.g. a container for a text control and a button) as
editors.

Create a helper container wrapping them now and implementing GtkCellEditable
now to allow this.
2016-02-28 20:25:07 +01:00
Vadim Zeitlin
fd738c5fdb Merge miscellaneous wxDataViewCtrl-related bug fixes
Make it possible to define custom renderers using text controls reacting to
error presses in at least wxMSW and wxGTK.

Closes https://github.com/wxWidgets/wxWidgets/pull/221
2016-02-27 18:08:12 +01:00
Vadim Zeitlin
6a7420e454 Don't try to redraw empty areas in wxGTK wxDataViewCtrl
This just results in warnings from pixman_region32_init_rect() and doesn't
seem to have any useful effects.
2016-02-27 02:41:18 +01:00
Paul Cornett
6674ca57da implement wxDC::GetContentScaleFactor() for GTK3 2016-02-22 09:52:26 -08:00
Vadim Zeitlin
31a10d0355 Fix editing items with custom renderers in wxGTK wxDataViewCtrl
Call FinishEditing() when the cell is done being edited instead of sending
wxEVT_DATAVIEW_ITEM_EDITING_DONE event manually from wxGTK code.

This fixes the bug with not being able to edit an item the second time if the
editor was dismissed by GTK+ itself and not by our own code (which already did
call FinishEditing()) as the old editor still remained alive because
DestroyEditControl(), usually called from FinishEditing(), wasn't executed.

It also removes code duplication and avoids the need to keep a global
s_user_data pointer as the item currently being edited is already stored in
wxDataViewRenderer anyhow.
2016-02-20 17:07:04 +01:00
Vadim Zeitlin
235e8ebd1a Factor out wxDataViewRendererBase::NotifyEditingStarted()
Reuse the same code from the generic and native GTK and OS X implementations
of wxDataViewCtrl instead of triplicating it.

This fixes a small discrepancy between the wxOSX version, which didn't see the
model pointer correctly in the generated event, and all the others, but mainly
paves way for future improvements.
2016-02-20 17:07:04 +01:00
Vadim Zeitlin
6768695d14 Extract wxGtkTreePath from src/gtk/dataview.cpp
Put this class into its own header so that it could be reused from other
places.

No real changes.
2016-02-06 19:13:35 +01:00
Vadim Zeitlin
4379f599e8 Implement wxDataViewCtrl::SetIndent() for wxGTK
Use gtk_tree_view_set_level_indentation().
2016-02-05 17:00:57 +01:00
Vadim Zeitlin
602783facb Merge branch 'dvc-type-check'
Various fixes to make wxDataViewCtrl behaviour more homogeneous across all
ports.
2015-09-03 00:01:24 +02:00
Paul Cornett
83ce88402c Add gtk_cell_renderer_set_padding() compatibility function 2015-09-01 08:41:15 -07:00
Vadim Zeitlin
361c6357b4 Use wxDataViewRenderer::PrepareForItem() in all ports
wxOSX and wxGTK previously used their own methods for handling the enabled
state and the attributes of the items being rendered, change them to reuse the
same methods as the generic implementation, i.e. SetEnabled() and SetAttr()
and remove the port-specific GtkSetAttr(), OSXApplyAttr() and so on.

This has the advantage of ensuring that the logic is the same for all
platforms (e.g. item enabled status wasn't handled in the same way in wxGTK as
in the other ports previously) and hopefully makes the code simpler by cutting
down on the number of virtual methods.

Notice that GtkSupportsAttrs() optimization was removed as it didn't seem to
be worth the bother (we basically saved a call to a virtual model method at a
price of a virtual renderer method call) and preserving it would have
complicated things needlessly.
2015-08-31 22:20:33 +02:00
Vadim Zeitlin
a49567109a Consistently check for type mismatch in all ports in wxDataViewCtrl.
Move the checks for the type mismatch between the type of the value returned
by wxDataViewModel and the type expected by wxDataViewRenderer into common
code. This avoids duplicating the same code in wxGTK and wxOSX and, more
importantly, means that this check is also performed in wxMSW when using the
generic version, so that the problems such as the one fixed in 3ff8c3c ("add
missing wxDataViewDateRenderer::GetDefaultType()") would be visible there too.
2015-08-29 00:03:15 +02:00
Vadim Zeitlin
e8647b4751 No changes, just use an extra variable in wxGTK wxDataViewCtrl code.
Store the column index in a variable instead of accessing it several times
using the clumsy and unclear cell->GetOwner()->GetModelColumn() expression.
2015-08-28 23:37:51 +02:00
Paul Cornett
e77c48331b Update internal sorting state in wxDataViewColumn::SetSortOrder()
This allows a subsequent wxDataViewModel::Resort() to actually work, see #15626
2015-08-25 22:38:26 -07:00