-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from byteit101/master
Fix #24: add bindings for CssProvider sufficient to do basic css
- Loading branch information
Showing
9 changed files
with
340 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* java-gnome, a UI library for writing GTK and GNOME programs from Java! | ||
* | ||
* Copyright © 2020 java-gnome contributors | ||
* | ||
* The code in this file, and the program it is a part of, is made available | ||
* to you by its authors as open source software: you can redistribute it | ||
* and/or modify it under the terms of the GNU General Public License version | ||
* 2 ("GPL") as published by the Free Software Foundation. | ||
* | ||
* This program 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 GPL for more details. | ||
* | ||
* You should have received a copy of the GPL along with this program. If not, | ||
* see http://www.gnu.org/licenses/. The authors of this program may be | ||
* contacted through http://java-gnome.sourceforge.net/. | ||
* | ||
* Linking this library statically or dynamically with other modules is making | ||
* a combined work based on this library. Thus, the terms and conditions of | ||
* the GPL cover the whole combination. As a special exception (the | ||
* "Classpath Exception"), the copyright holders of this library give you | ||
* permission to link this library with independent modules to produce an | ||
* executable, regardless of the license terms of these independent modules, | ||
* and to copy and distribute the resulting executable under terms of your | ||
* choice, provided that you also meet, for each linked independent module, | ||
* the terms and conditions of the license of that module. An independent | ||
* module is a module which is not derived from or based on this library. If | ||
* you modify this library, you may extend the Classpath Exception to your | ||
* version of the library, but you are not obligated to do so. If you do not | ||
* wish to do so, delete this exception statement from your version. | ||
*/ | ||
package org.gnome.gtk; | ||
|
||
import org.gnome.gdk.Screen; | ||
import org.gnome.glib.GlibException; | ||
import org.gnome.glib.Object; | ||
|
||
/** | ||
* CSS-like styling for widgets | ||
* <br/><br/> | ||
* CssProvider is an object implementing the {@link StyleProvider} interface. | ||
* It is able to parse CSS-like input in order to style widgets. | ||
* <br/><br/> | ||
* An application can make GTK+ parse a specific CSS style sheet by calling | ||
* {@link #loadFromPath(String)} or {@link #loadFromResource(String)} and | ||
* adding the provider with {@link StyleContext#addProvider(StyleProvider, int)} | ||
* or {@link StyleContext#addProviderForScreen(Screen, StyleProvider, int)} | ||
* | ||
* @author Patrick Plenefisch | ||
* @since 4.1.4 | ||
*/ | ||
public class CssProvider extends Object implements StyleProvider | ||
{ | ||
protected CssProvider(long pointer) { | ||
super(pointer); | ||
} | ||
|
||
/** | ||
* Creates a new CssProvider | ||
* | ||
* @since 4.1.4 | ||
*/ | ||
public CssProvider() { | ||
super(GtkCssProvider.createCssProvider()); | ||
} | ||
|
||
/** | ||
* Loads a theme from the usual theme paths. | ||
* | ||
* @since 4.1.4 | ||
*/ | ||
public static CssProvider getNamed(String name, String variant) { | ||
return GtkCssProvider.getNamed(name, variant); | ||
} | ||
/** | ||
* Loads the data contained in the resource at resource_path into the | ||
* CssProvider, clearing any previously loaded information. | ||
* | ||
* @since 4.1.4 | ||
*/ | ||
public void loadFromResource(String resource_path) { | ||
GtkCssProvider.loadFromResource(this, resource_path); | ||
} | ||
|
||
/** | ||
* Loads data into css_provider , and by doing so clears any previously loaded information. | ||
* | ||
* @since 4.1.4 | ||
*/ | ||
public boolean loadFromData(String data) { | ||
try { | ||
return GtkCssProvider.loadFromData(this, data, data.length()); | ||
} catch (GlibException e) { | ||
throw new RuntimeException(e.getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Loads the data contained in path into css_provider, | ||
* making it clear any previously loaded information. | ||
* | ||
* @since 4.1.4 | ||
*/ | ||
public boolean loadFromPath(String path) { | ||
try { | ||
return GtkCssProvider.loadFromPath(this, path); | ||
} catch (GlibException e) { | ||
throw new RuntimeException(e.getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Converts the provider into a string representation in CSS format. | ||
* | ||
* @since 4.1.4 | ||
*/ | ||
public String toString() { | ||
return GtkCssProvider.toString(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* java-gnome, a UI library for writing GTK and GNOME programs from Java! | ||
* | ||
* Copyright © 2020 java-gnome contributors | ||
* | ||
* The code in this file, and the program it is a part of, is made available | ||
* to you by its authors as open source software: you can redistribute it | ||
* and/or modify it under the terms of the GNU General Public License version | ||
* 2 ("GPL") as published by the Free Software Foundation. | ||
* | ||
* This program 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 GPL for more details. | ||
* | ||
* You should have received a copy of the GPL along with this program. If not, | ||
* see http://www.gnu.org/licenses/. The authors of this program may be | ||
* contacted through http://java-gnome.sourceforge.net/. | ||
* | ||
* Linking this library statically or dynamically with other modules is making | ||
* a combined work based on this library. Thus, the terms and conditions of | ||
* the GPL cover the whole combination. As a special exception (the | ||
* "Classpath Exception"), the copyright holders of this library give you | ||
* permission to link this library with independent modules to produce an | ||
* executable, regardless of the license terms of these independent modules, | ||
* and to copy and distribute the resulting executable under terms of your | ||
* choice, provided that you also meet, for each linked independent module, | ||
* the terms and conditions of the license of that module. An independent | ||
* module is a module which is not derived from or based on this library. If | ||
* you modify this library, you may extend the Classpath Exception to your | ||
* version of the library, but you are not obligated to do so. If you do not | ||
* wish to do so, delete this exception statement from your version. | ||
*/ | ||
package org.gnome.gtk; | ||
|
||
/** | ||
* Interface to provide style information to {@link StyleContext} | ||
* | ||
* @see StyleContext | ||
* @see CssProvider | ||
* | ||
* @author Patrick Plenefisch | ||
* @since 4.1.4 | ||
*/ | ||
public interface StyleProvider | ||
{ | ||
/** | ||
* The priority used for default style information that is used in the absence of themes. | ||
* <br/><br/> | ||
* Note that this is not very useful for providing default styling for custom style classes | ||
* - themes are likely to override styling provided at this priority with | ||
* catch-all <code>* {...}</code> rules. | ||
*/ | ||
public final static int PRIORITY_FALLBACK = 1; | ||
|
||
/** | ||
* The priority used for style information provided by themes. | ||
*/ | ||
public final static int PRIORITY_THEME = 200; | ||
|
||
/** | ||
* The priority used for style information provided via {@link Settings}. | ||
* <br/><br/> | ||
* This priority is higher than {@link #PRIORITY_THEME} to let settings override themes. | ||
*/ | ||
public final static int PRIORITY_SETTINGS = 400; | ||
|
||
/** | ||
* A priority that can be used when adding a StyleProvider for application-specific style information. | ||
*/ | ||
public final static int PRIORITY_APPLICATION = 600; | ||
|
||
/** | ||
* The priority used for the style information from <code>XDG_CONFIG_HOME/gtk-3.0/gtk.css</code>. | ||
* <br/><br/> | ||
* You should not use priorities higher than this, to give the user the last word. | ||
*/ | ||
public final static int PRIORITY_USER = 800; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
(define-object CssProvider | ||
(in-module "Gtk") | ||
(parent "GObject") | ||
(implements "GtkStyleProvider") | ||
(c-name "GtkCssProvider") | ||
(gtype-id "GTK_TYPE_CSS_PROVIDER") | ||
) | ||
|
||
(define-function new | ||
(is-constructor-of "GtkCssProvider") | ||
(c-name "gtk_css_provider_new") | ||
(caller-owns-return #t) | ||
(return-type "GtkCssProvider*") | ||
) | ||
|
||
(define-function get_named | ||
(of-object "GtkCssProvider") | ||
(c-name "gtk_css_provider_get_named") | ||
(caller-owns-return #f) | ||
(return-type "GtkCssProvider*") | ||
(parameters | ||
'("const-gchar*" "name") | ||
'("const-gchar*" "variant") | ||
) | ||
) | ||
|
||
(define-method load_from_data | ||
(of-object "GtkCssProvider") | ||
(c-name "gtk_css_provider_load_from_data") | ||
(return-type "gboolean") | ||
(parameters | ||
'("const-gchar*" "data") | ||
'("gsize" "length") | ||
'("GError**" "error") | ||
) | ||
) | ||
|
||
(define-method load_from_resource | ||
(of-object "GtkCssProvider") | ||
(c-name "gtk_css_provider_load_from_resource") | ||
(return-type "none") | ||
(parameters | ||
'("const-gchar*" "resource_path") | ||
) | ||
) | ||
|
||
(define-method load_from_path | ||
(of-object "GtkCssProvider") | ||
(c-name "gtk_css_provider_load_from_path") | ||
(return-type "gboolean") | ||
(parameters | ||
'("const-gchar*" "path") | ||
'("GError**" "error") | ||
) | ||
) | ||
|
||
(define-method to_string | ||
(of-object "GtkCssProvider") | ||
(c-name "gtk_css_provider_to_string") | ||
(return-type "char*") | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(define-interface StyleProvider | ||
(in-module "Gtk") | ||
(c-name "GtkStyleProvider") | ||
(gtype-id "GTK_TYPE_STYLE_PROVIDER") | ||
) | ||
|
||
; get_style_property requires WidgetPath |