Revision: 7171
Author:   ek.kato
Date:     Fri Jul  1 07:27:47 2011
Log:      * gtk2/immodule/uim-cand-win-horizontal-gtk.c
  - (get_layout_x) : New.  Get adjusted parameter for label.
  - (label_exposed) : Adjust the highlight label position.
  - (button_clicked) : Ditto.
  - (uim_cand_win_horizontal_gtk_set_index) : Ditto.

http://code.google.com/p/uim/source/detail?r=7171

Modified:
 /trunk/gtk2/immodule/uim-cand-win-horizontal-gtk.c

=======================================
--- /trunk/gtk2/immodule/uim-cand-win-horizontal-gtk.c Fri Jul 1 06:51:49 2011 +++ /trunk/gtk2/immodule/uim-cand-win-horizontal-gtk.c Fri Jul 1 07:27:47 2011
@@ -36,6 +36,8 @@
 #include "uim-cand-win-horizontal-gtk.h"
 #include <string.h>
 #include <stdlib.h>
+#include <math.h>
+
 #include <uim/uim.h>
 #include <uim/uim-scm.h>

@@ -166,6 +168,38 @@
gtk_window_set_default_size(GTK_WINDOW(cwin), DEFAULT_MIN_WINDOW_WIDTH, -1);
   gtk_window_set_resizable(GTK_WINDOW(cwin), FALSE);
 }
+
+#if !GTK_CHECK_VERSION(2, 90, 0)
+static void
+get_layout_x(GtkLabel *label, gint *xp)
+{
+  GtkMisc *misc;
+  GtkWidget *widget;
+  gfloat xalign;
+  gint req_width, x;
+
+  misc = GTK_MISC(label);
+  widget = GTK_WIDGET(label);
+
+  if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_LTR)
+    xalign = misc->xalign;
+  else
+    xalign = 1.0 - misc->xalign;
+
+  req_width = widget->requisition.width;
+
+  x = floor(widget->allocation.x + (gint)misc->xpad +
+            xalign * (widget->allocation.width - req_width));
+
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
+    x = MAX(x, widget->allocation.x + misc->xpad);
+  else
+ x = MIN(x, widget->allocation.x + widget->allocation.width - misc->xpad);
+
+  if (xp)
+    *xp = x;
+}
+#endif

 static gboolean
 label_exposed(GtkWidget *label, GdkEventExpose *event, gpointer data)
@@ -183,8 +217,10 @@
     /* FIXME */
     ;
 #else
+    gint x;
+    get_layout_x(GTK_LABEL(label), &x);
     gdk_draw_layout_with_colors(label->window,
-                     label->style->black_gc, 0, 0,
+                     label->style->black_gc, x, 0,
                      GTK_LABEL(label)->layout,
                      &label->style->text[GTK_STATE_SELECTED],
                      &label->style->bg[GTK_STATE_SELECTED]);
@@ -228,13 +264,15 @@
     p = idxbutton->button;
     if (p == button) {
       GtkWidget *label = gtk_bin_get_child(GTK_BIN(button));
+      gint x;
       idx = idxbutton->cand_index_in_page;
 #if GTK_CHECK_VERSION(2, 90, 0)
       /* FIXME */
 #else
+      get_layout_x(GTK_LABEL(label), &x);
       if (GTK_LABEL(label)->layout) {
         gdk_draw_layout_with_colors(label->window,
-                     label->style->black_gc, 0, 0,
+                     label->style->black_gc, x, 0,
                      GTK_LABEL(label)->layout,
                      &label->style->text[GTK_STATE_SELECTED],
                      &label->style->bg[GTK_STATE_SELECTED]);
@@ -358,7 +396,7 @@
     uim_cand_win_gtk_set_page(cwin, new_page);

   if (cwin->candidate_index >= 0) {
-    gint pos;
+    gint pos, x;
     struct index_button *idxbutton, *prev_selected;
     GtkWidget *label;

@@ -388,9 +426,10 @@
 #if GTK_CHECK_VERSION(2, 90, 0)
     /* FIXME */
 #else
+    get_layout_x(GTK_LABEL(label), &x);
     if (GTK_LABEL(label)->layout) {
       gdk_draw_layout_with_colors(label->window,
-                     label->style->black_gc, 0, 0,
+                     label->style->black_gc, x, 0,
                      GTK_LABEL(label)->layout,
                      &label->style->text[GTK_STATE_SELECTED],
                      &label->style->bg[GTK_STATE_SELECTED]);

Reply via email to