Compare commits

...

895 Commits

Author SHA1 Message Date
Matthias Clasen
d17f224e71 Add search support
Add a filter to GtkListBase, and move the selection
to the first matching item whenever the filter changes.
This is meant to be used with single selection and
a string filter that is hooked up to a search entry.
2020-05-30 22:27:54 -04:00
Matthias Clasen
b73be6e344 printdialog: Port to column view
This is not 100% complete. The search is not there yet.
2020-05-30 22:27:54 -04:00
Matthias Clasen
4a80f23213 printer: Fix the default value of icon-name
Just set this to "printer", so we don't have
to fix it up in the print dialog.
2020-05-30 20:01:14 -04:00
Matthias Clasen
3b8888acda printbackend: Add a list model getter
Now that we have a list model for printers,
we can start using it.
2020-05-30 20:01:14 -04:00
Matthias Clasen
786c95e503 printbackend: Use a list store 2020-05-30 20:01:14 -04:00
Matthias Clasen
7007c72fc5 inspector: Expand the actions list 2020-05-30 20:01:14 -04:00
Matthias Clasen
9eaeb81433 inspector: Expand the resource list
This is an experiment with adding a filler column.
2020-05-30 20:01:14 -04:00
Matthias Clasen
3bddbcdd52 inspector: Expand the property list
It looks better this way.
2020-05-30 20:01:14 -04:00
Matthias Clasen
13d5d60db0 inspector: Expand the object tree
This is how it used to look, and it looks better that way.
2020-05-30 20:01:14 -04:00
Matthias Clasen
1b24528b9c columnview: Take expand into account
When allocating columns, distribute extra space
to columns that have expand set to TRUE.
2020-05-30 20:01:14 -04:00
Matthias Clasen
6e7ebc49eb columnviewcolumn: Add an expand property
This will be used to determine how to distribute
available extra space in a column view.
2020-05-30 20:01:14 -04:00
Matthias Clasen
bdc6770bd9 gtk-demo: Add more scrolling benchmarks
Add a listview and gridview to the scrolling
benchmarks.
2020-05-30 20:01:14 -04:00
Matthias Clasen
8d2fef1e23 gtk-demo: Make gridview demo use rubberbanding 2020-05-30 20:01:14 -04:00
Matthias Clasen
90668f7e01 Add rubberband api
Add an enable-rubberband property to GtkListView,
GtkGridView and GtkColumnView.
2020-05-30 20:01:14 -04:00
Matthias Clasen
74f72a146c listbase: Add rubberband selection
Implement the typical rubberband selection, including
autoscroll. This is only useful with multiselection,
and not very compatible with single-click-activate.
Therefore, it is not enabled by default, and needs
to be turned on with the enable-rubber-band property.
2020-05-30 20:01:14 -04:00
Matthias Clasen
5553bf1c39 Add GtkMultiSelection
This is implemented using a private GtkSet helper.
2020-05-30 20:01:14 -04:00
Matthias Clasen
77a3f81971 Add a selection model test
The test shows that we are failing to emit
::selection-changed in some circumstances.
2020-05-30 20:01:14 -04:00
Matthias Clasen
b3e0353e6b testcolumnview: Reordering in the column editor
Use Ctrl-Up/Down to move the column around.
2020-05-30 20:01:14 -04:00
Matthias Clasen
780915e318 testcolumnview: Flesh out column editor
Turn the column list into an editor with
controls for visibility, resizability, reorderability
and width.
2020-05-30 20:01:14 -04:00
Matthias Clasen
7242b801ff columnviewtitle: Display a context menu
When the ::header-menu property is set on the
column, use the menu model to create and show
a context menu.
2020-05-30 20:01:14 -04:00
Matthias Clasen
88669080c4 columnviewcolumn: Add a menu property
Add a ::header-menu property that will be used
to create a context menu for the header of the
column.
2020-05-30 20:01:14 -04:00
Matthias Clasen
51e8dc924b columnview: Add autoscroll
Autoscroll when the pointer gets close to the
edge during column resizing or reordering. This
is similar to what the treeview does, but it is
implemented using a tick callback, and has
variable speed.
2020-05-30 20:01:14 -04:00
Matthias Clasen
29b5d3ab38 columnview: Allow to cancel reorder with Escape
The treeview does this too.
2020-05-30 20:01:14 -04:00
Matthias Clasen
bb06fffab1 columnview: Interactive column reordering
Allow rearranging columns by dragging, in the same
way the treeview does.

We add the "dnd" style class to the header while
it is dragged, and we move the header of the dragged
column to the end of its parents children, so that
it gets drawn on top.
2020-05-30 20:01:14 -04:00
Matthias Clasen
94c5b00231 columnviewcolumn: Add a reorderable property
This will be used for interactive column reordering
in the future.
2020-05-30 20:01:14 -04:00
Matthias Clasen
59e49dafd7 columnviewlayout: Use header allocation for titles
Normally, this will be identical to the column
allocation, but we will temporarily change it
during column reordering.
2020-05-30 20:01:14 -04:00
Matthias Clasen
d5ce5b53d6 columnviewcolumn: Add reordering helpers
Add helper functions that let us temporarily give
a different allocation to headers. These will be
used to implement interactive column reordering
in GtkColumnView.
2020-05-30 20:01:14 -04:00
Matthias Clasen
915bdf24a7 columnviewtitle: Invert on release
This is necessary to make drag-to-reorder work
without triggering inversion.
2020-05-30 20:01:14 -04:00
Matthias Clasen
114054266b columnview: Interactive column resizing
This copies just enough of the treeview code to
get columns moving.
2020-05-30 20:01:14 -04:00
Matthias Clasen
dcea6d6cda columnviewcolumn: Add a helper
We need to check whether clicks are in the headers
of columns, so let the column view get at the the
header widget.
2020-05-30 20:01:14 -04:00
Matthias Clasen
a118267ab7 columnviewcolumn: Add a resizable property
This will be used for interactive column resizing
in the future.
2020-05-30 20:01:14 -04:00
Matthias Clasen
cc63c581c3 columnview: Add a helper
The column code needs to get access to the
listitem widgets that are children of the listview,
so add a getter.
2020-05-30 20:01:14 -04:00
Matthias Clasen
dbc1a8ba11 columnview: Add column reordering
Add an API to allow reordering columns.
2020-05-30 20:01:14 -04:00
Matthias Clasen
515a86645a columnview: Implement horizontal scrolling
The listview inside always thinks it gets its full size,
and updates its horizontal adjustment accordingly.

So keep our own adjustment, and update it in size_allocate.
2020-05-30 20:01:14 -04:00
Matthias Clasen
cbabb85e6d columnview: Revise scroll-minimum handling
Tweak the behavior slightly. We don't show
a scrollbar as long as we have at least
min-size available, but we still give the
entire size to the child, up to nat-size.

This matches how viewports handle scroll-minimum.
2020-05-30 20:01:14 -04:00
Matthias Clasen
1031625bd4 columnviewcolumn: Add a visible property
This lets us hide columns, which is useful.
2020-05-30 20:01:14 -04:00
Matthias Clasen
65ed3aa1d9 inspector: Touch up list styling
This is just the minimal amount of work to make
headers recognizable.
2020-05-30 20:01:14 -04:00
Matthias Clasen
ed04c46078 inspector: Use a column view for actions
A straight conversion from list box to column view.
2020-05-30 20:01:14 -04:00
Matthias Clasen
1b2df91e6d inspector: Make the resource list sortable
This is using a GtkTreeListRowSorter to keep expanded
state of the tree while changing the sorting.
2020-05-30 20:01:14 -04:00
Matthias Clasen
f745c0c2aa inspector: Use a column view for the resource list
A conversion from tree view to column view.
2020-05-30 20:01:14 -04:00
Matthias Clasen
2ed46450ea inspector: Use a column view for properties
Just a straight conversion from list box to column view.
2020-05-30 20:01:14 -04:00
Matthias Clasen
6d168079d4 inspector: Add columns to the object tree
Add columnview columns in the object tree.
We do the same for treeview columns.
2020-05-30 20:01:14 -04:00
Matthias Clasen
fc9462d49e Add some tests for new GtkBuilder syntax
Some valid and invalid examples for <closure>,
<lookup> and <constant>.
2020-05-30 19:31:38 -04:00
Matthias Clasen
9c849d2084 docs: Update the list widget overview
Fill in the GtkComboBox and GtkCellView replacements
in the quick reference table.
2020-05-30 19:31:38 -04:00
Matthias Clasen
336b30c532 gtk-demo: Add a large grid demo
This is similar to the flowbox demo, but much bigger.
2020-05-30 19:31:38 -04:00
Matthias Clasen
b331e29e43 inspector: Use dropdowns in the visual page
Convert everything in the visual page to dropdowns.
2020-05-30 19:31:38 -04:00
Matthias Clasen
54cdafdd67 inspector: Use a dropdown for size groups
Use a GtkDropDown for the modes of size groups.
2020-05-30 19:31:38 -04:00
Matthias Clasen
30541201b6 inspector: Use a dropdown for controllers
Use a GtkDropDown for the phases of event controllers.
2020-05-30 19:31:38 -04:00
Matthias Clasen
6346fa960c inspector: Use a dropdown for attribute mapping
Use a GtkDropDown for the attribute mapping editor.
2020-05-30 19:31:38 -04:00
Matthias Clasen
99c98d0736 inspector: Use dropdowns in property editor
Replace combo boxes by dropdowns in the property editor.
2020-05-30 19:31:38 -04:00
Matthias Clasen
496e673d77 filechooser: Use a dropdown for choices 2020-05-30 19:31:38 -04:00
Matthias Clasen
d3aad3b574 filechooser: Use a dropdown for the filter combo
Replace an internal use of GtkComboBox with GtkDropDown.
2020-05-30 19:31:38 -04:00
Matthias Clasen
371dab51bb Add GtkDropDown
This is a simple drop down control using list models.
2020-05-30 19:31:38 -04:00
Benjamin Otte
3ea2258ce9 xxx: isnanf() is some wtf 2020-05-30 19:30:14 -04:00
Matthias Clasen
c7feae65f1 builderlistitemfactory: Precompile the xml
This is the one place where we can really take advantage
of precompiling, since we instantiate this template
over and over.
2020-05-30 19:30:14 -04:00
Matthias Clasen
b087948933 gtk-demo: Use single-click-activate for minesweeper
The explanation say we do, so do it.
2020-05-30 19:30:14 -04:00
Matthias Clasen
f611d55f16 Spread single-click-activate api
This makes sense to have in all the views,
not just GtkListView.
2020-05-30 19:30:14 -04:00
Matthias Clasen
12b1007046 docs: Add a listview overview section
Add a conceptual overview for all the listmodel-based
widgets.

Fixes: #2214
2020-05-30 19:30:14 -04:00
Matthias Clasen
4a4c15b2ac gtk-demo: Add filtering to the settings demo
A demo of filtering with lists was missing so far.
2020-05-30 19:30:14 -04:00
Matthias Clasen
8804427677 gtk-demo: Demo columnview sorting
Enhance the settings demo to have a sortable column.
2020-05-30 19:30:14 -04:00
Matthias Clasen
d717971f41 gtk-demo: Cosmetic improvements to the listview demos
Set default sizes, window titles and add more
detail to the descriptions.
2020-05-30 19:30:14 -04:00
Matthias Clasen
f33df84eff gtk-builder-tool: Minimally validate <binding>
Check that the toplevel property name is legit.
2020-05-30 19:30:14 -04:00
Benjamin Otte
7910271b6c testsuite: Add tests for GtkTreeListSorter 2020-05-30 19:30:14 -04:00
Matthias Clasen
e3ce99988f Add GtkTreeListRowSorter
This is a special-purpose sorter that can
apply the sorting of another sorter to the
levels of a GtkTreeListModel.
2020-05-30 19:30:14 -04:00
Benjamin Otte
fb78f1ef8e testcolumnview: Add sorters 2020-05-30 19:28:30 -04:00
Matthias Clasen
1ba1eda8ab column view title: Show sort indicators 2020-05-30 19:28:30 -04:00
Matthias Clasen
2945430ad7 columnview: Add a sort-by api 2020-05-30 19:28:28 -04:00
Matthias Clasen
66500a6882 columnview: Add sorting
This is a somewhat large commit that:

- Adds GtkColumnViewSorter
This is a special-purpose, private sorter implementation which sorts
according to multiple sorters, allowing each individual sorter to be
inverted. This will be used with clickable column view headers.

- Adds a read-only GtkColumnView::sorter property
The GtkColumnView creates a GtkColumnViewSorter at startup that it uses
for this property.

- Adds a writable GtkColumnViewColumn::sorter property
This allows defining per-column sorters. Whenever an application sets a
sorter for a column, the header becomes clickable and whenever
a header is clicked, that column's sorter is prepended to the list of
sorters, unless it is already the first sorter, in which case we invert
its order. No column can be in the list more than once.
2020-05-30 19:26:46 -04:00
Matthias Clasen
2c4c07c96d listview: Add single-click-activate
Add a single-click-activate property to GtkListView.
2020-05-30 19:26:46 -04:00
Matthias Clasen
69c86ae385 listitemwidget: Add single-click-activate
Add a mode to GtkListItemWidget that activates on
single click and selects on hover. Make
GtkListItemManager set this on its items
when its own 'property' of the same name is set.
2020-05-30 19:26:46 -04:00
Matthias Clasen
21eac434c3 builder-tool: Pass through CDATA where it makes sense
This avoids a ton of escaping for
GtkBuilderListItemFactory::bytes.
2020-05-30 19:26:46 -04:00
Matthias Clasen
2f21003064 docs: Reorganize list widgets in their own chapter 2020-05-30 19:26:46 -04:00
Benjamin Otte
58b65d1bf6 fontchooserwidget: Port to listmodels
The port is kind of evil, in that it stores either a PangoFontFamily or a
PangoFontFace in the list, depending on if the fontchooser is configured
to select fonts or faces.
It also does not cache the font description anymore, so more calls to
pango_font_describe() may happen.

If both of these issues turn out problematic, the fontchooser would need
to resurrect GtkDelayedFontDescription again and put objects of that
type through the model.

These changes depend on Pango 1.46's introduction of listmodels and
various new getters, so the dependency has been upgraded.
2020-05-30 19:26:46 -04:00
Matthias Clasen
542829ee81 Add some tests for expression binding
In particular, test that expressios can deal with object == this.
2020-05-30 19:26:46 -04:00
Benjamin Otte
b43c8ae646 expression: Allow passing a this object to bind()
This gives a bit more control over the arguments passed to expressions.
2020-05-30 19:26:46 -04:00
Benjamin Otte
22e6fa3a64 gtk-demo: Add a Clocks demo
This demo is meant to showcase expressions.

It also needs the fixes in glib 2.64 to work properly.
2020-05-30 19:26:46 -04:00
Benjamin Otte
c337887e29 xxx: Add a hack to make paintables transform to/from objects
See also: https://gitlab.gnome.org/GNOME/glib/merge_requests/1251
2020-05-30 19:26:46 -04:00
Benjamin Otte
650688c635 inspector: Remove private struct for prop editor 2020-05-30 19:26:46 -04:00
Benjamin Otte
2787e916b2 inspector: Make Controller page a GtkWidget 2020-05-30 19:26:46 -04:00
Benjamin Otte
e72119e9bb inspector: Remove private struct from controllers 2020-05-30 19:26:46 -04:00
Benjamin Otte
efcb3a9d67 columnview: Add header
This uses a custom GtkColumnViewTitle widget. So far that widget is
pretty boring, but that will change once we added
resizing, reordering, dnd, sorting, hiding/showing of columns or
whatever UIs we want.
2020-05-30 19:26:46 -04:00
Benjamin Otte
9f19699806 tests: Add testcolumnview 2020-05-30 19:26:46 -04:00
Benjamin Otte
326cb1148b columnview: Add a custom LayoutManager
The ColumnView now allocates column widths first and then the individual
rows use the new layout manager which looks at the column allocations to
allocate their children.
2020-05-30 19:26:46 -04:00
Benjamin Otte
767e7cb06f constraint-editor: Don't poke around in widget internals 2020-05-30 19:26:46 -04:00
Benjamin Otte
084725e280 columnview: Fix styling with Adwaita
- Use "treeview" as the node name
- Add .view style class
2020-05-30 19:26:46 -04:00
Benjamin Otte
6e3b6980de inspector: Port object tree to GtkColumnView 2020-05-30 19:26:46 -04:00
Benjamin Otte
9927d9bda2 columnview: Add GtkColumnViewCell
It's a GtkListItemWidget subclass that tracks the column it belongs to
and allows the column to track it.

We also use this subclass to implement sizing support so columns share
the same size and get resized in sync.
2020-05-30 19:26:46 -04:00
Benjamin Otte
34c6ef5332 widget: Add a hook for resizes
It's private, no APIs, we don't talk about it. But we will start using
it very soon, so we can do size request caching in columns and avoid
sizegroups...
2020-05-30 19:26:46 -04:00
Benjamin Otte
8af3e407c2 columnview: Implement GtkScrollable
Just forward it to the listview for now.
2020-05-30 19:26:46 -04:00
Benjamin Otte
8736343544 columnview: Add listitems for the columns
They are not aligned in columns yet, but they do exist.
2020-05-30 19:26:46 -04:00
Benjamin Otte
9caca0b127 listitemwidget: Lazily create listitems
We only create them in root/unroot (they should be created in
appear/disappear, but that vfunc doesn't exist yet), that way we can
avoid expensive work while the widget isn't used for anything.
2020-05-30 19:26:46 -04:00
Benjamin Otte
9d86020d4c listitem: Move position/item/selected tracking to widget
This way, we can ensure it's always there when we need it (before the
item gets created) and gone when we don't (if some GC language holds on
to the item after we've destroyed the widget).
2020-05-30 19:26:46 -04:00
Benjamin Otte
32eedec565 listitemwidget: Add a private struct
I had to rename the item property to list_item anyway, so I could just
do the next step with it.
2020-05-30 19:26:46 -04:00
Benjamin Otte
1af004361c listitemfactory: Simplify
Instead of 6 vfuncs, we now have 3 and rely on the factory keeping track
of what it needs to do.

We're doing lots of dancing from one object to another here, but this
will hopefully get simpler with further commits.
2020-05-30 19:26:46 -04:00
Benjamin Otte
b33c56819b listitemfactory: Reorganize vfuncs
Instead of bind/rebind/update/unbind, we now just have update, and the
factories get to interpret that in the way they want.
2020-05-30 19:26:46 -04:00
Benjamin Otte
30f09ea10b listitem: Make this a GObject
This splits GtkListItem into 2 parts:

1. GtkListItem
   This is purely a GObject with public API for developers who want to
   populate lists. There is no chance to cause conflict with GtkWidget
   properties that the list implementation assumed control over and
   defines a clear boundary.
2. GtkListItemWidget
   The widget part of the listitem. This is not only fully in control of
   the list machinery, the machinery can also use different widget
   implementations for different list widgets like I inted to for
   GtkColumnView.
2020-05-30 19:26:46 -04:00
Benjamin Otte
db3e225f09 builder: Make gtk_builder_extend_with_template() work with objects
This will be relevant later when we introduce GtkListItem which is not a
GtkWidget.
2020-05-30 19:26:46 -04:00
Benjamin Otte
a44c06b264 gtk-demo: Add a Coverflow application launcher
This is roughly the simplest demo I could come up with.

But I documented it, so there's your tutorial.

Related: #2214
2020-05-30 19:26:46 -04:00
Benjamin Otte
f5f9f70dd0 Add GtkSignalListItemFactory
So the poor Rust users can actually use this.

I would totally not use this ever!
2020-05-30 19:26:46 -04:00
Benjamin Otte
03e5c6e32d columnview: Allow adding/removing columns
... and make that work in UI files via <child>, too.
2020-05-30 19:26:46 -04:00
Benjamin Otte
ca9e0c0e68 gtk-demo: Add a minesweeper demo
The demo shows creating ones own listmodel and using it to fill a grid.

I am totally getting the hang of React btw:
500 lines of logic with no UI code and 100 lines of GtkBuilder XML and
I get a sweet UI.
2020-05-30 19:26:46 -04:00
Benjamin Otte
0e1632d002 Add GtkColumnView skeleton
It's just a copy/paste of the listview code with all the internals
gutted. The code doesn't do anything.
2020-05-30 19:26:46 -04:00
Benjamin Otte
f4eb026c86 wip: Add GtkCoverFlow
The widget mostly works out of the box, but some tweaking may be
necessary (in particular in the theme) and the gtk-demo changes might
require removing before this is production-ready.
2020-05-30 19:26:46 -04:00
Benjamin Otte
e46fa81927 listbase: Take over anchor handling
With that, pretty much all code but allocating the widgets is gone from
the gridview and listview.
2020-05-30 19:26:46 -04:00
Benjamin Otte
33c6b428f7 listbase: Add vfuncs to convert positions to/from coordinates
... and use that to implement PageUp/PageDown.

With that, all keyboard handling has been moved to GtkListBase.
2020-05-30 19:26:46 -04:00
Benjamin Otte
12331e3376 listbase: Move focus moving keybindings here
The focus tracker is not yet moved because that depends on scroll_to()
support and we don't have that yet.
Whoops.
So we use a hack.
2020-05-30 19:26:46 -04:00
Benjamin Otte
dd5e6d47db Remove gtk_selection_model_user_select_item() again
This reverts commit 6a164ab306dad9096bde736c907494c71086d3c4.

The function was awkward and we now have only one caller again, so we
can fold it back into it.
2020-05-30 19:26:46 -04:00
Benjamin Otte
2541037ec2 listbase: Move orientable implementation here 2020-05-30 19:26:46 -04:00
Benjamin Otte
9d6aa7d88e listbase: Move selection handling here 2020-05-30 19:26:46 -04:00
Benjamin Otte
0bd16308d6 listbase: Move item manager here
Nothing really changes, because both ListView and GridView still keep
self->item_manager around, but it's set up to point at the base's item
manager.

This way we can slowly move things to GtkListBase that need the item
manager (like trackers).
2020-05-30 19:26:46 -04:00
Benjamin Otte
0011ce949c listbase: Move GtkScrollable implementation
Shared code between GtkGridView and GtkListView.
2020-05-30 19:26:46 -04:00
Benjamin Otte
cc987b31ae Add GtkListBase
This is a base item for GTK's list widgets so they can share some (read:
hopefully a lot of) code.
2020-05-30 19:26:46 -04:00
Benjamin Otte
c092d0a616 gridview: Simplify allocation code
It doesn't fix the bug I'm after, but it looks a lot better.
2020-05-30 19:26:46 -04:00
Benjamin Otte
ea390a4a73 listview: Port various gridview improvements
- Handle anchor as align + top/bottom
  This fixes behavior for cells that are higher than the view
- Add gtk_list_view_adjustment_is_flipped()
  This should fix RTL handling of horizontal lists
- Fix scrolling
  This should make scrolling more reliable, particularly on short lists
  that are only a few pages long.
2020-05-30 19:26:46 -04:00
Benjamin Otte
6b98948f9a demo: Add a file browser demo 2020-05-30 19:26:46 -04:00
Benjamin Otte
f57afe51af gridview: Add move keybindings 2020-05-30 19:26:46 -04:00
Benjamin Otte
bc22d04737 gridview: Implement (un)select all
Adds listitem.select-all and listitem.unselect-all actions and installs
the same keybindings as the treeview for those actions.
2020-05-30 19:26:46 -04:00
Benjamin Otte
093677b0f8 gridview: Add a focus tracker
... and use that to properly update selections when moving around with
the arrow keys.
2020-05-30 19:26:46 -04:00
Benjamin Otte
c38e050cc7 gridview: Implement list.scroll-to action 2020-05-30 19:26:46 -04:00
Benjamin Otte
ba0122fd02 gridview: Add activation 2020-05-30 19:26:46 -04:00
Benjamin Otte
affd2737d5 gridview: Implement minimum row height
We only allocate a certain amount of widgets - and we don't want to run
out of them. So we make all widgets high enough for this to never
happen.
2020-05-30 19:26:46 -04:00
Benjamin Otte
cc68073af0 gridview: Implement the list.select-item action 2020-05-30 19:26:46 -04:00
Benjamin Otte
cb2948eda6 selectionmodel: Add gtk_selection_model_user_select_item()
I'm not sure this should be public API because it's incredibly awkward.
But it should definitely be shared between list widget implementations.
2020-05-30 19:26:46 -04:00
Benjamin Otte
1b105cdbef gridview: Implement anchors and scrolling 2020-05-30 19:26:45 -04:00
Benjamin Otte
dd436e8fe6 listitemmanager: Handle NULL factory
Just don't call it and create empty listitems.
2020-05-30 19:26:45 -04:00
Timm Bäder
a8d2bb6b22 demo: Use a listview as sidebar 2020-05-30 19:26:45 -04:00
Benjamin Otte
fcdc5030bd gtk-demo: Introduce awards
We need a way to get a useful listbox, so here we go!
2020-05-30 19:26:45 -04:00
Benjamin Otte
aad9adf8c3 builder: Autofill scope property of listitemfactory
I couldn't come up with a better way to automatically inherit the scope
in the builder list item factory that didn't involve a magic
incantation in the XML file. And I do not want developers to know magic
incantations to do a thing that should pretty much always be done.
2020-05-30 19:26:45 -04:00
Benjamin Otte
48a223abdf builderlistitemfactory: Add scope argument
This way, the scope used when creating builder instances can be
influenced. This way, callbacks can be passed into the factory.
2020-05-30 19:26:45 -04:00
Benjamin Otte
12e720fb23 listitemfactory: Make the builder factory properly buildable
Turn the construct arguments into construct properties so that they can
be set from ui files.
2020-05-30 19:26:45 -04:00
Benjamin Otte
042e13a932 listview: Add move keybindings
My god, these are a lot.

And my god, these are complicated to get right.
2020-05-30 19:26:45 -04:00
Benjamin Otte
2b9481ecdc listview: Add gtk_list_view_get_position_at_y() 2020-05-30 19:26:45 -04:00
Benjamin Otte
933c0c678a listitem: Add "listitem.select" action and keybindings for it
In fact, grab space with all modifiers to toggle selection of the
current item.
2020-05-30 19:26:45 -04:00
Benjamin Otte
2539828eac listview: Add a focus tracker
This ensures that the row with the input focus always stays available,
even when scrolled out of view.
2020-05-30 19:26:45 -04:00
Benjamin Otte
4b6f3e0f2c listview: Implement (un)select all
Adds listitem.select-all and listitem.unselect-all actions and installs
the same keybindings as the treeview for those actions.
2020-05-30 19:26:45 -04:00
Benjamin Otte
b9eb818b57 listview: Track focus movements and update selection
When focus moves via tab/arrow, we need to select the new item.
2020-05-30 19:26:45 -04:00
Benjamin Otte
eda547fc4e listview: Implement activation
- a GtkListview::activate signal
- a GtkListItem::activatable property
- activate list items on double clicks and <Enter> presses
2020-05-30 19:26:45 -04:00
Benjamin Otte
1dbd017766 treeexpander: Implement input support
This implements all the keybindings from GtkTreeView that can be
supported.

It does not implement expand-all, because supporting that means
causing the TreeListModel to emit lots of create_model vfuncs which in
turn would cause many items-changed signal which in turn would cause
many signal handlers to run which in turn would make "expand-all" very
reentrant, and I'm uneasy about supporting that.

For the mouse, just add a click gesture to the expander icon that toggles
expanded state.
2020-05-30 19:26:45 -04:00
Benjamin Otte
08d9a57c6e listitem: Change focus handling
Focus in the listitem now works like this:
1. If any child can take focus, do not ever attempt
   to take focus.
2. Otherwise, if this item is selectable or activatable,
   allow focusing this widget.

This makes sure every item in a list is focusable for
activation and selection handling, but no useless widgets
get focused and moving focus is as fast as possible.
2020-05-30 19:26:45 -04:00
Benjamin Otte
d7b5966fa7 inspector: Make the recorder node list use a ListView
It's quite a bit faster now, but the code is also a bit more awkward.

Pain points:

- GtkTreeListModel cannot be created in UI files because it needs
  a CreateModelFunc.
  Using a signal for this doesn't work because autoexpand wants to
  expand the model before the signal handler is connected.

- The list item factory usage is still awkward. It's bearable here
  because the list items are very simple, but still.
2020-05-30 19:26:45 -04:00
Benjamin Otte
bb44120ae3 inspector: Use a GtkTreeExpander in the object tree 2020-05-30 19:26:45 -04:00
Benjamin Otte
8b1f034242 inspector: Use a treeexpander in the recorder 2020-05-30 19:26:45 -04:00
Benjamin Otte
bb7968ba77 demo: Add a GSettings tree demo
It is meant to look somewhat like dconf-editor when it is done.

So far, it's just a list.
2020-05-30 19:26:45 -04:00
Benjamin Otte
7451e51619 Add GtkTreeExpander
This is a container widget that takes over all the duties of tree
expanding and collapsing.
It has to be a container so it can capture keybindings while focus is
inside the listitem.

So far, this widget does not allow interacting with it, but it shows the
expander arrow in its correct state.

Also, testlistview uses this widget now instead of implementing
expanding itself.
2020-05-30 19:26:45 -04:00
Benjamin Otte
ea93e18081 gridview: Actually do something
Implement measuring and allocating items - which makes the items appear
when drawing and allows interacting with the items.

However, the gridview still does not allow any user interaction
(including scrolling).
2020-05-30 19:26:45 -04:00
Benjamin Otte
443e44853a listview: Pass the CSS name of listitems to the manager
... instead of hardcoding "row".
2020-05-30 19:26:45 -04:00
Benjamin Otte
b73e95655d gridview: Implement GtkOrientable
Again, this is just the skeleton, because the Gridview does nothing yet.
2020-05-30 19:26:45 -04:00
Benjamin Otte
e8bb84e0e2 gridview: Add factory handling
Just copy the listview APIs.

Code still doesn't do anything with it.
2020-05-30 19:26:45 -04:00
Benjamin Otte
626c525706 listview: Expose GtkListItemFactory APIs
Due to the many different ways to set factories, it makes sense to
expose them as custom objects.

This makes the actual APIs for the list widgets simpler, because they
can just have a regular "factory" property.

As a convenience function, gtk_list_view_new_with_factory() was added
to make this whole approach easy to use from C.
2020-05-30 19:26:45 -04:00
Benjamin Otte
2ef2148fb5 gtk-demo: Add a rough start at a Weather demo
This demos a horizontal listview.
2020-05-30 19:26:45 -04:00
Benjamin Otte
86ad1bec16 listview: Implement GtkOrientable 2020-05-30 19:26:45 -04:00
Benjamin Otte
360a728d77 tests: Add a rough form of multiselection
Just store a "filechooser::selected" attribute in the GFileInfo if
the file is meant to be selected.
2020-05-30 19:26:45 -04:00
Benjamin Otte
cfcf0a7a8a listview: Implement extending selections
Shift-clicking to extend selections now also works, imitating the
behavior of normal clicking and Windows Explorer (but not treeview):

1. We track the last selected item (normally, not via extend-clicking).

2. When shift-selecting, we modify the range from the last selected item
   to this item the same way we modify the regular item when not using
   shift:

2a. If Ctrl is not pressed, we select the range and unselect everything
    else.

2b. If Ctrl is pressed, we make the range have the same selection state
    as the last selected item:
    - If the last selected item is selected, select the range.
    - If the last selected item is not selected, unselect the range.
2020-05-30 19:26:45 -04:00
Benjamin Otte
f57fca7a00 listview: Add list.scroll_to_item action
The action scrolls the given item into view.

Listitems activate this action when they gain focus.
2020-05-30 19:26:45 -04:00
Benjamin Otte
7c38ac1954 testlistview: Load icons async
Speeds up loading by 4x, because out of view icons aren't loaded
anymore.
2020-05-30 19:26:45 -04:00
Benjamin Otte
dbe802f685 testlistview: Port to directory list 2020-05-30 19:26:45 -04:00
Benjamin Otte
cfb293d396 listitemfactory: Add a factory for ui files
Reuse <template> magic to initialize GtkListItems. This feels
amazingly hacky, but it also amazingly worked on the first try.
2020-05-30 19:26:45 -04:00
Benjamin Otte
2227fb957f listitemfactory: Split implementation out
.. into gtkfunctionslistitemfactory.c

Now we can add a different implmenetation.
2020-05-30 19:26:45 -04:00
Benjamin Otte
824326a029 listitemfactory: vfuncify
No functional changes other than a new indirection.
2020-05-30 19:26:45 -04:00
Benjamin Otte
10b967ae1f listitemfactory: Sanitize APIs
Make sure the APIs follow a predictable path:

setup
  bind
    rebind/update (0-N times)
  unbind
teardown

This is the first step towards providing multiple different factories.
2020-05-30 19:26:45 -04:00
Benjamin Otte
0174bf4345 listview: Add gtk_list_view_set_show_separators()
Do the same thing that GtkListBox does in commit
0249bd4f8a
2020-05-30 19:26:45 -04:00
Benjamin Otte
1acfae8df2 listitemmanager: Add trackers
... and replace the anchor tracking with a tracker.

Trackers track an item through the list across changes and ensure that
this item (and potentially siblings before/after it) are always backed
by a GtkListItem and that if the item gets removed a replacement gets
chosen.

This is now used for tracking the anchor but can also be used to add
trackers for the cursor later.
2020-05-30 19:26:45 -04:00
Benjamin Otte
ce489f21fb listitemmanager: Simplify
Remove a bunch of API from the headers that isn't used anymore and then
refactor code to not call it anymore.

In particular, get rid of GtkListItemManagerChange and replace it with a
GHashTable.
2020-05-30 19:26:45 -04:00
Benjamin Otte
368f04e06b gridview: Implement GtkScrollable
We can now scroll all the nothing we display.

We also clip it properly.
2020-05-30 19:26:45 -04:00
Benjamin Otte
dc91782165 listitemmanager: Move list of listitems here
All the listview infrastructure moved with it, so the next step is
moving that back...
2020-05-30 19:26:45 -04:00
Benjamin Otte
86a75abe51 gridview: Add API for setting number of columns
The API isn't used yet.
2020-05-30 19:26:45 -04:00
Benjamin Otte
70aaecc937 gtk: Add a GtkGridView skeleton 2020-05-30 19:26:45 -04:00
Benjamin Otte
057effc5d6 listitem: Add a press gesture to select the item
This is implemented by using actions, which are a neat trick to get to
allow the ListItem to call functions on the ListView without actually
needing to be aware of it.
2020-05-30 19:26:45 -04:00
Benjamin Otte
d8c116f20a listview: Add initial support for displaying selections 2020-05-30 19:26:45 -04:00
Benjamin Otte
01386aef29 listview: Reset listitems' CSS animations when rebinding
This way, newly displayed rows don't play an unselect animation (text
fading in) when they are unselected, but the row was previously used for
a selected item.
2020-05-30 19:26:45 -04:00
Benjamin Otte
b3fb80c608 listview: Add selection properties to ListItem
This just brings the infrastructure into place, we're not using the
properties yet.
2020-05-30 19:26:45 -04:00
Benjamin Otte
5b69fd535d listview: Try to keep the list items in order when scrolling
Instead of just destroying all items and then recreating them (or even
hide()ing and then show()ing them again (or even even repositioning
them in the widget tree)), just try to reust them in the order they are.

This works surprisingly well when scrolling and most/all widgets
just moved.
2020-05-30 19:26:45 -04:00
Benjamin Otte
7831980c1d listlistmodel: Add gtk_list_list_model_item_moved()
Use it to fix a case that just said g_warning ("oops").

Apparently I had forgotten the case where a container moved a child
in the widget tree.
2020-05-30 19:26:45 -04:00
Benjamin Otte
fbfc7dc690 listitemmanager: Switch from "insert_before" to "insert_after" argumnet
We reorder widgets start to end, so when reusing a list item, we
correctly know the previous sibling for that list item, but not the
next sibling yet. We just know the widget it should ultimately be in
front of.
So we can do a more correct guess of the list item's place in the widget
tree if we think about where to place an item like this.

Actually using this change will come in the next commit.
2020-05-30 19:26:45 -04:00
Benjamin Otte
d8eec549f0 testlistview: Create widgets only once
Previously, we were recreating all widgets every time the list item was
rebound, which caused a lot of extra work every time we scrolled.

Now we keep the widgets around and only set their properties again when
the item changes.
2020-05-30 19:26:45 -04:00
Benjamin Otte
7389e704dc testlistview: Show the row number
Always show the current row. This is mostly useful for debugging, not
for beauty.
2020-05-30 19:26:45 -04:00
Benjamin Otte
b64da6d268 listview: Only allocate necesary rows
This is the big one.

The listview only allocates 200 rows around the visible row now.
Everything else is kept in ListRow instances with row->widget == NULL.

For rows without a widget, we assign the median height of the child
widgets as the row's height and then do all calculations as if there
were widgets that had requested that height (like setting adjustment
values or reacting to adjustment value changes).

When the view is scrolled, we bind the 200 rows to the new visible area,
so that the part of the listview that can be seen is always allocated.
2020-05-30 19:26:45 -04:00
Benjamin Otte
2ba2a216ca listview: Change anchor handling again
The anchor is now a tuple of { listitem, align }.

Using the actual list item allows keeping the anchor across changes
in position (ie when lists get resorted) while still being able to fall
back to positions (list items store their position) when an item gets
removed.

The align value is in the range [0..1] and defines where in the visible
area to do the alignment.
0.0 means to align the top of the row with the top of the visible area,
1.0 aligns the bottom of the widget with the visible area and 0.5 keeps
the center of the widget at the center of the visible area.
It works conceptually the same as percentages in CSS background-position
(where the background area and the background image's size are matched
the same way) or CSS transform-origin.
2020-05-30 19:26:45 -04:00
Benjamin Otte
e5add36a17 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.
2020-05-30 19:26:45 -04:00
Benjamin Otte
fe14181d4e 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.
2020-05-30 19:26:45 -04:00
Benjamin Otte
378a573cf4 tests: Make animating listview do random resorts 2020-05-30 19:26:45 -04:00
Benjamin Otte
ec8684e87d 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.
2020-05-30 19:26:45 -04:00
Benjamin Otte
54042029d3 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.
2020-05-30 19:26:45 -04:00
Benjamin Otte
e1fa627158 listview: Add GtkListItem
GtkListItem is a generic row widget that is supposed to replace
GtkListBoxRow and GtkFlowBoxChild.
2020-05-30 19:26:45 -04:00
Benjamin Otte
9d5bb875b1 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.
2020-05-30 19:26:44 -04:00
Benjamin Otte
b3c150e929 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.
2020-05-30 19:26:44 -04:00
Benjamin Otte
d03a55599b 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.
2020-05-30 19:26:44 -04:00
Benjamin Otte
ed8fe6c219 listview: Implement GtkScrollable
Scrolling in a very basic form is also supported
2020-05-30 19:26:44 -04:00
Benjamin Otte
c835ae2a02 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.
2020-05-30 19:26:44 -04:00
Benjamin Otte
e20c207a22 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.
2020-05-30 19:26:44 -04:00
Benjamin Otte
e19c4a3372 gtk: Add a GtkListView skeleton 2020-05-30 19:26:44 -04:00
Benjamin Otte
934bfc8887 builder: Add <binding> tag
The tag contains an expression that it then gtk_expression_bind()s to
the object it is contained in.
2020-05-30 19:26:44 -04:00
Benjamin Otte
713a6676ff 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.
2020-05-30 19:26:44 -04:00
Benjamin Otte
448a88e4f5 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.
2020-05-30 19:26:44 -04:00
Benjamin Otte
ed22af50bc builder: Make <lookup> type optional
If no type is set, use the type of the expression.
2020-05-30 19:26:44 -04:00
Benjamin Otte
d3dc9c41b4 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).
2020-05-30 19:26:44 -04:00
Matthias Clasen
d1b2ded7e2 sorter: Add tests
Some basic tests for GtkSorter.
2020-05-30 19:26:44 -04:00
Benjamin Otte
ee3faf24b9 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.
2020-05-30 19:26:44 -04:00
Benjamin Otte
16ab648093 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.
2020-05-30 19:26:44 -04:00
Matthias Clasen
11a1f8f36a Redo sort list model with GtkSorter
Reshuffle the api to take full advantage
of GtkSorter. Update all callers.
2020-05-30 19:26:44 -04:00
Matthias Clasen
1eda9884a0 Add GtkNumericSorter
This sorter compares numbers obtained from items
by evaluating an expression.
2020-05-30 19:26:44 -04:00
Matthias Clasen
ae4bb2d914 Add GtkMultiSorter
This is a sorter that tries multiple sorters in turn.
2020-05-30 19:26:44 -04:00
Matthias Clasen
6d68c536f3 Add GtkStringSorter
This is a GtkSorter implementation collating strings
2020-05-30 19:26:44 -04:00
Matthias Clasen
e74a9d09e6 Add GtkCustomSorter
This is a GtkSorter implementation which uses a GCompareDataFunc.
2020-05-30 17:48:44 -04:00
Matthias Clasen
b2b847f365 Add GtkSorter
This is a helper object for sorting, similar to GtkFilter.
2020-05-30 17:48:44 -04:00
Benjamin Otte
cb15ec0257 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.
2020-05-30 17:48:44 -04:00
Matthias Clasen
115923b2d9 More expression tests
Test type mismatches, and the this pointer
during evaluation.
2020-05-30 17:48:44 -04:00
Benjamin Otte
ad60efb5d7 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.
2020-05-30 17:48:44 -04:00
Benjamin Otte
b7efe4eb4f 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().
2020-05-30 17:48:44 -04:00
Benjamin Otte
92c359ca09 testsuite: Add expression tests 2020-05-30 17:48:44 -04:00
Benjamin Otte
ec742f9373 expression: Add the ability to watch an expression 2020-05-30 17:48:44 -04:00
Benjamin Otte
fde75aa9f6 builder: Add support for parsing expressions 2020-05-30 17:47:47 -04:00
Benjamin Otte
2df3c39e50 filter: Add tests
Some basic tests for GtkFilter
2020-05-30 17:42:09 -04:00
Benjamin Otte
22659afd00 Add GtkMultiFilter, GtkAnyFilter, GtkEveryFilter
GtkMultiFilter is the abstract base class for managing multiple child
filter.
GtkAnyFilter and GtkEveryFilter are the actual implementations.
2020-05-30 17:42:09 -04:00
Benjamin Otte
410e7dcf5d 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.
2020-05-30 17:42:09 -04:00
Benjamin Otte
bd8655fdee expression: Add GtkObjectExpression
Weak refs break cycles...
2020-05-30 17:42:09 -04:00
Benjamin Otte
e9f1ee5aab 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.
2020-05-30 17:42:08 -04:00
Benjamin Otte
4abdf695e3 filterlistmodel: Rewrite to use GtkFilter 2020-05-30 12:30:23 -04:00
Benjamin Otte
b1090ac8e2 tests: Remove testtreemodel test
testlistview does everything this test does.
2020-05-30 12:30:23 -04:00
Benjamin Otte
1ab081b584 Add GtkCustomFilter 2020-05-30 12:30:23 -04:00
Benjamin Otte
1df17f2fea Add GtkFilter 2020-05-30 12:30:23 -04:00
Benjamin Otte
682e97826c 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.
2020-05-30 12:30:23 -04:00
Benjamin Otte
805fea20cb eventcontrollermotion: Remove mode argument
It's not used and nobody has documented how it's meant to work anyway.
2020-05-30 12:30:23 -04:00
Matthias Clasen
415bfeb950 Merge branch 'fix-pango-deps' into 'master'
Fix inconsistencies in our pango deps

See merge request GNOME/gtk!1989
2020-05-30 16:29:12 +00:00
Matthias Clasen
2f20a40922 Merge branch 'matthiasc/for-master' into 'master'
Some listview preparations

See merge request GNOME/gtk!1988
2020-05-30 15:51:21 +00:00
Matthias Clasen
5235a4c48a Fix inconsistencies in our pango deps
We were applying the pango version requirements inconsistently,
leading to different pango variables being taking from system
pango vs the subproject at times. Thankfully, meson detects
this and complains, so we can fix it.
2020-05-30 11:13:55 -04:00
Matthias Clasen
bb7f6ed544 Merge branch 'fix-gesture-leak' into 'master'
gesture: Don't leak target widgets

Closes #2801

See merge request GNOME/gtk!1986
2020-05-30 15:12:05 +00:00
Benjamin Otte
f1d6a0a4ed widget: Add gtk_widget_get_size()
A little bit of convenience.
2020-05-30 10:48:02 -04:00
Benjamin Otte
3c1cca13b7 wayland: Remove function declaration for nonexisting function 2020-05-30 10:46:49 -04:00
Benjamin Otte
1ef805328f builder: Allow <property bind /> for objects
Previously, object properties had to always be set to a value.
This now works without it.
2020-05-30 10:46:27 -04:00
Matthias Clasen
fd73f8d972 Merge branch 'pango-bump-v2' into 'master'
pango version bump v2

See merge request GNOME/gtk!1987
2020-05-30 14:45:47 +00:00
Matthias Clasen
3a8ebf4c9f Merge branch 'wip/jimmac/backdrop-assasination' into 'master'
Adwaita: limit scope of :backdrop

Closes #2694

See merge request GNOME/gtk!1978
2020-05-30 14:41:52 +00:00
Matthias Clasen
b482b7d8af Bump the pango dependency
We soon want to rely on the list model apis in
pango 1.45. This commit also fixes a mixup where
using pango as a submodule would break the build
when pangoft2 is required.
2020-05-30 15:47:56 +02:00
Matthias Clasen
0d69c42320 gesture: Don't leak target widgets
This was broken when we started tracking event targets
in dcbecdac31.

Fixes: #2801
2020-05-30 09:47:24 -04:00
Christoph Reiter
011f5afe4e CI: install a newer pango for MSYS2
Uses a build from git master from today
2020-05-30 15:47:02 +02:00
Matthias Clasen
8bab7b237c Merge branch 'matthiasc/for-master' into 'master'
eventcontroller: Fix crossing event scopes

See merge request GNOME/gtk!1983
2020-05-30 13:41:42 +00:00
Matthias Clasen
821a458393 Revert "Bump the pango dependency"
This reverts commit 98df0be43d.

It broke the win32 build.
2020-05-30 08:55:21 -04:00
Matthias Clasen
66120cff4b eventcontroller: Fix crossing event scopes
We want to deliver crossing events to controllers
with scope same-native as long as at least one of
the targets is on the same native. As a new approach,
treat out-of-scope targets like NULL, and deliver
crossing events as long as one of the targets is
not NULL.
2020-05-29 19:41:39 -04:00
Matthias Clasen
8ce1034e87 Add GTK_DEBUG=shortcuts
If the shortcuts debug flag is set, print out
shortcut activations.
2020-05-29 17:59:58 -04:00
Matthias Clasen
a39d708859 meson: Cosmetics
Treat the display backend list like other lists in the summary.
2020-05-29 15:40:34 -04:00
Matthias Clasen
98df0be43d Bump the pango dependency
We soon want to rely on the list model apis in
pango 1.45. This commit also fixes a mixup where
using pango as a submodule would break the build
when pangoft2 is required.
2020-05-29 10:53:39 -04:00
Matthias Clasen
4125eb01ba Merge branch 'matthiasc/for-master' into 'master'
Bring back gdk_display_put_event

See merge request GNOME/gtk!1980
2020-05-29 14:14:02 +00:00
Matthias Clasen
346bba6592 Bring back gdk_display_put_event
It is still needed in WebKit.
2020-05-29 09:26:50 -04:00
Jakub Steiner
f4705bab1e Adwaita: limit scope of :backdrop
- most controls don't have:backdrop state
- different :backdrop state reserved for windows, headebars and toolbars
  and some buttons

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/2694
2020-05-29 12:43:13 +02:00
Matthias Clasen
c7a9d7b56b Merge branch 'im-context-key-forward' into 'master'
Add back keyboard related apis

See merge request GNOME/gtk!1977
2020-05-29 00:10:39 +00:00
Matthias Clasen
4d4b836976 Merge branch 'display-api' into 'master'
gdk: Make event-related apis private

See merge request GNOME/gtk!1929
2020-05-28 21:11:54 +00:00
Matthias Clasen
506d73cf32 Add gtk_im_context_filter_key
An event-less variant of the filtering api.
2020-05-28 17:08:33 -04:00
Jordi Mas
d71ad3539e Update Catalan translation 2020-05-28 21:43:02 +02:00
Matthias Clasen
266a3a5267 Export keymap translation again
This is needed in WebKit webdriver test environment.
2020-05-28 15:15:53 -04:00
Matthias Clasen
48f8affb2c gdk: Make event-related apis private
Without a way to create events, there is no point
in allowing gdk_display_put_event to be used from
the outside. And little good can come out of using
the other apis, so just make them all private.
2020-05-28 14:53:08 -04:00
Alexander Larsson
2503251576 Merge branch 'frame-clock-alternative-approach-gtk4' into 'master'
Frame clock alternative approach for gtk4

See merge request GNOME/gtk!1932
2020-05-28 16:22:53 +00:00
Alexander Larsson
a27fed47e0 frame-clock: Ensure we're always monotonic
A call to frame gdk_frame_clock_get_frame_time() outside of the paint
cycle could report an un-error-corrected frame time, and later a
corrected value could be earlier than the previously reported value.

We now always store the latest reported time so we can ensure
monotonicity.
2020-05-28 17:44:51 +02:00
Matthias Clasen
56030a7a81 Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1976
2020-05-28 13:43:22 +00:00
Alexander Larsson
fee3aaae94 tests: Disable idle locking in headless weston
In my local testing i was burned by the default 300sec value here.
I'm not sure if we actually hit this in the CI, but lets not
take any chances.
2020-05-28 15:15:04 +02:00
Alexander Larsson
20f15f5111 reftests: Fix frame inhibiting
Actually inhibit snapshotting of frames from reftest_inhibit_snapshot.
We were not ignoring the case where inhibit_count > 0, and then disconnected
the callback meaning we only ever got the first snapshot.
2020-05-28 15:13:13 +02:00
Alexander Larsson
9ef3e70040 frame-clock: New approach in smoothing frame clock
In commit c6901a8b, the frame clock reported time was changed from
simply reporting the time we ran the frame clock cycle to reporting a
smoothed value that increased by the frame interval each time it was
called.

However, this change caused some problems, such as:
 https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/1415
 https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/1416
 https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/1482

I think a lot of this is caused by the fact that we just overwrote the
old frame time with the smoothed, monotonous timestamp, breaking
some things that relied on knowing the actual time something happened.

This is a new approach to doing the smoothing that is more explicit.
The "frame_time" we store is the actual time we ran the update cycle,
and then we separately compute and store the derived smoothed time and
its period, allowing us to easily return a smoothed time at any time
by rounding the time difference to an integer number of frames.

The initial frame_time can be somewhat arbitrary, as it depends on the
first cycle which is not driven by the frame clock. But follow-up
cycles are typically tied to the the compositor sending the drawn
signal. It may happen that the initial frame is exactly in the middle
between two frames where jitter causes us to randomly round in
different directions when rounding to nearest frame. To fix this we
additionally do a quadratic convergence towards the "real" time,
during presentation driven clock cycles (i.e. when the frame times are
small).
2020-05-28 15:13:07 +02:00
Alexander Larsson
f1215d2d77 frame clock: Use compositor refresh rate info even if presentation time not set
On my X11 + nvidia setup gnome-shell doesn't report presentation times.
However it does report refresh rate. We were mostly using this in our
calculation except when computing predicted presentation time, were
it fell back on the default 60Hz.
2020-05-28 15:12:32 +02:00
Alexander Larsson
0ad73da68a frame clock: Used drawn_time (as well as presentation time) in profiler marks. 2020-05-28 15:12:32 +02:00
Alexander Larsson
e2a4be0243 FrameClock debug: Log drawn_time if set 2020-05-28 15:12:32 +02:00
Matthias Clasen
2d80b105ce shortcut controller: Fix mnemonic cycling
Iterate the shortcuts we found in order, not in
reverse. Otherwise, we always end up activating
the last_selected one, since it is last in the
list.

This broke in fb9b54d4b2 when a list was
turned into an array.
2020-05-28 08:52:55 -04:00
Matthias Clasen
1f4130b927 widget-factory: Add a mnemonic conflict
Make Alt-e the mnemionic for both the Edit menu
and the Select button on page 2. This shows that
mnemonic cycling doesn't currently work, we always
open the menu.
2020-05-28 08:34:06 -04:00
Yuri Chornoivan
bdf40943db Update Ukrainian translation 2020-05-28 10:05:11 +00:00
Emmanuele Bassi
4c9357aaef Merge branch 'fix_typos' into 'master'
Fix minor typos

See merge request GNOME/gtk!1974
2020-05-28 09:11:43 +00:00
Yuri Chornoivan
01bd4cc4e1 Fix minor typos 2020-05-28 11:00:03 +03:00
Matthias Clasen
92bc78c12f Merge branch 'matthiasc/for-master' into 'master'
a11y: Widgets have children

See merge request GNOME/gtk!1973
2020-05-28 03:58:02 +00:00
Matthias Clasen
8e427b7d69 a11y: Widgets have children
This brings back some of what we lost when
GtkContainerAccessible went away.
2020-05-27 22:56:33 -04:00
Matthias Clasen
2ad127d290 Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1972
2020-05-28 00:55:42 +00:00
Matthias Clasen
2c80691be6 aboutdialog: Stop overriding show()
This is entirely unnecessary.
2020-05-27 20:05:26 -04:00
Matthias Clasen
1cd71203b8 volumebutton: Enable the tooltips
Little point in having a query-tooltip handler if
we don't make sure ::query-tooltip is emitted.
2020-05-27 19:02:30 -04:00
Matthias Clasen
9c5fc0fb7a volumebutton: Remove broken a11y code
The accessible of a button is not an AtkImage,
so whatever this code was trying to do isn't
working. Remove it.
2020-05-27 19:02:19 -04:00
Matthias Clasen
1927a8af71 tooltips: Fix a line wrap mishap
We don't want wrapping labels to cause tooltips to
have excessive height, so we need to set a reasonable
value for width-chars, without forcing short tooltips
into a full line length. Also be careful to respect
preexisting line breaks (we have such examples in
widget factory).
2020-05-27 19:01:46 -04:00
Emmanuele Bassi
fe40e674c5 Merge branch 'ebassi/overlay-docs' into 'master'
Ebassi/overlay docs

See merge request GNOME/gtk!1970
2020-05-27 16:50:55 +00:00
Matthias Clasen
194b0be8bf Merge branch 'matthiasc/for-master' into 'master'
Add to the docs README

See merge request GNOME/gtk!1971
2020-05-27 16:36:18 +00:00
Matthias Clasen
c42219cd5b Add to the docs README
Mention markdown syntax and gtk-doc additions.
2020-05-27 11:11:30 -04:00
Emmanuele Bassi
637186976c Remove spurious annotations
Boolean values are not nullable, and have no ownership to transfer.
2020-05-27 15:49:24 +01:00
Emmanuele Bassi
175d4ef03e Add missing documentation for GtkOverlayLayout
We're missing the documentation for the constructor, and for the child
properties.
2020-05-27 15:49:24 +01:00
Emmanuele Bassi
85af410b8b Merge branch 'ebassi/howto-docs' into 'master'
Ebassi/howto docs

See merge request GNOME/gtk!1969
2020-05-27 14:10:40 +00:00
Emmanuele Bassi
347cb94c43 docs: Link the documentation guidelines
From the coding style.
2020-05-27 13:44:50 +01:00
Emmanuele Bassi
c5485cd6b1 Add the beginnings of a docs contribution guide
We have one for the whole project, but the documentation should have a
proper introduction and a proper style guide.
2020-05-27 13:44:50 +01:00
Emmanuele Bassi
e30c974646 Add myself to more sections 2020-05-27 13:44:50 +01:00
Emmanuele Bassi
6b6c76e3a2 docs: Remove last two steps from the release howto
Drop the GTK list announcements, as we don't have lists any more.

The GTK website updates itself automatically, these days.
2020-05-27 13:44:50 +01:00
Emmanuele Bassi
25a8fa73f8 docs: Turn coding style into a markdown document
It was mostly one already, just needed some minor fixes.
2020-05-27 13:44:50 +01:00
Timm Bäder
7f2e3c44b3 Merge branch 'carlosgc/fix-build' into 'master'
build: add gtkoverlaylayout.h to the list of public headers

See merge request GNOME/gtk!1968
2020-05-27 10:06:53 +00:00
Carlos Garcia Campos
a2aa25d28e build: add gtkoverlaylayout.h to the list of public headers
GtkOverlayLayout is now public but the header is not installed.
2020-05-27 11:13:02 +02:00
Matthias Clasen
9f4da7dfd1 Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1967
2020-05-27 03:54:59 +00:00
Matthias Clasen
646a1c2b88 win32: Drop an unsed variable 2020-05-26 22:23:43 -04:00
Matthias Clasen
c47553e319 gdk: Drop no-longer-used documentation
Thread support is gone, and we don't have that
section in the docs anymore.
2020-05-26 20:52:41 -04:00
Matthias Clasen
45f162fc50 gdk: Remove an unused texture api
gdk_gl_texture_from_surface wasn't used anywhere,
so lets drop it.
2020-05-26 20:43:47 -04:00
Matthias Clasen
a20291f235 gdk: Drop some unused event queue functions 2020-05-26 20:43:47 -04:00
Matthias Clasen
3468b2fc44 gdk: Clean up gdkinternals.h
Remove definitions that are just leftovers with
nothing behind them anymore.
2020-05-26 20:43:47 -04:00
Matthias Clasen
aa0d0dc510 gdk: Drop _gdk_windowing_args
We are no longer parsing commandline args, so this
was a useless leftover that was still defined in
the win32 backend.
2020-05-26 20:13:13 -04:00
Matthias Clasen
9c82946e45 docs: Drop a mention of gdk_window_move()
We don't have windows anymore, and they don't move
anymore either.
2020-05-26 20:05:34 -04:00
Matthias Clasen
e5a9255555 gdk: Move the GdkGeometry typedef to gdkinternals.h
The struct was already there, so this is just a leftover.
2020-05-26 20:04:40 -04:00
Matthias Clasen
e14322137f gdk: Drop the GdkByteOrder enum
Move it to the private gdkvisual-x11.h header, which
is the only place where its used.
2020-05-26 19:45:01 -04:00
Matthias Clasen
f27d855c68 gdk: Drop the GdkEventMask enum
This is not used in public api anymore.
Some of the backends still use it internally,
so keep it in gdkinternals.h for now.
2020-05-26 19:39:31 -04:00
Matthias Clasen
0553b10214 gdk: Drop the GdkSurfaceTypeHint enum
This is not used in public api anymore.
Some of the backends still use it internally,
so keep it in gdkinternals.h for now.
2020-05-26 19:34:59 -04:00
Matthias Clasen
105fc16a9a testsuite: Drop the type-hint property from tests
No point in excluding a property that no longer
exists.
2020-05-26 19:31:12 -04:00
Matthias Clasen
efbc661620 window: Drop an unused field
The type-hint property is gone, and nothing reads
or writes the type_hint field anymore.
2020-05-26 19:30:26 -04:00
Matthias Clasen
7fb5b970f5 gdk: Drop GDK_PARENT_RELATIVE
This define is not used anywhere.
2020-05-26 19:21:55 -04:00
Matthias Clasen
5f9bcd0409 accelgroup: Expand translator comment
Add details about the use of KP.
2020-05-25 22:50:03 -04:00
Matthias Clasen
bd3f4599ed Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

Closes #2778

See merge request GNOME/gtk!1966
2020-05-26 02:41:37 +00:00
Matthias Clasen
ddf6138d07 Merge branch 'ebassi/for-master' into 'master'
Ebassi/for master

Closes #2783

See merge request GNOME/gtk!1962
2020-05-26 01:35:11 +00:00
Matthias Clasen
8c6bbcdc2e docs: Mention shortcuts in the migration guide
Add a few paragraphs about GtkAccelGroup, GtkBindingSet
and GtkAccelMap to the migration guide.

Fixes: #2778
2020-05-25 21:27:58 -04:00
Matthias Clasen
a55d179215 accelgroup: Drop some unused code 2020-05-25 20:56:09 -04:00
Matthias Clasen
ec39ddee63 Help static analysis with an assertion
It is hard for clang to see that layouts will
always be smaller than num_layouts, so just assert
that.
2020-05-25 20:56:09 -04:00
Matthias Clasen
0f096d6ad9 bitmask: add an assertion
The static analysis in ci is complaining about
this, since it doesn't know that start is always
smaller than end.
2020-05-25 20:56:09 -04:00
Matthias Clasen
92d42d4b67 printing: Drop a redundant assignment
This showed up as a warning in static analysis in ci.
2020-05-25 20:56:09 -04:00
Matthias Clasen
17b5cfc924 docs: Mention pandoc as build dependency 2020-05-25 20:56:09 -04:00
Matthias Clasen
5590e2f6f2 Merge branch 'doc-chapters-markdown' into 'master'
Include markdown content, via pandoc

See merge request GNOME/gtk!1961
2020-05-26 00:55:10 +00:00
Matthias Clasen
ae2e548b4b docs: Use the right python 2020-05-25 18:40:09 -04:00
Matthias Clasen
4dbf73d9aa Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1965
2020-05-25 20:23:06 +00:00
Matthias Clasen
86f8be41d0 ci: Use fedora-docs for the doc build
Our doc build now uses pandoc, so use an image
that has it.
2020-05-25 16:11:18 -04:00
Matthias Clasen
f60149cd9e ci: Add a fedora-docs image
Split the fedora image into fedora-base (containing just
the packages) and fedora (adding the user setup), and add
a fedora-docs image that is adding pandoc on top of the
fedora-base image.
2020-05-25 16:11:18 -04:00
Matthias Clasen
aca8090a09 docs: Convert question index to markdown
With this, the expand_content_files list has been
completely converted to markdown files. Whats left
in content_files is man pages, and a few special
cases.
2020-05-25 16:11:18 -04:00
Matthias Clasen
84437ee0e0 docs: Allow interrupted lists
We use such an interrupted, numbered list in the
q&a section, so tell pandoc to pay attention to
start numbers.
2020-05-25 16:11:18 -04:00
Matthias Clasen
dc858c9686 docs: Convert treeview and textview overview to markdown 2020-05-25 16:11:18 -04:00
Matthias Clasen
581b39a38d docs: Allow influencing pandoc divisons
Arrange for files named section-foo.md to be turned
into docbook sections, while others get turned into
chapters. This is necessary to allow including such
content in chapters, since chapters in docbook don't
nest.
2020-05-25 16:11:18 -04:00
Matthias Clasen
a37b9d7578 docs: Drop the glossary
It is very incomplete, somewhat outdated, and
we lack the resources to maintain it properly.
2020-05-25 16:11:18 -04:00
Matthias Clasen
5a3fe9e5f5 docs: Convert resources section to markdown 2020-05-25 16:11:18 -04:00
Matthias Clasen
f44d611f77 docs: Drop a long-stale file
The other_software.xml section has not been included in
the docs since 2.x, as far as I can tell. It was clearly
written before GIO existed.
2020-05-25 16:11:18 -04:00
Matthias Clasen
29fb9ae2d6 docs: Convert platform sections to markdown 2020-05-25 16:11:18 -04:00
Matthias Clasen
2595cd5a93 docs: Convert getting_started to markdown
As part of the conversion, give up on including
sources files from the examples directory, and
instead include the content directly. All include
mechanisms add complications. They were already
complicated with xml, and markdown is not making
things easier.

We already did that for fragments, and if you
make changes to these example sources, you
probably need to revise the surrounding text
anyway.
2020-05-25 16:11:18 -04:00
Matthias Clasen
bf14d75cad docs: Refresh the inspector screenshot 2020-05-25 16:11:18 -04:00
Matthias Clasen
b99511ee55 docs: Convert building, compiling, running to markdown 2020-05-25 16:11:18 -04:00
Matthias Clasen
3bf90b4218 doc: Check for pandoc
Add an explicit check for pandoc, so we get a clear
error message if it is missing.
2020-05-25 16:11:18 -04:00
Matthias Clasen
9873d983ed docs: Convert css overview to markdown 2020-05-25 16:11:18 -04:00
Matthias Clasen
3338d24da4 docs: Be more careful when expanding abbreviations
We must not expand #symbol in the middle of a url,
where it is probably a fragment identifier. Restrict
problem.
2020-05-25 16:11:18 -04:00
Matthias Clasen
10cd539104 wip: Include markdown content, via pandoc
Use pandoc to convert freestanding markdown files to docbook for
inclusion in the generated docs, and use bits and pieces of
gtk-doc code to continue expanding typical gtk-doc abbreviations.
The new tool for markdown -> docbook is a python script called
gtk-markdown-to-docbook.

The markdown dialect is specified via a list of pandoc extension
in gtk-markdown-to-docbook. It includes header annocations,
definition lists and tables, among other things.

This commit converts the 3 overview chapters (drawing, input
handling and actions) and the migration guide to markdown
syntax. Other files that are still listed in content_files
can be converted later.

This commit adds a pandoc dependency.
2020-05-25 16:11:18 -04:00
Matthias Clasen
e4623fd0c4 Add GtkOverlayLayout to the docs 2020-05-25 15:18:14 -04:00
Matthias Clasen
9fa3742c09 Make GtkOverlayLayout public
Keeping the layout manager type private does not
really work when it has layout child properties
that need to be usable in ui files.
2020-05-25 14:22:10 -04:00
Matthias Clasen
5317e4bc07 constraint-editor: Don't use g_type_ensure
This isn't necessary if we export the get_type function.
2020-05-25 14:14:28 -04:00
Timm Bäder
2127cc1943 adwaita: move backdrop box shadows to .csd
Fixes #2781
2020-05-25 10:36:29 +02:00
Timm Bäder
04b7dd802a compare-render: Fix some memory leaks 2020-05-24 17:14:18 +02:00
Emmanuele Bassi
7de9eb005e Add a comment for translators
"KP" refers to the numeric keypad, in this context.

Fixes: #2783
2020-05-24 15:20:13 +01:00
Emmanuele Bassi
d68e312c2b Use the private GdkKeyEvent.translated_key getter
We can avoid poking directly at the GdkKeyEvent structure, now.
2020-05-24 15:19:01 +01:00
Emmanuele Bassi
0cf5b66e7b Add private accessor for GdkKeyEvent.translated
Avoid accessing the event structure directly, even from within GTK.
2020-05-24 15:19:01 +01:00
Timm Bäder
d5bf3c2cd1 gl renderer: Improve clipping code
don't render a clip to a texture if the new clip does not intersect with
any of the corners of the currently rounded clip.

Fixes #2770
2020-05-24 15:59:05 +02:00
Timm Bäder
094788f1a3 gl renderer: Refactor render_clipped_child 2020-05-24 15:59:05 +02:00
Timm Bäder
23e68c0988 gl renderer: Cache whether clips is rectilinear 2020-05-24 15:59:05 +02:00
Timm Bäder
60902484fd applicationwindow: Simplify measure implementation
We already chain up first thing in this function, so no need to do it
again.
2020-05-24 15:59:05 +02:00
Timm Bäder
48c9c86626 window: Remove private _get_shadow_width()
Unused now.
2020-05-24 15:59:05 +02:00
Timm Bäder
2e27a76edd applicationwindow: Stop querying shadow width
don't need to do this anymore.
2020-05-24 15:59:05 +02:00
Piotr Drąg
be8fc8f26b Update Polish translation 2020-05-24 15:07:03 +02:00
Florentina Mușat
f1e3581347 Update Romanian translation 2020-05-24 10:48:29 +00:00
Florentina Mușat
0606dd511a Update Romanian translation 2020-05-24 10:37:15 +00:00
Emin Tufan Çetin
3e68c694b9 Update Turkish translation 2020-05-23 08:50:36 +00:00
Matthias Clasen
ffa5334a2d Merge branch 'matthiasc/for-master' into 'master'
gtk-demo: Fix the dnd demo drop highlight

See merge request GNOME/gtk!1958
2020-05-23 00:05:16 +00:00
Matthias Clasen
5e25ba6c5a Merge branch 'no-app-menu' into 'master'
Drop the app menu

Closes #2731

See merge request GNOME/gtk!1951
2020-05-22 23:46:56 +00:00
Matthias Clasen
5f6d072459 gtk-demo: Fix the dnd demo drop highlight
We want the drop highlight to be around the label,
not around the item containing it, so move the drop
target gesture to the right widget.
2020-05-22 18:52:56 -04:00
Matthias Clasen
1038b9b8a1 docs: Mention app menus in the migration guide 2020-05-22 18:46:51 -04:00
Matthias Clasen
0dc384265c Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1957
2020-05-22 22:19:59 +00:00
Matthias Clasen
133461581f Merge branch 'BUG_filechooserbutton_remote_GTK4' into 'master'
FileChooserButton: query 'display name' also for unbookmarked files

Closes #1966

See merge request GNOME/gtk!1725
2020-05-22 21:37:40 +00:00
Matthias Clasen
79d6a77d58 gtkapplication: Drop app menu support
Drop apis and code related to appmenus from
both GtkApplication and GtkApplicationWindow.

We still keep the menubar support, since it
is needed for system integration on OS X.

Fixes: #2731
2020-05-22 17:31:05 -04:00
Matthias Clasen
d5da3b9199 print-editor: Stop using appmenu apis
The appmenu-related GtkApplication apis are going away.
2020-05-22 17:31:05 -04:00
Matthias Clasen
a8df81b27c inspector: Drop app-menu support
Don't add app menu to the object tree anymore;
this property is going away.
2020-05-22 17:31:05 -04:00
Matthias Clasen
6c31092c69 examples: Stop using appmenu apis
The appmenu-related GtkApplication apis are going away.
2020-05-22 17:31:05 -04:00
Matthias Clasen
ca1c570c21 gtk-demo: Stop using appmenu apis
The appmenu-related GtkApplication apis are going away.
2020-05-22 17:31:05 -04:00
Matthias Clasen
33b836af7f fixed: Change coordinate apis to doubles
We are using floating point for coordinates
everywhere now, so be consistent here.

This commit also changes the implementation of
gtk_fixed_get_child_position to work with
non-translation child transforms.
2020-05-22 17:26:08 -04:00
Matthias Clasen
e7a420c40e testsuite: Re-add the sizegroups-evolution reftest
It doesn't seem to cause problems in ci anymore.
2020-05-22 17:10:28 -04:00
Matthias Clasen
962c4d6a69 Merge branch 'matthiasc/for-master' into 'master'
text: Avoid clash of preedit and placeholder

See merge request GNOME/gtk!1955
2020-05-22 20:59:44 +00:00
Matthias Clasen
0f053d1804 gtk-demo: Improve rotation in the dnd demo
Make the drag icon preserve the rotation, and improve
placement for the editor and for dnd to take the offset
into account.
2020-05-22 15:38:02 -04:00
Timm Bäder
930d779eb3 gl renderer: don't pretend all transform nodes support being transformed
It doesn't work in the general case. The transform handling could use a
general overhaul though.

Fixes #2773
2020-05-22 21:29:10 +02:00
Timm Bäder
f3ca814f3d gl renderer: Fix some off-by-one and rounding errors in the shadow code
Take 24

Fixes #2759
2020-05-22 21:29:10 +02:00
Matthias Clasen
7fac6b37db gtk-demo: Improve editing in the dnd demo
Add a scale for the angle, make the edits apply immediately,
and keep the item visible.
2020-05-22 14:06:00 -04:00
Matthias Clasen
d2f979ffaf gtk-demo: Improve drag icon handling in dnd example
Make the opacity change only apply to the 'ghost' of
the item, not the drag icon.
2020-05-22 13:25:17 -04:00
Matthias Clasen
e54060bac2 gtk-demo: Fix entry position in dnd demo
gtk_fixed_get_child_position does not work if children
have transforms that are not just 2D translations.
Use gtk_widget_translate_coordinates instead.
2020-05-22 13:17:59 -04:00
Matthias Clasen
965483eb67 gtk-demo: Reorganize the dnd demo
Introduce a CanvasItem widget to make things a
bit less ad hoc.
2020-05-22 12:35:18 -04:00
Matthias Clasen
dff5986ec2 main: Keep the target widget alive
We are passing the event to the tooltip handle_event
function at the very end. Unfortunately, the target_widget
may have already died at that point. We prevent that
by taking a ref during propagage_event, but the tooltip
code was outside of that. Keep a ref until the very
end ot prevent crashes.
2020-05-22 12:25:23 -04:00
Matthias Clasen
028bccc188 gtk-demo: Use proper drag icons in the dnd demo
Use a widget paintable to make the drag icon appear
in two places at once.
2020-05-22 10:50:09 -04:00
Matthias Clasen
78b427c99d dragsource: Actually use the paintable
We were just ignoring a paintable provided by
gtk_drag_source_set_icon().
2020-05-22 10:49:57 -04:00
Matthias Clasen
aec0a49e91 colorswatch: Remove a redundant include 2020-05-22 10:48:49 -04:00
Matthias Clasen
e60ea00e8b reftests: Fix the background-origin test
This was broken when I accidentally removed
one of the buttons.
2020-05-22 10:48:33 -04:00
Matthias Clasen
01df133401 text: Avoid clash of preedit and placeholder
Take preedit into account when determining the
visibility of placeholder text.
2020-05-22 10:48:33 -04:00
Matthias Clasen
56a6120136 Merge branch 'fix-printbackend' into 'master'
Build media backends with common_cflags and export the symbol

Closes #2771

See merge request GNOME/gtk!1956
2020-05-22 14:20:35 +00:00
Qiu Wenbo
340a8e11b0 Build media backends with common_cflags and export the symbol
Fixes: #2771
2020-05-22 17:00:06 +08:00
Yuri Chornoivan
2da14da32c Update Ukrainian translation 2020-05-22 05:47:20 +00:00
Matthias Clasen
641f2f72cd Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

Closes #227, #328, and #1010

See merge request GNOME/gtk!1954
2020-05-22 01:59:34 +00:00
Ondrej Holy
e8a120e5af trash-monitor: Rate limit updates
Trash monitor queries info from gvfsd-trash after each file monitor
change which can be problematic when too many changes happen in
a short time. Let's rate limit the number of queries...

Fixes: #1010
2020-05-21 21:15:12 -04:00
Matthias Clasen
e9872d52d8 range: Treat lower and upper limit the same
When clamping values to be within the range of
the adjustment, treat the lower and upper limit
the same.

Fixes: #328
2020-05-21 20:37:54 -04:00
Matthias Clasen
3b8bd265a3 windowhandle: Drop Move and Resize from the fallback menu
The expected behavior is that we trigger a keyboard-driven
interactive move or resize operation. But that doesn't work
with common compositors like mutter or weston, so lets not
expose non-working menuitems.
2020-05-21 19:38:36 -04:00
Matthias Clasen
af162b70c5 tooltip: Avoid criticals
It is possible that the target widget is already
unparented at the time that we call the tooltips
handle_event function. Quietly return in that case,
no need to emit a critical.
2020-05-21 19:38:36 -04:00
Matthias Clasen
061f257e83 accelgroup: Use Unicode in string literals
Its 2020, non-ASCII characters are not taboo anymore.
2020-05-21 19:38:36 -04:00
Matthias Clasen
c58d9446f4 Differentiate keypad keysyms in accelerators
When displaying accelerators, differentiate keypad
symbols with a 'KP' prefix. Fixing a 17 year old bug.

Update expected output in accelerator tests.

Fixes: #227
2020-05-21 19:38:19 -04:00
Matthias Clasen
e4d684b116 Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1953
2020-05-21 21:31:17 +00:00
Matthias Clasen
8f5444c75b gtk-demo: Fix breakage in a css demo
This is fallout from container api changes. We
were treating a GtkOverlay like a GtkBox, which
it isn't.
2020-05-21 16:24:56 -04:00
Matthias Clasen
96c0fbf209 gtk-demo: Plug another leak
We were leaking the builder in the css blendmodes demo,
by creating a ref cycle. This was showing up as
the list entry not going back to upright after
closing the window.
2020-05-21 16:24:20 -04:00
Matthias Clasen
98178d8823 gtk-demo: Plug another leak
We were leaking the builder in the revealers demo,
by creating a ref cycle. This was showing up as
the list entry not going back to upright after
closing the window.
2020-05-21 16:23:42 -04:00
Matthias Clasen
3f6dd34b18 gtk-demo: Plug another leak
We were leaking the builder in the cursors demo,
by creating a ref cycle. This was showing up as
the list entry not going back to upright after
closing the window.
2020-05-21 15:41:54 -04:00
Matthias Clasen
aaed61de66 gtk-demo: Plug a leak
We were leaking the builder in the builder demo,
by creating a ref cycle. This was showing up as
the list entry not going back to upright after
closing the window.
2020-05-21 15:41:48 -04:00
Timm Bäder
1aa86d23f4 gl renderer: Fix blurred outset shadow slicing
Take 23.

Fixes #2759
2020-05-21 15:32:12 +02:00
Matthias Clasen
c4607f72d1 Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1950
2020-05-20 20:57:34 +00:00
Matthias Clasen
f5f4c3cdfc Merge branch 'wip/exalm/window-polish' into 'master'
window: Fix tiled style class names

See merge request GNOME/gtk!1949
2020-05-20 20:13:30 +00:00
Matthias Clasen
9a1b4a766f mediastream: Volume is a double
Another obvious copy-paste error in the property
declarations of GtkMediaStream. Volume should be
a double, with range [0, 1], not a boolean.
2020-05-20 16:07:50 -04:00
Matthias Clasen
87d2e86429 mediastream: Some properties were meant to be readonly
These properties aren't covered by set_property(), and
it doesn't make sense to do so. They were just declared
as read-write by mistake.
2020-05-20 16:07:50 -04:00
Matthias Clasen
ee2c55379c mediacontrols: Make volume control react to has-audio 2020-05-20 16:07:50 -04:00
Matthias Clasen
be8a831496 Merge branch 'matthiasc/for-master' into 'master'
gdk: Short-circuit some surface setters

See merge request GNOME/gtk!1947
2020-05-20 18:01:07 +00:00
Alexander Mikhaylenko
2ce8c82846 window: Fix tiled style class names
This should fix the round corners on tiled windows.
2020-05-20 22:10:32 +05:00
Timm Bäder
7d57f978c5 Merge branch 'wip/baedert/single-node-window' into 'master'
single node GtkWindow

See merge request GNOME/gtk!1863
2020-05-20 17:06:37 +00:00
Timm Bäder
22e7d11583 window: Use GtkNative's check_resize everywhere 2020-05-20 18:12:22 +02:00
Timm Bäder
9cc6ddf80d window: Create default titlebar directly in realize
Instead of having two functions that are only called from one place but
look like they can be called from anywhere.
2020-05-20 18:12:22 +02:00
Timm Bäder
ee9d99cba3 update documentation for new style classes and node names 2020-05-20 18:12:22 +02:00
Timm Bäder
5c458e3061 Adwaita: style updates for new window node hierarchy 2020-05-20 18:12:20 +02:00
Timm Bäder
dfbcd475f3 window: Fix the surface coordinates everywhere 2020-05-20 17:08:24 +02:00
Timm Bäder
018efdb8eb window: Inline gtk_window_configure() into only caller
And remove the prototype from gtkwindowprivate.h
2020-05-20 17:08:24 +02:00
Timm Bäder
ec594f80dc window: Rewrite edge region detection 2020-05-20 17:08:24 +02:00
Timm Bäder
131837087b window: Fix computing the opaque region
We need to look at the surface transform here as well now.
2020-05-20 17:08:21 +02:00
Timm Bäder
7eec162502 window: Avoid using GtkStyleContext in subtract_decoration_corners
We can do this by just using the GtkCssStyle these days.
2020-05-20 17:06:54 +02:00
Timm Bäder
8c884e94c2 window: Fix get_surface_transform()
Look at the shadow here.
2020-05-20 17:06:54 +02:00
Timm Bäder
7659d8af3d window: Set overflow to HIDDEN
It really doesn't make sense for the general window to allow drawing
outside of it.
2020-05-20 17:06:54 +02:00
Timm Bäder
a5e7e72dd8 inspector: Fix overlay coordinates
Get the native transform only once, for all overlays. Unfortunately we
have to undo this for the updates overlay since that one gets values
in surface coordinates.
2020-05-20 17:06:54 +02:00
Timm Bäder
8e8e869853 inspector: Don't offset layout overlay too much
We already do this earlier.
2020-05-20 17:06:54 +02:00
Timm Bäder
b41838a7fd Window: Remove extra_input_region API
This is unused.
2020-05-20 17:06:54 +02:00
Timm Bäder
5ebabd7cf6 Call all window subclasses "window"
And add style classes to differentiate them
2020-05-20 17:06:54 +02:00
Timm Bäder
388733fe77 testsuite: Remove window decoration nodes from reference results 2020-05-20 17:06:54 +02:00
Timm Bäder
e1007e6c2b window: Remove decoration node 2020-05-20 17:06:54 +02:00
Timm Bäder
2c2092e7b8 window: Don't care about shadow in measure() 2020-05-20 17:06:54 +02:00
Timm Bäder
2579f66150 window: Don't care about shadow in size_allocate() 2020-05-20 17:06:54 +02:00
Timm Bäder
077692a8e1 window: Remove custom snapshot() implementation 2020-05-20 17:06:54 +02:00
Timm Bäder
5b77d3fde3 widget: Remove GtkWindow special case in create_render_node() 2020-05-20 17:06:54 +02:00
Matthias Clasen
6d8153d8fd gdk: Short-circuit some surface setters
Don't call into the backends when the input region
or shadow width don't actually change. This avoid
distracting calls in debug logs, and just generally
is the right thing to do.
2020-05-20 10:55:27 -04:00
Timm Bäder
ae711d8301 gdkdisplay-wayland: only remove one monitor
Ids here are unique, so break out of the loop once we found the monitor
with the given ID.
2020-05-20 15:51:11 +02:00
Emmanuele Bassi
00d889b4b6 Merge branch 'wip/ricotz/annotations' into 'master'
gdk: Preserve typed event parameter of GdkSurface:event signal for gir

See merge request GNOME/gtk!1946
2020-05-20 11:57:00 +00:00
Daniel Mustieles
401e2d16a8 Updated Spanish translation 2020-05-20 12:08:17 +02:00
Timm Bäder
4b5a8c45b4 gtk4-demo: Fix css_basics demo 2020-05-20 10:29:50 +02:00
Timm Bäder
ae54517b33 gtk4-demo: Fix sliding puzzle demo 2020-05-20 10:29:50 +02:00
Rico Tzschichholz
ebaeb9f3b8 gdk: Preserve typed event parameter of GdkSurface:event signal for gir
In conjunction to https://gitlab.gnome.org/GNOME/gtk/merge_requests/1936
2020-05-20 08:48:34 +02:00
Christian Hergert
a21d97db2e Merge branch 'wip/chergert/remove-get_toplevel' into 'master'
device: remove get_toplevel from surface_at_position vfunc

Closes #2765

See merge request GNOME/gtk!1941
2020-05-19 22:59:41 +00:00
Matthias Clasen
ebc8b01718 Merge branch 'wip/baedert/for-master' into 'master'
Wip/baedert/for master

See merge request GNOME/gtk!1935
2020-05-19 22:40:57 +00:00
Matthias Clasen
cf5e923d84 Merge branch 'wip/carlosg/tracker3' into 'master'
Move to tracker3 search engine

See merge request GNOME/gtk!1944
2020-05-19 22:37:34 +00:00
Christian Hergert
fa08d848ca device: remove get_toplevel from surface_at_position vfunc
This is not used anymore now that surfaces are always toplevel in the
semantics of GdkWindow where child windows were available. We can drop
that and simplify the vfunc just a bit more.

Fixes #2765
2020-05-19 13:07:38 -07:00
Carlos Garnacho
d29d59d1f9 gtksearchengine: Drop tracker 2.x search engine
This is being superseded by 3.x
2020-05-19 22:05:07 +02:00
Carlos Garnacho
edf6f9e108 gtksearchenginetracker3: Pre-fill GFileInfo from query
Provide the minimal info necessary. Improves apparent responsiveness
(since we don't visibly clear and repopulate the list) and saves doing
file stat/reads on every file in the result set.
2020-05-19 22:05:07 +02:00
Carlos Garnacho
98f376a19e gtksearchengine: Add tracker3 search engine
Make this dependency optional at build time, and prefer it over
the old tracker <= 2.x implementation.
2020-05-19 22:05:07 +02:00
Carlos Garnacho
de68925f0c gtksearchengine: Add autoptr handler for this type
So subclasses can just use G_DECLARE_*_TYPE.
2020-05-19 22:04:25 +02:00
Carlos Garnacho
b890e87818 gtksearchengine: Add "got_results" argument to ::finished
The filechooser tries to figure out whether it got results by poking
the model, but all files might go through the async GFileInfo querying
state.

Make all search engines (and the composite one) just notify about this
fact, so the file chooser can behave appropriately without waiting for
the async operations to finish.
2020-05-19 22:04:25 +02:00
Matthias Clasen
e0f4e44044 Merge branch 'matthiasc/for-master' into 'master'
docs: Refresh the build and backend sections

See merge request GNOME/gtk!1942
2020-05-19 19:59:46 +00:00
Matthias Clasen
edf85cb1b3 docs: Refresh the build and backend sections
Remove some outdated information from the sections
about building and about particular backends.
2020-05-19 15:19:53 -04:00
Matthias Clasen
841e9b3f0e Merge branch 'x11-shortcuts-inhibit-fix' into 'master'
x11: update inhibit shortcuts on grab broken

See merge request GNOME/gtk!1590
2020-05-19 14:06:25 +00:00
Olivier Fourdan
93f9138c9b x11: update inhibit shortcuts on grab broken
On X11, shortcuts inhibition is emulated using a grab on the keyboard.

So if another widget ungrabs the keyboard behind our back (for example
when a popup window is dismissed) that effectively disables the effects
of the shortcut inhibition on the surface and we need to update the
shortcut inhibition status accordingly.

Check for "grab-broken" events on the surface and clear existing
shortcuts inhibition for the matching seat, so that the client can be
notified and may decide to re-enable shortcut inhibition if desired.
2020-05-19 14:51:25 +02:00
Emmanuele Bassi
1ace77b923 Merge branch 'ebassi/surface-event' into 'master'
Use the right types for the GdkSurface::event arguments

See merge request GNOME/gtk!1936
2020-05-19 12:14:17 +00:00
Emmanuele Bassi
dd4d6930b5 Use the right types for the GdkSurface::event arguments
We pass the GdkEvent as a pointer, because the autogenerated marshallers
don't know how to handle GTypeInstance-derived classes.

Since the GValue box that we use in the marshaller passes the GdkEvent
instance as is, we also need to acquire a reference before invoking the
closure, and release it afterwards, to ensure that the GdkEvent instance
survices the invocation.
2020-05-19 12:21:22 +01:00
Timm Bäder
db76b52744 treeview: Remove animate parameters
Nothing ever reads them.
2020-05-19 08:32:33 +02:00
Timm Bäder
7235472a58 text: Assert that we have ranges before using them
We never hit this code path otherwise but let's make sure.
2020-05-19 08:32:33 +02:00
Timm Bäder
99871639fe unsetvalue: Add G_GNUC_NORETURN annotation 2020-05-19 08:32:33 +02:00
Timm Bäder
eebc2f20fa testgtk: Add G_GNUC_NORETURN to usage() 2020-05-19 08:32:33 +02:00
Timm Bäder
b92f4177aa builder-tool Make preview closeable 2020-05-19 08:32:33 +02:00
Timm Bäder
20b906cee8 Build print backends with common_cflags 2020-05-19 08:32:33 +02:00
Timm Bäder
7a768a2581 build: Pass common_cflags to focus-chain test 2020-05-19 08:32:33 +02:00
Timm Bäder
17c7662a6c bloatpad: Pass common_cflags to the build 2020-05-19 08:32:33 +02:00
Timm Bäder
14c3bc542d tetsuite/a11y: Pass common_cflags to build 2020-05-19 08:32:33 +02:00
Timm Bäder
dd370db62a reftests: Pass common_cflags 2020-05-19 08:32:33 +02:00
Timm Bäder
43ba86b7af tools: Pass common_cflags to executables 2020-05-19 08:32:33 +02:00
Timm Bäder
2425d61516 Pass common_cflags to testuite/gsk executables 2020-05-19 08:32:33 +02:00
Timm Bäder
3bf4c5687c Pass common_cflags to print backends 2020-05-19 08:32:33 +02:00
Matthias Clasen
7fc2d9adc0 Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

Closes #2739 and #2760

See merge request GNOME/gtk!1934
2020-05-19 02:47:03 +00:00
Matthias Clasen
17dd32da88 testsuite: Remove obsolete test from list
The test was removed in 97d0e8c6e0, but I neglected
to remove the test files from meson.build.

Fixes: #2760
2020-05-18 21:49:34 -04:00
Matthias Clasen
ec2aac5b61 gsk: Document blend modes
Add some information about blend modes, mostly taken
from the css compositing spec.

Fixes: #2739
2020-05-18 18:21:39 -04:00
Matthias Clasen
15f7d2a27d 3.98.4 2020-05-18 16:38:11 -04:00
Matthias Clasen
3dafdcbab0 testsuite: Remove GDK_DEBUG=misc
This snuck in by accident in recent ci setup
changes, and breaks the test runs by adding
stray output.
2020-05-18 16:38:11 -04:00
Matthias Clasen
383fa6b0b0 Merge branch 'matthiasc/for-master' into 'master'
colorscale: Bring back the right-click on slider

See merge request GNOME/gtk!1933
2020-05-18 16:46:12 +00:00
Matthias Clasen
f637ab57f1 colorscale: Bring back the right-click on slider
This was lost when we converted the color editor to actions.
2020-05-18 11:31:42 -04:00
Emmanuele Bassi
615b4d8c65 Merge branch 'ebassi/ci-fix' into 'master'
docs: Fix the argument name to match

See merge request GNOME/gtk!1930
2020-05-18 15:10:38 +00:00
Jakub Steiner
9be5c7b0c8 Merge branch 'theme-aligned-combo-labels' into 'master'
Adwaita: Align combo menu labels with the combo button label

See merge request GNOME/gtk!1928
2020-05-18 14:04:19 +00:00
Yuri Chornoivan
670b102553 Update Ukrainian translation 2020-05-18 14:03:41 +00:00
Emmanuele Bassi
9bd9a11de4 docs: Fix the argument name to match
Both gtk-doc and g-i require the name of the argument of a function to
match in the declaration, definition, and gtk-doc stanza.
2020-05-18 14:55:25 +01:00
Jakub Steiner
ec26e4f6b4 Merge branch 'theme-checkbutton-padding' into 'master'
Adwaita: Tweak padding in checkbutton & radiobutton

Closes #2697

See merge request GNOME/gtk!1927
2020-05-18 13:12:15 +00:00
nana-4
538ab75002 Adwaita: Align combo menu labels with the combo button label
Apply the same left and right padding to the combo menu items as the
combo button.
2020-05-18 21:52:00 +09:00
nana-4
1c99dbc70e Adwaita: Tweak padding in checkbutton & radiobutton
Since we can now use border-spacing in checkbutton and radiobutton,
we don't need the margin in check and radio for spacing anymore.

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/2697
2020-05-18 20:29:23 +09:00
Timm Bäder
afd56517d1 bloatpad: Avoid a few theoretical compiler warnings 2020-05-18 11:30:08 +02:00
Timm Bäder
3c7ba21a6a Add G_GNUC_NORETURN to functions that never return 2020-05-18 11:30:08 +02:00
Timm Bäder
4b655ecd36 examples: Add common_cflags to executables 2020-05-18 11:30:08 +02:00
Daniel Mustieles
028942c8c3 Updated Spanish translation 2020-05-18 10:15:03 +02:00
Matthias Clasen
55b171c986 Merge branch 'shape-apis' into 'master'
Shape apis

See merge request GNOME/gtk!1925
2020-05-18 04:26:01 +00:00
Chun-wei Fan
a4416e389a print-editor demo: Fix linking on Visual Studio
We need to pass in '/entry:mainCRTStartup' as we did for the other demo
programs that have 'gui_app: true' in their Meson build settings.
2020-05-18 11:35:52 +08:00
Matthias Clasen
d6818475d7 gdk: Simplify gdk_display_supports_input_shapes
Make this a display property, and do away with
the vfunc in favor of a private setter, to match
how we handle other display characteristics.
2020-05-17 22:05:24 -04:00
Matthias Clasen
287c40276a gdk: Drop gdk_display_supports_shapes
The apis to set shapes on surfaces are gone,
so there is no point in providing this information
on GdkDisplay.
2020-05-17 21:52:15 -04:00
Matthias Clasen
5916ae5ec4 x11: Avoid some frontend api use
We can just use our backend information directly.
2020-05-17 21:47:22 -04:00
Matthias Clasen
03829e191e docs: Tweak docs for gdk_surface_set_input_region 2020-05-17 21:46:54 -04:00
Matthias Clasen
f958a6ecf7 Merge branch 'coordinate-api' into 'master'
Coordinate api

See merge request GNOME/gtk!1924
2020-05-18 00:08:44 +00:00
Matthias Clasen
71bad81aff gdk: Make gdk_drag_begin take doubles
This is a better fit to the way we treat coordinates
everywhere else.
2020-05-17 17:51:03 -04:00
Matthias Clasen
75d9310986 Change coordinate translation apis to take doubles
Change gtk_widget_translate_coordinates and
gtk_native_get_surface_transform to operate
on doubles. Update all callers.
2020-05-17 17:17:31 -04:00
Matthias Clasen
93d4253c93 native: Make gtk_native_get_surface_transform public
This api is needed to translate between surface
and widget coordinates.
2020-05-17 16:01:08 -04:00
Matthias Clasen
c0faf0c6b6 Merge branch 'toplevel-move-resize' into 'master'
Toplevel move resize

See merge request GNOME/gtk!1923
2020-05-17 19:15:46 +00:00
Matthias Clasen
b63690aa6b docs: Mention begin_resize_drag in the migration guide 2020-05-17 14:38:10 -04:00
Matthias Clasen
1e8a58e367 gdk: Move the begin_move/resize_drag vfuncs around
Move these from GdkSurface to GdkToplevel, where they
belong. Update all backends.
2020-05-17 14:15:06 -04:00
Benjamin Otte
34d7e25a1f x11: Fix up for last merge 2020-05-17 19:21:28 +02:00
Benjamin Otte
b353221185 Merge branch 'wip/otte/monitors' into 'master'
various GDK cleanups

See merge request GNOME/gtk!1920
2020-05-17 16:57:52 +00:00
Matthias Clasen
eb6edac4bd gdk: Drop gdk_surface_begin_move/resize_drag
These have been replaced by GdkToplevel api.
2020-05-17 12:49:29 -04:00
Matthias Clasen
f316fe0f58 window: Use toplevel begin_move/resize api
The GdkSurface api for this is going away.
2020-05-17 12:49:26 -04:00
Emmanuele Bassi
12854f1428 Merge branch 'ebassi/ci-extends' into 'master'
ci: Use extends instead of YAML anchors

See merge request GNOME/gtk!1908
2020-05-17 16:43:24 +00:00
Matthias Clasen
309a7aa253 gdk: Add gdk_toplevel_begin_move/resize
For now, these are wrappers around the surface apis,
but they are going to replace them, since this operation
is only available on toplevels.
2020-05-17 12:41:16 -04:00
Benjamin Otte
363c88cef7 migration guide: Update paragraph about monitors
Clarify the new handling of monitors via a listmodel of GdkMonitor
instead of int monitor_num.
2020-05-17 18:05:07 +02:00
Timm Bäder
74a1c60dd4 windowhandle: Apply surface transform before passing coords to GDK
Otherwise coordinates are incorrect and the window can jump around after
starting a drag.
2020-05-17 15:30:50 +02:00
Timm Bäder
a4bb81b61c inspector: Apply toplevel transform before snapshotting overlays 2020-05-17 15:30:44 +02:00
Timm Bäder
01c0acb707 gl renderer: Apply scaled clip when rendering offscreen clipped child 2020-05-17 15:30:28 +02:00
Timm Bäder
afbc1d5b66 shortcutmanager: Fix private header include guard 2020-05-17 15:30:03 +02:00
Timm Bäder
1d9e68245a shortcutcontroller: Don't return a shortcut stope as GdkModifierType 2020-05-17 15:30:03 +02:00
Timm Bäder
9b98641ddd window: Use TRUE/FALSE for boolean values 2020-05-17 15:30:03 +02:00
Timm Bäder
2c1d218749 Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

Closes #1619

See merge request GNOME/gtk!1921
2020-05-17 13:08:26 +00:00
Emin Tufan Çetin
716485113a Update Turkish translation 2020-05-17 11:42:10 +00:00
Matthias Clasen
d70feb9165 Apply surface transform in more places
With these fixes, GtkSwitch now works in the presence
of surface transforms.
2020-05-17 02:23:23 -04:00
Matthias Clasen
38af49d4fd inspector: Take surface transform into account 2020-05-17 02:10:56 -04:00
Timm Bäder
007de568c9 gl renderer: Fix an uninitialized value 2020-05-17 08:07:11 +02:00
Matthias Clasen
d2913b81cb windowhandle: Take surface transform into account 2020-05-17 02:05:32 -04:00
Matthias Clasen
c90078fd4a widget: Fix gtk_widget_get_surface_allocation
As the name implies, this should be surface-relative
coordinates, so it needs to take the surface transform
into account.
2020-05-17 02:04:22 -04:00
Matthias Clasen
428e647238 textview: Fix context menu placement
Take the surface transform into account for
positioning the context menu.
2020-05-17 02:03:41 -04:00
Benjamin Otte
4c7914dc49 display: Remove unneeded getters
Applications can use the listmodel instead.
2020-05-17 07:32:37 +02:00
Matthias Clasen
5e35a4b69a tooltip: Fix positioning
There are a few more places where we were forgetting
to apply the surface->native transform. With these
changes, tooltips are positioned correctly when
the toplevel has padding applied.

Fixes: #1619
2020-05-17 01:22:02 -04:00
Benjamin Otte
9a30019268 display: Remove the monitor signals
Applications can listen to GdkDisplay:monitors::items-changed if they
want to track monitor changes.
2020-05-17 07:10:34 +02:00
Benjamin Otte
972276436f x11: Directly notify surfaces of monitor changes
Do not use signals.
2020-05-17 07:10:34 +02:00
Benjamin Otte
e81a1db48c monitor: Add gdk_monitor_set_geometry()
Make it replace gdk_monitor_set_size() and gdk_monitor_set_position()
which used to be called in pairs anyway.
2020-05-17 07:10:34 +02:00
Benjamin Otte
33a4442988 x11: Remove unused change tracking
Change tracking now works automatically via GdkMonitor.
2020-05-17 05:14:24 +02:00
Matthias Clasen
3035bf1e39 widget-factory: Cosmetics
Add a frame around the white background in the background
selection dialog. Otherwise, it is not really visible.
2020-05-16 21:54:14 -04:00
Benjamin Otte
14bf58ec5d x11: Remove XDamage dependency
It's not used.
2020-05-17 02:14:58 +02:00
Matthias Clasen
a2a3aab94d Merge branch 'wip/baedert/for-master' into 'master'
Wip/baedert/for master

Closes #2601

See merge request GNOME/gtk!1918
2020-05-16 23:35:51 +00:00
Emmanuele Bassi
7ff9a3f3a0 ci: Allow using "latest" as the image version
Just like the documentation says.
2020-05-17 00:32:22 +01:00
Emmanuele Bassi
8070bac06c ci: Use extends instead of YAML anchors
The `extends` keyword is more readable than YAML's weird anchor syntax,
and we don't have too many anchors in our job definitions anyway.
2020-05-17 00:30:07 +01:00
Benjamin Otte
d4731a4ab4 x11: Remove gdk_x11_register_standard_event_type()
It's not used anymore since GdkX11Display::xevent exists.
2020-05-17 01:02:17 +02:00
Benjamin Otte
0c6266fd1a surface: Remove gdk_surface_is_viewable()
It returns the same value as gdk_surface_get_mapped(), so use that
instead.
2020-05-17 00:41:44 +02:00
Timm Bäder
5b0e91844b popover: Fix input shape rendering
Once again, calling gtk_widget_get_allocation() is wrong.

Fixes #2601
2020-05-16 22:34:38 +02:00
Timm Bäder
c4363e2706 showrendernode: Set widget overflow 2020-05-16 22:04:00 +02:00
Timm Bäder
ccaacfc8c3 texthandle: Remove min-width/height handling
We do that automatically for all widgets.
2020-05-16 22:04:00 +02:00
Timm Bäder
2e9d772e66 natives: Use GtkCssBoxes in get_surface_transform 2020-05-16 22:04:00 +02:00
Timm Bäder
bac6e79614 native: Add documenation for get_surface_transform 2020-05-16 22:03:58 +02:00
Timm Bäder
2fd86ef80c popover: Return correct values from get_surface_transform()
We do not (yet) care about the box shadow here, so it's sufficient to
return the css values.
2020-05-16 22:03:58 +02:00
Timm Bäder
f9370d7e83 main: Translate coordinates from surface to native before picking
gtk_widget_pick() needs them to be in @self coordinates.
2020-05-16 22:03:55 +02:00
Matthias Clasen
bc75965053 Merge branch 'matthiasc/for-master' into 'master'
broadway: Be careful about destroyed surfaces

See merge request GNOME/gtk!1917
2020-05-16 18:27:19 +00:00
Matthias Clasen
77107f70c4 broadway: Be careful about destroyed surfaces
Just because we take a ref on a surface does not
guarantee that it is still usable a second later.
Check if its been destroyed in the meantime.

This is breaking the template tests in ci, since
there is no client behind the Broadway server.
2020-05-16 13:47:18 -04:00
Matthias Clasen
b41aeabbec Merge branch 'matthiasc/for-master' into 'master'
broadway: Don't create overlarge images

See merge request GNOME/gtk!1916
2020-05-16 17:01:30 +00:00
Matthias Clasen
c0ae36e943 broadway: Create slave devices
The assumption is that the source device in events
is a slave device, so create pointer and keyboard
devices and use them in events.

This fixes the seat test on Broadway.
2020-05-16 12:27:22 -04:00
Matthias Clasen
5851415fca broadway: Don't create overlarge images
Respect that cairo won't create image surfaces larger
than 32767 x 32767.

This makes the one reftest pass that specifically checks
this condition, treeview-crash-too-wide.
2020-05-16 11:27:21 -04:00
Matthias Clasen
36b4b39619 Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1915
2020-05-16 15:03:10 +00:00
Yuri Chornoivan
d7bf3605b9 Update Ukrainian translation 2020-05-16 14:52:15 +00:00
Matthias Clasen
15211556df Merge branch 'broadway-surface-destroy' into 'master'
Broadway surface destroy

See merge request GNOME/gtk!1914
2020-05-16 14:16:52 +00:00
Matthias Clasen
13f8583934 ci: Don't run opengl renderer tests on Broadway
The test setup mechanism in meson is not flexible
enough to let us run different suites depending
on setup, so just pass in explicitly which suites
we want to skip, depending on the backend.
2020-05-16 10:14:10 -04:00
Matthias Clasen
350110ad9d testsuite: Add a gsk-compare-broadway suite
We have a Broadway renderer, might as well spell
that out in the tests, and make the suite exclude the
3d tests it can't handle.
2020-05-16 10:14:10 -04:00
Matthias Clasen
d771aa6fee testsuite: Destroy surfaces
If we don't destroy the surface, it leaks.

GDK backends keep an extra reference on the
surface for the external resources associated
with it, and only drop it in destroy().
2020-05-16 09:12:18 -04:00
Matthias Clasen
4acb56d8c5 broadway: Keep an reference on surfaces
GDK backends are expected to keep a references on
their surfaces as long as they are associated with
external resources, and drop it in destroy().

This showed up as criticals in the shortcuts test
which manually creates and destroys surfaces.
2020-05-16 09:12:07 -04:00
Matthias Clasen
afaa9810d1 Merge branch 'matthiasc/for-master' into 'master'
inspector: Use tabular numbers in the fps overlay

See merge request GNOME/gtk!1912
2020-05-16 11:21:00 +00:00
Piotr Drąg
6aa68fcfee Update POTFILES.in and POTFILES.skip 2020-05-16 12:37:01 +02:00
Timm Bäder
b2b2070415 Implement diff() for color matrix nodes
This way we don't redraw color matrix nodes all the time.
2020-05-16 08:22:55 +02:00
Matthias Clasen
c5b2bbf01b inspector: Use tabular numbers in the fps overlay
It is a lot more readable if it doesn't constantly jitter.
2020-05-15 21:30:14 -04:00
Matthias Clasen
f4d3d8e27c Merge branch 'better-ci-reports' into 'master'
ci: Add the backend to the reports

See merge request GNOME/gtk!1911
2020-05-16 00:52:56 +00:00
Matthias Clasen
4f6fa87f00 Merge branch 'wip/carlosg/tablet-disconnects-master' into 'master'
gdk/wayland: Handle disorderly tablet/pad disconnects

See merge request GNOME/gtk!1910
2020-05-15 23:50:54 +00:00
Matthias Clasen
01bd6cfd17 ci: Add the backend to the reports
We want the test names in the junit xml to be
unique across all the tests in a job, so we need
to include the backend in the test name.

And we also want to see the used backend in
the html report.
2020-05-15 19:49:18 -04:00
Carlos Garnacho
000487c36c gdk/wayland: Handle disorderly tablet/pad disconnects
If the tablet gets removed/freed while there are pad events in flight,
we leave a dangling pointer from the pad to the tablet, which may
lead to invalid reads/writes when handling the pad event(s).
2020-05-15 23:40:18 +02:00
Matthias Clasen
5870f1c90a Merge branch 'headless-seatless' into 'master'
gtk: Handle seatless displays

See merge request GNOME/gtk!1905
2020-05-15 21:13:01 +00:00
Matthias Clasen
30ef48143f ci: Ignore Broadway failures
These need some more work, so ignore them for now,
to get the initial multi-backend testsuite into
production.
2020-05-15 15:24:04 -04:00
Matthias Clasen
0232218100 displayclose: Quietly skip if no X available 2020-05-15 14:58:58 -04:00
Matthias Clasen
31cf894092 ci: Run tests with different backends
Run the testsuite under x11, wayland and broadway
in the fedora-x86_64 job. This requires us to use
the v17 image which includes weston.
2020-05-15 14:11:53 -04:00
Matthias Clasen
509db01319 tests: Centralize our test setup a bit
Put all of the constant environment into the
toplevel meson.build file, to reduce repetition
and copy-paste errors.
2020-05-15 14:11:53 -04:00
Matthias Clasen
ff4552c842 testsuite: Add test setups for backends
Add test setups that set the GDK_BACKEND and
TEST_OUTPUT_SUBDIR environment variables.

This lets use run
meson test --setup x11 --suite reftest
meson test --setup wayland --suite reftest
and the output will be nicely separated.

We still need to do compositor / display server
setup from the outside.
2020-05-15 14:11:53 -04:00
Matthias Clasen
c22af88235 tests: Allow setting a subdir for output
meson seems somewhat weak when it comes to handling
test output. We need to get the output from different
test runs into different locations, and the only
way to communicate from a test setup with the actual
test code seems the environment, so use that.

Make all tests that produce output in files respect
a TEST_OUTPUT_SUBDIR environment variable which specifies
the name of a subdirectory to use. This is combined
with the existing --output argument, which specifies
a per-test location.

Affected tests are reftests, css performance tests
and gsk compare tests.
2020-05-15 14:11:53 -04:00
Matthias Clasen
6719616c36 ci: Fix a typo in the run-docker.sh script 2020-05-15 14:11:53 -04:00
Matthias Clasen
18c7284817 ci: Add weston and weston-libs to the fedora image
We want to run tests under Wayland, using weston
as the compositor. The weston-libs package contains
the headless backend for weston.
2020-05-15 14:11:53 -04:00
Matthias Clasen
8912a6eb75 gtk: Handle seatless displays
If you run weston with the headless backend, you get a Wayland
display with no seat, which is just fine by the protocol.

gdk_display_get_default_seat() returns NULL in this case. Various
widgets assume that we always have a seat with a keyboard and a
pointer, since that is what X guarantees. Make things survive
without that, so we can run the testsuite under a headless
Wayland compositor.
2020-05-15 14:11:53 -04:00
Matthias Clasen
9b7a73268e docs: Clarify gdk_display_get_default_seat() docs
This function can return %NULL if the display
does not have a seat. Document that.
2020-05-15 14:11:53 -04:00
Timm Bäder
d4d9644409 Merge branch 'wip/tintou/set_css_classes_array' into 'master'
widget: Add array annotation to set_css_classes

See merge request GNOME/gtk!1907
2020-05-15 11:19:05 +00:00
Corentin Noël
80473ccd69 widget: Add array annotation to set_css_classes
It expects a NULL-terminated array so annotate it.
2020-05-15 12:01:56 +02:00
Jakub Steiner
b51a5446ba Merge branch 'wip/jimmac/tabs-again-focus' into 'master'
Adwaita: notebook tab focus tweak

Closes #2721

See merge request GNOME/gtk!1906
2020-05-15 08:17:58 +00:00
Jakub Steiner
d7e6fbf8a2 Adwaita: notebook tab focus tweak
Finally fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/2721
2020-05-15 09:34:57 +02:00
Matthias Clasen
acae90cc6e Merge branch 'tests-cleanup' into 'master'
Tests cleanup

See merge request GNOME/gtk!1904
2020-05-15 01:38:38 +00:00
Matthias Clasen
dcfb4690c3 tests: Drop testdnd3
This has been integrated in gtk4-demo as the
DND example.

See #2738
2020-05-14 20:32:53 -04:00
Matthias Clasen
9e8d845a61 tests: Rename testheaderbar2 to testheaderbar
There is only one headerbar test now.
2020-05-14 20:15:59 -04:00
Matthias Clasen
1e2b5a9c19 tests: Consolidate all headerbar tests
No need to have several binaries for this.

See #2738
2020-05-14 20:15:31 -04:00
Matthias Clasen
4079b782d6 tests: Drop testorientable
Not really that interesting, and it only
tests a single case of orientable, a box.

See #2738
2020-05-14 19:48:08 -04:00
Matthias Clasen
dca142d5d2 tests: Drop testemblems
We no longer support emblems on icons.

See #2738
2020-05-14 19:44:54 -04:00
Matthias Clasen
52c630d994 tests: Drop testgiconpixbuf
More a pixbuf test, and we don't support
emblems anymore.

See #2738
2020-05-14 19:44:08 -04:00
Matthias Clasen
aadd9ae201 tests: Drop testbuttons
This does not really add much. We have plenty
of different button styles in our demos and
tests.

See #2738
2020-05-14 19:44:05 -04:00
Matthias Clasen
3df0f95ee3 Merge branch 'wip/exalm/kinetic_scrolling' into 'master'
eventcontrollerscroll: Fix the history push condition

See merge request GNOME/gtk!1902
2020-05-14 22:40:54 +00:00
Alexander Mikhaylenko
5dc6194b98 eventcontrollerscroll: Fix the history push condition
Once upon a time, there was a function called gdk_event_get_scroll_deltas().
It returned %TRUE when an event had scroll deltas and that was used as the
condition to decide whether to push scroll deltas to the scroll history,
even when the both deltas are 0 for the stop event at the end of scrolling.

When GtkScrolledWindow kinetic scrolling code was adapted for
GtkEventControllerScroll, it was replaced with a (dx != 0 && dy != 0)
check. This prevented the stop event from getting into the history, and
instead allowed non-smooth scrolling to affect the history as they have
synthetic deltas with one of the values being -1 or 1 and the other on 0.

Instead, check the direction as we already have it as a local variable.
2020-05-15 01:32:04 +05:00
Jakub Steiner
c025a569a9 Merge branch 'wip/jimmac/focus-tabs' into 'master'
Adwaita: don't focus outline tabs with mouse

Closes #2721

See merge request GNOME/gtk!1901
2020-05-14 17:35:10 +00:00
Jakub Steiner
dd61c248c1 Adwaita: don't focus outline tabs with mouse
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/2721
2020-05-14 18:50:47 +02:00
Matthias Clasen
a6c1aef78b Merge branch 'wip/exalm/headerbar-migration' into 'master'
docs: Mention GtkHeaderBar title and subtitle changes in migration guide

See merge request GNOME/gtk!1900
2020-05-14 15:37:16 +00:00
Alexander Mikhaylenko
9f761feb93 docs: Mention GtkHeaderBar title and subtitle changes in migration guide 2020-05-14 19:51:19 +05:00
Matthias Clasen
38f09ac38e Merge branch 'x11-dnd-fix' into 'master'
Fix dnd on X11

See merge request GNOME/gtk!1899
2020-05-14 13:10:54 +00:00
Alexander Larsson
fed071ca96 GdkX11DragSurface: set visible state and invalidate on present
Without this we won't actually draw the surface.
2020-05-14 14:33:57 +02:00
Daniel Mustieles
4629f206c5 Updated Spanish translation 2020-05-14 12:04:27 +02:00
Daniel Mustieles
aba6371ea5 Updated Spanish translation 2020-05-14 12:00:33 +02:00
Alexander Larsson
bca4af360d X11 dnd: Calculate relative coords right in events
GdkSurface.x/y is mostly 0, we need to look atht GdkX11Surface->abs_x/y.
2020-05-14 11:46:33 +02:00
Alexander Larsson
32f58e6c0b gtk-demo/dnd: Fix up drag_cancel
This needs to return a boolean, also it should not call end because
that will be called anyway by Gtk+ after cancel, and this was causing
warnings due to the opacity being unset with no dragged widget set.
2020-05-14 10:45:38 +02:00
Alexander Larsson
4ce65f019e GtkDragSource: Pass return value of drag-cancel into drag_end()
This is needed to work as the docs say (don't play fallback cancel animation
if cancel returned TRUE to signal the drop already happened).
2020-05-14 10:44:07 +02:00
Alexander Larsson
707229ce17 gtk-demo/dnd: Use gtk_popover_set_child(), not gtk_box_append 2020-05-14 10:13:05 +02:00
Alexander Larsson
e702d42597 x11 drag: Fix mapped error
In the gtk-demo drag-and-drop demo i can't drag anything, all I get
is:

(gtk4-demo:358993): Gdk-CRITICAL **: 09:36:19.617: Surface 0x7e1bb0 has not been mapped in GdkSeatGrabPrepareFunc

This is because GdkX11Drag.ipc_surface is not considered mapped, even
though we called gdk_x11_surface_show() on it, because the
GDK_SURFACE_STATE_WITHDRAWN flag is still set.

I added calls to gdk_synthesize_surface_state() to match what
e.g. show_popup() and gdk_x11_toplevel_present() does.
2020-05-14 09:54:34 +02:00
Matthias Clasen
64db8be7d5 Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1897
2020-05-14 05:47:26 +00:00
Matthias Clasen
7eaa10dd8e gtk-demo: Fix a problem with the dnd demo
When I move this into gtk-demo, I broke the hack
that ensures the GtkColorSwatch type is registered.
Bring it back.
2020-05-14 01:16:56 -04:00
Matthias Clasen
102e7d0838 widget-factory: Ensure we have some backgrounds
The flowbox demo is otherwise less than useful,
if /usr/share/gnome/backgrounds isn't present.

At the same time, give the scale in the listbox
some function.
2020-05-14 00:28:03 -04:00
Matthias Clasen
9f4e7b1249 Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1896
2020-05-14 03:28:08 +00:00
Matthias Clasen
378cca75ea Add a test for a flowbox crash 2020-05-13 21:47:11 -04:00
Matthias Clasen
69ab403d78 flowbox: Avoid an assertion in snapshot()
The api contract for size_allocate() vfuncs is
that they must allocate all the children that are
going to be snapshotted in snapshot(). The flowbox
size_allocate() was just bailing out when the children
request a size of 0x0, leading to an assertion in
snapshot() vfunc later. Just allocate all children
a size of 0x0 in this case.
2020-05-13 21:47:11 -04:00
Matthias Clasen
33011ccdff flowbox: Avoid a crash in measure()
When the children request a height of zero, the
flowbox measure() function was happily dividing
by that zero, leading to badness.
2020-05-13 21:47:11 -04:00
Matthias Clasen
7915e998e2 listbox: Make Shift-Tab work again
The previous fix broke the case where we're Shift-Tabbing
from a listboxrow child to the row itself. This was causing
the widget-factory2.tab-backward test to fail. Fix it, by
grabbing the focus to the row explicitly.
2020-05-13 21:45:49 -04:00
Matthias Clasen
7ef51da1c1 listbox: Don't steal focus-on-click
If a row has content that is focus-on-click, and is set
to focus-on-click itself, then the row steals the focus
fromt he content, since it uses focus-on-click on button
release, as opposed to button press. Avoid that by
refusing to take focus if it is already on some
descendent of the row.

This was showing up in the widget-factory listbox on
page 2, where clicking on the spinbutton would briefly
put the focus on the spinbutton, only to lose it to
the row.
2020-05-13 19:43:04 -04:00
Matthias Clasen
ce949c0f25 widget-factory: Cosmetic changes
Change which rows in the listbox on page 2 are activatable,
and trigger a dialog. It did not really make sense that this
would happen when clicking on the spin button to focus it.
2020-05-13 19:22:31 -04:00
Matthias Clasen
e9d966488b gtk-demo: Don't overdraw the fishbowl
Set overflow to hidden for the fishbowl widget, so the
blur buttons don't leak out into the window shadow.
2020-05-13 19:21:00 -04:00
Matthias Clasen
4c8688b846 inspector: Disable recursive inspection
We can't inspect the inspector, it doesn't work.
Therefore, disable the keybindings in the
inspector window.
2020-05-13 18:56:25 -04:00
Matthias Clasen
cea66139ae flowbox: Make the children focusable again
This broke when the :focusable property was introduced.
The symptom was that keynav in the Emoji chooser did
not work anymore.
2020-05-13 18:27:18 -04:00
Matthias Clasen
c1658903b7 Merge branch 'tests-cleanup' into 'master'
Tests cleanup

See merge request GNOME/gtk!1894
2020-05-13 22:19:55 +00:00
Matthias Clasen
15e7bf50df Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1895
2020-05-13 21:57:15 +00:00
Matthias Clasen
e87bc3d33d gtk-demo: Plug a memory leak
This leak was there all along. But with the new
gtk_window_destroy(), it shows up as an unclosable
window. Very noticable.
2020-05-13 17:24:57 -04:00
Matthias Clasen
10be40a8b1 scrolledwindow: Fix swapping out child
This was not working in the case that the existing child
is not a scrollable. It showed up as crashes of the
scrolling benchmark in gtk4-demo when switching examples.
2020-05-13 17:10:36 -04:00
Matthias Clasen
8e6ec0b8a3 tests: Fix scrolling performance test
Maybe this should be added to the benchmarks section
in gtk-demo. For now, fix it to work again.
2020-05-13 17:10:00 -04:00
Matthias Clasen
25577e4fbf tests: Drop testnoscreen
It tests something that no longer works, and that
we probably don't want to guarantee anyway.

See #2738
2020-05-13 16:35:28 -04:00
Matthias Clasen
dc8c37120e tests: Drop testexpander
This was copied into gtk4-demo at some point.

See #2738
2020-05-13 16:23:48 -04:00
Matthias Clasen
a375c41510 tests: Drop testfontchooser
This test adds nothing over the font choosers in
our various demos.

See #2738
2020-05-13 16:18:50 -04:00
Matthias Clasen
b8e905eae7 tests: Drop testcolorchooser
We have plenty of color choosers in demos.
This test doesn't add anything.

See #2738
2020-05-13 16:15:09 -04:00
Matthias Clasen
d1134e7616 Merge branch 'usable-scales' into 'master'
Usable scales

See merge request GNOME/gtk!1893
2020-05-13 20:06:51 +00:00
Matthias Clasen
b0fcf64544 tests: Drop testbox
Not useful enough to keep.

See #2738
2020-05-13 16:04:00 -04:00
Matthias Clasen
604f4cf8bf tests: Drop testcolorchooser2
This tests an embedded colorchooser. Just like we have in
widget-factory. And it doesn't work in !srcdir builds, so
it can go.

See: #2738
2020-05-13 15:55:29 -04:00
Matthias Clasen
1420e846b5 tests: Drop testicontheme
This is a command line utility for GtkIconTheme
that is probably not as useful as gtk4-icon-browser.

See: #2738
2020-05-13 15:55:21 -04:00
Matthias Clasen
c3aeac19bc tests: Drop testpixbuf-scale
This looks like a GdkPixbuf utility, and we
are moving away from GdkPixbuf anyway.

See: #2738
2020-05-13 15:55:18 -04:00
Matthias Clasen
deef018c68 tests: Drop testtoolbar2
This is just a tool bar styling test; we have
the same in the widget factory.

See: #2738
2020-05-13 15:37:21 -04:00
Matthias Clasen
aae0770b82 scale: Make the area around the trough clickable
The narrow trough is too hard to hit as a click target.
Make the entire scale clickable.
2020-05-13 15:27:35 -04:00
Matthias Clasen
51ec0f1348 Merge branch 'wip/exalm/ocd' into 'master'
demo: Remove double borders from the treeview

See merge request GNOME/gtk!1892
2020-05-13 18:31:39 +00:00
Matthias Clasen
4ed062ec2a Merge branch 'wip/jimmac/menu-styling-adjustments' into 'master'
Wip/jimmac/menu styling adjustments

See merge request GNOME/gtk!1891
2020-05-13 17:18:45 +00:00
Jakub Steiner
69ee1e1b86 Adwaita: use thinner arrows for navigation
- go-next go-previous instead of pan-end pan-start

See https://gitlab.gnome.org/GNOME/gtk/-/issues/2675
2020-05-13 17:18:45 +00:00
Alexander Mikhaylenko
3bf6bdae73 demo: Remove double borders from the treeview 2020-05-13 20:57:00 +05:00
sicklylife
d0c54c1286 Update Japanese translation 2020-05-13 15:16:19 +00:00
sicklylife
cbc2493315 Update Japanese translation 2020-05-13 15:12:03 +00:00
Matthias Clasen
fa784aaa06 Cosmetics 2020-05-13 08:11:50 -04:00
Matthias Clasen
ab148c0135 Merge branch 'wip/baedert/for-master' into 'master'
Wip/baedert/for master

Closes #2740, #2742, and #2741

See merge request GNOME/gtk!1890
2020-05-13 12:08:29 +00:00
Matthias Clasen
10813ddc23 Merge branch 'gtk-demo-expander-fix' into 'master'
gtk-demo: Fix expander demo

See merge request GNOME/gtk!1889
2020-05-13 11:44:11 +00:00
Matthias Clasen
8dfdd682cc Merge branch 'print-editor-new-crash' into 'master'
print-editor: Fix crash

See merge request GNOME/gtk!1888
2020-05-13 11:42:00 +00:00
Timm Bäder
9149c79f25 window: Restructure gtk_window_destroy()
The previous code was unreffing the window twice, which caused problems
during dialog destruction. Move to g_list_store_find instead of
iterating manually.

ref() the window before and unref() after. g_list_store_remove will
actually unref() the window, since the toplevel_list owns its own
reference.

Fixes #2741
Fixes #2742
2020-05-13 12:18:09 +02:00
Timm Bäder
a50bf27cf2 main: Inline propagate_{down,up} in propagate_internal()
Don't have to worry about anyone calling the up/down variants on their
own this way.
2020-05-13 11:52:22 +02:00
Timm Bäder
ddaf50dfcc window: Create constraint solver on demand 2020-05-13 11:52:16 +02:00
Timm Bäder
8a7fb4b133 widget: Make 1 if out of 2 ifs 2020-05-13 11:52:07 +02:00
Alexander Larsson
a02c588b19 gtk-demo: InfoBar is not a GtkBox anymore
Use gtk_info_bar_add_child to add children
2020-05-13 11:04:49 +02:00
Alexander Larsson
fede7cd81c gtk-demo: Fix expander demo
GtkExpander is not a GtkBox anymore, so use the new gtk_expander_set_child()
API.
2020-05-13 10:50:41 +02:00
Alexander Larsson
fcbc972c2a print-editor: Fix crash
We're trying to g_free a GFile, which is not good...
2020-05-13 10:18:17 +02:00
Timm Bäder
9e0bf35941 paned: Fix up the docs once more 2020-05-13 09:42:51 +02:00
Timm Bäder
f78c167476 cssvalue: Add class check to transition
In b25f93e24c we removed the code
comparing the transition functions, but we didn't add any other check
back.

Fixes #2740
2020-05-13 08:07:55 +02:00
Timm Bäder
b9ed957af3 gl renderer: Fix nested rounded clip rendering
If the inner clip intersects with the corners of the outer clip, we
potentially need a texture. We should add more fine-grained checks for
this in the future though.

Test case included.
2020-05-13 08:07:55 +02:00
Timm Bäder
949eb8d17a node-editor: Monitor file and reload on changes 2020-05-13 08:07:55 +02:00
Timm Bäder
167c6119eb widget: Move adjusted size calculation below early-out goto 2020-05-13 08:07:55 +02:00
Timm Bäder
ef2af521b1 widget: Remove size allocate signal enum member 2020-05-13 08:07:55 +02:00
Timm Bäder
aedc956f6c renderboder: Ignore transparent outlines 2020-05-13 08:07:55 +02:00
Benjamin Otte
d9c0d98871 inspector: Use the monitor list to list monitors 2020-05-13 07:49:56 +02:00
Benjamin Otte
dd7d76f389 gdk: Add gdk_display_get_monitors()
Returns a GListModel of GDK_TYPE_MONITOR.

This will replace the current andling of monitors in GdkDisplay.
2020-05-13 07:00:35 +02:00
Benjamin Otte
bc88f01165 win32: Use a GListStore for the monitors 2020-05-13 06:45:08 +02:00
Benjamin Otte
7ff69e9356 x11: Use a GListStore for the monitors 2020-05-13 05:22:18 +02:00
Benjamin Otte
188e28e196 display: Remove unused vfunc 2020-05-13 04:51:52 +02:00
Benjamin Otte
3536bdd7a6 wayland: Use a GListStore for the monitors
Guess where this is going...
2020-05-13 04:51:52 +02:00
Benjamin Otte
c0c8e93d90 display: Remove gdk_display_get_last_seen_time()
Replace the only usage - in the X11 backend - with an X11-specific call.
2020-05-13 04:48:22 +02:00
Matthias Clasen
8d9a3de65a Merge branch 'matthiasc/for-master' into 'master'
x11: Avoid a critical in clipboard data transfer

Closes #2736

See merge request GNOME/gtk!1887
2020-05-13 02:10:20 +00:00
Matthias Clasen
c66f2ca9eb x11: Avoid a critical in clipboard data transfer
The handler we are calling here asserts that it gets
an interned string as mime_type. So give it one.

Fixes: #2736
2020-05-12 21:31:19 -04:00
Matthias Clasen
9c13bf70a7 Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!1885
2020-05-12 21:18:03 +00:00
Matthias Clasen
a4debecfb1 Merge branch 'tests-cleanup' into 'master'
Tests cleanup

See merge request GNOME/gtk!1884
2020-05-12 21:17:29 +00:00
Matthias Clasen
b230ea2140 paned: Don't ignore the type attribute
We were meaning to only handle <child> here for
compatibility, not <child type="somethingelse">.
2020-05-12 16:27:25 -04:00
Matthias Clasen
a37dc29850 paned: Drop the Private struct 2020-05-12 16:25:58 -04:00
Matthias Clasen
fe6238d1c4 tests: Drop the visuals test
This was just a different way to load a ui file
and try it with dark mode. This can be done
with gtk-builder-tool preview and GTK_THEME.
2020-05-12 15:56:46 -04:00
Matthias Clasen
e7bf4a3de8 tests: Move testcairo into gtk4-demo
Replace the boring checkboard pattern with this
exciting drawing, and save one test binary at the
same time!
2020-05-12 15:43:43 -04:00
Matthias Clasen
c133db4364 Drop the gtkgears test
This has recently been moved to gtk4-demo.
No need to duplicate it.
2020-05-12 15:43:43 -04:00
Matthias Clasen
694daa1d20 Move print-editor to demos
It is too demo-esque for languishing in tests/.
2020-05-12 15:43:43 -04:00
Matthias Clasen
f858a269dd NEWS: Updates 2020-05-12 15:14:09 -04:00
Matthias Clasen
c916221f59 Merge branch 'matthiasc/for-master' into 'master'
printoperation-unix: Fix a use-after-free

See merge request GNOME/gtk!1883
2020-05-12 18:54:59 +00:00
Emmanuele Bassi
80539811c0 Merge branch 'docs-fixes' into 'master'
Docs fixes

See merge request GNOME/gtk!1882
2020-05-12 18:40:34 +00:00
Matthias Clasen
09ea880a43 printoperation-unix: Fix a use-after-free
It turns out that finish_print destroys the
PrintResponseData, so we can't access it afterwards.
2020-05-12 14:09:51 -04:00
Emmanuele Bassi
58774eea72 docs: Add annotations for GtkPaned new getters
Which means also adding gtk-doc stanzas.
2020-05-12 18:52:45 +01:00
Emmanuele Bassi
68682dda89 docs: Remove unnecessary SECTION
The GdkDragSurface definitions fall under the "dnd" section.
2020-05-12 18:44:21 +01:00
Emmanuele Bassi
6ae01f9815 docs: Remove redundant SECTION
We already have a SECTION stanza for gtk-doc.
2020-05-12 18:43:56 +01:00
Carlos Garnacho
3b9a8194a5 Merge branch 'wip/carlosg/broken-grabs' into 'master'
Fixes to broken grabs

Closes #2665

See merge request GNOME/gtk!1879
2020-05-12 16:14:47 +00:00
Matthias Clasen
fdc9bfa2e9 Merge branch 'matthiasc/for-master' into 'master'
window: Hide windows on destroy

See merge request GNOME/gtk!1881
2020-05-12 15:58:10 +00:00
Carlos Garnacho
9103fd6687 gtkmain: Release the active state on GDK_GRAB_BROKEN
This is handled internally here, but misses broken grabs. The active
state should be dropped just as if the button were released.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/2665
2020-05-12 17:39:54 +02:00
Matthias Clasen
ffcffcd773 window: Hide windows on destroy
I thought I could get away with just unrealizing the
window, but it turns out that gtk_window_hide() is the
place where we remove grabs when a modal dialog goes
away, so we ended up with stuck grabs.
2020-05-12 11:10:36 -04:00
Matthias Clasen
450879b1da Merge branch 'matthiasc/for-master' into 'master'
Documentation work

See merge request GNOME/gtk!1880
2020-05-12 14:52:01 +00:00
Matthias Clasen
c6cdd36586 Merge branch 'ebassi/run-dialog-run' into 'master'
Remove gtk_dialog_run() and friends

Closes #371

See merge request GNOME/gtk!1801
2020-05-12 14:29:54 +00:00
Emmanuele Bassi
717d4abebb Do not release the GFile prematurely
Otherwise we won't be able to access it to get the URI for the
GtkPrinterOption.

This fixes a regression introduced in commit 5f070ff233.
2020-05-12 13:45:15 +01:00
Emmanuele Bassi
e8c4b8338f docs: Mention blocking functions in the migration guide
Link to how to make a dialog modal, and to the response signal.
2020-05-12 13:45:15 +01:00
Emmanuele Bassi
d54b7dec94 Remove gtk_dialog_run()
Nested main loops are bad, as they introduce layers of complexity caused
by the potential re-entrancy in the case of multiple event sources, like
IPC, threads, etc. Additionally, the programming model they provide—stop
the world while spinning a new loop—does not conform to the event-driven
model employed by GTK.
2020-05-12 13:45:15 +01:00
Emmanuele Bassi
0a6848d70b Remove gtk_dialog_run() from GtkPrintUnixDialog
Replace it with an explicit nested main loop, as we need to block the
signal handler currently being emitted depending on the response of the
overwrite confirmation dialog.

This is a bit of a hack, and the only reason we need it is that the
print dialog will load the last used path as the output file name, when
printing to a file; this means that, in theory, it would be possible to
press Print without selecting a file, and accidentally overwriting an
existing file.

It would be much simpler if we did not store the last used path, and
always explicitly asked the user to select a file; this would avoid
destructive actions, and would allow us to rely on the overwrite
confirmation dialog right inside the file chooser.
2020-05-12 13:45:15 +01:00
Emmanuele Bassi
b8988be4b5 Remove unnecessary deprecation pragmas
The gtk_window_present() function is not deprecated.
2020-05-12 13:45:15 +01:00
Emmanuele Bassi
45eec06500 Drop gtk_dialog_run() from GtkPrintOperationUnix
We still provide a blocking API, but we should strongly reconsider it.
2020-05-12 13:45:15 +01:00
Emmanuele Bassi
2090dbb27d tests: Remove gtk_dialog_run()
Either use the "response" signal for dialogs that are already modal, or
use an explicit nested loop for tests that rely on the response id being
available in sequence.
2020-05-12 13:45:15 +01:00
Emmanuele Bassi
96856527e6 Drop gtk_dialog_run() from GtkFileChooserWidget
The various dialogs we use inside the file chooser are modal already,
and do no need a nested loop.
2020-05-12 13:22:09 +01:00
Emmanuele Bassi
f81e6042be docs: Remove use of gtk_dialog_run()
Direct people to use GTK_DIALOG_MODAL and the "response" signal instead
of nested main loops.
2020-05-12 13:18:38 +01:00
Emmanuele Bassi
5d272a12cb Remove gtk_native_dialog_run()
Nested main loops are bad, as they introduce layers of complexity caused
by the potential re-entrancy in the case of multiple event sources, like
IPC, threads, etc. Additionally, the programming model they provide—stop
the world while spinning a new loop—does not conform to the event-driven
model employed by GTK.
2020-05-12 13:15:19 +01:00
Emmanuele Bassi
3212b07cf1 docs: Remove use of gtk_native_dialog_run() from examples
Use the "response" signal instead.
2020-05-12 13:15:19 +01:00
Emmanuele Bassi
f573a1f3f2 Remove gtk_dialog_run() from GtkMountOperation 2020-05-12 13:15:16 +01:00
Carlos Garnacho
fbd0c8dc34 gtkmain: Propagate GDK_GRAB_BROKEN events to/from current focus
Let keyboard/pointer paths handle their own events, and find the
current focus. The event will be propagated through instead of
being just emitted on the toplevel.

This makes it handled throughout all the gestures that want to
know about it.
2020-05-12 14:14:39 +02:00
Carlos Garnacho
e33af5895f gdk/wayland: Drop explicit ungrab after surface move/resize
We now break grabs properly if receiving a .leave event with
active buttons. This is not necessary anymore.
2020-05-12 14:14:39 +02:00
Carlos Garnacho
f7d2985f89 gdk/wayland: Ensure .leave events with active buttons breaks grabs
Instead of silently ending up the grab, make it sure that we emit
a GDK_GRAB_BROKEN event if needed.
2020-05-12 14:14:39 +02:00
Carlos Garnacho
2bd8124b5d gdk/wayland: Keep track of implicit grabs
Tracking of those broke sometime along the gdk cleanups, so we
started missing some GDK_GRAB_BROKEN events from being emitted
(eg. after a button press/implicit grab triggers an active grab).

Implicit grabs are only added if there's no prior grab (either
implicit through other button presses, or explicit), in order to
keep accounting correct, make those prevail.
2020-05-12 14:14:39 +02:00
Carlos Garnacho
5e765eaac4 gtktexthandle: Set css name on GtkWidgetClass
Handles are their own widget, special names are not necessary
anymore.
2020-05-12 14:14:39 +02:00
Emmanuele Bassi
4d09bf3b9b demos: Remove gtk_dialog_run()
Use modal dialogs and the "response" signal.
2020-05-12 13:12:08 +01:00
Matthias Clasen
6df8bf7dde docs: Updates to the migration guide
Remove some duplicated content, reorder things
to make more sense, and tweak the wording.
2020-05-12 07:50:17 -04:00
Matthias Clasen
d8db984890 docs: Tweaks
Replace some occurrences of GTK+ by GTK.
2020-05-12 07:50:12 -04:00
Matthias Clasen
072adbf079 docs: Updates to the common questions
Refresh the answers to some common questions.
2020-05-12 01:03:34 -04:00
Matthias Clasen
1ef6a35f3e docs: Don't point at mailing lists
Replace references to the mailing lists by
discourse + irc.
2020-05-12 01:02:49 -04:00
Matthias Clasen
91f0fcde96 docs: Rearrange the introduction some more
Fine-tune some wording, and move the Custom Drawing
example earlier.
2020-05-12 01:02:07 -04:00
Matthias Clasen
82823dac97 Merge branch 'kill-containers' into 'master'
Kill containers

See merge request GNOME/gtk!1866
2020-05-12 03:14:26 +00:00
Matthias Clasen
848a8a792e docs: Update migration guide
Add sections about GtkBin, GtkContainer and gtk_widget_destroy().
2020-05-11 22:38:21 -04:00
Matthias Clasen
7ef173aa34 dialog: Firm up handling of action widgets
It is unreliable to use the widget dom api to locate
action widgets. For example in a headerbar, they might
be deeper in the hierarchy, with boxes in between.
Therefore, make GtkDialog keep a list of action widgets,
and use that when operating on action widgets.
2020-05-11 22:38:21 -04:00
Matthias Clasen
f72d672434 dialog: Remove an unused struct 2020-05-11 22:38:21 -04:00
Matthias Clasen
5ebd42d402 Drop GtkContainer and its accessible implementation
It is no longer used.
2020-05-11 22:38:21 -04:00
Matthias Clasen
e706d4860e testsuite: Drop a container api use 2020-05-11 22:38:21 -04:00
Matthias Clasen
5573a3465c Drop gtkcontainer.h includes
These includes are unused.
2020-05-11 22:38:21 -04:00
Matthias Clasen
5f642f8096 box: Derive from GtkWidget 2020-05-11 22:38:21 -04:00
Matthias Clasen
6bc4446e3e assistant: Remove code that doesn't work anymore
When GtkContainer goes away, we don't have
an "add" signal anymore.
2020-05-11 22:38:21 -04:00
Matthias Clasen
6c78eeebe4 dialog: Remove code that doesn't work anymore
When GtkContainer goes away, we don't have an
"add" signal anymore.
2020-05-11 22:38:21 -04:00
Matthias Clasen
58a88a88b8 shortcutssection: Drop container bits
When GtkBox stops being a container, GtkShortcutsSection
will also no longer be a container. So, stop overriding
container vfuncs, and instead add a buildable implementation
that does the right thing.
2020-05-11 22:38:21 -04:00
Matthias Clasen
537d21155f shortcutsgroup: Drop container bits
When GtkBox stops being a container, GtkShortcutsGroup
will also no longer be a container. So, stop overriding
container vfuncs, and instead add a buildable implementation
that does the right thing.
2020-05-11 22:38:21 -04:00
Matthias Clasen
2a24b8c653 Replace most remaining uses of container api
These are all on GtkBox or enumerating children.
2020-05-11 22:38:21 -04:00
Matthias Clasen
665edcba53 box: Add gtk_box_append/prepend/remove
Add replacement api for gtk_container_add/remove.
2020-05-11 22:38:21 -04:00
Matthias Clasen
a0437628e3 notebook: Derive from GtkWidget 2020-05-11 22:38:21 -04:00
Matthias Clasen
0daa1f3daa Stop using container api on GtkNotebook 2020-05-11 22:38:21 -04:00
Matthias Clasen
c7b7d78ae1 headerbar: Derive from GtkWidget 2020-05-11 22:38:21 -04:00
Matthias Clasen
abfa4d4a5c Stop using container api on GtkHeaderBar 2020-05-11 22:21:39 -04:00
Matthias Clasen
d59d9d4bd5 headerbar: Add gtk_header_bar_remove
This is a replacement for gtk_container_remove.
2020-05-11 22:21:39 -04:00
Matthias Clasen
3d100abea8 listbox: Derive from GtkWidget 2020-05-11 22:21:39 -04:00
Matthias Clasen
6f170a0cf7 testsuite: Fix listbox tests
When moving from gtk_container_forall to the widget dom
api, we are now iterating over all children of the listbox,
including headers, separators, etc. So, skip everything
that is not a listboxrow, to make the tests work again.
2020-05-11 22:21:39 -04:00
Matthias Clasen
c55aa7e590 testsuite: Redo listbox sort test
This test was relying on gtk_container_forall returning
the visual (ie sorted) order of children, while iterating
with the widget dom api gives the insertion order.

Instead of using gtk_container_forall, use
gtk_list_box_row_get_index to reconstruct the visual
order.
2020-05-11 22:21:39 -04:00
Matthias Clasen
88141103cd Don't use container api on GtkListBox 2020-05-11 22:21:39 -04:00
Matthias Clasen
ff91ce9eb4 listbox: Add gtk_list_box_remove
This is a gtk_container_remove replacement.
2020-05-11 22:21:39 -04:00
Matthias Clasen
7af15ae277 buildable: Cosmetics
Don't refer to GtkContainer in the docs.
2020-05-11 22:21:39 -04:00
Matthias Clasen
001d62381a customlayout: Cosmetics
Don't refer to GtkContainer in the docs.
2020-05-11 22:21:39 -04:00
Matthias Clasen
47139bc506 textviewchild: Derive from GtkWidget
GtkContainer is going away.
2020-05-11 22:21:39 -04:00
Matthias Clasen
bf543e0367 text: Fix popover use
There were some leftover gtk_container_add calls here
on popovers on buttons, but these are no longer containers.
2020-05-11 22:21:39 -04:00
Matthias Clasen
5c34b30819 textview: Fix popover use
There were some leftover gtk_container_add calls here
on popovers on buttons, but these are no longer containers.
2020-05-11 22:21:39 -04:00
Matthias Clasen
ddcc9db568 flowbox: Derive from GtkWidget 2020-05-11 22:21:39 -04:00
Matthias Clasen
3bff7d3a37 Stop using container api on GtkFlowBox
GtkContainer is going away.
2020-05-11 22:21:39 -04:00
Matthias Clasen
2f7f6e6a37 flowbox: Add gtk_flow_box_remove
This is the replacement for gtk_container_remove.
2020-05-11 22:21:39 -04:00
Matthias Clasen
5907ecebfc stack: Derive from GtkWidget 2020-05-11 22:21:39 -04:00
Matthias Clasen
a7769c9c88 treepopover: Stop using container api 2020-05-11 22:21:39 -04:00
Matthias Clasen
b490800949 shortcutswindow: Stop using container api 2020-05-11 22:21:39 -04:00
Matthias Clasen
ee5587d516 shortcutssection: Stop using container api 2020-05-11 22:21:39 -04:00
Matthias Clasen
01c3e2ce0d Don't use container api on GtkStack 2020-05-11 22:21:39 -04:00
Matthias Clasen
5e0c1e6a86 stack: Add gtk_stack_remove
This is a replacement for gtk_container_remove.
2020-05-11 22:21:39 -04:00
Matthias Clasen
741a9cb320 fixed: Derive from GtkWidget 2020-05-11 22:21:39 -04:00
Matthias Clasen
0d57abfe65 Stop using container api on GtkFixed
GtkContainer is going away.
2020-05-11 22:21:39 -04:00
Matthias Clasen
96d707444d fixed: Add gtk_fixed_remove
This is the replacement for gtk_container_reomve.
2020-05-11 22:21:39 -04:00
Matthias Clasen
3852661865 grid: Derive from GtkWidget
GtkContainer is going away.
2020-05-11 22:21:39 -04:00
Matthias Clasen
c0657297d1 grid: Remove a test for grid container functionality
This test was specifically testing how gtk_container_add
behaves on grids. Well, it doesn't anymore.
2020-05-11 22:21:39 -04:00
Matthias Clasen
932aa58237 Avoid container api on grids
GtkContainer is going away.
2020-05-11 22:21:39 -04:00
Matthias Clasen
5cda824784 grid: Add gtk_grid_remove
This is a replacement for gtk_container_remove.
2020-05-11 22:21:39 -04:00
Matthias Clasen
1a33278703 infobar: Derive from GtkWidget
GtkContainer is going away.
2020-05-11 22:21:39 -04:00
Matthias Clasen
bd843acde9 Use gtk_info_bar_add_child throughout 2020-05-11 22:21:39 -04:00
Matthias Clasen
12ca08c382 infobar: Add gtk_info_bar_add/remove_child
This is a replacement for container api that is going away.
2020-05-11 22:21:39 -04:00
Matthias Clasen
78d20b9301 infobar: Add gtk_info_bar_remove_action_widget
This is mainly for completeness, since gtk_container_remove
will not work for those anymore.
2020-05-11 22:21:39 -04:00
Matthias Clasen
bc6643f3c2 paned: Redo the api
This commit is porting GtkPaned to be derived
from GtkWidget instead of GtkContainer, while adding
start-child and end-child properties. The existing
properties are renamed to follow the start/end naming
scheme, and we add proper getters and setters.

Update all users.

See #2719
2020-05-11 22:21:33 -04:00
Matthias Clasen
fc9873e9ef paned: Drop some dead code 2020-05-11 22:21:14 -04:00
Matthias Clasen
253a39c6e9 iconview: Derive from GtkWidget
GtkIconView is not a container.
2020-05-11 22:21:14 -04:00
Matthias Clasen
825e98dcca expander: Derive from GtkWidget
We want to remove GtkBin and GtkContainer as they don't
provide much useful functionality anymore. This requires
us to move get_request_mode and compute_expand down.

See #2719
2020-05-11 22:21:14 -04:00
Matthias Clasen
1afc749443 Use gtk_expander_set_child throughout
Replace all uses of gtk_container_add on expanders
with gtk_expander_set_child.
2020-05-11 22:21:14 -04:00
Matthias Clasen
6b80d90db5 expander: Add a child property 2020-05-11 22:21:14 -04:00
Matthias Clasen
e2b23e8fde actionbar: Derive from GtkWidget
GtkContainer is going away.
2020-05-11 22:21:09 -04:00
Matthias Clasen
c0f090627a actionbar: Add gtk_action_bar_remove
This is a replacement for gtk_container_remove.
2020-05-11 20:33:23 -04:00
Matthias Clasen
3697c57e56 treeview: Derive from GtkWidget
Drop the GtkContainer vfuncs.
2020-05-11 20:33:23 -04:00
Matthias Clasen
52b1a347d8 treeview: Stop using container api 2020-05-11 20:33:23 -04:00
Matthias Clasen
aeef59fda9 textview: Derive from GtkWidget
Drop the GtkContainer vfuncs. As a replacement for
gtk_container_remove, make gtk_text_view_remove public.
2020-05-11 20:33:23 -04:00
Matthias Clasen
84632b0901 dragicon: drop gtkcontainer.h include
We don't need it anymore here.
2020-05-11 20:33:23 -04:00
Matthias Clasen
e516616cca textviewchild: Don't leak children
Like everybody else, GtkTextViewChild must
unparent its children in dispose.
2020-05-11 20:33:23 -04:00
Matthias Clasen
d62ad4e6df Fix a leftover window
We were still using container api on a window here.
2020-05-11 15:42:52 -04:00
Matthias Clasen
a7abb394e8 Fix a leftover list box child
We were still using container api on a list box child here.
2020-05-11 15:42:52 -04:00
Matthias Clasen
501eda2956 window: Fix accessible implementation
Now that GtkWindow is no longer a container,
update the accessible implementation to match.
2020-05-11 15:42:52 -04:00
Matthias Clasen
7fac7c2d28 statusbar: Fix accessible implementation
Now that GtkStatusBar is no longer a container,
update the accessible implementation to match.
2020-05-11 15:42:52 -04:00
Matthias Clasen
295c5594ce scrolledwindow: Fix accessible implementation
Now that GtkScrolledWindow is no longer a container,
update the accessible implementation to match.
2020-05-11 15:42:52 -04:00
Matthias Clasen
a65f70ac23 popover: Fix accessible implementation
Now that GtkPopover is no longer a container,
update the accessible implementation to match.
2020-05-11 15:42:52 -04:00
Matthias Clasen
2e615d8c20 frame: Fix accessible implementation
Now that GtkFrame is no longer a container,
update the accessible implementation to match.
2020-05-11 15:42:52 -04:00
Matthias Clasen
ce5b51b017 flowboxchild: Fix accessible implementation
Now that GtkFlowBoxChild is no longer a container,
update the accessible implementation to match.
2020-05-11 15:42:51 -04:00
Matthias Clasen
cca73c436d combobox: Fix accessible implementation
Now that GtkComboBox is no longer a container,
update the accessible implementation to match.
2020-05-11 15:42:51 -04:00
Matthias Clasen
840a5e35f4 listboxrow: Fix the accessible implementation
GtkListBoxRow is no longer a container, update
the accessible implementation to match.
2020-05-11 15:42:51 -04:00
Matthias Clasen
af19c7275b button: Fix accessible implementation
Now that GtkButton is no longer a container,
update the accessible implementation to match.
2020-05-11 15:42:51 -04:00
Matthias Clasen
d7b1ecdf52 Cosmetics: Replace GtkContainer in an error message
GtkWidget is not that much better here, unfortunately.

Adapt the testsuite to match.
2020-05-11 15:42:51 -04:00
Matthias Clasen
ba0579c670 Merge branch 'matthiasc/for-master' into 'master'
print-editor: Bring back the menubar

See merge request GNOME/gtk!1875
2020-05-11 19:08:53 +00:00
Matthias Clasen
757c9675b0 Merge branch 'wip/exalm/2242-test' into 'master'
tests: Add a headerbar-in-window test case

See merge request GNOME/gtk!1878
2020-05-11 18:51:20 +00:00
Matthias Clasen
cc28a7b0ef Merge branch 'wip/tintou/doc-fixes' into 'master'
docs: Fix several missing references in the documentation

See merge request GNOME/gtk!1874
2020-05-11 18:40:34 +00:00
Matthias Clasen
58fd969b2d printeroptionwidget: Avoid a critical
The new_location can be NULL, as we clearly
knew earlier in the function. We've forgotten
about that by the time we unref it :(
2020-05-11 14:26:31 -04:00
Matthias Clasen
495b9caf63 headerbar: Don't clean up other widget children
The parent of the title_widget is the center box,
it needs to call gtk_widget_unparent on it.
2020-05-11 14:25:57 -04:00
Emmanuele Bassi
aece8bab17 Merge branch 'cherry-pick-6d8fb83a' into 'master'
aboutdialog: Update precondition checks for new licenses added in 3.24.20

Closes #2734

See merge request GNOME/gtk!1877
2020-05-11 18:25:39 +00:00
Matthias Clasen
ea53b445a8 filechooserdialog: Be more careful with widgets
We were stepping on our own toes, by first setting
up a save entry and telling the filechooserwidget
about it, and then nuking it by setting a title
on the headerbar. The filechooserwidget wasn't
ready for the entry to die without anybody telling
it.

This fixes a crash when using the filechooser for
print-to-file in the print dialog.
2020-05-11 14:23:58 -04:00
Alexander Mikhaylenko
70d14f60b2 tests: Add a headerbar-in-window test case
See https://gitlab.gnome.org/GNOME/gtk/-/issues/2242
2020-05-11 22:37:58 +05:00
Simon McVittie
6451250b2e aboutdialog: Update precondition checks for new licenses added in 3.24.20
To avoid making this mistake again, add a static assertion that the
enum is in sync with gtk_license_info, and use the length of
gtk_license_info for the precondition check.

Signed-off-by: Simon McVittie <smcv@debian.org>
Resolves: #2734
2020-05-11 18:37:22 +01:00
Corentin Noël
076b2f11d2 docs: Fix several missing references in the documentation
This fixes several typos and missing references
2020-05-11 19:26:20 +02:00
Matthias Clasen
7ae1d9d796 Merge branch 'window-destroy' into 'master'
Drop gtk_widget_destroy

See merge request GNOME/gtk!1864
2020-05-11 17:15:59 +00:00
Matthias Clasen
c8a96d08a0 print-editor: Bring back the menubar
This was the one place where we relied on
the menubar fallback in GtkApplicationWindow.

So turn it on explicitly.
2020-05-11 12:55:15 -04:00
Matthias Clasen
6d969d1026 Update the docs
Remove various references to gtk_widget_destroy in the docs.
2020-05-11 12:20:59 -04:00
Matthias Clasen
177c0eb9e2 Unset tooltip window earlier
This avoids a crash when the tooltip window tries
to update its action muxers.
2020-05-11 12:20:59 -04:00
Matthias Clasen
1306727fb1 window: Remove _set_has_user_ref_count 2020-05-11 12:20:59 -04:00
Timm Bäder
e5d6b493c0 testsuite: add widget refcount test case
Testing toplevels and popovers.
2020-05-11 12:20:59 -04:00
Matthias Clasen
0f10b170f4 widget: Drop gtk_widget_destroy 2020-05-11 12:20:59 -04:00
Matthias Clasen
6aebedb8bc window: Implement gtk_window_destroy
Don't call gtk_widget_destroy; instead implement
gtk_window_destroy outselves by removing the window
from the toplevel lista and dropping the reference that
GTK holds.
2020-05-11 12:20:59 -04:00
Matthias Clasen
025375ff5f Replace gtk_widget_destroy everywhere
Replace all remaining uses of gtk_widget_destroy
by gtk_container_remove or g_object_unref.
2020-05-11 12:20:59 -04:00
Matthias Clasen
cd0081d08a Use gtk_window_destroy
Replace calls to gtk_widget_destroy on windows
with gtk_window_destroy.
2020-05-11 12:20:57 -04:00
Matthias Clasen
48821a64d0 window: Add gtk_window_destroy
This is a replacement for gtk_widget_destroy for toplevels.
For now, it is just a wrapper.
2020-05-11 12:19:39 -04:00
Matthias Clasen
81340da8b6 nativedialog: Do not ref the transient_for parent
gtk_window_set_transient_for does not ref its parent either. This is
important because a child widget of the parent might be the one calling
this function.

This was showing up as widget-factory not existing on close after
opening the file chooser.
2020-05-11 12:19:39 -04:00
Matthias Clasen
466d2a84de testsuite: Clean up unexpected children
If you call gtk_widget_set_parent on an unsuspecting
parent widget, it is your reponsibility to clean up
before the parent gets finalized.
2020-05-11 12:19:39 -04:00
Matthias Clasen
ddebf07236 popover: Fix a reference leak
Don't leak the reference to the default widget.
2020-05-11 12:19:39 -04:00
Matthias Clasen
0ba1aad4e3 filechooserdialog: Fix disposing
We need to drop our widgetry in dispose to prevent
leakage.
2020-05-11 12:19:39 -04:00
Matthias Clasen
4b144855b9 colorchooserdialog: Fix disposing
We need to drop our widgetry in dispose to prevent
leakage.
2020-05-11 12:19:39 -04:00
Matthias Clasen
b6bfeb786f fontchooserdialog: Fix disposing
We need to drop our widgetry in dispose to prevent
leakage.
2020-05-11 12:19:39 -04:00
Matthias Clasen
573b20a8f8 Drop gtk_widget_destroyed
Use g_object_add_weak_pointer or a weak reference instead.
2020-05-11 12:19:39 -04:00
Matthias Clasen
8f9c3ed44a Stop using gtk_widget_destroyed
Replace all internal use of gtk_widget_destroyed
by g_object_add_weak_pointer.
2020-05-11 12:19:37 -04:00
Matthias Clasen
9ce7b16dd8 Merge branch 'wip/exalm/test' into 'master'
Fix (most of the) tests

See merge request GNOME/gtk!1873
2020-05-11 15:52:24 +00:00
Matthias Clasen
597665517c Merge branch 'teardown-cleanup-2' into 'master'
Treeview teardown cleanup

See merge request GNOME/gtk!1872
2020-05-11 15:23:40 +00:00
Alexander Mikhaylenko
228b3fc622 tests: Stop explicitly showing widgets 2020-05-11 20:15:57 +05:00
Alexander Mikhaylenko
ea9cea9be7 tests: Remove redundant image from testdialog 2020-05-11 20:04:23 +05:00
Alexander Mikhaylenko
56f56e6352 tests: Connect signal properly for testvolumebutton 2020-05-11 19:54:32 +05:00
Alexander Mikhaylenko
2323e8d77d tests: Remove orientation from testvolumebutton
GtkVolumeButton isn't orientable anymore.
2020-05-11 19:53:31 +05:00
Alexander Mikhaylenko
531468cab6 test: Stop using stock-size for teestverticalcells 2020-05-11 19:51:18 +05:00
Alexander Mikhaylenko
58fcd09cff tests: Fix testtreeelistmodel
Stop using GtkContainer API for GtkListBoxRow and GtkToggleButton.
2020-05-11 19:47:58 +05:00
Alexander Mikhaylenko
2940b17a8e tests: Fix teststackedheader
Connect to signals programmatically.
2020-05-11 19:33:05 +05:00
Matthias Clasen
b8c5bf8af8 testsuite: Enable the remaining template tests
These are no longer failing.
2020-05-11 10:30:03 -04:00
Matthias Clasen
d061bcad52 treeview: Break reference cycles on unroot
It is a bad idea to have such cycles in the first place,
and there is no need to let them linger past unroot.

This stop the treeview depending on run_dispose to get
freed, a simple unparent will work now.
2020-05-11 10:30:03 -04:00
Alexander Mikhaylenko
1d2af907fc tests: Fix teststack "add icon" button 2020-05-11 19:27:41 +05:00
Matthias Clasen
329994291a Merge branch 'wip/baedert/for-master' into 'master'
Wip/baedert/for master

See merge request GNOME/gtk!1867
2020-05-11 14:24:45 +00:00
Alexander Mikhaylenko
b2da99fd4e tests: Fix testselectionmode
Stop using <packing/> and GtkContainer API for random widgets.
2020-05-11 19:21:03 +05:00
Yuri Chornoivan
2d97357136 Update Ukrainian translation 2020-05-11 14:20:13 +00:00
Alexander Mikhaylenko
4361a884bf tests: Fix testoverlay
Stop using child properties and margin property.
2020-05-11 19:13:04 +05:00
Alexander Mikhaylenko
14dc92c747 tests: Simplify testorientable
Since GtkButtonBox is gone, remove the separator and change grid to box.
2020-05-11 19:08:56 +05:00
Alexander Mikhaylenko
c9760ed456 tests: Remove testmodelbutton
GtkModelButton is private now, so it can't work anymore.
2020-05-11 19:03:53 +05:00
Alexander Mikhaylenko
7c148bebef tests: Remove use-popover from testmenubutton
The corresponding property doesn't exist anymore.
2020-05-11 18:55:15 +05:00
Alexander Mikhaylenko
7aeb504652 tests: Fix testlogout
Stop using GtkApplication::quit signal.
2020-05-11 18:54:53 +05:00
Alexander Mikhaylenko
e0d36d1f2d tests: Fix testiconview
Stop using GtkContainer API for GtkPopover.
2020-05-11 18:54:23 +05:00
Alexander Mikhaylenko
68fb643a7e tests: Fix testheightforwidth layout
Stop using child properties and setting visible=true everywhere.
2020-05-11 18:39:32 +05:00
Alexander Mikhaylenko
fb0dcaf066 tests: Expand content for testheaderbar 2020-05-11 18:31:59 +05:00
Alexander Mikhaylenko
4277eeee1b tests: Fix testgtk
An assorted collection of fixes.
2020-05-11 18:12:18 +05:00
Matthias Clasen
9f3fb69dce Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

Closes #2729 and #2730

See merge request GNOME/gtk!1870
2020-05-11 12:51:08 +00:00
Matthias Clasen
0e18e52f00 menubutton: Cosmetics
Fix a few typos in the docs.
2020-05-11 08:15:56 -04:00
Matthias Clasen
d2430c70bd Refresh the tutorial examples
Redo this series of examples from 2013, and adapt it to modern
way of doing things. The biggest differences are that we use
a headerbar right from the start, and don't mention the app
menu.

Fixes: #2730
2020-05-11 08:15:56 -04:00
Matthias Clasen
4de4957aa3 applicationswindow: Make show-menubar FALSE by default
The fallback to the menubar is not a good sight,
we should not do that by default.
2020-05-11 08:15:56 -04:00
Matthias Clasen
0fc1a290e2 docs: Cosmetic updates to the tutorial
Since the meson conversion, we are no longer expanding
gtk-doc references in this file, so take them out. And
touch up the wording in various places.
2020-05-11 08:15:55 -04:00
Matthias Clasen
1b8a025a5f Clean up a leak in a test
One of the treeview tests was calling gtk_widget_destroy
on a child instead of the toplevel, which leaks the toplevel
unnecessarily. Plus, we're moving towards allowing destroy
only on toplevels.
2020-05-11 08:15:55 -04:00
Matthias Clasen
d798527290 treeviewcolumn: Another case of box <> frame confusion
Don't call your boxes frames, folks!
2020-05-11 08:15:55 -04:00
Matthias Clasen
6140dafecf builderscope: Fix finalize <> dispose confusion
Don't chain up to dispose if you implement finalize.

This fix s courtesy of GOBJECT_DEBUG=objects.
2020-05-11 08:15:55 -04:00
Matthias Clasen
3a5cf61a4d print dialog: Fix frame <> box confusion
It is a bad idea to have a GtkBox called frame, event
if it started out its existence as a GtkFrame.
2020-05-11 08:15:55 -04:00
Matthias Clasen
a11119d317 treeview: Ensure search popover is properly inserted
The css tree and the widget tree are not in sync, so we need
to explicitly set the parent of the css node before inserting
the widget, or else we end up with critical warnings and a
non-working popover.

This can be seen in the print dialog, when moving the focus
to the printer list.
2020-05-11 08:15:55 -04:00
Matthias Clasen
756720fde4 print-editor: Cosmetics
Make the about dialog a bit less barren.
2020-05-11 08:15:55 -04:00
Matthias Clasen
2b920b22c1 print-editor: Fix a critical
GtkWindow is no longer a container, so don't call
gtk_container_add on it.
2020-05-11 08:15:55 -04:00
Matthias Clasen
bb8fa045c2 Merge branch 'focusable-property' into 'master'
Focusable property

See merge request GNOME/gtk!1834
2020-05-11 11:23:15 +00:00
Emmanuele Bassi
4cc21f1fa1 Merge branch 'aperezdc/vk-result-range-size' into 'master'
Fix build issue due to missing VK_RESULT_RANGE_SIZE

See merge request GNOME/gtk!1871
2020-05-11 10:02:53 +00:00
Adrian Perez de Castro
5c4ca1424d Fix build issue due to missing VK_RESULT_RANGE_SIZE
Conditionally check whether the Vulkan headers version defines
VK_RESULT_RANGE_SIZE, and avoid using it for version >=140. The
following comming in Vulkan-Headers has removed the enum value:

  0c5351f5e9 (diff-4febd94c0666d59030d8b1dd20c72403)
2020-05-11 10:07:41 +03:00
Matthias Clasen
6372a33838 Clarify docs around focus. 2020-05-11 00:29:41 -04:00
Matthias Clasen
b93631164f Remove lots of focus vfuncs
In many cases, the default widget vfuncs work just fine,
combined with setting focusable.
2020-05-11 00:11:37 -04:00
Matthias Clasen
46bad5d513 widget: Fix gtk_widget_focus_all for !focusable
This was a case that wasn't handle properly when
the focus is entering from the outside, in forward
direction.
2020-05-11 00:11:04 -04:00
Matthias Clasen
edc31a264c widget: Add a :focusable property
Add back a property that determines whether an individual
widget will accept focus or not. :can-focus prevents the
focus from ever entering the entire widget hierarchy
below a widget, and :focusable just determines if grabbing
the focus to the widget itself will succeed.

See #2686
2020-05-10 23:24:48 -04:00
Alexander Mikhaylenko
99704248b7 tests: Fix testgmenu
GtkMenuButton isn't a GtkButton anymore.
2020-05-11 04:58:36 +05:00
Alexander Mikhaylenko
7a09143519 tests: Add missing margin for testglarea 2020-05-11 04:57:01 +05:00
Alexander Mikhaylenko
25295d1e17 tests: Fix testgiconpixbuf test
Don't use GtkContainer API on GtkWindow.
2020-05-11 04:55:22 +05:00
Alexander Mikhaylenko
6920fc3625 tests: Fix testfontchooser layout
Remove an extra box so that we don't need to expand the chooser.
2020-05-11 04:52:04 +05:00
Alexander Mikhaylenko
b2f2b3f169 tests: Fix testfilechooser test
Don't use GtkContainer API on GtkWindow.
2020-05-11 04:47:26 +05:00
Alexander Mikhaylenko
466e8a70e5 tests: Add missing margin for testentrycompletion 2020-05-11 03:47:39 +05:00
Alexander Mikhaylenko
f2542e95f9 tests: Fix testdnd popup
Don't use GtkContainer API for GtkWindow.
2020-05-11 03:38:10 +05:00
Alexander Mikhaylenko
02b27775d8 tests: Fix testdialogtest
Fix deprecations in UI files, add a missing expand.
2020-05-11 03:36:51 +05:00
Alexander Mikhaylenko
9af4a420a3 tests: Update testcombochange test
GtkComboBox doesn't have list mode anymore, remove that.
2020-05-11 03:23:12 +05:00
Alexander Mikhaylenko
9efdf3c65c tests: Fix testcombo
Don't use GtkContainer API on GtkFrame.
2020-05-11 03:22:34 +05:00
Alexander Mikhaylenko
e162b3ee19 tests: Fix testcalendar layout
Add a missing expand.
2020-05-11 03:22:15 +05:00
Alexander Mikhaylenko
1fd75d0fa2 tests: Add missing margin to simple test 2020-05-11 02:49:09 +05:00
Alexander Mikhaylenko
de5939f319 tests: Fix testadjustsize test
Don't assume GtkWindow is a container, also add missing expand and margin.
2020-05-11 02:47:40 +05:00
Alexander Mikhaylenko
31e3c1e362 tests: Fix testappchooser test
Don't assume GtkWindow is a container.
2020-05-11 02:47:40 +05:00
Alexander Mikhaylenko
1c03745ee4 tests: Fix testaccel layout
hexpand doesn't matter there, set vexpand instead.
2020-05-11 02:47:40 +05:00
Alexander Mikhaylenko
778d3884e2 tests: Fix testaccel indentation 2020-05-11 02:47:32 +05:00
Alexander Mikhaylenko
0f57e6c3c0 tests: Fix syncscroll
Set expand for the scrolled windows.
2020-05-11 02:26:42 +05:00
Alexander Mikhaylenko
edfaa5fc36 tests: Fix overlayscroll
Set expand for the scrolled window.
2020-05-11 02:18:06 +05:00
Alexander Mikhaylenko
b7bfb29ae8 tests: Fix print-editor
Don't assume GtkWindow is a container.
2020-05-11 02:17:42 +05:00
Matthias Clasen
caab6ac6e7 testsuite: Add more tests for automated components
Add template tests that show the complex dialogs before
destroying them. This reveals that we are leaking in
several of them. These leaks don't show up if the
dialogs are destroyed right away, as the existing
tests do.

Disable the two failing tests for now:
  /template/GtkFileChooserDialog/show
  /template/GtkPrintUnixDialog/show
2020-05-10 16:25:28 -04:00
Matthias Clasen
9d4b01fff8 testsuite: Use lowercase component in test paths
This is purely cosmetic.
2020-05-10 16:25:28 -04:00
Matthias Clasen
10921aa237 textview: Ensure popup menu is properly inserted
In the presence of attached children, the css tree and the
widget tree are not in sync, so we need to explicitly set
the parent of the css node before inserting the widget, or
else we end up with critical warnings and a non-working
menu.

This can be seen in testtextview.
2020-05-10 16:25:28 -04:00
Matthias Clasen
3f548327b5 textview: Give attached children a different css name
If we use "text" for the children that are attached to the
text view, they end up rendering the same background as the
main text content, causing that content to be covered up.

Fixes: #2729
2020-05-10 16:25:28 -04:00
Aurimas Černius
f6a4e68973 Updated Lithuanian translation 2020-05-10 22:34:16 +03:00
Matthias Clasen
eae4a194b8 Merge branch 'wip/exalm/headerbar-dragging' into 'master'
Extract GtkWindow dragging and titlebar actions

Closes #2689

See merge request GNOME/gtk!1814
2020-05-10 18:15:57 +00:00
Yuri Chornoivan
f693da148e Update Ukrainian translation 2020-05-10 16:03:34 +00:00
Piotr Drąg
386b36a625 Update POTFILES.in 2020-05-10 14:34:33 +02:00
Timm Bäder
52ae384bfd gl shaders: unify frag coord handling 2020-05-10 09:30:15 +02:00
Timm Bäder
b98ad549c2 gl renderer: Only destroy shader programs with ids > 0
We may return -1 as an error return value.
2020-05-10 09:30:15 +02:00
Timm Bäder
d015b1b29e scrolledwindow: Always keep the main child first
Otherwise we can't pick the scrollbars, which are allocated behind it.
2020-05-10 09:30:15 +02:00
Timm Bäder
343d294bfb stylecontext: Remove _save_named
Now unused.
2020-05-10 09:30:15 +02:00
Timm Bäder
6566fdc1e3 scrolledwindwo: Add a permanent junction node
Use that instead of save_named'ing a junction node.
2020-05-10 09:30:15 +02:00
Timm Bäder
bcdd6d5425 printunixdialog: Use two "paper" css nodes
Instead of save_named'ing to a temporary "paper" node.
2020-05-10 09:30:15 +02:00
Timm Bäder
cbbbf44dd4 cellrenderertoggle: Replace save_named with a css node 2020-05-10 09:30:13 +02:00
Timm Bäder
2455978c78 widget: Move {dis,}connect_frame_clock into their only caller
Makes sense to have these only in (un)realize.
2020-05-10 08:44:20 +02:00
Timm Bäder
343707e0a2 stylecontext: Remove some unused private API 2020-05-10 08:44:20 +02:00
Timm Bäder
1b10020b6e css: Make GtkStyleAnimation and subclasses non-objects
Making them GObjects is unnecessary. This enables further optimizations
down the road. The only place we use them in is gtkcssanimatedstyle.c
after all.
2020-05-10 08:44:20 +02:00
Timm Bäder
57444f77f7 testtreeview: Properly annotate a switch fallthrough 2020-05-10 08:44:20 +02:00
Timm Bäder
06460ea50c css: Drop a few dynamic type checks
We hit these code paths a lot
2020-05-10 08:44:20 +02:00
Timm Bäder
e12c9de5df csstransiton: Save finished state
Once a transtion is finished it can't change to unfinished again, so we
don't have to consult the progress tracker all the time.
2020-05-10 08:44:20 +02:00
Timm Bäder
f38bbb9bc2 gtkarray: memcpy() directly into the GPtrArray 2020-05-10 08:44:20 +02:00
Timm Bäder
75cfe3c6ae gtkarray: Create GPtrArray in insert() if we have to 2020-05-10 08:44:20 +02:00
Timm Bäder
24608d5c23 gtkarray: Fix a typo 2020-05-10 08:44:20 +02:00
Timm Bäder
b25f93e24c Make dimension values and calc values just number values 2020-05-10 08:44:20 +02:00
Timm Bäder
df08387e35 csscalcvalue: Avoid allocating memory in compute()
We already know how many values we're going to have, it's
value->n_terms.
2020-05-10 08:44:20 +02:00
Christoph Reiter
90b3105d99 CI: install brotli in msys2
Not a direct dependency, but the freetype package is missing it atm
2020-05-10 08:37:01 +02:00
Matthias Clasen
0fdcc3778d Merge branch 'matthiasc/for-master' into 'master'
window: Remove some dead code

Closes #2726 and #2724

See merge request GNOME/gtk!1862
2020-05-10 00:36:49 +00:00
Matthias Clasen
78343ef61a placesview: Don't do the same thing twice
When the schema is supported, we want to remove
the error style class, not add it again. Pointed
out by Rafał Mikrut.

Fixes: #2724
2020-05-09 19:41:30 -04:00
Matthias Clasen
d83df5a928 gsk: Fix a typo
We were checking x_offset twice, when we meant to check
x_offset and y_offset. Pointed out by Rafał Mikrut.

Fixes: #2726
2020-05-09 19:40:06 -04:00
Matthias Clasen
fc42a0696e Add a test for refcounts under reordering
It turns out that we have a ref leak at the very
core of our dom model :( gtk_widget_insert_before/after
leak a reference if the widget was already under
the same parent. This is something that GtkBox
frequently does. It shows up e.g. when packing
widgets at the end in a headerbar.
2020-05-09 19:38:19 -04:00
Matthias Clasen
0cd0ef2d26 widget: Don't leak a reference when reordering
When reordering a widget that is alrady under the
same parent, we must not take another reference.
2020-05-09 19:27:56 -04:00
Matthias Clasen
c4514e7eb4 window: Remove some dead code
We are not attaching windows anymore.
2020-05-09 19:27:56 -04:00
Alexander Mikhaylenko
8d24711567 testsuite: Update bloomfilter test
Add the 2 new css nodes.
2020-05-08 00:03:42 +05:00
Alexander Mikhaylenko
f4538839d4 window: Stop handling dragging and titlebar actions
Since GtkWindowHandle and GtkHeaderBar do it now, it can be removed from
GtkWindow, along with GTK_WINDOW_REGION_TITLE which at this point doesn't
differ from GTK_WINDOW_REGION_CONTENT.

Closes https://gitlab.gnome.org/GNOME/gtk/-/issues/2689, since
GtkWindowHandle doesn't do that anymore.
2020-05-08 00:02:08 +05:00
Alexander Mikhaylenko
8ca1e0ddc3 headerbar: Include GtkWindowHandle
This allows it to continue being draggable when placed inside a window, and
will allow to remove the corresponding gestures from GtkWindow.
2020-05-07 23:58:16 +05:00
Alexander Mikhaylenko
4135276252 headerbar: Use GtkCenterBox internally
This will allow to easily wrap it into another widget in the next commits.
2020-05-07 23:58:16 +05:00
Alexander Mikhaylenko
8bd44cb3eb Add GtkWindowHandle
This will allow to move the titlebar handling logic out from GtkWindow.
2020-05-07 23:57:58 +05:00
Alexander Mikhaylenko
6c636642df widget: Pass parent to gtk_widget_consumes_motion()
Right now it assumes that the parent is a GtkWindow. This will break when
window dragging is handled by another widget.
2020-05-07 09:44:15 +05:00
Nelson Benítez León
13506e36aa FileChooserButton: query 'display name' also for unbookmarked files
Do also the async file info query for remote files when they
are not bookmarked, because otherwise "None" will be shown as
file name (and fallback text generic icon will be used).

The remote file was already browsed by the file chooser
instance when selecting it, so querying the display name
again should be using gio cache and not be slow.

Even if it's were slow it's better than showing 'None'
which makes it seem as if nothing was selected.

Fixes #1966
2020-04-19 16:59:33 -04:00
1103 changed files with 151860 additions and 47509 deletions

View File

@@ -27,14 +27,41 @@ variables:
style-check-diff:
extends: .only-default
image: registry.gitlab.gnome.org/gnome/gtk/fedora:v16
image: registry.gitlab.gnome.org/gnome/gtk/fedora:v17
stage: .pre
allow_failure: true
script:
- .gitlab-ci/run-style-check-diff.sh
.build-fedora-default:
image: registry.gitlab.gnome.org/gnome/gtk/fedora:v17
artifacts:
when: always
reports:
junit:
- "${CI_PROJECT_DIR}/_build/report-x11.xml"
- "${CI_PROJECT_DIR}/_build/report-wayland.xml"
- "${CI_PROJECT_DIR}/_build/report-broadway.xml"
name: "gtk-${CI_COMMIT_REF_NAME}"
paths:
- "${CI_PROJECT_DIR}/_build/meson-logs"
- "${CI_PROJECT_DIR}/_build/report*.xml"
- "${CI_PROJECT_DIR}/_build/report*.html"
- "${CI_PROJECT_DIR}/_build/testsuite/reftests/output/*/*.png"
- "${CI_PROJECT_DIR}/_build/testsuite/gsk/compare/*/*/*.png"
- "${CI_PROJECT_DIR}/_build/testsuite/css/output/*/*.syscap"
cache:
key: "$CI_JOB_NAME"
paths:
- _ccache/
- subprojects/gdk-pixbuf/
- subprojects/glib/
- subprojects/graphene/
- subprojects/libepoxy/
- subprojects/pango/
fedora-x86_64:
image: registry.gitlab.gnome.org/gnome/gtk/fedora:v16
extends: .build-fedora-default
stage: build
variables:
EXTRA_MESON_FLAGS: "--buildtype=debug --default-library=both"
@@ -47,26 +74,12 @@ fedora-x86_64:
-Dprofiler=true
_build
- ninja -C _build
- .gitlab-ci/run-tests.sh _build
artifacts:
when: always
reports:
junit:
- "${CI_PROJECT_DIR}/_build/report.xml"
name: "gtk-${CI_COMMIT_REF_NAME}"
paths:
- "${CI_PROJECT_DIR}/_build/meson-logs"
- "${CI_PROJECT_DIR}/_build/report.xml"
- "${CI_PROJECT_DIR}/_build/report.html"
- "${CI_PROJECT_DIR}/_build/testsuite/reftests/output/*.png"
- "${CI_PROJECT_DIR}/_build/testsuite/gsk/compare/*/*.png"
- "${CI_PROJECT_DIR}/_build/testsuite/css/output/*.syscap"
cache:
key: "$CI_JOB_NAME"
<<: *cache-paths
- .gitlab-ci/run-tests.sh _build x11
- .gitlab-ci/run-tests.sh _build wayland
- .gitlab-ci/run-tests.sh _build broadway
release-build:
image: registry.gitlab.gnome.org/gnome/gtk/fedora:v16
extends: .build-fedora-default
stage: build
variables:
EXTRA_MESON_FLAGS: "--buildtype=release"
@@ -78,25 +91,9 @@ release-build:
-Dvulkan=yes
_build
- ninja -C _build
- .gitlab-ci/run-tests.sh _build
artifacts:
when: always
reports:
junit:
- "${CI_PROJECT_DIR}/_build/report.xml"
name: "gtk-${CI_COMMIT_REF_NAME}"
paths:
- "${CI_PROJECT_DIR}/_build/meson-logs"
- "${CI_PROJECT_DIR}/_build/report.xml"
- "${CI_PROJECT_DIR}/_build/report.html"
- "${CI_PROJECT_DIR}/_build/testsuite/reftests/output/*.png"
- "${CI_PROJECT_DIR}/_build/testsuite/gsk/compare/*/*.png"
- "${CI_PROJECT_DIR}/_build/testsuite/css/output/*.syscap"
cache:
key: "$CI_JOB_NAME"
<<: *cache-paths
- .gitlab-ci/run-tests.sh _build x11
.mingw-defaults: &mingw-defaults
.mingw-defaults:
stage: build
tags:
- win32-ps
@@ -105,15 +102,21 @@ release-build:
- C:\msys64\usr\bin\bash -lc "bash -x ./.gitlab-ci/test-msys2.sh"
cache:
key: "$CI_JOB_NAME"
<<: *cache-paths
paths:
- _ccache/
- subprojects/gdk-pixbuf/
- subprojects/glib/
- subprojects/graphene/
- subprojects/libepoxy/
- subprojects/pango/
msys2-mingw32:
extends: .mingw-defaults
variables:
MSYSTEM: "MINGW32"
CHERE_INVOKING: "yes"
<<: *mingw-defaults
.flatpak-defaults: &flatpak-defaults
.flatpak-defaults:
image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:master
stage: flatpak
allow_failure: true
@@ -127,45 +130,45 @@ msys2-mingw32:
- bash -x ./.gitlab-ci/flatpak-build.sh "${APPID}"
# Manual jobs, for branches and MRs
.flatpak-manual: &flatpak-manual
<<: *flatpak-defaults
.flatpak-manual:
extends: .flatpak-defaults
when: manual
# Only build Flatpak bundles automatically on master
.flatpak-master: &flatpak-master
<<: *flatpak-defaults
.flatpak-master:
extends: .flatpak-defaults
only:
- master
flatpak-manual:demo:
extends: .flatpak-manual
variables:
APPID: org.gtk.Demo4
<<: *flatpak-manual
flatpak-master:demo:
extends: .flatpak-master
variables:
APPID: org.gtk.Demo4
<<: *flatpak-master
flatpak-manual:widget-factory:
extends: .flatpak-manual
variables:
APPID: org.gtk.WidgetFactory4
<<: *flatpak-manual
flatpak-master:widget-factory:
extends: .flatpak-master
variables:
APPID: org.gtk.WidgetFactory4
<<: *flatpak-master
flatpak-manual:icon-browser:
extends: .flatpak-manual
variables:
APPID: org.gtk.IconBrowser4
<<: *flatpak-manual
flatpak-master:icon-browser:
extends: .flatpak-master
variables:
APPID: org.gtk.IconBrowser4
<<: *flatpak-master
static-scan:
image: registry.gitlab.gnome.org/gnome/gtk/fedora:v16
@@ -181,7 +184,7 @@ static-scan:
allow_failure: true
reference:
image: registry.gitlab.gnome.org/gnome/gtk/fedora:v16
image: registry.gitlab.gnome.org/gnome/gtk/fedora-docs:v19
stage: docs
variables:
EXTRA_MESON_FLAGS: "--buildtype=release"

View File

@@ -0,0 +1,88 @@
FROM fedora:31
RUN dnf -y install \
adwaita-icon-theme \
atk-devel \
at-spi2-atk-devel \
avahi-gobject-devel \
cairo-devel \
cairo-gobject-devel \
ccache \
clang \
clang-analyzer \
colord-devel \
cups-devel \
dbus-daemon \
dbus-x11 \
dejavu-sans-mono-fonts \
desktop-file-utils \
diffutils \
elfutils-libelf-devel \
fribidi-devel \
gcc \
gcc-c++ \
gdk-pixbuf2-devel \
gdk-pixbuf2-modules \
gettext \
git \
glib2-devel \
glib2-static \
glibc-devel \
glibc-headers \
gobject-introspection-devel \
graphene-devel \
gstreamer1-devel \
gstreamer1-plugins-good \
gstreamer1-plugins-bad-free-devel \
gstreamer1-plugins-base-devel \
gtk-doc \
hicolor-icon-theme \
iso-codes \
itstool \
json-glib-devel \
lcov \
libattr-devel \
libepoxy-devel \
libffi-devel \
libmount-devel \
librsvg2 \
libselinux-devel \
libXcomposite-devel \
libXcursor-devel \
libXcursor-devel \
libXdamage-devel \
libXfixes-devel \
libXi-devel \
libXinerama-devel \
libxkbcommon-devel \
libXrandr-devel \
libXrender-devel \
libXtst-devel \
libxslt \
mesa-dri-drivers \
mesa-libEGL-devel \
mesa-libwayland-egl-devel \
ninja-build \
pango-devel \
pcre-devel \
pcre-static \
python3 \
python3-jinja2 \
python3-pip \
python3-pygments \
python3-wheel \
redhat-rpm-config \
sassc \
sysprof-devel \
systemtap-sdt-devel \
vulkan-devel \
wayland-devel \
wayland-protocols-devel \
weston \
weston-libs \
which \
xorg-x11-server-Xvfb \
&& dnf clean all
RUN pip3 install meson==0.53.1

View File

@@ -0,0 +1,12 @@
FROM registry.gitlab.gnome.org/gnome/gtk/fedora-base:v19
RUN dnf -y install pandoc
ARG HOST_USER_ID=5555
ENV HOST_USER_ID ${HOST_USER_ID}
RUN useradd -u $HOST_USER_ID -ms /bin/bash user
USER user
WORKDIR /home/user
ENV LANG C.UTF-8

View File

@@ -1,88 +1,4 @@
FROM fedora:31
RUN dnf -y install \
adwaita-icon-theme \
atk-devel \
at-spi2-atk-devel \
avahi-gobject-devel \
cairo-devel \
cairo-gobject-devel \
ccache \
clang \
clang-analyzer \
colord-devel \
cups-devel \
dbus-daemon \
dbus-x11 \
dejavu-sans-mono-fonts \
desktop-file-utils \
diffutils \
elfutils-libelf-devel \
fribidi-devel \
gcc \
gcc-c++ \
gdk-pixbuf2-devel \
gdk-pixbuf2-modules \
gettext \
git \
glib2-devel \
glib2-static \
glibc-devel \
glibc-headers \
gobject-introspection-devel \
graphene-devel \
gstreamer1-devel \
gstreamer1-plugins-good \
gstreamer1-plugins-bad-free-devel \
gstreamer1-plugins-base-devel \
gtk-doc \
hicolor-icon-theme \
iso-codes \
itstool \
json-glib-devel \
lcov \
libattr-devel \
libepoxy-devel \
libffi-devel \
libmount-devel \
librsvg2 \
libselinux-devel \
libXcomposite-devel \
libXcursor-devel \
libXcursor-devel \
libXdamage-devel \
libXfixes-devel \
libXi-devel \
libXinerama-devel \
libxkbcommon-devel \
libXrandr-devel \
libXrender-devel \
libXtst-devel \
libxslt \
mesa-dri-drivers \
mesa-libEGL-devel \
mesa-libwayland-egl-devel \
ninja-build \
pango-devel \
pcre-devel \
pcre-static \
python3 \
python3-jinja2 \
python3-pip \
python3-pygments \
python3-wheel \
redhat-rpm-config \
sassc \
sysprof-devel \
systemtap-sdt-devel \
vulkan-devel \
wayland-devel \
wayland-protocols-devel \
which \
xorg-x11-server-Xvfb \
&& dnf clean all
RUN pip3 install meson==0.53.1
FROM registry.gitlab.gnome.org/gnome/gtk/fedora-base:v19
ARG HOST_USER_ID=5555
ENV HOST_USER_ID ${HOST_USER_ID}

View File

@@ -138,12 +138,13 @@ ul.images li {
</head>
<body>
<header>
<h1>{{ report.project_name }}/{{ report.branch_name }} :: Test Reports</h1>
<h1>{{ report.project_name }}/{{ report.backend }}/{{ report.branch_name }} :: Test Reports</h1>
</header>
<article>
<section>
<div class="report-meta">
<p><strong>Backend:</strong> {{ report.backend }}</p>
<p><strong>Branch:</strong> {{ report.branch_name }}</p>
<p><strong>Date:</strong> <time datetime="{{ report.date.isoformat() }}">{{ report.locale_date }}</time></p>
{% if report.job_id %}<p><strong>Job ID:</strong> {{ report.job_id }}</p>{% endif %}
@@ -259,6 +260,9 @@ aparser = argparse.ArgumentParser(description='Turns a Meson test log into an HT
aparser.add_argument('--project-name', metavar='NAME',
help='The project name',
default='Unknown')
aparser.add_argument('--backend', metavar='NAME',
help='The used backend',
default='unknown')
aparser.add_argument('--job-id', metavar='ID',
help='The job ID for the report',
default=None)
@@ -319,6 +323,7 @@ report = {}
report['date'] = datetime.datetime.utcnow()
report['locale_date'] = report['date'].strftime("%c")
report['project_name'] = args.project_name
report['backend'] = args.backend
report['job_id'] = args.job_id
report['branch_name'] = args.branch
report['total_successes'] = 0

View File

@@ -19,6 +19,9 @@ aparser = argparse.ArgumentParser(description='Turns a Meson test log into a JUn
aparser.add_argument('--project-name', metavar='NAME',
help='The project name',
default='unknown')
aparser.add_argument('--backend', metavar='NAME',
help='The used backend',
default='unknown')
aparser.add_argument('--job-id', metavar='ID',
help='The job ID for the report',
default='Unknown')
@@ -92,18 +95,18 @@ for name, units in suites.items():
for unit in successes:
testcase = ET.SubElement(testsuite, 'testcase')
testcase.set('classname', '{}/{}'.format(args.project_name, unit['suite']))
testcase.set('name', unit['name'])
testcase.set('name', '{}/{}'.format(args.backend, unit['name']))
testcase.set('time', str(unit['duration']))
for unit in failures:
testcase = ET.SubElement(testsuite, 'testcase')
testcase.set('classname', '{}/{}'.format(args.project_name, unit['suite']))
testcase.set('name', unit['name'])
testcase.set('name', '{}/{}'.format(args.backend, unit['name']))
testcase.set('time', str(unit['duration']))
failure = ET.SubElement(testcase, 'failure')
failure.set('classname', '{}/{}'.format(args.project_name, unit['suite']))
failure.set('name', unit['name'])
testcase.set('name', '{}/{}'.format(args.backend, unit['name']))
failure.set('type', 'error')
failure.text = unit['stdout']

View File

@@ -81,7 +81,7 @@ fi
if [ -z $base_version ]; then
base_version="latest"
else
elif [ $base_version != "latest" ]; then
base_version="v$base_version"
fi
@@ -95,7 +95,7 @@ if [ ! -x "$(command -v docker)" ] || [ docker --help |& grep -q podman ]; then
else
echo "Using: Docker"
format=""
CMD="sudo socker"
CMD="sudo docker"
fi
REGISTRY="registry.gitlab.gnome.org"

View File

@@ -5,30 +5,75 @@ set +e
srcdir=$( pwd )
builddir=$1
backend=$2
export GDK_BACKEND=x11
xvfb-run -a -s "-screen 0 1024x768x24" \
meson test -C ${builddir} \
case "${backend}" in
x11)
xvfb-run -a -s "-screen 0 1024x768x24" \
meson test -C ${builddir} \
--print-errorlogs \
--setup=${backend} \
--suite=gtk \
--no-suite=gtk:a11y
--no-suite=gtk:a11y \
--no-suite=gsk-compare-broadway
# Store the exit code for the CI run, but always
# generate the reports
exit_code=$?
# Store the exit code for the CI run, but always
# generate the reports
exit_code=$?
;;
wayland)
export XDG_RUNTIME_DIR="$(mktemp -p $(pwd) -d xdg-runtime-XXXXXX)"
weston --backend=headless-backend.so --socket=wayland-5 --idle-time=0 &
compositor=$!
export WAYLAND_DISPLAY=wayland-5
meson test -C ${builddir} \
--print-errorlogs \
--setup=${backend} \
--suite=gtk \
--no-suite=gtk:a11y \
--no-suite=gsk-compare-broadway
exit_code=$?
kill ${compositor}
;;
broadway)
export XDG_RUNTIME_DIR="$(mktemp -p $(pwd) -d xdg-runtime-XXXXXX)"
${builddir}/gdk/broadway/gtk4-broadwayd :5 &
server=$!
export BROADWAY_DISPLAY=:5
meson test -C ${builddir} \
--print-errorlogs \
--setup=${backend} \
--suite=gtk \
--no-suite=gtk:a11y \
--no-suite=gsk-compare-opengl
# don't let Broadway failures fail the run, for now
exit_code=0
kill ${server}
;;
esac
cd ${builddir}
$srcdir/.gitlab-ci/meson-junit-report.py \
--project-name=gtk \
--backend=${backend} \
--job-id="${CI_JOB_NAME}" \
--output=report.xml \
meson-logs/testlog.json
--output=report-${backend}.xml \
meson-logs/testlog-${backend}.json
$srcdir/.gitlab-ci/meson-html-report.py \
--project-name=gtk \
--backend=${backend} \
--job-id="${CI_JOB_NAME}" \
--reftest-output-dir="testsuite/reftests/output" \
--output=report.html \
meson-logs/testlog.json
--reftest-output-dir="testsuite/reftests/output/${backend}" \
--output=report-${backend}.html \
meson-logs/testlog-${backend}.json
exit $exit_code

View File

@@ -34,8 +34,11 @@ pacman --noconfirm -S --needed \
mingw-w64-$MSYS2_ARCH-shared-mime-info
# https://gitlab.gnome.org/GNOME/gtk/issues/2243
wget "https://gitlab.gnome.org/creiter/gitlab-ci-win32-runner-v2/raw/master/pango/mingw-w64-$MSYS2_ARCH-pango-1.44.7-1-any.pkg.tar.xz"
pacman --noconfirm -U "mingw-w64-$MSYS2_ARCH-pango-1.44.7-1-any.pkg.tar.xz"
wget "https://gitlab.gnome.org/creiter/gitlab-ci-win32-runner-v2/raw/master/pango/mingw-w64-$MSYS2_ARCH-pango-git-1.44.7.90.ge48ae523-1-any.pkg.tar.zst"
pacman --noconfirm -U "mingw-w64-$MSYS2_ARCH-pango-git-1.44.7.90.ge48ae523-1-any.pkg.tar.zst"
# https://github.com/msys2/MINGW-packages/pull/6465
pacman --noconfirm -S --needed mingw-w64-$MSYS2_ARCH-brotli
mkdir -p _ccache
export CCACHE_BASEDIR="$(pwd)"

89
NEWS
View File

@@ -1,3 +1,92 @@
Overview of Changes in GTK 3.98.4
=================================
* Themes
- Refine menu styling
- Tweak visible focus behavior
- HighConstrast: Add public colors
- HighContrast: Fix scale borders
* CSS:
- Drop the nonstandard -gtk-icon-theme property
- Add a system_setting_changed vfunc to propagate global changes
* Untangle titlebars from windows:
- Add a GtkWindowControls widget
- Add a GtkWindowHandle widget
- Add actions for window menu items
- Remove app menu fallback from GtkHeaderBar
- Remove title and subtitle properties from GtkHeaderBar,
rename custom-title to title-widget
* GtkWidget
- Add a focusable property
* GtkPopover:
- Fix (re-)positioning issues
* GtkStack:
- Drop the homogeneous property
- Add a use-underline property to stack pages
* GtkScale:
- Make area around the trough clickable
* GtkScrolledWindow:
- Fix kinetic scrolling
* GtkTreeView:
- Break reference cycles in unroot
* Drop GtkBin and GtkContainer. All existing GtkBin subclasses
have grown a child property with setter and getter. All
existing GtkContainer subclasses have grown widget-specific
remove (and in some cases, add) functions. <child> in ui
files continues to work as before
* Replace gtk_widget_destroy by gtk_window_destroy
* Drop the ::size-allocate signal. Use a GtkWidgetPaintable
if you need to be informed about changes to a widgets
content or size
* Remove gtk_dialog_run
* GDK:
- Wayland: Provide a builtin cursor of last resort
- Change the monitor api to use a GListModel
* GSK:
- Don't include renderer-specific headers automatically
- GL: Fix nested rounded clips
* Introspection:
- Assorted annotation fixes
* Inspector:
- Preview media resources
- Show media backend information
* gtk4-widget-factory:
- Add GtkVideo
- Add text styles
- Add a print dialog
- Add a password entry
- Improve toolbar styling
- Revamp transition effects
* gtk4-demo:
- Replace some demos
* Translation updates:
Chinese (Taiwan)
Esperanto
Japanese
Romanian
Spanish
Ukrainian
Overview of Changes in GTK 3.98.3
=================================

View File

@@ -35,6 +35,10 @@
*/
#mesondefine HAVE_DECL_ISNAN
/* Define to 1 if you have the declaration of `isnanf', and to 0 if you don't.
*/
#mesondefine HAVE_DECL_ISNANF
/* Define to 1 if you have the <dlfcn.h> header file. */
#mesondefine HAVE_DLFCN_H
@@ -146,9 +150,6 @@
/* Have the Xcursor library */
#mesondefine HAVE_XCURSOR
/* Have the XDAMAGE X extension */
#mesondefine HAVE_XDAMAGE
/* Have the XFIXES X extension */
#mesondefine HAVE_XFIXES
@@ -295,3 +296,6 @@
#mesondefine HAVE_PANGOFT
#mesondefine ISO_CODES_PREFIX
/* Define if tracker3 is available */
#mesondefine HAVE_TRACKER3

View File

@@ -317,7 +317,7 @@ save_response_cb (GtkNativeDialog *dialog,
"Saving failed");
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message_dialog),
"%s", error->message);
g_signal_connect (message_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
g_signal_connect (message_dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (message_dialog);
g_error_free (error);
}
@@ -403,7 +403,7 @@ constraint_editor_done (ConstraintEditor *editor,
g_clear_object (&old_constraint);
gtk_widget_destroy (gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_WINDOW));
gtk_window_destroy (GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_WINDOW)));
}
static void
@@ -444,7 +444,7 @@ guide_editor_done (GuideEditor *editor,
GtkConstraintGuide *guide,
ConstraintEditorWindow *win)
{
gtk_widget_destroy (gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_WINDOW));
gtk_window_destroy (GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_WINDOW)));
}
static void
@@ -487,8 +487,6 @@ constraint_editor_window_class_init (ConstraintEditorWindowClass *class)
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
g_type_ensure (CONSTRAINT_VIEW_TYPE);
object_class->finalize = constraint_editor_window_finalize;
gtk_widget_class_set_template_from_resource (widget_class,
@@ -607,8 +605,8 @@ create_widget_func (gpointer item,
gtk_widget_set_margin_bottom (label, 10);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_widget_set_hexpand (label, TRUE);
gtk_container_add (GTK_CONTAINER (row), box);
gtk_container_add (GTK_CONTAINER (box), label);
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), box);
gtk_box_append (GTK_BOX (box), label);
if (GTK_IS_CONSTRAINT (item) || GTK_IS_CONSTRAINT_GUIDE (item))
{
@@ -616,18 +614,18 @@ create_widget_func (gpointer item,
gtk_button_set_has_frame (GTK_BUTTON (button), FALSE);
g_signal_connect (button, "clicked", G_CALLBACK (row_edit), win);
g_object_set_data (G_OBJECT (row), "edit", button);
gtk_container_add (GTK_CONTAINER (box), button);
gtk_box_append (GTK_BOX (box), button);
button = gtk_button_new_from_icon_name ("edit-delete-symbolic");
gtk_button_set_has_frame (GTK_BUTTON (button), FALSE);
g_signal_connect (button, "clicked", G_CALLBACK (row_delete), win);
gtk_container_add (GTK_CONTAINER (box), button);
gtk_box_append (GTK_BOX (box), button);
}
else if (GTK_IS_WIDGET (item))
{
button = gtk_button_new_from_icon_name ("edit-delete-symbolic");
gtk_button_set_has_frame (GTK_BUTTON (button), FALSE);
g_signal_connect (button, "clicked", G_CALLBACK (row_delete), win);
gtk_container_add (GTK_CONTAINER (box), button);
gtk_box_append (GTK_BOX (box), button);
}
g_free (freeme);

View File

@@ -169,6 +169,7 @@ constraint_view_init (ConstraintView *self)
GListModel *guides;
GListModel *children;
GListModel *constraints;
GtkFilter *filter;
manager = gtk_constraint_layout_new ();
gtk_widget_set_layout_manager (GTK_WIDGET (self), manager);
@@ -176,8 +177,12 @@ constraint_view_init (ConstraintView *self)
all_children = gtk_widget_observe_children (GTK_WIDGET (self));
all_constraints = gtk_constraint_layout_observe_constraints (GTK_CONSTRAINT_LAYOUT (manager));
guides = gtk_constraint_layout_observe_guides (GTK_CONSTRAINT_LAYOUT (manager));
constraints = (GListModel *)gtk_filter_list_model_new (all_constraints, omit_internal, NULL, NULL);
children = (GListModel *)gtk_filter_list_model_new (all_children, omit_internal, NULL, NULL);
filter = gtk_custom_filter_new (omit_internal, NULL, NULL);
constraints = (GListModel *)gtk_filter_list_model_new (all_constraints, filter);
g_object_unref (filter);
filter = gtk_custom_filter_new (omit_internal, NULL, NULL);
children = (GListModel *)gtk_filter_list_model_new (all_children, filter);
g_object_unref (filter);
list = g_list_store_new (G_TYPE_LIST_MODEL);
g_list_store_append (list, children);

View File

@@ -23,6 +23,7 @@
#define CONSTRAINT_VIEW_TYPE (constraint_view_get_type ())
G_MODULE_EXPORT
G_DECLARE_FINAL_TYPE (ConstraintView, constraint_view, CONSTRAINT, VIEW, GtkWidget)
ConstraintView * constraint_view_new (void);

View File

@@ -184,58 +184,6 @@ max_input (GtkSpinButton *spin_button,
return FALSE;
}
static gboolean
min_output (GtkSpinButton *spin_button)
{
GtkAdjustment *adjustment;
double value;
GtkWidget *box, *text;
adjustment = gtk_spin_button_get_adjustment (spin_button);
value = gtk_adjustment_get_value (adjustment);
box = gtk_widget_get_first_child (GTK_WIDGET (spin_button));
text = gtk_widget_get_first_child (box);
if (value == 0.0)
{
gtk_editable_set_text (GTK_EDITABLE (spin_button), "");
gtk_text_set_placeholder_text (GTK_TEXT (text), "unset");
return TRUE;
}
else
{
gtk_text_set_placeholder_text (GTK_TEXT (text), "");
return FALSE;
}
}
static gboolean
max_output (GtkSpinButton *spin_button)
{
GtkAdjustment *adjustment;
double value;
GtkWidget *box, *text;
adjustment = gtk_spin_button_get_adjustment (spin_button);
value = gtk_adjustment_get_value (adjustment);
box = gtk_widget_get_first_child (GTK_WIDGET (spin_button));
text = gtk_widget_get_first_child (box);
if (value == (double)G_MAXINT)
{
gtk_editable_set_text (GTK_EDITABLE (spin_button), "");
gtk_text_set_placeholder_text (GTK_TEXT (text), "unset");
return TRUE;
}
else
{
gtk_text_set_placeholder_text (GTK_TEXT (text), "");
return FALSE;
}
}
static void
guide_editor_constructed (GObject *object)
{
@@ -244,16 +192,12 @@ guide_editor_constructed (GObject *object)
guide_strength_combo (editor->strength);
g_signal_connect (editor->min_width, "input", G_CALLBACK (min_input), NULL);
g_signal_connect (editor->min_width, "output", G_CALLBACK (min_output), NULL);
g_signal_connect (editor->min_height, "input", G_CALLBACK (min_input), NULL);
g_signal_connect (editor->min_height, "output", G_CALLBACK (min_output), NULL);
g_signal_connect (editor->max_width, "input", G_CALLBACK (max_input), NULL);
g_signal_connect (editor->max_width, "output", G_CALLBACK (max_output), NULL);
g_signal_connect (editor->max_height, "input", G_CALLBACK (max_input), NULL);
g_signal_connect (editor->max_height, "output", G_CALLBACK (max_output), NULL);
if (editor->guide)
{

View File

@@ -47,7 +47,7 @@ show_action_dialog (GSimpleAction *action)
name);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
}
@@ -120,7 +120,7 @@ open_response_cb (GtkNativeDialog *dialog,
"Error loading file: \"%s\"",
error->message);
g_signal_connect (message_dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (message_dialog);
g_error_free (error);
}
@@ -234,7 +234,7 @@ activate_quit (GSimpleAction *action,
win = list->data;
next = list->next;
gtk_widget_destroy (GTK_WIDGET (win));
gtk_window_destroy (GTK_WINDOW (win));
list = next;
}
@@ -328,19 +328,14 @@ static void
startup (GApplication *app)
{
GtkBuilder *builder;
GMenuModel *appmenu;
GMenuModel *menubar;
G_APPLICATION_CLASS (demo_application_parent_class)->startup (app);
builder = gtk_builder_new ();
gtk_builder_add_from_resource (builder, "/application_demo/menus.ui", NULL);
appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
menubar = (GMenuModel *)gtk_builder_get_object (builder, "menubar");
gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
gtk_application_set_menubar (GTK_APPLICATION (app), menubar);
gtk_application_set_menubar (GTK_APPLICATION (app),
G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
g_object_unref (builder);
}
@@ -353,6 +348,7 @@ create_window (GApplication *app,
window = (DemoApplicationWindow *)g_object_new (demo_application_window_get_type (),
"application", app,
"show-menubar", TRUE,
NULL);
if (content)
gtk_text_buffer_set_text (window->buffer, content, -1);

View File

@@ -31,12 +31,7 @@ on_name_vanished (GDBusConnection *connection,
if (!name_seen)
return;
if (placeholder)
{
gtk_widget_destroy (placeholder);
g_object_unref (placeholder);
placeholder = NULL;
}
g_clear_object (&placeholder);
}
#ifdef G_OS_WIN32

View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="appmenu">
<section>
<item>
<attribute name="label" translatable="yes">About</attribute>
<attribute name="action">app.about</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Quit</attribute>
<attribute name="action">app.quit</attribute>
<attribute name="accel">&lt;Control&gt;q</attribute>
</item>
</section>
</menu>
</interface>

View File

@@ -26,7 +26,7 @@ apply_changes_gradually (gpointer data)
else
{
/* Close automatically once changes are fully applied. */
gtk_widget_destroy (data);
gtk_window_destroy (GTK_WINDOW (data));
return G_SOURCE_REMOVE;
}
}
@@ -41,7 +41,7 @@ on_assistant_apply (GtkWidget *widget, gpointer data)
static void
on_assistant_close_cancel (GtkWidget *widget, gpointer data)
{
gtk_widget_destroy (widget);
gtk_window_destroy (GTK_WINDOW (widget));
}
static void
@@ -95,12 +95,12 @@ create_page1 (GtkWidget *assistant)
gtk_widget_set_margin_bottom (box, 12);
label = gtk_label_new ("You must fill out this entry to continue:");
gtk_container_add (GTK_CONTAINER (box), label);
gtk_box_append (GTK_BOX (box), label);
entry = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
gtk_widget_set_valign (entry, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (box), entry);
gtk_box_append (GTK_BOX (box), entry);
g_signal_connect (G_OBJECT (entry), "changed",
G_CALLBACK (on_entry_changed), assistant);
@@ -123,7 +123,7 @@ create_page2 (GtkWidget *assistant)
checkbutton = gtk_check_button_new_with_label ("This is optional data, you may continue "
"even if you do not check this");
gtk_widget_set_valign (checkbutton, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (box), checkbutton);
gtk_box_append (GTK_BOX (box), checkbutton);
gtk_assistant_append_page (GTK_ASSISTANT (assistant), box);
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), box, TRUE);
@@ -178,8 +178,7 @@ do_assistant (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (assistant),
gtk_widget_get_display (do_widget));
g_signal_connect (assistant, "destroy",
G_CALLBACK (gtk_widget_destroyed), &assistant);
g_object_add_weak_pointer (G_OBJECT (assistant), (gpointer *)&assistant);
create_page1 (assistant);
create_page2 (assistant);
@@ -199,7 +198,7 @@ do_assistant (GtkWidget *do_widget)
if (!gtk_widget_get_visible (assistant))
gtk_widget_show (assistant);
else
gtk_widget_destroy (assistant);
gtk_window_destroy (GTK_WINDOW (assistant));
return assistant;
}

247
demos/gtk-demo/award.c Normal file
View File

@@ -0,0 +1,247 @@
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#include "award.h"
struct _GtkAward
{
GObject parent;
char *explanation;
char *name;
char *title;
GDateTime *granted; /* or NULL if not granted */
};
enum {
PROP_0,
PROP_EXPLANATION,
PROP_NAME,
PROP_TITLE,
PROP_GRANTED,
N_PROPS,
};
static GParamSpec *properties[N_PROPS] = { NULL, };
G_DEFINE_TYPE (GtkAward, gtk_award, G_TYPE_OBJECT)
static void
gtk_award_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkAward *self = GTK_AWARD (object);
switch (prop_id)
{
case PROP_EXPLANATION:
self->explanation = g_value_dup_string (value);
break;
case PROP_NAME:
self->name = g_value_dup_string (value);
break;
case PROP_TITLE:
self->title = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_award_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkAward *self = GTK_AWARD (object);
switch (prop_id)
{
case PROP_EXPLANATION:
g_value_set_string (value, self->explanation);
break;
case PROP_NAME:
g_value_set_string (value, self->name);
break;
case PROP_TITLE:
g_value_set_string (value, self->title);
break;
case PROP_GRANTED:
g_value_set_boxed (value, self->granted);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_award_dispose (GObject *object)
{
GtkAward *self = GTK_AWARD (object);
g_clear_pointer (&self->name, g_free);
g_clear_pointer (&self->title, g_free);
g_clear_pointer (&self->granted, g_date_time_unref);
G_OBJECT_CLASS (gtk_award_parent_class)->dispose (object);
}
static void
gtk_award_class_init (GtkAwardClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
gobject_class->set_property = gtk_award_set_property;
gobject_class->get_property = gtk_award_get_property;
gobject_class->dispose = gtk_award_dispose;
properties[PROP_EXPLANATION] =
g_param_spec_string ("explanation",
"Explanation",
"How to get the title",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
properties[PROP_NAME] =
g_param_spec_string ("name",
"Name",
"internal name of the award",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
properties[PROP_TITLE] =
g_param_spec_string ("title",
"Title",
"user-visible title",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
properties[PROP_GRANTED] =
g_param_spec_boxed ("granted",
"Granted",
"Timestamp the award was granted or NULL if not granted yet",
G_TYPE_DATE_TIME,
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
static void
gtk_award_init (GtkAward *self)
{
}
GListModel *
gtk_award_get_list (void)
{
static GListModel *list = NULL;
if (list == NULL)
{
GtkBuilder *builder;
g_type_ensure (GTK_TYPE_AWARD);
builder = gtk_builder_new_from_resource ("/awards.ui");
list = G_LIST_MODEL (gtk_builder_get_object (builder, "list"));
g_object_ref (list);
g_object_unref (builder);
}
return g_object_ref (list);
}
const char *
gtk_award_get_name (GtkAward *award)
{
return award->name;
}
const char *
gtk_award_get_title (GtkAward *award)
{
return award->title;
}
GDateTime *
gtk_award_get_granted (GtkAward *award)
{
return award->granted;
}
GtkAward *
award_find (const char *name)
{
GListModel *list;
GtkAward *self;
guint i;
list = gtk_award_get_list ();
g_object_unref (list);
for (i = 0; i < g_list_model_get_n_items (list); i++)
{
self = g_list_model_get_item (list, i);
g_object_unref (self);
if (g_ascii_strcasecmp (name, self->name) == 0)
return self;
}
return NULL;
}
void
award (const char *name)
{
GtkAward *self;
GNotification *notification;
self = award_find (name);
if (self == NULL)
{
g_warning ("Did not find award \"%s\"", name);
return;
}
if (self->granted)
return;
self->granted = g_date_time_new_now_utc ();
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_GRANTED]);
notification = g_notification_new ("You won an award!");
g_notification_set_body (notification, self->title);
g_application_send_notification (g_application_get_default (), NULL, notification);
g_object_unref (notification);
}

18
demos/gtk-demo/award.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef __AWARD_H__
#define __AWARD_H__
#include <gtk/gtk.h>
#define GTK_TYPE_AWARD (gtk_award_get_type ())
G_DECLARE_FINAL_TYPE (GtkAward, gtk_award, GTK, AWARD, GObject)
GListModel * gtk_award_get_list (void);
const char * gtk_award_get_name (GtkAward *award);
const char * gtk_award_get_title (GtkAward *award);
GDateTime * gtk_award_get_granted (GtkAward *award);
void award (const char *name);
#endif /* __AWARD_H__ */

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk40">
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="label" bind-source="GtkListItem" bind-property="position"></property>
<property name="margin">6</property>
</object>
</property>
</template>
</interface>

89
demos/gtk-demo/awards.ui Normal file
View File

@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GListStore" id="list">
<property name="item-type">GtkAward</property>
<child>
<object class="GtkAward">
<property name="name">demo-inspector</property>
<!-- Transformers -->
<property name="title" translatable="yes">You got a high-rise double-pump carburetor.</property>
<property name="explanation" translatable="yes">Launch the inspector</property>
</object>
</child>
<child>
<object class="GtkAward">
<property name="name">demo-start</property>
<!-- The Matrix -->
<property name="title" translatable="yes">After this, there is no turning back.</property>
<property name="explanation" translatable="yes">Start gtk-demo</property>
</object>
</child>
<child>
<object class="GtkAward">
<property name="name">listbox-reshare</property>
<!-- Mean Girls -->
<property name="title" translatable="yes">Trying to make fetch happen</property>
<property name="explanation" translatable="yes">Reshare a tweet</property>
</object>
</child>
<child>
<object class="GtkAward">
<property name="name">listbox-100th-row</property>
<!-- Aladdin -->
<property name="title" translatable="yes">The ever impressive, long contained, often imitated, but never duplicated Genie of the lamp.</property>
<property name="explanation" translatable="yes">Select a 100th row in a list</property>
</object>
</child>
<child>
<object class="GtkAward">
<property name="name">password-best</property>
<!-- Spaceballs -->
<property name="title" translatable="yes">I've got the same combination on my luggage!</property>
<property name="explanation" translatable="yes">Use "12345" as the password</property>
</object>
</child>
<child>
<object class="GtkAward">
<property name="name">password-correct</property>
<!-- Stanley Parable -->
<property name="title" translatable="yes">Night Shark 1-1-5</property>
<property name="explanation" translatable="yes">Correctly enter a password</property>
</object>
</child>
<child>
<object class="GtkAward">
<property name="name">puzzle-give-up</property>
<!-- Pretty Woman -->
<property name="title" translatable="yes">Big Mistake. Big. Huge!</property>
<property name="explanation" translatable="yes">Close the puzzle without finishing it</property>
</object>
</child>
<child>
<object class="GtkAward">
<property name="name">puzzle-solve</property>
<!-- The Incredibles -->
<property name="title" translatable="yes">That was totally wicked!</property>
<property name="explanation" translatable="yes">Solve a puzzle</property>
</object>
</child>
<child>
<object class="GtkAward">
<property name="name">puzzle-solve-animated</property>
<!-- The Phantom Menace -->
<property name="title" translatable="yes">A surprise to be sure but a welcome one.</property>
<property name="explanation" translatable="yes">Solve an animated puzzle</property>
</object>
</child>
<child>
<object class="GtkAward">
<property name="name">puzzle-solve-large</property>
<!-- Portal -->
<property name="title" translatable="yes">Science isn't about WHY. It's about WHY NOT?!</property>
<property name="explanation" translatable="yes">Solve a puzzle with at least 20 pieces</property>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,48 @@
/* Awards
*
* This demo demonstrates how to use lists to show the awards you have collected
* while exploring this demo.
*
*/
#include <gtk/gtk.h>
/* Include the header for accessing the awards */
#include "award.h"
static GtkWidget *window = NULL;
GtkWidget *
do_awardview (GtkWidget *do_widget)
{
if (!window)
{
GtkWidget *sw, *listview;
GListModel *list;
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Awards");
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &window);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_window_set_child (GTK_WINDOW (window), sw);
listview = gtk_list_view_new_with_factory (
gtk_builder_list_item_factory_new_from_resource (NULL, "/awardview/awardlistitem.ui"));
list = gtk_award_get_list ();
gtk_list_view_set_model (GTK_LIST_VIEW (listview), list);
g_object_unref (list);
gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -12,7 +12,7 @@ quit_activate (GSimpleAction *action,
{
GtkWidget *window = user_data;
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
}
static void
@@ -26,8 +26,10 @@ about_activate (GSimpleAction *action,
builder = g_object_get_data (G_OBJECT (window), "builder");
about_dlg = GTK_WIDGET (gtk_builder_get_object (builder, "aboutdialog1"));
gtk_dialog_run (GTK_DIALOG (about_dlg));
gtk_widget_hide (about_dlg);
gtk_window_set_transient_for (GTK_WINDOW (about_dlg), GTK_WINDOW (window));
gtk_window_set_hide_on_close (GTK_WINDOW (about_dlg), TRUE);
g_signal_connect (about_dlg, "response", G_CALLBACK (gtk_widget_hide), NULL);
gtk_widget_show (about_dlg);
}
static void
@@ -74,21 +76,20 @@ do_builder (GtkWidget *do_widget)
window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
actions = (GActionGroup*)g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP (actions),
win_entries, G_N_ELEMENTS (win_entries),
window);
gtk_widget_insert_action_group (window, "win", actions);
g_object_set_data_full (G_OBJECT(window), "builder", builder, g_object_unref);
g_object_unref (builder);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -69,7 +69,7 @@ paste_received (GObject *source_object,
"Could not paste text: %s",
error->message);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
g_error_free (error);
@@ -108,9 +108,7 @@ do_clipboard (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Clipboard");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_margin_start (vbox, 8);
@@ -122,72 +120,72 @@ do_clipboard (GtkWidget *do_widget)
label = gtk_label_new ("\"Copy\" will copy the text\nin the entry to the clipboard");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
gtk_widget_set_margin_start (hbox, 8);
gtk_widget_set_margin_end (hbox, 8);
gtk_widget_set_margin_top (hbox, 8);
gtk_widget_set_margin_bottom (hbox, 8);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_box_append (GTK_BOX (vbox), hbox);
/* Create the first entry */
entry = gtk_entry_new ();
gtk_container_add (GTK_CONTAINER (hbox), entry);
gtk_box_append (GTK_BOX (hbox), entry);
/* Create the button */
button = gtk_button_new_with_mnemonic (_("_Copy"));
gtk_container_add (GTK_CONTAINER (hbox), button);
gtk_box_append (GTK_BOX (hbox), button);
g_signal_connect (button, "clicked",
G_CALLBACK (copy_button_clicked), entry);
label = gtk_label_new ("\"Paste\" will paste the text from the clipboard to the entry");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
gtk_widget_set_margin_start (hbox, 8);
gtk_widget_set_margin_end (hbox, 8);
gtk_widget_set_margin_top (hbox, 8);
gtk_widget_set_margin_bottom (hbox, 8);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_box_append (GTK_BOX (vbox), hbox);
/* Create the second entry */
entry = gtk_entry_new ();
gtk_container_add (GTK_CONTAINER (hbox), entry);
gtk_box_append (GTK_BOX (hbox), entry);
/* Create the button */
button = gtk_button_new_with_mnemonic (_("_Paste"));
gtk_container_add (GTK_CONTAINER (hbox), button);
gtk_box_append (GTK_BOX (hbox), button);
g_signal_connect (button, "clicked",
G_CALLBACK (paste_button_clicked), entry);
label = gtk_label_new ("Images can be transferred via the clipboard, too");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
gtk_widget_set_margin_start (hbox, 8);
gtk_widget_set_margin_end (hbox, 8);
gtk_widget_set_margin_top (hbox, 8);
gtk_widget_set_margin_bottom (hbox, 8);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_box_append (GTK_BOX (vbox), hbox);
/* Create the first image */
image = demo_image_new ("dialog-warning");
gtk_container_add (GTK_CONTAINER (hbox), image);
gtk_box_append (GTK_BOX (hbox), image);
/* Create the second image */
image = demo_image_new ("process-stop");
gtk_container_add (GTK_CONTAINER (hbox), image);
gtk_box_append (GTK_BOX (hbox), image);
/* Create the third image */
image = demo_image_new ("weather-clear");
gtk_container_add (GTK_CONTAINER (hbox), image);
gtk_box_append (GTK_BOX (hbox), image);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

File diff suppressed because it is too large Load Diff

View File

@@ -315,9 +315,7 @@ do_combobox (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Combo Boxes");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
gtk_widget_set_margin_start (vbox, 10);
@@ -330,7 +328,7 @@ do_combobox (GtkWidget *do_widget)
* insensitive rows
*/
frame = gtk_frame_new ("Items with icons");
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_margin_start (box, 5);
@@ -342,7 +340,7 @@ do_combobox (GtkWidget *do_widget)
model = create_icon_store ();
combo = gtk_combo_box_new_with_model (model);
g_object_unref (model);
gtk_container_add (GTK_CONTAINER (box), combo);
gtk_box_append (GTK_BOX (box), combo);
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, FALSE);
@@ -374,7 +372,7 @@ do_combobox (GtkWidget *do_widget)
/* A combobox demonstrating trees.
*/
frame = gtk_frame_new ("Where are we ?");
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_margin_start (box, 5);
@@ -386,7 +384,7 @@ do_combobox (GtkWidget *do_widget)
model = create_capital_store ();
combo = gtk_combo_box_new_with_model (model);
g_object_unref (model);
gtk_container_add (GTK_CONTAINER (box), combo);
gtk_box_append (GTK_BOX (box), combo);
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
@@ -405,7 +403,7 @@ do_combobox (GtkWidget *do_widget)
/* A GtkComboBoxEntry with validation */
frame = gtk_frame_new ("Editable");
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_margin_start (box, 5);
@@ -416,7 +414,7 @@ do_combobox (GtkWidget *do_widget)
combo = gtk_combo_box_text_new_with_entry ();
fill_combo_entry (combo);
gtk_container_add (GTK_CONTAINER (box), combo);
gtk_box_append (GTK_BOX (box), combo);
entry = g_object_new (TYPE_MASK_ENTRY, NULL);
MASK_ENTRY (entry)->mask = "^([0-9]*|One|Two|2\302\275|Three)$";
@@ -425,7 +423,7 @@ do_combobox (GtkWidget *do_widget)
/* A combobox with string IDs */
frame = gtk_frame_new ("String IDs");
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_margin_start (box, 5);
@@ -438,19 +436,19 @@ do_combobox (GtkWidget *do_widget)
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "never", "Not visible");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "when-active", "Visible when active");
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "always", "Always visible");
gtk_container_add (GTK_CONTAINER (box), combo);
gtk_box_append (GTK_BOX (box), combo);
entry = gtk_entry_new ();
g_object_bind_property (combo, "active-id",
entry, "text",
G_BINDING_BIDIRECTIONAL);
gtk_container_add (GTK_CONTAINER (box), entry);
gtk_box_append (GTK_BOX (box), entry);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -25,9 +25,9 @@ simple_grid_dispose (GObject *object)
{
SimpleGrid *self = SIMPLE_GRID (object);
g_clear_pointer (&self->button1, gtk_widget_destroy);
g_clear_pointer (&self->button2, gtk_widget_destroy);
g_clear_pointer (&self->button3, gtk_widget_destroy);
g_clear_pointer (&self->button1, gtk_widget_unparent);
g_clear_pointer (&self->button2, gtk_widget_unparent);
g_clear_pointer (&self->button3, gtk_widget_unparent);
G_OBJECT_CLASS (simple_grid_parent_class)->dispose (object);
}
@@ -263,8 +263,7 @@ do_constraints (GtkWidget *do_widget)
header = gtk_header_bar_new ();
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_window_set_child (GTK_WINDOW (window), box);
@@ -272,19 +271,19 @@ do_constraints (GtkWidget *do_widget)
grid = g_object_new (simple_grid_get_type (), NULL);
gtk_widget_set_hexpand (grid, TRUE);
gtk_widget_set_vexpand (grid, TRUE);
gtk_container_add (GTK_CONTAINER (box), grid);
gtk_box_append (GTK_BOX (box), grid);
button = gtk_button_new_with_label ("Close");
gtk_container_add (GTK_CONTAINER (box), button);
gtk_box_append (GTK_BOX (box), button);
gtk_widget_set_hexpand (grid, TRUE);
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy), window);
G_CALLBACK (gtk_window_destroy), window);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -26,9 +26,9 @@ interactive_grid_dispose (GObject *object)
{
InteractiveGrid *self = INTERACTIVE_GRID (object);
g_clear_pointer (&self->button1, gtk_widget_destroy);
g_clear_pointer (&self->button2, gtk_widget_destroy);
g_clear_pointer (&self->button3, gtk_widget_destroy);
g_clear_pointer (&self->button1, gtk_widget_unparent);
g_clear_pointer (&self->button2, gtk_widget_unparent);
g_clear_pointer (&self->button3, gtk_widget_unparent);
G_OBJECT_CLASS (interactive_grid_parent_class)->dispose (object);
}
@@ -219,8 +219,7 @@ do_constraints2 (GtkWidget *do_widget)
header = gtk_header_bar_new ();
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_window_set_child (GTK_WINDOW (window), box);
@@ -228,19 +227,19 @@ do_constraints2 (GtkWidget *do_widget)
grid = g_object_new (interactive_grid_get_type (), NULL);
gtk_widget_set_hexpand (grid, TRUE);
gtk_widget_set_vexpand (grid, TRUE);
gtk_container_add (GTK_CONTAINER (box), grid);
gtk_box_append (GTK_BOX (box), grid);
button = gtk_button_new_with_label ("Close");
gtk_container_add (GTK_CONTAINER (box), button);
gtk_box_append (GTK_BOX (box), button);
gtk_widget_set_hexpand (grid, TRUE);
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy), window);
G_CALLBACK (gtk_window_destroy), window);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -24,9 +24,9 @@ vfl_grid_dispose (GObject *object)
{
VflGrid *self = VFL_GRID (object);
g_clear_pointer (&self->button1, gtk_widget_destroy);
g_clear_pointer (&self->button2, gtk_widget_destroy);
g_clear_pointer (&self->button3, gtk_widget_destroy);
g_clear_pointer (&self->button1, gtk_widget_unparent);
g_clear_pointer (&self->button2, gtk_widget_unparent);
g_clear_pointer (&self->button3, gtk_widget_unparent);
G_OBJECT_CLASS (vfl_grid_parent_class)->dispose (object);
}
@@ -139,8 +139,7 @@ do_constraints3 (GtkWidget *do_widget)
header = gtk_header_bar_new ();
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_window_set_child (GTK_WINDOW (window), box);
@@ -148,19 +147,19 @@ do_constraints3 (GtkWidget *do_widget)
grid = g_object_new (vfl_grid_get_type (), NULL);
gtk_widget_set_hexpand (grid, TRUE);
gtk_widget_set_vexpand (grid, TRUE);
gtk_container_add (GTK_CONTAINER (box), grid);
gtk_box_append (GTK_BOX (box), grid);
button = gtk_button_new_with_label ("Close");
gtk_container_add (GTK_CONTAINER (box), button);
gtk_box_append (GTK_BOX (box), button);
gtk_widget_set_hexpand (grid, TRUE);
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy), window);
G_CALLBACK (gtk_window_destroy), window);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -9,9 +9,13 @@
static void
apply_css (GtkWidget *widget, GtkStyleProvider *provider)
{
GtkWidget *child;
gtk_style_context_add_provider (gtk_widget_get_style_context (widget), provider, G_MAXUINT);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback) apply_css, provider);
for (child = gtk_widget_get_first_child (widget);
child != NULL;
child = gtk_widget_get_next_sibling (child))
apply_css (child, provider);
}
GtkWidget *
@@ -28,8 +32,7 @@ do_css_accordion (GtkWidget *do_widget)
gtk_window_set_title (GTK_WINDOW (window), "CSS Accordion");
gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
gtk_window_set_default_size (GTK_WINDOW (window), 600, 300);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_halign (container, GTK_ALIGN_CENTER);
@@ -37,22 +40,22 @@ do_css_accordion (GtkWidget *do_widget)
gtk_window_set_child (GTK_WINDOW (window), container);
child = gtk_button_new_with_label ("This");
gtk_container_add (GTK_CONTAINER (container), child);
gtk_box_append (GTK_BOX (container), child);
child = gtk_button_new_with_label ("Is");
gtk_container_add (GTK_CONTAINER (container), child);
gtk_box_append (GTK_BOX (container), child);
child = gtk_button_new_with_label ("A");
gtk_container_add (GTK_CONTAINER (container), child);
gtk_box_append (GTK_BOX (container), child);
child = gtk_button_new_with_label ("CSS");
gtk_container_add (GTK_CONTAINER (container), child);
gtk_box_append (GTK_BOX (container), child);
child = gtk_button_new_with_label ("Accordion");
gtk_container_add (GTK_CONTAINER (container), child);
gtk_box_append (GTK_BOX (container), child);
child = gtk_button_new_with_label (":-)");
gtk_container_add (GTK_CONTAINER (container), child);
gtk_box_append (GTK_BOX (container), child);
provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
gtk_css_provider_load_from_resource (GTK_CSS_PROVIDER (provider), "/css_accordion/css_accordion.css");
@@ -63,7 +66,7 @@ do_css_accordion (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -55,9 +55,13 @@ css_text_changed (GtkTextBuffer *buffer,
static void
apply_css (GtkWidget *widget, GtkStyleProvider *provider)
{
GtkWidget *child;
gtk_style_context_add_provider (gtk_widget_get_style_context (widget), provider, G_MAXUINT);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback) apply_css, provider);
for (child = gtk_widget_get_first_child (widget);
child != NULL;
child = gtk_widget_get_next_sibling (child))
apply_css (child, provider);
}
GtkWidget *
@@ -76,8 +80,7 @@ do_css_basics (GtkWidget *do_widget)
gtk_window_set_title (GTK_WINDOW (window), "CSS Basics");
gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
text = gtk_text_buffer_new (NULL);
gtk_text_buffer_create_tag (text,
@@ -94,7 +97,7 @@ do_css_basics (GtkWidget *do_widget)
container = gtk_scrolled_window_new (NULL, NULL);
gtk_window_set_child (GTK_WINDOW (window), container);
child = gtk_text_view_new_with_buffer (text);
gtk_container_add (GTK_CONTAINER (container), child);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (container), child);
g_signal_connect (text, "changed",
G_CALLBACK (css_text_changed), provider);
@@ -113,7 +116,7 @@ do_css_basics (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -79,7 +79,7 @@ setup_listbox (GtkBuilder *builder,
normal_row = NULL;
listbox = gtk_list_box_new ();
gtk_container_add (GTK_CONTAINER (WID ("scrolledwindow")), listbox);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (WID ("scrolledwindow")), listbox);
g_signal_connect (listbox, "row-activated", G_CALLBACK (row_activated), provider);
@@ -95,9 +95,8 @@ setup_listbox (GtkBuilder *builder,
"xalign", 0.0,
NULL);
gtk_container_add (GTK_CONTAINER (row), label);
gtk_container_add (GTK_CONTAINER (listbox), row);
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), label);
gtk_list_box_insert (GTK_LIST_BOX (listbox), row, -1);
/* The first selected row is "normal" */
if (g_strcmp0 (blend_modes[i].id, "normal") == 0)
@@ -125,7 +124,7 @@ do_css_blendmodes (GtkWidget *do_widget)
window = WID ("window");
gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
/* Setup the CSS provider for window */
provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
@@ -135,12 +134,14 @@ do_css_blendmodes (GtkWidget *do_widget)
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
setup_listbox (builder, provider);
g_object_unref (builder);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -69,9 +69,13 @@ drawing_area_draw (GtkDrawingArea *da,
static void
apply_css (GtkWidget *widget, GtkStyleProvider *provider)
{
GtkWidget *child;
gtk_style_context_add_provider (gtk_widget_get_style_context (widget), provider, G_MAXUINT);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback) apply_css, provider);
for (child = gtk_widget_get_first_child (widget);
child != NULL;
child = gtk_widget_get_next_sibling (child))
apply_css (child, provider);
}
GtkWidget *
@@ -81,7 +85,7 @@ do_css_multiplebgs (GtkWidget *do_widget)
if (!window)
{
GtkWidget *paned, *container, *child;
GtkWidget *paned, *overlay, *child, *sw;
GtkStyleProvider *provider;
GtkTextBuffer *text;
GBytes *bytes;
@@ -90,32 +94,31 @@ do_css_multiplebgs (GtkWidget *do_widget)
gtk_window_set_title (GTK_WINDOW (window), "Multiple Backgrounds");
gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
container = gtk_overlay_new ();
gtk_window_set_child (GTK_WINDOW (window), container);
overlay = gtk_overlay_new ();
gtk_window_set_child (GTK_WINDOW (window), overlay);
child = gtk_drawing_area_new ();
gtk_widget_set_name (child, "canvas");
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (child),
drawing_area_draw,
NULL, NULL);
gtk_container_add (GTK_CONTAINER (container), child);
gtk_overlay_set_child (GTK_OVERLAY (overlay), child);
child = gtk_button_new ();
gtk_overlay_add_overlay (GTK_OVERLAY (container), child);
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
gtk_widget_set_name (child, "bricks-button");
gtk_widget_set_halign (child, GTK_ALIGN_CENTER);
gtk_widget_set_valign (child, GTK_ALIGN_CENTER);
gtk_widget_set_size_request (child, 250, 84);
paned = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
gtk_overlay_add_overlay (GTK_OVERLAY (container), paned);
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), paned);
/* Need a filler so we get a handle */
child = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (paned), child);
gtk_paned_set_start_child (GTK_PANED (paned), child);
text = gtk_text_buffer_new (NULL);
gtk_text_buffer_create_tag (text,
@@ -129,10 +132,10 @@ do_css_multiplebgs (GtkWidget *do_widget)
provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
container = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (paned), container);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_paned_set_end_child (GTK_PANED (paned), sw);
child = gtk_text_view_new_with_buffer (text);
gtk_container_add (GTK_CONTAINER (container), child);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), child);
g_signal_connect (text,
"changed",
G_CALLBACK (css_text_changed),
@@ -153,7 +156,7 @@ do_css_multiplebgs (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -55,9 +55,13 @@ css_text_changed (GtkTextBuffer *buffer,
static void
apply_css (GtkWidget *widget, GtkStyleProvider *provider)
{
GtkWidget *child;
gtk_style_context_add_provider (gtk_widget_get_style_context (widget), provider, G_MAXUINT);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback) apply_css, provider);
for (child = gtk_widget_get_first_child (widget);
child != NULL;
child = gtk_widget_get_next_sibling (child))
apply_css (child, provider);
}
GtkWidget *
@@ -76,15 +80,14 @@ do_css_pixbufs (GtkWidget *do_widget)
gtk_window_set_title (GTK_WINDOW (window), "Animated Backgrounds");
gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
paned = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
gtk_window_set_child (GTK_WINDOW (window), paned);
/* Need a filler so we get a handle */
child = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (paned), child);
gtk_paned_set_start_child (GTK_PANED (paned), child);
text = gtk_text_buffer_new (NULL);
gtk_text_buffer_create_tag (text,
@@ -99,9 +102,9 @@ do_css_pixbufs (GtkWidget *do_widget)
provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
container = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (paned), container);
gtk_paned_set_end_child (GTK_PANED (paned), container);
child = gtk_text_view_new_with_buffer (text);
gtk_container_add (GTK_CONTAINER (container), child);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (container), child);
g_signal_connect (text, "changed",
G_CALLBACK (css_text_changed), provider);
@@ -120,7 +123,7 @@ do_css_pixbufs (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -53,9 +53,13 @@ css_text_changed (GtkTextBuffer *buffer,
static void
apply_css (GtkWidget *widget, GtkStyleProvider *provider)
{
GtkWidget *child;
gtk_style_context_add_provider (gtk_widget_get_style_context (widget), provider, G_MAXUINT);
if (GTK_IS_CONTAINER (widget))
gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback) apply_css, provider);
for (child = gtk_widget_get_first_child (widget);
child != NULL;
child = gtk_widget_get_next_sibling (child))
apply_css (child, provider);
}
static GtkWidget *
@@ -68,13 +72,13 @@ create_toolbar (void)
gtk_widget_set_valign (toolbar, GTK_ALIGN_CENTER);
item = gtk_button_new_from_icon_name ("go-next");
gtk_container_add (GTK_CONTAINER (toolbar), item);
gtk_box_append (GTK_BOX (toolbar), item);
item = gtk_button_new_from_icon_name ("go-previous");
gtk_container_add (GTK_CONTAINER (toolbar), item);
gtk_box_append (GTK_BOX (toolbar), item);
item = gtk_button_new_with_label ("Hello World");
gtk_container_add (GTK_CONTAINER (toolbar), item);
gtk_box_append (GTK_BOX (toolbar), item);
return toolbar;
}
@@ -95,14 +99,13 @@ do_css_shadows (GtkWidget *do_widget)
gtk_window_set_title (GTK_WINDOW (window), "Shadows");
gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
paned = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
gtk_window_set_child (GTK_WINDOW (window), paned);
child = create_toolbar ();
gtk_container_add (GTK_CONTAINER (paned), child);
gtk_paned_set_start_child (GTK_PANED (paned), child);
text = gtk_text_buffer_new (NULL);
gtk_text_buffer_create_tag (text,
@@ -117,9 +120,9 @@ do_css_shadows (GtkWidget *do_widget)
provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
container = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (paned), container);
gtk_paned_set_end_child (GTK_PANED (paned), container);
child = gtk_text_view_new_with_buffer (text);
gtk_container_add (GTK_CONTAINER (container), child);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (container), child);
g_signal_connect (text, "changed",
G_CALLBACK (css_text_changed), provider);
@@ -138,7 +141,7 @@ do_css_shadows (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -29,14 +29,14 @@ do_cursors (GtkWidget *do_widget)
gtk_widget_get_display (do_widget));
g_signal_connect (window, "destroy",
G_CALLBACK (on_destroy), NULL);
g_object_set_data_full (G_OBJECT (window), "builder", builder, g_object_unref);
g_object_unref (builder);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
{
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
}
return window;

View File

@@ -1,14 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/">
<file>awards.ui</file>
</gresource>
<gresource prefix="/ui">
<file preprocess="xml-stripblanks">main.ui</file>
<file preprocess="xml-stripblanks">appmenu.ui</file>
<file preprocess="xml-stripblanks">main-listitem.ui</file>
</gresource>
<gresource prefix="/application_demo">
<file>application.c</file>
<file>application.ui</file>
<file>menus.ui</file>
</gresource>
<gresource prefix="/awardview">
<file>awardlistitem.ui</file>
</gresource>
<gresource prefix="/builder">
<file>demo.ui</file>
</gresource>
@@ -119,6 +125,22 @@
<file>gnome-fs-directory.png</file>
<file>gnome-fs-regular.png</file>
</gresource>
<gresource prefix="/listview_filebrowser">
<file>listview_filebrowser.ui</file>
</gresource>
<gresource prefix="/listview_minesweeper">
<file>listview_minesweeper.ui</file>
<file>listview_minesweeper_cell.ui</file>
</gresource>
<gresource prefix="/listview_settings">
<file>listview_settings.ui</file>
</gresource>
<gresource prefix="/listview_weather">
<file compressed="true">listview_weather.txt</file>
</gresource>
<gresource prefix="/listview_colors">
<file compressed="true">color.names.txt</file>
</gresource>
<gresource prefix="/shortcuts">
<file>shortcuts.ui</file>
<file>shortcuts-builder.ui</file>
@@ -155,6 +177,7 @@
</gresource>
<gresource prefix="/sources">
<file>application_demo.c</file>
<file>awardview.c</file>
<file>assistant.c</file>
<file>builder.c</file>
<file>clipboard.c</file>
@@ -195,6 +218,13 @@
<file>infobar.c</file>
<file>links.c</file>
<file>listbox.c</file>
<file>listview_applauncher.c</file>
<file>listview_colors.c</file>
<file>listview_clocks.c</file>
<file>listview_filebrowser.c</file>
<file>listview_minesweeper.c</file>
<file>listview_settings.c</file>
<file>listview_weather.c</file>
<file>list_store.c</file>
<file>markup.c</file>
<file>modelbutton.c</file>

View File

@@ -94,6 +94,7 @@
<object class="GtkAboutDialog" id="aboutdialog1">
<property name="program-name" translatable="yes">Builder demo</property>
<property name="logo-icon-name" translatable="yes">gtk3-demo</property>
<property name="modal">True</property>
<accessibility>
<relation target="window1" type="subwindow-of"/>
</accessibility>

View File

@@ -49,7 +49,7 @@ demo_tagged_entry_init (DemoTaggedEntry *entry)
gtk_widget_set_vexpand (priv->entry, TRUE);
gtk_widget_set_hexpand (priv->box, FALSE);
gtk_widget_set_vexpand (priv->box, FALSE);
gtk_container_add (GTK_CONTAINER (priv->box), priv->entry);
gtk_box_append (GTK_BOX (priv->box), priv->entry);
gtk_editable_init_delegate (GTK_EDITABLE (entry));
}
@@ -188,7 +188,7 @@ demo_tagged_entry_add_tag (DemoTaggedEntry *entry,
g_return_if_fail (DEMO_IS_TAGGED_ENTRY (entry));
gtk_container_add (GTK_CONTAINER (priv->box), tag);
gtk_box_append (GTK_BOX (priv->box), tag);
}
void
@@ -201,7 +201,7 @@ demo_tagged_entry_insert_tag_after (DemoTaggedEntry *entry,
g_return_if_fail (DEMO_IS_TAGGED_ENTRY (entry));
if (sibling == NULL)
gtk_container_add (GTK_CONTAINER (priv->box), tag);
gtk_box_append (GTK_BOX (priv->box), tag);
else
gtk_box_insert_child_after (GTK_BOX (priv->box), tag, sibling);
}
@@ -214,7 +214,7 @@ demo_tagged_entry_remove_tag (DemoTaggedEntry *entry,
g_return_if_fail (DEMO_IS_TAGGED_ENTRY (entry));
gtk_container_remove (GTK_CONTAINER (priv->box), tag);
gtk_box_remove (GTK_BOX (priv->box), tag);
}
struct _DemoTaggedEntryTag
@@ -268,7 +268,7 @@ demo_tagged_entry_tag_init (DemoTaggedEntryTag *tag)
tag->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_parent (tag->box, GTK_WIDGET (tag));
tag->label = gtk_label_new ("");
gtk_container_add (GTK_CONTAINER (tag->box), tag->label);
gtk_box_append (GTK_BOX (tag->box), tag->label);
gesture = gtk_gesture_click_new ();
g_signal_connect (gesture, "released", G_CALLBACK (on_released), tag);
@@ -460,7 +460,7 @@ demo_tagged_entry_tag_set_has_close_button (DemoTaggedEntryTag *tag,
if (!has_close_button && tag->button)
{
gtk_container_remove (GTK_CONTAINER (tag->box), tag->button);
gtk_box_remove (GTK_BOX (tag->box), tag->button);
tag->button = NULL;
}
else if (has_close_button && tag->button == NULL)
@@ -469,11 +469,11 @@ demo_tagged_entry_tag_set_has_close_button (DemoTaggedEntryTag *tag,
image = gtk_image_new_from_icon_name ("window-close-symbolic");
tag->button = gtk_button_new ();
gtk_container_add (GTK_CONTAINER (tag->button), image);
gtk_box_append (GTK_BOX (tag->button), image);
gtk_widget_set_halign (tag->button, GTK_ALIGN_CENTER);
gtk_widget_set_valign (tag->button, GTK_ALIGN_CENTER);
gtk_button_set_has_frame (GTK_BUTTON (tag->button), FALSE);
gtk_container_add (GTK_CONTAINER (tag->box), tag->button);
gtk_box_append (GTK_BOX (tag->box), tag->button);
g_signal_connect (tag->button, "clicked", G_CALLBACK (on_button_clicked), tag);
}

View File

@@ -25,11 +25,36 @@ message_dialog_clicked (GtkButton *button,
"number of times:");
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%d", i);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
g_signal_connect (dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
i++;
}
typedef struct {
GtkWidget *local_entry1;
GtkWidget *local_entry2;
GtkWidget *global_entry1;
GtkWidget *global_entry2;
} ResponseData;
static void
on_dialog_response (GtkDialog *dialog,
int response,
gpointer user_data)
{
ResponseData *data = user_data;
if (response == GTK_RESPONSE_OK)
{
gtk_editable_set_text (GTK_EDITABLE (data->global_entry1),
gtk_editable_get_text (GTK_EDITABLE (data->local_entry1)));
gtk_editable_set_text (GTK_EDITABLE (data->global_entry2),
gtk_editable_get_text (GTK_EDITABLE (data->local_entry2)));
}
gtk_window_destroy (GTK_WINDOW (dialog));
}
static void
interactive_dialog_clicked (GtkButton *button,
gpointer user_data)
@@ -42,7 +67,7 @@ interactive_dialog_clicked (GtkButton *button,
GtkWidget *local_entry1;
GtkWidget *local_entry2;
GtkWidget *label;
gint response;
ResponseData *data;
dialog = gtk_dialog_new_with_buttons ("Interactive Dialog",
GTK_WINDOW (window),
@@ -56,16 +81,16 @@ interactive_dialog_clicked (GtkButton *button,
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
gtk_container_add (GTK_CONTAINER (content_area), hbox);
gtk_box_append (GTK_BOX (content_area), hbox);
image = gtk_image_new_from_icon_name ("dialog-question");
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
gtk_container_add (GTK_CONTAINER (hbox), image);
gtk_box_append (GTK_BOX (hbox), image);
table = gtk_grid_new ();
gtk_grid_set_row_spacing (GTK_GRID (table), 4);
gtk_grid_set_column_spacing (GTK_GRID (table), 4);
gtk_container_add (GTK_CONTAINER (hbox), table);
gtk_box_append (GTK_BOX (hbox), table);
label = gtk_label_new_with_mnemonic ("_Entry 1");
gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
local_entry1 = gtk_entry_new ();
@@ -81,15 +106,18 @@ interactive_dialog_clicked (GtkButton *button,
gtk_grid_attach (GTK_GRID (table), local_entry2, 1, 1, 1, 1);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), local_entry2);
response = gtk_dialog_run (GTK_DIALOG (dialog));
data = g_new (ResponseData, 1);
data->local_entry1 = local_entry1;
data->local_entry2 = local_entry2;
data->global_entry1 = entry1;
data->global_entry2 = entry2;
if (response == GTK_RESPONSE_OK)
{
gtk_editable_set_text (GTK_EDITABLE (entry1), gtk_editable_get_text (GTK_EDITABLE (local_entry1)));
gtk_editable_set_text (GTK_EDITABLE (entry2), gtk_editable_get_text (GTK_EDITABLE (local_entry2)));
}
g_signal_connect_data (dialog, "response",
G_CALLBACK (on_dialog_response),
data, (GClosureNotify) g_free,
0);
gtk_widget_destroy (dialog);
gtk_widget_show (dialog);
}
GtkWidget *
@@ -109,9 +137,7 @@ do_dialog (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Dialogs and Message Boxes");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
frame = gtk_frame_new ("Dialogs");
gtk_widget_set_margin_start (frame, 8);
@@ -129,29 +155,29 @@ do_dialog (GtkWidget *do_widget)
/* Standard message dialog */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_box_append (GTK_BOX (vbox), hbox);
button = gtk_button_new_with_mnemonic ("_Message Dialog");
g_signal_connect (button, "clicked",
G_CALLBACK (message_dialog_clicked), NULL);
gtk_container_add (GTK_CONTAINER (hbox), button);
gtk_box_append (GTK_BOX (hbox), button);
gtk_container_add (GTK_CONTAINER (vbox), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
gtk_box_append (GTK_BOX (vbox), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
/* Interactive dialog*/
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_box_append (GTK_BOX (vbox), hbox);
vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
button = gtk_button_new_with_mnemonic ("_Interactive Dialog");
g_signal_connect (button, "clicked",
G_CALLBACK (interactive_dialog_clicked), NULL);
gtk_container_add (GTK_CONTAINER (hbox), vbox2);
gtk_container_add (GTK_CONTAINER (vbox2), button);
gtk_box_append (GTK_BOX (hbox), vbox2);
gtk_box_append (GTK_BOX (vbox2), button);
table = gtk_grid_new ();
gtk_grid_set_row_spacing (GTK_GRID (table), 4);
gtk_grid_set_column_spacing (GTK_GRID (table), 4);
gtk_container_add (GTK_CONTAINER (hbox), table);
gtk_box_append (GTK_BOX (hbox), table);
label = gtk_label_new_with_mnemonic ("_Entry 1");
gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
@@ -170,7 +196,7 @@ do_dialog (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -7,6 +7,292 @@
#include <gtk/gtk.h>
G_DECLARE_FINAL_TYPE (CanvasItem, canvas_item, CANVAS, ITEM, GtkWidget)
struct _CanvasItem {
GtkWidget parent;
GtkWidget *fixed;
GtkWidget *label;
double r;
double angle;
double delta;
GtkWidget *editor;
};
struct _CanvasItemClass {
GtkWidgetClass parent_class;
};
G_DEFINE_TYPE (CanvasItem, canvas_item, GTK_TYPE_WIDGET)
static int n_items = 0;
static void
set_color (CanvasItem *item,
GdkRGBA *color)
{
char *css;
char *str;
GtkStyleContext *context;
GtkCssProvider *provider;
str = gdk_rgba_to_string (color);
css = g_strdup_printf ("* { background: %s; padding: 10px; margin: 1px; }", str);
context = gtk_widget_get_style_context (item->label);
provider = g_object_get_data (G_OBJECT (context), "style-provider");
if (provider)
gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (provider));
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider, css, -1);
gtk_style_context_add_provider (gtk_widget_get_style_context (item->label), GTK_STYLE_PROVIDER (provider), 800);
g_object_set_data_full (G_OBJECT (context), "style-provider", provider, g_object_unref);
g_free (str);
g_free (css);
}
static gboolean
item_drag_drop (GtkDropTarget *dest,
const GValue *value,
double x,
double y)
{
GtkWidget *label = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
CanvasItem *item = CANVAS_ITEM (gtk_widget_get_parent (gtk_widget_get_parent (label)));
set_color (item, g_value_get_boxed (value));
return TRUE;
}
static void
apply_transform (CanvasItem *item)
{
GskTransform *transform;
double x, y;
x = gtk_widget_get_allocated_width (item->label) / 2.0;
y = gtk_widget_get_allocated_height (item->label) / 2.0;
item->r = sqrt (x*x + y*y);
transform = gsk_transform_translate (
gsk_transform_rotate (
gsk_transform_translate (NULL,
&(graphene_point_t) { item->r, item->r }),
item->angle + item->delta),
&(graphene_point_t) { - x, - y });
gtk_fixed_set_child_transform (GTK_FIXED (item->fixed), item->label, transform);
gsk_transform_unref (transform);
}
static void
angle_changed (GtkGestureRotate *gesture,
double angle,
double delta)
{
CanvasItem *item = CANVAS_ITEM (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)));
item->delta = angle / M_PI * 180.0;
apply_transform (item);
}
static void
rotate_done (GtkGesture *gesture)
{
CanvasItem *item = CANVAS_ITEM (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)));
item->angle = item->angle + item->delta;
item->delta = 0;
}
static void
click_done (GtkGesture *gesture)
{
GtkWidget *item = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
GtkWidget *canvas = gtk_widget_get_parent (item);
GtkWidget *last_child;
last_child = gtk_widget_get_last_child (canvas);
if (item != last_child)
gtk_widget_insert_after (item, canvas, last_child);
}
static void
canvas_item_init (CanvasItem *item)
{
char *text;
char *id;
GdkRGBA rgba;
GtkDropTarget *dest;
GtkGesture *gesture;
n_items++;
text = g_strdup_printf ("Item %d", n_items);
item->label = gtk_label_new (text);
g_free (text);
item->fixed = gtk_fixed_new ();
gtk_widget_set_parent (item->fixed, GTK_WIDGET (item));
gtk_fixed_put (GTK_FIXED (item->fixed), item->label, 0, 0);
gtk_widget_add_css_class (item->label, "frame");
id = g_strdup_printf ("item%d", n_items);
gtk_widget_set_name (item->label, id);
g_free (id);
gdk_rgba_parse (&rgba, "yellow");
set_color (item, &rgba);
item->angle = 0;
dest = gtk_drop_target_new (GDK_TYPE_RGBA, GDK_ACTION_COPY);
g_signal_connect (dest, "drop", G_CALLBACK (item_drag_drop), NULL);
gtk_widget_add_controller (GTK_WIDGET (item->label), GTK_EVENT_CONTROLLER (dest));
gesture = gtk_gesture_rotate_new ();
g_signal_connect (gesture, "angle-changed", G_CALLBACK (angle_changed), NULL);
g_signal_connect (gesture, "end", G_CALLBACK (rotate_done), NULL);
gtk_widget_add_controller (GTK_WIDGET (item), GTK_EVENT_CONTROLLER (gesture));
gesture = gtk_gesture_click_new ();
g_signal_connect (gesture, "released", G_CALLBACK (click_done), NULL);
gtk_widget_add_controller (GTK_WIDGET (item), GTK_EVENT_CONTROLLER (gesture));
}
static void
canvas_item_dispose (GObject *object)
{
CanvasItem *item = CANVAS_ITEM (object);
g_clear_pointer (&item->fixed, gtk_widget_unparent);
g_clear_pointer (&item->editor, gtk_widget_unparent);
G_OBJECT_CLASS (canvas_item_parent_class)->dispose (object);
}
static void
canvas_item_map (GtkWidget *widget)
{
CanvasItem *item = CANVAS_ITEM (widget);
GTK_WIDGET_CLASS (canvas_item_parent_class)->map (widget);
apply_transform (item);
}
static void
canvas_item_class_init (CanvasItemClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
object_class->dispose = canvas_item_dispose;
widget_class->map = canvas_item_map;
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_set_css_name (widget_class, "item");
}
static GtkWidget *
canvas_item_new (void)
{
CanvasItem *item = g_object_new (canvas_item_get_type (), NULL);
return GTK_WIDGET (item);
}
static GdkPaintable *
canvas_item_get_drag_icon (CanvasItem *item)
{
return gtk_widget_paintable_new (item->fixed);
}
static gboolean
canvas_item_is_editing (CanvasItem *item)
{
return item->editor != NULL;
}
static void
scale_changed (GtkRange *range,
CanvasItem *item)
{
item->angle = gtk_range_get_value (range);
apply_transform (item);
}
static void
text_changed (GtkEditable *editable,
GParamSpec *pspec,
CanvasItem *item)
{
gtk_label_set_text (GTK_LABEL (item->label), gtk_editable_get_text (editable));
apply_transform (item);
}
static void
canvas_item_stop_editing (CanvasItem *item)
{
GtkWidget *scale;
if (!item->editor)
return;
scale = gtk_widget_get_last_child (item->editor);
g_signal_handlers_disconnect_by_func (scale, scale_changed, item);
gtk_fixed_remove (GTK_FIXED (gtk_widget_get_parent (item->editor)), item->editor);
item->editor = NULL;
}
static void
canvas_item_start_editing (CanvasItem *item)
{
GtkWidget *canvas = gtk_widget_get_parent (GTK_WIDGET (item));
GtkWidget *entry;
GtkWidget *scale;
double x, y;
if (item->editor)
return;
item->editor = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
entry = gtk_entry_new ();
gtk_editable_set_text (GTK_EDITABLE (entry),
gtk_label_get_text (GTK_LABEL (item->label)));
gtk_editable_set_width_chars (GTK_EDITABLE (entry), 12);
g_signal_connect (entry, "notify::text", G_CALLBACK (text_changed), item);
g_signal_connect_swapped (entry, "activate", G_CALLBACK (canvas_item_stop_editing), item);
gtk_box_append (GTK_BOX (item->editor), entry);
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 360, 1);
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
gtk_range_set_value (GTK_RANGE (scale), fmod (item->angle, 360));
g_signal_connect (scale, "value-changed", G_CALLBACK (scale_changed), item);
gtk_box_append (GTK_BOX (item->editor), scale);
gtk_widget_translate_coordinates (GTK_WIDGET (item), canvas, 0, 0, &x, &y);
gtk_fixed_put (GTK_FIXED (canvas), item->editor, x, y + 2 * item->r);
gtk_widget_grab_focus (entry);
}
static GdkContentProvider *
prepare (GtkDragSource *source,
double x,
@@ -18,7 +304,8 @@ prepare (GtkDragSource *source,
canvas = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
item = gtk_widget_pick (canvas, x, y, GTK_PICK_DEFAULT);
if (!GTK_IS_LABEL (item))
item = gtk_widget_get_ancestor (item, canvas_item_get_type ());
if (!item)
return NULL;
g_object_set_data (G_OBJECT (canvas), "dragged-item", item);
@@ -31,12 +318,17 @@ drag_begin (GtkDragSource *source,
GdkDrag *drag)
{
GtkWidget *canvas;
GtkWidget *item;
CanvasItem *item;
GdkPaintable *paintable;
canvas = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (source));
item = g_object_get_data (G_OBJECT (canvas), "dragged-item");
item = CANVAS_ITEM (g_object_get_data (G_OBJECT (canvas), "dragged-item"));
gtk_widget_set_opacity (item, 0.5);
paintable = canvas_item_get_drag_icon (item);
gtk_drag_source_set_icon (source, paintable, item->r, item->r);
g_object_unref (paintable);
gtk_widget_set_opacity (GTK_WIDGET (item), 0.3);
}
static void
@@ -53,32 +345,12 @@ drag_end (GtkDragSource *source,
gtk_widget_set_opacity (item, 1.0);
}
static void
static gboolean
drag_cancel (GtkDragSource *source,
GdkDrag *drag,
GdkDragCancelReason reason)
{
drag_end (source, drag);
}
typedef struct {
double x, y;
double angle;
double delta;
} TransformData;
static void
apply_transform (GtkWidget *item)
{
GtkWidget *canvas = gtk_widget_get_parent (item);
TransformData *data;
GskTransform *transform;
data = g_object_get_data (G_OBJECT (item), "transform-data");
transform = gsk_transform_rotate (gsk_transform_translate (NULL, &(graphene_point_t){data->x, data->y}),
data->angle + data->delta);
gtk_fixed_set_child_transform (GTK_FIXED (canvas), item, transform);
gsk_transform_unref (transform);
return FALSE;
}
static gboolean
@@ -87,90 +359,58 @@ drag_drop (GtkDropTarget *target,
double x,
double y)
{
GtkWidget *item;
TransformData *transform_data;
CanvasItem *item;
GtkWidget *canvas;
GtkWidget *last_child;
item = g_value_get_object (value);
transform_data = g_object_get_data (G_OBJECT (item), "transform-data");
transform_data->x = x;
transform_data->y = y;
canvas = gtk_widget_get_parent (item);
canvas = gtk_widget_get_parent (GTK_WIDGET (item));
last_child = gtk_widget_get_last_child (canvas);
if (item != last_child)
gtk_widget_insert_after (item, canvas, last_child);
if (GTK_WIDGET (item) != last_child)
gtk_widget_insert_after (GTK_WIDGET (item), canvas, last_child);
apply_transform (item);
gtk_fixed_move (GTK_FIXED (canvas), GTK_WIDGET (item), x - item->r, y - item->r);
return TRUE;
}
static double pos_x, pos_y;
static GtkWidget * canvas_item_new (double x, double y);
static void
new_item_cb (GtkWidget *button, gpointer data)
{
GtkWidget *canvas = data;
GtkWidget *popover;
GtkWidget *item;
GdkRectangle rect;
item = canvas_item_new (pos_x, pos_y);
gtk_container_add (GTK_CONTAINER (canvas), item);
apply_transform (item);
popover = gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER);
gtk_popover_get_pointing_to (GTK_POPOVER (popover), &rect);
item = canvas_item_new ();
gtk_fixed_put (GTK_FIXED (canvas), item, rect.x, rect.y);
apply_transform (CANVAS_ITEM (item));
gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
}
static void
edit_label_done (GtkWidget *entry, gpointer data)
{
GtkWidget *canvas = gtk_widget_get_parent (entry);
GtkWidget *label;
int x, y;
gtk_fixed_get_child_position (GTK_FIXED (canvas), entry, &x, &y);
label = GTK_WIDGET (g_object_get_data (G_OBJECT (entry), "label"));
gtk_label_set_text (GTK_LABEL (label), gtk_editable_get_text (GTK_EDITABLE (entry)));
gtk_widget_show (label);
gtk_widget_destroy (entry);
}
static void
edit_cb (GtkWidget *button, GtkWidget *child)
{
GtkWidget *canvas = gtk_widget_get_parent (child);
int x, y;
gtk_fixed_get_child_position (GTK_FIXED (canvas), child, &x, &y);
if (GTK_IS_LABEL (child))
{
GtkWidget *entry = gtk_entry_new ();
g_object_set_data (G_OBJECT (entry), "label", child);
gtk_editable_set_text (GTK_EDITABLE (entry), gtk_label_get_text (GTK_LABEL (child)));
gtk_editable_set_width_chars (GTK_EDITABLE (entry), 12);
g_signal_connect (entry, "activate", G_CALLBACK (edit_label_done), NULL);
gtk_fixed_put (GTK_FIXED (canvas), entry, x, y);
gtk_widget_grab_focus (entry);
gtk_widget_hide (child);
}
CanvasItem *item = CANVAS_ITEM (child);
if (button)
gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
if (!canvas_item_is_editing (item))
canvas_item_start_editing (item);
}
static void
delete_cb (GtkWidget *button, GtkWidget *child)
{
gtk_widget_destroy (child);
GtkWidget *canvas = gtk_widget_get_parent (child);
gtk_fixed_remove (GTK_FIXED (canvas), child);
gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
}
@@ -187,6 +427,7 @@ pressed_cb (GtkGesture *gesture,
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
child = gtk_widget_pick (widget, x, y, GTK_PICK_DEFAULT);
child = gtk_widget_get_ancestor (child, canvas_item_get_type ());
if (gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)) == GDK_BUTTON_SECONDARY)
{
@@ -194,38 +435,35 @@ pressed_cb (GtkGesture *gesture,
GtkWidget *box;
GtkWidget *item;
pos_x = x;
pos_y = y;
menu = gtk_popover_new ();
gtk_widget_set_parent (menu, widget);
gtk_popover_set_has_arrow (GTK_POPOVER (menu), FALSE);
gtk_popover_set_pointing_to (GTK_POPOVER (menu), &(GdkRectangle){ x, y, 1, 1});
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (menu), box);
gtk_popover_set_child (GTK_POPOVER (menu), box);
item = gtk_button_new_with_label ("New");
gtk_button_set_has_frame (GTK_BUTTON (item), FALSE);
g_signal_connect (item, "clicked", G_CALLBACK (new_item_cb), widget);
gtk_container_add (GTK_CONTAINER (box), item);
gtk_box_append (GTK_BOX (box), item);
item = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (box), item);
gtk_box_append (GTK_BOX (box), item);
item = gtk_button_new_with_label ("Edit");
gtk_button_set_has_frame (GTK_BUTTON (item), FALSE);
gtk_widget_set_sensitive (item, child != NULL && child != widget);
g_signal_connect (item, "clicked", G_CALLBACK (edit_cb), child);
gtk_container_add (GTK_CONTAINER (box), item);
gtk_box_append (GTK_BOX (box), item);
item = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (box), item);
gtk_box_append (GTK_BOX (box), item);
item = gtk_button_new_with_label ("Delete");
gtk_button_set_has_frame (GTK_BUTTON (item), FALSE);
gtk_widget_set_sensitive (item, child != NULL && child != widget);
g_signal_connect (item, "clicked", G_CALLBACK (delete_cb), child);
gtk_container_add (GTK_CONTAINER (box), item);
gtk_box_append (GTK_BOX (box), item);
gtk_popover_popup (GTK_POPOVER (menu));
}
@@ -240,14 +478,20 @@ released_cb (GtkGesture *gesture,
{
GtkWidget *widget;
GtkWidget *child;
CanvasItem *item;
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
child = gtk_widget_pick (widget, x, y, 0);
item = (CanvasItem *)gtk_widget_get_ancestor (child, canvas_item_get_type ());
if (!item)
return;
if (gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)) == GDK_BUTTON_PRIMARY)
{
if (child != NULL && child != widget)
edit_cb (NULL, child);
if (canvas_item_is_editing (item))
canvas_item_stop_editing (item);
else
canvas_item_start_editing (item);
}
}
@@ -285,131 +529,6 @@ canvas_new (void)
return canvas;
}
static void
set_color (GtkWidget *item,
GdkRGBA *color)
{
char *css;
char *str;
GtkStyleContext *context;
GtkCssProvider *provider;
str = gdk_rgba_to_string (color);
css = g_strdup_printf ("* { background: %s; padding: 10px; }", str);
context = gtk_widget_get_style_context (item);
provider = g_object_get_data (G_OBJECT (context), "style-provider");
if (provider)
gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (provider));
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider, css, -1);
gtk_style_context_add_provider (gtk_widget_get_style_context (item), GTK_STYLE_PROVIDER (provider), 800);
g_object_set_data_full (G_OBJECT (context), "style-provider", provider, g_object_unref);
g_free (str);
g_free (css);
}
static gboolean
item_drag_drop (GtkDropTarget *dest,
const GValue *value,
double x,
double y)
{
GtkWidget *item = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
set_color (item, g_value_get_boxed (value));
return TRUE;
}
static void
angle_changed (GtkGestureRotate *gesture,
double angle,
double delta)
{
GtkWidget *item = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
TransformData *data = g_object_get_data (G_OBJECT (item), "transform-data");
data->delta = angle / M_PI * 180.0;
apply_transform (item);
}
static void
rotate_done (GtkGesture *gesture)
{
GtkWidget *item = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
TransformData *data = g_object_get_data (G_OBJECT (item), "transform-data");
data->angle = data->angle + data->delta;
data->delta = 0;
}
static void
click_done (GtkGesture *gesture)
{
GtkWidget *item = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
GtkWidget *canvas = gtk_widget_get_parent (item);
GtkWidget *last_child;
last_child = gtk_widget_get_last_child (canvas);
if (item != last_child)
gtk_widget_insert_after (item, canvas, last_child);
}
static int n_items = 0;
static GtkWidget *
canvas_item_new (double x,
double y)
{
GtkWidget *widget;
char *label;
char *id;
TransformData *transform_data;
GdkRGBA rgba;
GtkDropTarget *dest;
GtkGesture *gesture;
n_items++;
label = g_strdup_printf ("Item %d", n_items);
id = g_strdup_printf ("item%d", n_items);
gdk_rgba_parse (&rgba, "yellow");
widget = gtk_label_new (label);
gtk_widget_add_css_class (widget, "frame");
gtk_widget_set_name (widget, id);
set_color (widget, &rgba);
transform_data = g_new0 (TransformData, 1);
transform_data->x = x;
transform_data->y = y;
transform_data->angle = 0.0;
g_object_set_data_full (G_OBJECT (widget), "transform-data", transform_data, g_free);
g_free (label);
g_free (id);
dest = gtk_drop_target_new (GDK_TYPE_RGBA, GDK_ACTION_COPY);
g_signal_connect (dest, "drop", G_CALLBACK (item_drag_drop), NULL);
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (dest));
gesture = gtk_gesture_rotate_new ();
g_signal_connect (gesture, "angle-changed", G_CALLBACK (angle_changed), NULL);
g_signal_connect (gesture, "end", G_CALLBACK (rotate_done), NULL);
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture));
gesture = gtk_gesture_click_new ();
g_signal_connect (gesture, "released", G_CALLBACK (click_done), NULL);
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (gesture));
return widget;
}
static GtkWidget *window = NULL;
GtkWidget *
@@ -417,9 +536,9 @@ do_dnd (GtkWidget *do_widget)
{
if (!window)
{
GtkWidget *button;
GtkWidget *sw;
GtkWidget *canvas;
GtkWidget *widget;
GtkWidget *box, *box2, *box3;
const char *colors[] = {
"red", "green", "blue", "magenta", "orange", "gray", "black", "yellow",
@@ -430,26 +549,24 @@ do_dnd (GtkWidget *do_widget)
int i;
int x, y;
widget = gtk_color_button_new ();
gtk_widget_destroy (widget);
button = gtk_color_button_new ();
g_object_unref (g_object_ref_sink (button));
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Drag-and-Drop");
gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_window_set_child (GTK_WINDOW (window), box);
box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (box), box2);
gtk_box_append (GTK_BOX (box), box2);
canvas = canvas_new ();
gtk_container_add (GTK_CONTAINER (box2), canvas);
gtk_box_append (GTK_BOX (box2), canvas);
n_items = 0;
@@ -458,9 +575,9 @@ do_dnd (GtkWidget *do_widget)
{
GtkWidget *item;
item = canvas_item_new (x, y);
gtk_container_add (GTK_CONTAINER (canvas), item);
apply_transform (item);
item = canvas_item_new ();
gtk_fixed_put (GTK_FIXED (canvas), item, x, y);
apply_transform (CANVAS_ITEM (item));
x += 150;
y += 100;
@@ -470,7 +587,7 @@ do_dnd (GtkWidget *do_widget)
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_NEVER);
gtk_container_add (GTK_CONTAINER (box), sw);
gtk_box_append (GTK_BOX (box), sw);
box3 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_add_css_class (box3, "linked");
@@ -487,14 +604,14 @@ do_dnd (GtkWidget *do_widget)
"rgba", &rgba,
"selectable", FALSE,
NULL);
gtk_container_add (GTK_CONTAINER (box3), swatch);
gtk_box_append (GTK_BOX (box3), swatch);
}
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -125,49 +125,164 @@ drag_end (GtkGestureDrag *gesture,
}
static void
checkerboard_draw (GtkDrawingArea *da,
cairo_t *cr,
int width,
int height,
gpointer data)
oval_path (cairo_t *cr,
double xc, double yc,
double xr, double yr)
{
gint i, j, xcount, ycount;
cairo_save (cr);
#define CHECK_SIZE 10
#define SPACING 2
cairo_translate (cr, xc, yc);
cairo_scale (cr, 1.0, yr / xr);
cairo_move_to (cr, xr, 0.0);
cairo_arc (cr,
0, 0,
xr,
0, 2 * G_PI);
cairo_close_path (cr);
/* At the start of a draw handler, a clip region has been set on
* the Cairo context, and the contents have been cleared to the
* widget's background color. The docs for
* gdk_surface_begin_paint_region() give more details on how this
* works.
*/
cairo_restore (cr);
}
xcount = 0;
i = SPACING;
while (i < width)
/* Fill the given area with checks in the standard style
* for showing compositing effects.
*
* It would make sense to do this as a repeating surface,
* but most implementations of RENDER currently have broken
* implementations of repeat + transform, even when the
* transform is a translation.
*/
static void
fill_checks (cairo_t *cr,
int x, int y,
int width, int height)
{
int i, j;
#define CHECK_SIZE 16
cairo_rectangle (cr, x, y, width, height);
cairo_set_source_rgb (cr, 0.4, 0.4, 0.4);
cairo_fill (cr);
/* Only works for CHECK_SIZE a power of 2 */
j = x & (-CHECK_SIZE);
for (; j < height; j += CHECK_SIZE)
{
j = SPACING;
ycount = xcount % 2; /* start with even/odd depending on row */
while (j < height)
{
if (ycount % 2)
cairo_set_source_rgb (cr, 0.45777, 0, 0.45777);
else
cairo_set_source_rgb (cr, 1, 1, 1);
/* If we're outside the clip, this will do nothing.
*/
i = y & (-CHECK_SIZE);
for (; i < width; i += CHECK_SIZE)
if ((i / CHECK_SIZE + j / CHECK_SIZE) % 2 == 0)
cairo_rectangle (cr, i, j, CHECK_SIZE, CHECK_SIZE);
cairo_fill (cr);
j += CHECK_SIZE + SPACING;
++ycount;
}
i += CHECK_SIZE + SPACING;
++xcount;
}
cairo_set_source_rgb (cr, 0.7, 0.7, 0.7);
cairo_fill (cr);
#undef CHECK_SIZE
}
/* Draw a red, green, and blue circle equally spaced inside
* the larger circle of radius r at (xc, yc)
*/
static void
draw_3circles (cairo_t *cr,
double xc, double yc,
double radius,
double alpha)
{
double subradius = radius * (2 / 3. - 0.1);
cairo_set_source_rgba (cr, 1., 0., 0., alpha);
oval_path (cr,
xc + radius / 3. * cos (G_PI * (0.5)),
yc - radius / 3. * sin (G_PI * (0.5)),
subradius, subradius);
cairo_fill (cr);
cairo_set_source_rgba (cr, 0., 1., 0., alpha);
oval_path (cr,
xc + radius / 3. * cos (G_PI * (0.5 + 2/.3)),
yc - radius / 3. * sin (G_PI * (0.5 + 2/.3)),
subradius, subradius);
cairo_fill (cr);
cairo_set_source_rgba (cr, 0., 0., 1., alpha);
oval_path (cr,
xc + radius / 3. * cos (G_PI * (0.5 + 4/.3)),
yc - radius / 3. * sin (G_PI * (0.5 + 4/.3)),
subradius, subradius);
cairo_fill (cr);
}
static void
groups_draw (GtkDrawingArea *darea,
cairo_t *cr,
int width,
int height,
gpointer data)
{
cairo_surface_t *overlay, *punch, *circles;
cairo_t *overlay_cr, *punch_cr, *circles_cr;
/* Fill the background */
double radius = 0.5 * (width < height ? width : height) - 10;
double xc = width / 2.;
double yc = height / 2.;
overlay = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_CONTENT_COLOR_ALPHA,
width, height);
punch = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_CONTENT_ALPHA,
width, height);
circles = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_CONTENT_COLOR_ALPHA,
width, height);
fill_checks (cr, 0, 0, width, height);
/* Draw a black circle on the overlay
*/
overlay_cr = cairo_create (overlay);
cairo_set_source_rgb (overlay_cr, 0., 0., 0.);
oval_path (overlay_cr, xc, yc, radius, radius);
cairo_fill (overlay_cr);
/* Draw 3 circles to the punch surface, then cut
* that out of the main circle in the overlay
*/
punch_cr = cairo_create (punch);
draw_3circles (punch_cr, xc, yc, radius, 1.0);
cairo_destroy (punch_cr);
cairo_set_operator (overlay_cr, CAIRO_OPERATOR_DEST_OUT);
cairo_set_source_surface (overlay_cr, punch, 0, 0);
cairo_paint (overlay_cr);
/* Now draw the 3 circles in a subgroup again
* at half intensity, and use OperatorAdd to join up
* without seams.
*/
circles_cr = cairo_create (circles);
cairo_set_operator (circles_cr, CAIRO_OPERATOR_OVER);
draw_3circles (circles_cr, xc, yc, radius, 0.5);
cairo_destroy (circles_cr);
cairo_set_operator (overlay_cr, CAIRO_OPERATOR_ADD);
cairo_set_source_surface (overlay_cr, circles, 0, 0);
cairo_paint (overlay_cr);
cairo_destroy (overlay_cr);
cairo_set_source_surface (cr, overlay, 0, 0);
cairo_paint (cr);
cairo_surface_destroy (overlay);
cairo_surface_destroy (punch);
cairo_surface_destroy (circles);
}
static void
@@ -207,22 +322,21 @@ do_drawingarea (GtkWidget *do_widget)
gtk_window_set_child (GTK_WINDOW (window), vbox);
/*
* Create the checkerboard area
* Create the groups area
*/
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"<u>Checkerboard pattern</u>");
gtk_container_add (GTK_CONTAINER (vbox), label);
"<u>Knockout groups</u>");
gtk_box_append (GTK_BOX (vbox), label);
frame = gtk_frame_new (NULL);
gtk_widget_set_vexpand (frame, TRUE);
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
da = gtk_drawing_area_new ();
gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (da), 100);
gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (da), 100);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), checkerboard_draw, NULL, NULL);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), groups_draw, NULL, NULL);
gtk_frame_set_child (GTK_FRAME (frame), da);
/*
@@ -232,11 +346,11 @@ do_drawingarea (GtkWidget *do_widget)
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"<u>Scribble area</u>");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
frame = gtk_frame_new (NULL);
gtk_widget_set_vexpand (frame, TRUE);
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
da = gtk_drawing_area_new ();
gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (da), 100);
@@ -260,7 +374,7 @@ do_drawingarea (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -352,8 +352,7 @@ do_editable_cells (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Editable Cells");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_widget_set_margin_start (vbox, 5);
@@ -362,7 +361,7 @@ do_editable_cells (GtkWidget *do_widget)
gtk_widget_set_margin_bottom (vbox, 5);
gtk_window_set_child (GTK_WINDOW (window), vbox);
gtk_container_add (GTK_CONTAINER (vbox),
gtk_box_append (GTK_BOX (vbox),
gtk_label_new ("Shopping list (you can edit the cells!)"));
sw = gtk_scrolled_window_new (NULL, NULL);
@@ -370,7 +369,7 @@ do_editable_cells (GtkWidget *do_widget)
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (vbox), sw);
gtk_box_append (GTK_BOX (vbox), sw);
/* create models */
items_model = create_items_model ();
@@ -392,17 +391,17 @@ do_editable_cells (GtkWidget *do_widget)
/* some buttons */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_box_append (GTK_BOX (vbox), hbox);
button = gtk_button_new_with_label ("Add item");
g_signal_connect (button, "clicked",
G_CALLBACK (add_item), treeview);
gtk_container_add (GTK_CONTAINER (hbox), button);
gtk_box_append (GTK_BOX (hbox), button);
button = gtk_button_new_with_label ("Remove item");
g_signal_connect (button, "clicked",
G_CALLBACK (remove_item), treeview);
gtk_container_add (GTK_CONTAINER (hbox), button);
gtk_box_append (GTK_BOX (hbox), button);
gtk_window_set_default_size (GTK_WINDOW (window), 320, 200);
}
@@ -410,7 +409,7 @@ do_editable_cells (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -50,9 +50,7 @@ do_entry_completion (GtkWidget *do_widget)
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Entry Completion");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_widget_set_margin_start (vbox, 5);
@@ -63,11 +61,11 @@ do_entry_completion (GtkWidget *do_widget)
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), "Completion demo, try writing <b>total</b> or <b>gnome</b> for example.");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
/* Create our entry */
entry = gtk_entry_new ();
gtk_container_add (GTK_CONTAINER (vbox), entry);
gtk_box_append (GTK_BOX (vbox), entry);
/* Create the completion object */
completion = gtk_entry_completion_new ();
@@ -88,7 +86,7 @@ do_entry_completion (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -25,8 +25,7 @@ do_entry_undo (GtkWidget *do_widget)
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Entry Undo");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_widget_set_margin_start (vbox, 5);
@@ -38,18 +37,18 @@ do_entry_undo (GtkWidget *do_widget)
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"Use Primary+z or Primary+Shift+z to undo or redo changes");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
/* Create our entry */
entry = gtk_entry_new ();
gtk_editable_set_enable_undo (GTK_EDITABLE (entry), TRUE);
gtk_container_add (GTK_CONTAINER (vbox), entry);
gtk_box_append (GTK_BOX (vbox), entry);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -15,7 +15,7 @@ static GtkWidget *window = NULL;
static void
response_cb (GtkDialog *dialog, gint response_id)
{
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
window = NULL;
}
@@ -79,8 +79,8 @@ do_expander (GtkWidget *do_widget)
"innuendo, just to make you scroll down or "
"resize the window. Do it already !", -1);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), tv);
gtk_container_add (GTK_CONTAINER (expander), sw);
gtk_container_add (GTK_CONTAINER (area), expander);
gtk_expander_set_child (GTK_EXPANDER (expander), sw);
gtk_box_append (GTK_BOX (area), expander);
g_signal_connect (expander, "notify::expanded",
G_CALLBACK (expander_cb), window);
@@ -90,7 +90,7 @@ do_expander (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -125,8 +125,7 @@ do_filtermodel (GtkWidget *do_widget)
window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
store = (GtkListStore*)gtk_builder_get_object (builder, "liststore1");
@@ -199,7 +198,7 @@ do_filtermodel (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -249,6 +249,14 @@ fishbowl_changes_toggled_cb (GtkToggleButton *button,
gtk_button_set_icon_name (GTK_BUTTON (button), "changes-allow");
}
char *
format_header_cb (GObject *object,
guint count,
double fps)
{
return g_strdup_printf ("%u Icons, %.2f fps", count, fps);
}
GtkWidget *
do_fishbowl (GtkWidget *do_widget)
{
@@ -273,15 +281,13 @@ do_fishbowl (GtkWidget *do_widget)
builder = gtk_builder_new_from_resource ("/fishbowl/fishbowl.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
bowl = GTK_WIDGET (gtk_builder_get_object (builder, "bowl"));
selected_widget_type = -1;
set_widget_type (GTK_FISHBOWL (bowl), 0);
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
gtk_widget_realize (window);
g_object_unref (builder);
@@ -290,7 +296,7 @@ do_fishbowl (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -28,22 +28,12 @@
</child>
<child type="end">
<object class="GtkLabel">
<property name="label">fps</property>
</object>
</child>
<child type="end">
<object class="GtkLabel">
<property name="label" bind-source="bowl" bind-property="framerate-string"/>
</object>
</child>
<child type="end">
<object class="GtkLabel">
<property name="label">Icons, </property>
</object>
</child>
<child type="end">
<object class="GtkLabel">
<property name="label" bind-source="bowl" bind-property="count"/>
<binding name="label">
<closure type="gchararray" function="format_header_cb">
<lookup name="count">bowl</lookup>
<lookup name="framerate">bowl</lookup>
</closure>
</binding>
</object>
</child>
<child type="end">
@@ -58,6 +48,7 @@
<child>
<object class="GtkFishbowl" id="bowl">
<property name="visible">True</property>
<property name="overflow">hidden</property>
<property name="animating">True</property>
<property name="benchmark" bind-source="changes_allow" bind-property="active" bind-flags="invert-boolean | sync-create"/>
</object>

View File

@@ -53,7 +53,7 @@ create_faces (void)
faces[i].face = gtk_frame_new (NULL);
gtk_widget_set_size_request (faces[i].face, face_size, face_size);
gtk_widget_add_css_class (faces[i].face, faces[i].css_class);
gtk_container_add (GTK_CONTAINER (fixed), faces[i].face);
gtk_fixed_put (GTK_FIXED (fixed), faces[i].face, 0, 0);
/* Set up the transformation for each face */
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (w, h));
@@ -139,7 +139,7 @@ create_demo_window (GtkWidget *do_widget)
gtk_widget_set_valign (GTK_WIDGET (fixed), GTK_ALIGN_CENTER);
cube = create_faces ();
gtk_container_add (GTK_CONTAINER (fixed), cube);
gtk_fixed_put (GTK_FIXED (fixed), cube, 0, 0);
gtk_widget_set_overflow (fixed, GTK_OVERFLOW_VISIBLE);
provider = gtk_css_provider_new ();
@@ -161,7 +161,7 @@ do_fixed (GtkWidget *do_widget)
if (!gtk_widget_get_visible (demo_window))
gtk_widget_show (demo_window);
else
gtk_widget_destroy (demo_window);
gtk_window_destroy (GTK_WINDOW (demo_window));
return demo_window;
}

View File

@@ -4,6 +4,8 @@
* as needed and support sorting and filtering.
*
* The children of a GtkFlowBox are regular widgets
*
* The dataset used here has 665 colors.
*/
#include <gtk/gtk.h>
@@ -724,9 +726,7 @@ do_flowbox (GtkWidget *do_widget)
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Flow Box");
gtk_window_set_default_size (GTK_WINDOW (window), 400, 600);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
scrolled = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
@@ -739,13 +739,13 @@ do_flowbox (GtkWidget *do_widget)
gtk_window_set_child (GTK_WINDOW (window), scrolled);
for (i = 0; colors[i]; i++)
gtk_container_add (GTK_CONTAINER (flowbox), color_swatch_new (colors[i]));
gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), color_swatch_new (colors[i]), -1);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -194,7 +194,7 @@ add_check_group (GtkWidget *box,
pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
gtk_label_set_attributes (GTK_LABEL (label), attrs);
pango_attr_list_unref (attrs);
gtk_container_add (GTK_CONTAINER (group), label);
gtk_box_append (GTK_BOX (group), label);
for (i = 0; tags[i]; i++)
{
@@ -211,7 +211,7 @@ add_check_group (GtkWidget *box,
g_signal_connect (feat, "notify::inconsistent", G_CALLBACK (update_display), NULL);
g_signal_connect (feat, "clicked", G_CALLBACK (feat_clicked), NULL);
gtk_container_add (GTK_CONTAINER (group), feat);
gtk_box_append (GTK_BOX (group), feat);
item = g_new (FeatureItem, 1);
item->name = tags[i];
@@ -223,7 +223,7 @@ add_check_group (GtkWidget *box,
feature_items = g_list_prepend (feature_items, item);
}
gtk_container_add (GTK_CONTAINER (box), group);
gtk_box_append (GTK_BOX (box), group);
}
static void
@@ -248,7 +248,7 @@ add_radio_group (GtkWidget *box,
pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
gtk_label_set_attributes (GTK_LABEL (label), attrs);
pango_attr_list_unref (attrs);
gtk_container_add (GTK_CONTAINER (group), label);
gtk_box_append (GTK_BOX (group), label);
for (i = 0; tags[i]; i++)
{
@@ -268,7 +268,7 @@ add_radio_group (GtkWidget *box,
g_signal_connect (feat, "notify::active", G_CALLBACK (update_display), NULL);
g_object_set_data (G_OBJECT (feat), "default", group_button);
gtk_container_add (GTK_CONTAINER (group), feat);
gtk_box_append (GTK_BOX (group), feat);
item = g_new (FeatureItem, 1);
item->name = tags[i];
@@ -280,7 +280,7 @@ add_radio_group (GtkWidget *box,
feature_items = g_list_prepend (feature_items, item);
}
gtk_container_add (GTK_CONTAINER (box), group);
gtk_box_append (GTK_BOX (box), group);
}
static void
@@ -1025,7 +1025,7 @@ denorm_coord (hb_ot_var_axis_info_t *axis, int coord)
static void
update_font_variations (void)
{
GtkWidget *child, *next;
GtkWidget *child;
PangoFont *pango_font = NULL;
hb_font_t *hb_font;
hb_face_t *hb_face;
@@ -1037,12 +1037,8 @@ update_font_variations (void)
int i;
child = gtk_widget_get_first_child (variations_grid);
while (child != NULL)
{
next = gtk_widget_get_next_sibling (child);
gtk_widget_destroy (child);
child = next;
}
while ((child = gtk_widget_get_first_child (variations_grid)))
gtk_grid_remove (GTK_GRID (variations_grid), child);
instance_combo = NULL;
@@ -1333,8 +1329,7 @@ do_font_features (GtkWidget *do_widget)
font_features_font_changed ();
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
g_object_unref (builder);
@@ -1344,7 +1339,7 @@ do_font_features (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_window_present (GTK_WINDOW (window));
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -281,7 +281,7 @@ do_fontrendering (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -53,7 +53,7 @@ create_axis_slider (GtkGears *gears,
}
label = gtk_label_new (text);
gtk_container_add (GTK_CONTAINER (box), label);
gtk_box_append (GTK_BOX (box), label);
gtk_widget_show (label);
adj = gtk_adjustment_new (gtk_gears_get_axis (gears, axis), 0.0, 360.0, 1.0, 12.0, 0.0);
@@ -63,7 +63,7 @@ create_axis_slider (GtkGears *gears,
gears);
slider = gtk_scale_new (GTK_ORIENTATION_VERTICAL, adj);
gtk_scale_set_draw_value (GTK_SCALE (slider), FALSE);
gtk_container_add (GTK_CONTAINER (box), slider);
gtk_box_append (GTK_BOX (box), slider);
gtk_widget_set_vexpand (slider, TRUE);
gtk_widget_show (slider);
@@ -85,7 +85,7 @@ do_gears (GtkWidget *do_widget)
gtk_window_set_title (GTK_WINDOW (window), "Gears");
gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
gtk_window_set_default_size (GTK_WINDOW (window), 640, 640);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
overlay = gtk_overlay_new ();
gtk_widget_set_margin_start (overlay, 12);
@@ -111,19 +111,19 @@ do_gears (GtkWidget *do_widget)
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE);
gtk_box_set_spacing (GTK_BOX (box), 6);
gtk_container_add (GTK_CONTAINER (box), hbox);
gtk_box_append (GTK_BOX (box), hbox);
gears = gtk_gears_new ();
gtk_widget_set_hexpand (gears, TRUE);
gtk_widget_set_vexpand (gears, TRUE);
gtk_container_add (GTK_CONTAINER (hbox), gears);
gtk_box_append (GTK_BOX (hbox), gears);
for (i = 0; i < GTK_GEARS_N_AXIS; i++)
gtk_container_add (GTK_CONTAINER (hbox), create_axis_slider (GTK_GEARS (gears), i));
gtk_box_append (GTK_BOX (hbox), create_axis_slider (GTK_GEARS (gears), i));
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE);
gtk_box_set_spacing (GTK_BOX (hbox), 6);
gtk_container_add (GTK_CONTAINER (box), hbox);
gtk_box_append (GTK_BOX (box), hbox);
gtk_gears_set_fps_label (GTK_GEARS (gears), GTK_LABEL (fps_label));
}
@@ -131,7 +131,7 @@ do_gears (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -13,17 +13,16 @@ in_files = sys.argv[2:]
file_output = """
typedef GtkWidget *(*GDoDemoFunc) (GtkWidget *do_widget);
typedef struct _Demo Demo;
typedef struct _DemoData DemoData;
struct _Demo
struct _DemoData
{
const char *name;
const char *title;
const char *filename;
GDoDemoFunc func;
Demo *children;
DemoData *children;
};
"""
# Demo = namedtuple('Demo', ['name', 'title', 'file', 'func'])
@@ -67,7 +66,7 @@ for demo in demos:
i = 0
for parent in parents:
id = parent_ids[i]
file_output += "\nDemo child" + str(id) + "[] = {\n"
file_output += "\nDemoData child" + str(id) + "[] = {\n"
# iterate over all demos and check if the name starts with the given parent name
for child in demos:
if child[1].startswith(parent + "/"):
@@ -82,7 +81,7 @@ for parent in parents:
# Sort demos by title
demos = sorted(demos, key=lambda x: x[1])
file_output += "\nDemo gtk_demos[] = {\n"
file_output += "\nDemoData gtk_demos[] = {\n"
for demo in demos:
# Do not generate one of these for demos with a parent demo
if "/" not in demo[1]:

View File

@@ -149,8 +149,7 @@ do_gestures (GtkWidget *do_widget)
window = gtk_window_new ();
gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
gtk_window_set_title (GTK_WINDOW (window), "Gestures");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
drawing_area = gtk_drawing_area_new ();
gtk_window_set_child (GTK_WINDOW (window), drawing_area);
@@ -210,7 +209,7 @@ do_gestures (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -354,7 +354,7 @@ create_axis_slider (int axis)
}
label = gtk_label_new (text);
gtk_container_add (GTK_CONTAINER (box), label);
gtk_box_append (GTK_BOX (box), label);
gtk_widget_show (label);
adj = gtk_adjustment_new (0.0, 0.0, 360.0, 1.0, 12.0, 0.0);
@@ -362,7 +362,7 @@ create_axis_slider (int axis)
G_CALLBACK (on_axis_value_change),
GINT_TO_POINTER (axis));
slider = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, adj);
gtk_container_add (GTK_CONTAINER (box), slider);
gtk_box_append (GTK_BOX (box), slider);
gtk_widget_set_hexpand (slider, TRUE);
gtk_widget_show (slider);
@@ -406,7 +406,7 @@ create_glarea_window (GtkWidget *do_widget)
gl_area = gtk_gl_area_new ();
gtk_widget_set_hexpand (gl_area, TRUE);
gtk_widget_set_vexpand (gl_area, TRUE);
gtk_container_add (GTK_CONTAINER (box), gl_area);
gtk_box_append (GTK_BOX (box), gl_area);
/* We need to initialize and free GL resources, so we use
* the realize and unrealize signals on the widget
@@ -418,16 +418,16 @@ create_glarea_window (GtkWidget *do_widget)
g_signal_connect (gl_area, "render", G_CALLBACK (render), NULL);
controls = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE);
gtk_container_add (GTK_CONTAINER (box), controls);
gtk_box_append (GTK_BOX (box), controls);
gtk_widget_set_hexpand (controls, TRUE);
for (i = 0; i < N_AXIS; i++)
gtk_container_add (GTK_CONTAINER (controls), create_axis_slider (i));
gtk_box_append (GTK_BOX (controls), create_axis_slider (i));
button = gtk_button_new_with_label ("Quit");
gtk_widget_set_hexpand (button, TRUE);
gtk_container_add (GTK_CONTAINER (box), button);
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
gtk_box_append (GTK_BOX (box), button);
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_destroy), window);
return window;
}
@@ -441,7 +441,7 @@ do_glarea (GtkWidget *do_widget)
if (!gtk_widget_get_visible (demo_window))
gtk_widget_show (demo_window);
else
gtk_widget_destroy (demo_window);
gtk_window_destroy (GTK_WINDOW (demo_window));
return demo_window;
}

View File

@@ -53,7 +53,6 @@ enum {
PROP_BENCHMARK,
PROP_COUNT,
PROP_FRAMERATE,
PROP_FRAMERATE_STRING,
PROP_UPDATE_DELAY,
NUM_PROPERTIES
};
@@ -289,14 +288,6 @@ gtk_fishbowl_get_property (GObject *object,
g_value_set_double (value, gtk_fishbowl_get_framerate (fishbowl));
break;
case PROP_FRAMERATE_STRING:
{
char *s = g_strdup_printf ("%.2f", gtk_fishbowl_get_framerate (fishbowl));
g_value_set_string (value, s);
g_free (s);
}
break;
case PROP_UPDATE_DELAY:
g_value_set_int64 (value, gtk_fishbowl_get_update_delay (fishbowl));
break;
@@ -350,13 +341,6 @@ gtk_fishbowl_class_init (GtkFishbowlClass *klass)
0,
G_PARAM_READABLE);
props[PROP_FRAMERATE_STRING] =
g_param_spec_string ("framerate-string",
"Framerate as string",
"Framerate as string, with 2 decimals",
NULL,
G_PARAM_READABLE);
props[PROP_UPDATE_DELAY] =
g_param_spec_int64 ("update-delay",
"Update delay",
@@ -508,7 +492,6 @@ gtk_fishbowl_do_update (GtkFishbowl *fishbowl)
priv->framerate = ((int)(priv->framerate * 100))/100.0;
g_object_notify_by_pspec (G_OBJECT (fishbowl), props[PROP_FRAMERATE]);
g_object_notify_by_pspec (G_OBJECT (fishbowl), props[PROP_FRAMERATE_STRING]);
if (!priv->benchmark)
return;

View File

@@ -197,7 +197,7 @@ gtk_gears_class_init (GtkGearsClass *klass)
* @param v the vertex to fill
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coortinate
* @param z the z coordinate
* @param n pointer to the normal table
*
* @return the operation error code

View File

@@ -25,8 +25,8 @@ do_headerbar (GtkWidget *do_widget)
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window), gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Welcome to Facebook - Log in, sign up or learn more");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
header = gtk_header_bar_new ();
@@ -43,10 +43,10 @@ do_headerbar (GtkWidget *do_widget)
gtk_widget_add_css_class (box, "linked");
button = gtk_button_new ();
gtk_button_set_child (GTK_BUTTON (button), gtk_image_new_from_icon_name ("pan-start-symbolic"));
gtk_container_add (GTK_CONTAINER (box), button);
gtk_box_append (GTK_BOX (box), button);
button = gtk_button_new ();
gtk_button_set_child (GTK_BUTTON (button), gtk_image_new_from_icon_name ("pan-end-symbolic"));
gtk_container_add (GTK_CONTAINER (box), button);
gtk_box_append (GTK_BOX (box), button);
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), box);
@@ -58,7 +58,7 @@ do_headerbar (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -237,9 +237,7 @@ do_hypertext (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_default_size (GTK_WINDOW (window), 450, 450);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
view = gtk_text_view_new ();
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
@@ -275,7 +273,7 @@ do_hypertext (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -12,7 +12,7 @@ static GtkWidget *window = NULL;
static GtkWidget *scrolledwindow;
static int selected;
#define N_WIDGET_TYPES 4
#define N_WIDGET_TYPES 6
static int hincrement = 5;
@@ -64,6 +64,7 @@ populate_icons (void)
gtk_grid_attach (GTK_GRID (grid), create_icon (), left, top, 1, 1);
hincrement = 0;
vincrement = 5;
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_POLICY_NEVER,
@@ -100,6 +101,7 @@ populate_text (gboolean hilight)
gtk_text_view_set_buffer (GTK_TEXT_VIEW (textview), buffer);
hincrement = 0;
vincrement = 5;
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_POLICY_NEVER,
@@ -124,6 +126,7 @@ populate_image (void)
gtk_picture_set_can_shrink (GTK_PICTURE (image), FALSE);
hincrement = 5;
vincrement = 5;
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_POLICY_AUTOMATIC,
@@ -131,6 +134,42 @@ populate_image (void)
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolledwindow), image);
}
extern GtkWidget *create_weather_view (void);
static void
populate_list (void)
{
GtkWidget *list;
list = create_weather_view ();
hincrement = 5;
vincrement = 0;
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolledwindow), list);
}
extern GtkWidget *create_color_grid (void);
static void
populate_grid (void)
{
GtkWidget *list;
list = create_color_grid ();
hincrement = 0;
vincrement = 5;
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolledwindow), list);
}
static void
set_widget_type (int type)
{
@@ -164,6 +203,16 @@ set_widget_type (int type)
populate_image ();
break;
case 4:
gtk_window_set_title (GTK_WINDOW (window), "Scrolling a list");
populate_list ();
break;
case 5:
gtk_window_set_title (GTK_WINDOW (window), "Scrolling a grid");
populate_grid ();
break;
default:
g_assert_not_reached ();
}
@@ -209,23 +258,23 @@ do_iconscroll (GtkWidget *do_widget)
builder = gtk_builder_new_from_resource ("/iconscroll/iconscroll.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
scrolledwindow = GTK_WIDGET (gtk_builder_get_object (builder, "scrolledwindow"));
gtk_widget_realize (window);
hadjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "hadjustment"));
vadjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "vadjustment"));
set_widget_type (0);
g_object_unref (builder);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -228,7 +228,7 @@ home_clicked (GtkButton *item,
static void close_window(void)
{
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
window = NULL;
g_object_unref (file_pixbuf);
@@ -266,14 +266,14 @@ do_iconview (GtkWidget *do_widget)
gtk_window_set_child (GTK_WINDOW (window), vbox);
tool_bar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (vbox), tool_bar);
gtk_box_append (GTK_BOX (vbox), tool_bar);
up_button = gtk_button_new_with_mnemonic ("_Up");
gtk_widget_set_sensitive (GTK_WIDGET (up_button), FALSE);
gtk_container_add (GTK_CONTAINER (tool_bar), up_button);
gtk_box_append (GTK_BOX (tool_bar), up_button);
home_button = gtk_button_new_with_mnemonic ("_Home");
gtk_container_add (GTK_CONTAINER (tool_bar), home_button);
gtk_box_append (GTK_BOX (tool_bar), home_button);
sw = gtk_scrolled_window_new (NULL, NULL);
@@ -283,7 +283,7 @@ do_iconview (GtkWidget *do_widget)
GTK_POLICY_AUTOMATIC);
gtk_widget_set_vexpand (sw, TRUE);
gtk_container_add (GTK_CONTAINER (vbox), sw);
gtk_box_append (GTK_BOX (vbox), sw);
/* Create the store and fill it with the contents of '/' */
parent = g_strdup ("/");
@@ -320,7 +320,7 @@ do_iconview (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -111,9 +111,7 @@ do_iconview_edit (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Editing and Drag-and-Drop");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
store = create_store ();
fill_store (store);
@@ -152,7 +150,7 @@ do_iconview_edit (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -91,7 +91,7 @@ progressive_timeout (gpointer data)
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
G_CALLBACK (gtk_window_destroy), NULL);
g_object_unref (image_stream);
image_stream = NULL;
@@ -119,7 +119,7 @@ progressive_timeout (gpointer data)
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
G_CALLBACK (gtk_window_destroy), NULL);
g_object_unref (image_stream);
image_stream = NULL;
@@ -152,7 +152,7 @@ progressive_timeout (gpointer data)
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
@@ -189,7 +189,7 @@ progressive_timeout (gpointer data)
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
@@ -223,7 +223,7 @@ progressive_timeout (gpointer data)
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
@@ -293,24 +293,16 @@ static void
toggle_sensitivity_callback (GtkWidget *togglebutton,
gpointer user_data)
{
GtkContainer *container = user_data;
GList *list;
GList *tmp;
GtkWidget *child;
list = gtk_container_get_children (container);
tmp = list;
while (tmp != NULL)
for (child = gtk_widget_get_first_child (GTK_WIDGET (user_data));
child != NULL;
child = gtk_widget_get_next_sibling (child))
{
/* don't disable our toggle */
if (GTK_WIDGET (tmp->data) != togglebutton)
gtk_widget_set_sensitive (GTK_WIDGET (tmp->data),
!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (togglebutton)));
tmp = tmp->next;
if (child != togglebutton)
gtk_widget_set_sensitive (child, !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (togglebutton)));
}
g_list_free (list);
}
@@ -335,9 +327,8 @@ do_images (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Images");
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_signal_connect (window, "destroy",
G_CALLBACK (cleanup_callback), NULL);
@@ -349,20 +340,20 @@ do_images (GtkWidget *do_widget)
gtk_window_set_child (GTK_WINDOW (window), base_vbox);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 16);
gtk_container_add (GTK_CONTAINER (base_vbox), hbox);
gtk_box_append (GTK_BOX (base_vbox), hbox);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
gtk_container_add (GTK_CONTAINER (hbox), vbox);
gtk_box_append (GTK_BOX (hbox), vbox);
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"<u>Image loaded from a file</u>");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
frame = gtk_frame_new (NULL);
gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
image = gtk_image_new_from_icon_name ("gtk3-demo");
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
@@ -375,12 +366,12 @@ do_images (GtkWidget *do_widget)
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"<u>Animation loaded from a file</u>");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
frame = gtk_frame_new (NULL);
gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
picture = gtk_picture_new_for_resource ("/images/floppybuddy.gif");
@@ -391,12 +382,12 @@ do_images (GtkWidget *do_widget)
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"<u>Symbolic themed icon</u>");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
frame = gtk_frame_new (NULL);
gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
gicon = g_themed_icon_new_with_default_fallbacks ("battery-caution-charging-symbolic");
image = gtk_image_new_from_gicon (gicon);
@@ -407,17 +398,17 @@ do_images (GtkWidget *do_widget)
/* Progressive */
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
gtk_container_add (GTK_CONTAINER (hbox), vbox);
gtk_box_append (GTK_BOX (hbox), vbox);
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"<u>Progressive image loading</u>");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
frame = gtk_frame_new (NULL);
gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
/* Create an empty image for now; the progressive loader
* will create the pixbuf and fill it in.
@@ -429,17 +420,17 @@ do_images (GtkWidget *do_widget)
/* Video */
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
gtk_container_add (GTK_CONTAINER (hbox), vbox);
gtk_box_append (GTK_BOX (hbox), vbox);
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"<u>Displaying video</u>");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
frame = gtk_frame_new (NULL);
gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
gtk_widget_set_valign (frame, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
video = gtk_video_new_for_resource ("/images/gtk-logo.webm");
gtk_media_stream_set_loop (gtk_video_get_media_stream (GTK_VIDEO (video)), TRUE);
@@ -447,22 +438,22 @@ do_images (GtkWidget *do_widget)
/* Widget paintables */
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
gtk_container_add (GTK_CONTAINER (hbox), vbox);
gtk_box_append (GTK_BOX (hbox), vbox);
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label),
"<u>GtkWidgetPaintable</u>");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
paintable = gtk_widget_paintable_new (do_widget);
picture = gtk_picture_new_for_paintable (paintable);
gtk_widget_set_size_request (picture, 100, 100);
gtk_widget_set_valign (picture, GTK_ALIGN_START);
gtk_container_add (GTK_CONTAINER (vbox), picture);
gtk_box_append (GTK_BOX (vbox), picture);
/* Sensitivity control */
button = gtk_toggle_button_new_with_mnemonic ("_Insensitive");
gtk_container_add (GTK_CONTAINER (base_vbox), button);
gtk_box_append (GTK_BOX (base_vbox), button);
g_signal_connect (button, "toggled",
G_CALLBACK (toggle_sensitivity_callback),
@@ -472,7 +463,7 @@ do_images (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -29,10 +29,8 @@ on_bar_response (GtkInfoBar *info_bar,
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"Your response has id %d", response_id);
g_signal_connect_swapped (dialog,
"response",
G_CALLBACK (gtk_widget_destroy),
dialog);
g_signal_connect_swapped (dialog, "response",
G_CALLBACK (gtk_window_destroy), dialog);
gtk_widget_show (dialog);
}
@@ -58,8 +56,7 @@ do_infobar (GtkWidget *do_widget)
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Info Bars");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_margin_start (vbox, 8);
@@ -69,73 +66,73 @@ do_infobar (GtkWidget *do_widget)
gtk_window_set_child (GTK_WINDOW (window), vbox);
bar = gtk_info_bar_new ();
gtk_container_add (GTK_CONTAINER (vbox), bar);
gtk_box_append (GTK_BOX (vbox), bar);
gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_INFO);
label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_INFO");
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_container_add (GTK_CONTAINER (bar), label);
gtk_info_bar_add_child (GTK_INFO_BAR (bar), label);
button = gtk_toggle_button_new_with_label ("Message");
g_object_bind_property (bar, "revealed", button, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
gtk_container_add (GTK_CONTAINER (actions), button);
gtk_box_append (GTK_BOX (actions), button);
bar = gtk_info_bar_new ();
gtk_container_add (GTK_CONTAINER (vbox), bar);
gtk_box_append (GTK_BOX (vbox), bar);
gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_WARNING);
label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_WARNING");
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_container_add (GTK_CONTAINER (bar), label);
gtk_info_bar_add_child (GTK_INFO_BAR (bar), label);
button = gtk_toggle_button_new_with_label ("Warning");
g_object_bind_property (bar, "revealed", button, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
gtk_container_add (GTK_CONTAINER (actions), button);
gtk_box_append (GTK_BOX (actions), button);
bar = gtk_info_bar_new_with_buttons (_("_OK"), GTK_RESPONSE_OK, NULL);
gtk_info_bar_set_show_close_button (GTK_INFO_BAR (bar), TRUE);
g_signal_connect (bar, "response", G_CALLBACK (on_bar_response), window);
gtk_container_add (GTK_CONTAINER (vbox), bar);
gtk_box_append (GTK_BOX (vbox), bar);
gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_QUESTION);
label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_QUESTION");
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_container_add (GTK_CONTAINER (bar), label);
gtk_info_bar_add_child (GTK_INFO_BAR (bar), label);
gtk_info_bar_set_default_response (GTK_INFO_BAR (bar), GTK_RESPONSE_OK);
button = gtk_toggle_button_new_with_label ("Question");
g_object_bind_property (bar, "revealed", button, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
gtk_container_add (GTK_CONTAINER (actions), button);
gtk_box_append (GTK_BOX (actions), button);
bar = gtk_info_bar_new ();
gtk_container_add (GTK_CONTAINER (vbox), bar);
gtk_box_append (GTK_BOX (vbox), bar);
gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_ERROR);
label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_ERROR");
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_container_add (GTK_CONTAINER (bar), label);
gtk_info_bar_add_child (GTK_INFO_BAR (bar), label);
button = gtk_toggle_button_new_with_label ("Error");
g_object_bind_property (bar, "revealed", button, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
gtk_container_add (GTK_CONTAINER (actions), button);
gtk_box_append (GTK_BOX (actions), button);
bar = gtk_info_bar_new ();
gtk_container_add (GTK_CONTAINER (vbox), bar);
gtk_box_append (GTK_BOX (vbox), bar);
gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_OTHER);
label = gtk_label_new ("This is an info bar with message type GTK_MESSAGE_OTHER");
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_xalign (GTK_LABEL (label), 0);
gtk_container_add (GTK_CONTAINER (bar), label);
gtk_info_bar_add_child (GTK_INFO_BAR (bar), label);
button = gtk_toggle_button_new_with_label ("Other");
g_object_bind_property (bar, "revealed", button, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
gtk_container_add (GTK_CONTAINER (actions), button);
gtk_box_append (GTK_BOX (actions), button);
frame = gtk_frame_new ("An example of different info bars");
gtk_widget_set_margin_top (frame, 8);
gtk_widget_set_margin_bottom (frame, 8);
gtk_container_add (GTK_CONTAINER (vbox), frame);
gtk_box_append (GTK_BOX (vbox), frame);
gtk_widget_set_halign (actions, GTK_ALIGN_CENTER);
@@ -149,7 +146,7 @@ do_infobar (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -12,7 +12,7 @@ response_cb (GtkWidget *dialog,
gint response_id,
gpointer data)
{
gtk_widget_destroy (dialog);
gtk_window_destroy (GTK_WINDOW (dialog));
}
static gboolean
@@ -59,8 +59,7 @@ do_links (GtkWidget *do_widget)
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Links");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
label = gtk_label_new ("Some <a href=\"http://en.wikipedia.org/wiki/Text\""
"title=\"plain text\">text</a> may be marked up "
@@ -88,7 +87,7 @@ do_links (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -257,9 +257,7 @@ do_list_store (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "List Store");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
gtk_widget_set_margin_start (vbox, 8);
@@ -269,14 +267,14 @@ do_list_store (GtkWidget *do_widget)
gtk_window_set_child (GTK_WINDOW (window), vbox);
label = gtk_label_new ("This is the bug list (note: not based on real data, it would be nice to have a nice ODBC interface to bugzilla or so, though).");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (vbox), sw);
gtk_box_append (GTK_BOX (vbox), sw);
/* create tree model */
model = create_model ();
@@ -309,7 +307,7 @@ do_list_store (GtkWidget *do_widget)
}
else
{
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
window = NULL;
if (timeout != 0)
{

View File

@@ -8,6 +8,7 @@
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include "award.h"
static GdkPixbuf *avatar_pixbuf_other;
static GtkWidget *window = NULL;
@@ -234,9 +235,9 @@ reshare_clicked (GtkMessageRow *row,
{
GtkMessageRowPrivate *priv = row->priv;
award ("listbox-reshare");
priv->message->n_reshares++;
gtk_message_row_update (row);
}
static void
@@ -255,11 +256,14 @@ gtk_message_row_state_flags_changed (GtkWidget *widget,
{
GtkMessageRowPrivate *priv = GTK_MESSAGE_ROW (widget)->priv;
GtkStateFlags flags;
gboolean visible;
flags = gtk_widget_get_state_flags (widget);
gtk_widget_set_visible (priv->extra_buttons_box,
flags & (GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED));
visible = flags & (GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED) ? TRUE : FALSE;
gtk_widget_set_visible (priv->extra_buttons_box, visible);
if (visible && gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (widget)) % 100 == 99)
award ("listbox-100th-row");
GTK_WIDGET_CLASS (gtk_message_row_parent_class)->state_flags_changed (widget, previous_state_flags);
}
@@ -351,22 +355,17 @@ do_listbox (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "List Box");
gtk_window_set_default_size (GTK_WINDOW (window),
400, 600);
/* NULL window variable when window is closed */
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&window);
gtk_window_set_default_size (GTK_WINDOW (window), 400, 600);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_window_set_child (GTK_WINDOW (window), vbox);
label = gtk_label_new ("Messages from GTK and friends");
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
scrolled = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_widget_set_vexpand (scrolled, TRUE);
gtk_container_add (GTK_CONTAINER (vbox), scrolled);
gtk_box_append (GTK_BOX (vbox), scrolled);
listbox = gtk_list_box_new ();
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled), listbox);
@@ -382,7 +381,7 @@ do_listbox (GtkWidget *do_widget)
message = gtk_message_new (lines[i]);
row = gtk_message_row_new (message);
gtk_widget_show (GTK_WIDGET (row));
gtk_container_add (GTK_CONTAINER (listbox), GTK_WIDGET (row));
gtk_list_box_insert (GTK_LIST_BOX (listbox), GTK_WIDGET (row), -1);
}
g_strfreev (lines);
@@ -392,7 +391,7 @@ do_listbox (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -150,7 +150,7 @@
</object>
</child>
<child>
<object class="GtkButton" id="favorite-buttton">
<object class="GtkButton" id="favorite-button">
<property name="label" translatable="yes">Favorite</property>
<property name="receives-default">1</property>
<property name="has-frame">0</property>

View File

@@ -0,0 +1,199 @@
/* Lists/Application launcher
*
* This demo uses the GtkCoverFlow widget as a fancy application launcher.
*
* It is also a very small introduction to listviews.
*/
#include <gtk/gtk.h>
/* This is the function that creates the #GListModel that we need.
* GTK list widgets need a #GListModel to display, as models support change
* notifications.
* Unfortunately various older APIs do not provide list models, so we create
* our own.
*/
static GListModel *
create_application_list (void)
{
GListStore *store;
GList *apps, *l;
/* We use a #GListStore here, which is a simple array-like list implementation
* for manual management.
* List models need to know what type of data they provide, so we need to
* provide the type here. As we want to do a list of applications, #GAppInfo
* is the object we provide.
*/
store = g_list_store_new (G_TYPE_APP_INFO);
apps = g_app_info_get_all ();
for (l = apps; l; l = l->next)
{
g_list_store_append (store, l->data);
}
g_list_free_full (apps, g_object_unref);
return G_LIST_MODEL (store);
}
/* This is the function we use for setting up new listitems to display.
* We add just a #GtkImage here to display the application's icon as this is just
* a simple demo.
*/
static void
setup_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *image;
image = gtk_image_new ();
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
gtk_list_item_set_child (list_item, image);
}
/* Here we need to prepare the listitem for displaying its item. We get the
* listitem already set up from the previous function, so we can reuse the
* #GtkImage widget we set up above.
* We get the item - which we know is a #GAppInfo because it comes out of
* the model we set up above, grab its icon and display it.
*/
static void
bind_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *image;
GAppInfo *app_info;
image = gtk_list_item_get_child (list_item);
app_info = gtk_list_item_get_item (list_item);
gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info));
}
/* In more complex code, we would also need functions to unbind and teardown
* the listitem, but this is simple code, so the default implementations are
* enough. If we had connected signals, this step would have been necessary.
*
* The #GtkSignalListItemFactory documentation contains more information about
* this step.
*/
/* This function is called whenever an item in the list is activated. This is
* the simple way to allow reacting to the Enter key or double-clicking on a
* listitem.
* Of course, it is possible to use far more complex interactions by turning
* off activation and adding buttons or other widgets in the setup function
* above, but this is a simple demo, so we'll use the simple way.
*/
static void
activate_cb (GtkCoverFlow *coverflow,
guint position,
gpointer unused)
{
GAppInfo *app_info;
GdkAppLaunchContext *context;
GError *error = NULL;
app_info = g_list_model_get_item (gtk_cover_flow_get_model (coverflow), position);
/* Prepare the context for launching the application and launch it. This
* code is explained in detail in the documentation for #GdkAppLaunchContext
* and #GAppInfo.
*/
context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (coverflow)));
if (!g_app_info_launch (app_info,
NULL,
G_APP_LAUNCH_CONTEXT (context),
&error))
{
GtkWidget *dialog;
/* And because error handling is important, even a simple demo has it:
* We display an error dialog that something went wrong.
*/
dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (coverflow))),
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Could not launch %s", g_app_info_get_display_name (app_info));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
g_clear_error (&error);
gtk_widget_show (dialog);
}
g_object_unref (context);
g_object_unref (app_info);
}
static GtkWidget *window = NULL;
GtkWidget *
do_listview_applauncher (GtkWidget *do_widget)
{
if (window == NULL)
{
GtkWidget *coverflow, *sw;;
GListModel *model;
GtkListItemFactory *factory;
/* Create a window and set a few defaults */
window = gtk_window_new ();
gtk_window_set_default_size (GTK_WINDOW (window), 640, 320);
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Application Launcher");
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &window);
/* The #GtkListitemFactory is what is used to create #GtkListItems
* to display the data from the model. So it is absolutely necessary
* to create one.
* We will use a #GtkSignalListItemFactory because it is the simplest
* one to use. Different ones are available for different use cases.
* The most powerful one is #GtkBuilderListItemFactory which uses
* #GtkBuilder .ui files, so it requires little code.
*/
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
/* Create the list widget here: We use a coverflow widget because it's
* the coolest one. We could just as well use other list widgets such
* as a #GtkListView or a #GtkGridView and the code would look very
* similar.
*/
coverflow = gtk_cover_flow_new_with_factory (factory);
/* We connect the activate signal here. It's the function we defined
* above for launching the selected application.
*/
g_signal_connect (coverflow, "activate", G_CALLBACK (activate_cb), NULL);
/* And of course we need to set the data model. Here we call the function
* we wrote above that gives us the list of applications. Then we set
* it on the coverflow list widget.
* The coverflow will now take items from the model and use the factory
* to create as many listitems as it needs to show itself to the user.
*/
model = create_application_list ();
gtk_cover_flow_set_model (GTK_COVER_FLOW (coverflow), model);
g_object_unref (model);
/* List widgets should always be contained in a #GtkScrolledWindow,
* because otherwise they might get too large or they might not
* be scrollable.
*/
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_window_set_child (GTK_WINDOW (window), sw);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), coverflow);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -0,0 +1,489 @@
/* Lists/Clocks
*
* This demo displays the time in different timezones.
*
* The goal is to show how to set up expressions that track changes
* in objects and make them update widgets.
*
* For that, we create a GtkClock object that updates its time every
* second and then use various ways to display that time.
*
* Typically, this will be done using GtkBuilder .ui files with the
* help of the <binding> tag, but this demo shows the code that runs
* behind that.
*/
#include <gtk/gtk.h>
#define GTK_TYPE_CLOCK (gtk_clock_get_type ())
G_DECLARE_FINAL_TYPE (GtkClock, gtk_clock, GTK, CLOCK, GObject)
/* This is our object. It's just a timezone */
typedef struct _GtkClock GtkClock;
struct _GtkClock
{
GObject parent_instance;
/* We allow this to be NULL for the local timezone */
GTimeZone *timezone;
/* Name of the location we're displaying time for */
char *location;
};
enum {
PROP_0,
PROP_LOCATION,
PROP_TIME,
PROP_TIMEZONE,
N_PROPS
};
/* This function returns the current time in the clock's timezone.
* Note that this returns a new object every time, so we need to
* remember to unref it after use. */
static GDateTime *
gtk_clock_get_time (GtkClock *clock)
{
if (clock->timezone)
return g_date_time_new_now (clock->timezone);
else
return g_date_time_new_now_local ();
}
/* Here, we implement the functionality required by the GdkPaintable interface.
* This way we have a trivial way to display an analog clock.
* It also allows demonstrating how to directly use objects in the listview
* later by making this object do something interesting. */
static void
gtk_clock_snapshot (GdkPaintable *paintable,
GdkSnapshot *snapshot,
double width,
double height)
{
GtkClock *self = GTK_CLOCK (paintable);
GDateTime *time;
GskRoundedRect outline;
#define BLACK ((GdkRGBA) { 0, 0, 0, 1 })
/* save/restore() is necessary so we can undo the transforms we start
* out with. */
gtk_snapshot_save (snapshot);
/* First, we move the (0, 0) point to the center of the area so
* we can draw everything relative to it. */
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (width / 2, height / 2));
/* Next we scale it, so that we can pretend that the clock is
* 100px in size. That way, we don't need to do any complicated
* math later.
* We use MIN() here so that we use the smaller dimension for sizing.
* That way we don't overdraw but keep the aspect ratio. */
gtk_snapshot_scale (snapshot, MIN (width, height) / 100.0, MIN (width, height) / 100.0);
/* Now we have a circle with diameter 100px (and radius 50px) that
* has its (0, 0) point at the center.
* Let's draw a simple clock into it. */
time = gtk_clock_get_time (self);
/* First, draw a circle. This is a neat little trick to draw a circle
* without requiring Cairo. */
gsk_rounded_rect_init_from_rect (&outline, &GRAPHENE_RECT_INIT(-50, -50, 100, 100), 50);
gtk_snapshot_append_border (snapshot,
&outline,
(float[4]) { 4, 4, 4, 4 },
(GdkRGBA [4]) { BLACK, BLACK, BLACK, BLACK });
/* Next, draw the hour hand.
* We do this using tranforms again: Instead of computing where the angle points
* to, we just rotate everything and then draw the hand as if if was :00.
* We don't even need to care about am/pm here because rotations just work. */
gtk_snapshot_save (snapshot);
gtk_snapshot_rotate (snapshot, 30 * g_date_time_get_hour (time) + 0.5 * g_date_time_get_minute (time));
gsk_rounded_rect_init_from_rect (&outline, &GRAPHENE_RECT_INIT(-2, -23, 4, 25), 2);
gtk_snapshot_push_rounded_clip (snapshot, &outline);
gtk_snapshot_append_color (snapshot, &BLACK, &outline.bounds);
gtk_snapshot_pop (snapshot);
gtk_snapshot_restore (snapshot);
/* And the same as above for the minute hand. Just make this one longer
* so people can tell the hands apart. */
gtk_snapshot_save (snapshot);
gtk_snapshot_rotate (snapshot, 6 * g_date_time_get_minute (time));
gsk_rounded_rect_init_from_rect (&outline, &GRAPHENE_RECT_INIT(-2, -43, 4, 45), 2);
gtk_snapshot_push_rounded_clip (snapshot, &outline);
gtk_snapshot_append_color (snapshot, &BLACK, &outline.bounds);
gtk_snapshot_pop (snapshot);
gtk_snapshot_restore (snapshot);
/* and finally, the second indicator. */
gtk_snapshot_save (snapshot);
gtk_snapshot_rotate (snapshot, 6 * g_date_time_get_second (time));
gsk_rounded_rect_init_from_rect (&outline, &GRAPHENE_RECT_INIT(-2, -43, 4, 10), 2);
gtk_snapshot_push_rounded_clip (snapshot, &outline);
gtk_snapshot_append_color (snapshot, &BLACK, &outline.bounds);
gtk_snapshot_pop (snapshot);
gtk_snapshot_restore (snapshot);
/* And finally, don't forget to restore the initial save() that we did for
* the initial transformations. */
gtk_snapshot_restore (snapshot);
g_date_time_unref (time);
}
/* Our desired size is 100px. That sounds okay for an analog clock */
static int
gtk_clock_get_intrinsic_width (GdkPaintable *paintable)
{
return 100;
}
static int
gtk_clock_get_intrinsic_height (GdkPaintable *paintable)
{
return 100;
}
/* Initialize the paintable interface. This way we turn our clock objects
* into objects that can be drawn.
* There are more functions to this interface to define desired size,
* but this is enough.
*/
static void
gtk_clock_paintable_init (GdkPaintableInterface *iface)
{
iface->snapshot = gtk_clock_snapshot;
iface->get_intrinsic_width = gtk_clock_get_intrinsic_width;
iface->get_intrinsic_height = gtk_clock_get_intrinsic_height;
}
/* Finally, we define the type. The important part is adding the paintable
* interface, so GTK knows that this object can indeed be drawm.
*/
G_DEFINE_TYPE_WITH_CODE (GtkClock, gtk_clock, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
gtk_clock_paintable_init))
static GParamSpec *properties[N_PROPS] = { NULL, };
static void
gtk_clock_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GtkClock *self = GTK_CLOCK (object);
switch (property_id)
{
case PROP_LOCATION:
g_value_set_string (value, self->location);
break;
case PROP_TIME:
g_value_take_boxed (value, gtk_clock_get_time (self));
break;
case PROP_TIMEZONE:
g_value_set_boxed (value, self->timezone);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_clock_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GtkClock *self = GTK_CLOCK (object);
switch (property_id)
{
case PROP_LOCATION:
self->location = g_value_dup_string (value);
break;
case PROP_TIMEZONE:
self->timezone = g_value_dup_boxed (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/* This is the list of all the ticking clocks */
static GSList *ticking_clocks = NULL;
/* This is the id of the timeout source that is updating all ticking clocks */
static guint ticking_clock_id = 0;
/* Every second, this function is called to tell everybody that the
* clocks are ticking.
*/
static gboolean
gtk_clock_tick (gpointer unused)
{
GSList *l;
for (l = ticking_clocks; l; l = l->next)
{
GtkClock *clock = l->data;
/* We will now return a different value for the time porperty,
* so notify about that.
*/
g_object_notify_by_pspec (G_OBJECT (clock), properties[PROP_TIME]);
/* We will also draw the hands of the clock differently.
* So notify about that, too.
*/
gdk_paintable_invalidate_contents (GDK_PAINTABLE (clock));
}
return G_SOURCE_CONTINUE;
}
static void
gtk_clock_stop_ticking (GtkClock *self)
{
ticking_clocks = g_slist_remove (ticking_clocks, self);
/* If no clock is remaining, stop running the tick updates */
if (ticking_clocks == NULL && ticking_clock_id != 0)
g_clear_handle_id (&ticking_clock_id, g_source_remove);
}
static void
gtk_clock_start_ticking (GtkClock *self)
{
/* if no clock is ticking yet, start */
if (ticking_clock_id == 0)
ticking_clock_id = g_timeout_add_seconds (1, gtk_clock_tick, NULL);
ticking_clocks = g_slist_prepend (ticking_clocks, self);
}
static void
gtk_clock_finalize (GObject *object)
{
GtkClock *self = GTK_CLOCK (object);
gtk_clock_stop_ticking (self);
g_free (self->location);
g_clear_pointer (&self->timezone, g_time_zone_unref);
G_OBJECT_CLASS (gtk_clock_parent_class)->finalize (object);
}
static void
gtk_clock_class_init (GtkClockClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = gtk_clock_get_property;
gobject_class->set_property = gtk_clock_set_property;
gobject_class->finalize = gtk_clock_finalize;
properties[PROP_LOCATION] =
g_param_spec_string ("location", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
properties[PROP_TIME] =
g_param_spec_boxed ("time", NULL, NULL, G_TYPE_DATE_TIME, G_PARAM_READABLE);
properties[PROP_TIMEZONE] =
g_param_spec_boxed ("timezone", NULL, NULL, G_TYPE_TIME_ZONE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
static void
gtk_clock_init (GtkClock *self)
{
gtk_clock_start_ticking (self);
}
static GtkClock *
gtk_clock_new (const char *location,
GTimeZone *timezone)
{
GtkClock *result;
result = g_object_new (GTK_TYPE_CLOCK,
"location", location,
"timezone", timezone,
NULL);
g_clear_pointer (&timezone, g_time_zone_unref);
return result;
}
static GListModel *
create_clocks_model (void)
{
GListStore *result;
GtkClock *clock;
result = g_list_store_new (GTK_TYPE_CLOCK);
/* local time */
clock = gtk_clock_new ("local", NULL);
g_list_store_append (result, clock);
g_object_unref (clock);
/* UTC time */
clock = gtk_clock_new ("UTC", g_time_zone_new_utc ());
g_list_store_append (result, clock);
g_object_unref (clock);
/* A bunch of timezones with GTK hackers */
clock = gtk_clock_new ("San Francisco", g_time_zone_new ("America/Los_Angeles"));
g_list_store_append (result, clock);
g_object_unref (clock);
clock = gtk_clock_new ("Boston", g_time_zone_new ("America/New_York"));
g_list_store_append (result, clock);
g_object_unref (clock);
clock = gtk_clock_new ("London", g_time_zone_new ("Europe/London"));
g_list_store_append (result, clock);
g_object_unref (clock);
clock = gtk_clock_new ("Berlin", g_time_zone_new ("Europe/Berlin"));
g_list_store_append (result, clock);
g_object_unref (clock);
clock = gtk_clock_new ("Moscow", g_time_zone_new ("Europe/Moscow"));
g_list_store_append (result, clock);
g_object_unref (clock);
clock = gtk_clock_new ("New Delhi", g_time_zone_new ("Asia/Kolkata"));
g_list_store_append (result, clock);
g_object_unref (clock);
clock = gtk_clock_new ("Shanghai", g_time_zone_new ("Asia/Shanghai"));
g_list_store_append (result, clock);
g_object_unref (clock);
return G_LIST_MODEL (result);
}
static char *
convert_time_to_string (GObject *image,
GDateTime *time,
gpointer unused)
{
return g_date_time_format (time, "%x\n%X");
}
/* And this function is the crux for this whole demo.
* It shows how to use expressions to set up bindings.
*/
static void
setup_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *box, *picture, *location_label, *time_label;
GtkExpression *clock_expression, *expression;
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_list_item_set_child (list_item, box);
/* First, we create an expression that gets us the clock from the listitem:
* 1. Create an expression that gets the list item.
* 2. Use that expression's "item" property to get the clock
*/
expression = gtk_constant_expression_new (GTK_TYPE_LIST_ITEM, list_item);
clock_expression = gtk_property_expression_new (GTK_TYPE_LIST_ITEM, expression, "item");
/* Bind the clock's location to a label.
* This is easy: We just get the "location" property of the clock.
*/
expression = gtk_property_expression_new (GTK_TYPE_CLOCK,
gtk_expression_ref (clock_expression),
"location");
/* Now create the label and bind the expression to it. */
location_label = gtk_label_new (NULL);
gtk_expression_bind (expression, location_label, "label", location_label);
gtk_box_append (GTK_BOX (box), location_label);
/* Here we bind the item itself to a GdkPicture.
* This is simply done by using the clock expression itself.
*/
expression = gtk_expression_ref (clock_expression);
/* Now create the widget and bind the expression to it. */
picture = gtk_picture_new ();
gtk_expression_bind (expression, picture, "paintable", picture);
gtk_box_append (GTK_BOX (box), picture);
/* And finally, everything comes together.
* We create a label for displaying the time as text.
* For that, we need to transform the "GDateTime" of the
* time property into a string so that the label can display it.
*/
expression = gtk_property_expression_new (GTK_TYPE_CLOCK,
gtk_expression_ref (clock_expression),
"time");
expression = gtk_cclosure_expression_new (G_TYPE_STRING,
NULL,
1, (GtkExpression *[1]) { expression },
G_CALLBACK (convert_time_to_string),
NULL, NULL);
/* Now create the label and bind the expression to it. */
time_label = gtk_label_new (NULL);
gtk_expression_bind (expression, time_label, "label", time_label);
gtk_box_append (GTK_BOX (box), time_label);
gtk_expression_unref (clock_expression);
}
static GtkWidget *window = NULL;
GtkWidget *
do_listview_clocks (GtkWidget *do_widget)
{
if (window == NULL)
{
GtkWidget *gridview, *sw;
GtkListItemFactory *factory;
GListModel *model;
GtkNoSelection *selection;
/* This is the normal window setup code every demo does */
window = gtk_window_new ();
gtk_window_set_title (GTK_WINDOW (window), "Clocks");
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &window);
/* List widgets go into a scrolled window. Always. */
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_window_set_child (GTK_WINDOW (window), sw);
/* Create the factory that creates the listitems. Because we
* used bindings above during setup, we only need to connect
* to the setup signal.
* The bindings take care of the bind step.
*/
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
gridview = gtk_grid_view_new_with_factory (factory);
gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
model = create_clocks_model ();
selection = gtk_no_selection_new (model);
gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), G_LIST_MODEL (selection));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), gridview);
g_object_unref (selection);
g_object_unref (model);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -0,0 +1,593 @@
/* Lists/Colors
*
* This demo displays a list of named colors.
*
* It is using a GtkGridView, and shows how to display
* and sort the data in various ways. The controls for
* this are implemented using GtkDropDown.
*
* The dataset used here has 9283 items.
*/
#include <gtk/gtk.h>
#define GTK_TYPE_COLOR (gtk_color_get_type ())
G_DECLARE_FINAL_TYPE (GtkColor, gtk_color, GTK, COLOR, GObject)
/* This is our object. It's just a color */
typedef struct _GtkColor GtkColor;
struct _GtkColor
{
GObject parent_instance;
char *name;
GdkRGBA *color;
int h, s, v;
};
enum {
PROP_0,
PROP_NAME,
PROP_COLOR,
PROP_RED,
PROP_GREEN,
PROP_BLUE,
PROP_HUE,
PROP_SATURATION,
PROP_VALUE,
N_PROPS
};
static void
gtk_color_snapshot (GdkPaintable *paintable,
GdkSnapshot *snapshot,
double width,
double height)
{
GtkColor *self = GTK_COLOR (paintable);
gtk_snapshot_append_color (snapshot, self->color, &GRAPHENE_RECT_INIT (0, 0, width, height));
}
static int
gtk_color_get_intrinsic_width (GdkPaintable *paintable)
{
return 32;
}
static int
gtk_color_get_intrinsic_height (GdkPaintable *paintable)
{
return 32;
}
static void
gtk_color_paintable_init (GdkPaintableInterface *iface)
{
iface->snapshot = gtk_color_snapshot;
iface->get_intrinsic_width = gtk_color_get_intrinsic_width;
iface->get_intrinsic_height = gtk_color_get_intrinsic_height;
}
/*
* Finally, we define the type. The important part is adding the paintable
* interface, so GTK knows that this object can indeed be drawm.
*/
G_DEFINE_TYPE_WITH_CODE (GtkColor, gtk_color, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
gtk_color_paintable_init))
static GParamSpec *properties[N_PROPS] = { NULL, };
static void
gtk_color_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GtkColor *self = GTK_COLOR (object);
switch (property_id)
{
case PROP_NAME:
g_value_set_string (value, self->name);
break;
case PROP_COLOR:
g_value_set_boxed (value, self->color);
break;
case PROP_RED:
g_value_set_float (value, self->color->red);
break;
case PROP_GREEN:
g_value_set_float (value, self->color->green);
break;
case PROP_BLUE:
g_value_set_float (value, self->color->blue);
break;
case PROP_HUE:
g_value_set_int (value, self->h);
break;
case PROP_SATURATION:
g_value_set_int (value, self->s);
break;
case PROP_VALUE:
g_value_set_int (value, self->v);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_color_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GtkColor *self = GTK_COLOR (object);
switch (property_id)
{
case PROP_NAME:
self->name = g_value_dup_string (value);
break;
case PROP_COLOR:
self->color = g_value_dup_boxed (value);
break;
case PROP_HUE:
self->h = g_value_get_int (value);
break;
case PROP_SATURATION:
self->s = g_value_get_int (value);
break;
case PROP_VALUE:
self->v = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_color_finalize (GObject *object)
{
GtkColor *self = GTK_COLOR (object);
g_free (self->name);
g_clear_pointer (&self->color, gdk_rgba_free);
G_OBJECT_CLASS (gtk_color_parent_class)->finalize (object);
}
static void
gtk_color_class_init (GtkColorClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = gtk_color_get_property;
gobject_class->set_property = gtk_color_set_property;
gobject_class->finalize = gtk_color_finalize;
properties[PROP_NAME] =
g_param_spec_string ("name", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
properties[PROP_COLOR] =
g_param_spec_boxed ("color", NULL, NULL, GDK_TYPE_RGBA, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
properties[PROP_RED] =
g_param_spec_float ("red", NULL, NULL, 0, 1, 0, G_PARAM_READABLE);
properties[PROP_GREEN] =
g_param_spec_float ("green", NULL, NULL, 0, 1, 0, G_PARAM_READABLE);
properties[PROP_BLUE] =
g_param_spec_float ("blue", NULL, NULL, 0, 1, 0, G_PARAM_READABLE);
properties[PROP_HUE] =
g_param_spec_int ("hue", NULL, NULL, 0, 360, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
properties[PROP_SATURATION] =
g_param_spec_int ("saturation", NULL, NULL, 0, 100, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
properties[PROP_VALUE] =
g_param_spec_int ("value", NULL, NULL, 0, 100, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
static void
gtk_color_init (GtkColor *self)
{
}
static GtkColor *
gtk_color_new (const char *name,
float r, float g, float b,
int h, int s, int v)
{
GtkColor *result;
GdkRGBA color = { r, g, b, 1.0 };
result = g_object_new (GTK_TYPE_COLOR,
"name", name,
"color", &color,
"hue", h,
"saturation", s,
"value", v,
NULL);
return result;
}
static GListModel *
create_colors_model (void)
{
GListStore *result;
GtkColor *color;
GBytes *data;
char **lines;
guint i;
result = g_list_store_new (GTK_TYPE_COLOR);
data = g_resources_lookup_data ("/listview_colors/color.names.txt", 0, NULL);
lines = g_strsplit (g_bytes_get_data (data, NULL), "\n", 0);
for (i = 0; lines[i]; i++)
{
const char *name;
char **fields;
int red, green, blue;
int h, s, v;
if (lines[i][0] == '#' || lines[i][0] == '\0')
continue;
fields = g_strsplit (lines[i], " ", 0);
name = fields[1];
red = atoi (fields[3]);
green = atoi (fields[4]);
blue = atoi (fields[5]);
h = atoi (fields[9]);
s = atoi (fields[10]);
v = atoi (fields[11]);
color = gtk_color_new (name, red / 255., green / 255., blue / 255., h, s, v);
g_list_store_append (result, color);
g_object_unref (color);
g_strfreev (fields);
}
g_strfreev (lines);
g_bytes_unref (data);
return G_LIST_MODEL (result);
}
static char *
get_rgb_markup (gpointer this,
GtkColor *color)
{
if (!color)
return NULL;
return g_strdup_printf ("<b>R:</b> %d <b>G:</b> %d <b>B:</b> %d",
(int)(color->color->red * 255),
(int)(color->color->green * 255),
(int)(color->color->blue * 255));
}
static char *
get_hsv_markup (gpointer this,
GtkColor *color)
{
if (!color)
return NULL;
return g_strdup_printf ("<b>H:</b> %d <b>S:</b> %d <b>V:</b> %d",
color->h,
color->s,
color->v);
}
static void
setup_simple_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *picture;
GtkExpression *color_expression, *expression;
expression = gtk_constant_expression_new (GTK_TYPE_LIST_ITEM, list_item);
color_expression = gtk_property_expression_new (GTK_TYPE_LIST_ITEM, expression, "item");
picture = gtk_picture_new ();
gtk_widget_set_size_request (picture, 32, 32);
gtk_expression_bind (color_expression, picture, "paintable", NULL);
gtk_list_item_set_child (list_item, picture);
}
static void
setup_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *box, *picture, *name_label, *rgb_label, *hsv_label;;
GtkExpression *color_expression, *expression;
GtkExpression *params[1];
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_list_item_set_child (list_item, box);
expression = gtk_constant_expression_new (GTK_TYPE_LIST_ITEM, list_item);
color_expression = gtk_property_expression_new (GTK_TYPE_LIST_ITEM, expression, "item");
expression = gtk_property_expression_new (GTK_TYPE_COLOR,
gtk_expression_ref (color_expression),
"name");
name_label = gtk_label_new (NULL);
gtk_expression_bind (expression, name_label, "label", NULL);
gtk_box_append (GTK_BOX (box), name_label);
expression = gtk_expression_ref (color_expression);
picture = gtk_picture_new ();
gtk_expression_bind (expression, picture, "paintable", NULL);
gtk_box_append (GTK_BOX (box), picture);
params[0] = gtk_expression_ref (color_expression);
expression = gtk_cclosure_expression_new (G_TYPE_STRING,
NULL,
1, params,
(GCallback)get_rgb_markup,
NULL, NULL);
rgb_label = gtk_label_new (NULL);
gtk_label_set_use_markup (GTK_LABEL (rgb_label), TRUE);
gtk_expression_bind (expression, rgb_label, "label", NULL);
gtk_box_append (GTK_BOX (box), rgb_label);
params[0] = gtk_expression_ref (color_expression);
expression = gtk_cclosure_expression_new (G_TYPE_STRING,
NULL,
1, params,
(GCallback)get_hsv_markup,
NULL, NULL);
hsv_label = gtk_label_new (NULL);
gtk_label_set_use_markup (GTK_LABEL (hsv_label), TRUE);
gtk_expression_bind (expression, hsv_label, "label", NULL);
gtk_box_append (GTK_BOX (box), hsv_label);
gtk_expression_unref (color_expression);
}
static void
set_title (gpointer item,
const char *title)
{
g_object_set_data (G_OBJECT (item), "title", (gpointer)title);
}
static char *
get_title (gpointer item)
{
return g_strdup ((char *)g_object_get_data (G_OBJECT (item), "title"));
}
static gboolean
set_item (GBinding *binding,
const GValue *from,
GValue *to,
gpointer data)
{
GObject *source = g_binding_get_source (binding);
GListModel *model;
guint selected;
gpointer item;
selected = g_value_get_uint (from);
model = gtk_drop_down_get_model (GTK_DROP_DOWN (source));
item = g_list_model_get_item (model, selected);
g_value_set_object (to, item);
g_clear_object (&item);
return TRUE;
}
GtkWidget *
create_color_grid (void)
{
GtkWidget *gridview;
GtkListItemFactory *factory;
GListModel *model, *selection;
gridview = gtk_grid_view_new ();
gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_simple_listitem_cb), NULL);
gtk_grid_view_set_factory (GTK_GRID_VIEW (gridview), factory);
g_object_unref (factory);
gtk_grid_view_set_max_columns (GTK_GRID_VIEW (gridview), 24);
gtk_grid_view_set_enable_rubberband (GTK_GRID_VIEW (gridview), TRUE);
model = G_LIST_MODEL (gtk_sort_list_model_new (create_colors_model (), NULL));
selection = G_LIST_MODEL (gtk_multi_selection_new (model));
gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), selection);
g_object_unref (selection);
g_object_unref (model);
return gridview;
}
static GtkWidget *window = NULL;
GtkWidget *
do_listview_colors (GtkWidget *do_widget)
{
if (window == NULL)
{
GtkWidget *header, *gridview, *sw, *box, *dropdown;
GtkListItemFactory *factory;
GListStore *factories;
GListModel *model;
GtkSorter *sorter;
GtkSorter *multi_sorter;
GListStore *sorters;
GtkExpression *expression;
window = gtk_window_new ();
gtk_window_set_title (GTK_WINDOW (window), "Colors");
header = gtk_header_bar_new ();
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), TRUE);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_object_add_weak_pointer (G_OBJECT (window), (gpointer*)&window);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_window_set_child (GTK_WINDOW (window), sw);
gridview = create_color_grid ();
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), gridview);
model = gtk_grid_view_get_model (GTK_GRID_VIEW (gridview));
g_object_get (model, "model", &model, NULL);
sorters = g_list_store_new (GTK_TYPE_SORTER);
sorter = gtk_string_sorter_new (gtk_property_expression_new (GTK_TYPE_COLOR, NULL, "name"));
set_title (sorter, "Name");
g_list_store_append (sorters, sorter);
g_object_unref (sorter);
multi_sorter = gtk_multi_sorter_new ();
sorter = gtk_numeric_sorter_new (gtk_property_expression_new (GTK_TYPE_COLOR, NULL, "red"));
gtk_numeric_sorter_set_sort_order (GTK_NUMERIC_SORTER (sorter), GTK_SORT_DESCENDING);
set_title (sorter, "Red");
g_list_store_append (sorters, sorter);
gtk_multi_sorter_append (GTK_MULTI_SORTER (multi_sorter), sorter);
sorter = gtk_numeric_sorter_new (gtk_property_expression_new (GTK_TYPE_COLOR, NULL, "green"));
gtk_numeric_sorter_set_sort_order (GTK_NUMERIC_SORTER (sorter), GTK_SORT_DESCENDING);
set_title (sorter, "Green");
g_list_store_append (sorters, sorter);
gtk_multi_sorter_append (GTK_MULTI_SORTER (multi_sorter), sorter);
sorter = gtk_numeric_sorter_new (gtk_property_expression_new (GTK_TYPE_COLOR, NULL, "blue"));
gtk_numeric_sorter_set_sort_order (GTK_NUMERIC_SORTER (sorter), GTK_SORT_DESCENDING);
set_title (sorter, "Blue");
g_list_store_append (sorters, sorter);
gtk_multi_sorter_append (GTK_MULTI_SORTER (multi_sorter), sorter);
set_title (multi_sorter, "RGB");
g_list_store_append (sorters, multi_sorter);
g_object_unref (multi_sorter);
multi_sorter = gtk_multi_sorter_new ();
sorter = gtk_numeric_sorter_new (gtk_property_expression_new (GTK_TYPE_COLOR, NULL, "hue"));
gtk_numeric_sorter_set_sort_order (GTK_NUMERIC_SORTER (sorter), GTK_SORT_DESCENDING);
set_title (sorter, "Hue");
g_list_store_append (sorters, sorter);
gtk_multi_sorter_append (GTK_MULTI_SORTER (multi_sorter), sorter);
sorter = gtk_numeric_sorter_new (gtk_property_expression_new (GTK_TYPE_COLOR, NULL, "saturation"));
gtk_numeric_sorter_set_sort_order (GTK_NUMERIC_SORTER (sorter), GTK_SORT_DESCENDING);
set_title (sorter, "Saturation");
g_list_store_append (sorters, sorter);
gtk_multi_sorter_append (GTK_MULTI_SORTER (multi_sorter), sorter);
sorter = gtk_numeric_sorter_new (gtk_property_expression_new (GTK_TYPE_COLOR, NULL, "value"));
gtk_numeric_sorter_set_sort_order (GTK_NUMERIC_SORTER (sorter), GTK_SORT_DESCENDING);
set_title (sorter, "Value");
g_list_store_append (sorters, sorter);
gtk_multi_sorter_append (GTK_MULTI_SORTER (multi_sorter), sorter);
set_title (multi_sorter, "HSV");
g_list_store_append (sorters, multi_sorter);
g_object_unref (multi_sorter);
dropdown = gtk_drop_down_new ();
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
gtk_box_append (GTK_BOX (box), gtk_label_new ("Sort by:"));
gtk_box_append (GTK_BOX (box), dropdown);
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), box);
expression = gtk_cclosure_expression_new (G_TYPE_STRING,
NULL,
0, NULL,
(GCallback)get_title,
NULL, NULL);
gtk_drop_down_set_expression (GTK_DROP_DOWN (dropdown), expression);
gtk_expression_unref (expression);
gtk_drop_down_set_model (GTK_DROP_DOWN (dropdown), G_LIST_MODEL (sorters));
g_object_unref (sorters);
g_object_bind_property_full (dropdown, "selected",
model, "sorter",
G_BINDING_SYNC_CREATE,
set_item, NULL,
NULL, NULL);
factories = g_list_store_new (GTK_TYPE_LIST_ITEM_FACTORY);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_simple_listitem_cb), NULL);
set_title (factory, "Colors");
g_list_store_append (factories, factory);
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
set_title (factory, "Everything");
g_list_store_append (factories, factory);
dropdown = gtk_drop_down_new ();
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
gtk_box_append (GTK_BOX (box), gtk_label_new ("Show:"));
gtk_box_append (GTK_BOX (box), dropdown);
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), box);
expression = gtk_cclosure_expression_new (G_TYPE_STRING,
NULL,
0, NULL,
(GCallback)get_title,
NULL, NULL);
gtk_drop_down_set_expression (GTK_DROP_DOWN (dropdown), expression);
gtk_expression_unref (expression);
gtk_drop_down_set_model (GTK_DROP_DOWN (dropdown), G_LIST_MODEL (factories));
g_object_unref (factories);
g_object_bind_property_full (dropdown, "selected",
gridview, "factory",
G_BINDING_SYNC_CREATE,
set_item, NULL,
NULL, NULL);
g_object_unref (model);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -0,0 +1,255 @@
/* Lists/File browser
*
* This demo shows off the different layouts that are quickly achievable
* with GtkListview and GtkGridView by implementing a file browser with
* different views.
*/
#include <glib/gi18n.h>
#include <gtk/gtk.h>
static GtkWidget *window = NULL;
/* Create a simple object that holds the data for the different views */
typedef struct _FileBrowserView FileBrowserView;
struct _FileBrowserView
{
GObject parent_instance;
GtkListItemFactory *factory;
char *icon_name;
GtkOrientation orientation;
};
enum {
PROP_0,
PROP_FACTORY,
PROP_ICON_NAME,
PROP_ORIENTATION,
N_PROPS
};
#define FILE_BROWSER_TYPE_VIEW (file_browser_view_get_type ())
G_DECLARE_FINAL_TYPE (FileBrowserView, file_browser_view, FILE_BROWSER, VIEW, GObject);
G_DEFINE_TYPE (FileBrowserView, file_browser_view, G_TYPE_OBJECT);
static GParamSpec *properties[N_PROPS] = { NULL, };
static void
file_browser_view_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
FileBrowserView *self = FILE_BROWSER_VIEW (object);
switch (property_id)
{
case PROP_FACTORY:
g_value_set_object (value, self->factory);
break;
case PROP_ICON_NAME:
g_value_set_string (value, self->icon_name);
break;
case PROP_ORIENTATION:
g_value_set_enum (value, self->orientation);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
file_browser_view_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
FileBrowserView *self = FILE_BROWSER_VIEW (object);
switch (prop_id)
{
case PROP_FACTORY:
g_set_object (&self->factory, g_value_get_object (value));
break;
case PROP_ICON_NAME:
g_free (self->icon_name);
self->icon_name = g_value_dup_string (value);
break;
case PROP_ORIENTATION:
self->orientation = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
file_browser_view_finalize (GObject *object)
{
FileBrowserView *self = FILE_BROWSER_VIEW (object);
g_object_unref (self->factory);
g_free (self->icon_name);
G_OBJECT_CLASS (file_browser_view_parent_class)->dispose (object);
}
static void
file_browser_view_class_init (FileBrowserViewClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = file_browser_view_get_property;
gobject_class->set_property = file_browser_view_set_property;
gobject_class->finalize = file_browser_view_finalize;
properties[PROP_FACTORY] =
g_param_spec_object ("factory",
"factory",
"factory to use in the main view",
GTK_TYPE_LIST_ITEM_FACTORY,
G_PARAM_READWRITE);
properties[PROP_ICON_NAME] =
g_param_spec_string ("icon-name",
"icon name",
"icon to display for selecting this view",
NULL,
G_PARAM_READWRITE);
properties[PROP_ORIENTATION] =
g_param_spec_enum ("orientation",
"orientation",
"orientation of the view",
GTK_TYPE_ORIENTATION,
GTK_ORIENTATION_VERTICAL,
G_PARAM_READWRITE);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
static void file_browser_view_init (FileBrowserView *self)
{
}
char *
filebrowser_get_display_name (GObject *object,
GFileInfo *info)
{
if (!info)
return NULL;
return g_strdup (g_file_info_get_attribute_string (info, "standard::display-name"));
}
char *
filebrowser_get_content_type (GObject *object,
GFileInfo *info)
{
if (!info)
return NULL;
return g_strdup (g_file_info_get_attribute_string (info, "standard::content-type"));
}
char *
filebrowser_get_size (GObject *object,
GFileInfo *info)
{
if (!info)
return NULL;
return g_format_size (g_file_info_get_attribute_uint64 (info, "standard::size"));
}
GIcon *
filebrowser_get_icon (GObject *object,
GFileInfo *info)
{
GIcon *icon;
if (info)
icon = G_ICON (g_file_info_get_attribute_object (info, "standard::icon"));
else
icon = NULL;
if (icon)
g_object_ref (icon);
return icon;
}
void
filebrowser_up_clicked_cb (GtkButton *button,
GtkDirectoryList *list)
{
GFile *file;
file = g_file_get_parent (gtk_directory_list_get_file (list));
if (file == NULL)
return;
gtk_directory_list_set_file (list, file);
}
void
filebrowser_view_activated_cb (GtkGridView *view,
guint pos,
GtkDirectoryList *list)
{
GFileInfo *info;
info = g_list_model_get_item (gtk_grid_view_get_model (view), pos);
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
gtk_directory_list_set_file (list, G_FILE (g_file_info_get_attribute_object (info, "standard::file")));
g_object_unref (info);
}
GtkWidget *
do_listview_filebrowser (GtkWidget *do_widget)
{
if (!window)
{
GtkWidget *view;
GtkBuilder *builder;
GtkDirectoryList *dirlist;
GFile *file;
char *cwd;
builder = gtk_builder_new_from_resource ("/listview_filebrowser/listview_filebrowser.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &window);
/* Create the model and fill it with the contents of the current directory */
cwd = g_get_current_dir ();
file = g_file_new_for_path (cwd);
g_free (cwd);
dirlist = GTK_DIRECTORY_LIST (gtk_builder_get_object (builder, "dirlist"));
gtk_directory_list_set_file (dirlist, file);
g_object_unref (file);
/* grab focus in the view */
view = GTK_WIDGET (gtk_builder_get_object (builder, "view"));
gtk_widget_grab_focus (view);
g_object_unref (builder);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -0,0 +1,240 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GListStore" id="viewlist">
<property name="item-type">FileBrowserView</property>
<child>
<object class="FileBrowserView">
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkBox">
<child>
<object class="GtkImage">
<binding name="gicon">
<closure type="GIcon" function="filebrowser_get_icon">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="halign">start</property>
<binding name="label">
<closure type="gchararray" function="filebrowser_get_display_name">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
</child>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
<property name="icon-name">view-list-symbolic</property>
<property name="orientation">horizontal</property>
</object>
</child>
<child>
<object class="FileBrowserView">
<property name="icon-name">view-grid-symbolic</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkImage">
<property name="icon-size">large</property>
<binding name="gicon">
<closure type="GIcon" function="filebrowser_get_icon">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="wrap">1</property>
<property name="wrap-mode">word-char</property>
<property name="lines">2</property>
<property name="ellipsize">end</property>
<property name="width-chars">10</property>
<property name="max-width-chars">30</property>
<binding name="label">
<closure type="gchararray" function="filebrowser_get_display_name">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
</child>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
<property name="orientation">vertical</property>
</object>
</child>
<child>
<object class="FileBrowserView">
<property name="icon-name">view-paged-symbolic</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkBox">
<child>
<object class="GtkImage">
<property name="icon-size">large</property>
<binding name="gicon">
<closure type="GIcon" function="filebrowser_get_icon">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="halign">start</property>
<binding name="label">
<closure type="gchararray" function="filebrowser_get_display_name">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="halign">start</property>
<binding name="label">
<closure type="gchararray" function="filebrowser_get_size">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="halign">start</property>
<binding name="label">
<closure type="gchararray" function="filebrowser_get_content_type">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
</object>
</child>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
<property name="orientation">horizontal</property>
</object>
</child>
</object>
<object class="GtkDirectoryList" id="dirlist">
<property name="attributes">standard::name,standard::display-name,standard::icon,standard::size,standard::content-type</property>
</object>
<object class="GtkWindow" id="window">
<property name="title" translatable="yes">File browser</property>
<property name="default-width">600</property>
<property name="default-height">400</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="">
<property name="show-title-buttons">1</property>
<child>
<object class="GtkButton">
<property name="icon-name">go-up</property>
<signal name="clicked" handler="filebrowser_up_clicked_cb" object="dirlist" swapped="no"/>
</object>
</child>
<child type="end">
<object class="GtkListView">
<property name="valign">center</property>
<property name="orientation">horizontal</property>
<style>
<class name="linked"/>
</style>
<property name="model">
<object class="GtkSingleSelection" id="selected-view">
<property name="model">viewlist</property>
</object>
</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkImage">
<binding name="icon-name">
<lookup type="FileBrowserView" name="icon-name">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="can-focus">1</property>
<child>
<object class="GtkGridView" id="view">
<property name="model">dirlist</property>
<property name="max-columns">15</property>
<binding name="factory">
<lookup name="factory" type="FileBrowserView">
<lookup name="selected-item">selected-view</lookup>
</lookup>
</binding>
<binding name="orientation">
<lookup name="orientation" type="FileBrowserView">
<lookup name="selected-item">selected-view</lookup>
</lookup>
</binding>
<signal name="activate" handler="filebrowser_view_activated_cb" object="dirlist" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,472 @@
/* Lists/Minesweeper
*
* This demo shows how to develop a user interface for small game using a
* gridview.
*
* It demonstrates how to use the activate signal and single-press behavior
* to implement rather different interaction behavior to a typical list.
*/
#include <glib/gi18n.h>
#include <gtk/gtk.h>
/*** The cell object ***/
/* Create an object that holds the data for a cell in the game */
typedef struct _SweeperCell SweeperCell;
struct _SweeperCell
{
GObject parent_instance;
gboolean is_mine;
gboolean is_visible;
guint neighbor_mines;
};
enum {
CELL_PROP_0,
CELL_PROP_LABEL,
N_CELL_PROPS
};
#define SWEEPER_TYPE_CELL (sweeper_cell_get_type ())
G_DECLARE_FINAL_TYPE (SweeperCell, sweeper_cell, SWEEPER, CELL, GObject);
G_DEFINE_TYPE (SweeperCell, sweeper_cell, G_TYPE_OBJECT);
static GParamSpec *cell_properties[N_CELL_PROPS] = { NULL, };
static const char *
sweeper_cell_get_label (SweeperCell *self)
{
static const char *minecount_labels[10] = { "", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
if (!self->is_visible)
return "?";
if (self->is_mine)
return "💣";
return minecount_labels[self->neighbor_mines];
}
static void
sweeper_cell_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
SweeperCell *self = SWEEPER_CELL (object);
switch (property_id)
{
case CELL_PROP_LABEL:
g_value_set_string (value, sweeper_cell_get_label (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
sweeper_cell_class_init (SweeperCellClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = sweeper_cell_get_property;
cell_properties[CELL_PROP_LABEL] =
g_param_spec_string ("label",
"label",
"label to display for this row",
NULL,
G_PARAM_READABLE);
g_object_class_install_properties (gobject_class, N_CELL_PROPS, cell_properties);
}
static void
sweeper_cell_init (SweeperCell *self)
{
}
static void
sweeper_cell_reveal (SweeperCell *self)
{
if (self->is_visible)
return;
self->is_visible = TRUE;
g_object_notify_by_pspec (G_OBJECT (self), cell_properties[CELL_PROP_LABEL]);
}
static SweeperCell *
sweeper_cell_new (void)
{
return g_object_new (SWEEPER_TYPE_CELL, NULL);
}
/*** The board object ***/
/* Create an object that holds the data for the game */
typedef struct _SweeperGame SweeperGame;
struct _SweeperGame
{
GObject parent_instance;
GPtrArray *cells;
guint width;
guint height;
gboolean playing;
gboolean win;
};
enum {
GAME_PROP_0,
GAME_PROP_HEIGHT,
GAME_PROP_PLAYING,
GAME_PROP_WIDTH,
GAME_PROP_WIN,
N_GAME_PROPS
};
#define SWEEPER_TYPE_GAME (sweeper_game_get_type ())
G_DECLARE_FINAL_TYPE (SweeperGame, sweeper_game, SWEEPER, GAME, GObject);
static GType
sweeper_game_list_model_get_item_type (GListModel *model)
{
return SWEEPER_TYPE_GAME;
}
static guint
sweeper_game_list_model_get_n_items (GListModel *model)
{
SweeperGame *self = SWEEPER_GAME (model);
return self->width * self->height;
}
static gpointer
sweeper_game_list_model_get_item (GListModel *model,
guint position)
{
SweeperGame *self = SWEEPER_GAME (model);
return g_object_ref (g_ptr_array_index (self->cells, position));
}
static void
sweeper_game_list_model_init (GListModelInterface *iface)
{
iface->get_item_type = sweeper_game_list_model_get_item_type;
iface->get_n_items = sweeper_game_list_model_get_n_items;
iface->get_item = sweeper_game_list_model_get_item;
}
G_DEFINE_TYPE_WITH_CODE (SweeperGame, sweeper_game, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, sweeper_game_list_model_init))
static GParamSpec *game_properties[N_GAME_PROPS] = { NULL, };
static void
sweeper_game_dispose (GObject *object)
{
SweeperGame *self = SWEEPER_GAME (object);
g_clear_pointer (&self->cells, g_ptr_array_unref);
G_OBJECT_CLASS (sweeper_game_parent_class)->dispose (object);
}
static void
sweeper_game_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
SweeperGame *self = SWEEPER_GAME (object);
switch (property_id)
{
case GAME_PROP_HEIGHT:
g_value_set_uint (value, self->height);
break;
case GAME_PROP_PLAYING:
g_value_set_boolean (value, self->playing);
break;
case GAME_PROP_WIDTH:
g_value_set_uint (value, self->width);
break;
case GAME_PROP_WIN:
g_value_set_boolean (value, self->win);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
sweeper_game_class_init (SweeperGameClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->dispose = sweeper_game_dispose;
gobject_class->get_property = sweeper_game_get_property;
game_properties[GAME_PROP_HEIGHT] =
g_param_spec_uint ("height",
"height",
"height of the game grid",
1, G_MAXUINT, 8,
G_PARAM_READABLE);
game_properties[GAME_PROP_PLAYING] =
g_param_spec_boolean ("playing",
"playing",
"if the game is still going on",
FALSE,
G_PARAM_READABLE);
game_properties[GAME_PROP_WIDTH] =
g_param_spec_uint ("width",
"width",
"width of the game grid",
1, G_MAXUINT, 8,
G_PARAM_READABLE);
game_properties[GAME_PROP_WIN] =
g_param_spec_boolean ("win",
"win",
"if the game was won",
FALSE,
G_PARAM_READABLE);
g_object_class_install_properties (gobject_class, N_GAME_PROPS, game_properties);
}
static void
sweeper_game_reset_board (SweeperGame *self,
guint width,
guint height)
{
guint i;
g_ptr_array_set_size (self->cells, 0);
for (i = 0; i < width * height; i++)
{
g_ptr_array_add (self->cells, sweeper_cell_new ());
}
if (self->width != width)
{
self->width = width;
g_object_notify_by_pspec (G_OBJECT (self), game_properties[GAME_PROP_WIDTH]);
}
if (self->height != height)
{
self->height = height;
g_object_notify_by_pspec (G_OBJECT (self), game_properties[GAME_PROP_HEIGHT]);
}
if (!self->playing)
{
self->playing = TRUE;
g_object_notify_by_pspec (G_OBJECT (self), game_properties[GAME_PROP_PLAYING]);
}
if (self->win)
{
self->win = FALSE;
g_object_notify_by_pspec (G_OBJECT (self), game_properties[GAME_PROP_WIN]);
}
}
static void
sweeper_game_place_mines (SweeperGame *self,
guint n_mines)
{
guint i;
for (i = 0; i < n_mines; i++)
{
SweeperCell *cell;
do {
cell = g_ptr_array_index (self->cells, g_random_int_range (0, self->cells->len));
} while (cell->is_mine);
cell->is_mine = TRUE;
}
}
static SweeperCell *
get_cell (SweeperGame *self,
guint x,
guint y)
{
return g_ptr_array_index (self->cells, y * self->width + x);
}
static void
sweeper_game_count_neighbor_mines (SweeperGame *self,
guint width,
guint height)
{
guint x, y, x2, y2;
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
SweeperCell *cell = get_cell (self, x, y);
for (y2 = MAX (1, y) - 1; y2 < MIN (height, y + 2); y2++)
{
for (x2 = MAX (1, x) - 1; x2 < MIN (width, x + 2); x2++)
{
SweeperCell *other = get_cell (self, x2, y2);
if (other->is_mine)
cell->neighbor_mines++;
}
}
}
}
}
static void
sweeper_game_new_game (SweeperGame *self,
guint width,
guint height,
guint n_mines)
{
guint n_items_before;
g_return_if_fail (n_mines <= width * height);
n_items_before = self->width * self->height;
g_object_freeze_notify (G_OBJECT (self));
sweeper_game_reset_board (self, width, height);
sweeper_game_place_mines (self, n_mines);
sweeper_game_count_neighbor_mines (self, width, height);
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items_before, width * height);
g_object_thaw_notify (G_OBJECT (self));
}
static void
sweeper_game_init (SweeperGame *self)
{
self->cells = g_ptr_array_new_with_free_func (g_object_unref);
sweeper_game_new_game (self, 8, 8, 10);
}
static void
sweeper_game_end (SweeperGame *self,
gboolean win)
{
if (self->playing)
{
self->playing = FALSE;
g_object_notify_by_pspec (G_OBJECT (self), game_properties[GAME_PROP_PLAYING]);
}
if (self->win != win)
{
self->win = win;
g_object_notify_by_pspec (G_OBJECT (self), game_properties[GAME_PROP_WIN]);
}
}
static void
sweeper_game_check_finished (SweeperGame *self)
{
guint i;
if (!self->playing)
return;
for (i = 0; i < self->cells->len; i++)
{
SweeperCell *cell = g_ptr_array_index (self->cells, i);
/* There's still a non-revealed cell that isn't a mine */
if (!cell->is_visible && !cell->is_mine)
return;
}
sweeper_game_end (self, TRUE);
}
static void
sweeper_game_reveal_cell (SweeperGame *self,
guint position)
{
SweeperCell *cell;
if (!self->playing)
return;
cell = g_ptr_array_index (self->cells, position);
sweeper_cell_reveal (cell);
if (cell->is_mine)
sweeper_game_end (self, FALSE);
sweeper_game_check_finished (self);
}
void
minesweeper_cell_clicked_cb (GtkGridView *gridview,
guint pos,
SweeperGame *game)
{
sweeper_game_reveal_cell (game, pos);
}
void
minesweeper_new_game_cb (GtkButton *button,
SweeperGame *game)
{
sweeper_game_new_game (game, 8, 8, 10);
}
static GtkWidget *window = NULL;
GtkWidget *
do_listview_minesweeper (GtkWidget *do_widget)
{
if (window == NULL)
{
GtkBuilder *builder;
g_type_ensure (SWEEPER_TYPE_GAME);
builder = gtk_builder_new_from_resource ("/listview_minesweeper/listview_minesweeper.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &window);
g_object_unref (builder);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="SweeperGame" id="game">
</object>
<object class="GtkWindow" id="window">
<property name="title" translatable="yes">Minesweeper</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="">
<property name="show-title-buttons">1</property>
<child>
<object class="GtkButton">
<property name="label">New Game</property>
<signal name="clicked" handler="minesweeper_new_game_cb" object="game" swapped="no"/>
</object>
</child>
<child type="title">
<object class="GtkImage">
<property name="icon-name">trophy-gold</property>
<binding name="visible">
<lookup name="win">game</lookup>
</binding>
</object>
</child>
</object>
</child>
<child>
<object class="GtkGridView" id="view">
<property name="model">
<object class="GtkNoSelection">
<property name="model">game</property>
</object>
</property>
<property name="single-click-activate">1</property>
<binding name="max-columns">
<lookup name="width">game</lookup>
</binding>
<binding name="min-columns">
<lookup name="width">game</lookup>
</binding>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="resource">/listview_minesweeper/listview_minesweeper_cell.ui</property>
</object>
</property>
<signal name="activate" handler="minesweeper_cell_clicked_cb" object="game" swapped="no"/>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="halign">center</property>
<property name="valign">center</property>
<binding name="label">
<lookup name="label" type="SweeperCell">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
</object>
</property>
</template>
</interface>

View File

@@ -0,0 +1,333 @@
/* Lists/Settings
*
* This demo shows a settings viewer for GSettings.
*
* It demonstrates how to implement support for trees with GtkListView.
* It also shows how to set up sorting and filtering for columns in a
* GtkColumnView.
*/
#include <gtk/gtk.h>
/* Create an object that wraps GSettingsSchemaKey because that's a boxed type */
typedef struct _SettingsKey SettingsKey;
struct _SettingsKey
{
GObject parent_instance;
GSettings *settings;
GSettingsSchemaKey *key;
};
enum {
PROP_0,
PROP_NAME,
PROP_SUMMARY,
PROP_DESCRIPTION,
PROP_VALUE,
N_PROPS
};
#define SETTINGS_TYPE_KEY (settings_key_get_type ())
G_DECLARE_FINAL_TYPE (SettingsKey, settings_key, SETTINGS, KEY, GObject);
G_DEFINE_TYPE (SettingsKey, settings_key, G_TYPE_OBJECT);
static GParamSpec *properties[N_PROPS] = { NULL, };
static void
settings_key_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
SettingsKey *self = SETTINGS_KEY (object);
switch (property_id)
{
case PROP_DESCRIPTION:
g_value_set_string (value, g_settings_schema_key_get_description (self->key));
break;
case PROP_NAME:
g_value_set_string (value, g_settings_schema_key_get_name (self->key));
break;
case PROP_SUMMARY:
g_value_set_string (value, g_settings_schema_key_get_summary (self->key));
break;
case PROP_VALUE:
{
GVariant *variant = g_settings_get_value (self->settings, g_settings_schema_key_get_name (self->key));
g_value_take_string (value, g_variant_print (variant, FALSE));
g_variant_unref (variant);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
settings_key_finalize (GObject *object)
{
SettingsKey *self = SETTINGS_KEY (object);
g_object_unref (self->settings);
g_settings_schema_key_unref (self->key);
G_OBJECT_CLASS (settings_key_parent_class)->finalize (object);
}
static void
settings_key_class_init (SettingsKeyClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = settings_key_finalize;
gobject_class->get_property = settings_key_get_property;
properties[PROP_DESCRIPTION] =
g_param_spec_string ("description", NULL, NULL, NULL, G_PARAM_READABLE);
properties[PROP_NAME] =
g_param_spec_string ("name", NULL, NULL, NULL, G_PARAM_READABLE);
properties[PROP_SUMMARY] =
g_param_spec_string ("summary", NULL, NULL, NULL, G_PARAM_READABLE);
properties[PROP_VALUE] =
g_param_spec_string ("value", NULL, NULL, NULL, G_PARAM_READABLE);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
static void
settings_key_init (SettingsKey *self)
{
}
static SettingsKey *
settings_key_new (GSettings *settings,
GSettingsSchemaKey *key)
{
SettingsKey *result = g_object_new (SETTINGS_TYPE_KEY, NULL);
result->settings = g_object_ref (settings);
result->key = g_settings_schema_key_ref (key);
return result;
}
static int
strvcmp (gconstpointer p1,
gconstpointer p2)
{
const char * const *s1 = p1;
const char * const *s2 = p2;
return strcmp (*s1, *s2);
}
static GtkFilter *current_filter;
static gboolean
transform_settings_to_keys (GBinding *binding,
const GValue *from_value,
GValue *to_value,
gpointer data)
{
GtkTreeListRow *treelistrow;
GSettings *settings;
GSettingsSchema *schema;
GListStore *store;
GtkSortListModel *sort_model;
GtkFilterListModel *filter_model;
GtkFilter *filter;
GtkExpression *expression;
char **keys;
guint i;
treelistrow = g_value_get_object (from_value);
if (treelistrow == NULL)
return TRUE;
settings = gtk_tree_list_row_get_item (treelistrow);
g_object_get (settings, "settings-schema", &schema, NULL);
store = g_list_store_new (SETTINGS_TYPE_KEY);
keys = g_settings_schema_list_keys (schema);
for (i = 0; keys[i] != NULL; i++)
{
GSettingsSchemaKey *almost_there = g_settings_schema_get_key (schema, keys[i]);
SettingsKey *finally = settings_key_new (settings, almost_there);
g_list_store_append (store, finally);
g_object_unref (finally);
g_settings_schema_key_unref (almost_there);
}
g_strfreev (keys);
g_settings_schema_unref (schema);
g_object_unref (settings);
sort_model = gtk_sort_list_model_new (G_LIST_MODEL (store),
gtk_column_view_get_sorter (GTK_COLUMN_VIEW (data)));
g_object_unref (store);
expression = gtk_property_expression_new (SETTINGS_TYPE_KEY, NULL, "name");
filter = gtk_string_filter_new ();
gtk_string_filter_set_expression (GTK_STRING_FILTER (filter), expression);
filter_model = gtk_filter_list_model_new (G_LIST_MODEL (sort_model), filter);
gtk_expression_unref (expression);
g_object_unref (sort_model);
g_set_object (&current_filter, filter);
g_object_unref (filter);
g_value_take_object (to_value, filter_model);
return TRUE;
}
static GListModel *
create_settings_model (gpointer item,
gpointer unused)
{
GSettings *settings = item;
char **schemas;
GListStore *result;
guint i;
if (settings == NULL)
{
g_settings_schema_source_list_schemas (g_settings_schema_source_get_default (),
TRUE,
&schemas,
NULL);
}
else
{
schemas = g_settings_list_children (settings);
}
if (schemas == NULL || schemas[0] == NULL)
{
g_free (schemas);
return NULL;
}
qsort (schemas, g_strv_length (schemas), sizeof (char *), strvcmp);
result = g_list_store_new (G_TYPE_SETTINGS);
for (i = 0; schemas[i] != NULL; i++)
{
GSettings *child;
if (settings == NULL)
child = g_settings_new (schemas[i]);
else
child = g_settings_get_child (settings, schemas[i]);
g_list_store_append (result, child);
g_object_unref (child);
}
g_strfreev (schemas);
return G_LIST_MODEL (result);
}
static void
search_enabled (GtkSearchEntry *entry)
{
gtk_editable_set_text (GTK_EDITABLE (entry), "");
}
static void
search_changed (GtkSearchEntry *entry,
gpointer data)
{
const char *text = gtk_editable_get_text (GTK_EDITABLE (entry));
if (current_filter)
gtk_string_filter_set_search (GTK_STRING_FILTER (current_filter), text);
}
static void
stop_search (GtkSearchEntry *entry,
gpointer data)
{
gtk_editable_set_text (GTK_EDITABLE (entry), "");
if (current_filter)
gtk_string_filter_set_search (GTK_STRING_FILTER (current_filter), "");
}
static GtkWidget *window = NULL;
GtkWidget *
do_listview_settings (GtkWidget *do_widget)
{
if (window == NULL)
{
GtkWidget *listview, *columnview;
GListModel *model;
GtkTreeListModel *treemodel;
GtkSingleSelection *selection;
GtkBuilderScope *scope;
GtkBuilder *builder;
GtkColumnViewColumn *name_column;
GtkSorter *sorter;
g_type_ensure (SETTINGS_TYPE_KEY);
scope = gtk_builder_cscope_new ();
gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "search_enabled", (GCallback)search_enabled);
gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "search_changed", (GCallback)search_changed);
gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope), "stop_search", (GCallback)stop_search);
builder = gtk_builder_new ();
gtk_builder_set_scope (builder, scope);
gtk_builder_add_from_resource (builder, "/listview_settings/listview_settings.ui", NULL);
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &window);
listview = GTK_WIDGET (gtk_builder_get_object (builder, "listview"));
columnview = GTK_WIDGET (gtk_builder_get_object (builder, "columnview"));
model = create_settings_model (NULL, NULL);
treemodel = gtk_tree_list_model_new (FALSE,
model,
TRUE,
create_settings_model,
NULL,
NULL);
selection = gtk_single_selection_new (G_LIST_MODEL (treemodel));
g_object_bind_property_full (selection, "selected-item",
columnview, "model",
G_BINDING_SYNC_CREATE,
transform_settings_to_keys,
NULL,
columnview, NULL);
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
g_object_unref (selection);
g_object_unref (treemodel);
g_object_unref (model);
name_column = GTK_COLUMN_VIEW_COLUMN (gtk_builder_get_object (builder, "name_column"));
sorter = gtk_string_sorter_new (gtk_property_expression_new (SETTINGS_TYPE_KEY, NULL, "name"));
gtk_column_view_column_set_sorter (name_column, sorter);
g_object_unref (sorter);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window">
<property name="title" translatable="yes">Settings</property>
<property name="default-width">640</property>
<property name="default-height">480</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="show-title-buttons">1</property>
<child type="end">
<object class="GtkToggleButton" id="search_button">
<property name="icon-name">system-search-symbolic</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkPaned">
<property name="position">300</property>
<child>
<object class="GtkScrolledWindow">
<child>
<object class="GtkListView" id="listview">
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkTreeExpander" id="expander">
<binding name="list-row">
<lookup name="item">GtkListItem</lookup>
</binding>
<property name="child">
<object class="GtkLabel">
<property name="xalign">0</property>
<binding name="label">
<lookup name="schema" type="GSettings">
<lookup name="item">expander</lookup>
</lookup>
</binding>
</object>
</property>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkSearchBar">
<property name="search-mode-enabled" bind-source="search_button" bind-property="active" bind-flags="bidirectional"/>
<signal name="notify::search-mode-enabled" handler="search_enabled" object="entry"/>
<child>
<object class="GtkSearchEntry" id="entry">
<signal name="search-changed" handler="search_changed"/>
<signal name="stop-search" handler="stop_search"/>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<child>
<object class="GtkColumnView" id="columnview">
<child>
<object class="GtkColumnViewColumn" id="name_column">
<property name="title">Name</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="xalign">0</property>
<binding name="label">
<lookup name="name" type="SettingsKey">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn">
<property name="title">Value</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="xalign">0</property>
<binding name="label">
<lookup name="value" type="SettingsKey">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@@ -0,0 +1,326 @@
/* Lists/Weather
*
* This demo shows a few of the rarer features of GtkListView and
* how they can be used to display weather information.
*
* The hourly weather info uses a horizontal listview. This is easy
* to achieve because GtkListView implements the GtkOrientable interface.
* To make the items in the list stand out more, the listview uses
* separators.
*
* A GtkNoSelectionModel is used to make sure no item in the list can be
* selected. All other interactions with the items is still possible.
*
* The dataset used here has 70000 items.
*/
#include <gtk/gtk.h>
#define GTK_TYPE_WEATHER_INFO (gtk_weather_info_get_type ())
G_DECLARE_FINAL_TYPE (GtkWeatherInfo, gtk_weather_info, GTK, WEATHER_INFO, GObject)
typedef enum {
GTK_WEATHER_CLEAR,
GTK_WEATHER_FEW_CLOUDS,
GTK_WEATHER_FOG,
GTK_WEATHER_OVERCAST,
GTK_WEATHER_SCATTERED_SHOWERS,
GTK_WEATHER_SHOWERS,
GTK_WEATHER_SNOW,
GTK_WEATHER_STORM
} GtkWeatherType;
struct _GtkWeatherInfo
{
GObject parent_instance;
gint64 timestamp;
int temperature;
GtkWeatherType weather_type;
};
struct _GtkWeatherInfoClass
{
GObjectClass parent_class;
};
G_DEFINE_TYPE (GtkWeatherInfo, gtk_weather_info, G_TYPE_OBJECT)
static void
gtk_weather_info_class_init (GtkWeatherInfoClass *klass)
{
}
static void
gtk_weather_info_init (GtkWeatherInfo *self)
{
}
static GtkWeatherInfo *
gtk_weather_info_new (GDateTime *timestamp,
GtkWeatherInfo *copy_from)
{
GtkWeatherInfo *result;
result = g_object_new (GTK_TYPE_WEATHER_INFO, NULL);
result->timestamp = g_date_time_to_unix (timestamp);
if (copy_from)
{
result->temperature = copy_from->temperature;
result->weather_type = copy_from->weather_type;
g_object_unref (copy_from);
}
return result;
}
static GDateTime *
parse_timestamp (const char *string,
GTimeZone *timezone)
{
char *with_seconds;
GDateTime *result;
with_seconds = g_strconcat (string, ":00", NULL);
result = g_date_time_new_from_iso8601 (with_seconds, timezone);
g_free (with_seconds);
return result;
}
static GtkWeatherType
parse_weather_type (const char *clouds,
const char *precip,
GtkWeatherType fallback)
{
if (strstr (precip, "SN"))
return GTK_WEATHER_SNOW;
if (strstr (precip, "TS"))
return GTK_WEATHER_STORM;
if (strstr (precip, "DZ"))
return GTK_WEATHER_SCATTERED_SHOWERS;
if (strstr (precip, "SH") || strstr (precip, "RA"))
return GTK_WEATHER_SHOWERS;
if (strstr (precip, "FG"))
return GTK_WEATHER_FOG;
if (g_str_equal (clouds, "M") ||
g_str_equal (clouds, ""))
return fallback;
if (strstr (clouds, "OVC") ||
strstr (clouds, "BKN"))
return GTK_WEATHER_OVERCAST;
if (strstr (clouds, "BKN") ||
strstr (clouds, "SCT"))
return GTK_WEATHER_FEW_CLOUDS;
if (strstr (clouds, "VV"))
return GTK_WEATHER_FOG;
return GTK_WEATHER_CLEAR;
}
static double
parse_temperature (const char *s,
double fallback)
{
char *endptr;
double d;
d = g_ascii_strtod (s, &endptr);
if (*endptr != '\0')
return fallback;
return d;
}
static GListModel *
create_weather_model (void)
{
GListStore *store;
GTimeZone *utc;
GDateTime *timestamp;
GtkWeatherInfo *info;
GBytes *data;
char **lines;
guint i;
store = g_list_store_new (GTK_TYPE_WEATHER_INFO);
data = g_resources_lookup_data ("/listview_weather/listview_weather.txt", 0, NULL);
lines = g_strsplit (g_bytes_get_data (data, NULL), "\n", 0);
utc = g_time_zone_new_utc ();
timestamp = g_date_time_new (utc, 2011, 1, 1, 0, 0, 0);
info = gtk_weather_info_new (timestamp, NULL);
g_list_store_append (store, info);
for (i = 0; lines[i] != NULL && *lines[i]; i++)
{
char **fields;
GDateTime *date;
fields = g_strsplit (lines[i], ",", 0);
date = parse_timestamp (fields[0], utc);
while (g_date_time_difference (date, timestamp) > 30 * G_TIME_SPAN_MINUTE)
{
GDateTime *new_timestamp = g_date_time_add_hours (timestamp, 1);
g_date_time_unref (timestamp);
timestamp = new_timestamp;
info = gtk_weather_info_new (timestamp, info);
g_list_store_append (store, info);
}
info->temperature = parse_temperature (fields[1], info->temperature);
info->weather_type = parse_weather_type (fields[2], fields[3], info->weather_type);
g_date_time_unref (date);
g_strfreev (fields);
}
g_strfreev (lines);
g_bytes_unref (data);
g_time_zone_unref (utc);
return G_LIST_MODEL (store);
}
static void
setup_widget (GtkListItem *list_item,
gpointer unused)
{
GtkWidget *box, *child;
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_list_item_set_child (list_item, box);
child = gtk_label_new (NULL);
gtk_label_set_width_chars (GTK_LABEL (child), 5);
gtk_box_append (GTK_BOX (box), child);
child = gtk_image_new ();
gtk_image_set_icon_size (GTK_IMAGE (child), GTK_ICON_SIZE_LARGE);
gtk_box_append (GTK_BOX (box), child);
child = gtk_label_new (NULL);
gtk_widget_set_vexpand (child, TRUE);
gtk_widget_set_valign (child, GTK_ALIGN_END);
gtk_label_set_width_chars (GTK_LABEL (child), 4);
gtk_box_append (GTK_BOX (box), child);
}
static void
bind_widget (GtkListItem *list_item,
gpointer unused)
{
GtkWidget *box, *child;
GtkWeatherInfo *info;
GDateTime *timestamp;
char *s;
box = gtk_list_item_get_child (list_item);
info = gtk_list_item_get_item (list_item);
child = gtk_widget_get_first_child (box);
timestamp = g_date_time_new_from_unix_utc (info->timestamp);
s = g_date_time_format (timestamp, "%R");
gtk_label_set_text (GTK_LABEL (child), s);
g_free (s);
g_date_time_unref (timestamp);
child = gtk_widget_get_next_sibling (child);
switch (info->weather_type)
{
case GTK_WEATHER_CLEAR:
gtk_image_set_from_icon_name (GTK_IMAGE (child), "weather-clear-symbolic");
break;
case GTK_WEATHER_FEW_CLOUDS:
gtk_image_set_from_icon_name (GTK_IMAGE (child), "weather-few-clouds-symbolic");
break;
case GTK_WEATHER_FOG:
gtk_image_set_from_icon_name (GTK_IMAGE (child), "weather-fog-symbolic");
break;
case GTK_WEATHER_OVERCAST:
gtk_image_set_from_icon_name (GTK_IMAGE (child), "weather-overcast-symbolic");
break;
case GTK_WEATHER_SCATTERED_SHOWERS:
gtk_image_set_from_icon_name (GTK_IMAGE (child), "weather-showers-scattered-symbolic");
break;
case GTK_WEATHER_SHOWERS:
gtk_image_set_from_icon_name (GTK_IMAGE (child), "weather-showers-symbolic");
break;
case GTK_WEATHER_SNOW:
gtk_image_set_from_icon_name (GTK_IMAGE (child), "weather-snow-symbolic");
break;
case GTK_WEATHER_STORM:
gtk_image_set_from_icon_name (GTK_IMAGE (child), "weather-storm-symbolic");
break;
default:
gtk_image_clear (GTK_IMAGE (child));
break;
}
child = gtk_widget_get_next_sibling (child);
s = g_strdup_printf ("%d°", info->temperature);
gtk_label_set_text (GTK_LABEL (child), s);
g_free (s);
}
static GtkWidget *window = NULL;
GtkWidget *
create_weather_view (void)
{
GtkWidget *listview;
GListModel *model, *selection;
listview = gtk_list_view_new_with_factory (
gtk_functions_list_item_factory_new (setup_widget,
bind_widget,
NULL, NULL));
gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL);
gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
model = create_weather_model ();
selection = G_LIST_MODEL (gtk_no_selection_new (model));
gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
g_object_unref (selection);
g_object_unref (model);
return listview;
}
GtkWidget *
do_listview_weather (GtkWidget *do_widget)
{
if (window == NULL)
{
GtkWidget *listview, *sw;;
window = gtk_window_new ();
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
gtk_window_set_title (GTK_WINDOW (window), "Weather");
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Weather");
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &window);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_window_set_child (GTK_WINDOW (window), sw);
listview = create_weather_view ();
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkTreeExpander" id="expander">
<binding name="list-row">
<lookup name="item">GtkListItem</lookup>
</binding>
<property name="child">
<object class="GtkLabel">
<property name="halign">start</property>
<binding name="label">
<lookup name="title" type="GtkDemo">
<lookup name="item">expander</lookup>
</lookup>
</binding>
</object>
</property>
</object>
</property>
</template>
</interface>

View File

@@ -8,6 +8,7 @@
#include <gtk/gtk.h>
#include <glib/gstdio.h>
#include "award.h"
#include "demos.h"
static GtkWidget *info_view;
@@ -16,18 +17,96 @@ static GtkWidget *source_view;
static gchar *current_file = NULL;
static GtkWidget *notebook;
static GtkWidget *treeview;
static GtkSingleSelection *selection;
static GtkWidget *toplevel;
enum {
NAME_COLUMN,
TITLE_COLUMN,
FILENAME_COLUMN,
FUNC_COLUMN,
STYLE_COLUMN,
NUM_COLUMNS
typedef struct _GtkDemo GtkDemo;
struct _GtkDemo
{
GObject parent_instance;
const char *name;
const char *title;
const char *filename;
GDoDemoFunc func;
GListModel *children_model;
};
enum {
PROP_0,
PROP_FILENAME,
PROP_NAME,
PROP_TITLE,
N_PROPS
};
# define GTK_TYPE_DEMO (gtk_demo_get_type ())
G_DECLARE_FINAL_TYPE (GtkDemo, gtk_demo, GTK, DEMO, GObject);
G_DEFINE_TYPE (GtkDemo, gtk_demo, G_TYPE_OBJECT);
static GParamSpec *properties[N_PROPS] = { NULL, };
static void
gtk_demo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GtkDemo *self = GTK_DEMO (object);
switch (property_id)
{
case PROP_FILENAME:
g_value_set_string (value, self->filename);
break;
case PROP_NAME:
g_value_set_string (value, self->name);
break;
case PROP_TITLE:
g_value_set_string (value, self->title);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void gtk_demo_class_init (GtkDemoClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = gtk_demo_get_property;
properties[PROP_FILENAME] =
g_param_spec_string ("filename",
"filename",
"filename",
NULL,
G_PARAM_READABLE);
properties[PROP_NAME] =
g_param_spec_string ("name",
"name",
"name",
NULL,
G_PARAM_READABLE);
properties[PROP_TITLE] =
g_param_spec_string ("title",
"title",
"title",
NULL,
G_PARAM_READABLE);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
static void gtk_demo_init (GtkDemo *self)
{
}
typedef struct _CallbackData CallbackData;
struct _CallbackData
{
@@ -35,6 +114,27 @@ struct _CallbackData
GtkTreePath *path;
};
static gboolean
gtk_demo_run (GtkDemo *self,
GtkWidget *window)
{
GtkWidget *result;
if (!self->func)
return FALSE;
result = self->func (window);
if (result == NULL)
return FALSE;
if (GTK_IS_WINDOW (result))
{
gtk_window_set_transient_for (GTK_WINDOW (result), GTK_WINDOW (window));
gtk_window_set_modal (GTK_WINDOW (result), TRUE);
}
return TRUE;
}
static void
activate_about (GSimpleAction *action,
GVariant *parameter,
@@ -61,7 +161,7 @@ activate_about (GSimpleAction *action,
gtk_get_major_version (),
gtk_get_minor_version (),
gtk_get_micro_version ());
g_string_append_printf (s, "\nA link can apppear here: <http://www.gtk.org>");
g_string_append_printf (s, "\nA link can appear here: <http://www.gtk.org>");
version = g_strdup_printf ("%s\nRunning against GTK %d.%d.%d",
PACKAGE_VERSION,
@@ -101,7 +201,7 @@ activate_quit (GSimpleAction *action,
win = list->data;
next = list->next;
gtk_widget_destroy (GTK_WIDGET (win));
gtk_window_destroy (GTK_WINDOW (win));
list = next;
}
@@ -113,84 +213,18 @@ activate_inspector (GSimpleAction *action,
gpointer user_data)
{
gtk_window_set_interactive_debugging (TRUE);
}
static void
window_closed_cb (GtkWidget *window, gpointer data)
{
CallbackData *cbdata = data;
GtkTreeIter iter;
PangoStyle style;
gtk_tree_model_get_iter (cbdata->model, &iter, cbdata->path);
gtk_tree_model_get (GTK_TREE_MODEL (cbdata->model), &iter,
STYLE_COLUMN, &style,
-1);
if (style == PANGO_STYLE_ITALIC)
gtk_tree_store_set (GTK_TREE_STORE (cbdata->model), &iter,
STYLE_COLUMN, PANGO_STYLE_NORMAL,
-1);
gtk_tree_path_free (cbdata->path);
g_free (cbdata);
}
static void
run_example_for_row (GtkWidget *window,
GtkTreeModel *model,
GtkTreeIter *iter)
{
PangoStyle style;
GDoDemoFunc func;
GtkWidget *demo;
gtk_tree_model_get (GTK_TREE_MODEL (model),
iter,
FUNC_COLUMN, &func,
STYLE_COLUMN, &style,
-1);
if (func)
{
gtk_tree_store_set (GTK_TREE_STORE (model),
iter,
STYLE_COLUMN, (style == PANGO_STYLE_ITALIC ? PANGO_STYLE_NORMAL : PANGO_STYLE_ITALIC),
-1);
demo = (func) (window);
if (demo != NULL)
{
CallbackData *cbdata;
cbdata = g_new (CallbackData, 1);
cbdata->model = model;
cbdata->path = gtk_tree_model_get_path (model, iter);
if (GTK_IS_WINDOW (demo))
{
gtk_window_set_transient_for (GTK_WINDOW (demo), GTK_WINDOW (window));
gtk_window_set_modal (GTK_WINDOW (demo), TRUE);
}
g_signal_connect (demo, "destroy",
G_CALLBACK (window_closed_cb), cbdata);
}
}
award ("demo-inspector");
}
static void
activate_run (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
gpointer window)
{
GtkWidget *window = user_data;
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreeIter iter;
GtkTreeListRow *row = gtk_single_selection_get_selected_item (selection);
GtkDemo *demo = gtk_tree_list_row_get_item (row);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
if (gtk_tree_selection_get_selected (selection, &model, &iter))
run_example_for_row (window, model, &iter);
gtk_demo_run (demo, window);
}
/* Stupid syntax highlighting.
@@ -895,124 +929,93 @@ load_file (const gchar *demoname,
}
static void
selection_cb (GtkTreeSelection *selection,
GtkTreeModel *model)
activate_cb (GtkWidget *widget,
guint position,
gpointer window)
{
GtkTreeIter iter;
char *name;
char *filename;
char *title;
GtkTreeListRow *row = g_list_model_get_item (gtk_list_view_get_model (GTK_LIST_VIEW (widget)), position);
GtkDemo *demo = gtk_tree_list_row_get_item (row);
if (! gtk_tree_selection_get_selected (selection, NULL, &iter))
return;
gtk_demo_run (demo, window);
gtk_tree_model_get (model, &iter,
NAME_COLUMN, &name,
TITLE_COLUMN, &title,
FILENAME_COLUMN, &filename,
-1);
if (filename)
load_file (name, filename);
gtk_window_set_title (GTK_WINDOW (toplevel), title);
g_free (name);
g_free (title);
g_free (filename);
g_object_unref (row);
}
static void
populate_model (GtkTreeModel *model)
selection_cb (GtkSingleSelection *sel,
GParamSpec *pspec,
gpointer user_data)
{
Demo *d = gtk_demos;
GtkTreeListRow *row = gtk_single_selection_get_selected_item (sel);
GtkDemo *demo = gtk_tree_list_row_get_item (row);
/* this code only supports 1 level of children. If we
* want more we probably have to use a recursing function.
*/
while (d->title)
if (demo->filename)
load_file (demo->name, demo->filename);
gtk_window_set_title (GTK_WINDOW (toplevel), demo->title);
}
static GListModel *
create_demo_model (void)
{
GListStore *store = g_list_store_new (GTK_TYPE_DEMO);
DemoData *demo = gtk_demos;
while (demo->title)
{
Demo *children = d->children;
GtkTreeIter iter;
GtkDemo *d = GTK_DEMO (g_object_new (GTK_TYPE_DEMO, NULL));
DemoData *children = demo->children;
gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
d->name = demo->name;
d->title = demo->title;
d->filename = demo->filename;
d->func = demo->func;
gtk_tree_store_set (GTK_TREE_STORE (model),
&iter,
NAME_COLUMN, d->name,
TITLE_COLUMN, d->title,
FILENAME_COLUMN, d->filename,
FUNC_COLUMN, d->func,
STYLE_COLUMN, PANGO_STYLE_NORMAL,
-1);
g_list_store_append (store, d);
d++;
if (!children)
continue;
while (children->title)
if (children)
{
GtkTreeIter child_iter;
d->children_model = G_LIST_MODEL (g_list_store_new (GTK_TYPE_DEMO));
gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &iter);
while (children->title)
{
GtkDemo *child = GTK_DEMO (g_object_new (GTK_TYPE_DEMO, NULL));
gtk_tree_store_set (GTK_TREE_STORE (model),
&child_iter,
NAME_COLUMN, children->name,
TITLE_COLUMN, children->title,
FILENAME_COLUMN, children->filename,
FUNC_COLUMN, children->func,
STYLE_COLUMN, PANGO_STYLE_NORMAL,
-1);
child->name = children->name;
child->title = children->title;
child->filename = children->filename;
child->func = children->func;
children++;
g_list_store_append (G_LIST_STORE (d->children_model), child);
children++;
}
}
demo++;
}
return G_LIST_MODEL (store);
}
static void
startup (GApplication *app)
static GListModel *
get_child_model (gpointer item,
gpointer user_data)
{
GtkBuilder *builder;
GMenuModel *appmenu;
const char *ids[] = { "appmenu", NULL };
GtkDemo *demo = item;
builder = gtk_builder_new ();
gtk_builder_add_objects_from_resource (builder, "/ui/appmenu.ui", ids, NULL);
if (demo->children_model)
return g_object_ref (G_LIST_MODEL (demo->children_model));
appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
g_object_unref (builder);
}
static void
row_activated_cb (GtkWidget *tree_view,
GtkTreePath *path,
GtkTreeViewColumn *column)
{
GtkTreeIter iter;
GtkWidget *window;
GtkTreeModel *model;
window = GTK_WIDGET (gtk_widget_get_root (tree_view));
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
gtk_tree_model_get_iter (model, &iter, path);
run_example_for_row (window, model, &iter);
return NULL;
}
static void
activate (GApplication *app)
{
GtkBuilder *builder;
GtkWindow *window;
GtkWidget *widget;
GtkTreeModel *model;
GtkTreeIter iter;
GListModel *listmodel;
GtkTreeListModel *treemodel;
GtkWidget *window, *listview;
static GActionEntry win_entries[] = {
{ "run", activate_run, NULL, NULL, NULL }
@@ -1020,33 +1023,35 @@ activate (GApplication *app)
builder = gtk_builder_new_from_resource ("/ui/main.ui");
window = (GtkWindow *)gtk_builder_get_object (builder, "window");
gtk_application_add_window (GTK_APPLICATION (app), window);
window = (GtkWidget *)gtk_builder_get_object (builder, "window");
gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (window));
g_action_map_add_action_entries (G_ACTION_MAP (window),
win_entries, G_N_ELEMENTS (win_entries),
window);
notebook = (GtkWidget *)gtk_builder_get_object (builder, "notebook");
notebook = GTK_WIDGET (gtk_builder_get_object (builder, "notebook"));
info_view = (GtkWidget *)gtk_builder_get_object (builder, "info-textview");
source_view = (GtkWidget *)gtk_builder_get_object (builder, "source-textview");
treeview = (GtkWidget *)gtk_builder_get_object (builder, "treeview");
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
info_view = GTK_WIDGET (gtk_builder_get_object (builder, "info-textview"));
source_view = GTK_WIDGET (gtk_builder_get_object (builder, "source-textview"));
toplevel = GTK_WIDGET (window);
listview = GTK_WIDGET (gtk_builder_get_object (builder, "listview"));
g_signal_connect (listview, "activate", G_CALLBACK (activate_cb), window);
load_file (gtk_demos[0].name, gtk_demos[0].filename);
populate_model (model);
listmodel = create_demo_model ();
treemodel = gtk_tree_list_model_new (FALSE,
G_LIST_MODEL (listmodel),
FALSE,
get_child_model,
NULL,
NULL);
selection = gtk_single_selection_new (G_LIST_MODEL (treemodel));
g_signal_connect (selection, "notify::selected-item", G_CALLBACK (selection_cb), NULL);
gtk_list_view_set_model (GTK_LIST_VIEW (listview),
G_LIST_MODEL (selection));
g_signal_connect (treeview, "row-activated", G_CALLBACK (row_activated_cb), model);
widget = (GtkWidget *)gtk_builder_get_object (builder, "treeview-selection");
g_signal_connect (widget, "changed", G_CALLBACK (selection_cb), model);
gtk_tree_model_get_iter_first (gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)), &iter);
gtk_tree_selection_select_iter (GTK_TREE_SELECTION (widget), &iter);
gtk_tree_view_collapse_all (GTK_TREE_VIEW (treeview));
award ("demo-start");
gtk_widget_show (GTK_WIDGET (window));
@@ -1063,7 +1068,7 @@ auto_quit (gpointer data)
static void
list_demos (void)
{
Demo *d, *c;
DemoData *d, *c;
d = gtk_demos;
@@ -1090,7 +1095,7 @@ command_line (GApplication *app,
const gchar *name = NULL;
gboolean autoquit = FALSE;
gboolean list = FALSE;
Demo *d, *c;
DemoData *d, *c;
GDoDemoFunc func = 0;
GtkWidget *window, *demo;
@@ -1219,7 +1224,6 @@ main (int argc, char **argv)
g_application_add_main_option (G_APPLICATION (app), "list", 0, 0, G_OPTION_ARG_NONE, "List examples", NULL);
g_application_add_main_option (G_APPLICATION (app), "autoquit", 0, 0, G_OPTION_ARG_NONE, "Quit after a delay", NULL);
g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
g_signal_connect (app, "handle-local-options", G_CALLBACK (local_options), NULL);

View File

@@ -60,43 +60,24 @@
<child>
<object class="GtkBox">
<child>
<object class="GtkFrame">
<object class="GtkScrolledWindow">
<property name="width-request">120</property>
<property name="hscrollbar-policy">never</property>
<property name="min-content-width">150</property>
<child>
<object class="GtkScrolledWindow">
<property name="width-request">120</property>
<property name="hscrollbar-policy">never</property>
<property name="min-content-width">150</property>
<child>
<object class="GtkTreeView" id="treeview">
<property name="model">treestore</property>
<property name="headers-visible">0</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection">
<property name="mode">browse</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="style">4</attribute>
<attribute name="text">1</attribute>
</attributes>
</child>
<child>
<object class="GtkCellRendererText">
<property name="text"> </property>
</object>
</child>
</object>
</child>
<object class="GtkListView" id="listview">
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="resource">/ui/main-listitem.ui</property>
</object>
</child>
</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkSeparator"/>
</child>
<child>
<object class="GtkNotebook" id="notebook">
<property name="scrollable">1</property>

View File

@@ -58,8 +58,7 @@ do_markup (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_default_size (GTK_WINDOW (window), 450, 450);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
stack = gtk_stack_new ();
gtk_widget_show (stack);
@@ -126,7 +125,7 @@ do_markup (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -1,38 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="appmenu">
<section>
<item>
<attribute name="label" translatable="yes">_New</attribute>
<attribute name="action">app.new</attribute>
<attribute name="accel">&lt;Control&gt;n</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Open</attribute>
<attribute name="action">app.open</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Save</attribute>
<attribute name="action">app.save</attribute>
<attribute name="accel">&lt;Control&gt;s</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Save _As...</attribute>
<attribute name="action">app.save-as</attribute>
<attribute name="accel">&lt;Control&gt;s</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Quit</attribute>
<attribute name="action">app.quit</attribute>
<attribute name="accel">&lt;Control&gt;q</attribute>
</item>
</section>
</menu>
<menu id="menubar">
<submenu>
<attribute name="label" translatable="yes">_Preferences</attribute>
<attribute name="label" translatable="yes">_Application</attribute>
<section>
<item>
<attribute name="label" translatable="yes">_New</attribute>
<attribute name="action">app.new</attribute>
<attribute name="accel">&lt;Control&gt;n</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Open</attribute>
<attribute name="action">app.open</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Save</attribute>
<attribute name="action">app.save</attribute>
<attribute name="accel">&lt;Control&gt;s</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Save _As...</attribute>
<attribute name="action">app.save-as</attribute>
<attribute name="accel">&lt;Control&gt;s</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Quit</attribute>
<attribute name="action">app.quit</attribute>
<attribute name="accel">&lt;Control&gt;q</attribute>
</item>
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">_File</attribute>
<section>
<item>
<attribute name="label" translatable="yes">_Prefer Dark Theme</attribute>

View File

@@ -3,6 +3,7 @@
demos = files([
'application_demo.c',
'assistant.c',
'awardview.c',
'builder.c',
'clipboard.c',
'combobox.c',
@@ -41,6 +42,13 @@ demos = files([
'listbox.c',
'flowbox.c',
'list_store.c',
'listview_applauncher.c',
'listview_clocks.c',
'listview_colors.c',
'listview_filebrowser.c',
'listview_minesweeper.c',
'listview_settings.c',
'listview_weather.c',
'markup.c',
'modelbutton.c',
'overlay.c',
@@ -84,6 +92,7 @@ demos = files([
gtkdemo_deps = [ libgtk_dep, ]
extra_demo_sources = files(['main.c',
'award.c',
'gtkfishbowl.c',
'fontplane.c',
'gtkgears.c',
@@ -95,7 +104,7 @@ extra_demo_sources = files(['main.c',
if harfbuzz_dep.found() and pangoft_dep.found()
demos += files('font_features.c')
extra_demo_sources += files(['script-names.c', 'language-names.c'])
gtkdemo_deps += [ harfbuzz_dep, ]
gtkdemo_deps += [ harfbuzz_dep, epoxy_dep ]
endif
if os_unix

View File

@@ -43,8 +43,7 @@ do_modelbutton (GtkWidget *do_widget)
window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
actions = (GActionGroup*)g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP (actions),
@@ -59,7 +58,7 @@ do_modelbutton (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;

View File

@@ -66,7 +66,7 @@ do_overlay (GtkWidget *do_widget)
gtk_widget_set_can_target (label, FALSE);
gtk_widget_set_margin_top (label, 8);
gtk_widget_set_margin_bottom (label, 8);
gtk_container_add (GTK_CONTAINER (vbox), label);
gtk_box_append (GTK_BOX (vbox), label);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), vbox);
@@ -76,18 +76,16 @@ do_overlay (GtkWidget *do_widget)
gtk_entry_set_placeholder_text (GTK_ENTRY (entry), "Your Lucky Number");
gtk_widget_set_margin_top (entry, 8);
gtk_widget_set_margin_bottom (entry, 8);
gtk_container_add (GTK_CONTAINER (vbox), entry);
gtk_box_append (GTK_BOX (vbox), entry);
gtk_window_set_child (GTK_WINDOW (window), overlay);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -60,9 +60,7 @@ do_overlay2 (GtkWidget *do_widget)
gtk_window_set_child (GTK_WINDOW (window), overlay);
gtk_overlay_set_child (GTK_OVERLAY (overlay), sw);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), text);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
image = gtk_picture_new_for_resource ("/overlay2/decor1.png");
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), image);
@@ -97,7 +95,7 @@ do_overlay2 (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -11,7 +11,7 @@
static void
done_cb (GtkDialog *dialog, gint response, gpointer data)
{
gtk_widget_destroy (GTK_WIDGET (dialog));
gtk_window_destroy (GTK_WINDOW (dialog));
}
GtkWidget *
@@ -22,14 +22,14 @@ do_pagesetup (GtkWidget *do_widget)
if (!window)
{
window = gtk_page_setup_unix_dialog_new ("Page Setup", GTK_WINDOW (do_widget));
g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
g_signal_connect (window, "response", G_CALLBACK (done_cb), NULL);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -405,16 +405,13 @@ do_paint (GtkWidget *toplevel)
gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), colorbutton);
gtk_window_set_titlebar (GTK_WINDOW (window), headerbar);
gtk_window_set_title (GTK_WINDOW (window), "Paint");
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -171,7 +171,7 @@ do_paintable (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -203,7 +203,7 @@ do_paintable_animated (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -218,7 +218,7 @@ gtk_nuclear_media_stream_seek (GtkMediaStream *stream,
gtk_media_stream_seek_success (stream);
/* We also have to update our timestamp and tell the
* paintable interface abbout the seek
* paintable interface about the seek
*/
gtk_media_stream_update (stream, nuclear->progress);
gdk_paintable_invalidate_contents (GDK_PAINTABLE (nuclear));
@@ -263,7 +263,7 @@ gtk_nuclear_media_stream_init (GtkNuclearMediaStream *nuclear)
/* This time, we don't have to add a timer here, because media
* streams start paused.
*
* However, media streams need to tell GTK once they are intialized,
* However, media streams need to tell GTK once they are initialized,
* so we do that here.
*/
gtk_media_stream_prepared (GTK_MEDIA_STREAM (nuclear),
@@ -306,7 +306,7 @@ do_paintable_mediastream (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -19,32 +19,14 @@ toggle_resize (GtkWidget *widget,
{
GtkWidget *parent;
GtkPaned *paned;
gboolean is_child1;
gboolean resize, shrink;
parent = gtk_widget_get_parent (child);
paned = GTK_PANED (parent);
is_child1 = (child == gtk_paned_get_child1 (paned));
if (is_child1)
g_object_get (paned,
"resize-child1", &resize,
"shrink-child1", &shrink,
NULL);
if (child == gtk_paned_get_start_child (paned))
gtk_paned_set_resize_start_child (paned, !gtk_paned_get_resize_start_child (paned));
else
g_object_get (paned,
"resize-child2", &resize,
"shrink-child2", &shrink,
NULL);
g_object_ref (child);
gtk_container_remove (GTK_CONTAINER (parent), child);
if (is_child1)
gtk_paned_pack1 (paned, child, !resize, shrink);
else
gtk_paned_pack2 (paned, child, !resize, shrink);
g_object_unref (child);
gtk_paned_set_resize_end_child (paned, !gtk_paned_get_resize_end_child (paned));
}
static void
@@ -53,32 +35,14 @@ toggle_shrink (GtkWidget *widget,
{
GtkWidget *parent;
GtkPaned *paned;
gboolean is_child1;
gboolean resize, shrink;
parent = gtk_widget_get_parent (child);
paned = GTK_PANED (parent);
is_child1 = (child == gtk_paned_get_child1 (paned));
if (is_child1)
g_object_get (paned,
"resize-child1", &resize,
"shrink-child1", &shrink,
NULL);
if (child == gtk_paned_get_start_child (paned))
gtk_paned_set_shrink_start_child (paned, !gtk_paned_get_shrink_start_child (paned));
else
g_object_get (paned,
"resize-child2", &resize,
"shrink-child2", &shrink,
NULL);
g_object_ref (child);
gtk_container_remove (GTK_CONTAINER (parent), child);
if (is_child1)
gtk_paned_pack1 (paned, child, resize, !shrink);
else
gtk_paned_pack2 (paned, child, resize, !shrink);
g_object_unref (child);
gtk_paned_set_shrink_end_child (paned, !gtk_paned_get_shrink_end_child (paned));
}
static GtkWidget *
@@ -93,8 +57,8 @@ create_pane_options (GtkPaned *paned,
GtkWidget *label;
GtkWidget *check_button;
child1 = gtk_paned_get_child1 (paned);
child2 = gtk_paned_get_child2 (paned);
child1 = gtk_paned_get_start_child (paned);
child2 = gtk_paned_get_end_child (paned);
frame = gtk_frame_new (frame_label);
gtk_widget_set_margin_start (frame, 4);
@@ -152,9 +116,7 @@ do_panes (GtkWidget *do_widget)
window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
gtk_window_set_title (GTK_WINDOW (window), "Paned Widgets");
@@ -166,35 +128,35 @@ do_panes (GtkWidget *do_widget)
gtk_widget_set_margin_end (vpaned, 5);
gtk_widget_set_margin_top (vpaned, 5);
gtk_widget_set_margin_bottom (vpaned, 5);
gtk_container_add (GTK_CONTAINER (vbox), vpaned);
gtk_box_append (GTK_BOX (vbox), vpaned);
hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
gtk_paned_add1 (GTK_PANED (vpaned), hpaned);
gtk_paned_set_start_child (GTK_PANED (vpaned), hpaned);
frame = gtk_frame_new (NULL);
gtk_widget_set_size_request (frame, 60, 60);
gtk_paned_add1 (GTK_PANED (hpaned), frame);
gtk_paned_set_start_child (GTK_PANED (hpaned), frame);
button = gtk_button_new_with_mnemonic ("_Hi there");
gtk_frame_set_child (GTK_FRAME (frame), button);
frame = gtk_frame_new (NULL);
gtk_widget_set_size_request (frame, 80, 60);
gtk_paned_add2 (GTK_PANED (hpaned), frame);
gtk_paned_set_end_child (GTK_PANED (hpaned), frame);
frame = gtk_frame_new (NULL);
gtk_widget_set_size_request (frame, 60, 80);
gtk_paned_add2 (GTK_PANED (vpaned), frame);
gtk_paned_set_end_child (GTK_PANED (vpaned), frame);
/* Now create toggle buttons to control sizing */
gtk_container_add (GTK_CONTAINER (vbox),
gtk_box_append (GTK_BOX (vbox),
create_pane_options (GTK_PANED (hpaned),
"Horizontal",
"Left",
"Right"));
gtk_container_add (GTK_CONTAINER (vbox),
gtk_box_append (GTK_BOX (vbox),
create_pane_options (GTK_PANED (vpaned),
"Vertical",
"Top",
@@ -204,7 +166,7 @@ do_panes (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -11,6 +11,8 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "award.h"
static GtkWidget *entry;
static GtkWidget *entry2;
static GtkWidget *button;
@@ -25,6 +27,18 @@ update_button (GObject *object,
gtk_widget_set_sensitive (button,
text[0] != '\0' && g_str_equal (text, text2));
if (g_str_equal (text, text2) &&
g_ascii_strcasecmp (text, "12345") == 0)
award ("password-best");
}
static void
button_pressed (GtkButton *widget,
GtkWidget *window)
{
award ("password-correct");
gtk_window_destroy (GTK_WINDOW (window));
}
GtkWidget *
@@ -45,8 +59,7 @@ do_password_entry (GtkWidget *do_widget)
gtk_window_set_title (GTK_WINDOW (window), "Choose a Password");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
gtk_window_set_deletable (GTK_WINDOW (window), FALSE);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_widget_set_margin_start (box, 18);
@@ -62,7 +75,7 @@ do_password_entry (GtkWidget *do_widget)
"activates-default", TRUE,
NULL);
g_signal_connect (entry, "notify::text", G_CALLBACK (update_button), NULL);
gtk_container_add (GTK_CONTAINER (box), entry);
gtk_box_append (GTK_BOX (box), entry);
entry2 = gtk_password_entry_new ();
gtk_password_entry_set_show_peek_icon (GTK_PASSWORD_ENTRY (entry2), TRUE);
@@ -71,11 +84,11 @@ do_password_entry (GtkWidget *do_widget)
"activates-default", TRUE,
NULL);
g_signal_connect (entry2, "notify::text", G_CALLBACK (update_button), NULL);
gtk_container_add (GTK_CONTAINER (box), entry2);
gtk_box_append (GTK_BOX (box), entry2);
button = gtk_button_new_with_mnemonic ("_Done");
gtk_widget_add_css_class (button, "suggested-action");
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
g_signal_connect (button, "clicked", G_CALLBACK (button_pressed), window);
gtk_widget_set_sensitive (button, FALSE);
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
@@ -85,7 +98,7 @@ do_password_entry (GtkWidget *do_widget)
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

Some files were not shown because too many files have changed in this diff Show More