Add widget alignment gtk compatability interface.

This commit is contained in:
Vincent Sanders 2015-04-11 15:20:52 +01:00
parent e193566de4
commit df4e9e322d
4 changed files with 75 additions and 11 deletions

View File

@ -543,3 +543,43 @@ gboolean nsgtk_icon_size_lookup_for_settings(GtkSettings *settings,
return gtk_icon_size_lookup_for_settings(settings, size, width, height);
#endif
}
/* exported interface documented in gtk/compat.h */
void nsgtk_widget_set_alignment(GtkWidget *widget, GtkAlign halign, GtkAlign valign)
{
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_halign(widget, halign);
gtk_widget_set_valign(widget, valign);
#else
gfloat x, y;
switch(halign) {
case GTK_ALIGN_START:
x = 0.0;
break;
case GTK_ALIGN_END:
x = 1.0;
break;
default:
x = 0.5;
break;
}
switch(valign) {
case GTK_ALIGN_START:
y = 0.0;
break;
case GTK_ALIGN_END:
y = 1.0;
break;
default:
y = 0.5;
break;
}
gtk_misc_set_alignment(GTK_MISC(widget), x, y);
#endif
}

View File

@ -69,6 +69,31 @@
#define NSGTK_STOCK_OPEN GTK_STOCK_OPEN
#endif
/* widget alignment only available since 3.0 */
#if !GTK_CHECK_VERSION(3,0,0)
typedef enum {
GTK_ALIGN_FILL,
GTK_ALIGN_START,
GTK_ALIGN_END,
GTK_ALIGN_CENTER,
GTK_ALIGN_BASELINE
} GtkAlign;
#endif
/**
* Set the alignment of a widget.
*
* sets both the horizontal and vertical alignement of a widget
*
* @note this type of alignemnt was not available prior to GTK 3.0 so
* we emulate it using gtk_misc_set_alignment.
*
* \param widget The widget to set alignent on.
* \param halign The horizontal alignment to set.
* \param valign The vertical alignment to set
*/
void nsgtk_widget_set_alignment(GtkWidget *widget, GtkAlign halign, GtkAlign valign);
void nsgtk_widget_set_can_focus(GtkWidget *widget, gboolean can_focus);
gboolean nsgtk_widget_has_focus(GtkWidget *widget);
gboolean nsgtk_widget_get_visible(GtkWidget *widget);

View File

@ -19,14 +19,16 @@
#include <stdint.h>
#include <string.h>
#include "utils/nsoption.h"
#include "utils/utils.h"
#include "utils/messages.h"
#include "desktop/browser.h"
#include "content/content.h"
#include "desktop/search.h"
#include "gtk/compat.h"
#include "gtk/window.h"
#include "gtk/gui.h"
#include "desktop/browser.h"
#include "content/content.h"
#include "utils/nsoption.h"
#include "desktop/search.h"
#include "utils/utils.h"
#include "gtk/search.h"
#include "gtk/tabs.h"
@ -70,13 +72,10 @@ static GtkWidget *nsgtk_tab_label_setup(struct gui_window *window)
hbox = nsgtk_hbox_new(FALSE, 2);
if (nsoption_bool(new_blank) == true)
label = gtk_label_new("New Tab");
else
label = gtk_label_new("Loading...");
label = gtk_label_new(messages_get("NewTab"));
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
gtk_label_set_single_line_mode(GTK_LABEL(label), TRUE);
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
nsgtk_widget_set_alignment(label, GTK_ALIGN_START, GTK_ALIGN_CENTER);
gtk_misc_set_padding(GTK_MISC(label), 0, 0);
gtk_widget_show(label);

View File

@ -709,7 +709,7 @@ de.all.NewWindowNS:Neues Fenster
fr.all.NewWindowNS:Nouvelle fenêtre
it.all.NewWindowNS:Nuova finestra
nl.all.NewWindowNS:Nieuw venster
en.all.NewTab:New tab
en.all.NewTab:New Tab
de.all.NewTab:Neuer Tab
fr.all.NewTab:Nouvel onglet
it.all.NewTab:Nuova scheda