soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SNcPainter.h
1#ifndef __SNCPAINTER__H__
2#define __SNCPAINTER__H__
3
4#include <sobject/Sobject.hpp>
5#include <interface/SNcPainter-i.h>
6#include <core/SItemPanel.h>
7
8SNSBEGIN
9
10// Forward declarations
11class SNcPanel;
12class SHostWnd;
13
14/**
15 * @brief Non-client area painter class.
16 * This class handles the painting and event processing for the non-client area of a window.
17 */
19 : public TObjRefImpl<SObjectImpl<INcPainter>>
20 , public IItemContainer
21 , public IHostProxy {
22 DEF_SOBJECT(SObjectImpl<INcPainter>, L"ncpainter")
23 friend class SHostWnd;
24 friend class SNcPanel;
25
26 enum
27 {
28 IDC_SYS_ICON = -100,
29 IDC_SYS_TITLE = -101,
30 IDC_SYS_CLOSE = -102,
31 IDC_SYS_MIN = -103,
32 IDC_SYS_MAX = -104,
33 IDC_SYS_RESTORE = -105,
34 };
35
36 public:
37 /**
38 * @brief Constructor for SNcPainter.
39 * @param pHost Pointer to the host window.
40 */
41 SNcPainter(SHostWnd *pHost);
42
43 /**
44 * @brief Destructor for SNcPainter.
45 */
46 ~SNcPainter(void);
47
48 /**
49 * @brief Converts a string to a built-in non-client ID.
50 * @param str String representing the non-client ID.
51 * @return The corresponding non-client ID.
52 */
53 static int toNcBuiltinID(const SStringW &str);
54
55 /**
56 * @brief Updates system buttons in the non-client area.
57 * @param pRoot Pointer to the root window.
58 * @param nResizeMode Resize mode for the window.
59 */
60 static void updateSystemButton(SWindow *pRoot, UINT nResizeMode);
61
62 public:
63 /**
64 * @brief Initializes the non-client painter from an XML node.
65 * @param pXmlNode Pointer to the XML node.
66 * @return TRUE if initialization is successful, FALSE otherwise.
67 */
68 STDMETHOD_(BOOL, InitFromXml)(THIS_ IXmlNode *pXmlNode) OVERRIDE;
69
70 public:
71 /**
72 * @brief Gets the root window.
73 * @return Pointer to the root window.
74 */
75 STDMETHOD_(IWindow *, GetRoot)(THIS) OVERRIDE;
76
77 protected:
78 /**
79 * @brief Called when an item sets capture.
80 * @param pItem Pointer to the item.
81 * @param bCapture TRUE if the item sets capture, FALSE otherwise.
82 */
83 virtual void OnItemSetCapture(SOsrPanel *pItem, BOOL bCapture);
84
85 /**
86 * @brief Called to get the rectangle of an item.
87 * @param pItem Pointer to the item.
88 * @param rcItem Rectangle to receive the item's bounds.
89 * @return TRUE if the rectangle is successfully retrieved, FALSE otherwise.
90 */
91 virtual BOOL OnItemGetRect(const SOsrPanel *pItem, CRect &rcItem) const;
92
93 /**
94 * @brief Checks if item redraw is delayed.
95 * @return TRUE if redraw is delayed, FALSE otherwise.
96 */
97 virtual BOOL IsItemRedrawDelay() const;
98
99 /**
100 * @brief Gets the host object.
101 * @return Pointer to the host object.
102 */
103 virtual IObject *GetHost();
104
105 protected:
106 /**
107 * @brief Called when an event is fired on the host.
108 * @param e Pointer to the event arguments.
109 * @return TRUE if the event is handled, FALSE otherwise.
110 */
111 virtual BOOL OnHostFireEvent(IEvtArgs *e);
112
113 /**
114 * @brief Checks if host updates are locked.
115 * @return TRUE if updates are locked, FALSE otherwise.
116 */
117 virtual BOOL IsHostUpdateLocked() const;
118
119 /**
120 * @brief Checks if the host is visible.
121 * @return TRUE if the host is visible, FALSE otherwise.
122 */
123 virtual BOOL IsHostVisible() const;
124
125 /**
126 * @brief Gets the rectangle of the host.
127 * @return Rectangle of the host.
128 */
129 virtual CRect GetHostRect() const;
130
131 /**
132 * @brief Invalidates a rectangle in the host.
133 * @param pRc Pointer to the rectangle to invalidate.
134 * @param bClip TRUE to clip the rectangle, FALSE otherwise.
135 */
136 virtual void InvalidateHostRect(LPCRECT pRc, BOOL bClip);
137
138 /**
139 * @brief Gets the host container.
140 * @return Pointer to the host container.
141 */
143
144 /**
145 * @brief Called to get the host render target.
146 * @param rc Rectangle for the render target.
147 * @param gdcFlags Flags for the render target.
148 * @return Pointer to the render target.
149 */
150 virtual IRenderTarget *OnGetHostRenderTarget(LPCRECT rc, GrtFlag gdcFlags);
151
152 /**
153 * @brief Called to release the host render target.
154 * @param pRT Pointer to the render target.
155 * @param rc Rectangle for the render target.
156 * @param gdcFlags Flags for the render target.
157 */
158 virtual void OnReleaseHostRenderTarget(IRenderTarget *pRT, LPCRECT rc, GrtFlag gdcFlags);
159
160 /**
161 * @brief Called when layout is dirty.
162 */
163 virtual void OnLayoutDirty();
164
165 protected:
166 /**
167 * @brief Gets the scale factor.
168 * @return Scale factor.
169 */
170 int GetScale() const;
171
172 /**
173 * @brief Gets the size of the non-client area.
174 * @return Size of the non-client area.
175 */
176 CSize GetNcSize() const;
177
178 public:
179 SOUI_ATTRS_BEGIN()
180 ATTR_LAYOUTSIZE(L"titleHeight", m_titleHeight, FALSE)
181 ATTR_LAYOUTSIZE(L"borderWidth", m_borderWidth, FALSE)
182 ATTR_SKIN(L"skinBorder", m_skinBorder, FALSE)
183 ATTR_BOOL(L"system", m_bSysNcPainter, FALSE)
184 SOUI_ATTRS_END()
185
186 protected:
187 /**
188 * @brief Handles the WM_NCCALCSIZE message.
189 * @param bCalcValidRects TRUE if valid rectangle calculation is required.
190 * @param lParam LPARAM for the message.
191 * @return Result of the message handling.
192 */
193 LRESULT OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam);
194
195 /**
196 * @brief Handles the WM_NCACTIVATE message.
197 * @param bActive TRUE if the window is activated, FALSE otherwise.
198 * @return Result of the message handling.
199 */
200 BOOL OnNcActivate(BOOL bActive);
201
202 /**
203 * @brief Handles the WM_NCHITTEST message.
204 * @param point Point to test.
205 * @return Hit test result.
206 */
207 UINT OnNcHitTest(CPoint point);
208
209 /**
210 * @brief Handles the WM_NCPAINT message.
211 * @param hRgn Region to paint.
212 */
213 void OnNcPaint(HRGN hRgn);
214
215 /**
216 * @brief Handles the WM_SETTEXT message.
217 * @param pszText New text for the window.
218 * @return Result of the message handling.
219 */
220 LRESULT OnSetText(LPCTSTR pszText);
221
222 /**
223 * @brief Handles repaint messages.
224 * @param msg Message identifier.
225 * @param wp WPARAM for the message.
226 * @param lp LPARAM for the message.
227 * @return Result of the message handling.
228 */
229 LRESULT OnRepaint(UINT msg, WPARAM wp, LPARAM lp);
230
231 /**
232 * @brief Handles the WM_NCDESTROY message.
233 */
234 void OnNcDestroy();
235
236 /**
237 * @brief Handles the WM_NCLBUTTONDOWN message.
238 * @param flag Flags for the message.
239 * @param pt Point where the button was pressed.
240 */
241 void OnNcLButtonDown(UINT flag, CPoint pt);
242
243 /**
244 * @brief Handles the WM_LBUTTONUP message.
245 * @param wp WPARAM for the message.
246 * @param lp LPARAM for the message.
247 */
248 void OnLButtonUp(WPARAM wp, LPARAM lp);
249
250 /**
251 * @brief Handles the WM_MOUSEMOVE message.
252 * @param wp WPARAM for the message.
253 * @param lp LPARAM for the message.
254 */
255 void OnMouseMove(WPARAM wp, LPARAM lp);
256
257 /**
258 * @brief Handles non-client mouse events.
259 * @param msg Message identifier.
260 * @param wp WPARAM for the message.
261 * @param lp LPARAM for the message.
262 * @return Result of the message handling.
263 */
264 LRESULT OnNcMouseEvent(UINT msg, WPARAM wp, LPARAM lp);
265
266 /**
267 * @brief Handles the WM_NCMOUSELEAVE message.
268 * @param msg Message identifier.
269 * @param wp WPARAM for the message.
270 * @param lp LPARAM for the message.
271 * @return Result of the message handling.
272 */
273 LRESULT OnNcMouseLeave(UINT msg, WPARAM wp, LPARAM lp);
274
275 /**
276 * @brief Handles the WM_SIZE message.
277 * @param nType Type of size change.
278 * @param size New size of the window.
279 */
280 void OnSize(UINT nType, CSize size);
281
282 /**
283 * @brief Handles the WM_TIMER message.
284 * @param tid Timer ID.
285 */
286 void OnTimer(UINT_PTR tid);
287
288 BEGIN_MSG_MAP_EX(SNcPainter)
289 if (m_bSysNcPainter)
290 return FALSE;
291 MSG_WM_NCCALCSIZE(OnNcCalcSize)
292 MSG_WM_NCACTIVATE(OnNcActivate)
293 MSG_WM_NCHITTEST(OnNcHitTest)
294 MSG_WM_NCPAINT(OnNcPaint)
295 MSG_WM_NCDESTROY(OnNcDestroy)
296 MSG_WM_SETTEXT(OnSetText)
297 MSG_WM_SIZE(OnSize)
298 MSG_WM_NCLBUTTONDOWN(OnNcLButtonDown)
299 MESSAGE_HANDLER_EX(WM_NCMOUSELEAVE, OnNcMouseLeave)
300 MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCMBUTTONDBLCLK, OnNcMouseEvent)
301 MESSAGE_HANDLER_EX(WM_SETTINGCHANGE, OnRepaint)
302 MESSAGE_HANDLER_EX(WM_SYSCOLORCHANGE, OnRepaint)
303 MSG_WM_TIMER(OnTimer)
304 END_MSG_MAP()
305
306 protected:
307 /**
308 * @brief Resets the non-client painter.
309 */
310 void Reset();
311
312 /**
313 * @brief Checks if non-client area should be drawn.
314 * @return TRUE if non-client area should be drawn, FALSE otherwise.
315 */
316 BOOL IsDrawNc() const;
317
318 /**
319 * @brief Paints the caption.
320 */
322
323 /**
324 * @brief Updates the tooltip.
325 */
326 void UpdateToolTip();
327
328 private:
329 // Pointer to the host window
330 SHostWnd *m_pHost;
331
332 // Height of the title bar
333 SLayoutSize m_titleHeight;
334 // Width of the border
335 SLayoutSize m_borderWidth;
336 // Skin for the border
337 SAutoRefPtr<ISkinObj> m_skinBorder;
338 // Flag indicating if the system non-client painter is used
339 BOOL m_bSysNcPainter;
340
341 // Memory render target for the main area
343 // Memory render target for the left side
345 // Memory render target for the right side
347 // Memory render target for the top side
349 // Memory render target for the bottom side
350 SAutoRefPtr<IRenderTarget> m_memBottom;
351 // Hit test part
352 UINT m_htPart;
353 // Flag indicating if painting is in progress
354 BOOL m_bInPaint;
355 // Flag indicating if the left mouse button is down
356 BOOL m_bLButtonDown;
357 // Flag indicating if the mouse is hovering
358 BOOL m_bMouseHover;
359 // Root non-client panel
360 SNcPanel *m_root;
361 // Invalid rectangle
362 CRect m_rcInvalid;
363};
364
365/**
366 * @brief Non-client panel class.
367 * This class represents a panel in the non-client area.
368 */
369class SNcPanel : public SOsrPanel {
370 DEF_SOBJECT(SOsrPanel, L"ncpanel")
371
372 public:
373 /**
374 * @brief Constructor for SNcPanel.
375 * @param pFrameHost Pointer to the frame host.
376 * @param pItemContainer Pointer to the item container.
377 */
378 SNcPanel(IHostProxy *pFrameHost, IItemContainer *pItemContainer);
379
380 /**
381 * @brief Sets the active state of the panel.
382 * @param bActive TRUE if the panel is active, FALSE otherwise.
383 */
384 void SetActive(BOOL bActive);
385
386 /**
387 * @brief Checks if the panel is active.
388 * @return TRUE if the panel is active, FALSE otherwise.
389 */
390 BOOL IsActive() const
391 {
392 return m_bActive;
393 }
394
395 protected:
396 /**
397 * @brief Erases the background of the panel.
398 * @param pRT Pointer to the render target.
399 * @return TRUE if the background is erased, FALSE otherwise.
400 */
401 BOOL OnEraseBkgnd(IRenderTarget *pRT);
402
403 SOUI_MSG_MAP_BEGIN()
404 MSG_WM_ERASEBKGND_EX(OnEraseBkgnd)
405 SOUI_MSG_MAP_END()
406
407 public:
408 SOUI_ATTRS_BEGIN()
409 ATTR_SKIN(L"skinActive", m_skinActive, FALSE)
410 ATTR_SKIN(L"skinInactive", m_skinInactive, FALSE)
411 ATTR_COLOR(L"colorActiveTitle", m_crActiveTitle, TRUE)
412 ATTR_COLOR(L"colorInactiveTitle", m_crInactiveTitle, TRUE)
413 SOUI_ATTRS_END()
414
415 protected:
416 // Skin for the active state
417 SAutoRefPtr<ISkinObj> m_skinActive;
418 // Skin for the inactive state
419 SAutoRefPtr<ISkinObj> m_skinInactive;
420 // Color for the active title
421 COLORREF m_crActiveTitle;
422 // Color for the inactive title
423 COLORREF m_crInactiveTitle;
424
425 // Flag indicating if the panel is active
426 BOOL m_bActive;
427};
428
429SNSEND
430
431#endif // __SNCPAINTER__H__
GrtFlag
Smart pointer class for managing COM-style reference-counted objects.
The main host window class responsible for managing the layout, events, and rendering of SOUI windows...
Definition SHostWnd.h:318
布局大小类
Definition SLayoutSize.h:10
virtual BOOL IsHostUpdateLocked() const
Checks if host updates are locked.
LRESULT OnSetText(LPCTSTR pszText)
Handles the WM_SETTEXT message.
void OnSize(UINT nType, CSize size)
Handles the WM_SIZE message.
void OnLButtonUp(WPARAM wp, LPARAM lp)
Handles the WM_LBUTTONUP message.
virtual BOOL OnHostFireEvent(IEvtArgs *e)
Called when an event is fired on the host.
virtual ISwndContainer * GetHostContainer()
Gets the host container.
virtual void OnLayoutDirty()
Called when layout is dirty.
virtual CRect GetHostRect() const
Gets the rectangle of the host.
void OnNcLButtonDown(UINT flag, CPoint pt)
Handles the WM_NCLBUTTONDOWN message.
BOOL IsDrawNc() const
Checks if non-client area should be drawn.
void PaintCaption()
Paints the caption.
CSize GetNcSize() const
Gets the size of the non-client area.
static void updateSystemButton(SWindow *pRoot, UINT nResizeMode)
Updates system buttons in the non-client area.
LRESULT OnNcMouseLeave(UINT msg, WPARAM wp, LPARAM lp)
Handles the WM_NCMOUSELEAVE message.
virtual BOOL IsItemRedrawDelay() const
Checks if item redraw is delayed.
static int toNcBuiltinID(const SStringW &str)
Converts a string to a built-in non-client ID.
void Reset()
Resets the non-client painter.
void OnTimer(UINT_PTR tid)
Handles the WM_TIMER message.
virtual void OnReleaseHostRenderTarget(IRenderTarget *pRT, LPCRECT rc, GrtFlag gdcFlags)
Called to release the host render target.
LRESULT OnRepaint(UINT msg, WPARAM wp, LPARAM lp)
Handles repaint messages.
virtual IRenderTarget * OnGetHostRenderTarget(LPCRECT rc, GrtFlag gdcFlags)
Called to get the host render target.
void OnMouseMove(WPARAM wp, LPARAM lp)
Handles the WM_MOUSEMOVE message.
void OnNcDestroy()
Handles the WM_NCDESTROY message.
virtual void OnItemSetCapture(SOsrPanel *pItem, BOOL bCapture)
Called when an item sets capture.
LRESULT OnNcCalcSize(BOOL bCalcValidRects, LPARAM lParam)
Handles the WM_NCCALCSIZE message.
BOOL OnNcActivate(BOOL bActive)
Handles the WM_NCACTIVATE message.
virtual BOOL OnItemGetRect(const SOsrPanel *pItem, CRect &rcItem) const
Called to get the rectangle of an item.
int GetScale() const
Gets the scale factor.
SNcPainter(SHostWnd *pHost)
Constructor for SNcPainter.
virtual void InvalidateHostRect(LPCRECT pRc, BOOL bClip)
Invalidates a rectangle in the host.
IWindow * GetRoot() OVERRIDE
Gets the root window.
UINT OnNcHitTest(CPoint point)
Handles the WM_NCHITTEST message.
virtual IObject * GetHost()
Gets the host object.
void OnNcPaint(HRGN hRgn)
Handles the WM_NCPAINT message.
~SNcPainter(void)
Destructor for SNcPainter.
virtual BOOL IsHostVisible() const
Checks if the host is visible.
void UpdateToolTip()
Updates the tooltip.
BOOL InitFromXml(IXmlNode *pXmlNode) OVERRIDE
Initializes the non-client painter from an XML node.
LRESULT OnNcMouseEvent(UINT msg, WPARAM wp, LPARAM lp)
Handles non-client mouse events.
Non-client panel class. This class represents a panel in the non-client area.
Definition SNcPainter.h:369
BOOL OnEraseBkgnd(IRenderTarget *pRT)
Erases the background of the panel.
BOOL IsActive() const
Checks if the panel is active.
Definition SNcPainter.h:390
SNcPanel(IHostProxy *pFrameHost, IItemContainer *pItemContainer)
Constructor for SNcPanel.
Definition SNcPainter.cpp:7
void SetActive(BOOL bActive)
Sets the active state of the panel.
A class representing an ASCII string.
Definition sstringw.h:96
Base class for SOUI DUI windows.
Definition SWnd.h:286
Interface for rendering target objects.
Definition SRender-i.h:1440
Interface for Skin Objects.
Definition SSkinobj-i.h:29
SOUI Window Container Interface.
Interface for XML nodes.
Definition sxml-i.h:128