Commit Graph

186 Commits

Author SHA1 Message Date
Benjamin Otte
c59948169d iconhelper: transition to GdkPaintable
This is in preparation for accepting the image type paintable.

It's a bit incovenient because we need more code to track width/height
ourselves (as the paintable no longer does it for us), but it's not too
hard.

GtkIconHelper does not track invalidations on the paintable.
2018-03-16 06:04:44 +01:00
Matthias Clasen
a1c0b81bae icon helper: Avoid gratitious pixbuf use
We can just get the texture directly from the icontheme.
2017-11-30 17:31:17 -05:00
Matthias Clasen
7c4a1a596f icon helper: Avoid a few string copies 2017-11-17 23:21:24 -05:00
Matthias Clasen
c6c3427507 iconhelper: Query size via CSS
Instead of looking at the icon size, look at the CSS value for
-gtk-icon-size. Set style classes depending on icon size instead.

Trivially change Adwaita and HighContrast to report the same values as
before.
2017-11-15 14:22:17 -05:00
Matthias Clasen
2301d8d90b enums: Change GtkIconSize values
The new values are the ones we intend to keep. The old ones had
duplicated meanings and nobody knew which one to take.
2017-11-15 14:22:17 -05:00
Matthias Clasen
dbfaa99107 image: Remove icon-size argument from icon setters
Instead, add a function gtk_image_set_icon_size() for the cases where
overriding the icon size is necessary.

Treat icon sizes the same way as pixel sizes, too. So gtk_image_clear()
no longer unsets the icon size.
2017-11-15 14:22:17 -05:00
Matthias Clasen
2aa52c7d00 Simplify the gtk_snapshot_icon_texture API
Instead of passing the color matrix in from the outside,
just pass a boolean and set up the matrix internally.
2017-11-08 22:21:42 -05:00
Benjamin Otte
0f5d807cae iconhelper: Don't render to surface anymore
Just go directly to texture.
2017-11-05 06:30:45 +01:00
Benjamin Otte
2d959553e9 image: Add the ability to set textures
This also adds it to all other places that use the same infrastructure:
GtkEntry and GtkCellRendererPixbuf
2017-11-05 00:07:17 +01:00
Benjamin Otte
a0ff63e162 iconhelper: Compute surface size without icon helper
This is so we can do the next batch of changes
2017-11-04 15:22:25 +01:00
Benjamin Otte
ca3c23662c GskTexture => GdkTexture
We want this thing to replace GdkPixbuf, so it has to live in GDK.
2017-11-04 00:07:13 +01:00
Alexander Larsson
96b04836d8 Drop all uses of GdkPixbufAnimation in the gtk APIs
These are basically animated gifs, and don't fit well in how
modern things animate.
2017-10-23 16:56:49 +02:00
Alexander Larsson
b1250935a0 GtkIconHelper: Remove unused code 2017-10-23 15:34:17 +02:00
Alexander Larsson
0089e4ad58 Drop pixbuf support in IconHelper and ImageDefinition
These are no longer used, instead we always covert to surface as
early as possible and drop the pixbuf.

This means we never store both the pixbuf and the surface at
for any longer time, which is wasteful. Also, its one step further
to drop GdkPixbufs from generic use in our APIs.
2017-10-23 15:28:33 +02:00
Matthias Clasen
a072f9fc06 Use a color matrix for symbolic icons
The recoloring of symbolic icons is just a color matrix
operation.
2017-10-23 11:47:17 +02:00
Matthias Clasen
e4cdbef092 Allow passing a color matrix when rendering icons
This will be used for symbolic icons.
Update all callers.
2017-10-23 11:44:52 +02:00
Matthias Clasen
b543257e42 icon helper: Use cached textures
Use a cached texture for themed icons if we can.
Currently, we only do this for non-symbolic icons.
2017-10-23 08:07:35 +02:00
Timm Bäder
4e24cb8588 css: Add GTK_CSS_AFFECTS_ICON_SIZE
And use it in GtkIconHelper. This way, we can avoid resizes when e.g.
the fg color of a symbolic icon changes.
2017-10-14 17:27:55 +02:00
Timm Bäder
ce5560a790 iconhelper: Short-circuit clear() if it's cleared already 2017-10-14 17:27:55 +02:00
Benjamin Otte
43c212ac28 build: Enable -Wswitch-enum and -Wswitch-default
This patch makes that work using 1 of 2 options:

1. Add all missing enums to the switch statement
  or
2. Cast the switch argument to a uint to avoid having to do that (mostly
   for GdkEventType).

I even found a bug while doing that: clearing a GtkImage with a surface
did not notify thae surface property.

The reason for enabling this flag even though it is tedious at times is
that it is very useful when adding values to an enum, because it makes
GTK immediately warn about all the switch statements where this enum is
relevant.
And I expect changes to enums to be frequent during the GTK4 development
cycle.
2017-10-06 21:23:39 +02:00
Timm Bäder
a32725bc9a iconhelper: Don't inherit from GObject
It's not a GtkCssGadget anymore, it doesn't have any properties or
signals either and it's not public. Further, its lifetime is very clear
the way it's being used inside GTK+.
2017-10-01 09:19:09 +02:00
Timm Bäder
7b5c12c7dc iconhelper: Inherit from GObject
Nothing is using any gadget API on iconhelpers anymore.
2017-07-19 21:27:14 -04:00
Robert Ancell
82a4e830a3 iconhelper: Show error if fail to load placeholder icon 2017-06-09 09:24:02 +12:00
Timm Bäder
4e141883e8 iconhelper: Remove unused _draw implementation 2017-02-14 16:56:55 +01:00
Benjamin Otte
87497ca2e1 snapshot: Rename gtk_snapshot_translate_2d()
It's now called gtk_snapshot_offset().
2017-01-13 14:37:48 +01:00
Matthias Clasen
a013a16d1c Use _gtk_widget_get_window more
This avoids type checks in places where we know it is safe.
2017-01-10 19:56:02 -05:00
Benjamin Otte
2571036c07 gsk: Turn GskTexture into a GObject 2017-01-01 19:53:36 +01:00
Benjamin Otte
45fbc25e5e css: Remove -gtk-icon-effect
-gtk-icon-filter replaces this now.
2016-12-31 02:49:47 +01:00
Benjamin Otte
1d84555729 iconhelper: Invalidate style before accessing texture
Invalidating the style might cause invalidation of the texture. So we
end up with a pointer to freed memory.
SAD!
2016-12-24 06:19:16 +01:00
Benjamin Otte
c258ee403a snapshot: Make gtk_snapshot_get_renderer() private
Public API doesn't need to be concerned with renderers. Worst case, they
can use NULL instead of the actual renderer.
2016-12-20 18:01:10 +01:00
Benjamin Otte
3ba5c70028 iconhelper: Implement snapshot 2016-12-19 05:36:06 +01:00
Timm Bäder
3dac21f20b entry: Refactor get_icon_pixbuf
This way it will only return a pixbuf if the icon helper has a pixbuf.
2016-12-03 13:19:26 +01:00
Timm Bäder
8a543ab23c iconhelper: Ensure the surface used for textures is ARGB32 2016-12-03 13:19:26 +01:00
Timm Bäder
49508ddfdb iconhelper: Remove allocate implementation 2016-12-03 13:19:26 +01:00
Benjamin Otte
8161f8dcca rendericon: Pass the scale factor when rendeirng textures
Fixes icon rendeirng on hidpi.
2016-11-26 11:52:30 +01:00
Benjamin Otte
2745c2502f snapshot: Move GtkSnapshot declaration to gtypes.h 2016-11-19 20:58:36 +01:00
Benjamin Otte
6d9725f7fd snapshot: Add infrastructure to snapshot CSS images
Use this infrastructure to render builtin images. Which means from now
on, GtkCheckbutton, GtkSpinner and a few others use snapshots.
2016-11-16 20:51:53 +01:00
Benjamin Otte
40565fb030 gsk: Rework GskTexture
We do no longer bind textures to a renderer, instead they are a way for
applications to provide texture data.

For now, that's it. We've reverted to uploading it from scratch every
frame.
2016-11-16 17:36:33 +01:00
Benjamin Otte
dad8703e03 snapshot: Convert GtkSpinner 2016-11-15 17:49:19 +01:00
Benjamin Otte
4b8b06bb08 image: Invalidate icon helper when unrealizing
This frees up any cached surfaces and textures in the iconhelper,
ensuring that the renderer can release its texture data.
2016-11-15 17:49:19 +01:00
Benjamin Otte
c0aa065ac1 snapshot: Convert GtkImage and GtkIconHelper
Adds a bunch of new APIs to render textures with theming.

FIXME: Cannot draw shadows for textures.
2016-11-15 17:49:19 +01:00
Benjamin Otte
1259a489f2 iconhelper: Add support for GskTexture
... and use that in GtkImage.
2016-11-08 20:31:34 +01:00
Timm Bäder
ed184b3935 Remove GtkIconFactory
Move the icon size lookup API into gtkicontheme.c
2016-10-16 18:17:21 +02:00
Timm Bäder
627a824cab image: Remove GtkIconSet API 2016-10-16 18:17:21 +02:00
Timm Bäder
ad155fb26c Remove GtkStock API from GtkImage 2016-10-16 18:17:21 +02:00
Daniel Drake
fa23641992 _gtk_icon_helper_draw: get style earlier
After checking for rendered_surface, the call to gtk_css_node_get_style
can invalidate the style and result in rendered_surface being set to
NULL. This was result in some icon views appearing blank on
Endless OS on armv7hl, and this error:

Gtk-CRITICAL **: gtk_css_style_render_icon_surface: assertion 'surface != NULL' failed

Call gtk_css_node_get_style earlier to ensure we always pass a valid
surface to gtk_css_style_render_icon_surface.

https://bugzilla.gnome.org/show_bug.cgi?id=765649
https://phabricator.endlessm.com/T13524
2016-09-26 14:23:51 -07:00
Christian Hergert
8fc11ef2a5 Revert "iconhelper: check if surface was invalidated"
This reverts commit 88d0258397.
2016-04-27 19:02:25 -07:00
Christian Hergert
88d0258397 iconhelper: check if surface was invalidated
Fetching the style may cause the surface to be invalidated.
2016-04-27 17:45:01 -07:00
Benjamin Otte
3bc58d01e3 iconhelper: Invalidate on clear()
When clearing the icon helper, we need to invalidate it. Otherwise the
previous icon keeps lingering along.
This is not relevant inside gtkiconhelper.c where other code causes the
invalidation, but happens when external code calls
_gtk_icon_helper_clear().

https://bugzilla.gnome.org/show_bug.cgi?id=765066
2016-04-14 15:17:02 -04:00
Matthias Clasen
7382f3c347 icon helper: Properly update on style change
A GtkCssChange of NULL means 'everything changed!'.
2016-03-04 08:50:52 -05:00
Matthias Clasen
bbd94b5a9f gtk: Strip newlines from g_warning and g_error
g_logv adds one for us already.
2016-02-28 12:23:12 -05:00
Matthias Clasen
abd781a2c9 icon helper: Don't set baseline to 0
It is clearly not the intention that the baseline of icons is at
the very top. The visible effect of this was that spin buttons were
higher than expeted, because the box gadget was trying to line up
the baseline of the text with the top of the buttons, forcing extra
height to be requested.

Just don't set a baseline at all for now.
2016-02-25 13:18:02 -05:00
Timm Bäder
ded745a4b9 Make gtk_icon_helper_invalidate private 2016-02-07 19:16:26 +01:00
Timm Bäder
0bd6c48315 Add and use gtk_icon_helper_invalidate_for_change 2016-02-07 19:16:26 +01:00
Timm Bäder
0c80210685 iconhelper: Save whether the surface is symbolic 2016-02-07 19:16:26 +01:00
Timm Bäder
2902063f24 iconhelper: Un-duplicate some code 2016-02-07 19:16:26 +01:00
Matthias Clasen
f63e8edec6 Make sure icons update on theme change
Gadgets don't connect to style-changed for widget nodes, and
GtkImage uses its widget node for the icon helper. The visible
effect of this is that symbolic icons don't change color when
switching to the dark variant of Adwaita.

Fix this by manually invalidating the icon helper.
2016-01-04 21:32:19 -05:00
Руслан Ижбулатов
1f154f576a Fix a surface leak
Was introduced as part of b79a187d47.
Results in memory leaks (and GDI objects leaks on W32).
2015-12-27 02:02:19 +00:00
Matthias Clasen
ac65952f0d icon helper: suppress style_changed when transient
Transient nodes should not propagate style-changed signals
that can cause widgets to get reallocated. This was causing
treeviews and iconviews with pixbuf cells to be constantly
resized and redrawn.
2015-12-18 20:53:02 -05:00
Benjamin Otte
1f6efbf669 iconhelper: Queue resize on invalidation
When things change in the iconhelper, queue a resize on the owner widget
so that it automatically resizes.

Only do this for iconhelpers that are used as gadgets though, not for
temporary helpers - and to check this, check if the node is transient.
2015-12-15 08:41:16 -05:00
Benjamin Otte
4586503e93 iconhelper: Finish gadget conversion
Implement missing vfuncs
2015-12-15 08:41:16 -05:00
Benjamin Otte
b79a187d47 iconhelper: Handle invalidation
When CSS, direction or scale factor change, handle the invalidation
inside the iconhelper.
This way the widgets using them don't have to.
2015-12-15 08:41:16 -05:00
Benjamin Otte
de6dca4f81 iconhelper: Use the gadget's node
... instead of looking at the widget's style context.

This removes all calls to the style context.
2015-12-15 08:41:16 -05:00
Benjamin Otte
ad22612ab2 iconhelper: Require passing a cssnode to the constructor
Note that we don't use it yet.
2015-12-15 08:41:16 -05:00
Benjamin Otte
7075d00958 iconhelper: Use the gadget's owner property
Don't keep the owner widget ourselves.
2015-12-15 08:41:16 -05:00
Benjamin Otte
25ecd8cd37 iconhelper: Turn into gadget
This is just the basic conversion to inheriting from
GTK_TYPE_CSS_GADGET.
2015-12-15 08:41:16 -05:00
Benjamin Otte
861ac8e373 iconhelper_ Don't use deprecated functions
Use gtk_widget_get_direction() instead of
gtk_style_context_get_direction().
2015-12-09 13:30:40 +01:00
Benjamin Otte
ccfc4d3f12 iconhelper: Remove the context argument
Instead, use the widget's context.
2015-12-09 13:30:40 +01:00
Benjamin Otte
e95e2d5048 iconhelper: Get rid of _gtk_icon_helper_set_window()
Instead use the window of the owner widget.
2015-12-09 13:30:40 +01:00
Benjamin Otte
c9d1a45d30 iconhelper: Require a widget as construction argument
Note that the caller needs to ensure the widget lives as long as the
iconhelper as the iconhelper will not ref the widget.
2015-12-09 13:30:40 +01:00
Benjamin Otte
01387428a3 iconhelper: Pass only the CssStyle when loading pixbufs 2015-12-09 13:30:40 +01:00
Benjamin Otte
6afeab4313 iconhelper: Remove unused GtkStyleContext parameters 2015-12-09 13:30:40 +01:00
Benjamin Otte
cf77c1695d iconhelper: Pass only the CssStyle when loading iconsets 2015-12-09 13:30:40 +01:00
Benjamin Otte
ee6e685478 iconhelper: Pass only the CssStyle when loading icons
This is the first step in replacing StyleContext usage with CssNode
usage.
2015-12-09 13:30:39 +01:00
Benjamin Otte
d14e2a489a iconhelper: Fold function into callers
The function takes so many arguments and is so short that it's not worth
keeping.
2015-12-04 17:44:51 +01:00
Benjamin Otte
72d4b65b1d iconhelper: Apply icon-effect directly
Instead of creating an icon source, making sure no state is set and
therefore the icon-effect will be applied and then rendering that icon
source, just call the icon-effect apply function.

Also, the new way isn't deprecated.
2015-12-04 17:44:51 +01:00
Benjamin Otte
cefba86fb3 iconhelper: Return surface from icon-effect function
All the callers where converting to a surface anyway.
2015-12-04 17:44:51 +01:00
Benjamin Otte
295f208e1c iconhelper: Refactor missing icon handling
In particular, stop using deprecated code for loading the missing image
icon.
2015-12-04 17:44:51 +01:00
Benjamin Otte
3c54a49633 iconhelper: Fold function into only caller 2015-12-04 17:44:51 +01:00
Benjamin Otte
bc1b53a34c css: Query icon theme from style, not from settings
No need to look at the settings when the CSS has a property for the icon
theme.
2015-12-02 03:18:26 +01:00
Benjamin Otte
0c027937e8 iconhelper: Stop tracking state
The iconfactory code doesn't use it anymore, so we don't need to track
it either.
2015-12-02 00:29:31 +01:00
Benjamin Otte
6a4b91d0ed iconhelper: Remove _gtk_icon_helper_ensure_pixbuf()
The code isn't used anymore. Everything uses
gtk_icon_helper_load_surface() now.
2015-12-02 00:29:30 +01:00
Benjamin Otte
4a42aa5229 imagedefinition: Remove icon-size
The size of icons is a property that is relevant to who is rendering the
icon, not to the icon itself.

Example: Starting a DND operation from an entry icon should cause the
icon to resize (from the entr icon's size to the DND icon size).
2015-12-02 00:29:30 +01:00
Benjamin Otte
e99eba4415 dnd: Rewrite iconhelper code
It now uses GtkImageDefinition instead.
2015-12-02 00:29:30 +01:00
Benjamin Otte
482d71d680 iconhelper: Add a scale argument to gtk_icon_helper_load_surface()
It will be used in the next patch.
2015-12-02 00:29:30 +01:00
Benjamin Otte
afad393b15 iconhelper: Refactor ensure_surface()
Make gtk_icon_helper_ensure_surface() a private function that just
ensures the surface was loaded.

Add gtk_icon_helper_load_surface() that is called by the above function
and the dnd code to actually load the surface.
2015-12-02 00:29:30 +01:00
Benjamin Otte
2ce67f0098 iconhelper: Store surface in ensure_surface()
Do not assign it in the functions that actually load the surface. Make
those just return the surface.
2015-12-02 00:29:30 +01:00
Benjamin Otte
b2584eb8ed iconhelper: Don't store surface size
Instead, compute it on demand.

This avoids having to cache it in lots of places and simplifies code.
2015-12-02 00:29:29 +01:00
Benjamin Otte
751a1a9926 iconhelper: Move invalidation check
Just do the invalidation check once, there's no need to do it in every
branch of the switch.

Also remove useless checks: These functions will not be called if we
already have a rendered surface.
2015-12-02 00:29:29 +01:00
Benjamin Otte
c601a9653a iconhelper: Move invalidation check
Just do the invalidation check once, there's no need to do it in every
branch of the switch.

Also remove useless checks: These functions will not be called if we
already have a rendered surface.
2015-12-02 00:29:29 +01:00
Benjamin Otte
afd0e28437 iconhelper: Improve size determination for surfaces
Instead of just working for image surface, this should now work for all
bounded surfaces.

Test included.
2015-12-02 00:29:29 +01:00
Benjamin Otte
071d2a1d69 iconhelper: Move size computation
We do a switch on the image type, so compute the size for a certain
image type right there.
2015-12-02 00:29:29 +01:00
Benjamin Otte
1c96b703a6 dragsource: Store an itemdefinition, not an iconhelper
The icon is never rendered, so there's no need for the extra iconhelper
code.
2015-12-02 00:29:29 +01:00
Benjamin Otte
e666106a43 imagedefinition: Split out from icon helper
The image definition is supposed to hold the description about the image
to be displayed. The icon helper actually does caching and tracks
changes.
2015-12-02 00:29:29 +01:00
Benjamin Otte
29cdb2001c iconhelper: Don't include gtk.h 2015-11-25 16:32:39 +01:00
Benjamin Otte
4843925660 iconhelper: Remove unused function 2015-11-25 16:32:39 +01:00
Benjamin Otte
2a8e6619a7 iconhelper: Remove unused context argument
Various functions don't use the style context.
2015-11-25 16:32:39 +01:00
Benjamin Otte
5cffbed165 iconhelper: Don't pass GENERIC_FALLBACK flag
It's not used when looking up with a GIcon.
2015-10-28 19:44:26 +01:00
Benjamin Otte
b6bf982289 iconhelper: Track icon-name fallback usage in the GIcon
Passing GTK_ICON_LOOKUP_GENERIC_FALLBACK to the icon lookup doesn't work
for GIcons, so we have to make sure we use the right GThemedIcon.

Fixes image-icon-name-use-fallback reftest.
2015-10-08 14:44:38 +02:00
Matthias Clasen
ddf7501acd More of the same
A similar case in GtkIconHelper. Here we were confusing ourselves,
and compared a icon_size against -1, although the variable is
never set to -1.
2015-03-22 15:14:42 -04:00