?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /*****************************************************************************
2 * Module for Microchip Graphics Library
3 * GOL Layer
4 * Edit Box
5 *****************************************************************************
6 * FileName: EditBox.c
7 * Dependencies: None
8 * Processor: PIC24F, PIC24H, dsPIC, PIC32
9 * Compiler: MPLAB C30 V3.00, C32
10 * Linker: MPLAB LINK30, 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 #include "Graphics\Graphics.h"
42  
43 #ifdef USE_EDITBOX
44  
45 /*********************************************************************
46 * Function: EDITBOX *EbCreate(WORD ID, SHORT left, SHORT top, SHORT right, SHORT bottom,
47 * WORD state , XCHAR *pText, WORD charMax, GOL_SCHEME *pScheme)
48 *
49 * Notes: Create the EDITBOX Object.
50 *
51 ********************************************************************/
52 EDITBOX *EbCreate(WORD ID, SHORT left, SHORT top, SHORT right, SHORT bottom,
53 WORD state , XCHAR *pText, WORD charMax, GOL_SCHEME *pScheme){
54  
55 EDITBOX *pEb = NULL;
56  
57 pEb = (EDITBOX*)GFX_malloc(sizeof(EDITBOX)+ (charMax + 1)*sizeof(XCHAR)); // ending zero is not included into charMax
58 if (pEb == NULL)
59 return pEb;
60  
61 pEb->pBuffer = (XCHAR*)((BYTE*)pEb+sizeof(EDITBOX));
62 *pEb->pBuffer = 0;
63 pEb->length = 0;
64 pEb->charMax = charMax;
65  
66 if(pText != NULL)
67 EbSetText(pEb, pText);
68  
69 pEb->hdr.ID = ID;
70 pEb->hdr.pNxtObj = NULL;
71 pEb->hdr.type = OBJ_EDITBOX;
72 pEb->hdr.left = left;
73 pEb->hdr.top = top;
74 pEb->hdr.right = right;
75 pEb->hdr.bottom = bottom;
76 pEb->hdr.state = state;
77  
78 // Set the style scheme to be used
79 if (pScheme == NULL)
80 pEb->hdr.pGolScheme = _pDefaultGolScheme;
81 else
82 pEb->hdr.pGolScheme = (GOL_SCHEME *)pScheme;
83  
84 pEb->textHeight = GetTextHeight(pEb->hdr.pGolScheme->pFont);
85  
86 GOLAddObject((OBJ_HEADER*) pEb);
87 return pEb;
88 }
89  
90 /*********************************************************************
91 * Function: EbSetText(EDITBOX *pEb, XCHAR *pText)
92 *
93 * Notes: Sets a new text.
94 *
95 ********************************************************************/
96 void EbSetText(EDITBOX *pEb, XCHAR *pText){
97 WORD ch;
98 WORD length;
99 XCHAR* pointerFrom;
100 XCHAR* pointerTo;
101  
102 // Copy and count length
103 pointerFrom = pText;
104 pointerTo = pEb->pBuffer;
105 length = 0;
106  
107 do{
108 ch = *pointerFrom++;
109 *pointerTo++ = ch;
110 length++;
111 if(length >= pEb->charMax){
112 *pointerTo = 0;
113 break;
114 }
115 }while(ch);
116  
117  
118 pEb->length = length-1;
119 }
120  
121 /*********************************************************************
122 * Function: void EbAddChar(EDITBOX* pEb, XCHAR ch)
123 *
124 * Notes: Adds character at the end.
125 *
126 ********************************************************************/
127 void EbAddChar(EDITBOX* pEb, XCHAR ch){
128  
129 if(pEb->length >= pEb->charMax)
130 return;
131  
132 // Add character
133 pEb->pBuffer[pEb->length] = ch;
134 pEb->length++;
135 pEb->pBuffer[pEb->length] = 0;
136 }
137  
138 /*********************************************************************
139 * Function: void EbDeleteChar(EDITBOX* pEb)
140 *
141 * Notes: Deletes character at the end.
142 *
143 ********************************************************************/
144 void EbDeleteChar(EDITBOX* pEb){
145  
146 if(pEb->length == 0)
147 return;
148  
149 // Delete charachter
150 pEb->length--;
151 pEb->pBuffer[pEb->length] = 0;
152  
153 }
154  
155 /*********************************************************************
156 * Function: WORD StTranslateMsg(EDITBOX *pEb, GOL_MSG *pMsg)
157 *
158 * Notes: Translates GOL message for the edit box
159 *
160 ********************************************************************/
161 WORD EbTranslateMsg(EDITBOX *pEb, GOL_MSG *pMsg)
162 {
163 // Evaluate if the message is for the edit box
164 // Check if disabled first
165 if (GetState(pEb, EB_DISABLED))
166 return OBJ_MSG_INVALID;
167  
168 #ifdef USE_FOCUS
169 #ifdef USE_TOUCHSCREEN
170 if(pMsg->type == TYPE_TOUCHSCREEN) {
171 // Check if it falls in edit box borders
172 if( (pEb->hdr.left < pMsg->param1) &&
173 (pEb->hdr.right > pMsg->param1) &&
174 (pEb->hdr.top < pMsg->param2) &&
175 (pEb->hdr.bottom > pMsg->param2) )
176 return EB_MSG_TOUCHSCREEN;
177  
178 return OBJ_MSG_INVALID;
179 }
180 #endif
181 #endif
182  
183 #ifdef USE_KEYBOARD
184 if(pMsg->type == TYPE_KEYBOARD) {
185  
186 if(pMsg->uiEvent == EVENT_CHARCODE)
187 return EB_MSG_CHAR;
188  
189 if(pMsg->uiEvent == EVENT_KEYSCAN)
190 if(pMsg->param2 == SCAN_BS_PRESSED)
191 return EB_MSG_DEL;
192  
193 return OBJ_MSG_INVALID;
194 }
195 #endif
196  
197  
198 return OBJ_MSG_INVALID;
199 }
200  
201 /*********************************************************************
202 * Function: void EbMsgDefault(WORD translatedMsg, EDITBOX *pEb, GOL_MSG *pMsg)
203 *
204 * Notes: Changes the state of the edit box by default.
205 *
206 ********************************************************************/
207 void EbMsgDefault(WORD translatedMsg, EDITBOX *pEb, GOL_MSG *pMsg){
208  
209 #ifdef USE_FOCUS
210 #ifdef USE_TOUCHSCREEN
211 if(pMsg->type == TYPE_TOUCHSCREEN){
212 if(!GetState(pEb,BTN_FOCUSED)){
213 GOLSetFocus((OBJ_HEADER*)pEb);
214 }
215 }
216 #endif
217 #endif
218  
219 switch(translatedMsg){
220  
221 case EB_MSG_CHAR:
222 EbAddChar(pEb,(XCHAR)pMsg->param2);
223 SetState(pEb, EB_DRAW);
224 break;
225  
226 case EB_MSG_DEL:
227 EbDeleteChar(pEb);
228 SetState(pEb, EB_DRAW);
229 break;
230  
231 }
232 }
233  
234 /*********************************************************************
235 * Function: WORD EbDraw(EDITBOX *pEb)
236 *
237 * Notes: This is the state machine to draw the button.
238 *
239 ********************************************************************/
240 WORD EbDraw(EDITBOX *pEb)
241 {
242 typedef enum {
243 EB_STATE_START,
244 EB_STATE_PANEL,
245 EB_STATE_TEXT,
246 EB_STATE_CARET,
247 } EB_DRAW_STATES;
248  
249 static EB_DRAW_STATES state = EB_STATE_START;
250 static XCHAR* pText;
251 SHORT temp;
252 SHORT width = 0;
253  
254  
255 if(IsDeviceBusy())
256 return 0;
257  
258 switch(state){
259  
260 case EB_STATE_START:
261  
262 if(GetState(pEb, EB_HIDE)){
263 SetColor(pEb->hdr.pGolScheme->CommonBkColor);
264 if(!Bar(pEb->hdr.left,pEb->hdr.top,pEb->hdr.right,pEb->hdr.bottom)) return 0;
265 return 1;
266 }
267  
268 if(GetState(pEb,EB_DISABLED)){
269 temp = pEb->hdr.pGolScheme->ColorDisabled;
270 ClrState(pEb,EB_CARET);
271 }else{
272 temp = pEb->hdr.pGolScheme->Color0;
273 if(GetState(pEb,EB_DRAW)){
274 if(GetState(pEb,EB_FOCUSED)){
275 SetState(pEb,EB_CARET);
276 }else{
277 ClrState(pEb,EB_CARET);
278 }
279 }
280 }
281  
282 if(GetState(pEb,EB_DRAW)){
283  
284 GOLPanelDraw(pEb->hdr.left,pEb->hdr.top,pEb->hdr.right,pEb->hdr.bottom,0,
285 temp,
286 pEb->hdr.pGolScheme->EmbossDkColor,
287 pEb->hdr.pGolScheme->EmbossLtColor,
288 NULL,
289 GOL_EMBOSS_SIZE);
290  
291 state = EB_STATE_PANEL;
292  
293 case EB_STATE_PANEL:
294  
295 if(!GOLPanelDrawTsk())
296 return 0;
297  
298 }
299  
300 SetClip(CLIP_ENABLE);
301  
302 SetClipRgn(pEb->hdr.left+GOL_EMBOSS_SIZE+EB_INDENT,
303 pEb->hdr.top+GOL_EMBOSS_SIZE+EB_INDENT,
304 pEb->hdr.right-GOL_EMBOSS_SIZE-EB_INDENT,
305 pEb->hdr.bottom-GOL_EMBOSS_SIZE-EB_INDENT);
306  
307 SetFont(pEb->hdr.pGolScheme->pFont);
308  
309 if(GetState(pEb,EB_DISABLED)){
310 SetColor(pEb->hdr.pGolScheme->TextColorDisabled);
311 }else{
312 SetColor(pEb->hdr.pGolScheme->TextColor0);
313 }
314  
315  
316 pText = pEb->pBuffer;
317 temp = 1;
318  
319 while((XCHAR)*pText != (XCHAR)0){
320 if((XCHAR)*pText == (XCHAR)'\n')
321 temp++;
322 pText++;
323 }
324  
325 pText = pEb->pBuffer;
326 MoveTo(GetX(),(pEb->hdr.top+pEb->hdr.bottom-temp*pEb->textHeight)>>1);
327  
328  
329 do{
330 width = GetTextWidth(pText,pEb->hdr.pGolScheme->pFont);
331  
332 if (!GetState(pEb, EB_CENTER_ALIGN|EB_RIGHT_ALIGN)) {
333 MoveTo(pEb->hdr.left+GOL_EMBOSS_SIZE+EB_INDENT, GetY());
334 }else{
335 if (GetState(pEb, EB_RIGHT_ALIGN)) {
336 MoveTo(pEb->hdr.right-width-EB_INDENT-GOL_EMBOSS_SIZE, GetY());
337 }else{
338 MoveTo((pEb->hdr.left+pEb->hdr.right-width)>>1,GetY());
339 }
340 }
341  
342 state = EB_STATE_TEXT;
343  
344 case EB_STATE_TEXT:
345 if(GetState(pEb,EB_DRAW)){
346 if(!OutText(pText))
347 return 0;
348 }else{
349 MoveRel(width, 0);
350 }
351 while((XCHAR)*pText>(XCHAR)15)
352 pText++;
353  
354 if((XCHAR)*pText == (XCHAR)'\n')
355 {
356 MoveRel(0, pEb->textHeight);
357 }
358  
359 }while(*pText++ != 0);
360  
361 state = EB_STATE_CARET;
362  
363 case EB_STATE_CARET:
364 if(!GetState(pEb,EB_DISABLED)){
365 if(GetState(pEb,EB_CARET)){
366 SetColor(pEb->hdr.pGolScheme->TextColor0);
367 }else{
368 SetColor(pEb->hdr.pGolScheme->Color0);
369 }
370 if(!Bar(GetX(),GetY(),GetX()+EB_CARET_WIDTH,GetY()+pEb->textHeight)) return 0;
371 }
372  
373 SetClip(CLIP_DISABLE);
374  
375 state = EB_STATE_START;
376  
377 return 1;
378 }
379 return 1;
380 }
381  
382 #endif // USE_EDITBOX
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3