soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SDropDown.cpp
Go to the documentation of this file.
1/**
2 * Copyright (C) 2014-2050 SOUI团队
3 * All rights reserved.
4 *
5 * @file SDropDown.cpp
6 * @brief SDropDownWnd类源文件
7 * @version v1.0
8 * @author soui
9 * @date 2014-05-25
10 *
11 * Describe 此文件主要用于SDropDownWnd类相关实现
12 */
13#include <souistd.h>
14#include <control/SDropDown.h>
15#include <core/SMsgLoop.h>
16
17SNSBEGIN
18#define IDINIT -1
19
21 : m_pOwner(pOwner)
22 , m_bClick(FALSE)
23 , m_uExitCode((UINT)IDINIT)
24{
25}
26
30
32{
34 delete this;
35}
36
37void SDropDownWnd::OnKillFocus(HWND wndFocus)
38{
39 if (wndFocus != m_hWnd)
40 {
42 }
43}
44
46{
47 SASSERT(m_pOwner);
48 return m_pOwner->GetDropDownOwner();
49}
50
51BOOL SDropDownWnd::Create(LPCRECT lpRect, LPVOID lParam, DWORD dwStyle, DWORD dwExStyle)
52{
53 HWND hParent = m_pOwner->GetDropDownOwner()->GetContainer()->GetHostHwnd();
54 HWND hWnd = SNativeWnd::CreateNative(NULL, dwStyle, dwExStyle, lpRect->left, lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top, hParent, 0, NULL);
55 if (!hWnd)
56 return FALSE;
58 m_pOwner->OnCreateDropDown(this);
59 return TRUE;
60}
61
62void SDropDownWnd::OnLButtonDown(UINT nFlags, CPoint point)
63{
64 CRect rcWnd;
66 if (!rcWnd.PtInRect(point))
67 {
69 }
70 else
71 {
72 m_bClick = TRUE;
73 SetMsgHandled(FALSE);
74 }
75}
76
77void SDropDownWnd::OnLButtonUp(UINT nFlags, CPoint point)
78{
79 if (m_bClick)
80 {
81 LRESULT lRes = 0;
82 HWND hWnd = m_hWnd;
83 CRect rcWnd;
85 SHostWnd::ProcessWindowMessage(m_hWnd, WM_LBUTTONUP, nFlags, MAKELPARAM(point.x, point.y), lRes);
86 if (::IsWindow(hWnd) && !rcWnd.PtInRect(point))
87 EndDropDown(); //强制关闭弹出窗口
88 }
89}
90
91void SDropDownWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
92{
93 if (nChar == VK_RETURN)
94 EndDropDown(IDOK);
95 else if (nChar == VK_ESCAPE)
97 else
98 SetMsgHandled(FALSE);
99}
100
102{
103 if (m_uExitCode != IDINIT)
104 return;
105 m_uExitCode = uCode;
107}
108
110{
111 m_pOwner->OnDestroyDropDown(this);
113 SetMsgHandled(FALSE);
114}
115
117{
118 if (pMsg->message == WM_ACTIVATEAPP)
119 {
120 SNativeWnd::SendMessage(pMsg->message, pMsg->wParam, pMsg->lParam);
121 }
122 else if (pMsg->message == WM_MOUSEMOVE)
123 { //由于窗口显示后就调用了setcapture,导致收不到setcursor消息,这里在WM_MOUSEMOVE消息里模拟一个setcursor消息。
124 SNativeWnd::SendMessage(WM_SETCURSOR, (WPARAM)m_hWnd, MAKELPARAM(HTCLIENT, WM_MOUSEMOVE));
125 }
126 return FALSE;
127}
128
129void SDropDownWnd::OnActivateApp(BOOL bActive, DWORD dwThreadID)
130{
131 if (!bActive)
132 {
133 EndDropDown();
134 }
135}
136
137int SDropDownWnd::OnMouseActivate(HWND wndTopLevel, UINT nHitTest, UINT message)
138{
139 return MA_NOACTIVATEANDEAT;
140}
141
143{
144 BOOL bRet = SHostWnd::OnReleaseSwndCapture();
146 return bRet;
147}
148
150{
151 return m_pOwner->GetDropDownOwner()->GetContainer()->GetMsgLoop();
152}
153
154SNSEND
void OnDestroy()
Handle destroy event.
void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
Handle key down event.
Definition SDropDown.cpp:91
void OnActivateApp(BOOL bActive, DWORD dwThreadID)
Handle activate application event.
IMessageLoop * GetMsgLoop()
Get the message loop.
int OnMouseActivate(HWND wndTopLevel, UINT nHitTest, UINT message)
Handle mouse activate event.
SWindow * GetDropDownOwner()
Get the dropdown owner window.
Definition SDropDown.cpp:45
void OnKillFocus(HWND wndFocus)
Handle kill focus event.
Definition SDropDown.cpp:37
void OnLButtonDown(UINT nFlags, CPoint point)
Handle left mouse button down event.
Definition SDropDown.cpp:62
virtual ~SDropDownWnd()
Destructor.
Definition SDropDown.cpp:27
ISDropDownOwner * m_pOwner
Definition SDropDown.h:184
UINT m_uExitCode
Definition SDropDown.h:186
virtual BOOL Create(LPCRECT lpRect, LPVOID lParam, DWORD dwStyle=WS_POPUP, DWORD dwExStyle=WS_EX_TOOLWINDOW|WS_EX_TOPMOST)
Create the dropdown window.
Definition SDropDown.cpp:51
void EndDropDown(UINT uCode=IDCANCEL)
End the dropdown window.
BOOL OnReleaseSwndCapture()
Prevent the window from releasing capture.
void OnLButtonUp(UINT nFlags, CPoint point)
Handle left mouse button up event.
Definition SDropDown.cpp:77
virtual BOOL WINAPI PreTranslateMessage(MSG *pMsg)
Pre-translate messages.
virtual void OnFinalMessage(HWND hwnd)
Handle final message.
Definition SDropDown.cpp:31
SDropDownWnd(ISDropDownOwner *pOwner)
Constructor.
Definition SDropDown.cpp:20
BOOL OnReleaseSwndCapture() OVERRIDE
Releases the capture from the container.
HWND SetCapture() OVERRIDE
Sets the window to capture the mouse.
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0) OVERRIDE
Sends a message to the window.
virtual BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult, DWORD dwMsgMapID=0)
Processes a window message.
HWND m_hWnd
Handle to the window.
Definition SNativeWnd.h:744
BOOL GetClientRect(LPRECT lpRect) SCONST OVERRIDE
Retrieves the client rectangle.
HWND CreateNative(LPCTSTR lpWindowName, DWORD dwStyle, DWORD dwExStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, int nID=0, LPVOID lpParam=0) OVERRIDE
Creates a native window.
virtual void OnFinalMessage(HWND hWnd)
Handles the final message for the window.
BOOL DestroyWindow() OVERRIDE
Destroys the window.
Base class for SOUI DUI windows.
Definition SWnd.h:286
Interface for message loops.
Definition SMsgLoop-i.h:42
BOOL RemoveMessageFilter(IMsgFilter *pMessageFilter) PURE
Removes a message filter.
BOOL AddMessageFilter(IMsgFilter *pMessageFilter) PURE
Adds a message filter.
Interface for Dropdown Owner.
Definition SDropDown.h:16