soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SComboBase.h
1#ifndef __SCOMBOBASE__H__
2#define __SCOMBOBASE__H__
3
4#include <core/SWnd.h>
5#include <control/SEdit.h>
6#include <control/SDropDown.h>
7
8SNSBEGIN
9
10#define IDC_CB_EDIT -100
11#define IDC_DROPDOWN_LIST -200
12
13/**
14 * @class SComboEdit
15 * @brief Edit Control Embedded in ComboBox
16 * @details An edit control embedded within a ComboBox.
17 */
18class SOUI_EXP SComboEdit : public SEdit {
19 DEF_SOBJECT(SEdit, L"ComboEdit")
20
21 public:
22 /**
23 * @brief Constructor
24 */
25 SComboEdit();
26
27 /**
28 * @brief Destructor
29 */
30 virtual ~SComboEdit();
31
32 protected:
33 /**
34 * @brief Handle mouse hover event
35 * @param wParam Extra parameters
36 * @param ptPos Mouse position
37 * @details This function is a message handler.
38 */
39 void OnMouseHover(WPARAM wParam, CPoint ptPos);
40
41 /**
42 * @brief Handle mouse leave event
43 * @details This function is a message handler.
44 */
45 void OnMouseLeave();
46
47 /**
48 * @brief Handle key down event
49 * @param nChar Key code
50 * @param nRepCnt Repeat count
51 * @param nFlags Flags
52 * @details This function is a message handler.
53 */
54 void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
55
56 /**
57 * @brief Notify event
58 * @param evt Event object
59 * @return Success--TRUE Failure--FALSE
60 * @details This function is a message handler.
61 */
62 STDMETHOD_(BOOL, FireEvent)(THIS_ IEvtArgs *evt) OVERRIDE;
63
64 /**
65 * @brief Handle kill focus event
66 * @param wndFocus New focus window handle
67 */
68 void OnKillFocus(SWND wndFocus);
69
70 SOUI_MSG_MAP_BEGIN()
71 MSG_WM_MOUSEHOVER(OnMouseHover)
72 MSG_WM_MOUSELEAVE(OnMouseLeave)
73 MSG_WM_KEYDOWN(OnKeyDown)
74 MSG_WM_KILLFOCUS_EX(OnKillFocus)
75 SOUI_MSG_MAP_END()
76};
77
78class SOUI_EXP SDropDownWnd_ComboBox : public SDropDownWnd {
79 public:
80 SDropDownWnd_ComboBox(ISDropDownOwner *pOwner)
81 : SDropDownWnd(pOwner)
82 {
83 }
84
85 virtual BOOL WINAPI PreTranslateMessage(MSG *pMsg);
86};
87
88/**
89 * @class SComboBoxBase
90 * @brief Base ComboBox Control
91 * @details A base class for ComboBox controls that can be editable or dropdown-only.
92 */
93class SOUI_EXP SComboBase
94 : public TWindowProxy<IComboBase>
95 , public ISDropDownOwner {
96 DEF_SOBJECT(SWindow, L"combobase")
97
98 public:
99 /**
100 * @brief Constructor
101 */
102 SComboBase(void);
103
104 /**
105 * @brief Destructor
106 */
107 virtual ~SComboBase(void);
108
109 public:
110 /**
111 * @brief Find string in the list box
112 * @param pszFind String to find
113 * @param nAfter Index after which to start searching
114 * @param bPartMatch Whether to allow partial matches
115 * @return Index of the found string or -1 if not found
116 */
117 STDMETHOD_(int, FindString)
118 (THIS_ LPCTSTR pszFind, int nAfter = -1, BOOL bPartMatch = TRUE) OVERRIDE;
119
120 /**
121 * @brief Find string in the list box (ANSI version)
122 * @param pszFind String to find
123 * @param nAfter Index after which to start searching
124 * @param bPartMatch Whether to allow partial matches
125 * @return Index of the found string or -1 if not found
126 */
127 STDMETHOD_(int, FindStringA)
128 (THIS_ LPCSTR pszFind, int nAfter = -1, BOOL bPartMatch = TRUE) OVERRIDE
129 {
130 SStringT str = S_CA2T(pszFind, CP_UTF8);
131 return FindString(str, nAfter, bPartMatch);
132 }
133
134 /**
135 * @brief Drop down the list box
136 */
137 STDMETHOD_(void, DropDown)(THIS) OVERRIDE;
138
139 /**
140 * @brief Close the dropped list box
141 */
142 STDMETHOD_(void, CloseUp)(THIS) OVERRIDE;
143
144 /**
145 * @brief Check if the list box is dropped down
146 * @return TRUE if dropped down, FALSE otherwise
147 */
148 STDMETHOD_(BOOL, IsDropdown)(THIS) SCONST OVERRIDE;
149
150 /**
151 * @brief Set the dropdown state
152 * @param bDropdown TRUE to drop down, FALSE to close up
153 */
154 STDMETHOD_(void, SetDropdown)(THIS_ BOOL bDropdown) OVERRIDE;
155
156 public:
157 /**
158 * @brief Set the window text
159 * @param pszText Text to set
160 */
161 STDMETHOD_(void, SetWindowText)(LPCTSTR pszText) OVERRIDE;
162
163 /**
164 * @brief Get the desired size of the control
165 * @param psz Output size
166 * @param nParentWid Parent container width
167 * @param nParentHei Parent container height
168 */
169 STDMETHOD_(void, GetDesiredSize)(THIS_ SIZE *psz, int nParentWid, int nParentHei) OVERRIDE;
170
171 /**
172 * @brief Set focus to the control
173 */
174 STDMETHOD_(void, SetFocus)(THIS) OVERRIDE;
175
176 /**
177 * @brief Notify event
178 * @param evt Event object
179 * @return Success--TRUE Failure--FALSE
180 */
181 STDMETHOD_(BOOL, FireEvent)(THIS_ IEvtArgs *evt) OVERRIDE;
182
183 /**
184 * @brief Get dialog code
185 * @return Dialog code
186 */
187 STDMETHOD_(UINT, OnGetDlgCode)(CTHIS) SCONST OVERRIDE;
188
189 /**
190 * @brief Check if the control is focusable
191 * @return TRUE if focusable, FALSE otherwise
192 */
193 STDMETHOD_(BOOL, IsFocusable)(CTHIS) SCONST OVERRIDE;
194
195 /**
196 * @brief Update the position of child controls
197 */
198 STDMETHOD_(void, UpdateChildrenPosition)(THIS) OVERRIDE;
199
200 /**
201 * @brief Get the window text
202 * @param bRawText Whether to get raw text
203 * @return Window text
204 */
205 SStringT GetWindowText(BOOL bRawText = FALSE) OVERRIDE;
206
207 /**
208 * @brief Get the text of a list box item
209 * @param iItem Item index
210 * @param bRawText Whether to get raw text
211 * @return Item text
212 */
213 SStringT GetLBText(int iItem, BOOL bRawText = FALSE);
214
215 protected:
216 /**
217 * @brief Get the owner window
218 * @return Owner window pointer
219 */
220 virtual SWindow *GetDropDownOwner();
221
222 /**
223 * @brief Handle creation of the dropdown window
224 * @param pDropDown Dropdown window pointer
225 */
226 virtual void OnCreateDropDown(SDropDownWnd *pDropDown);
227
228 /**
229 * @brief Handle destruction of the dropdown window
230 * @param pDropDown Dropdown window pointer
231 * @param uCode Message code
232 */
233 virtual void OnDestroyDropDown(SDropDownWnd *pDropDown);
234
235 /**
236 * @brief Handle selection change in the dropdown window
237 */
238 virtual void OnSelChanged();
239
240 protected:
241 /**
242 * @brief Update the dropdown list based on input
243 * @param strInput Input string
244 */
245 void UpdateDropdown(const SStringT &strInput);
246
247 /**
248 * @brief Calculate the popup rectangle
249 * @param nHeight Height of the dropdown window
250 * @param rcPopup Output rectangle for the popup
251 * @return TRUE if successful, FALSE otherwise
252 */
253 BOOL CalcPopupRect(int nHeight, CRect &rcPopup);
254
255 /**
256 * @brief Create the list box
257 * @param xmlNode XML node for the list box
258 * @return TRUE if successful, FALSE otherwise
259 */
260 virtual BOOL CreateListBox(SXmlNode xmlNode) = 0;
261
262 /**
263 * @brief Get the height of the list box
264 * @return Height of the list box
265 */
266 virtual int GetListBoxHeight() = 0;
267
268 /**
269 * @brief Get the rectangle of the dropdown button
270 * @param prc Output rectangle for the button
271 */
272 void GetDropBtnRect(LPRECT prc);
273
274 /**
275 * @brief Create child controls
276 * @param xmlNode XML node for the child controls
277 * @return TRUE if successful, FALSE otherwise
278 */
279 virtual BOOL CreateChildren(SXmlNode xmlNode);
280
281 /**
282 * @brief Get the rectangle of the text
283 * @param pRect Output rectangle for the text
284 */
285 virtual void GetTextRect(LPRECT pRect);
286
287 /**
288 * @brief Handle colorization event
289 * @param cr Color
290 */
291 virtual void OnColorize(COLORREF cr);
292
293 /**
294 * @brief Handle language change event
295 * @return HRESULT
296 */
297 virtual HRESULT OnLanguageChanged();
298
299 /**
300 * @brief Handle scale change event
301 * @param nScale Scale factor
302 */
303 virtual void OnScaleChanged(int nScale);
304
305 /**
306 * @brief Paint the control
307 * @param pRT Rendering target handle
308 */
309 void OnPaint(IRenderTarget *pRT);
310
311 /**
312 * @brief Handle left mouse button down event
313 * @param nFlags Flags
314 * @param pt Mouse coordinates
315 */
316 void OnLButtonDown(UINT nFlags, CPoint pt);
317
318 /**
319 * @brief Handle mouse move event
320 * @param nFlags Flags
321 * @param pt Mouse coordinates
322 */
323 void OnMouseMove(UINT nFlags, CPoint pt);
324
325 /**
326 * @brief Handle mouse leave event
327 */
328 void OnMouseLeave();
329
330 /**
331 * @brief Handle key down event
332 * @param nChar Key code
333 * @param nRepCnt Repeat count
334 * @param nFlags Flags
335 */
336 void OnKeyDown(TCHAR nChar, UINT nRepCnt, UINT nFlags);
337
338 /**
339 * @brief Handle mouse wheel event
340 * @param nFlags Flags
341 * @param zDelta Wheel delta
342 * @param pt Mouse coordinates
343 * @return TRUE if handled, FALSE otherwise
344 */
345 BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
346
347 /**
348 * @brief Handle character input event
349 * @param nChar Character code
350 * @param nRepCnt Repeat count
351 * @param nFlags Flags
352 */
353 void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
354
355 /**
356 * @brief Handle destroy event
357 */
358 void OnDestroy();
359
360 /**
361 * @brief Handle create event
362 * @param lp Creation parameters
363 * @return 0 if successful
364 */
365 int OnCreate(LPVOID);
366
367 /**
368 * @brief Handle kill focus event
369 * @param wndFocus New focus window handle
370 */
371 void OnKillFocus(SWND wndFocus);
372
373 /**
374 * @brief Get the cue text
375 * @param bRawText Whether to get raw text
376 * @return Cue text
377 */
378 SStringT GetCueText(BOOL bRawText = FALSE) const;
379
380 /**
381 * @brief Handle custom attribute "dropDown"
382 * @param strValue Attribute value
383 * @param bLoading Loading flag
384 * @return HRESULT
385 */
386 HRESULT OnAttrDropDown(const SStringW &strValue, BOOL bLoading);
387
388 SOUI_ATTRS_BEGIN()
389 ATTR_CUSTOM(L"dropDown", OnAttrDropDown)
390 ATTR_LAYOUTSIZE(L"dropHeight", m_nDropHeight, TRUE)
391 ATTR_INT(L"curSel", m_iInitSel, FALSE)
392 ATTR_SKIN(L"btnSkin", m_pSkinBtn, TRUE)
393 ATTR_INT(L"animateTime", m_nAnimTime, FALSE)
394 ATTR_INT(L"autoFitDropBtn", m_bAutoFitDropBtn, TRUE)
395 ATTR_COLOR(L"cueColor", m_crCue, TRUE)
396 ATTR_I18NSTRT(L"cueText", m_strCue, TRUE)
397 ATTR_BOOL(L"autoMatch", m_bAutoMatch, FALSE)
398 ATTR_BOOL(L"autoDropdown", m_bAutoDropdown, FALSE)
399 SOUI_ATTRS_END()
400
401 SOUI_MSG_MAP_BEGIN()
402 MSG_WM_PAINT_EX(OnPaint)
403 MSG_WM_LBUTTONDOWN(OnLButtonDown)
404 MSG_WM_MOUSEMOVE(OnMouseMove)
405 MSG_WM_MOUSELEAVE(OnMouseLeave)
406 MSG_WM_MOUSEWHEEL(OnMouseWheel)
407 MSG_WM_KEYDOWN(OnKeyDown)
408 MSG_WM_CHAR(OnChar)
409 MSG_WM_DESTROY(OnDestroy)
410 MSG_WM_CREATE(OnCreate)
411 MSG_WM_KILLFOCUS_EX(OnKillFocus)
412 SOUI_MSG_MAP_END()
413
414 protected:
415 /**
416 * @brief Get the text from the edit control
417 * @return Edit control text
418 */
419 SStringT GetEditText() const
420 {
421 if (!m_bDropdown)
422 {
423 return m_pEdit->GetWindowText();
424 }
425 else
426 {
427 return SStringT();
428 }
429 }
430
431 SEdit *m_pEdit; /**< Edit control pointer */
432 DWORD m_dwBtnState; /**< Button state */
433 SAutoRefPtr<ISkinObj> m_pSkinBtn; /**< Button skin object */
434
435 BOOL m_bDropdown; /**< Editable or dropdown-only */
436 SLayoutSize m_nDropHeight; /**< Dropdown height */
437 int m_nAnimTime; /**< Animation time */
438 int m_iInitSel; /**< Initial selection index */
439 SDropDownWnd *m_pDropDownWnd; /**< Dropdown window pointer */
440 SXmlDoc m_xmlDropdownStyle; /**< Dropdown style XML document */
441 BOOL m_bAutoFitDropBtn; /**< Auto-fit dropdown button size */
442 COLORREF m_crCue; /**< Cue text color */
443 STrText m_strCue; /**< Cue text */
444
445 SStringT m_strMatch; /**< Quick input to locate items in the dropdown list */
446 DWORD m_LastPressTime; /**< Last key press time */
447 BOOL m_bAutoMatch; /**< Automatically match from the dropdown list on edit input */
448 BOOL m_bAutoDropdown; /**< Automatically update the dropdown list on edit input */
449 int m_nTextLength;
450};
451
452template <class T>
453class TComboBaseProxy
454 : public T
455 , public SComboBase {
456 public:
457 STDMETHOD_(long, AddRef)(THIS) OVERRIDE
458 {
459 return SComboBase::AddRef();
460 }
461
462 STDMETHOD_(long, Release)(THIS) OVERRIDE
463 {
464 return SComboBase::Release();
465 }
466
467 STDMETHOD_(void, OnFinalRelease)(THIS) OVERRIDE
468 {
470 }
471
472 STDMETHOD_(IWindow *, ToIWindow)(THIS) OVERRIDE
473 {
474 return (SComboBase *)this;
475 }
476
477 STDMETHOD_(HRESULT, QueryInterface)(REFGUID id, IObjRef **ppRet) OVERRIDE
478 {
479 if (id == T::GetIID())
480 {
481 *ppRet = (T *)this;
482 AddRef();
483 return S_OK;
484 }
485 else
486 {
487 return SComboBase::QueryInterface(id, ppRet);
488 }
489 }
490
491 STDMETHOD_(int, FindString)
492 (THIS_ LPCTSTR pszFind, int nAfter = -1, BOOL bPartMatch = TRUE) OVERRIDE
493 {
494 return SComboBase::FindString(pszFind, nAfter, bPartMatch);
495 }
496
497 STDMETHOD_(int, FindStringA)
498 (THIS_ LPCSTR pszFind, int nAfter = -1, BOOL bPartMatch = TRUE) OVERRIDE
499 {
500 return SComboBase::FindStringA(pszFind, nAfter, bPartMatch);
501 }
502
503 STDMETHOD_(void, DropDown)(THIS) OVERRIDE
504 {
505 return SComboBase::DropDown();
506 }
507
508 STDMETHOD_(void, CloseUp)(THIS) OVERRIDE
509 {
510 return SComboBase::CloseUp();
511 }
512
513 STDMETHOD_(BOOL, IsDropdown)(THIS) SCONST OVERRIDE
514 {
515 return SComboBase::IsDropdown();
516 }
517
518 STDMETHOD_(void, SetDropdown)(THIS_ BOOL bDropdown) OVERRIDE
519 {
520 return SComboBase::SetDropdown(bDropdown);
521 }
522};
523
524SNSEND
525#endif // __SCOMBOBASE__H__
SOUI基础DUI窗口模块
Smart pointer class for managing COM-style reference-counted objects.
void OnMouseHover(WPARAM wParam, CPoint ptPos)
Handle mouse hover event.
SComboEdit()
Constructor.
void OnMouseLeave()
Handle mouse leave event.
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Notify event.
void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
Handle key down event.
void OnKillFocus(SWND wndFocus)
Handle kill focus event.
Dropdown Window Class.
Definition SDropDown.h:43
Simple Edit Control.
Definition SEdit.h:13
void OnKillFocus(SWND wndFocus)
Handle kill focus event.
Definition SEdit.cpp:14
virtual HRESULT OnLanguageChanged()
Handle language change event.
Definition SEdit.cpp:65
void OnPaint(IRenderTarget *pRT)
Paint the control.
Definition SEdit.cpp:39
SEdit()
Constructor.
Definition SEdit.cpp:6
void GetCueText(IStringT *pStr) SCONST
Get the cue text.
Definition SEdit.h:27
布局大小类
Definition SLayoutSize.h:10
A class representing an ASCII string.
Definition sstringw.h:96
Class for handling text with translation support.
Definition SWnd.h:230
Base class for SOUI DUI windows.
Definition SWnd.h:286
HRESULT QueryInterface(REFGUID id, IObjRef **ppRet) OVERRIDE
Queries an interface.
Definition Swnd.cpp:3572
void OnFinalRelease()
Called when the last reference to the object is released.
Definition Swnd.cpp:198
Implementation of IXmlDoc.
Definition SXml.h:912
Class representing an XML node.
Definition SXml.h:352
Interface for rendering target objects.
Definition SRender-i.h:1440
Interface for Dropdown Owner.
Definition SDropDown.h:16