How do I use an image as the background of a gtk toolbar in GTK+2.0 - image

Is there any api like gtk_widget_modify_bg() to modify the background of a gtk toolbar by an image.
gtk_widget_modify_bg() only can change the color of the background.

After one day's try, now I has known how to set an image backgroud for a gtk toolbar.
The keypoint is that you could not directly modify background for GtkToolbar or even GtkVBox (generally you would put GtkToolbar in a GtkVBox). Because they are all none window GtkWidget, so they couldn't catch expose-event, then can't draw their own background. Their background are same as their parent.
But the GtkEventBox can. So you can put the GtkToolbar into a GtkEventBox, and put GtkEventBox into a GtkVBox. Then you modify GtkEventBox's backgroud by an image, It seems GtkToolBar's background changed.
Following is my test codes:
int main(int argc, char* argv[])
{
GtkWidget* window;
GtkWidget* vbox;
GtkWidget* event_box;
GtkWidget* toolbar;
GtkToolItem* item;
gtk_init(&argc, &argv);
gtk_rc_parse("./gtk.rc");
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 250, 200);
gtk_window_set_title(GTK_WINDOW(window), "toolbar");
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
event_box = gtk_event_box_new();
//gtk_widget_set_name(vbox, "toolbar_event_box");
//set_event_box_background(event_box);
gtk_box_pack_start(GTK_BOX(vbox), event_box, FALSE, FALSE, 5);
toolbar = gtk_toolbar_new();
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);
gtk_container_set_border_width(GTK_CONTAINER(toolbar), 2);
item = gtk_tool_button_new_from_stock(GTK_STOCK_NEW);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
item = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
item = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
item = gtk_separator_tool_item_new();
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
item = gtk_tool_button_new_from_stock(GTK_STOCK_QUIT);
g_signal_connect(G_OBJECT(item), "clicked", G_CALLBACK(gtk_main_quit), NULL);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
gtk_container_add(GTK_CONTAINER(event_box), toolbar);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
and I use gtkrc file to set the GtkEventBox backgroud. Following is the gtk.rc:
pixmap_path "/usr/share/pixmaps:/usr/share/myself"
style "window"
{
bg_pixmap[NORMAL] = "firefox.png"
}
style "toolbar"
{
bg_pixmap[NORMAL] = "bk.bmp"
}
widget_class "GtkWindow" style "window"
widget_class "GtkEventBox" style "toolbar"
The result of the program run:
If you don't use gtkrc file, you can use gtk_widget_set_style() to change the GtkEventBox background. like this:
void set_event_box_background(GtkWidget* event_box)
{
GError* error = NULL;
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file("/usr/share/myself/bk.bmp", &error);
GdkPixmap *pixmap = NULL;
GdkPixmap *mask = NULL;
gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &mask, 255);
GtkStyle* orig_style = gtk_widget_get_style(event_box);
GtkStyle* style = gtk_style_copy(orig_style);
style->bg_pixmap[GTK_STATE_NORMAL] = pixmap;
gtk_widget_set_style(event_box, style);
}
I get this method from Yuren's Info Area.
When you use this method, you should comment gtk_rc_parse("./gtk.rc"); and uncomment set_event_box_background(event_box); line at above main() function.

Related

Why doesn't FindWindowEx find tooltip class

I need to delete tooltip window created for controls that will be deleted while the main window stays around. I came up with what is below, but it doesn't find any TOOLTIPS_CLASS windows. Any reason why?
TIA!!
for (HWND hwndtip=NULL; (hwndtip=FindWindowEx(hwnd, hwndtip, TOOLTIPS_CLASS, NULL))!=NULL;) {
// check if it has the control id we want
TOOLINFO toolinfo ={ 0 };
toolinfo.cbSize = sizeof(toolinfo);
toolinfo.hwnd = hwnd;
toolinfo.uFlags = TTF_IDISHWND;
toolinfo.uId = (UINT_PTR)hwndctl;
if (SendMessage(hwndtip, TTM_GETTOOLINFO, 0, (LPARAM)&toolinfo)) {
// found tooltip to delete
DestroyWindow(hwndtip);
result=TRUE;
break;
}
}
Okay, I found a way that doesn't crash other things via sending the TTM_GETTOOLINFO to each tooltip window found. Basically, give your created tooltip window a name. Example, _T("MINE!!") Then to find it:
for (HWND hwndtip=NULL; (hwndtip=FindWindowEx(NULL, hwndtip, TOOLTIPS_CLASS, _T("MINE!!")))!=NULL;) {
// check if it has the control id we want
TOOLINFO toolinfo ={ 0 };
toolinfo.cbSize = sizeof(toolinfo);
toolinfo.hwnd = hwnd;
toolinfo.uFlags = TTF_IDISHWND;
toolinfo.uId = (UINT_PTR)hwndctl;
if (SendMessage(hwndtip, TTM_GETTOOLINFO, 0, (LPARAM)&toolinfo)) {
// found tooltip to delete
DestroyWindow(hwndtip);
result=TRUE;
break;
}
}

How to use TextButtonStyle.overFont?

I'm trying to use overFont and overColor on TextButton so the button appearance can changes when the mouse move over.
Here's the style I defined.
var buttonStyle = new TextButtonStyle();
buttonStyle.fontColor = new Color(1f, 1f, 1f, 1f);
buttonStyle.disabledFontColor = new Color(0, 0, 0, 0.4f);
buttonStyle.down = skin.getDrawable( "button_down");
buttonStyle.up= skin.getDrawable( "button_up");
buttonStyle.over= skin.getDrawable( "button_over");
buttonStyle.overFontColor = new Color(0, 0.3f, 0.3f, 1f);
buttonStyle.font = font
skin.add("default", buttonStyle);
The button is created as follows:
var startGameButton = new TextButton("Start game", skin);
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
stage.addActor(startGameButton);
/*startGameButton.addListener ([ Event e |
Gdx.app.log ("App", "Start game") ;
return true ;
])*/
startGameButton.addListener (new ChangeListener () {
override changed(ChangeEvent event, Actor actor) {
Gdx.app.log ("App", "Start game") ;
}
})
While the down and up state are properly taken into account, the over properties are not used: the button doesn't change when the mouse enters the button area.
buttonStyle.fontOverColor = Color.BLUE; works fine for me,
try to pass to your TextButton constructor not skin, but buttonStyle,
in TextButton there is such constructor
public TextButton (String text, TextButtonStyle style)
It's difficult to say something else, because code not looks like real working code, I mean var keyword or this code is not correct (there is no public variables x, y, width, height):
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
If changing constructor will not help you, please post your real code.

Add custom action to System Menu in a QDialog

I have a need to add a custom action (say ‘About’ clicking which a QMessageBox needs to be displayed) in the system menu shown when the icon on the title bar of a QDialog is clicked. How do I achieve this?
Regards,
Bharath
You cannot do it with Qt because it's OS specific. But you can use GetSystemMenu and AppendMenu functions in Windows to modify the menu and then catch events that then item is clicked.
Here is a simple example from here. It appends a separator and an about item to the menu:
#include "windows.h"
// IDM_ABOUTBOX must be in the system command range
// (IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX)
// and (IDM_ABOUTBOX < 0xF000)
#define IDM_ABOUTBOX 0x0010
MyWidget::MyWidget() : QMainWindow()
{
...
HMENU hMenu = ::GetSystemMenu(winId(), FALSE);
if (hMenu != NULL)
{
::AppendMenuA(hMenu, MF_SEPARATOR, 0, 0);
::AppendMenuA(hMenu, MF_STRING, IDM_ABOUTBOX, "About MyApp...");
}
...
}
bool MyWidget::winEvent(MSG *m, long *result)
{
if (m->message == WM_SYSCOMMAND)
{
if ((m->wParam & 0xfff0) == IDM_ABOUTBOX)
{
*result = 0;
// open About dialog
about();
return (true);
}
}
return (false);
}
PRO-file:
LIBS += -lUser32

firebreath plugin create a full screen window, but the window always under the browser window when it appers, how can I bring it to top

CaptureScreenApp app;
int MyPluginAPI::captureScreen(const FB::JSObjectPtr& callback)
{
boost::thread cs(boost::bind(&CaptureScreenApp ::captureScreen,
app, callback));
return 1;
}
class CaptureScreenApp {
public:
CaptureScreenApp() {
HRESULT hRes;
hRes = OleInitialize(NULL);
ATLASSERT(SUCCEEDED(hRes));
AtlInitCommonControls(ICC_WIN95_CLASSES);
g_Module.Init(NULL, NULL);
};
~CaptureScreenApp() {
g_Module.Term();
OleUninitialize();
};
bool captureScreen() {
CMessageLoop theLoop;
CMainDialog g_MainDlg;
g_Module.AddMessageLoop(&theLoop);
if (NULL == g_MainDlg.Create(NULL)){
DWORD ret = GetLastError();
return FALSE;
}
g_MainDlg.ShowWindow(SW_SHOW);
g_MainDlg.UpdateWindow();
int nRet = theLoop.Run();
g_Module.RemoveMessageLoop();
return TRUE;
};
};
class CMainDialog : public CDialogImpl<CMainDialog>
{
public:
enum {IDD = IDD_MAIN};
....
}
the window(the new window is a full screen window with a desktop pic as the background) I create in CaptureScreenApp::captureScreen always under the browser window when it appears(browser window always actived in other word), what ever how I set the HWND_TOPMOST for the new window. like this:
enter link description here
how can i bring the full screen window to top when it appers?
SetWindowPos API lets you change Z order (make sure to read Remarks there). You create your window with NULL parent, so your window is completely independent from browser window, so there is nothing to push it to the front: it would be either you or interactive user.

WP7 Popup not showing

In my app I want to display a simple string within a popup when the user clicks on an image. For this I added a Tap gesture listener to the image and within the handler I have the following code:
private void GestureListener_Tap( object sender, GestureEventArgs e )
{
var img = sender as Image;
if( img == null ) {
return;
}
Point pos = e.GetPosition( img );
string text = "I'm a popup!";
var popup = new Popup() {
Child = new Border() {
BorderBrush = new SolidColorBrush( Colors.LightGray ),
Child = new TextBlock() {
Text = text,
TextWrapping = TextWrapping.Wrap,
},
},
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalOffset = pos.X,
VerticalOffset = pos.Y,
Visibility = Visibility.Visible,
};
popup.IsOpen = true;
Debug.WriteLine( "GestureListener_Tap: " + text );
}
The call to WriteLine prints in the debugger output window but the popup doesn't get displayed. What am I doing wrong here?
Thanks for your help!
I tried your code and the Popup is displayed. I think the problem for you is the Position for the Image relative to the Mouse. Try to set another Background for the Parent Container and I think you'll see the Popup. You can also try to play around with
Point pos = e.GetPosition(null);
until you get the Position you require

Resources