1 /** @file scim_lookup_table.h
2 * @brief definition of LookupTable classes.
5 /* ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable. */
8 * Smart Common Input Method
10 * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this program; if not, write to the
25 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
26 * Boston, MA 02111-1307 USA
28 * $Id: scim_lookup_table.h,v 1.32 2005/05/13 04:21:29 suzhe Exp $
31 #ifndef __SCIM_LOOKUP_TABLE_H
32 #define __SCIM_LOOKUP_TABLE_H
36 * @addtogroup Accessories
37 * @ingroup InputServiceFramework
41 #define SCIM_LOOKUP_TABLE_MAX_PAGESIZE 128
44 * @brief The base class of lookup table.
46 * LookupTable is used to store the candidate phrases, it provides a easy way
47 * to manage the content of candidates and flip between multiple pages.
49 * It also can manage the attributes for each candidate string.
51 * This is abstract class and cannot store data.
52 * IMEngine should use its derivation class.
53 * This class is the interface that uses within FrontEnd class.
57 class LookupTableImpl;
59 LookupTableImpl * m_impl;
61 LookupTable (const LookupTable &);
62 const LookupTable & operator= (const LookupTable &);
67 * @param page_size - the maximum page size, can be set by set_page_size() later.
69 LookupTable (int page_size = 10);
72 * @brief Virtual destructor.
74 virtual ~LookupTable ();
77 * @brief Set the strings to label the candidates in one page.
78 * @param labels - the strings to label the candidates in one page.
80 void set_candidate_labels (const std::vector<WideString> &labels);
83 * @brief Get the label string of a candidate in a page.
84 * @param page_index - the index in a page, 0 to (max page size - 1).
85 * @return the corresponding label of the index.
87 WideString get_candidate_label (int page_index) const;
90 * @brief Set the maximum page size.
91 * @param page_size - the max page size of the table.
93 void set_page_size (int page_size);
96 * @brief Get the maximum page size.
97 * @return the max page size of the table.
99 int get_page_size () const;
102 * @brief Get current page size,
103 * @return the page size of current page.It can be less than the max page size.
105 int get_current_page_size () const;
108 * @brief Get the start index of current page.
109 * @return the start item index of current page, starting from 0.
111 int get_current_page_start () const;
114 * @brief Check if the cursor is visible.
115 * @return true if the cursor should be shown.
117 bool is_cursor_visible () const;
120 * @brief Check if the page size is fixed, aka. couldn't reduced by FrontEnd.
121 * @return true if the page size shouldn't be reduced by FrontEnd.
123 bool is_page_size_fixed () const;
126 * @brief Get current cursor position.
127 * @return the cursor position in the table, starting from 0.
129 int get_cursor_pos () const;
132 * @brief Get the cursor position in current page.
133 * @return the cursor position in current page,
134 * equals to get_cursor_pos () - get_current_page_start ().
136 int get_cursor_pos_in_current_page () const;
139 * @brief Flip to the previous page.
140 * @return true if success, false if it's already in the first page.
145 * @brief Flip to the next page.
146 * @return true if success, false if it's already in the last page.
151 * @brief Move cursor position to the previous entry.
152 * @return true if success, false if it's already at the first entry.
157 * @brief Move cursor position to the next entry.
158 * @return true if success. false if it's already at the last entry.
163 * @brief Set the cursor visibility.
164 * @param show - true to show the cursor.
166 void show_cursor (bool show=true);
169 * @brief Set the page size to be fixed, aka. prevent from being changed by FrontEnd.
171 void fix_page_size (bool fixed=true);
174 * @brief Set the cursor position.
175 * @param pos - the absolute position of the cursor.
177 void set_cursor_pos (int pos);
180 * @brief Set the cursor position in current page.
181 * @param pos - the relative position of the cursor in current page.
183 void set_cursor_pos_in_current_page (int pos);
186 * @brief Get a candidate in current page.
188 * @param page_index - the candidate index in current page.
189 * @return the content of this candidate.
193 WideString get_candidate_in_current_page (int page_index) const;
196 * @brief Get the display attributes of a candidate in current page.
198 * @param page_index - the index in current page.
199 * @return the AttributeList object holding the attributes of this candidate.
203 AttributeList get_attributes_in_current_page (int page_index) const;
207 * @name Pure Virtual functions.
208 * These functions should be implemented in derivation classes.
214 * @brief Get a candidate.
215 * @param index - the candidate index in the lookup table.
216 * @return the content of this candidate.
218 virtual WideString get_candidate (int index) const = 0;
221 * @brief Get the attributes of a candidate.
222 * @param index - the index in the lookup table.
223 * @return the AttributeList object holding the attributes of this candidate.
225 virtual AttributeList get_attributes (int index) const = 0;
228 * @brief Return the number of candidates in this table.
229 * @return the number of entries currently in this table.
231 virtual uint32 number_of_candidates () const = 0;
234 * @brief Clear the table.
236 virtual void clear () = 0;
245 * @brief A common lookup table class.
247 * This class implements the LookupTable interface in a common way.
250 class CommonLookupTable : public LookupTable
252 class CommonLookupTableImpl;
254 CommonLookupTableImpl *m_impl;
256 CommonLookupTable (const CommonLookupTable &);
257 const CommonLookupTable & operator= (const CommonLookupTable &);
260 CommonLookupTable (int page_size = 10);
265 * @param page_size - the maximum page size, can be set by set_page_size () later.
266 * @param labels - the strings to label the candidates in one page.
268 CommonLookupTable (int page_size,
269 const std::vector<WideString> &labels);
271 ~CommonLookupTable ();
273 virtual WideString get_candidate (int index) const;
275 virtual AttributeList get_attributes (int index) const;
277 virtual uint32 number_of_candidates () const;
279 virtual void clear ();
283 * @brief Append a candidate string into the table.
285 * @param cand - a candidate string to be added into the table.
286 * @param attrs - the attributes to control the display effect of this entry.
287 * It can be omitted if no attribute.
289 * @return true if success.
291 bool append_candidate (const WideString &cand,
292 const AttributeList &attrs = AttributeList ());
295 * @brief Append a candidate char into the table.
297 * @param cand - a candidate char to be added into the table.
298 * @param attrs - the attributes to control the display effect of this entry.
299 * It can be omitted if no attribute.
301 * @return true if success.
303 bool append_candidate (ucs4_t cand,
304 const AttributeList &attrs = AttributeList ());
311 #endif //__SCIM_LOOKUP_TABLE_H
314 vi:ts=4:nowrap:ai:expandtab