Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /***************************************************************************** |
2 | * Module for Microchip Graphics Library |
||
3 | * GOL Layer |
||
4 | * Edit box |
||
5 | ***************************************************************************** |
||
6 | * FileName: EditBox.h |
||
7 | * Dependencies: None |
||
8 | * Processor: PIC24F, PIC24H, dsPIC, PIC32 |
||
9 | * Compiler: MPLAB C30 V3.00, MPLAB C32 |
||
10 | * Linker: MPLAB LINK30, MPLAB LINK32 |
||
11 | * Company: Microchip Technology Incorporated |
||
12 | * |
||
13 | * Software License Agreement |
||
14 | * |
||
15 | * Copyright © 2008 Microchip Technology Inc. All rights reserved. |
||
16 | * Microchip licenses to you the right to use, modify, copy and distribute |
||
17 | * Software only when embedded on a Microchip microcontroller or digital |
||
18 | * signal controller, which is integrated into your product or third party |
||
19 | * product (pursuant to the sublicense terms in the accompanying license |
||
20 | * agreement). |
||
21 | * |
||
22 | * You should refer to the license agreement accompanying this Software |
||
23 | * for additional information regarding your rights and obligations. |
||
24 | * |
||
25 | * SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY |
||
26 | * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
27 | * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR |
||
28 | * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR |
||
29 | * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, |
||
30 | * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT |
||
31 | * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, |
||
32 | * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, |
||
33 | * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY |
||
34 | * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), |
||
35 | * OR OTHER SIMILAR COSTS. |
||
36 | * |
||
37 | * Author Date Comment |
||
38 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
39 | * Anton Alkhimenok 11/12/07 Version 1.0 release |
||
40 | *****************************************************************************/ |
||
41 | #ifndef _EDITBOX_H |
||
42 | #define _EDITBOX_H |
||
43 | |||
44 | #include <Graphics\GOL.h> |
||
45 | |||
46 | /********************************************************************* |
||
47 | * Object States Definition: |
||
48 | *********************************************************************/ |
||
49 | #define EB_FOCUSED 0x0001 // Bit for focused state. |
||
50 | #define EB_DISABLED 0x0002 // Bit for disabled state. |
||
51 | #define EB_RIGHT_ALIGN 0x0004 // Bit to indicate text is left aligned. |
||
52 | #define EB_CENTER_ALIGN 0x0008 // Bit to indicate text is center aligned. |
||
53 | #define EB_CARET 0x0010 // Bit to indicate the cursor will be shown when focused. |
||
54 | #define EB_DRAW_CARET 0x2000 // Bit to indicate the cursor must be redrawn. |
||
55 | #define EB_DRAW 0x4000 // Bit to indicate whole edit box must be redrawn. |
||
56 | #define EB_HIDE 0x8000 // Bit to remove object from screen. |
||
57 | #define EB_INDENT 0x02 // Indent for the text from the frame. |
||
58 | #define EB_CARET_WIDTH 0x02 // Caret line width. |
||
59 | |||
60 | /********************************************************************* |
||
61 | * Overview: Defines the parameters required for a Edit Box Object. |
||
62 | *********************************************************************/ |
||
63 | typedef struct |
||
64 | { |
||
65 | OBJ_HEADER hdr; // Generic header for all Objects (see OBJ_HEADER). |
||
66 | SHORT textHeight; // Pre-computed text height. |
||
67 | XCHAR *pBuffer; // Pointer to text buffer. |
||
68 | WORD charMax; // Maximum number of characters in the edit box. |
||
69 | WORD length; // Current text length. |
||
70 | } EDITBOX; |
||
71 | |||
72 | /********************************************************************* |
||
73 | * Function: EDITBOX *EbCreate(WORD ID, SHORT left, SHORT top, SHORT right, SHORT bottom, |
||
74 | * WORD state , XCHAR *pText, WORD charMax, GOL_SCHEME *pScheme) |
||
75 | * |
||
76 | * Overview: This function creates a EDITBOX object with the parameters given and |
||
77 | * initializes the default settings. It automatically attaches the new |
||
78 | * object into a global linked list of objects and returns the address |
||
79 | * of the object. |
||
80 | * |
||
81 | * PreCondition: none |
||
82 | * |
||
83 | * Input: ID - Unique user defined ID for the object instance. |
||
84 | * left - Left most position of the Object. |
||
85 | * top - Top most position of the Object. |
||
86 | * right - Right most position of the Object. |
||
87 | * bottom - Bottom most position of the object. |
||
88 | * state - Sets the initial state of the object. |
||
89 | * pText - Pointer to the text to be used. |
||
90 | * charMax - Defines the maximum number of characters in the edit box. |
||
91 | * pScheme - Pointer to the style scheme. |
||
92 | * |
||
93 | * Output: Returns the pointer to the object created. |
||
94 | * |
||
95 | * Example: |
||
96 | * <CODE> |
||
97 | * #define ID_MYEDITBOX 101 |
||
98 | * EDITBOX *pEb; |
||
99 | * |
||
100 | * pEb = EbCreate(ID_MYEDITBOX, // ID |
||
101 | * 10, // left |
||
102 | * 10, // top |
||
103 | * 100, // right |
||
104 | * 30, // bottom |
||
105 | * EB_DRAW, // redraw after creation |
||
106 | * NULL, // no text yet |
||
107 | * 4, // display only four characters |
||
108 | * pScheme); // pointer to the style scheme |
||
109 | * |
||
110 | * if( pEb == NULL ) |
||
111 | * { |
||
112 | * // MEMORY ERROR. Object was not created. |
||
113 | * } |
||
114 | * |
||
115 | * </CODE> |
||
116 | * |
||
117 | * Side Effects: none |
||
118 | * |
||
119 | ********************************************************************/ |
||
120 | EDITBOX *EbCreate |
||
121 | ( |
||
122 | WORD ID, |
||
123 | SHORT left, |
||
124 | SHORT top, |
||
125 | SHORT right, |
||
126 | SHORT bottom, |
||
127 | WORD state, |
||
128 | XCHAR *pText, |
||
129 | WORD charMax, |
||
130 | GOL_SCHEME *pScheme |
||
131 | ); |
||
132 | |||
133 | /********************************************************************* |
||
134 | * Function: EbSetText(EDITBOX *pEb, XCHAR *pText) |
||
135 | * |
||
136 | * Overview: This function sets the text to be used for the object. |
||
137 | * |
||
138 | * PreCondition: none |
||
139 | * |
||
140 | * Input: pEb - The pointer to the object whose text will be modified. |
||
141 | * pText - Pointer to the text that will be used. |
||
142 | * |
||
143 | * Output: none |
||
144 | * |
||
145 | * Side Effects: none |
||
146 | * |
||
147 | ********************************************************************/ |
||
148 | void EbSetText(EDITBOX *pEb, XCHAR *pText); |
||
149 | |||
150 | /********************************************************************* |
||
151 | * Macros: EbGetText(pEb) |
||
152 | * |
||
153 | * Overview: This macro returns the address of the current |
||
154 | * text string used for the object. |
||
155 | * |
||
156 | * PreCondition: none |
||
157 | * |
||
158 | * Input: pEb - Pointer to the object |
||
159 | * |
||
160 | * Output: Returns pointer to the text string being used. |
||
161 | * |
||
162 | * Side Effects: none |
||
163 | * |
||
164 | ********************************************************************/ |
||
165 | #define EbGetText(pEb) (pEb->pBuffer) |
||
166 | |||
167 | /********************************************************************* |
||
168 | * Function: void EbAddChar(EDITBOX* pEb, XCHAR ch) |
||
169 | * |
||
170 | * Overview: This function inserts a character at the end of the |
||
171 | * text used by the object. |
||
172 | * |
||
173 | * PreCondition: none |
||
174 | * |
||
175 | * Input: pEb - The pointer to the object whose text will be modified. |
||
176 | * ch - Character to be inserted. |
||
177 | * |
||
178 | * Output: none |
||
179 | * |
||
180 | * Side Effects: none |
||
181 | * |
||
182 | ********************************************************************/ |
||
183 | void EbAddChar(EDITBOX *pEb, XCHAR ch); |
||
184 | |||
185 | /********************************************************************* |
||
186 | * Function: void EbDeleteChar(EDITBOX* pEb) |
||
187 | * |
||
188 | * Overview: This function removes a character at the end of the |
||
189 | * text used by the object. |
||
190 | * |
||
191 | * PreCondition: none |
||
192 | * |
||
193 | * Input: pEb - The pointer to the object to be modified. |
||
194 | * |
||
195 | * Output: none |
||
196 | * |
||
197 | * Side Effects: none |
||
198 | * |
||
199 | ********************************************************************/ |
||
200 | void EbDeleteChar(EDITBOX *pEb); |
||
201 | |||
202 | /********************************************************************* |
||
203 | * Function: WORD EbTranslateMsg(EDITBOX *pEb, GOL_MSG *pMsg) |
||
204 | * |
||
205 | * Overview: This function evaluates the message from a user if the |
||
206 | * message will affect the object or not. The table below enumerates the translated |
||
207 | * messages for each event of the touch screen and keyboard inputs. |
||
208 | * |
||
209 | * <TABLE> |
||
210 | * Translated Message Input Source Events Description |
||
211 | * ################## ############ ###### ########### |
||
212 | * EB_MSG_CHAR Keyboard EVENT_CHARCODE New character should be added. |
||
213 | * EB_MSG_DEL Keyboard EVENT_KEYPRESS Last character should be removed. |
||
214 | * OBJ_MSG_INVALID Any Any If the message did not affect the object. |
||
215 | * </TABLE> |
||
216 | * |
||
217 | * PreCondition: none |
||
218 | * |
||
219 | * Input: pEb - The pointer to the object where the message will be |
||
220 | * evaluated to check if the message will affect the object. |
||
221 | * pMsg - Pointer to the message struct containing the message from |
||
222 | * the user interface. |
||
223 | * |
||
224 | * Output: Returns the translated message depending on the received GOL message: |
||
225 | * - EB_MSG_CHAR New character should be added. |
||
226 | * - EB_MSG_DEL Last character should be removed. |
||
227 | * - OBJ_MSG_INVALID Object is not affected. |
||
228 | * |
||
229 | * Example: |
||
230 | * Usage is similar to BtnTranslateMsg() example. |
||
231 | * |
||
232 | * Side Effects: none |
||
233 | * |
||
234 | ********************************************************************/ |
||
235 | WORD EbTranslateMsg(EDITBOX *pEb, GOL_MSG *pMsg); |
||
236 | |||
237 | /********************************************************************* |
||
238 | * Function: void EbMsgDefault(WORD translatedMsg, EDITBOX *pEb, GOL_MSG *pMsg) |
||
239 | * |
||
240 | * Overview: This function performs the actual state change |
||
241 | * based on the translated message given. The following state changes |
||
242 | * are supported: |
||
243 | * <TABLE> |
||
244 | * Translated Message Input Source Set/Clear State Bit Description |
||
245 | * ################## ############ ###### ########### |
||
246 | * EB_MSG_CHAR Keyboard Set EB_DRAW New character is added and Edit Box will be redrawn. |
||
247 | * EB_MSG_DEL Keyboard Set EB_DRAW Last character is removed and Edit Box will be redrawn. |
||
248 | * </TABLE> |
||
249 | * |
||
250 | * PreCondition: none |
||
251 | * |
||
252 | * Input: translatedMsg - The translated message. |
||
253 | * pEb - The pointer to the object whose state will be modified. |
||
254 | * pMsg - The pointer to the GOL message. |
||
255 | * |
||
256 | * Output: none |
||
257 | * |
||
258 | * Example: |
||
259 | * Usage is similar to BtnMsgDefault() example. |
||
260 | * |
||
261 | * Side Effects: none |
||
262 | * |
||
263 | ********************************************************************/ |
||
264 | void EbMsgDefault(WORD translatedMsg, EDITBOX *pEb, GOL_MSG *pMsg); |
||
265 | |||
266 | /********************************************************************* |
||
267 | * Function: WORD EbDraw(EDITBOX *pEb) |
||
268 | * |
||
269 | * Overview: This function renders the object on the screen using |
||
270 | * the current parameter settings. Location of the object is |
||
271 | * determined by the left, top, right and bottom parameters. |
||
272 | * The colors used are dependent on the state of the object. |
||
273 | * The font used is determined by the style scheme set. |
||
274 | * |
||
275 | * When rendering objects of the same type, each object |
||
276 | * must be rendered completely before the rendering of the |
||
277 | * next object is started. This is to avoid incomplete |
||
278 | * object rendering. |
||
279 | * |
||
280 | * PreCondition: Object must be created before this function is called. |
||
281 | * |
||
282 | * Input: pEb - Pointer to the object to be rendered. |
||
283 | * |
||
284 | * Output: Returns the status of the drawing |
||
285 | * - 1 - If the rendering was completed and |
||
286 | * - 0 - If the rendering is not yet finished. |
||
287 | * |
||
288 | * Next call to the function will resume the |
||
289 | * rendering on the pending drawing state. |
||
290 | * |
||
291 | * Side Effects: none |
||
292 | * |
||
293 | ********************************************************************/ |
||
294 | WORD EbDraw(EDITBOX *pEb); |
||
295 | #endif // _EDITBOX_H |
Powered by WebSVN v2.8.3