Revision: 6462
Author: nogu.dev
Date: Sun Jun 20 03:45:40 2010
Log: * qt4/immodule/candidatetablewindow.cpp
  - Add TABLE_NR_CELLS.
  - (CandidateTableWindow::~CandidateTableWindow):
    New destructor to free table.
  - (initTableInternal): New function.
  - (CandidateTableWindow::initTable): Call initTableInternal
    to add support for "uim-candwin-prog-layout".
* qt4/immodule/candidatetablewindow.h
  - (CandidateTableWindow): Add destructor.
http://code.google.com/p/uim/source/detail?r=6462

Modified:
 /trunk/qt4/immodule/candidatetablewindow.cpp
 /trunk/qt4/immodule/candidatetablewindow.h

=======================================
--- /trunk/qt4/immodule/candidatetablewindow.cpp        Sun Jun 20 00:04:31 2010
+++ /trunk/qt4/immodule/candidatetablewindow.cpp        Sun Jun 20 03:45:40 2010
@@ -42,6 +42,8 @@

 #include "quiminputcontext.h"

+static const int TABLE_NR_CELLS = TABLE_NR_COLUMNS * TABLE_NR_ROWS;
+
 static const int BLOCK_SPACING = 20;
 static const int HOMEPOSITION_SPACING = 2;

@@ -56,7 +58,7 @@
 static const int AS_HEIGHT = 4;

 // 106 keyboard
-static char DEFAULT_TABLE[TABLE_NR_COLUMNS * TABLE_NR_ROWS] = {
+static char DEFAULT_TABLE[TABLE_NR_CELLS] = {
   '1','2','3','4','5', '6','7','8','9','0',   '-','^','\\',
   'q','w','e','r','t', 'y','u','i','o','p',   '@','[','\0',
   'a','s','d','f','g', 'h','j','k','l',';',   ':',']','\0',
@@ -97,6 +99,12 @@

     initTable();
 }
+
+CandidateTableWindow::~CandidateTableWindow()
+{
+    if (table != DEFAULT_TABLE)
+        free(table);
+}

 QGridLayout *CandidateTableWindow::createLayout(int row, int column,
         int rowOffset, int columnOffset)
@@ -115,10 +123,42 @@
     }
     return layout;
 }
+
+static char *initTableInternal()
+{
+    uim_lisp list = uim_scm_symbol_value("uim-candwin-prog-layout");
+    if (!list || !uim_scm_listp(list))
+        return DEFAULT_TABLE;
+    size_t len = 0;
+    void **array = uim_scm_list2array(list, &len, 0);
+    if (!array|| len <= 0) {
+        free(array);
+        return DEFAULT_TABLE;
+    }
+ char *table = static_cast<char *>(malloc(TABLE_NR_CELLS * sizeof(char)));
+    if (!table) {
+        free(array);
+        return DEFAULT_TABLE;
+    }
+    for (int i = 0; i < TABLE_NR_CELLS; i++) {
+        if (i >= static_cast<int>(len)) {
+            table[i] = '\0';
+            continue;
+        }
+        char *str = static_cast<char *>(array[i]);
+        // XXX: only use first char
+        table[i] = str[0];
+    }
+    free(array);
+    return table;
+}

 void CandidateTableWindow::initTable()
 {
-    table = DEFAULT_TABLE;
+    uim_gc_gate_func_ptr func_body
+        = reinterpret_cast<uim_gc_gate_func_ptr>(initTableInternal);
+    void *ret = uim_scm_call_with_gc_ready_stack(func_body, 0);
+    table = static_cast<char *>(ret);
 }

 void CandidateTableWindow::slotCandidateClicked(int index)
=======================================
--- /trunk/qt4/immodule/candidatetablewindow.h  Sun Jun 20 00:04:31 2010
+++ /trunk/qt4/immodule/candidatetablewindow.h  Sun Jun 20 03:45:40 2010
@@ -50,6 +50,7 @@

     public:
         explicit CandidateTableWindow(QWidget *parent);
+        ~CandidateTableWindow();

     private slots:
         void slotCandidateClicked(int index);

Reply via email to