Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

scim_lookup_table.h

Go to the documentation of this file.
00001 /** @file scim_lookup_table.h
00002  * @brief definition of LookupTable classes.
00003  */
00004 
00005 /*
00006  * Smart Common Input Method
00007  * 
00008  * Copyright (c) 2004 James Su <suzhe@turbolinux.com.cn>
00009  * Copyright (c) 2003 James Su <suzhe@turbolinux.com.cn>
00010  * Copyright (c) 2002 James Su <suzhe@turbolinux.com.cn>
00011  *
00012  *
00013  * This library is free software; you can redistribute it and/or
00014  * modify it under the terms of the GNU Lesser General Public
00015  * License as published by the Free Software Foundation; either
00016  * version 2 of the License, or (at your option) any later version.
00017  *
00018  * This library is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU Lesser General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public
00024  * License along with this program; if not, write to the
00025  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00026  * Boston, MA  02111-1307  USA
00027  *
00028  * $Id: scim_lookup_table.h,v 1.25 2004/06/15 03:25:38 suzhe Exp $
00029  */
00030 
00031 #ifndef __SCIM_LOOKUP_TABLE_H
00032 #define __SCIM_LOOKUP_TABLE_H
00033 
00034 namespace scim {
00035 /**
00036  * @addtogroup Helper
00037  * @{
00038  */
00039 
00040 #define SCIM_LOOKUP_TABLE_MAX_PAGESIZE  16
00041 
00042 /**
00043  * @brief The base class of lookup table.
00044  *
00045  * LookupTable is used to store the candidate phrases, it provides a easy way
00046  * to manage the content of candidates and flip between multiple pages.
00047  *
00048  * It also can manage the attributes for each candidate string.
00049  *
00050  * This is abstract class and cannot store data.
00051  * IMEngine should use its derivation class.
00052  * This class is the interface that uses within FrontEnd class.
00053  */
00054 class LookupTable
00055 {
00056     class LookupTableImpl;
00057 
00058     LookupTableImpl * m_impl;
00059 
00060     LookupTable (const LookupTable &);
00061     const LookupTable & operator= (const LookupTable &);
00062 
00063 public:
00064     /**
00065      * @brief Constructor
00066      * @param page_size - the maximum page size, can be set by set_page_size() later.
00067      */
00068     LookupTable (int page_size = 10);
00069 
00070     /**
00071      * @brief Virtual destructor.
00072      */
00073     virtual ~LookupTable ();
00074 
00075     /**
00076      * @brief Set the strings to label the candidates in one page.
00077      * @param labels - the strings to label the candidates in one page.
00078      */
00079     void set_candidate_labels (const std::vector<WideString> &labels);
00080 
00081     /**
00082      * @brief Get the label string of a candidate in a page.
00083      * @param page_index - the index in a page, 0 to (max page size - 1).
00084      * @return the corresponding label of the index. 
00085      */
00086     WideString get_candidate_label (int page_index) const;
00087 
00088     /**
00089      * @brief Set the maximum page size.
00090      * @param page_size - the max page size of the table.
00091      */
00092     void set_page_size (int page_size); 
00093 
00094     /**
00095      * @brief Get the maximum page size.
00096      * @return the max page size of the table.
00097      */
00098     int get_page_size () const;
00099 
00100     /**
00101      * @brief Get current page size,
00102      * @return the page size of current page.It can be less than the max page size.
00103      */
00104     int get_current_page_size () const;
00105 
00106     /**
00107      * @brief Get the start index of current page.
00108      * @return the start item index of current page, starting from 0.
00109      */
00110     int get_current_page_start () const;
00111 
00112     /**
00113      * @brief Check if the cursor is visible.
00114      * @return true if the cursor should be shown.
00115      */
00116     bool is_cursor_visible () const;
00117 
00118     /**
00119      * @brief Get current cursor position.
00120      * @return the cursor position in the table, starting from 0.
00121      */
00122     int get_cursor_pos () const;
00123 
00124     /**
00125      * @brief Get the cursor position in current page.
00126      * @return the cursor position in current page,
00127      *         equals to get_cursor_pos () - get_current_page_start ().
00128      */
00129     int get_cursor_pos_in_current_page () const;
00130 
00131     /**
00132      * @brief Flip to the previous page.
00133      * @return true if success, false if it's already in the first page.
00134      */
00135     bool page_up ();
00136 
00137     /**
00138      * @brief Flip to the next page.
00139      * @return true if success, false if it's already in the last page.
00140      */
00141     bool page_down ();
00142 
00143     /**
00144      * @brief Move cursor position to the previous entry.
00145      * @return true if success, false if it's already at the first entry.
00146      */
00147     bool cursor_up ();
00148 
00149     /**
00150      * @brief Move cursor position to the next entry.
00151      * @return true if success. false if it's already at the last entry.
00152      */
00153     bool cursor_down ();
00154 
00155     /**
00156      * @brief Set the cursor visibility.
00157      * @param show - true to show the cursor.
00158      */
00159     void show_cursor (bool show=true);
00160 
00161     /**
00162      * @brief Set the cursor position.
00163      * @param pos - the absolute position of the cursor.
00164      */
00165     void set_cursor_pos (int pos);
00166 
00167     /**
00168      * @brief Set the cursor position in current page.
00169      * @param pos - the relative position of the cursor in current page.
00170      */
00171     void set_cursor_pos_in_current_page (int pos);
00172 
00173     /**
00174      * @brief Get a candidate in current page.
00175      *
00176      * @param page_index - the candidate index in current page.
00177      * @return the content of this candidate.
00178      * 
00179      * @sa get_candidate
00180      */
00181     WideString get_candidate_in_current_page (int page_index) const;
00182 
00183     /**
00184      * @brief Get the display attributes of a candidate in current page.
00185      *
00186      * @param page_index - the index in current page.
00187      * @return the AttributeList object holding the attributes of this candidate.
00188      *
00189      * @sa get_attributes
00190      */
00191     AttributeList get_attributes_in_current_page (int page_index) const;
00192 
00193 public:
00194     /**
00195      * @name Pure Virtual functions.
00196      * These functions should be implemented in derivation classes.
00197      *
00198      * @{
00199      */
00200 
00201     /**
00202      * @brief Get a candidate.
00203      * @param index - the candidate index in the lookup table.
00204      * @return the content of this candidate.
00205      */
00206     virtual WideString get_candidate (int index) const = 0;
00207 
00208     /**
00209      * @brief Get the attributes of a candidate.
00210      * @param index - the index in the lookup table.
00211      * @return the AttributeList object holding the attributes of this candidate.
00212      */
00213     virtual AttributeList get_attributes (int index) const = 0;
00214 
00215     /**
00216      * @brief Return the number of candidates in this table.
00217      * @return the number of entries currently in this table.
00218      */
00219     virtual uint32 number_of_candidates () const = 0;
00220 
00221     /**
00222      * @brief Clear the table.
00223      */
00224     virtual void clear () = 0;
00225 
00226     /**
00227      * @}
00228      */
00229 };
00230 
00231 
00232 /**
00233  * @brief A common lookup table class.
00234  *
00235  * This class implements the LookupTable interface in a common way.
00236  *
00237  */
00238 class CommonLookupTable : public LookupTable
00239 {
00240     std::vector <ucs4_t> m_buffer;
00241     std::vector <uint32> m_index;
00242 
00243     AttributeList        m_attributes;
00244     std::vector <uint32> m_attrs_index;
00245 
00246 public:
00247     CommonLookupTable (int page_size = 10);
00248  
00249     /**
00250      * @brief Constructor
00251      *
00252      * @param page_size - the maximum page size, can be set by set_page_size () later.
00253      * @param labels - the strings to label the candidates in one page.
00254      */
00255     CommonLookupTable (int                            page_size,
00256                        const std::vector<WideString> &labels);
00257 
00258     virtual WideString get_candidate (int index) const;
00259 
00260     virtual AttributeList get_attributes (int index) const;
00261 
00262     virtual uint32 number_of_candidates () const;
00263 
00264     virtual void clear ();
00265 
00266 public:
00267     /**
00268      * @brief Append a candidate string into the table.
00269      *
00270      * @param cand  - a candidate string to be added into the table.
00271      * @param attrs - the attributes to control the display effect of this entry.
00272      *                It can be omitted if no attribute.
00273      *
00274      * @return true if success.
00275      */
00276     bool append_candidate (const WideString    &cand,
00277                            const AttributeList &attrs = AttributeList ());
00278 
00279     /**
00280      * @brief Append a candidate char into the table.
00281      *
00282      * @param cand  - a candidate char to be added into the table.
00283      * @param attrs - the attributes to control the display effect of this entry.
00284      *                It can be omitted if no attribute.
00285      *
00286      * @return true if success.
00287      */
00288     bool append_candidate (ucs4_t               cand,
00289                            const AttributeList &attrs = AttributeList ());
00290 };
00291 
00292 /** @} */
00293 
00294 } // namespace scim
00295 
00296 #endif //__SCIM_LOOKUP_TABLE_H
00297 
00298 /*
00299 vi:ts=4:nowrap:ai:expandtab
00300 */

Generated on Tue Apr 19 00:10:59 2005 for scim by  doxygen 1.4.1