[gnome-commander/gcmd-1-3] GnomeCmdCombo: more C++ rework
- From: Piotr Eljasiak <epiotr src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-commander/gcmd-1-3] GnomeCmdCombo: more C++ rework
- Date: Thu, 1 Oct 2009 22:01:15 +0000 (UTC)
commit 5c8ad2ea51241577da4ef40493b9235e233e0094
Author: Piotr Eljasiak <epiotr src gnome org>
Date: Thu Oct 1 23:58:22 2009 +0200
GnomeCmdCombo: more C++ rework
src/gnome-cmd-cmdline.cc | 49 +++++++++++++++++++--------------------
src/gnome-cmd-combo.cc | 28 +++++++---------------
src/gnome-cmd-combo.h | 20 +++++++++++++---
src/gnome-cmd-file-selector.cc | 42 +++++++++++++++++-----------------
src/gnome-cmd-file-selector.h | 5 +++-
src/widget-factory.h | 8 +++---
6 files changed, 78 insertions(+), 74 deletions(-)
---
diff --git a/src/gnome-cmd-cmdline.cc b/src/gnome-cmd-cmdline.cc
index faed556..98cd62b 100644
--- a/src/gnome-cmd-cmdline.cc
+++ b/src/gnome-cmd-cmdline.cc
@@ -36,7 +36,7 @@ static GtkHBoxClass *parent_class = NULL;
struct GnomeCmdCmdlinePrivate
{
- GtkWidget *combo;
+ GnomeCmdCombo *combo;
GtkWidget *cwd;
GList *history;
@@ -45,7 +45,7 @@ struct GnomeCmdCmdlinePrivate
inline void update_history_combo (GnomeCmdCmdline *cmdline)
{
- GNOME_CMD_COMBO (cmdline->priv->combo)->clear();
+ cmdline->priv->combo->clear();
gchar *text[2];
@@ -55,10 +55,10 @@ inline void update_history_combo (GnomeCmdCmdline *cmdline)
{
gchar *command = text[0] = (gchar *) tmp->data;
- GNOME_CMD_COMBO (cmdline->priv->combo)->append(text, command);
+ cmdline->priv->combo->append(text, command);
}
- gtk_clist_select_row (GTK_CLIST (GNOME_CMD_COMBO (cmdline->priv->combo)->list), 0, 0);
+ gtk_clist_select_row (GTK_CLIST (cmdline->priv->combo->list), 0, 0);
}
@@ -145,7 +145,7 @@ static void on_exec (GnomeCmdCmdline *cmdline, gboolean term)
{
const gchar *cmdline_text;
- cmdline_text = gtk_entry_get_text (GTK_ENTRY (GNOME_CMD_COMBO (cmdline->priv->combo)->entry));
+ cmdline_text = gtk_entry_get_text (GTK_ENTRY (cmdline->priv->combo->entry));
cmdline_text = g_strstrip (g_strdup (cmdline_text));
GnomeCmdFileSelector *fs = main_win->fs(ACTIVE);
@@ -311,19 +311,18 @@ static void init (GnomeCmdCmdline *cmdline)
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (cmdline), label, FALSE, FALSE, 0);
- cmdline->priv->combo = gnome_cmd_combo_new (1, 0, NULL);
- gtk_widget_ref (cmdline->priv->combo);
+ cmdline->priv->combo = new GnomeCmdCombo(1, 0);
+ gtk_widget_ref (*cmdline->priv->combo);
gtk_object_set_data_full (GTK_OBJECT (cmdline), "combo", cmdline->priv->combo,
(GtkDestroyNotify) gtk_widget_unref);
- gtk_clist_set_column_width (
- GTK_CLIST (GNOME_CMD_COMBO (cmdline->priv->combo)->list), 0, 500);
- gtk_box_pack_start (GTK_BOX (cmdline), cmdline->priv->combo, TRUE, TRUE, 2);
- gtk_widget_show (cmdline->priv->combo);
- gtk_entry_set_editable (GTK_ENTRY (GNOME_CMD_COMBO (cmdline->priv->combo)->entry), TRUE);
- GTK_WIDGET_UNSET_FLAGS (GNOME_CMD_COMBO (cmdline->priv->combo)->button, GTK_CAN_FOCUS);
- GTK_WIDGET_SET_FLAGS (GNOME_CMD_COMBO (cmdline->priv->combo)->entry, GTK_CAN_FOCUS);
-
- gtk_signal_connect (GTK_OBJECT (GNOME_CMD_COMBO (cmdline->priv->combo)->entry),
+ gtk_clist_set_column_width (GTK_CLIST (cmdline->priv->combo->list), 0, 500);
+ gtk_box_pack_start (GTK_BOX (cmdline), *cmdline->priv->combo, TRUE, TRUE, 2);
+ gtk_widget_show (*cmdline->priv->combo);
+ gtk_entry_set_editable (GTK_ENTRY (cmdline->priv->combo->entry), TRUE);
+ GTK_WIDGET_UNSET_FLAGS (cmdline->priv->combo->button, GTK_CAN_FOCUS);
+ GTK_WIDGET_SET_FLAGS (cmdline->priv->combo->entry, GTK_CAN_FOCUS);
+
+ gtk_signal_connect (GTK_OBJECT (cmdline->priv->combo->entry),
"key-press-event",
GTK_SIGNAL_FUNC (on_key_pressed), cmdline);
gtk_signal_connect (GTK_OBJECT (cmdline->priv->combo), "item-selected",
@@ -396,7 +395,7 @@ void gnome_cmd_cmdline_append_text (GnomeCmdCmdline *cmdline, const gchar *text)
g_return_if_fail (cmdline->priv != NULL);
g_return_if_fail (cmdline->priv->combo != NULL);
- GtkEntry *entry = GTK_ENTRY (GNOME_CMD_COMBO (cmdline->priv->combo)->entry);
+ GtkEntry *entry = GTK_ENTRY (cmdline->priv->combo->entry);
const gchar *curtext = gtk_entry_get_text (entry);
if (curtext[strlen(curtext)-1] != ' ' && strlen(curtext) > 0)
@@ -414,7 +413,7 @@ void gnome_cmd_cmdline_insert_text (GnomeCmdCmdline *cmdline, const gchar *text)
g_return_if_fail (cmdline->priv != NULL);
g_return_if_fail (cmdline->priv->combo != NULL);
- GtkEntry *entry = GTK_ENTRY (GNOME_CMD_COMBO (cmdline->priv->combo)->entry);
+ GtkEntry *entry = GTK_ENTRY (cmdline->priv->combo->entry);
gint curpos = gtk_editable_get_position (GTK_EDITABLE (entry));
gint tmp = curpos;
gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp);
@@ -428,13 +427,13 @@ void gnome_cmd_cmdline_set_text (GnomeCmdCmdline *cmdline, const gchar *text)
g_return_if_fail (cmdline->priv != NULL);
g_return_if_fail (cmdline->priv->combo != NULL);
- gtk_entry_set_text (GTK_ENTRY (GNOME_CMD_COMBO (cmdline->priv->combo)->entry), text);
+ gtk_entry_set_text (GTK_ENTRY (cmdline->priv->combo->entry), text);
}
gboolean gnome_cmd_cmdline_is_empty (GnomeCmdCmdline *cmdline)
{
- const gchar *text = gtk_entry_get_text (GTK_ENTRY (GNOME_CMD_COMBO (cmdline->priv->combo)->entry));
+ const gchar *text = gtk_entry_get_text (GTK_ENTRY (cmdline->priv->combo->entry));
if (text == NULL || strcmp (text, ""))
return TRUE;
@@ -454,8 +453,8 @@ void gnome_cmd_cmdline_focus (GnomeCmdCmdline *cmdline)
g_return_if_fail (GNOME_CMD_IS_CMDLINE (cmdline));
g_return_if_fail (cmdline->priv->combo != NULL);
- gtk_widget_grab_focus (GTK_WIDGET (GNOME_CMD_COMBO (cmdline->priv->combo)->entry));
- gtk_editable_set_position (GTK_EDITABLE (GNOME_CMD_COMBO (cmdline->priv->combo)->entry), -1);
+ gtk_widget_grab_focus (GTK_WIDGET (cmdline->priv->combo->entry));
+ gtk_editable_set_position (GTK_EDITABLE (cmdline->priv->combo->entry), -1);
}
@@ -463,7 +462,7 @@ void gnome_cmd_cmdline_update_style (GnomeCmdCmdline *cmdline)
{
g_return_if_fail (GNOME_CMD_IS_CMDLINE (cmdline));
- GNOME_CMD_COMBO (cmdline->priv->combo)->update_style();
+ cmdline->priv->combo->update_style();
}
@@ -471,7 +470,7 @@ void gnome_cmd_cmdline_show_history (GnomeCmdCmdline *cmdline)
{
g_return_if_fail (GNOME_CMD_IS_CMDLINE (cmdline));
- GNOME_CMD_COMBO (cmdline->priv->combo)->popup_list();
+ cmdline->priv->combo->popup_list();
}
@@ -500,7 +499,7 @@ GtkWidget *gnome_cmd_cmdline_get_entry (GnomeCmdCmdline *cmdline)
{
g_return_val_if_fail (GNOME_CMD_IS_CMDLINE (cmdline), NULL);
- return GNOME_CMD_COMBO (cmdline->priv->combo)->entry;
+ return cmdline->priv->combo->entry;
}
diff --git a/src/gnome-cmd-combo.cc b/src/gnome-cmd-combo.cc
index 5aa8953..df25465 100644
--- a/src/gnome-cmd-combo.cc
+++ b/src/gnome-cmd-combo.cc
@@ -463,32 +463,22 @@ GtkType gnome_cmd_combo_get_type ()
}
-GtkWidget *gnome_cmd_combo_new (gint num_cols, gint text_col, gchar **col_titles)
+GnomeCmdCombo::GnomeCmdCombo(gint num_cols, gint _text_col, gchar **col_titles): sel_data(NULL), sel_text(NULL), text_col(_text_col)
{
- GnomeCmdCombo *combo = (GnomeCmdCombo *) gtk_type_new (gnome_cmd_combo_get_type ());
- combo->text_col = text_col;
- combo->sel_data = NULL;
- combo->sel_text = NULL;
+ list = col_titles ? gnome_cmd_clist_new_with_titles (num_cols, col_titles) : gnome_cmd_clist_new (num_cols);
- if (col_titles)
- combo->list = gnome_cmd_clist_new_with_titles (num_cols, col_titles);
- else
- combo->list = gnome_cmd_clist_new (num_cols);
-
- gtk_widget_ref (combo->list);
- gtk_object_set_data_full (*combo, "combo->list", combo->list, (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_ref (list);
+ g_object_set_data_full (*this, "list", list, (GDestroyNotify) gtk_widget_unref);
// We'll use enter notify events to figure out when to transfer the grab to the list
- gtk_container_add (GTK_CONTAINER (combo->popup), combo->list);
- gtk_widget_show (combo->list);
+ gtk_container_add (GTK_CONTAINER (popup), list);
+ gtk_widget_show (list);
// connect list signals
- g_signal_connect (combo->list, "button-press-event", G_CALLBACK (on_list_button_press), combo);
- g_signal_connect (combo->list, "button-release-event", G_CALLBACK (on_list_button_release), combo);
- g_signal_connect (combo->list, "key-press-event", G_CALLBACK (on_list_key_press), combo);
-
- return GTK_WIDGET (combo);
+ g_signal_connect (list, "button-press-event", G_CALLBACK (on_list_button_press), this);
+ g_signal_connect (list, "button-release-event", G_CALLBACK (on_list_button_release), this);
+ g_signal_connect (list, "key-press-event", G_CALLBACK (on_list_key_press), this);
}
diff --git a/src/gnome-cmd-combo.h b/src/gnome-cmd-combo.h
index 0f2e52a..69d126e 100644
--- a/src/gnome-cmd-combo.h
+++ b/src/gnome-cmd-combo.h
@@ -35,9 +35,10 @@
#include "imageloader.h"
#include "gnome-cmd-pixmap.h"
-#define GNOME_CMD_COMBO(obj) GTK_CHECK_CAST (obj, gnome_cmd_combo_get_type (), GnomeCmdCombo)
-#define GNOME_CMD_COMBO_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gnome_cmd_combo_get_type (), GnomeCmdComboClass)
-#define GNOME_CMD_IS_COMBO(obj) GTK_CHECK_TYPE (obj, gnome_cmd_combo_get_type ())
+#define GNOME_CMD_TYPE_COMBO (gnome_cmd_combo_get_type())
+#define GNOME_CMD_COMBO(obj) GTK_CHECK_CAST (obj, GNOME_CMD_TYPE_COMBO, GnomeCmdCombo)
+#define GNOME_CMD_COMBO_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, GNOME_CMD_TYPE_COMBO, GnomeCmdComboClass)
+#define GNOME_CMD_IS_COMBO(obj) GTK_CHECK_TYPE (obj, GNOME_CMD_TYPE_COMBO)
GtkType gnome_cmd_combo_get_type ();
@@ -49,7 +50,9 @@ struct GnomeCmdCombo
public:
+ operator GObject * () { return G_OBJECT (this); }
operator GtkObject * () { return GTK_OBJECT (this); }
+ operator GtkWidget * () { return GTK_WIDGET (this); }
GtkWidget *entry;
GtkWidget *list;
@@ -79,6 +82,12 @@ struct GnomeCmdCombo
public:
+ void *operator new (size_t size);
+ void operator delete (void *p) { g_object_unref (p); }
+
+ GnomeCmdCombo(gint num_cols, gint text_col, gchar **col_titles=NULL);
+ ~GnomeCmdCombo() {}
+
void clear() { gtk_clist_clear (GTK_CLIST (list)); }
gint append(gchar **text, gpointer data);
gint insert(gchar **text, gpointer data);
@@ -96,6 +105,9 @@ struct GnomeCmdCombo
const gchar *get_selected_text() { return sel_text; }
};
-GtkWidget *gnome_cmd_combo_new (gint num_cols, gint text_col, gchar **col_titles);
+inline void *GnomeCmdCombo::operator new (size_t size)
+{
+ return g_object_new (GNOME_CMD_TYPE_COMBO, NULL);
+}
#endif // __GNOME_CMD_COMBO_H__
diff --git a/src/gnome-cmd-file-selector.cc b/src/gnome-cmd-file-selector.cc
index decb842..9e00cda 100644
--- a/src/gnome-cmd-file-selector.cc
+++ b/src/gnome-cmd-file-selector.cc
@@ -252,7 +252,7 @@ inline void set_connection (GnomeCmdFileSelector *fs, GnomeCmdCon *con, GnomeCmd
fs->set_directory(dir);
if (con_change_needed)
- GNOME_CMD_COMBO (fs->con_combo)->select_data(con);
+ fs->con_combo->select_data(con);
}
@@ -895,7 +895,7 @@ static void on_list_empty_space_clicked (GnomeCmdFileList *fl, GdkEventButton *e
static void on_list_con_changed (GnomeCmdFileList *fl, GnomeCmdCon *con, GnomeCmdFileSelector *fs)
{
fs->priv->dir_history = gnome_cmd_con_get_dir_history (con);
- GNOME_CMD_COMBO (fs->con_combo)->select_data(con);
+ fs->con_combo->select_data(con);
}
@@ -1145,15 +1145,15 @@ static void init (GnomeCmdFileSelector *fs)
fs->file_list()->show_column(GnomeCmdFileList::COLUMN_DIR, FALSE);
// create the connection combo
- fs->con_combo = gnome_cmd_combo_new (2, 1, NULL);
- gtk_widget_ref (fs->con_combo);
+ fs->con_combo = new GnomeCmdCombo(2, 1);
+ gtk_widget_ref (*fs->con_combo);
g_object_set_data_full (*fs, "con_combo", fs->con_combo, (GDestroyNotify) gtk_widget_unref);
- gtk_widget_set_size_request (fs->con_combo, 150, -1);
- gtk_clist_set_row_height (GTK_CLIST (GNOME_CMD_COMBO (fs->con_combo)->list), 20);
- gtk_entry_set_editable (GTK_ENTRY (GNOME_CMD_COMBO (fs->con_combo)->entry), FALSE);
- gtk_clist_set_column_width (GTK_CLIST (GNOME_CMD_COMBO (fs->con_combo)->list), 0, 20);
- gtk_clist_set_column_width (GTK_CLIST (GNOME_CMD_COMBO (fs->con_combo)->list), 1, 60);
- GTK_WIDGET_UNSET_FLAGS (GNOME_CMD_COMBO (fs->con_combo)->button, GTK_CAN_FOCUS);
+ gtk_widget_set_size_request (*fs->con_combo, 150, -1);
+ gtk_clist_set_row_height (GTK_CLIST (fs->con_combo->list), 20);
+ gtk_entry_set_editable (GTK_ENTRY (fs->con_combo->entry), FALSE);
+ gtk_clist_set_column_width (GTK_CLIST (fs->con_combo->list), 0, 20);
+ gtk_clist_set_column_width (GTK_CLIST (fs->con_combo->list), 1, 60);
+ GTK_WIDGET_UNSET_FLAGS (fs->con_combo->button, GTK_CAN_FOCUS);
// create the free space on volume label
fs->vol_label = gtk_label_new ("");
@@ -1187,7 +1187,7 @@ static void init (GnomeCmdFileSelector *fs)
padding = create_hbox (*fs, FALSE, 6);
gtk_box_pack_start (GTK_BOX (vbox), padding, FALSE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (padding), fs->info_label, FALSE, TRUE, 6);
- gtk_box_pack_start (GTK_BOX (fs->con_hbox), fs->con_combo, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (fs->con_hbox), *fs->con_combo, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (fs->con_hbox), fs->vol_label, TRUE, TRUE, 6);
// initialize dnd
@@ -1215,7 +1215,7 @@ static void init (GnomeCmdFileSelector *fs)
// show the widgets
gtk_widget_show (GTK_WIDGET (vbox));
fs->update_concombo_visibility();
- gtk_widget_show (fs->con_combo);
+ gtk_widget_show (*fs->con_combo);
gtk_widget_show (fs->vol_label);
gtk_widget_show (fs->dir_indicator);
gtk_widget_show (fs->scrolledwindow);
@@ -1504,11 +1504,11 @@ void GnomeCmdFileSelector::update_connections()
gboolean found_my_con = FALSE;
- GNOME_CMD_COMBO (con_combo)->clear();
- GNOME_CMD_COMBO (con_combo)->highest_pixmap = 20;
- GNOME_CMD_COMBO (con_combo)->widest_pixmap = 20;
- gtk_clist_set_row_height (GTK_CLIST (GNOME_CMD_COMBO (con_combo)->list), 20);
- gtk_clist_set_column_width (GTK_CLIST (GNOME_CMD_COMBO (con_combo)->list), 0, 20);
+ con_combo->clear();
+ con_combo->highest_pixmap = 20;
+ con_combo->widest_pixmap = 20;
+ gtk_clist_set_row_height (GTK_CLIST (con_combo->list), 20);
+ gtk_clist_set_column_width (GTK_CLIST (con_combo->list), 0, 20);
for (GList *l=gnome_cmd_con_list_get_all (gnome_cmd_con_list_get ()); l; l = l->next)
{
@@ -1529,9 +1529,9 @@ void GnomeCmdFileSelector::update_connections()
if (pixmap)
{
- gint row = GNOME_CMD_COMBO (con_combo)->append(text, con);
+ gint row = con_combo->append(text, con);
- GNOME_CMD_COMBO (con_combo)->set_pixmap(row, 0, pixmap);
+ con_combo->set_pixmap(row, 0, pixmap);
}
}
@@ -1539,7 +1539,7 @@ void GnomeCmdFileSelector::update_connections()
if (!found_my_con)
set_connection(get_home_con ());
else
- GNOME_CMD_COMBO (con_combo)->select_data(get_connection());
+ con_combo->select_data(get_connection());
create_con_buttons (this);
}
@@ -1583,7 +1583,7 @@ gboolean gnome_cmd_file_selector_is_local (FileSelectorID fsID)
void GnomeCmdFileSelector::update_style()
{
- GNOME_CMD_COMBO (con_combo)->update_style();
+ con_combo->update_style();
file_list()->update_style();
if (priv->realized)
diff --git a/src/gnome-cmd-file-selector.h b/src/gnome-cmd-file-selector.h
index 3105cf1..a25e49c 100644
--- a/src/gnome-cmd-file-selector.h
+++ b/src/gnome-cmd-file-selector.h
@@ -41,6 +41,9 @@ typedef enum
} FileSelectorID;
+struct GnomeCmdCombo;
+
+
struct GnomeCmdFileSelector
{
GtkVBox vbox;
@@ -51,7 +54,7 @@ struct GnomeCmdFileSelector
GtkWidget *dir_label;
GtkWidget *scrolledwindow;
GtkWidget *info_label;
- GtkWidget *con_combo;
+ GnomeCmdCombo *con_combo;
GtkWidget *vol_label;
private:
diff --git a/src/widget-factory.h b/src/widget-factory.h
index 5c4d1c9..57274c6 100644
--- a/src/widget-factory.h
+++ b/src/widget-factory.h
@@ -26,12 +26,12 @@
inline GtkWidget *create_clist_combo (GtkWidget *parent, gint num_cols, gint text_col, gchar **titles)
{
- GtkWidget *combo = gnome_cmd_combo_new (num_cols, text_col, titles);
- gtk_widget_ref (combo);
+ GnomeCmdCombo *combo = new GnomeCmdCombo(num_cols, text_col, titles);
+ gtk_widget_ref (*combo);
g_object_set_data_full (G_OBJECT (parent), "combo", combo, (GDestroyNotify) gtk_widget_unref);
- gtk_widget_show (combo);
+ gtk_widget_show (*combo);
- return combo;
+ return *combo;
}
#endif // __WIDGET_FACTORY_H__
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]