removed getTextPadding. (dead code)
This commit is contained in:
parent
5368c6db75
commit
aa33dabb9b
|
@ -4,7 +4,6 @@ import static dorkbox.systemTray.util.CssParser.injectAdditionalCss;
|
||||||
import static dorkbox.systemTray.util.CssParser.removeComments;
|
import static dorkbox.systemTray.util.CssParser.removeComments;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Insets;
|
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -14,7 +13,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import com.sun.jna.Pointer;
|
import com.sun.jna.Pointer;
|
||||||
import com.sun.jna.ptr.IntByReference;
|
|
||||||
import com.sun.jna.ptr.PointerByReference;
|
import com.sun.jna.ptr.PointerByReference;
|
||||||
|
|
||||||
import dorkbox.systemTray.SystemTray;
|
import dorkbox.systemTray.SystemTray;
|
||||||
|
@ -106,227 +104,6 @@ class GtkTheme {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the text padding of menu items (in the system tray menu), as specified by CSS. This is the padding value for all sides!
|
|
||||||
* NOTE: not all themes have CSS
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("Duplicates")
|
|
||||||
public static
|
|
||||||
Insets getTextPadding(String text) {
|
|
||||||
// have to use pango to get the size of text (for the checkmark size)
|
|
||||||
Pointer offscreen = Gtk.gtk_offscreen_window_new();
|
|
||||||
|
|
||||||
// we use the size of "X" as the checkmark
|
|
||||||
Pointer item = Gtk.gtk_image_menu_item_new_with_mnemonic(text);
|
|
||||||
|
|
||||||
Gtk.gtk_container_add(offscreen, item);
|
|
||||||
|
|
||||||
// get the text widget (GtkAccelLabel) from inside the GtkMenuItem
|
|
||||||
Pointer textLabel = Gtk.gtk_bin_get_child(item);
|
|
||||||
|
|
||||||
int top = 0;
|
|
||||||
int bottom = 0;
|
|
||||||
int right = 0;
|
|
||||||
int left = 0;
|
|
||||||
|
|
||||||
IntByReference pointer = new IntByReference();
|
|
||||||
Gobject.g_object_get(textLabel, "ypad", pointer.getPointer(), null);
|
|
||||||
int value = pointer.getValue();
|
|
||||||
|
|
||||||
top += value;
|
|
||||||
bottom += value;
|
|
||||||
|
|
||||||
Gobject.g_object_get(textLabel, "xpad", pointer.getPointer(), null);
|
|
||||||
value = pointer.getValue();
|
|
||||||
|
|
||||||
left += value;
|
|
||||||
right += value;
|
|
||||||
|
|
||||||
|
|
||||||
value = Gtk.gtk_container_get_border_width(item);
|
|
||||||
|
|
||||||
top += value;
|
|
||||||
bottom += value;
|
|
||||||
left += value;
|
|
||||||
right += value;
|
|
||||||
|
|
||||||
|
|
||||||
if (Gtk.isGtk3) {
|
|
||||||
Pointer context = Gtk3.gtk_widget_get_style_context(item);
|
|
||||||
GtkBorder tmp = new GtkBorder();
|
|
||||||
|
|
||||||
Gtk3.gtk_style_context_save(context);
|
|
||||||
|
|
||||||
Gtk3.gtk_style_context_add_class(context, "frame");
|
|
||||||
Gtk3.gtk_style_context_get_padding(context, Gtk.State.NORMAL, tmp.getPointer());
|
|
||||||
tmp.read();
|
|
||||||
|
|
||||||
top += tmp.top;
|
|
||||||
bottom += tmp.bottom;
|
|
||||||
left += tmp.left;
|
|
||||||
right += tmp.right;
|
|
||||||
|
|
||||||
Gtk3.gtk_style_context_get_border(context, Gtk.State.NORMAL, tmp.getPointer());
|
|
||||||
tmp.read();
|
|
||||||
|
|
||||||
top += tmp.top;
|
|
||||||
bottom += tmp.bottom;
|
|
||||||
left += tmp.left;
|
|
||||||
right += tmp.right;
|
|
||||||
|
|
||||||
Gtk3.gtk_style_context_restore (context);
|
|
||||||
} else {
|
|
||||||
GtkStyle.ByReference style = Gtk.gtk_widget_get_style(item);
|
|
||||||
top += style.ythickness;
|
|
||||||
bottom += style.ythickness;
|
|
||||||
left += style.xthickness;
|
|
||||||
right += style.xthickness;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Gtk.gtk_widget_destroy(item);
|
|
||||||
Gtk.gtk_widget_destroy(offscreen);
|
|
||||||
|
|
||||||
|
|
||||||
if (top == 0 && bottom == 0 && left == 0 && right == 0) {
|
|
||||||
// sometimes GTK2 cannot get this info!!
|
|
||||||
|
|
||||||
// parse if from CSS...
|
|
||||||
Css css = getCss();
|
|
||||||
if (css != null) {
|
|
||||||
// collect a list of all of the sections that have what we are interested in.
|
|
||||||
List<CssNode> sections = CssParser.getSections(css, cssNodes, null);
|
|
||||||
|
|
||||||
List<Entry> paddingEntries = CssParser.getAttributeFromSections(sections, "padding", true);
|
|
||||||
String padding = CssParser.selectMostRelevantAttribute(cssNodes, paddingEntries);
|
|
||||||
|
|
||||||
// can be padding: 2px 4px;
|
|
||||||
// can be padding-bottom: 3px;
|
|
||||||
if (padding != null) {
|
|
||||||
String[] split = padding.split(" ");
|
|
||||||
if (split.length == 4) {
|
|
||||||
// padding:10px 5px 15px 20px;
|
|
||||||
// top padding is 10px
|
|
||||||
// right padding is 5px
|
|
||||||
// bottom padding is 15px
|
|
||||||
// left padding is 20px
|
|
||||||
top = MathUtil.stripTrailingNonDigits(split[0]);
|
|
||||||
right = MathUtil.stripTrailingNonDigits(split[1]);
|
|
||||||
bottom = MathUtil.stripTrailingNonDigits(split[2]);
|
|
||||||
left = MathUtil.stripTrailingNonDigits(split[3]);
|
|
||||||
}
|
|
||||||
else if (split.length == 3) {
|
|
||||||
// padding:10px 5px 15px;
|
|
||||||
// top padding is 10px
|
|
||||||
// right and left padding are 5px
|
|
||||||
// bottom padding is 15px
|
|
||||||
top = MathUtil.stripTrailingNonDigits(split[0]);
|
|
||||||
right = left = MathUtil.stripTrailingNonDigits(split[1]);
|
|
||||||
bottom = MathUtil.stripTrailingNonDigits(split[2]);
|
|
||||||
}
|
|
||||||
else if (split.length == 2) {
|
|
||||||
// padding:10px 5px;
|
|
||||||
// top and bottom padding are 10px
|
|
||||||
// right and left padding are 5px
|
|
||||||
top = bottom = MathUtil.stripTrailingNonDigits(split[0]);
|
|
||||||
right = left = MathUtil.stripTrailingNonDigits(split[1]);
|
|
||||||
}
|
|
||||||
else if (split.length == 1) {
|
|
||||||
// padding:10px;
|
|
||||||
// all four paddings are 10px
|
|
||||||
top = bottom = right = left = MathUtil.stripTrailingNonDigits(split[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// it's explicit padding sizes.
|
|
||||||
paddingEntries = CssParser.getAttributeFromSections(sections, "padding-top", true);
|
|
||||||
padding = CssParser.selectMostRelevantAttribute(cssNodes, paddingEntries);
|
|
||||||
top = MathUtil.stripTrailingNonDigits(padding);
|
|
||||||
|
|
||||||
|
|
||||||
paddingEntries = CssParser.getAttributeFromSections(sections, "padding-right", true);
|
|
||||||
padding = CssParser.selectMostRelevantAttribute(cssNodes, paddingEntries);
|
|
||||||
right = MathUtil.stripTrailingNonDigits(padding);
|
|
||||||
|
|
||||||
|
|
||||||
paddingEntries = CssParser.getAttributeFromSections(sections, "padding-bottom", true);
|
|
||||||
padding = CssParser.selectMostRelevantAttribute(cssNodes, paddingEntries);
|
|
||||||
bottom = MathUtil.stripTrailingNonDigits(padding);
|
|
||||||
|
|
||||||
|
|
||||||
paddingEntries = CssParser.getAttributeFromSections(sections, "padding-left", true);
|
|
||||||
padding = CssParser.selectMostRelevantAttribute(cssNodes, paddingEntries);
|
|
||||||
left = MathUtil.stripTrailingNonDigits(padding);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Entry> borderEntries = CssParser.getAttributeFromSections(sections, "border-width", true);
|
|
||||||
String border = CssParser.selectMostRelevantAttribute(cssNodes, borderEntries);
|
|
||||||
|
|
||||||
|
|
||||||
// can be border-width, etc
|
|
||||||
// can be border-bottom-width, etc
|
|
||||||
if (border != null) {
|
|
||||||
String[] split = border.split(" ");
|
|
||||||
if (split.length == 4) {
|
|
||||||
top += MathUtil.stripTrailingNonDigits(split[0]);
|
|
||||||
right += MathUtil.stripTrailingNonDigits(split[1]);
|
|
||||||
bottom += MathUtil.stripTrailingNonDigits(split[2]);
|
|
||||||
left += MathUtil.stripTrailingNonDigits(split[3]);
|
|
||||||
}
|
|
||||||
else if (split.length == 3) {
|
|
||||||
top += MathUtil.stripTrailingNonDigits(split[0]);
|
|
||||||
|
|
||||||
int borderX = MathUtil.stripTrailingNonDigits(split[1]);
|
|
||||||
right += borderX;
|
|
||||||
left += borderX;
|
|
||||||
|
|
||||||
bottom += MathUtil.stripTrailingNonDigits(split[2]);
|
|
||||||
}
|
|
||||||
else if (split.length == 2) {
|
|
||||||
int borderY = MathUtil.stripTrailingNonDigits(split[0]);
|
|
||||||
int borderX = MathUtil.stripTrailingNonDigits(split[1]);
|
|
||||||
|
|
||||||
top += borderY;
|
|
||||||
bottom += borderY;
|
|
||||||
|
|
||||||
right += borderX;
|
|
||||||
left += borderX;
|
|
||||||
}
|
|
||||||
else if (split.length == 1) {
|
|
||||||
int b = MathUtil.stripTrailingNonDigits(split[0]);
|
|
||||||
|
|
||||||
top += b;
|
|
||||||
bottom += b;
|
|
||||||
right += b;
|
|
||||||
left += b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// it's explicit border sizes.
|
|
||||||
|
|
||||||
borderEntries = CssParser.getAttributeFromSections(sections, "border-top-width", true);
|
|
||||||
border = CssParser.selectMostRelevantAttribute(cssNodes, borderEntries);
|
|
||||||
top += MathUtil.stripTrailingNonDigits(border);
|
|
||||||
|
|
||||||
borderEntries = CssParser.getAttributeFromSections(sections, "border-right-width", true);
|
|
||||||
border = CssParser.selectMostRelevantAttribute(cssNodes, borderEntries);
|
|
||||||
right += MathUtil.stripTrailingNonDigits(border);
|
|
||||||
|
|
||||||
borderEntries = CssParser.getAttributeFromSections(sections, "border-bottom-width", true);
|
|
||||||
border = CssParser.selectMostRelevantAttribute(cssNodes, borderEntries);
|
|
||||||
bottom += MathUtil.stripTrailingNonDigits(border);
|
|
||||||
|
|
||||||
borderEntries = CssParser.getAttributeFromSections(sections, "border-left-width", true);
|
|
||||||
border = CssParser.selectMostRelevantAttribute(cssNodes, borderEntries);
|
|
||||||
left += MathUtil.stripTrailingNonDigits(border);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Insets(top, left, bottom, right);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the size of the GTK menu entry's IMAGE, as best as we can tell, for determining how large of icons to use for the menu entry
|
* @return the size of the GTK menu entry's IMAGE, as best as we can tell, for determining how large of icons to use for the menu entry
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user