Refactor: remove unused GncCellRendererPopupEntry

This commit is contained in:
Richard Cohen 2023-05-31 10:58:14 +01:00
parent 0f2c6a002f
commit 6cc6ac8681
4 changed files with 0 additions and 433 deletions

View File

@ -50,7 +50,6 @@ set (gnome_utils_SOURCES
gnc-amount-edit.c
gnc-autoclear.c
gnc-autosave.c
gnc-cell-renderer-popup-entry.c
gnc-cell-renderer-text-flag.c
gnc-cell-renderer-text-view.c
gnc-cell-view.c
@ -137,7 +136,6 @@ set (gnome_utils_HEADERS
gnc-account-sel.h
gnc-amount-edit.h
gnc-autoclear.h
gnc-cell-renderer-popup-entry.h
gnc-cell-renderer-text-flag.h
gnc-cell-renderer-text-view.h
gnc-cell-view.h

View File

@ -1,356 +0,0 @@
/*************************************************************************
* The following code has come from Planner. This code implements a
* GtkCalendar in a custom GtkCellEditable popup from GtkCellRenderer.
*
* These files have been renamed and changed to remove code not required
* and to remove a dependency on libplanner.
*
* Copyright (C) 2012 Robert Fewell
*
* Copyright (C) 2001-2002 CodeFactory AB
* Copyright (C) 2001-2002 Richard Hult <richard@imendio.com>
* Copyright (C) 2001-2002 Mikael Hallendal <micke@imendio.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*************************************************************************/
#include <config.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>
#include "gnc-cell-renderer-popup-entry.h"
#include "dialog-utils.h"
#include "gnc-date.h"
static void gpw_cell_editable_init (GtkCellEditableIface *iface);
static gboolean gpw_key_press_event (GtkWidget *box,
GdkEventKey *key_event);
static void gpw_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
static void gpw_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
enum
{
ARROW_CLICKED,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_EDITING_CANCELED,
};
static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE_WITH_CODE (GncPopupEntry, gnc_popup_entry, GTK_TYPE_EVENT_BOX,
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, gpw_cell_editable_init))
static void
gnc_popup_entry_init (GncPopupEntry *widget)
{
GtkWidget *arrow;
GtkStyleContext *context;
widget->editing_canceled = FALSE;
widget->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_set_homogeneous (GTK_BOX(widget->hbox), FALSE);
gtk_widget_show (widget->hbox);
widget->entry = g_object_new (GTK_TYPE_ENTRY, "has_frame", FALSE, NULL);
gtk_entry_set_visibility (GTK_ENTRY(widget->entry), TRUE);
gtk_widget_show (widget->entry);
context = gtk_widget_get_style_context (widget->entry);
gtk_style_context_add_class (context, "combo");
widget->button = gtk_button_new ();
gtk_widget_show (widget->button);
context = gtk_widget_get_style_context (widget->button);
gtk_style_context_add_class (context, "combo");
arrow = gtk_image_new_from_icon_name ("pan-down-symbolic", GTK_ICON_SIZE_BUTTON);
gtk_widget_show (arrow);
gtk_container_add (GTK_CONTAINER(widget->button), arrow);
gtk_box_pack_start (GTK_BOX(widget->hbox), widget->entry, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX(widget->hbox), widget->button, FALSE, TRUE, 0);
gtk_container_add (GTK_CONTAINER(widget), widget->hbox);
gtk_widget_set_can_focus (GTK_WIDGET(widget), TRUE);
gtk_widget_add_events (GTK_WIDGET(widget), GDK_KEY_PRESS_MASK);
gtk_widget_add_events (GTK_WIDGET(widget), GDK_KEY_RELEASE_MASK);
}
static void
gpw_grab_focus (GtkWidget *box)
{
GncPopupEntry *widget = GNC_POPUP_ENTRY(box);
gtk_widget_grab_focus (widget->entry);
}
static void
gnc_popup_entry_class_init (GncPopupEntryClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
widget_class->key_press_event = gpw_key_press_event;
widget_class->grab_focus = gpw_grab_focus;
gobject_class->set_property = gpw_set_property;
gobject_class->get_property = gpw_get_property;
g_object_class_override_property (gobject_class,
PROP_EDITING_CANCELED,
"editing-canceled");
signals[ARROW_CLICKED] = g_signal_new
("arrow-clicked",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
static void
gpw_set_property (GObject *object, guint param_id,
const GValue *value, GParamSpec *pspec)
{
GncPopupEntry *pe = GNC_POPUP_ENTRY(object);
switch (param_id)
{
case PROP_EDITING_CANCELED:
pe->editing_canceled = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
break;
}
}
static void
gpw_get_property (GObject *object, guint param_id,
GValue *value, GParamSpec *pspec)
{
GncPopupEntry *pe = GNC_POPUP_ENTRY(object);
switch (param_id)
{
case PROP_EDITING_CANCELED:
g_value_set_boolean (value, pe->editing_canceled);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
break;
}
}
static void
gpw_arrow_clicked (GtkWidget *button, GncPopupEntry *widget)
{
g_signal_emit (widget, signals[ARROW_CLICKED], 0);
}
/* GtkCellEditable method implementations
*/
static void
gtk_cell_editable_entry_activated (GtkEntry *entry, GncPopupEntry *widget)
{
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE(widget));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE(widget));
}
static gboolean
gtk_cell_editable_key_press_event (GtkEntry *entry,
GdkEventKey *key_event,
GncPopupEntry *widget)
{
const char *date_string;
gint year = 0, month = 0, day = 0;
struct tm when;
if (key_event->keyval == GDK_KEY_Escape)
{
widget->editing_canceled = TRUE;
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE(widget));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE(widget));
return TRUE;
}
date_string = gtk_entry_get_text (entry);
memset (&when, 0, sizeof (when));
if (qof_scan_date (date_string, &day, &month, &year))
{
gchar *datestr;
when.tm_year = year - 1900;
when.tm_mon = month - 1;
when.tm_mday = day;
if (!gnc_handle_date_accelerator (key_event, &when, date_string))
return FALSE;
datestr = qof_print_date (gnc_mktime (&when));
gtk_entry_set_text (entry, datestr);
g_free (datestr);
gtk_widget_grab_focus (GTK_WIDGET(entry));
return TRUE;
}
return FALSE;
}
static gboolean
gpw_key_press_event (GtkWidget *box,
GdkEventKey *key_event)
{
GncPopupEntry *widget = GNC_POPUP_ENTRY(box);
GdkEvent tmp_event;
gtk_widget_grab_focus (widget->entry);
if (key_event->keyval == GDK_KEY_Escape)
{
widget->editing_canceled = TRUE;
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE(widget));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE(widget));
return TRUE;
}
if (key_event->keyval == GDK_KEY_Left)
{
gtk_editable_set_position (GTK_EDITABLE(widget->entry), 0);
return TRUE;
}
if (key_event->keyval == GDK_KEY_Right)
{
gtk_editable_set_position (GTK_EDITABLE(widget->entry), -1);
return TRUE;
}
/* Hackish :/ Synthesize a key press event for the entry. */
memcpy (&tmp_event, key_event, sizeof (GdkEventKey));
tmp_event.key.window = gtk_widget_get_window (widget->entry);
tmp_event.key.send_event = TRUE;
gtk_widget_event (widget->entry, &tmp_event);
return GTK_WIDGET_CLASS (gnc_popup_entry_parent_class)->key_press_event (GTK_WIDGET(widget),
key_event);
}
static void
gpw_start_editing (GtkCellEditable *cell_editable,
GdkEvent *event)
{
GncPopupEntry *widget = GNC_POPUP_ENTRY(cell_editable);
gtk_editable_select_region (GTK_EDITABLE(widget->entry), 0, -1);
g_signal_connect (G_OBJECT(widget->entry),
"activate",
G_CALLBACK(gtk_cell_editable_entry_activated),
widget);
g_signal_connect (G_OBJECT(widget->entry),
"key_press_event",
G_CALLBACK(gtk_cell_editable_key_press_event),
widget);
g_signal_connect (G_OBJECT(widget->button),
"clicked",
(GCallback)gpw_arrow_clicked,
widget);
}
static void
gpw_cell_editable_init (GtkCellEditableIface *iface)
{
iface->start_editing = gpw_start_editing;
}
void
gnc_popup_entry_set_text (GncPopupEntry *popup, const gchar *text)
{
g_return_if_fail (GNC_IS_POPUP_ENTRY(popup));
gtk_entry_set_text (GTK_ENTRY(popup->entry), text ? text : "");
}
const gchar *
gnc_popup_entry_get_text (GncPopupEntry *popup)
{
g_return_val_if_fail (GNC_IS_POPUP_ENTRY(popup), NULL);
return gtk_entry_get_text (GTK_ENTRY(popup->entry));
}
gint
gnc_popup_get_button_width (void)
{
GtkWidget *window, *button, *arrow;
gint width;
GtkRequisition req;
window = gtk_window_new (GTK_WINDOW_POPUP);
button = gtk_button_new ();
gtk_widget_show (button);
gtk_container_add (GTK_CONTAINER(window), button);
arrow = gtk_image_new_from_icon_name ("pan-down-symbolic", GTK_ICON_SIZE_BUTTON);
gtk_widget_show (arrow);
gtk_container_add (GTK_CONTAINER(button), arrow);
gtk_window_move (GTK_WINDOW(window), -500, -500);
gtk_widget_show (window);
gtk_widget_get_preferred_size (window, &req, NULL);
width = req.width;
gtk_widget_destroy (window);
return width;
}

View File

@ -1,74 +0,0 @@
/*************************************************************************
* The following code has come from Planner. This code implements a
* GtkCalendar in a custom GtkCellEditable popup from GtkCellRenderer.
*
* These files have been renamed and changed to remove code not required
* and to remove a dependency on libplanner.
*
* Copyright (C) 2012 Robert Fewell
*
* Copyright (C) 2001-2002 CodeFactory AB
* Copyright (C) 2001-2002 Richard Hult <richard@imendio.com>
* Copyright (C) 2001-2002 Mikael Hallendal <micke@imendio.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*************************************************************************/
#ifndef __GNC_POPUP_ENTRY_H__
#define __GNC_POPUP_ENTRY_H__
#include <pango/pango.h>
#include <gtk/gtk.h>
#define GNC_TYPE_POPUP_ENTRY (gnc_popup_entry_get_type ())
#define GNC_POPUP_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_POPUP_ENTRY, GncPopupEntry))
#define GNC_POPUP_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_POPUP_ENTRY, GncPopupEntryClass))
#define GNC_IS_POPUP_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_POPUP_ENTRY))
#define GNC_IS_POPUP_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), GNC_TYPE_POPUP_ENTRY))
#define GNC_POPUP_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_POPUP_ENTRY, GncPopupEntryClass))
typedef struct _GncPopupEntry GncPopupEntry;
typedef struct _GncPopupEntryClass GncPopupEntryClass;
struct _GncPopupEntry
{
GtkEventBox parent;
GtkWidget *hbox;
GtkWidget *button;
GtkWidget *entry;
gboolean editing_canceled;
};
struct _GncPopupEntryClass
{
GtkEventBoxClass parent_class;
};
GType gnc_popup_entry_get_type (void) G_GNUC_CONST;
GtkWidget *gnc_popup_entry_new (void);
void gnc_popup_entry_set_text (GncPopupEntry *popup,
const gchar *text);
const gchar *gnc_popup_entry_get_text (GncPopupEntry *popup);
gint gnc_popup_get_button_width (void);
#endif /* __GNC_POPUP_ENTRY_H__ */

View File

@ -149,7 +149,6 @@ gnucash/gnome-utils/gnc-account-sel.c
gnucash/gnome-utils/gnc-amount-edit.c
gnucash/gnome-utils/gnc-autoclear.c
gnucash/gnome-utils/gnc-autosave.c
gnucash/gnome-utils/gnc-cell-renderer-popup-entry.c
gnucash/gnome-utils/gnc-cell-renderer-text-flag.c
gnucash/gnome-utils/gnc-cell-renderer-text-view.c
gnucash/gnome-utils/gnc-cell-view.c