Commit Graph

59716 Commits

Author SHA1 Message Date
Benjamin Otte
aeef38c1eb listview: Change how binding is done
We now don't let the functions create widgets for the item from the
listmodel, instead we hand out a GtkListItem for them to add a widget
to.

GtkListItems are created in advance and can only be filled in by the
binding code by gtk_container_add()ing a widget.
However, they are GObjects, so they can provide properties that the
binding code can make use of - either via notify signals or GBinding.
2019-12-12 07:47:43 +01:00
Benjamin Otte
2650390f7f listitem: Add gtk_list_item_get_position()
Also refactor the whole list item management yet again.

Now, list item APIs doesn't have bind/unbind functions anymore, but only
property setters.

The item factory is the only one doing the binding.
As before, the item manager manages when items need to be bound.
2019-12-12 07:47:43 +01:00
Benjamin Otte
42718368e0 tests: Make animating listview do random resorts 2019-12-12 07:47:43 +01:00
Benjamin Otte
b9fce82de6 listview: Change change management
Add a GtkListItemManagerChange object that tracks all removed list
rows during an item-changed signal so they can be added back later.
2019-12-12 07:47:43 +01:00
Benjamin Otte
00a6e1592e listview: Make the listitemmanager stricter
Require that items created with the manager get destroyed via the
manager.

To that purpose, renamed create_list_item() to acquire_list_item() and
add a matching release_list_item() function.

This way, the manager can in the future keep track of all items and
cache information about them.
2019-12-12 07:47:43 +01:00
Benjamin Otte
0a72ddc3d3 listview: Add GtkListItem
GtkListItem is a generic row widget that is supposed to replace
GtkListBoxRow and GtkFlowBoxChild.
2019-12-12 07:47:43 +01:00
Benjamin Otte
899dd4ea53 listview: Add GtkListItemManager
It's all stubs for now, but here's the basic ideas about what
this object is supposed to do:

(1) It's supposed to be handling all the child GtkWidgets that are
    used by the listview, so that the listview can concern
    itself with how many items it needs and where to put them.
(2) It's meant to do the caching of widgets that are not (currently)
    used.
(3) It's meant to track items that remain in the model across
    items-changed emissions and just change position.
(2) It's code that can be shared between listview and potential
    other widgets like a GridView.

It's also free to assume that the number of items it's supposed to
manage doesn't grow too much, so it's free to use O(N) algorithms.
2019-12-12 07:47:43 +01:00
Benjamin Otte
c4f6ac48b8 listview: Implement an anchor
The anchor selection is very basic: just anchor the top row.

That's vastly better than any other widget already though.
2019-12-12 07:47:43 +01:00
Benjamin Otte
41f451ea9d tests: Add a test for a permanently changing listview
This is mostly for dealing with proper anchoring and can be used to
check that things don't scroll or that selection and focus handling
properly works.

For comparison purposes, a ListBox is provided next to it.
2019-12-12 07:47:43 +01:00
Benjamin Otte
f1e9f5e68b listview: Implement GtkScrollable
Scrolling in a very basic form is also supported
2019-12-12 07:47:43 +01:00
Benjamin Otte
a37ce0a844 listview: Make widget actually do something
The thing we're actually doing is create and maintain a widget for every
row. That's it.

Also add a testcase using this. The testcase quickly allocates too many
rows though and then becomes unresponsive though. You have been warned.
2019-12-12 07:47:43 +01:00
Benjamin Otte
e30147d229 listview: Introduce GtkListItemFactory
Thisis the abstraction I intend to use for creating widgets and binding
them to the item out of the listview.

For now this is a very dumb wrapper around the functions that exist in
the API.

But it leaves the freedom to turn this into public API, make an
interface out of it and most of all write different implementations, in
particular one that uses GtkBuilder.
2019-12-12 07:47:43 +01:00
Benjamin Otte
f89c37d8d9 gtk: Add a GtkListView skeleton 2019-12-12 07:47:43 +01:00
Benjamin Otte
78ee16386b builder: Add <binding> tag
The tag contains an expression that it then gtk_expression_bind()s to
the object it is contained in.
2019-12-12 07:47:43 +01:00
Benjamin Otte
936f908af7 builder: Allow text content in <lookup>
<lookup>foo</lookup>
is now short for
  <lookup>
    <constant>foo</constant>
  </lookup>
ie it looks up the object with the given name so it can then do a
property lookup with it.

This is the most common operation, so it's a nice shortcut.
2019-12-12 07:47:43 +01:00
Benjamin Otte
42f3e2bae5 builder: Allow <constant> without a type
A constant without a type is assumed to be an object. This is the most
common case and allows
  <constant>foo</constant>
without requiring updates to the type whenever the foo object changes.
2019-12-12 07:47:43 +01:00
Benjamin Otte
b6ed4fe5a4 builder: Make <lookup> type optional
If no type is set, use the type of the expression.
2019-12-12 07:47:43 +01:00
Benjamin Otte
df1040e405 gtk-demo: Make fishbowl info text use bindings
It's a good demo for how bindings can format multiple properties into an
informative string with 1 line of code (and 5 lines of XML).
2019-12-12 07:47:43 +01:00
Matthias Clasen
152db84876 sorter: Add tests
Some basic tests for GtkSorter.
2019-12-12 07:47:43 +01:00
Benjamin Otte
c6f4bce5e4 sortlistmodel: Make sort stable
The sort of the sortlistmodel is now stable with respect to the original
list model.

That means that if the sorter compares items as equal, the model
will make sure those items keep the order they were in in the original
model.

Or in other words: The model guarantees a total order based on the
item's position in the original model.
2019-12-12 07:47:43 +01:00
Benjamin Otte
c692b454f8 sortlistmodel: Redo the way we store the items
We need to keep this data around for changes in future commits where we
make the sorting stable.

An important part of the new data handling is that the unsorted list
needs to always be dealt with before the sorted list - upon creation we
rely on the unsorted iter and upon destruction, the sorted sequence
frees the entry leaving the unsorted sequence pointer invalid.

This change does not do any behavioral changes.
2019-12-12 07:47:43 +01:00
Matthias Clasen
3d451f040a Redo sort list model with GtkSorter
Reshuffle the api to take full advantage
of GtkSorter. Update all callers.
2019-12-12 07:47:43 +01:00
Matthias Clasen
72ab1a3b21 Add GtkNumericSorter
This sorter compares numbers obtained from items
by evaluating an expression.
2019-12-12 07:47:43 +01:00
Matthias Clasen
6aea70cb80 Add GtkMultiSorter
This is a sorter that tries multiple sorters in turn.
2019-12-12 07:47:43 +01:00
Matthias Clasen
f496b5892c Add GtkStringSorter
This is a GtkSorter implementation collating strings
2019-12-12 07:47:43 +01:00
Matthias Clasen
451c3cbe35 Add GtkCustomSorter
This is a GtkSorter implementation which uses a GCompareDataFunc.
2019-12-12 07:47:43 +01:00
Matthias Clasen
5b7a386f45 Add GtkSorter
This is a helper object for sorting, similar to GtkFilter.
2019-12-12 07:47:41 +01:00
Benjamin Otte
b88499d49d Add GtkOrdering
This is an enum that we're gonna use soon and it's worth introducing as a
separate commit.

The intention is to have meaningful names for return values in
comparison functions.
2019-12-12 07:47:25 +01:00
Matthias Clasen
de6e65c8cc More expression tests
Test type mismatches, and the this pointer
during evaluation.
2019-12-12 04:39:05 +01:00
Benjamin Otte
88ed0db609 expression: Invalidate bindings before destroying them
Use a weak ref to invalidate bindings. Make sure that this happens
before creating any watches, so that notifies from the
watched expression about changes will not trigger set_property() calls
during dispose()/finalize().

Invalidating also ensures that the watches aren't removed, which can
trigger warnings if the watches are watching the object itself, and the
weak refs cannot be removed anymore.
2019-12-12 04:39:05 +01:00
Benjamin Otte
d1d1708c87 expression: Add gtk_expression_bind()
Add a simple way to bind expressions to object properties. This is
essentially the thing to replace g_object_bind_property().
2019-12-12 04:39:05 +01:00
Benjamin Otte
a1e3d2511c testsuite: Add expression tests 2019-12-12 04:39:05 +01:00
Benjamin Otte
d4e31033a1 expression: Add the ability to watch an expression 2019-12-12 04:39:05 +01:00
Benjamin Otte
62d6a97837 builder: Add support for parsing expressions 2019-12-12 04:39:05 +01:00
Benjamin Otte
b2c5580bb8 filter: Add tests
Some basic tests for GtkFilter
2019-12-12 04:39:05 +01:00
Benjamin Otte
74b5780192 Add GtkMultiFilter, GtkAnyFilter, GtkEveryFilter
GtkMultiFilter is the abstract base class for managing multiple child
filter.
GtkAnyFilter and GtkEveryFilter are the actual implementations.
2019-12-12 04:39:05 +01:00
Benjamin Otte
48861b6d96 filter: Add GtkStringFilter
Users provide a search filter and an expression that evaluates the items
to a string and then the filter goes and matches those strings to the
search term.
2019-12-12 04:39:05 +01:00
Benjamin Otte
3baee2c661 expression: Make property expression allow subexpressions 2019-12-12 04:25:59 +01:00
Benjamin Otte
0b101897fb expression: Add GtkObjectExpression
Weak refs break cycles...
2019-12-12 04:25:59 +01:00
Benjamin Otte
4b4a933b49 Add GtkExpression
GtkExpressions allow looking up values from objects.

There are a few simple expressions, but the main one is the closure
expression that just calls a user-provided closure.
2019-12-12 04:25:59 +01:00
Benjamin Otte
c99c7dcb1e filterlistmodel: Rewrite to use GtkFilter 2019-12-12 04:25:59 +01:00
Benjamin Otte
87b9cb3964 tests: Remove testtreemodel test
testlistview does everything this test does.
2019-12-12 04:25:59 +01:00
Benjamin Otte
381ec83f8a Add GtkCustomFilter 2019-12-12 04:25:59 +01:00
Benjamin Otte
9d43d57f1a Add GtkFilter 2019-12-12 04:25:59 +01:00
Benjamin Otte
56ff557f9f Add GtkDirectoryList
Adds a new listmodel called GtkDirectoryList that lists the children of
a GFile as GFileInfos.

This is supposed to be used by the filechooser.
2019-12-12 04:25:59 +01:00
Benjamin Otte
f2c9d657d8 builder: Turn last dlsym() function into a scope API
Looking up a get_type function by its name is now also part of
GtkBuilderScope.
2019-12-12 04:25:59 +01:00
Benjamin Otte
366fbdc0e5 builder: Add GtkBuilderScope
GtkBuilderScope is an interface that provides the scope that a builder
instance operates in.
It creates closures and resolves types. Language bindings are meant to
use this interface to customize the behavior of builder files, in
particular when instantiating templates.

A default implementation for C is provided via GtkBuilderCScope (to keep
with the awkward naming that glib uses for closures). It is derivable on
purpose so that languages or extensions that extend C can use it.

The reftest code in fact does derive GtkBuilderCScope for its own scope
implementation that implements looking up symbols in modules.

gtk-widget-factory was updated to use the new GtkBuilderCScope to add
its custom callback symbols.
So it does it different from gtk-demo, which uses the normal way of
exporting symbols for dlsym() and thereby makes the 2 demos test the 2
ways GtkBuilder uses for looking up symbols.
2019-12-12 04:25:59 +01:00
Benjamin Otte
a600b473ec builder: Add gtk_builder_set_current_object()
Use it as the default object for expression binds and when connecting
signals. It is intended to work kind of as the "this" object while
parsing. In fact, the term "current object" was stolen from the Java
docs and various C++ tutorials for the this pointer.

Set the current object in gtk_widget_init_template() and
GtkListItemBuilder.

This more-or-less replaces the object passed to
gtk_builder_connect_signals() in GTK3.
2019-12-12 04:25:58 +01:00
Benjamin Otte
864a265184 builder: Add gtk_builder_lookup_object()
... and use it. This function looks up an object like
gtk_builder_get_object() but generates an error on failure.

Unlike the evil function _gtk_builder_lookup_object() which also
generates an error but hides it for later lookup.

Use this to avoid continuing applying properties when an error was
encountered.
2019-12-12 04:25:58 +01:00
Benjamin Otte
72dc0cd5c3 gtk: Add GTK_DECLARE_EXPORTED_TYPE()
This is like G_DECLARE_FINAL_TYPE(), except it doesn't make the class
struct public, so internally all the subclassing in the world can
happen.

Port The whole event controller + gesture machinery to make use of it.

As a side effect, we gained a bunch of missing autocleanups.
2019-12-12 04:25:58 +01:00