eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4d_combo_box.c
Go to the documentation of this file.
1 /**************************************************************************
2 *
3 * Copyright 2014 by Petr Gargulak. eGUI Community.
4 * Copyright 2009-2013 by Petr Gargulak. Freescale Semiconductor, Inc.
5 *
6 ***************************************************************************
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License Version 3
9 * or later (the "LGPL").
10 *
11 * As a special exception, the copyright holders of the eGUI project give you
12 * permission to link the eGUI sources with independent modules to produce an
13 * executable, regardless of the license terms of these independent modules,
14 * and to copy and distribute the resulting executable under terms of your
15 * choice, provided that you also meet, for each linked independent module,
16 * the terms and conditions of the license of that module.
17 * An independent module is a module which is not derived from or based
18 * on this library.
19 * If you modify the eGUI sources, you may extend this exception
20 * to your version of the eGUI sources, but you are not obligated
21 * to do so. If you do not wish to do so, delete this
22 * exception statement from your version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 *
28 * You should have received a copy of the GNU General Public License
29 * and the GNU Lesser General Public License along with this program.
30 * If not, see <http://www.gnu.org/licenses/>.
31 *
32 ***************************************************************************/
46 #include "d4d.h"
48 
49 //Internal API
50 static void D4D_ComboBoxOnMessage(D4D_MESSAGE* pMsg);
51 static void D4D_ComboBoxStornoSelection(D4D_OBJECT * pThis);
52 
53 /*******************************************************
54 *
55 * Button arrow of
56 *
57 *******************************************************/
58 /* D4D array declaration */
59 const Byte arrow[];
61 /* End of D4D array declaration - DO NOT MODIFY */
62 
63 /* D4D bitmap definition */
65 /* End of D4D bitmap definition - DO NOT MODIFY */
66 
67 /* Color palette */
68 Word palette_arrow[] = {
69 0xFFFF, 0x0000
70 };
71 
72 /* Compression ratio: 50% */
73 const Byte arrow[] = {
74 
75 /* Bitmap dimension (W x H) */
76 0x00, 0x0C, 0x00, 0x06,
77 
78 /* Color mode */
79 0x80, 0x07,
80 
81 /* Data */
82 0x00, 0x00, 0x0B, 0x01, 0x01, 0x08, 0x00, 0x00, 0x01, 0x01, 0x01, 0x06, 0x00, 0x00, 0x03, 0x01,
83 0x01, 0x04, 0x00, 0x00, 0x05, 0x01, 0x01, 0x02, 0x00, 0x00, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00,
84 0x03
85 };
86 
88 {
89  D4D_DEFSTR("Combo Box"),
91  NULL,
92  NULL
93 };
94 
96 {
100  D4D_BEVEL_WIDTH
101 };
102 
103 // temporary structure for comboBox temporary value calculation
104 typedef struct
105 {
107  D4D_SIZE size;
108  D4D_POINT contentPos;
109  D4D_SIZE contentSize;
110  D4D_COOR textOff;
111 } D4D_COMBO_BOX_TMP_VAL;
112 
113 #define _calc (*((D4D_COMBO_BOX_TMP_VAL*)d4d_scratchPad))
114 
115 /*******************************************************
116 *
117 * COMBO_BOX Child Object CallBack function from list box
118 *
119 *******************************************************/
121 {
122  D4D_OBJECT *pParent = D4D_GetParentObject(pMsg->pObject);
123  if((((pMsg->nMsgId == D4D_MSG_KILLFOCUS) || (pMsg->nMsgId == D4D_MSG_MOUSE_LEAVE)) && !D4D_IsMineFocus(pParent)))
124  {
126  }
127 
128  return D4D_MSG_NOSKIP;
129 }
130 
132 {
133  D4D_OBJECT* pParent = D4D_GetParentObject(pThis);
134 
135  if(eventId == D4D_EVENT_ONCLICK)
136  {
137  D4D_OBJECT* pListBoxObject = D4D_GET_COMBO_BOX_LIST_BOX(pParent);
138  D4D_OBJECT* pEditBoxObject = D4D_GET_COMBO_BOX_EDIT_BOX(pParent);
139 
140  D4D_GET_COMBO_BOX_DATA(pParent)->real_ix = D4D_ListBoxGetIndex(pListBoxObject);
141 
142  if(D4D_GET_COMBO_BOX(pParent)->OnEvent)
143  D4D_GET_COMBO_BOX(pParent)->OnEvent(pParent, D4D_EVENT_ONCLICK);
144 
145  D4D_EditBoxClearAll(pEditBoxObject);
146  D4D_EditBoxPutString(pEditBoxObject, D4D_ListBoxGetItemText(pListBoxObject));
147 
148  D4D_ShowObject(pListBoxObject, D4D_FALSE);
150  }
151 
152  if(eventId == D4D_EVENT_ONCHANGE)
153  {
154  //D4D_InvalidateObject(pParent, D4D_FALSE);
155 
156  if(D4D_GET_COMBO_BOX(pParent)->OnEvent)
157  D4D_GET_COMBO_BOX(pParent)->OnEvent(pParent, D4D_EVENT_ONCHANGE);
158  }
159 }
160 
161 
162 /*******************************************************
163 *
164 * COMBO_BOX Child Object CallBack function from edit box
165 *
166 *******************************************************/
168 {
169  D4D_OBJECT* pParent = D4D_GetParentObject(pThis);
170 
171  D4D_GET_COMBO_BOX(pParent)->pData->real_ix = -1;
172 
173  if(eventId == D4D_EVENT_ONCHANGEDONE)
174  {
177 
178  for(j=0; j<i;j++)
179  {
181  {
182  //hit - the edit box text is same as in list of items
183  D4D_GET_COMBO_BOX(pParent)->pData->real_ix = j;
184  break;
185  }
186  }
187  }
188 }
189 
190 
191 /*******************************************************
192 *
193 * COMBO_BOX Child Object CallBack function from button
194 *
195 *******************************************************/
197 {
198  if(pMsg->nMsgId == D4D_MSG_DRAW && bmp_arrow.pParam)
199  {
200  D4D_COLOR color = D4D_ObjectGetBckgColor(pMsg->pObject, pMsg->prm.draw);
201 
202  ((Word*)(bmp_arrow.pParam))[0] = D4D_COLOR_RGB565(D4D_COLOR_GET_R(color), D4D_COLOR_GET_G(color), D4D_COLOR_GET_B(color));
203 
204  color = D4D_ObjectGetForeColor(pMsg->pObject, pMsg->prm.draw);
205 
206  ((Word*)(bmp_arrow.pParam))[1] = D4D_COLOR_RGB565(D4D_COLOR_GET_R(color), D4D_COLOR_GET_G(color), D4D_COLOR_GET_B(color));
207  }
208 
209  return D4D_MSG_NOSKIP;
210 }
211 
212 // Combo Box Button on click event call back
213 
215 {
216  D4D_OBJECT* pParent = D4D_GetParentObject(pThis);
217  D4D_OBJECT* pListBoxObject = D4D_GET_COMBO_BOX_LIST_BOX(pParent);
218 
219  if(D4D_IsVisible(pListBoxObject))
220  {
222  }else
223  {
224  D4D_ShowObject(pListBoxObject, D4D_TRUE);
225  D4D_CaptureKeys(pListBoxObject);
226  D4D_InvalidateObject(pParent, D4D_TRUE);
227  }
228 }
229 
230 /*******************************************************
231 *
232 * The COMBO_BOX Get index function
233 *
234 *******************************************************/
235 
237 {
238  D4D_COMBO_BOX* pComboBox = D4D_GET_COMBO_BOX(pThis);
239 
240  if(pThis == NULL)
241  return 0;
242 
243  return pComboBox->pData->real_ix;
244 }
245 
246 /*******************************************************
247 *
248 * The COMBO_BOX Set index function
249 *
250 *******************************************************/
251 
253 {
254  D4D_COMBO_BOX* pComboBox = D4D_GET_COMBO_BOX(pThis);
255 
256  if(pThis == NULL)
257  return;
258 
259  if(pComboBox->pData->real_ix == ix)
260  return;
261 
262  if(ix != -1)
263  {
266  }else
267  {
268  pComboBox->pData->real_ix = -1;
269 
270  if(pComboBox->OnEvent)
271  pComboBox->OnEvent(pThis, D4D_EVENT_ONCHANGE);
272  }
273 
274 
275 }
276 
277 
278 /**************************************************************/
289 {
290  D4D_OBJECT* pListBoxObject = D4D_GET_COMBO_BOX_LIST_BOX(pThis);
291 
292  if(D4D_IsVisible(pListBoxObject))
293  {
294  D4D_ShowObject(pListBoxObject, D4D_FALSE);
295  D4D_InvalidateScreen(pThis->pData->pScreen, D4D_TRUE); //TODO
296  }
297 
298  D4D_ListBoxSetIndex(pListBoxObject, D4D_GET_COMBO_BOX_DATA(pThis)->real_ix);
299 
300 }
301 
302 /*******************************************************
303 *
304 * The COMBO_BOX message handler
305 *
306 *******************************************************/
307 
309 {
310  switch(pMsg->nMsgId)
311  {
312  case D4D_MSG_ONINIT:
313  {
314  D4D_OBJECT* pListBoxObject = D4D_GET_COMBO_BOX_LIST_BOX(pMsg->pObject);
315  D4D_OBJECT* pEditBoxObject = D4D_GET_COMBO_BOX_EDIT_BOX(pMsg->pObject);
316 
318 
319  D4D_GET_COMBO_BOX_DATA(pMsg->pObject)->real_ix = D4D_ListBoxGetIndex(pListBoxObject);
320  D4D_EditBoxClearAll(pEditBoxObject);
321  D4D_EditBoxPutString(pEditBoxObject, D4D_ListBoxGetItemText(pListBoxObject));
322  }
323 
324  break;
325 
326  default:
327  // call the default behavior of all objects
328  D4D_ObjOnMessage(pMsg);
329  }
330 }
D4D_COLOR D4D_ObjectGetBckgColor(D4D_OBJECT *pObj, D4D_OBJECT_DRAWFLAGS draw)
Function return object current background color.
Definition: d4d_scheme.c:185
static void D4D_ComboBoxOnMessage(D4D_MESSAGE *pMsg)
D4D_BOOL D4D_IsMineFocus(D4D_OBJECT *pObject)
Function find out if the object (including compounded objects) is focused.
Definition: d4d_object.c:348
D4D_OBJECT * D4D_GetParentObject(D4D_OBJECT *pObject)
Definition: d4d_object.c:498
#define D4D_COLOR_RGB565(R, G, B)
The macro create the color from the color component Red/Green/Blue to 16-bit RGB565 format (the input...
Definition: d4d_scheme.h:301
D4D_COLOR D4D_ObjectGetForeColor(D4D_OBJECT *pObj, D4D_OBJECT_DRAWFLAGS draw)
Function return object current fore color.
Definition: d4d_scheme.c:161
const D4D_OBJECT_SYS_FUNCTION d4d_comboBoxSysFunc
Definition: d4d_combo_box.c:87
void D4D_InvalidateScreen(const D4D_SCREEN *pScreen, D4D_BOOL bComplete)
The function mark the screen and its abject as &quot;redraw pending&quot;.
Definition: d4d_screen.c:238
#define D4D_COLOR_GET_B(color)
Definition: d4d_scheme.h:438
Byte D4D_ComboBoxButtonMsgFeedBack(D4D_MESSAGE *pMsg)
struct D4D_SCREEN_S * pScreen
pointer to object screen owner - it is placed in RAM bacause one object could be used in multiply scr...
Definition: d4d_object.h:146
Type definition of eGUI point structure.
Definition: d4d_types.h:223
On Init message - is send for first time when the object is inicialized.
Definition: d4d_base.h:370
D4D object messages structure.
Definition: d4d_base.h:400
D4D_OBJECT_DATA_PTR pData
Pointer on runtime object data.
Definition: d4d_object.h:180
#define D4D_GET_COMBO_BOX(pObj)
static void D4D_ComboBoxStornoSelection(D4D_OBJECT *pThis)
#define D4D_FALSE
This is definition of boolean operation value in eGUI - FALSE.
Definition: d4d_types.h:104
void D4D_ComboBoxEditFeedBack(D4D_OBJECT *pThis, D4D_EVENTID eventId)
void D4D_ComboBoxButtonFeedBack(D4D_OBJECT *pThis)
const Byte arrow[]
Definition: d4d_combo_box.c:59
On Change done (complete change is finished.
Definition: d4d_base.h:434
D4D_LIST_BOX_INDEX D4D_COMBO_BOX_INDEX
#define D4D_TRUE
This is definition of boolean operation value in eGUI - TRUE.
Definition: d4d_types.h:106
#define D4D_CompareStringsUniversal(s1, s2)
Definition: d4d_extsrc.h:371
struct D4D_OBJECT_S * pObject
Pointer to object who is receiver of this message. If the receiver is just screen this field must be ...
Definition: d4d_base.h:402
D4D_COMBO_BOX_DATA * pData
D4D Driver main header file.
D4D_OBJECT_FLAGS flags
runtime object flags
Definition: d4d_object.h:145
Byte D4D_ComboBoxListBoxMsgFeedBack(D4D_MESSAGE *pMsg)
D4D_LIST_BOX_INDEX D4D_ListBoxGetIndex(D4D_OBJECT *pThis)
Function returns the current selected item index.
Definition: d4d_list_box.c:516
D4D Driver private header file.
void D4D_ComboBoxListFeedBack(D4D_OBJECT *pThis, D4D_EVENTID eventId)
#define D4D_DEFSTR(str)
Macro that helps declare the strings in eGUI.
Definition: d4d_string.h:246
D4D_CMBBX_ON_EVENT OnEvent
Byte D4D_COOR
Type definition of eGUI coordination variables.
Definition: d4d_types.h:219
#define D4D_ComboBoxGetItemCount(pThis)
Function gets the count of combo box items.
unsigned char Byte
Type definition of Byte (unsigned 8-bit).
Definition: d4d_types.h:151
void D4D_ObjOnMessage(D4D_MESSAGE *pMsg)
Definition: d4d_object.c:443
Word palette_arrow[]
Definition: d4d_combo_box.c:60
void D4D_ShowObject(D4D_OBJECT_PTR pObject, D4D_BOOL bShow)
Function control visibility of object on screen.
Definition: d4d_object.c:92
void D4D_ListBoxSetIndex(D4D_OBJECT *pThis, D4D_LIST_BOX_INDEX ix)
Function select new item by index.
Definition: d4d_list_box.c:533
#define NULL
Type definition of null pointer.
Definition: d4d_types.h:184
D4D_EVENTID
D4D events that is handled by object callback functions.
Definition: d4d_base.h:429
#define D4D_ComboBoxGetItemTextIx(pThis, ix)
Function gets the text of item choosed by item index.
void D4D_EditBoxClearAll(D4D_OBJECT_PTR pObj)
The function clear whole edit box data.
Definition: d4d_edit_box.c:621
D4D_LIST_BOX_INDEX real_ix
#define D4D_OBJECT_F_NOTINIT
Definition: d4d_object.h:113
D4D_SIZE size
Screen size (standard screen has full size of physical screen)
Definition: d4d_screen.h:176
D4D_MSGID nMsgId
Type of message.
Definition: d4d_base.h:404
D4D_TCHAR * D4D_EditBoxGetText(D4D_OBJECT_PTR pObj)
The function returns the pointer to the edit box text buffer.
Definition: d4d_edit_box.c:652
#define D4D_GET_COMBO_BOX_EDIT_BOX(pObj)
D4D_BOOL D4D_IsVisible(D4D_OBJECT *pObject)
Function find out if the object is visible or not.
Definition: d4d_object.c:325
The object main structure type definition.
Definition: d4d_object.h:167
void D4D_CaptureKeys(D4D_OBJECT_PTR pObj)
Function switch on capturing the keys to objects.
Definition: d4d_object.c:190
#define D4D_BEVEL_WIDTH
D4D_BEVEL_WIDTH constant declaration - can&#39;t be changed!
Draw message - is send when the object should be redrawed.
Definition: d4d_base.h:371
The return value of user/application message function - continue handling of message by eGUI...
Definition: d4d_base.h:418
const D4D_MARGIN comboBox_marginDefault
Definition: d4d_combo_box.c:95
D4D_TCHAR * D4D_ListBoxGetItemText(D4D_OBJECT_PTR pThis)
Function gets the selected item text.
Definition: d4d_list_box.c:607
D4D_DECLARE_BMP(bmp_arrow, arrow, palette_arrow)
Definition: d4d_combo_box.c:64
The object system function needed for each object - this is part of D4D_OBJECT main structure...
Definition: d4d_object.h:134
D4D_POINT position
Screen coordination on physical screen (standard screen has {0,0})
Definition: d4d_screen.h:175
void D4D_ComboBoxSetIndex(D4D_OBJECT *pThis, D4D_COMBO_BOX_INDEX ix)
Type definition of eGUI size structure.
Definition: d4d_types.h:230
#define D4D_COLOR_GET_G(color)
Definition: d4d_scheme.h:437
D4D_BOOL D4D_EditBoxPutString(D4D_OBJECT_PTR pObj, D4D_TCHAR *pText)
The function puts string on cursor position and updates cursor.
Definition: d4d_edit_box.c:455
D4D_OBJECT_DRAWFLAGS draw
Contains draw flags - is valid with D4D_MSG_DRAW and D4D_MSG_DRAWDONE message.
Definition: d4d_base.h:408
On Click Event.
Definition: d4d_base.h:431
On Change Event.
Definition: d4d_base.h:433
void D4D_InvalidateObject(D4D_OBJECT_PTR pObject, D4D_BOOL bComplete)
Function invalidate object to redraw on screen.
Definition: d4d_object.c:71
LWord D4D_COLOR
Type definition of eGUI color variables.
Definition: d4d_types.h:262
unsigned short Word
Type definition of Word (unsigned 16-bit).
Definition: d4d_types.h:159
#define D4D_GET_COMBO_BOX_LIST_BOX(pObj)
#define D4D_GET_COMBO_BOX_DATA(pObj)
#define D4D_COLOR_GET_R(color)
Definition: d4d_scheme.h:436
Kill Focus message - is send when the object is losing focus.
Definition: d4d_base.h:374
union D4D_MESSAGE_S::@0 prm
Additional data for some type of messages.
Type definition of eGUI client area margin structure.
Definition: d4d_types.h:244
Mouse Cursor Leave message - is send in case that mouse cursor leave the object area.
Definition: d4d_base.h:392
D4D_COMBO_BOX_INDEX D4D_ComboBoxGetIndex(D4D_OBJECT *pThis)