GtkCellRendererToggle - color of toggle button inside treeview - gtk

I have a treeview that uses GtkCellRendererToggle to display toggle buttons inside cells. My question: Is is possible to set the color just for the toggle button there? I only know how to set the cell background, which is done like this:
g_object_set (toggle-renderer, "cell-background",
"anycolouryoulike", "cell-background-set", TRUE, NULL);
GtkCellRenderer features only cell background properties, I wonder if there is nethertheless a way to do it? (I use C, but if there is a way, an example in any language would do).

GtkCssProvider might help, just try to style buttons within GtkCssProvider (list of suported properties per widget , not necessary for this case)
You could use something like
#supercolorme {
color: #ffed00;
}
and name your widgets supercolorme by using
void gtk_widget_set_name (GtkWidget *widget, const gchar *name); as described in the gtk+ API docs

Related

GWT - HTML widget - setEnabled

Is there a way to make com.google.gwt.user.client.ui.HTML widget being enabled or not-enabled? I tried but there seems no setEnabled(boolean) method :S Share your experience please
Thanks
I'm not sure what you mean by enabled but I'll take a stab at it.
I assume that you mean visible or not visible.
HTMLPanel panel = new HTMLPanel();
panel.setVisible(false); // Disabled
panel.setVisible(true); // Enabled
Hopefully that's what you were looking for.
Only a few HTML elements can be enabled or disabled, like inputs. GWT has setEnabled() for elements that can get focus:
http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/FocusWidget.html#setEnabled(boolean)
Only some form elements(inputs, options) can be disabled.
To disable:
widget.getElement().setAttribute("disabled","disabled");
To enable again:
widget.getElement().removeAttribute("disabled");
For other widget, you need to set their style to mimic "disabling". (e.g. set the color to grey)
Unfortunately there is no such a method in Widget.
But there is a little room to acheive .I made it work with help of google groups
public void setEnabled (boolean e)
{
Iterator<Widget> itr = grd.iterator (); // grd is a FlexTable which
contains my form controls
while (itr.hasNext ())
{
Widget w = itr.next ();
if (w instanceof TextBox)
{
TextBox t = (TextBox) w;
t.setEnabled (e);
}
if (w instanceof PasswordTextBox)
{
PasswordTextBox t = (PasswordTextBox) w;
t.setEnabled (e);
}
...
}
To Give appearance of enable and disable feature in a widget which does not inherit from FocusWidget.
You would need to override both style and event handling implementation. Keep a enableFl in your MyHTMLPanel extends HTMLPanel.
Step 1 - Provide enable and disable style. Using opacity css turn on/off greying sort of coloring. Based on state of enableFl turn on/off the enable/disable feature.
Step 2 - Disable/Enable event handling on the widget by overriding onBrowserEvent and making its execution conditional on your own enableFl state.
Step 3 - Recursively disable all widgets internal to HTMLPanel.
If your use case is simple you might opt to use com.google.gwt.user.client.ui.HTML instead of com.google.gwt.user.client.ui.HTMLPanel .

CaptionPanel -> CaptionLayoutPanel

I want to use the CaptionPanel inside a Layout Panel (DockLayoutPanel) .
The problem is that there is no CaptionLayoutPanel(like SimpleLayoutPanel) implementation and therefore if I want to use
this panel inside a Layout Panel, all childs will loose the resize events because the "resize-chain" is broken through the CaptionPanel.
Is there any workaround?
Extend CaptionPanel and implement the ProvidesResize and RequiresResize interfaces
CustomCaptionPanel extends CaptionPanel implements RequiresResize,ProvidesResize {
public void onResize() {
if (getContentWidget() instanceof RequiresResize) {
((RequiresResize) getContentWidget()).onResize();
}
}
The easiest solution is not to use CaptionPanel.
If you want children to respond to resize events, add a layer to your LayoutPanel that will hold a caption (Label), and another layer that will contain a child widget that you want to respond to resize. You can style these widgets any way you like (e.g. a Label can look like a tab or a panel with some background and rounded corners, etc.)
An alternative solution is style your CaptionPanel as Roddy of the Frozen Peas suggested, and then add a ResizeHandler to your window. When triggered, you can set the size of a child widget to
myChildWidget.setSize(myCaptionPanel.getOffsetWidth() + "px", myCaptionPanel.getOffsetHeight() + "px");

TabLayoutPanel disable a Tab GWT

How can i disable a tab (i.e the user cannot open the tab when he clicks on it) in the TabLayoutPanel?I searched online but was not able to find a solution
Thanks
Use a BeforeSelectionHandler:
TabLayoutPanel myPanel = new TabLayoutPanel();
// Add children...
myPanel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
#Override
public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
// Simple if statement - your test for whether the tab should be disabled
// will probably be more complicated
if (event.getItem() == 1) {
// Canceling the event prevents the tab from being selected.
event.cancel();
}
}
});
If you want to style the disabled tab differently than enabled tabs, you can use TabLayoutPanel#getTabWidget to get the tab widget and add a style name to it.
For anyone who comes across this later:
As of GWT version 1.6, disabling/enabling tabs is built into GWT.
The TabBar class has a method setTabEnabled(int index, boolean enabled) that enables/disables the tab at a given index.
For example, to disable all the tabs in a TabPanel:
TabPanel myTabPanel = new TabPanel();
// Add children
TabBar tabBar = myTabPanel.getTabBar();
for(int i=0; i<tabBar.getTabCount(); i++) {
tabBar.setTabEnabled(i, false);
}
See the GWT javadoc for more info.
To style disabled tabs differently (which GWT does automatically, but if you wanted to change the style): disabled tabBarItem divs are given another CSS class: gwt-TabBarItem-disabled.
You can access tab style by casting class Tab to Widget
TabPanel tabPanel = new TabPanel();
((Widget)tabPanel().getTabBar().getTab(tabsToDisable.iterator().next())).addStyleName("disabled");

swt table change selection item color

I'm using a standard swt table which, as you may know, by default when an item is selected is colored blue (windows standard). When the selection is inactive, it turns light gray. I would like to override both colors... I've searched all over the web but could only find some very old code which no longer seems to work with the table widget.
Below is some sample code I was trying to overwrite the default color but it doesn't seem to be working (please excuse the dirty code, was just trying to get something to work):
table.addSelectionListener(new SelectionListener() {
#Override
public void widgetSelected(SelectionEvent event) {
Color rowSelectionColor =
new Color(Display.getCurrent(),new RGB(235, 200, 211));
TableItem item =(TableItem)event.item;
item.setBackground(0,rowSelectionColor);
item.setBackground(1,rowSelectionColor);
item.setBackground(2,rowSelectionColor);
}
#Override
public void widgetDefaultSelected(SelectionEvent event) {
Color rowSelectionColor =
new Color(Display.getCurrent(),new RGB(235, 200, 211));
TableItem item =(TableItem)event.item;
item.setBackground(0,rowSelectionColor);
item.setBackground(1,rowSelectionColor);
item.setBackground(2,rowSelectionColor);
}
});
Any ideas would be greaaatly massively appreciated :D
If you want to go with a TableViewer to manage your table, you can use a StyledCellLabelProvider to determine the colors/fonts/etc for individual cells. The TableViewer will take care of the "owner draw" aspects for you. The biggest hassle is setting up the ContentProvider, LabelProvider, and input classes that go with the TableViewer.

How to add a GWT click listener to an Image?

I want to click on an image and therefore want to register (e.g.) a ClickHandler. The image I get from a ClientResource. This works so far to set the image into a table cell:
MyResources.INSTANCE.css().ensureInjected();
Image colorImage = new Image( MyResources.INSTANCE.colorImage() );
Element colorImageElement = colorImage.getElement();
colorImage.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
System.out.println( event );
}
} );
TableElement table = Document.get().createTableElement();
TableRowElement headRow = table.insertRow(-1);
headRow.insertCell(-1).appendChild( colorImageElement );
RootPanel.get().getElement().appendChild( table );
How can I add a listener to the icon? I tried ClickHandler and to put the image on a PushButton and get the Element from this PushButton but all don't work.
But mind, if I add the widget (Image is a Widget) to a panel it works!
RootPanel.get().add( colorImage );
But I am not working with widgets here but with the Element. So the handler disappears and that's the point I don't get how to preserve this added handler information.
In the end I would like to build a table with different rows where I can click on the icon I get a popup menu and thereby change the colour of the row.
You should be able to just add a ClickHandler (or a MouseDownHandler if that fits your needs better).
Like this:
colorImage.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// Do something....
}
});
Don't unwrap your widget and append only the DOM elements. The Widget class allows your code to refer to both elements and events at the same time, and deals with possible memory leaks, as well as grouping your code in logical ways.
This might make sense for other frameworks, but in GWT you almost always want to work with the Widgets directly, adding them together, then appending them to the RootPanel.
If you really want to use a html table to build this up, look at the com.google.gwt.user.client.ui.HTMLTable subclasses, com.google.gwt.user.client.ui.Grid and com.google.gwt.user.client.ui.FlexTable. This probably should never be necessary, unless you are adding multiple items to the table - when trying to specify layouts, use actual layout classes.
did you tried to add image.sinkEvents( Event.ONCLICK | Event.MOUSEEVENTS )?
The image has to be inside a focus widget. I don't know why that is, but somewhere the events don't get propagated right and the DOM events don't fire.