📄 toolbar.cpp
字号:
// ToolBar.cpp: implementation of the CToolBar class.
//
//////////////////////////////////////////////////////////////////////
#include "ToolBar.h"
#include "config.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CToolBar::CToolBar(CWidget* parent, int width, int height) : CWidget(parent)
{
m_CloseButton = (CButton*)NULL;
m_ActiveButton = NULL;
m_group = (GSList*)NULL;
on_close = NULL;
m_hHandle = Create(width, height);
gtk_signal_connect (GTK_OBJECT (m_hHandle), "destroy",
GTK_SIGNAL_FUNC (on_widget_destroy),
this);
Show();
}
CToolBar::~CToolBar()
{
CButton* b;
GSList* list = m_group;
while(list){
b = (CButton*)(list->data);
delete b;
list = list->next;
}
g_slist_free(m_group);
m_group = (GSList*)NULL;
delete m_CloseButton;
}
CButton* CToolBar::AddButton(const gchar *file_normal, const gchar *file_active,
GtkSignalFunc on_pressed, gpointer user_data)
{
CButton* b = new CButton(NULL, this);
b->SetPixmap(file_normal, file_active);
m_group = g_slist_append(m_group, b);
gtk_box_pack_start (GTK_BOX (m_hbox), b->GetHandle(), FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (b->GetHandle()), "pressed",
GTK_SIGNAL_FUNC (on_toolbutton_pressed),
b);
if(on_pressed)
gtk_signal_connect (GTK_OBJECT (b->GetHandle()), "pressed",
GTK_SIGNAL_FUNC (on_pressed),
user_data);
return b;
}
GtkWidget* CToolBar::Create(int w, int h)
{
static GdkColor blue = {0, 0x0000, 0x5050, 0xE0E0 };
GtkWidget* fixed1;
fixed1 = gtk_fixed_new();
gtk_widget_set_usize(fixed1, w, h);
GtkStyle* style = gtk_style_copy(gtk_widget_get_style(fixed1));
style->bg[GTK_STATE_NORMAL] = blue;
gtk_widget_set_style(fixed1, style);
gtk_style_unref(style);
m_hbox = gtk_hbox_new(FALSE, 0);
gtk_widget_show(m_hbox);
gtk_fixed_put (GTK_FIXED (fixed1), m_hbox, 0, 0);
CPixmap* pix;
pix = new CPixmap(PUBLICXPMFILEPATH "toolbar.xpm");
GtkWidget* pixmapwid = gtk_pixmap_new(pix->GetPixmap(), pix->GetMask());
gtk_widget_show(pixmapwid);
gtk_fixed_put (GTK_FIXED (fixed1), pixmapwid, w-47, 0);
delete pix;
m_CloseButton = new CButton(NULL, this);
m_CloseButton->SetPixmap(PUBLICXPMFILEPATH "close.xpm",
PUBLICXPMFILEPATH "close-down.xpm",
true);
gtk_signal_connect (GTK_OBJECT (m_CloseButton->GetHandle()), "clicked",
GTK_SIGNAL_FUNC (on_button_close_clicked),
this);
gtk_fixed_put (GTK_FIXED (fixed1), m_CloseButton->GetHandle(), w-23, 0);
return fixed1;
}
void CToolBar::set_on_close_func(GtkSignalFunc fun, gpointer user_data)
{
SetData("on_button_close_clicked user_data", user_data);
on_close = ToolBarCloseFunc(fun);
}
void
CToolBar::on_button_close_clicked (GtkButton *button,
gpointer user_data)
{
CToolBar* tb = (CToolBar*) user_data;
if(!tb)
return;
if(tb->on_close){
gpointer data = tb->GetData("on_button_close_clicked user_data");
tb->on_close(button, data);
}
}
void CToolBar::on_toolbutton_pressed (GtkButton *button,
gpointer user_data)
{
CButton* b = (CButton*)user_data;
if(!b)
return;
CToolBar* tb = (CToolBar*)b->GetParent();
if(!tb)
return;
CButton* oldbut = tb->m_ActiveButton;
tb->m_ActiveButton = b;
b->SetState(true);
if(oldbut && (oldbut != b))
oldbut->SetState(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -