notepad_rename.cpp File Reference

#include <gtk/gtk.h>
#include <libergtk/ergtk.h>
#include <liberkeyb/ergtk-keyb.h>
#include "i18n.h"
#include "log.h"
#include "notepad_rename.h"
Include dependency graph for notepad_rename.cpp:

Go to the source code of this file.

Defines

#define WINDOW_TOP_PADDING   46
#define WINDOW_BOTTOM_PADDING   10
#define WINDOW_H_PADDING   40
#define PREVNEXT_HEIGHT   20
#define PREVNEXT_ARROW_WIDTH   140
#define TITLE_V_PADDING   10
#define TITLE_SPACING   20
#define TITLE_PATH_SPACING   10
#define FILEGRID_V_PADDING   10
#define LISTVIEW_COL_SPACING   20
#define LISTVIEW_ICON_WIDTH   30
#define LISTVIEW_ICON_HEIGHT   30
#define POPUP_DIALOG_WIDTH   600
#define POPUP_DIALOG_V_PADDING   10
#define POPUP_DIALOG_H_PADDING   10
#define POPUP_DIALOG_V_SPACING   10
#define POPUP_DIALOG_H_SPACING   10
#define BUTTON_WIDTH   -1
#define BUTTON_HEIGHT   27
#define TEXT_ENTRY_WIDTH   300
#define TEXT_ENTRY_HEIGHT   27
#define TITLE_HEIGHT   44
#define MAX_FILENAME_LEN   200

Functions

static void rename_on_hbox_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data)
static void rename_on_rename_button_clicked (GtkWidget *widget, gpointer data)
static void rename_on_cancel_button_clicked (GtkWidget *widget, gpointer data)
GtkWidget * rename_dialog_create (const GtkWidget *parent, const gchar *current_filename)
void rename_locale_changed ()
const gchar * rename_get_text ()
void rename_set_focus ()

Variables

static GtkWidget * g_dialog = NULL
static GtkWidget * g_rename_label = NULL
static GtkWidget * g_input_entry = NULL
static GtkWidget * g_rename_button = NULL
static GtkWidget * g_cancel_button = NULL
static gchar * g_lastfilename = NULL

Define Documentation

#define BUTTON_HEIGHT   27

Definition at line 65 of file notepad_rename.cpp.

#define BUTTON_WIDTH   -1

Definition at line 64 of file notepad_rename.cpp.

#define FILEGRID_V_PADDING   10

Definition at line 53 of file notepad_rename.cpp.

#define LISTVIEW_COL_SPACING   20

Definition at line 54 of file notepad_rename.cpp.

#define LISTVIEW_ICON_HEIGHT   30

Definition at line 56 of file notepad_rename.cpp.

#define LISTVIEW_ICON_WIDTH   30

Definition at line 55 of file notepad_rename.cpp.

#define MAX_FILENAME_LEN   200

Definition at line 72 of file notepad_rename.cpp.

Referenced by rename_dialog_create().

#define POPUP_DIALOG_H_PADDING   10

Definition at line 60 of file notepad_rename.cpp.

#define POPUP_DIALOG_H_SPACING   10

Definition at line 62 of file notepad_rename.cpp.

#define POPUP_DIALOG_V_PADDING   10

Definition at line 59 of file notepad_rename.cpp.

#define POPUP_DIALOG_V_SPACING   10

Definition at line 61 of file notepad_rename.cpp.

#define POPUP_DIALOG_WIDTH   600

Definition at line 58 of file notepad_rename.cpp.

#define PREVNEXT_ARROW_WIDTH   140

Definition at line 49 of file notepad_rename.cpp.

#define PREVNEXT_HEIGHT   20

Definition at line 48 of file notepad_rename.cpp.

#define TEXT_ENTRY_HEIGHT   27

Definition at line 68 of file notepad_rename.cpp.

#define TEXT_ENTRY_WIDTH   300

Definition at line 67 of file notepad_rename.cpp.

#define TITLE_HEIGHT   44

Definition at line 70 of file notepad_rename.cpp.

#define TITLE_PATH_SPACING   10

Definition at line 52 of file notepad_rename.cpp.

#define TITLE_SPACING   20

Definition at line 51 of file notepad_rename.cpp.

#define TITLE_V_PADDING   10

Definition at line 50 of file notepad_rename.cpp.

#define WINDOW_BOTTOM_PADDING   10

Definition at line 46 of file notepad_rename.cpp.

#define WINDOW_H_PADDING   40

Definition at line 47 of file notepad_rename.cpp.

#define WINDOW_TOP_PADDING   46

Copyright (C) 2010 IREX Technologies B.V. All rights reserved.

Definition at line 45 of file notepad_rename.cpp.


Function Documentation

GtkWidget* rename_dialog_create ( const GtkWidget *  parent,
const gchar *  current_filename 
)

File Name : notepad_rename.h

Description: rename dialog Copyright (C) 2010 IREX Technologies B.V. All rights reserved.

Definition at line 98 of file notepad_rename.cpp.

References BUTTON_HEIGHT, BUTTON_WIDTH, ergtk_keyb_new(), g_cancel_button, g_dialog, g_input_entry, g_lastfilename, g_rename_button, g_rename_label, MAX_FILENAME_LEN, POPUP_DIALOG_H_PADDING, POPUP_DIALOG_H_SPACING, POPUP_DIALOG_V_PADDING, POPUP_DIALOG_V_SPACING, POPUP_DIALOG_WIDTH, rename_locale_changed(), rename_on_cancel_button_clicked(), rename_on_hbox_size_allocate(), rename_on_rename_button_clicked(), TEXT_ENTRY_HEIGHT, and TEXT_ENTRY_WIDTH.

Referenced by notepad::CNotepadWindow::rename().

00099 {
00100 
00101     // dialog
00102     GtkWidget* dialog = gtk_dialog_new ();
00103     gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
00104     gtk_window_set_title (GTK_WINDOW(dialog), "");
00105     gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
00106     gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
00107     gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
00108     g_dialog = dialog;
00109 
00110     // alignment
00111     GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 0);
00112     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 
00113                               POPUP_DIALOG_V_PADDING, 
00114                               POPUP_DIALOG_V_PADDING, 
00115                               POPUP_DIALOG_H_PADDING, 
00116                               POPUP_DIALOG_H_PADDING);
00117     gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), alignment);
00118 
00119     // vbox
00120     GtkWidget* vbox = gtk_vbox_new(FALSE, POPUP_DIALOG_V_SPACING);
00121     gtk_container_add(GTK_CONTAINER(alignment), vbox);
00122 
00123     // rename_label_widget
00124     GtkWidget * rename_label_widget = gtk_label_new("");
00125     gtk_widget_set_name(rename_label_widget, "irex-normal-text");
00126     gtk_widget_set_size_request(rename_label_widget, 
00127             POPUP_DIALOG_WIDTH - 2 * POPUP_DIALOG_H_PADDING, -1);
00128     gtk_misc_set_alignment(GTK_MISC(rename_label_widget), 0.0, 0.0);
00129     gtk_label_set_justify(GTK_LABEL(rename_label_widget), GTK_JUSTIFY_LEFT);
00130     gtk_label_set_single_line_mode(GTK_LABEL(rename_label_widget), FALSE);
00131     gtk_label_set_line_wrap(GTK_LABEL(rename_label_widget), TRUE);
00132     gtk_label_set_ellipsize(GTK_LABEL(rename_label_widget), PANGO_ELLIPSIZE_NONE);
00133     gtk_box_pack_start(GTK_BOX(vbox), rename_label_widget, TRUE, TRUE, 0);
00134     g_rename_label = rename_label_widget;
00135 
00136     // hbox
00137     GtkWidget* hbox = gtk_hbox_new(FALSE, POPUP_DIALOG_H_SPACING);
00138     gtk_widget_set_size_request(hbox, -1, -1);
00139     gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
00140 
00141     // input_entry
00142     GtkWidget* entry_widget = gtk_entry_new();
00143     gtk_widget_set_size_request(entry_widget, TEXT_ENTRY_WIDTH, TEXT_ENTRY_HEIGHT);
00144     gtk_entry_set_max_length(GTK_ENTRY(entry_widget), MAX_FILENAME_LEN);
00145     g_free(g_lastfilename);
00146     g_lastfilename = g_strdup(current_filename);
00147 
00148     if (g_lastfilename)
00149         gtk_entry_set_text(GTK_ENTRY(entry_widget), g_lastfilename);
00150     else 
00151         gtk_entry_set_text(GTK_ENTRY(entry_widget), "");
00152 
00153     gtk_box_pack_start(GTK_BOX(hbox), entry_widget, TRUE, TRUE, 0); 
00154     g_object_set(G_OBJECT(entry_widget), "im-context-inhibit", TRUE, NULL );
00155     g_object_set(G_OBJECT(entry_widget), "activates-default", TRUE, NULL );
00156     g_input_entry = entry_widget;
00157 
00158     // sub_hbox
00159     GtkWidget* sub_hbox = gtk_hbox_new(FALSE, POPUP_DIALOG_H_SPACING);
00160     gtk_box_pack_start(GTK_BOX(hbox), sub_hbox, FALSE, FALSE, 0); 
00161 
00162     // rename_button
00163     GtkWidget* button_widget = gtk_button_new();
00164     gtk_widget_set_size_request(button_widget, BUTTON_WIDTH, BUTTON_HEIGHT);
00165     gtk_box_pack_start(GTK_BOX(sub_hbox), button_widget, FALSE, FALSE, 0); 
00166     g_rename_button = button_widget;
00167     GTK_WIDGET_SET_FLAGS(g_rename_button, GTK_CAN_DEFAULT);
00168     gtk_window_set_default(GTK_WINDOW(dialog), g_rename_button);
00169     
00170     // cancel_button
00171     GtkWidget* cancel_widget = gtk_button_new();
00172     gtk_widget_set_size_request(cancel_widget, BUTTON_WIDTH, BUTTON_HEIGHT);
00173     gtk_box_pack_start(GTK_BOX(sub_hbox), cancel_widget, FALSE, FALSE, 0); 
00174     g_cancel_button = cancel_widget;
00175 
00176     // keyboard_widget
00177     GtkWidget* keyboard_widget = ergtk_keyb_new();
00178     gtk_box_pack_start(GTK_BOX(vbox), keyboard_widget, TRUE, TRUE, 10);
00179 
00180     // install signal hanlders.
00181     g_signal_connect(G_OBJECT(sub_hbox), "size-allocate",  
00182             G_CALLBACK(rename_on_hbox_size_allocate), sub_hbox); 
00183     g_signal_connect(G_OBJECT(button_widget), "clicked", 
00184             G_CALLBACK(rename_on_rename_button_clicked), (gpointer) dialog);
00185     g_signal_connect(G_OBJECT(cancel_widget), "clicked", 
00186             G_CALLBACK(rename_on_cancel_button_clicked), (gpointer) dialog);
00187 
00188     // Focus on the entry in order to show keyboard automatically.
00189     gtk_widget_grab_focus(g_input_entry);
00190     
00191     rename_locale_changed();
00192 
00193     gtk_widget_show_all(dialog);
00194     return dialog;
00195 }

Here is the call graph for this function:

Here is the caller graph for this function:

const gchar* rename_get_text (  ) 

Definition at line 209 of file notepad_rename.cpp.

References g_lastfilename, and LOGPRINTF.

00210 {
00211     LOGPRINTF("%s", g_lastfilename);
00212     return g_lastfilename;
00213 }

void rename_locale_changed (  ) 

Definition at line 198 of file notepad_rename.cpp.

References g_cancel_button, g_rename_button, and g_rename_label.

Referenced by rename_dialog_create().

00199 {
00200     gtk_label_set_text(GTK_LABEL(g_rename_label), 
00201                        _("Type the new name for this note and then tap the Rename button to save it. \n"
00202                          " / \\ |: * ? < or > cannot be used in the name and it cannot begin with a space or period."));
00203 
00204     gtk_button_set_label(GTK_BUTTON(g_rename_button), _("Rename"));
00205     gtk_button_set_label(GTK_BUTTON(g_cancel_button), _("Cancel"));
00206 }

Here is the caller graph for this function:

static void rename_on_cancel_button_clicked ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 237 of file notepad_rename.cpp.

References g_dialog, g_input_entry, g_lastfilename, and LOGPRINTF.

Referenced by rename_dialog_create().

00238 {
00239     const gchar* text = gtk_entry_get_text(GTK_ENTRY(g_input_entry));
00240     LOGPRINTF("%s", text);
00241     g_free(g_lastfilename);
00242     g_lastfilename = g_strdup(text);
00243     gtk_dialog_response(GTK_DIALOG(g_dialog), GTK_RESPONSE_CLOSE);
00244 }

Here is the caller graph for this function:

static void rename_on_hbox_size_allocate ( GtkWidget *  widget,
GtkAllocation *  allocation,
gpointer  user_data 
) [static]

Definition at line 246 of file notepad_rename.cpp.

References BUTTON_WIDTH, ERRORPRINTF, and LOGPRINTF.

Referenced by rename_dialog_create().

00249 {
00250     if (!user_data || !GTK_IS_HBOX(user_data))
00251     {
00252         ERRORPRINTF("Can't adjust for this widget because it's not a HBOX!");
00253         return;
00254     }
00255 
00256     // Get child widgets.
00257     GList * children = gtk_container_get_children(GTK_CONTAINER(user_data));
00258     if (!children)
00259     {
00260         ERRORPRINTF("The hbox hasn't any children!");
00261         return;
00262     }
00263     int n_children = g_list_length(children);
00264 
00265     // Calculate the button's width.
00266     int request_width = BUTTON_WIDTH;
00267     int index = 0;
00268     while (index < n_children)
00269     {
00270         gpointer gp = g_list_nth_data(children, index);
00271         GtkWidget * child = GTK_WIDGET(gp);
00272         GtkRequisition requisition;
00273         gtk_widget_size_request(child, &requisition);
00274         if (request_width < requisition.width)
00275         {
00276             request_width = requisition.width;
00277         }
00278 
00279         LOGPRINTF("index [%d] width [%d]", index, requisition.width);
00280         index++;
00281     }
00282 
00283     // Set the buttons's width to be the request_width.
00284     index = 0;
00285     while (index < n_children)
00286     {
00287         gpointer gp = g_list_nth_data(children, index);
00288         GtkWidget * child = GTK_WIDGET(gp);
00289         GtkRequisition requisition;
00290         gtk_widget_size_request(child, &requisition);
00291         if (requisition.width != request_width)
00292         {   
00293             gtk_widget_set_size_request(child,
00294                     request_width,
00295                     requisition.height);
00296         }
00297         index++;
00298     }
00299 }

Here is the caller graph for this function:

static void rename_on_rename_button_clicked ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 222 of file notepad_rename.cpp.

References g_dialog, g_input_entry, g_lastfilename, and LOGPRINTF.

Referenced by rename_dialog_create().

00223 {
00224     const gchar* text = gtk_entry_get_text(GTK_ENTRY(g_input_entry));
00225     LOGPRINTF("%s", text);
00226     g_free(g_lastfilename);
00227     g_lastfilename = g_strdup(text);
00228     if (g_strcmp0(text, "") == 0) 
00229     {
00230         gtk_dialog_response(GTK_DIALOG(g_dialog), GTK_RESPONSE_CLOSE);
00231     } else 
00232     {
00233         gtk_dialog_response(GTK_DIALOG(g_dialog), GTK_RESPONSE_ACCEPT);
00234     }
00235 }

Here is the caller graph for this function:

void rename_set_focus (  ) 

Definition at line 216 of file notepad_rename.cpp.

References g_input_entry.

00217 {
00218     gtk_widget_grab_focus(g_input_entry);
00219 }


Variable Documentation

GtkWidget* g_cancel_button = NULL [static]

Definition at line 82 of file notepad_rename.cpp.

Referenced by rename_dialog_create(), and rename_locale_changed().

GtkWidget* g_dialog = NULL [static]
GtkWidget* g_input_entry = NULL [static]
gchar* g_lastfilename = NULL [static]
GtkWidget* g_rename_button = NULL [static]

Definition at line 81 of file notepad_rename.cpp.

Referenced by rename_dialog_create(), and rename_locale_changed().

GtkWidget* g_rename_label = NULL [static]

Definition at line 79 of file notepad_rename.cpp.

Referenced by rename_dialog_create(), and rename_locale_changed().

Generated by  doxygen 1.6.2-20100208