Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | 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.19 2004/03/01 03:47:34 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  * This is abstract class and cannot store data.
00046  * Server should use its derivation class.
00047  * This class is the interface that uses within FrontEnd class.
00048  */
00049 class LookupTable
00050 {
00051     class LookupTableImpl;
00052 
00053     LookupTableImpl * m_impl;
00054 
00055     LookupTable (const LookupTable &);
00056     const LookupTable & operator= (const LookupTable &);
00057 
00058 public:
00059     /**
00060      * @brief Constructor
00061      * @param page_size - the maximum page size, can be set by set_page_size() later.
00062      * @param page_up_key - the key event to page up.
00063      * @param page_down_key - the key event to page down.
00064      * @param page_index_keys - the key events to select items in current page directly.
00065      */
00066     LookupTable (int                          page_size,
00067                  const KeyEvent&              page_up_key,
00068                  const KeyEvent&              page_down_key,
00069                  const std::vector<KeyEvent> &page_index_keys);
00070 
00071     /**
00072      * @brief Virtual destructor.
00073      */
00074     virtual ~LookupTable ();
00075 
00076     /**
00077      * @brief Set the key events of page indexes.
00078      * @param page_index_keys - the key events to select items in current page directly.
00079      */
00080     void set_page_index_keys (const std::vector<KeyEvent> &page_index_keys);
00081 
00082     /**
00083      * @brief Set the key events of page up and down.
00084      * @param page_up - the key event to page up.
00085      * @param page_down - the key event to page down.
00086      */
00087     void set_page_updown_keys (const KeyEvent &page_up,
00088                                const KeyEvent &page_down);
00089 
00090     /**
00091      * @brief Set the maximum page size.
00092      * @param page_size - the max page size of the table.
00093      */
00094     void set_page_size (int page_size); 
00095 
00096     /**
00097      * @brief Get the maximum page size.
00098      * @return the max page size of the table.
00099      */
00100     int get_page_size () const;
00101 
00102     /**
00103      * @brief Get current page size,
00104      * @return the page size of current page.It can be less than the max page size.
00105      */
00106     int get_current_page_size () const;
00107 
00108     /**
00109      * @brief Get the start index of current page.
00110      * @return the start item index of current page, starting from 0.
00111      */
00112     int get_current_page_start () const;
00113 
00114     /**
00115      * @brief Get current cursor position.
00116      * @return the cursor position in the table, starting from 0.
00117      */
00118     int get_cursor_pos () const;
00119 
00120     /**
00121      * @brief Get the cursor position in current page.
00122      * @return the cursor position in current page,
00123      *         equals to get_cursor_pos () - get_current_page_start ().
00124      */
00125     int get_cursor_pos_in_page () const;
00126 
00127     /**
00128      * @brief Flip to the previous page.
00129      * @return true if success, false if it's already in the first page.
00130      */
00131     bool page_up ();
00132 
00133     /**
00134      * @brief Flip to the next page.
00135      * @return true if success, false if it's already in the last page.
00136      */
00137     bool page_down ();
00138 
00139     /**
00140      * @brief Move cursor position to the previous entry.
00141      * @return true if success, false if it's already at the first entry.
00142      */
00143     bool cursor_up ();
00144 
00145     /**
00146      * @brief Move cursor position to the next entry.
00147      * @return true if success. false if it's already at the last entry.
00148      */
00149     bool cursor_down ();
00150 
00151     /**
00152      * @brief Set the cursor visibility.
00153      * @param show - true to show the cursor.
00154      */
00155     void show_cursor (bool show=true);
00156 
00157     /**
00158      * @brief Check if the cursor is visible.
00159      * @return true if the cursor should be shown.
00160      */
00161     bool is_cursor_visible () const;
00162     
00163     /**
00164      * @brief Get the key event of a page index.
00165      * @param page_index - the page index, 0 to (max page size - 1).
00166      * @return the corresponding key event of page_index. 
00167      */
00168     KeyEvent get_page_index_key (int page_index) const;
00169 
00170     /**
00171      * @brief Get the key event of page up.
00172      * @return the page up key event.
00173      */
00174     KeyEvent get_page_up_key () const;
00175 
00176     /**
00177      * @brief Get key event of page down.
00178      * @return the page down key event.
00179      */
00180     KeyEvent get_page_down_key () const;
00181 
00182     /**
00183      * @brief Get the content of an entry in current page.
00184      *
00185      * @param page_index - the index in current page.
00186      * @return the content.
00187      * 
00188      * @sa get_content
00189      */
00190     WideString get_content_in_page (int page_index) const;
00191 
00192 public:
00193     /**
00194      * @name Pure Virtual functions.
00195      * These functions should be implemented in derivation classes.
00196      *
00197      * @{
00198      */
00199 
00200     /**
00201      * @brief Get the content of an entry.
00202      * @param index - the index in the lookup table.
00203      * @return the content.
00204      */
00205     virtual WideString get_content (int index) const = 0;
00206 
00207     /**
00208      * @brief Return the number of entries in this table.
00209      * @return the number of entries currently in this table.
00210      */
00211     virtual uint32 number_of_entries () const = 0;
00212 
00213     /**
00214      * @brief Clear the table.
00215      */
00216     virtual void clear () = 0;
00217 
00218     /**
00219      * @}
00220      */
00221 };
00222 
00223 
00224 /**
00225  * @brief A common lookup table class.
00226  *
00227  * This class implements the LookupTable interface in a common way.
00228  *
00229  */
00230 class CommonLookupTable : public LookupTable
00231 {
00232     std::vector <ucs4_t> m_buffer;
00233     std::vector <uint32> m_index;
00234 
00235 public:
00236     CommonLookupTable (int                          page_size,
00237                        const KeyEvent&              page_up_key,
00238                        const KeyEvent&              page_down_key,
00239                        const std::vector<KeyEvent> &page_index_keys);
00240 
00241     CommonLookupTable (int                          page_size,
00242                        const std::vector<KeyEvent> &page_index_keys);
00243 
00244     CommonLookupTable (int page_size = 10);
00245 
00246     virtual WideString get_content (int index) const;
00247 
00248     virtual uint32 number_of_entries () const;
00249 
00250     virtual void clear ();
00251 
00252 public:
00253     /**
00254      * @brief Append a string into the table.
00255      * @param entry - an entry to be added into the table.
00256      * @return true if success.
00257      */
00258     bool append_entry (const WideString& entry);
00259 
00260     /**
00261      * @brief Append a single char into the table.
00262      * @param entry - an entry to be added into the table.
00263      * @return true if success.
00264      */
00265     bool append_entry (ucs4_t entry);
00266 };
00267 
00268 /** @} */
00269 
00270 } // namespace scim
00271 
00272 #endif //__SCIM_LOOKUP_TABLE_H
00273 
00274 /*
00275 vi:ts=4:nowrap:ai:expandtab
00276 */

Generated on Fri May 7 17:27:25 2004 for scim by doxygen 1.3.6