Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fwl / src / core / fwl_formimp.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 #include "include/fwl_targetimp.h"\r
9 #include "include/fwl_threadimp.h"\r
10 #include "include/fwl_noteimp.h"\r
11 #include "include/fwl_widgetimp.h"\r
12 #include "include/fwl_panelimp.h"\r
13 #include "include/fwl_formimp.h"\r
14 #include "include/fwl_widgetmgrimp.h"\r
15 #include "include/fwl_appimp.h"\r
16 #define FWL_SYSBTNSIZE          21\r
17 #define FWL_SYSBTNMARGIN        5\r
18 #define FWL_SYSBTNSPAN          2\r
19 #define FWL_CornerEnlarge       10\r
20 IFWL_Form* IFWL_Form::Create()\r
21 {\r
22     return new IFWL_Form;\r
23 }\r
24 FWL_ERR IFWL_Form::Initialize(IFWL_Widget *pOuter )\r
25 {\r
26     m_pData = FX_NEW CFWL_FormImp(pOuter);\r
27     ((CFWL_FormImp*)m_pData)->SetInterface(this);\r
28     return ((CFWL_FormImp*)m_pData)->Initialize();\r
29 }\r
30 FWL_ERR IFWL_Form::Initialize(CFWL_WidgetImpProperties &properties, IFWL_Widget *pOuter )\r
31 {\r
32     m_pData = FX_NEW CFWL_FormImp(properties, pOuter);\r
33     ((CFWL_FormImp*)m_pData)->SetInterface(this);\r
34     return ((CFWL_FormImp*)m_pData)->Initialize();\r
35 }\r
36 FWL_ERR IFWL_Form::Initialize(CFWL_WidgetImpProperties &properties, CFX_WideString *classname, IFWL_Widget *pOuter )\r
37 {\r
38     m_pData = FX_NEW CFWL_FormImp(properties, pOuter);\r
39     ((CFWL_FormImp*)m_pData)->SetInterface(this);\r
40     ((CFWL_FormImp*)m_pData)->SetPrivateData(this, classname, NULL);\r
41     return ((CFWL_FormImp*)m_pData)->Initialize();\r
42 }\r
43 FWL_FORMSIZE IFWL_Form::GetFormSize()\r
44 {\r
45     return ((CFWL_FormImp*)m_pData)->GetFormSize();\r
46 }\r
47 FWL_ERR IFWL_Form::SetFormSize(FWL_FORMSIZE eFormSize)\r
48 {\r
49     return ((CFWL_FormImp*)m_pData)->SetFormSize(eFormSize);\r
50 }\r
51 IFWL_Widget* IFWL_Form::DoModal()\r
52 {\r
53     return ((CFWL_FormImp*)m_pData)->DoModal();\r
54 }\r
55 IFWL_Widget* IFWL_Form::DoModal(FX_DWORD &dwCommandID)\r
56 {\r
57     return ((CFWL_FormImp*)m_pData)->DoModal(dwCommandID);\r
58 }\r
59 FWL_ERR IFWL_Form::EndDoModal()\r
60 {\r
61     return ((CFWL_FormImp*)m_pData)->EndDoModal();\r
62 }\r
63 FWL_ERR IFWL_Form::SetBorderRegion(CFX_Path *pPath)\r
64 {\r
65     return ((CFWL_FormImp*)m_pData)->SetBorderRegion(pPath);\r
66 }\r
67 IFWL_Form::IFWL_Form()\r
68 {\r
69     m_pData = NULL;\r
70 }\r
71 IFWL_Form::~IFWL_Form()\r
72 {\r
73     if (m_pData) {\r
74         delete (CFWL_FormImp*)m_pData;\r
75         m_pData = NULL;\r
76     }\r
77 }\r
78 CFWL_FormImp::CFWL_FormImp(IFWL_Widget *pOuter )\r
79     : CFWL_PanelImp(pOuter)\r
80     , m_pCloseBox(NULL)\r
81     , m_pMinBox(NULL)\r
82     , m_pMaxBox(NULL)\r
83     , m_pCaptionBox(NULL)\r
84     , m_pNoteLoop(NULL)\r
85     , m_pSubFocus(NULL)\r
86     , m_fCXBorder(0)\r
87     , m_fCYBorder(0)\r
88     , m_iCaptureBtn(-1)\r
89     , m_iSysBox(0)\r
90     , m_eResizeType(FORM_RESIZETYPE_None)\r
91     , m_bLButtonDown(FALSE)\r
92     , m_bMaximized(FALSE)\r
93     , m_bSetMaximize(FALSE)\r
94     , m_bCustomizeLayout(FALSE)\r
95     , m_eFormSize(FWL_FORMSIZE_Manual)\r
96     , m_bDoModalFlag(FALSE)\r
97     , m_pBigIcon(NULL)\r
98     , m_pSmallIcon(NULL)\r
99     , m_bMouseIn(FALSE)\r
100 {\r
101     m_rtRelative.Reset();\r
102     m_rtCaption.Reset();\r
103     m_rtRestore.Reset();\r
104     m_rtCaptionText.Reset();\r
105     m_rtIcon.Reset();\r
106     m_InfoStart.m_ptStart.Reset();\r
107     m_InfoStart.m_szStart.Reset();\r
108 }\r
109 CFWL_FormImp::CFWL_FormImp(const CFWL_WidgetImpProperties &properties, IFWL_Widget *pOuter )\r
110     : CFWL_PanelImp(properties, pOuter)\r
111     , m_pCloseBox(NULL)\r
112     , m_pMinBox(NULL)\r
113     , m_pMaxBox(NULL)\r
114     , m_pCaptionBox(NULL)\r
115     , m_pNoteLoop(NULL)\r
116     , m_pSubFocus(NULL)\r
117     , m_fCXBorder(0)\r
118     , m_fCYBorder(0)\r
119     , m_iCaptureBtn(-1)\r
120     , m_iSysBox(0)\r
121     , m_eResizeType(FORM_RESIZETYPE_None)\r
122     , m_bLButtonDown(FALSE)\r
123     , m_bMaximized(FALSE)\r
124     , m_bSetMaximize(FALSE)\r
125     , m_bCustomizeLayout(FALSE)\r
126     , m_eFormSize(FWL_FORMSIZE_Manual)\r
127     , m_bDoModalFlag(FALSE)\r
128     , m_pBigIcon(NULL)\r
129     , m_pSmallIcon(NULL)\r
130     , m_bMouseIn(FALSE)\r
131 {\r
132     m_rtRelative.Reset();\r
133     m_rtCaption.Reset();\r
134     m_rtRestore.Reset();\r
135     m_rtCaptionText.Reset();\r
136     m_rtIcon.Reset();\r
137     m_InfoStart.m_ptStart.Reset();\r
138     m_InfoStart.m_szStart.Reset();\r
139 }\r
140 CFWL_FormImp::~CFWL_FormImp()\r
141 {\r
142     RemoveSysButtons();\r
143     if (m_pNoteLoop) {\r
144         delete m_pNoteLoop;\r
145         m_pNoteLoop = NULL;\r
146     }\r
147 }\r
148 FWL_ERR CFWL_FormImp::GetClassName(CFX_WideString &wsClass) const\r
149 {\r
150     wsClass = FWL_CLASS_Form;\r
151     return FWL_ERR_Succeeded;\r
152 }\r
153 FX_DWORD CFWL_FormImp::GetClassID() const\r
154 {\r
155     return FWL_CLASSHASH_Form;\r
156 }\r
157 FX_BOOL CFWL_FormImp::IsInstance(FX_WSTR wsClass) const\r
158 {\r
159     if (wsClass == CFX_WideStringC(FWL_CLASS_Form)) {\r
160         return TRUE;\r
161     }\r
162     return CFWL_PanelImp::IsInstance(wsClass);\r
163 }\r
164 FWL_ERR CFWL_FormImp::Initialize()\r
165 {\r
166     _FWL_ERR_CHECK_RETURN_VALUE_IF_FAIL(CFWL_WidgetImp::Initialize(), FWL_ERR_Indefinite);\r
167     RegisterForm();\r
168     RegisterEventTarget();\r
169     m_pDelegate = (IFWL_WidgetDelegate*) FX_NEW CFWL_FormDelegate(this);\r
170     return FWL_ERR_Succeeded;\r
171 }\r
172 FWL_ERR CFWL_FormImp::Finalize()\r
173 {\r
174     if ( m_pDelegate) {\r
175         delete (CFWL_FormDelegate*)m_pDelegate;\r
176         m_pDelegate = NULL;\r
177     }\r
178     UnregisterEventTarget();\r
179     UnRegisterForm();\r
180     return CFWL_WidgetImp::Finalize();\r
181 }\r
182 FWL_ERR CFWL_FormImp::GetWidgetRect(CFX_RectF &rect, FX_BOOL bAutoSize )\r
183 {\r
184     if (bAutoSize) {\r
185         rect.Reset();\r
186         FX_FLOAT fCapHeight = GetCaptionHeight();\r
187         FX_FLOAT fCXBorder = GetBorderSize(TRUE);\r
188         FX_FLOAT fCYBorder = GetBorderSize(FALSE);\r
189         FX_FLOAT fEdge = GetEdgeWidth();\r
190         if (m_pContent) {\r
191             m_pContent->GetWidgetRect(rect, TRUE);\r
192         }\r
193         rect.height += fCapHeight + fCYBorder + fEdge + fEdge;\r
194         rect.width += fCXBorder + fCXBorder + fEdge + fEdge;\r
195     } else {\r
196         rect = m_pProperties->m_rtWidget;\r
197     }\r
198     return FWL_ERR_Succeeded;\r
199 }\r
200 FWL_ERR CFWL_FormImp::GetClientRect(CFX_RectF &rect)\r
201 {\r
202     if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_Caption) == 0) {\r
203         rect = m_pProperties->m_rtWidget;\r
204         rect.Offset(-rect.left, -rect.top);\r
205         return FWL_ERR_Succeeded;\r
206     }\r
207 #ifdef FWL_UseMacSystemBorder\r
208     rect = m_rtRelative;\r
209     CFWL_WidgetMgr *pWidgetMgr = (CFWL_WidgetMgr*)FWL_GetWidgetMgr();\r
210     _FWL_RETURN_VALUE_IF_FAIL(pWidgetMgr, FWL_ERR_Indefinite);\r
211     IFWL_AdapterWidgetMgr * adapterWidgetMgr = pWidgetMgr->GetAdapterWidgetMgr();\r
212     FX_FLOAT l, t, r, b;\r
213     l = t = r = b = 0;\r
214     adapterWidgetMgr->GetSystemBorder(l, t, r, b);\r
215     rect.Deflate(l, t, r, b);\r
216     rect.left = rect.top = 0;\r
217     return FWL_ERR_Succeeded;\r
218 #else\r
219     FX_FLOAT x = 0;\r
220     FX_FLOAT y = 0;\r
221     FX_FLOAT t = 0;\r
222     IFWL_ThemeProvider *pTheme = m_pProperties->m_pThemeProvider;\r
223     if (pTheme) {\r
224         CFWL_ThemePart part;\r
225         part.m_pWidget = m_pInterface;\r
226         FX_FLOAT * value = NULL;\r
227         value = (FX_FLOAT *) pTheme->GetCapacity(&part, FWL_WGTCAPACITY_CXBorder);\r
228         x = *value;\r
229         value = (FX_FLOAT *) pTheme->GetCapacity(&part, FWL_WGTCAPACITY_CYBorder);\r
230         y = *value;\r
231         value = (FX_FLOAT*)pTheme->GetCapacity(&part, FWL_WGTCAPACITY_FRM_CYCaption);\r
232         t = *value;\r
233     }\r
234     rect = m_pProperties->m_rtWidget;\r
235     rect.Offset(-rect.left, -rect.top);\r
236     rect.Deflate(x, t, x, y);\r
237     return FWL_ERR_Succeeded;\r
238 #endif\r
239 }\r
240 FWL_ERR CFWL_FormImp::Update()\r
241 {\r
242     if (m_iLock > 0) {\r
243         return FWL_ERR_Succeeded;\r
244     }\r
245     if (!m_pProperties->m_pThemeProvider) {\r
246         m_pProperties->m_pThemeProvider = GetAvailableTheme();\r
247     }\r
248 #ifdef FWL_UseMacSystemBorder\r
249 #else\r
250     SetThemeData();\r
251     if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Icon) {\r
252         UpdateIcon();\r
253     }\r
254 #endif\r
255     UpdateCaption();\r
256     Layout();\r
257     return FWL_ERR_Succeeded;\r
258 }\r
259 FX_DWORD CFWL_FormImp::HitTest(FX_FLOAT fx, FX_FLOAT fy)\r
260 {\r
261     IFWL_ThemeProvider *pTheme = GetAvailableTheme();\r
262     if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) {\r
263         return FWL_WGTHITTEST_CloseBox;\r
264     }\r
265     if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) {\r
266         return FWL_WGTHITTEST_MaxBox;\r
267     }\r
268     if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) {\r
269         return FWL_WGTHITTEST_MinBox;\r
270     }\r
271     CFX_RectF rtCap;\r
272     rtCap.Set(m_rtCaption.left + m_fCYBorder,\r
273               m_rtCaption.top + m_fCXBorder,\r
274               m_rtCaption.width - FWL_SYSBTNSIZE * m_iSysBox - 2 * m_fCYBorder,\r
275               m_rtCaption.height - m_fCXBorder);\r
276     if (rtCap.Contains(fx, fy)) {\r
277         return FWL_WGTHITTEST_Titlebar;\r
278     }\r
279     if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) && (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize)) {\r
280         FX_FLOAT fWidth = m_rtRelative.width - 2 * (m_fCYBorder + FWL_CornerEnlarge);\r
281         FX_FLOAT fHeight = m_rtRelative.height - 2 * (m_fCXBorder + FWL_CornerEnlarge);\r
282         CFX_RectF rt;\r
283         rt.Set(0, m_fCXBorder + FWL_CornerEnlarge, m_fCYBorder, fHeight);\r
284         if (rt.Contains(fx, fy)) {\r
285             return FWL_WGTHITTEST_Left;\r
286         }\r
287         rt.Set(m_rtRelative.width - m_fCYBorder, m_fCXBorder + FWL_CornerEnlarge, m_fCYBorder, fHeight);\r
288         if (rt.Contains(fx, fy)) {\r
289             return FWL_WGTHITTEST_Right;\r
290         }\r
291         rt.Set(m_fCYBorder + FWL_CornerEnlarge, 0, fWidth, m_fCXBorder);\r
292         if (rt.Contains(fx, fy)) {\r
293             return FWL_WGTHITTEST_Top;\r
294         }\r
295         rt.Set(m_fCYBorder + FWL_CornerEnlarge, m_rtRelative.height - m_fCXBorder, fWidth, m_fCXBorder);\r
296         if (rt.Contains(fx, fy)) {\r
297             return FWL_WGTHITTEST_Bottom;\r
298         }\r
299         rt.Set(0, 0, m_fCYBorder + FWL_CornerEnlarge, m_fCXBorder + FWL_CornerEnlarge);\r
300         if (rt.Contains(fx, fy)) {\r
301             return FWL_WGTHITTEST_LeftTop;\r
302         }\r
303         rt.Set(0, m_rtRelative.height - m_fCXBorder - FWL_CornerEnlarge,\r
304                m_fCYBorder + FWL_CornerEnlarge, m_fCXBorder + FWL_CornerEnlarge);\r
305         if (rt.Contains(fx, fy)) {\r
306             return FWL_WGTHITTEST_LeftBottom;\r
307         }\r
308         rt.Set(m_rtRelative.width - m_fCYBorder - FWL_CornerEnlarge, 0,\r
309                m_fCYBorder + FWL_CornerEnlarge, m_fCXBorder + FWL_CornerEnlarge);\r
310         if (rt.Contains(fx, fy)) {\r
311             return FWL_WGTHITTEST_RightTop;\r
312         }\r
313         rt.Set(m_rtRelative.width - m_fCYBorder - FWL_CornerEnlarge,\r
314                m_rtRelative.height - m_fCXBorder - FWL_CornerEnlarge,\r
315                m_fCYBorder + FWL_CornerEnlarge,\r
316                m_fCXBorder + FWL_CornerEnlarge);\r
317         if (rt.Contains(fx, fy)) {\r
318             return FWL_WGTHITTEST_RightBottom;\r
319         }\r
320     }\r
321     return FWL_WGTHITTEST_Client;\r
322 }\r
323 FWL_ERR CFWL_FormImp::DrawWidget(CFX_Graphics *pGraphics, const CFX_Matrix *pMatrix )\r
324 {\r
325     _FWL_RETURN_VALUE_IF_FAIL(pGraphics, FWL_ERR_Indefinite);\r
326     _FWL_RETURN_VALUE_IF_FAIL(m_pProperties->m_pThemeProvider, FWL_ERR_Indefinite);\r
327     IFWL_ThemeProvider *pTheme = m_pProperties->m_pThemeProvider;\r
328     FX_BOOL bInactive = !IsActive();\r
329     FX_INT32 iState = bInactive ? FWL_PARTSTATE_FRM_Inactive : FWL_PARTSTATE_FRM_Normal;\r
330     if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_NoDrawClient) == 0) {\r
331         DrawBackground(pGraphics, pTheme);\r
332     }\r
333 #ifdef FWL_UseMacSystemBorder\r
334     return FWL_ERR_Succeeded;\r
335 #endif\r
336     CFWL_ThemeBackground param;\r
337     param.m_pWidget = m_pInterface;\r
338     param.m_dwStates = iState;\r
339     param.m_pGraphics = pGraphics;\r
340     param.m_rtPart = m_rtRelative;\r
341     if(pMatrix) {\r
342         param.m_matrix.Concat(*pMatrix);\r
343     }\r
344     if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) {\r
345         param.m_iPart = FWL_PART_FRM_Border;\r
346         pTheme->DrawBackground(&param);\r
347     }\r
348     if ((m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_EdgeMask) != FWL_WGTSTYLE_EdgeNone) {\r
349         CFX_RectF rtEdge;\r
350         GetEdgeRect(rtEdge);\r
351         param.m_iPart = FWL_PART_FRM_Edge;\r
352         param.m_rtPart = rtEdge;\r
353         param.m_dwStates = iState;\r
354         pTheme->DrawBackground(&param);\r
355     }\r
356     if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Caption) {\r
357         param.m_iPart = FWL_PART_FRM_Caption;\r
358         param.m_dwStates = iState;\r
359         param.m_rtPart = m_rtCaption;\r
360         pTheme->DrawBackground(&param);\r
361         DrawCaptionText(pGraphics, pTheme, pMatrix);\r
362     } else if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_NarrowCaption) {\r
363         param.m_iPart = FWL_PART_FRM_NarrowCaption;\r
364         param.m_dwStates = iState;\r
365         param.m_rtPart = m_rtCaption;\r
366         pTheme->DrawBackground(&param);\r
367         DrawCaptionText(pGraphics, pTheme, pMatrix);\r
368     }\r
369     if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Icon) {\r
370         param.m_iPart = FWL_PART_FRM_Icon;\r
371         if (HasIcon()) {\r
372             DrawIconImage(pGraphics, pTheme, pMatrix);\r
373         }\r
374     }\r
375 #if (_FX_OS_==_FX_MACOSX_)\r
376     {\r
377         if (m_pCloseBox) {\r
378             param.m_iPart = FWL_PART_FRM_CloseBox;\r
379             param.m_dwStates = m_pCloseBox->GetPartState();\r
380             if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) {\r
381                 param.m_dwStates = FWL_PARTSTATE_FRM_Disabled;\r
382             } else if (FWL_PARTSTATE_FRM_Normal == param.m_dwStates && m_bMouseIn) {\r
383                 param.m_dwStates = FWL_PARTSTATE_FRM_Hover;\r
384             }\r
385             param.m_rtPart = m_pCloseBox->m_rtBtn;\r
386             pTheme->DrawBackground(&param);\r
387         }\r
388         if (m_pMaxBox) {\r
389             param.m_iPart = FWL_PART_FRM_MaximizeBox;\r
390             param.m_dwStates =  m_pMaxBox->GetPartState();\r
391             if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) {\r
392                 param.m_dwStates = FWL_PARTSTATE_FRM_Disabled;\r
393             } else if (FWL_PARTSTATE_FRM_Normal == param.m_dwStates && m_bMouseIn) {\r
394                 param.m_dwStates = FWL_PARTSTATE_FRM_Hover;\r
395             }\r
396             param.m_rtPart = m_pMaxBox->m_rtBtn;\r
397             param.m_dwData = m_bMaximized;\r
398             pTheme->DrawBackground(&param);\r
399         }\r
400         if (m_pMinBox) {\r
401             param.m_iPart = FWL_PART_FRM_MinimizeBox;\r
402             param.m_dwStates = m_pMinBox->GetPartState();\r
403             if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) {\r
404                 param.m_dwStates = FWL_PARTSTATE_FRM_Disabled;\r
405             } else if (FWL_PARTSTATE_FRM_Normal == param.m_dwStates && m_bMouseIn) {\r
406                 param.m_dwStates = FWL_PARTSTATE_FRM_Hover;\r
407             }\r
408             param.m_rtPart = m_pMinBox->m_rtBtn;\r
409             pTheme->DrawBackground(&param);\r
410         }\r
411         m_bMouseIn = FALSE;\r
412     }\r
413 #else\r
414     {\r
415         if (m_pCloseBox) {\r
416             param.m_iPart = FWL_PART_FRM_CloseBox;\r
417             param.m_dwStates = m_pCloseBox->GetPartState();\r
418             param.m_rtPart = m_pCloseBox->m_rtBtn;\r
419             pTheme->DrawBackground(&param);\r
420         }\r
421         if (m_pMaxBox) {\r
422             param.m_iPart = FWL_PART_FRM_MaximizeBox;\r
423             param.m_dwStates = m_pMaxBox->GetPartState();\r
424             param.m_rtPart = m_pMaxBox->m_rtBtn;\r
425             param.m_dwData = m_bMaximized;\r
426             pTheme->DrawBackground(&param);\r
427         }\r
428         if (m_pMinBox) {\r
429             param.m_iPart = FWL_PART_FRM_MinimizeBox;\r
430             param.m_dwStates = m_pMinBox->GetPartState();\r
431             param.m_rtPart = m_pMinBox->m_rtBtn;\r
432             pTheme->DrawBackground(&param);\r
433         }\r
434     }\r
435 #endif\r
436     return FWL_ERR_Succeeded;\r
437 }\r
438 FWL_FORMSIZE CFWL_FormImp::GetFormSize()\r
439 {\r
440     return m_eFormSize;\r
441 }\r
442 FWL_ERR CFWL_FormImp::SetFormSize(FWL_FORMSIZE eFormSize)\r
443 {\r
444     m_eFormSize = eFormSize;\r
445     return FWL_ERR_Succeeded;\r
446 }\r
447 IFWL_Widget* CFWL_FormImp::DoModal()\r
448 {\r
449     IFWL_NoteThread *pThread = GetOwnerThread();\r
450     _FWL_RETURN_VALUE_IF_FAIL(pThread, NULL);\r
451     IFWL_NoteDriver *pDriver = pThread->GetNoteDriver();\r
452     _FWL_RETURN_VALUE_IF_FAIL(pDriver, NULL);\r
453     m_pNoteLoop = FX_NEW CFWL_NoteLoop(this);\r
454     pDriver->PushNoteLoop((IFWL_NoteLoop*)m_pNoteLoop);\r
455     m_bDoModalFlag = TRUE;\r
456     SetStates(FWL_WGTSTATE_Invisible, FALSE);\r
457     pDriver->Run();\r
458 #if (_FX_OS_==_FX_MACOSX_)\r
459 #else\r
460     pDriver->PopNoteLoop();\r
461 #endif\r
462     delete m_pNoteLoop;\r
463     m_pNoteLoop = NULL;\r
464     return NULL;\r
465 }\r
466 IFWL_Widget* CFWL_FormImp::DoModal(FX_DWORD &dwCommandID)\r
467 {\r
468     return DoModal();\r
469 }\r
470 FWL_ERR CFWL_FormImp::EndDoModal()\r
471 {\r
472     _FWL_RETURN_VALUE_IF_FAIL(m_pNoteLoop, FWL_ERR_Indefinite);\r
473     m_bDoModalFlag = FALSE;\r
474 #if (_FX_OS_==_FX_MACOSX_)\r
475     m_pNoteLoop->EndModalLoop();\r
476     IFWL_NoteThread *pThread = GetOwnerThread();\r
477     _FWL_RETURN_VALUE_IF_FAIL(pThread, NULL);\r
478     CFWL_NoteDriver *pDriver = (CFWL_NoteDriver*)pThread->GetNoteDriver();\r
479     _FWL_RETURN_VALUE_IF_FAIL(pDriver, NULL);\r
480     pDriver->PopNoteLoop();\r
481     SetStates(FWL_WGTSTATE_Invisible, TRUE);\r
482     return FWL_ERR_Succeeded;\r
483 #else\r
484     SetStates(FWL_WGTSTATE_Invisible, TRUE);\r
485     return m_pNoteLoop->EndModalLoop();\r
486 #endif\r
487 }\r
488 FWL_ERR CFWL_FormImp::SetBorderRegion(CFX_Path *pPath)\r
489 {\r
490     return FWL_ERR_Succeeded;\r
491 }\r
492 void CFWL_FormImp::DrawBackground(CFX_Graphics *pGraphics, IFWL_ThemeProvider *pTheme)\r
493 {\r
494     CFWL_ThemeBackground param;\r
495     param.m_pWidget = m_pInterface;\r
496     param.m_iPart = FWL_PART_FRM_Background;\r
497     param.m_pGraphics = pGraphics;\r
498     param.m_rtPart = m_rtRelative;\r
499     param.m_rtPart.Deflate(m_fCYBorder, m_rtCaption.height, m_fCYBorder, m_fCXBorder);\r
500     pTheme->DrawBackground(&param);\r
501 }\r
502 CFWL_WidgetImp* CFWL_FormImp::GetSubFocus()\r
503 {\r
504     return m_pSubFocus;\r
505 }\r
506 void CFWL_FormImp::SetSubFocus(CFWL_WidgetImp *pWidget)\r
507 {\r
508     m_pSubFocus = pWidget;\r
509 }\r
510 CFX_MapAccelerators& CFWL_FormImp::GetAccelerator()\r
511 {\r
512     return m_mapAccelerators;\r
513 }\r
514 void CFWL_FormImp::SetAccelerator(CFX_MapAccelerators *pAccelerators)\r
515 {\r
516     _FWL_RETURN_IF_FAIL(pAccelerators);\r
517     m_mapAccelerators.RemoveAll();\r
518     FX_DWORD vrKey, rValue;\r
519     FX_POSITION pos = pAccelerators->GetStartPosition();\r
520     while (pos) {\r
521         pAccelerators->GetNextAssoc(pos, vrKey, rValue);\r
522         m_mapAccelerators.SetAt(vrKey, rValue);\r
523     }\r
524 }\r
525 void CFWL_FormImp::ShowChildWidget(IFWL_Widget *pParent)\r
526 {\r
527     IFWL_App *pApp = FWL_GetApp();\r
528     _FWL_RETURN_IF_FAIL(pApp);\r
529     CFWL_WidgetMgr *pWidgetMgr = (CFWL_WidgetMgr*)pApp->GetWidgetMgr();\r
530     _FWL_RETURN_IF_FAIL(pWidgetMgr);\r
531     IFWL_Widget *pChild = pWidgetMgr->GetWidget(pParent, FWL_WGTRELATION_FirstChild);\r
532     while (pChild) {\r
533         pWidgetMgr->ShowWidget_Native(pChild);\r
534         ShowChildWidget(pChild);\r
535         pChild = pWidgetMgr->GetWidget(pChild, FWL_WGTRELATION_NextSibling);\r
536     }\r
537 }\r
538 void CFWL_FormImp::RemoveSysButtons()\r
539 {\r
540     m_rtCaption.Reset();\r
541     if (m_pCloseBox) {\r
542         delete m_pCloseBox;\r
543         m_pCloseBox = NULL;\r
544     }\r
545     if (m_pMinBox) {\r
546         delete m_pMinBox;\r
547         m_pMinBox = NULL;\r
548     }\r
549     if (m_pMaxBox) {\r
550         delete m_pMaxBox;\r
551         m_pMaxBox = NULL;\r
552     }\r
553     if (m_pCaptionBox) {\r
554         delete m_pCaptionBox;\r
555         m_pCaptionBox = NULL;\r
556     }\r
557 }\r
558 void CFWL_FormImp::CalcContentRect(CFX_RectF &rtContent)\r
559 {\r
560 #ifdef FWL_UseMacSystemBorder\r
561     rtContent = m_rtRelative;\r
562 #else\r
563     GetEdgeRect(rtContent);\r
564     if (HasEdge()) {\r
565         FX_FLOAT fEdge = GetEdgeWidth();\r
566         rtContent.Deflate(fEdge, fEdge);\r
567     }\r
568 #endif\r
569 }\r
570 CFWL_SysBtn* CFWL_FormImp::GetSysBtnAtPoint(FX_FLOAT fx, FX_FLOAT fy)\r
571 {\r
572     if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) {\r
573         return m_pCloseBox;\r
574     }\r
575     if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) {\r
576         return m_pMaxBox;\r
577     }\r
578     if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) {\r
579         return m_pMinBox;\r
580     }\r
581     if (m_pCaptionBox && m_pCaptionBox->m_rtBtn.Contains(fx, fy)) {\r
582         return m_pCaptionBox;\r
583     }\r
584     return NULL;\r
585 }\r
586 CFWL_SysBtn* CFWL_FormImp::GetSysBtnByState(FX_DWORD dwState)\r
587 {\r
588     if (m_pCloseBox && (m_pCloseBox->m_dwState & dwState)) {\r
589         return m_pCloseBox;\r
590     }\r
591     if (m_pMaxBox && (m_pMaxBox->m_dwState & dwState)) {\r
592         return m_pMaxBox;\r
593     }\r
594     if (m_pMinBox && (m_pMinBox->m_dwState & dwState)) {\r
595         return m_pMinBox;\r
596     }\r
597     if (m_pCaptionBox && (m_pCaptionBox->m_dwState & dwState)) {\r
598         return m_pCaptionBox;\r
599     }\r
600     return NULL;\r
601 }\r
602 CFWL_SysBtn* CFWL_FormImp::GetSysBtnByIndex(FX_INT32 nIndex)\r
603 {\r
604     if (nIndex < 0) {\r
605         return NULL;\r
606     }\r
607     CFX_PtrArray arrBtn;\r
608     if (m_pMinBox) {\r
609         arrBtn.Add(m_pMinBox);\r
610     }\r
611     if (m_pMaxBox) {\r
612         arrBtn.Add(m_pMaxBox);\r
613     }\r
614     if (m_pCloseBox) {\r
615         arrBtn.Add(m_pCloseBox);\r
616     }\r
617     return (CFWL_SysBtn*) arrBtn[nIndex];\r
618 }\r
619 FX_INT32 CFWL_FormImp::GetSysBtnIndex(CFWL_SysBtn *pBtn)\r
620 {\r
621     CFX_PtrArray arrBtn;\r
622     if (m_pMinBox) {\r
623         arrBtn.Add(m_pMinBox);\r
624     }\r
625     if (m_pMaxBox) {\r
626         arrBtn.Add(m_pMaxBox);\r
627     }\r
628     if (m_pCloseBox) {\r
629         arrBtn.Add(m_pCloseBox);\r
630     }\r
631     return arrBtn.Find(pBtn);\r
632 }\r
633 FX_FLOAT CFWL_FormImp::GetCaptionHeight()\r
634 {\r
635     FX_DWORD dwCapacity = 0;\r
636     if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Caption) {\r
637         dwCapacity = FWL_WGTCAPACITY_FRM_CYCaption;\r
638     } else if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_NarrowCaption) {\r
639         dwCapacity = FWL_WGTCAPACITY_FRM_CYNarrowCaption;\r
640     }\r
641     if (dwCapacity > 0) {\r
642         FX_FLOAT *pfCapHeight = (FX_FLOAT*)GetThemeCapacity(dwCapacity);\r
643         _FWL_RETURN_VALUE_IF_FAIL(pfCapHeight, 0);\r
644         return *pfCapHeight;\r
645     }\r
646     return 0;\r
647 }\r
648 void CFWL_FormImp::DrawCaptionText(CFX_Graphics *pGs, IFWL_ThemeProvider *pTheme, const CFX_Matrix* pMatrix )\r
649 {\r
650     CFX_WideString wsText;\r
651     IFWL_DataProvider *pData = m_pProperties->m_pDataProvider;\r
652     pData->GetCaption(m_pInterface, wsText);\r
653     if (wsText.IsEmpty()) {\r
654         return;\r
655     }\r
656     CFWL_ThemeText textParam;\r
657     textParam.m_pWidget = m_pInterface;\r
658     textParam.m_iPart = FWL_PART_FRM_Caption;\r
659     textParam.m_dwStates = FWL_PARTSTATE_FRM_Normal;\r
660     textParam.m_pGraphics = pGs;\r
661     if (pMatrix) {\r
662         textParam.m_matrix.Concat(*pMatrix);\r
663     }\r
664     CFX_RectF rtText;\r
665     if (m_bCustomizeLayout) {\r
666         rtText = m_rtCaptionText;\r
667         rtText.top -= 5;\r
668     } else {\r
669         rtText = m_rtCaption;\r
670         FX_FLOAT fpos;\r
671         fpos = HasIcon() ? 29.0f : 13.0f;\r
672         rtText.left += fpos;\r
673     }\r
674     textParam.m_rtPart = rtText;\r
675     textParam.m_wsText = wsText;\r
676     textParam.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine | FDE_TTOSTYLE_Ellipsis;\r
677     textParam.m_iTTOAlign = m_bCustomizeLayout ? FDE_TTOALIGNMENT_Center : FDE_TTOALIGNMENT_CenterLeft;\r
678     pTheme->DrawText(&textParam);\r
679 }\r
680 void CFWL_FormImp::DrawIconImage(CFX_Graphics *pGs, IFWL_ThemeProvider *pTheme, const CFX_Matrix* pMatrix )\r
681 {\r
682     IFWL_FormDP *pData = (IFWL_FormDP *)m_pProperties->m_pDataProvider;\r
683     CFWL_ThemeBackground param;\r
684     param.m_pWidget = m_pInterface;\r
685     param.m_iPart = FWL_PART_FRM_Icon;\r
686     param.m_pGraphics = pGs;\r
687     param.m_pImage = pData->GetIcon(m_pInterface, FALSE);\r
688     param.m_rtPart = m_rtIcon;\r
689     if(pMatrix) {\r
690         param.m_matrix.Concat(*pMatrix);\r
691     }\r
692     pTheme->DrawBackground(&param);\r
693 }\r
694 void CFWL_FormImp::GetEdgeRect(CFX_RectF &rtEdge)\r
695 {\r
696     rtEdge = m_rtRelative;\r
697     if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) {\r
698         FX_FLOAT fCX = GetBorderSize();\r
699         FX_FLOAT fCY = GetBorderSize(FALSE);\r
700         rtEdge.Deflate(fCX, m_rtCaption.Height(), fCX, fCY);\r
701     }\r
702 }\r
703 void CFWL_FormImp::SetWorkAreaRect()\r
704 {\r
705     m_rtRestore = m_pProperties->m_rtWidget;\r
706     CFWL_WidgetMgr *pWidgetMgr = (CFWL_WidgetMgr*)FWL_GetWidgetMgr();\r
707     _FWL_RETURN_IF_FAIL(pWidgetMgr);\r
708     m_bSetMaximize = TRUE;\r
709     pWidgetMgr->SetMaximize_Native(m_pInterface);\r
710     Repaint(&m_rtRelative);\r
711 }\r
712 void CFWL_FormImp::SetCursor(FX_FLOAT fx, FX_FLOAT fy)\r
713 {\r
714     IFWL_AdapterNative *pNative = FWL_GetAdapterNative();\r
715     IFWL_AdapterCursorMgr *pCursorMgr = pNative->GetCursorMgr();\r
716     _FWL_RETURN_IF_FAIL(pCursorMgr);\r
717     FX_DWORD dwHitTest = HitTest(fx, fy);\r
718     switch (dwHitTest) {\r
719         case FWL_WGTHITTEST_Right: {\r
720                 FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeWE);\r
721                 pCursorMgr->SetCursor(hCursor);\r
722                 pCursorMgr->ShowCursor(TRUE);\r
723                 m_eResizeType = FORM_RESIZETYPE_Right;\r
724                 break;\r
725             }\r
726         case FWL_WGTHITTEST_Bottom: {\r
727                 FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNS);\r
728                 pCursorMgr->SetCursor(hCursor);\r
729                 pCursorMgr->ShowCursor(TRUE);\r
730                 m_eResizeType = FORM_RESIZETYPE_Bottom;\r
731                 break;\r
732             }\r
733         case FWL_WGTHITTEST_Left: {\r
734                 FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeWE);\r
735                 pCursorMgr->SetCursor(hCursor);\r
736                 pCursorMgr->ShowCursor(TRUE);\r
737                 m_eResizeType = FORM_RESIZETYPE_Left;\r
738                 break;\r
739             }\r
740         case FWL_WGTHITTEST_Top: {\r
741                 FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNS);\r
742                 pCursorMgr->SetCursor(hCursor);\r
743                 pCursorMgr->ShowCursor(TRUE);\r
744                 m_eResizeType = FORM_RESIZETYPE_Top;\r
745                 break;\r
746             }\r
747         case FWL_WGTHITTEST_LeftTop: {\r
748                 FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNWSE);\r
749                 pCursorMgr->SetCursor(hCursor);\r
750                 pCursorMgr->ShowCursor(TRUE);\r
751                 m_eResizeType = FORM_RESIZETYPE_LeftTop;\r
752                 break;\r
753             }\r
754         case FWL_WGTHITTEST_LeftBottom: {\r
755                 FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNESW);\r
756                 pCursorMgr->SetCursor(hCursor);\r
757                 pCursorMgr->ShowCursor(TRUE);\r
758                 m_eResizeType = FORM_RESIZETYPE_LeftBottom;\r
759                 break;\r
760             }\r
761         case FWL_WGTHITTEST_RightTop: {\r
762                 FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNESW);\r
763                 pCursorMgr->SetCursor(hCursor);\r
764                 pCursorMgr->ShowCursor(TRUE);\r
765                 m_eResizeType = FORM_RESIZETYPE_RightTop;\r
766                 break;\r
767             }\r
768         case FWL_WGTHITTEST_RightBottom: {\r
769                 FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNWSE);\r
770                 pCursorMgr->SetCursor(hCursor);\r
771                 pCursorMgr->ShowCursor(TRUE);\r
772                 m_eResizeType = FORM_RESIZETYPE_RightBottom;\r
773                 break;\r
774             }\r
775         default: {\r
776                 FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_Arrow);\r
777                 pCursorMgr->SetCursor(hCursor);\r
778                 pCursorMgr->ShowCursor(TRUE);\r
779             }\r
780     }\r
781 }\r
782 void CFWL_FormImp::Layout()\r
783 {\r
784     GetRelativeRect(m_rtRelative);\r
785 #ifndef FWL_UseMacSystemBorder\r
786     ReSetSysBtn();\r
787 #endif\r
788     if (m_pContent) {\r
789         CFX_RectF rtClient;\r
790         GetClientRect(rtClient);\r
791         m_pContent->SetWidgetRect(rtClient);\r
792         m_pContent->Update();\r
793     }\r
794 }\r
795 void CFWL_FormImp::ReSetSysBtn()\r
796 {\r
797     m_fCXBorder = *(FX_FLOAT*)GetThemeCapacity(FWL_WGTCAPACITY_CXBorder);\r
798     m_fCYBorder = *(FX_FLOAT*)GetThemeCapacity(FWL_WGTCAPACITY_CYBorder);\r
799     RemoveSysButtons();\r
800     IFWL_ThemeProvider *pTheme = m_pProperties->m_pThemeProvider;\r
801     m_bCustomizeLayout = pTheme->IsCustomizedLayout(m_pInterface);\r
802     FX_FLOAT fCapHeight = GetCaptionHeight();\r
803     if (fCapHeight > 0) {\r
804         m_rtCaption = m_rtRelative;\r
805         m_rtCaption.height = fCapHeight;\r
806     }\r
807     m_iSysBox = 0;\r
808     if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_CloseBox) {\r
809         m_pCloseBox = FX_NEW CFWL_SysBtn;\r
810         if (m_bCustomizeLayout) {\r
811             CFWL_ThemeBackground param;\r
812             param.m_pWidget = m_pInterface;\r
813             param.m_iPart = FWL_PART_FRM_CloseBox;\r
814             pTheme->GetPartRect(&param, m_pCloseBox->m_rtBtn);\r
815         } else {\r
816             m_pCloseBox->m_rtBtn.Set(m_rtRelative.right() - FWL_SYSBTNMARGIN - FWL_SYSBTNSIZE,\r
817                                      FWL_SYSBTNMARGIN,\r
818                                      FWL_SYSBTNSIZE,\r
819                                      FWL_SYSBTNSIZE);\r
820         }\r
821         m_iSysBox ++;\r
822     }\r
823     if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MaximizeBox) {\r
824         m_pMaxBox = FX_NEW CFWL_SysBtn;\r
825         if (m_bCustomizeLayout) {\r
826             CFWL_ThemeBackground param;\r
827             param.m_pWidget = m_pInterface;\r
828             param.m_iPart = FWL_PART_FRM_MaximizeBox;\r
829             pTheme->GetPartRect(&param, m_pMaxBox->m_rtBtn);\r
830         } else {\r
831             if (m_pCloseBox) {\r
832                 m_pMaxBox->m_rtBtn.Set(m_pCloseBox->m_rtBtn.left - FWL_SYSBTNSPAN - FWL_SYSBTNSIZE,\r
833                                        m_pCloseBox->m_rtBtn.top,\r
834                                        FWL_SYSBTNSIZE,\r
835                                        FWL_SYSBTNSIZE);\r
836             } else {\r
837                 m_pMaxBox->m_rtBtn.Set(m_rtRelative.right() - FWL_SYSBTNMARGIN - FWL_SYSBTNSIZE,\r
838                                        FWL_SYSBTNMARGIN,\r
839                                        FWL_SYSBTNSIZE,\r
840                                        FWL_SYSBTNSIZE);\r
841             }\r
842         }\r
843         m_iSysBox ++;\r
844     }\r
845     if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MinimizeBox) {\r
846         m_pMinBox = FX_NEW CFWL_SysBtn;\r
847         if (m_bCustomizeLayout) {\r
848             CFWL_ThemeBackground param;\r
849             param.m_pWidget = m_pInterface;\r
850             param.m_iPart = FWL_PART_FRM_MinimizeBox;\r
851             pTheme->GetPartRect(&param, m_pMinBox->m_rtBtn);\r
852         } else {\r
853             if (m_pMaxBox) {\r
854                 m_pMinBox->m_rtBtn.Set(m_pMaxBox->m_rtBtn.left - FWL_SYSBTNSPAN - FWL_SYSBTNSIZE,\r
855                                        m_pMaxBox->m_rtBtn.top,\r
856                                        FWL_SYSBTNSIZE,\r
857                                        FWL_SYSBTNSIZE);\r
858             } else if (m_pCloseBox) {\r
859                 m_pMinBox->m_rtBtn.Set(m_pCloseBox->m_rtBtn.left - FWL_SYSBTNSPAN - FWL_SYSBTNSIZE,\r
860                                        m_pCloseBox->m_rtBtn.top,\r
861                                        FWL_SYSBTNSIZE,\r
862                                        FWL_SYSBTNSIZE);\r
863             } else {\r
864                 m_pMinBox->m_rtBtn.Set(m_rtRelative.right() - FWL_SYSBTNMARGIN - FWL_SYSBTNSIZE,\r
865                                        FWL_SYSBTNMARGIN,\r
866                                        FWL_SYSBTNSIZE,\r
867                                        FWL_SYSBTNSIZE);\r
868             }\r
869         }\r
870         m_iSysBox ++;\r
871     }\r
872     IFWL_FormDP *pData = (IFWL_FormDP *)m_pProperties->m_pDataProvider;\r
873     if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Icon && pData->GetIcon(m_pInterface, FALSE)) {\r
874         if (m_bCustomizeLayout) {\r
875             CFWL_ThemeBackground param;\r
876             param.m_pWidget = m_pInterface;\r
877             param.m_iPart = FWL_PART_FRM_Icon;\r
878             CFX_WideString wsText;\r
879             m_pProperties->m_pDataProvider->GetCaption(m_pInterface, wsText);\r
880             param.m_pData = &wsText;\r
881             pTheme->GetPartRect(&param, m_rtIcon);\r
882         } else {\r
883             m_rtIcon.Set(5, (m_rtCaption.height - m_fSmallIconSz) / 2, m_fSmallIconSz, m_fSmallIconSz);\r
884         }\r
885     }\r
886     if (m_bCustomizeLayout) {\r
887         CFWL_ThemeText parma;\r
888         parma.m_pWidget = m_pInterface;\r
889         parma.m_iPart = FWL_PART_FRM_HeadText;\r
890         m_pProperties->m_pDataProvider->GetCaption(m_pInterface, parma.m_wsText);\r
891         pTheme->GetPartRect(&parma, m_rtCaptionText);\r
892     }\r
893 }\r
894 void CFWL_FormImp::RegisterForm()\r
895 {\r
896     IFWL_NoteThread *pThread = GetOwnerThread();\r
897     _FWL_RETURN_IF_FAIL(pThread);\r
898     CFWL_NoteDriver *pDriver = (CFWL_NoteDriver*)pThread->GetNoteDriver();\r
899     _FWL_RETURN_IF_FAIL(pDriver);\r
900     pDriver->RegisterForm(this);\r
901 }\r
902 void CFWL_FormImp::UnRegisterForm()\r
903 {\r
904     IFWL_NoteThread *pThread = GetOwnerThread();\r
905     _FWL_RETURN_IF_FAIL(pThread);\r
906     CFWL_NoteDriver *pDriver = (CFWL_NoteDriver*)pThread->GetNoteDriver();\r
907     _FWL_RETURN_IF_FAIL(pDriver);\r
908     pDriver->UnRegisterForm(this);\r
909 }\r
910 FX_BOOL CFWL_FormImp::IsDoModal()\r
911 {\r
912     return m_bDoModalFlag;\r
913 }\r
914 void CFWL_FormImp::SetThemeData()\r
915 {\r
916     m_fSmallIconSz = *(FX_FLOAT *)GetThemeCapacity(FWL_WGTCAPACITY_FRM_SmallIcon);\r
917     m_fBigIconSz = *(FX_FLOAT *)GetThemeCapacity(FWL_WGTCAPACITY_FRM_BigIcon);\r
918 }\r
919 FX_BOOL CFWL_FormImp::HasIcon()\r
920 {\r
921     IFWL_FormDP *pData = (IFWL_FormDP *)m_pProperties->m_pDataProvider;\r
922     return pData->GetIcon(m_pInterface, FALSE) ? TRUE : FALSE;\r
923 }\r
924 void CFWL_FormImp::UpdateIcon()\r
925 {\r
926     CFWL_WidgetMgr *pWidgetMgr = (CFWL_WidgetMgr*)FWL_GetWidgetMgr();\r
927     _FWL_RETURN_IF_FAIL(pWidgetMgr);\r
928     IFWL_FormDP *pData = (IFWL_FormDP *)m_pProperties->m_pDataProvider;\r
929     CFX_DIBitmap *pBigIcon = pData->GetIcon(m_pInterface, TRUE);\r
930     CFX_DIBitmap *pSmallIcon = pData->GetIcon(m_pInterface, FALSE);\r
931     if (pBigIcon && pBigIcon != m_pBigIcon) {\r
932         m_pBigIcon = pBigIcon;\r
933         pWidgetMgr->SetWidgetIcon_Native(m_pInterface, m_pBigIcon, TRUE);\r
934     }\r
935     if (pSmallIcon && pSmallIcon != m_pSmallIcon) {\r
936         m_pSmallIcon = pSmallIcon;\r
937         pWidgetMgr->SetWidgetIcon_Native(m_pInterface, m_pBigIcon, FALSE);\r
938     }\r
939 }\r
940 void CFWL_FormImp::UpdateCaption()\r
941 {\r
942     CFWL_WidgetMgr *pWidgetMgr = (CFWL_WidgetMgr*)FWL_GetWidgetMgr();\r
943     _FWL_RETURN_IF_FAIL(pWidgetMgr);\r
944     IFWL_FormDP *pData = (IFWL_FormDP *)m_pProperties->m_pDataProvider;\r
945     _FWL_RETURN_IF_FAIL(pData);\r
946     CFX_WideString text;\r
947     pData->GetCaption(m_pInterface, text);\r
948     pWidgetMgr->SetWidgetCaption_Native(m_pInterface, text);\r
949 }\r
950 void  CFWL_FormImp::DoWidthLimit(FX_FLOAT &fLeft, FX_FLOAT &fWidth, FX_FLOAT fCurX, FX_FLOAT fSpace, FX_FLOAT fLimitMin, FX_FLOAT fLimitMax, FX_BOOL bLeft)\r
951 {\r
952     FX_FLOAT fx = fCurX;\r
953     FX_FLOAT fy = 0 ;\r
954     TransformTo(NULL, fx, fy);\r
955     FX_FLOAT fTemp = bLeft ? (fWidth - fx + fLeft + fSpace ) : (fx - fLeft + fSpace);\r
956     if (fTemp >= fLimitMin && fTemp <= fLimitMax) {\r
957         fWidth = fTemp;\r
958         fLeft += bLeft ? (fx - fLeft - fSpace ) : 0;\r
959     } else {\r
960         if (fTemp < fLimitMin && fWidth > fLimitMin) {\r
961             fLeft += bLeft ? (fWidth - fLimitMin) : 0;\r
962             fWidth = fLimitMin;\r
963         } else if (fTemp > fLimitMax && fWidth < fLimitMax) {\r
964             fLeft -= bLeft ? (fLimitMax - fWidth) : 0;\r
965             fWidth = fLimitMax;\r
966         }\r
967     }\r
968 }\r
969 void  CFWL_FormImp::DoHeightLimit(FX_FLOAT &fTop, FX_FLOAT &fHeight, FX_FLOAT fCurY, FX_FLOAT fSpace, FX_FLOAT fLimitMin, FX_FLOAT fLimitMax, FX_BOOL bTop)\r
970 {\r
971     FX_FLOAT fx = 0;\r
972     FX_FLOAT fy = fCurY ;\r
973     TransformTo(NULL, fx, fy);\r
974     FX_FLOAT fTemp = bTop ? (fHeight - fy + fTop + fSpace ) : (fy - fTop + fSpace);\r
975     if (fTemp >= fLimitMin && fTemp <= fLimitMax) {\r
976         fHeight = fTemp;\r
977         fTop += bTop ? (fy - fTop - fSpace ) : 0;\r
978     } else {\r
979         if (fTemp < fLimitMin && fHeight > fLimitMin) {\r
980             fTop += bTop ? (fHeight - fLimitMin) : 0;\r
981             fHeight = fLimitMin;\r
982         } else if (fTemp > fLimitMax && fHeight < fLimitMax) {\r
983             fTop -= bTop ? (fLimitMax - fHeight) : 0;\r
984             fHeight = fLimitMax;\r
985         }\r
986     }\r
987 }\r
988 CFWL_FormDelegate::CFWL_FormDelegate(CFWL_FormImp *pOwner)\r
989     : m_pOwner(pOwner)\r
990 {\r
991 }\r
992 FX_INT32 CFWL_FormDelegate::OnProcessMessage(CFWL_Message *pMessage)\r
993 {\r
994 #ifdef FWL_UseMacSystemBorder\r
995     _FWL_RETURN_VALUE_IF_FAIL(pMessage, 0);\r
996     FX_DWORD dwMsgCode = pMessage->GetClassID();\r
997     FX_INT32 iRet = 1;\r
998     switch (dwMsgCode) {\r
999         case FWL_MSGHASH_Activate: {\r
1000                 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Deactivated;\r
1001                 m_pOwner->Repaint(&m_pOwner->m_rtRelative);\r
1002                 break;\r
1003             }\r
1004         case FWL_MSGHASH_Deactivate: {\r
1005                 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Deactivated;\r
1006                 m_pOwner->Repaint(&m_pOwner->m_rtRelative);\r
1007                 break;\r
1008             }\r
1009     }\r
1010     return FWL_ERR_Succeeded;\r
1011 #else\r
1012     _FWL_RETURN_VALUE_IF_FAIL(pMessage, 0);\r
1013     FX_DWORD dwMsgCode = pMessage->GetClassID();\r
1014     FX_INT32 iRet = 1;\r
1015     switch (dwMsgCode) {\r
1016         case FWL_MSGHASH_Activate: {\r
1017                 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Deactivated;\r
1018                 IFWL_NoteThread *pThread = m_pOwner->GetOwnerThread();\r
1019                 CFWL_NoteDriver *pDriver = (CFWL_NoteDriver*)pThread->GetNoteDriver();\r
1020                 CFWL_WidgetImp *pSubFocusImp = m_pOwner->GetSubFocus();\r
1021                 IFWL_Widget *pSubFocus = pSubFocusImp ? pSubFocusImp->GetInterface() : NULL;\r
1022                 if (pSubFocus && pSubFocus != pDriver->GetFocus()) {\r
1023                     pDriver->SetFocus(pSubFocus);\r
1024                 }\r
1025                 m_pOwner->Repaint(&m_pOwner->m_rtRelative);\r
1026                 break;\r
1027             }\r
1028         case FWL_MSGHASH_Deactivate: {\r
1029                 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Deactivated;\r
1030                 IFWL_NoteThread *pThread = m_pOwner->GetOwnerThread();\r
1031                 CFWL_NoteDriver *pDriver = (CFWL_NoteDriver*)pThread->GetNoteDriver();\r
1032                 CFWL_WidgetImp *pSubFocusImp = m_pOwner->GetSubFocus();\r
1033                 IFWL_Widget *pSubFocus = pSubFocusImp ? pSubFocusImp->GetInterface() : NULL;\r
1034                 if (pSubFocus) {\r
1035                     if (pSubFocus == pDriver->GetFocus()) {\r
1036                         pDriver->SetFocus(NULL);\r
1037                     } else if (pSubFocus->GetStates() & FWL_WGTSTATE_Focused) {\r
1038                         CFWL_MsgKillFocus ms;\r
1039                         IFWL_WidgetDelegate *pDelegate = pSubFocus->SetDelegate(NULL);\r
1040                         if (pDelegate) {\r
1041                             pDelegate->OnProcessMessage(&ms);\r
1042                         }\r
1043                     }\r
1044                 }\r
1045                 m_pOwner->Repaint(&m_pOwner->m_rtRelative);\r
1046                 break;\r
1047             }\r
1048         case FWL_MSGHASH_Mouse: {\r
1049                 CFWL_MsgMouse *pMsg = (CFWL_MsgMouse*)pMessage;\r
1050                 switch (pMsg->m_dwCmd) {\r
1051                     case FWL_MSGMOUSECMD_LButtonDown: {\r
1052                             OnLButtonDown(pMsg);\r
1053                             break;\r
1054                         }\r
1055                     case FWL_MSGMOUSECMD_LButtonUp: {\r
1056                             OnLButtonUp(pMsg);\r
1057                             break;\r
1058                         }\r
1059                     case FWL_MSGMOUSECMD_MouseMove: {\r
1060                             OnMouseMove(pMsg);\r
1061                             break;\r
1062                         }\r
1063                     case FWL_MSGMOUSECMD_MouseHover: {\r
1064                             OnMouseHover(pMsg);\r
1065                             break;\r
1066                         }\r
1067                     case FWL_MSGMOUSECMD_MouseLeave: {\r
1068                             OnMouseLeave(pMsg);\r
1069                             break;\r
1070                         }\r
1071                     case FWL_MSGMOUSECMD_LButtonDblClk: {\r
1072                             OnLButtonDblClk(pMsg);\r
1073                             break;\r
1074                         }\r
1075                 }\r
1076                 break;\r
1077             }\r
1078         case FWL_MSGHASH_Size: {\r
1079                 CFWL_WidgetMgr *pWidgetMgr = (CFWL_WidgetMgr*)FWL_GetWidgetMgr();\r
1080                 _FWL_RETURN_VALUE_IF_FAIL(pWidgetMgr, 0);\r
1081                 pWidgetMgr->AddRedrawCounts(m_pOwner->m_pInterface);\r
1082                 if (!m_pOwner->m_bSetMaximize) {\r
1083                     break;\r
1084                 }\r
1085                 m_pOwner->m_bSetMaximize = FALSE;\r
1086                 CFWL_MsgSize *pMsg = (CFWL_MsgSize*)pMessage;\r
1087                 CFX_RectF rt;\r
1088                 pWidgetMgr->GetWidgetRect_Native(m_pOwner->m_pInterface, rt);\r
1089                 m_pOwner->m_pProperties->m_rtWidget.left = rt.left;\r
1090                 m_pOwner->m_pProperties->m_rtWidget.top = rt.top;\r
1091                 m_pOwner->m_pProperties->m_rtWidget.width = (FX_FLOAT)pMsg->m_iWidth;\r
1092                 m_pOwner->m_pProperties->m_rtWidget.height = (FX_FLOAT)pMsg->m_iHeight;\r
1093                 m_pOwner->Update();\r
1094                 break;\r
1095             }\r
1096         case FWL_MSGHASH_WindowMove: {\r
1097                 OnWindowMove((CFWL_MsgWindowMove* )pMessage);\r
1098                 break;\r
1099             }\r
1100         case FWL_MSGHASH_Close: {\r
1101                 OnClose((CFWL_MsgClose* )pMessage);\r
1102                 break;\r
1103             }\r
1104         default: {\r
1105                 iRet = 0;\r
1106             }\r
1107     }\r
1108     return iRet;\r
1109 #endif\r
1110 }\r
1111 FWL_ERR CFWL_FormDelegate::OnProcessEvent(CFWL_Event *pEvent)\r
1112 {\r
1113     _FWL_RETURN_VALUE_IF_FAIL(pEvent, FWL_ERR_Indefinite);\r
1114     if (pEvent->GetClassID() == FWL_EVTHASH_Close && pEvent->m_pSrcTarget == m_pOwner->m_pInterface) {\r
1115     }\r
1116     return FWL_ERR_Succeeded;\r
1117 }\r
1118 FWL_ERR CFWL_FormDelegate::OnDrawWidget(CFX_Graphics *pGraphics, const CFX_Matrix *pMatrix )\r
1119 {\r
1120     return m_pOwner->DrawWidget(pGraphics, pMatrix);\r
1121 }\r
1122 void CFWL_FormDelegate::OnLButtonDown(CFWL_MsgMouse *pMsg)\r
1123 {\r
1124     m_pOwner->SetGrab(TRUE);\r
1125     m_pOwner->m_bLButtonDown = TRUE;\r
1126     m_pOwner->m_eResizeType = FORM_RESIZETYPE_None;\r
1127     CFWL_SysBtn *pPressBtn = m_pOwner->GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy);\r
1128     m_pOwner->m_iCaptureBtn = m_pOwner->GetSysBtnIndex(pPressBtn);\r
1129     CFX_RectF rtCap;\r
1130     rtCap.Set(m_pOwner->m_rtCaption.left + m_pOwner->m_fCYBorder,\r
1131               m_pOwner->m_rtCaption.top + m_pOwner->m_fCXBorder,\r
1132               m_pOwner->m_rtCaption.width - FWL_SYSBTNSIZE * m_pOwner->m_iSysBox - 2 * m_pOwner->m_fCYBorder,\r
1133               m_pOwner->m_rtCaption.height - m_pOwner->m_fCXBorder);\r
1134     if (pPressBtn) {\r
1135         pPressBtn->SetPressed();\r
1136         m_pOwner->Repaint(&pPressBtn->m_rtBtn);\r
1137     } else if (rtCap.Contains(pMsg->m_fx, pMsg->m_fy)) {\r
1138         m_pOwner->m_eResizeType = FORM_RESIZETYPE_Cap;\r
1139     } else if ((m_pOwner->m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) &&\r
1140                (m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize) &&\r
1141                !m_pOwner->m_bMaximized) {\r
1142         m_pOwner->SetCursor(pMsg->m_fx, pMsg->m_fy);\r
1143     }\r
1144     m_pOwner->m_InfoStart.m_ptStart.Set(pMsg->m_fx, pMsg->m_fy);\r
1145     m_pOwner->m_InfoStart.m_szStart.Set(m_pOwner->m_pProperties->m_rtWidget.width, m_pOwner->m_pProperties->m_rtWidget.height);\r
1146 }\r
1147 void CFWL_FormDelegate::OnLButtonUp(CFWL_MsgMouse *pMsg)\r
1148 {\r
1149     m_pOwner->SetGrab(FALSE);\r
1150     m_pOwner->m_bLButtonDown = FALSE;\r
1151     CFWL_SysBtn *pPointBtn = m_pOwner->GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy);\r
1152     CFWL_SysBtn *pPressedBtn = m_pOwner->GetSysBtnByIndex(m_pOwner->m_iCaptureBtn);\r
1153     if (!pPressedBtn || pPointBtn != pPressedBtn) {\r
1154         return;\r
1155     }\r
1156     if (pPressedBtn == m_pOwner->GetSysBtnByState(FWL_SYSBUTTONSTATE_Pressed)) {\r
1157         pPressedBtn->SetNormal();\r
1158     }\r
1159     if (pPressedBtn == m_pOwner->m_pMaxBox) {\r
1160         if (m_pOwner->m_bMaximized) {\r
1161             m_pOwner->SetWidgetRect(m_pOwner->m_rtRestore);\r
1162             m_pOwner->Update();\r
1163             m_pOwner->Repaint();\r
1164         } else {\r
1165             m_pOwner->SetWorkAreaRect();\r
1166             m_pOwner->Update();\r
1167         }\r
1168         m_pOwner->m_bMaximized = !m_pOwner->m_bMaximized;\r
1169     } else if (pPressedBtn == m_pOwner->m_pMinBox) {\r
1170         CFWL_WidgetMgr *pWidgetMgr = (CFWL_WidgetMgr*)FWL_GetWidgetMgr();\r
1171         _FWL_RETURN_IF_FAIL(pWidgetMgr);\r
1172         pWidgetMgr->SetMinimize_Native(m_pOwner->m_pInterface);\r
1173     } else {\r
1174         CFWL_EvtClose eClose;\r
1175         eClose.m_pSrcTarget = m_pOwner->m_pInterface;\r
1176         m_pOwner->DispatchEvent(&eClose);\r
1177     }\r
1178 }\r
1179 void CFWL_FormDelegate::OnMouseMove(CFWL_MsgMouse *pMsg)\r
1180 {\r
1181     CFWL_WidgetMgr *pWidgetMgr = (CFWL_WidgetMgr*)FWL_GetWidgetMgr();\r
1182     if (m_pOwner->m_bLButtonDown) {\r
1183         IFWL_AdapterNative *pNative = FWL_GetAdapterNative();\r
1184         IFWL_AdapterCursorMgr *pCursorMgr = pNative->GetCursorMgr();\r
1185         _FWL_RETURN_IF_FAIL(pCursorMgr);\r
1186         CFWL_SysBtn *pPressedBtn = m_pOwner->GetSysBtnByIndex(m_pOwner->m_iCaptureBtn);\r
1187         FX_FLOAT fTop, fLeft, fWidth, fHeight;\r
1188         fTop = m_pOwner->m_pProperties->m_rtWidget.top;\r
1189         fLeft = m_pOwner->m_pProperties->m_rtWidget.left;\r
1190         fWidth = m_pOwner->m_pProperties->m_rtWidget.width;\r
1191         fHeight = m_pOwner->m_pProperties->m_rtWidget.height;\r
1192         FX_FLOAT fWidthMax, fWidthMin, fHeightMax, fHeightMin;\r
1193         if (m_pOwner->m_pContent) {\r
1194             m_pOwner->GetContent()->GetMaxSize(fWidthMax, fHeightMax);\r
1195             m_pOwner->GetContent()->GetMinSize(fWidthMin, fHeightMin);\r
1196         } else {\r
1197             fWidthMax = fHeightMax = 1024 * 4;\r
1198             fWidthMin = fHeightMin = 0;\r
1199         }\r
1200         FX_BOOL bWidthlimit = (fWidthMin != 0 || fWidthMax != 0);\r
1201         FX_BOOL bHeightlimit = (fHeightMin != 0 || fHeightMax != 0);\r
1202         FX_BOOL bSizelimit = bWidthlimit || bHeightlimit;\r
1203         if (fWidthMax != 0 || fHeightMax != 0 || fWidthMin != 0 || fHeightMin != 0) {\r
1204             bSizelimit = TRUE;\r
1205         }\r
1206         if (pPressedBtn) {\r
1207             if (!pPressedBtn->m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) {\r
1208                 pPressedBtn->SetNormal();\r
1209             } else {\r
1210                 pPressedBtn->SetPressed();\r
1211             }\r
1212             m_pOwner->Repaint(&pPressedBtn->m_rtBtn);\r
1213             return;\r
1214         } else if (m_pOwner->m_bMaximized) {\r
1215             return;\r
1216         } else if (m_pOwner->m_eResizeType == FORM_RESIZETYPE_Cap) {\r
1217             m_pOwner->m_pProperties->m_rtWidget.Offset(pMsg->m_fx - m_pOwner->m_InfoStart.m_ptStart.x, pMsg->m_fy - m_pOwner->m_InfoStart.m_ptStart.y);\r
1218             pWidgetMgr->SetWidgetPosition_Native(m_pOwner->m_pInterface,\r
1219                                                  m_pOwner->m_pProperties->m_rtWidget.left,\r
1220                                                  m_pOwner->m_pProperties->m_rtWidget.top);\r
1221             return;\r
1222         } else if (m_pOwner->m_eResizeType == FORM_RESIZETYPE_Right) {\r
1223             FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeWE);\r
1224             pCursorMgr->SetCursor(hCursor);\r
1225             pCursorMgr->ShowCursor(TRUE);\r
1226             if (!bWidthlimit) {\r
1227                 fWidth += pMsg->m_fx - m_pOwner->m_InfoStart.m_ptStart.x;\r
1228                 m_pOwner->m_InfoStart.m_ptStart.x = pMsg->m_fx;\r
1229             } else {\r
1230                 m_pOwner->DoWidthLimit(fLeft, fWidth, pMsg->m_fx, m_pOwner->m_InfoStart.m_szStart.x - m_pOwner->m_InfoStart.m_ptStart.x, fWidthMin, fWidthMax, FALSE);\r
1231             }\r
1232         } else if (m_pOwner->m_eResizeType == FORM_RESIZETYPE_Left) {\r
1233             FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeWE);\r
1234             pCursorMgr->SetCursor(hCursor);\r
1235             pCursorMgr->ShowCursor(TRUE);\r
1236             if (!bWidthlimit) {\r
1237                 fLeft -= m_pOwner->m_InfoStart.m_ptStart.x - pMsg->m_fx;\r
1238                 fWidth += m_pOwner->m_InfoStart.m_ptStart.x - pMsg->m_fx;\r
1239             } else {\r
1240                 m_pOwner->DoWidthLimit(fLeft, fWidth, pMsg->m_fx, m_pOwner->m_InfoStart.m_ptStart.x, fWidthMin, fWidthMax, TRUE);\r
1241             }\r
1242         } else if (m_pOwner->m_eResizeType == FORM_RESIZETYPE_Bottom) {\r
1243             FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNS);\r
1244             pCursorMgr->SetCursor(hCursor);\r
1245             pCursorMgr->ShowCursor(TRUE);\r
1246             if (!bHeightlimit) {\r
1247                 fHeight += pMsg->m_fy - m_pOwner->m_InfoStart.m_ptStart.y;\r
1248                 m_pOwner->m_InfoStart.m_ptStart.y = pMsg->m_fy;\r
1249             } else {\r
1250                 m_pOwner->DoHeightLimit(fTop, fHeight, pMsg->m_fy, m_pOwner->m_InfoStart.m_szStart.y - m_pOwner->m_InfoStart.m_ptStart.y, fHeightMin, fHeightMax, FALSE);\r
1251             }\r
1252         } else if (m_pOwner->m_eResizeType == FORM_RESIZETYPE_Top) {\r
1253             FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNS);\r
1254             pCursorMgr->SetCursor(hCursor);\r
1255             pCursorMgr->ShowCursor(TRUE);\r
1256             if (!bHeightlimit) {\r
1257                 fTop += pMsg->m_fy - m_pOwner->m_InfoStart.m_ptStart.y;\r
1258                 fHeight -= pMsg->m_fy - m_pOwner->m_InfoStart.m_ptStart.y;\r
1259             } else {\r
1260                 m_pOwner->DoHeightLimit(fTop, fHeight, pMsg->m_fy, m_pOwner->m_InfoStart.m_ptStart.y, fHeightMin, fHeightMax, TRUE);\r
1261             }\r
1262         } else if (m_pOwner->m_eResizeType == FORM_RESIZETYPE_LeftTop) {\r
1263             FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNWSE);\r
1264             pCursorMgr->SetCursor(hCursor);\r
1265             pCursorMgr->ShowCursor(TRUE);\r
1266             if (!bSizelimit) {\r
1267                 fLeft -= m_pOwner->m_InfoStart.m_ptStart.x - pMsg->m_fx;\r
1268                 fTop += pMsg->m_fy - m_pOwner-> m_InfoStart.m_ptStart.y;\r
1269                 fWidth += m_pOwner->m_InfoStart.m_ptStart.x - pMsg->m_fx;\r
1270                 fHeight -= pMsg->m_fy - m_pOwner->m_InfoStart.m_ptStart.y;\r
1271                 m_pOwner->m_InfoStart.m_ptStart.x = pMsg->m_fx;\r
1272                 m_pOwner->m_InfoStart.m_ptStart.y = pMsg->m_fy;\r
1273             } else {\r
1274                 m_pOwner->DoWidthLimit(fLeft, fWidth, pMsg->m_fx, m_pOwner->m_InfoStart.m_ptStart.x, fWidthMin, fWidthMax, TRUE);\r
1275                 m_pOwner->DoHeightLimit(fTop, fHeight, pMsg->m_fy, m_pOwner->m_InfoStart.m_ptStart.y, fHeightMin, fHeightMax, TRUE);\r
1276             }\r
1277         } else if (m_pOwner->m_eResizeType == FORM_RESIZETYPE_LeftBottom) {\r
1278             FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNESW);\r
1279             pCursorMgr->SetCursor(hCursor);\r
1280             pCursorMgr->ShowCursor(TRUE);\r
1281             if (!bSizelimit) {\r
1282                 fLeft -= m_pOwner->m_InfoStart.m_ptStart.x - pMsg->m_fx;\r
1283                 fWidth += m_pOwner->m_InfoStart.m_ptStart.x - pMsg->m_fx;\r
1284                 fHeight += pMsg->m_fy - m_pOwner->m_InfoStart.m_ptStart.y;\r
1285                 m_pOwner->m_InfoStart.m_ptStart.x = pMsg->m_fx;\r
1286                 m_pOwner->m_InfoStart.m_ptStart.y = pMsg->m_fy;\r
1287             } else {\r
1288                 m_pOwner->DoWidthLimit(fLeft, fWidth, pMsg->m_fx, m_pOwner->m_InfoStart.m_ptStart.x, fWidthMin, fWidthMax, TRUE);\r
1289                 m_pOwner->DoHeightLimit(fTop, fHeight, pMsg->m_fy, m_pOwner->m_InfoStart.m_szStart.y - m_pOwner->m_InfoStart.m_ptStart.y, fHeightMin, fHeightMax, FALSE);\r
1290             }\r
1291         } else if (m_pOwner->m_eResizeType == FORM_RESIZETYPE_RightTop) {\r
1292             FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNESW);\r
1293             pCursorMgr->SetCursor(hCursor);\r
1294             pCursorMgr->ShowCursor(TRUE);\r
1295             if (!bSizelimit) {\r
1296                 fTop += pMsg->m_fy - m_pOwner->m_InfoStart.m_ptStart.y;\r
1297                 fWidth += pMsg->m_fx - m_pOwner->m_InfoStart.m_ptStart.x;\r
1298                 fHeight -= pMsg->m_fy - m_pOwner->m_InfoStart.m_ptStart.y;\r
1299                 m_pOwner->m_InfoStart.m_ptStart.x = pMsg->m_fx;\r
1300                 m_pOwner->m_InfoStart.m_ptStart.y = pMsg->m_fy;\r
1301             } else {\r
1302                 m_pOwner->DoWidthLimit(fLeft, fWidth, pMsg->m_fx, m_pOwner->m_InfoStart.m_szStart.x - m_pOwner->m_InfoStart.m_ptStart.x, fWidthMin, fWidthMax, FALSE);\r
1303                 m_pOwner->DoHeightLimit(fTop, fHeight, pMsg->m_fy, m_pOwner->m_InfoStart.m_ptStart.y, fHeightMin, fHeightMax, TRUE);\r
1304             }\r
1305         } else if (m_pOwner->m_eResizeType == FORM_RESIZETYPE_RightBottom) {\r
1306             FWL_HCURSOR hCursor = pCursorMgr->GetSystemCursor(FWL_CURSORTYPE_SizeNWSE);\r
1307             pCursorMgr->SetCursor(hCursor);\r
1308             pCursorMgr->ShowCursor(TRUE);\r
1309             if (!bSizelimit) {\r
1310                 fWidth += pMsg->m_fx - m_pOwner->m_InfoStart.m_ptStart.x;\r
1311                 fHeight += pMsg->m_fy - m_pOwner->m_InfoStart.m_ptStart.y;\r
1312                 m_pOwner->m_InfoStart.m_ptStart.x = pMsg->m_fx;\r
1313                 m_pOwner->m_InfoStart.m_ptStart.y = pMsg->m_fy;\r
1314             } else {\r
1315                 m_pOwner->DoWidthLimit(fLeft, fWidth, pMsg->m_fx, m_pOwner->m_InfoStart.m_szStart.x - m_pOwner->m_InfoStart.m_ptStart.x, fWidthMin, fWidthMax, FALSE);\r
1316                 m_pOwner->DoHeightLimit(fTop, fHeight, pMsg->m_fy, m_pOwner->m_InfoStart.m_szStart.y - m_pOwner->m_InfoStart.m_ptStart.y, fHeightMin, fHeightMax, FALSE);\r
1317             }\r
1318         }\r
1319         if (m_pOwner->m_pContent) {\r
1320         }\r
1321         CFX_RectF rtForm;\r
1322         rtForm.Set(fLeft, fTop, fWidth, fHeight);\r
1323 #if (_FX_OS_==_FX_MACOSX_)\r
1324         m_pOwner->m_pProperties->m_rtWidget = rtForm;\r
1325         m_pOwner->Update();\r
1326         m_pOwner->SetWidgetRect(rtForm);\r
1327 #else\r
1328         m_pOwner->SetWidgetRect(rtForm);\r
1329         m_pOwner->Update();\r
1330 #endif\r
1331         return;\r
1332     }\r
1333     if ((m_pOwner->m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) &&\r
1334             (m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize) &&\r
1335             !m_pOwner->m_bMaximized) {\r
1336         m_pOwner->SetCursor(pMsg->m_fx, pMsg->m_fy);\r
1337     }\r
1338     CFX_RectF rtInvalidate;\r
1339     rtInvalidate.Reset();\r
1340     CFWL_SysBtn *pPointBtn = m_pOwner->GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy);\r
1341     CFWL_SysBtn *pOldHover = m_pOwner->GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover);\r
1342 #if (_FX_OS_==_FX_MACOSX_)\r
1343     {\r
1344         if (pOldHover && pPointBtn != pOldHover) {\r
1345             pOldHover->SetNormal();\r
1346         }\r
1347         if (pPointBtn && pPointBtn != pOldHover) {\r
1348             pPointBtn->SetHover();\r
1349         }\r
1350         if (m_pOwner->m_pCloseBox) {\r
1351             rtInvalidate = m_pOwner->m_pCloseBox->m_rtBtn;\r
1352         }\r
1353         if (m_pOwner->m_pMaxBox) {\r
1354             if (rtInvalidate.IsEmpty()) {\r
1355                 rtInvalidate = m_pOwner->m_pMaxBox->m_rtBtn;\r
1356             } else {\r
1357                 rtInvalidate.Union(m_pOwner->m_pMaxBox->m_rtBtn);\r
1358             }\r
1359         }\r
1360         if (m_pOwner->m_pMinBox) {\r
1361             if (rtInvalidate.IsEmpty()) {\r
1362                 rtInvalidate = m_pOwner->m_pMinBox->m_rtBtn;\r
1363             } else {\r
1364                 rtInvalidate.Union(m_pOwner->m_pMinBox->m_rtBtn);\r
1365             }\r
1366         }\r
1367         if (!rtInvalidate.IsEmpty() && rtInvalidate.Contains(pMsg->m_fx, pMsg->m_fy)) {\r
1368             m_pOwner->m_bMouseIn = TRUE;\r
1369         }\r
1370     }\r
1371 #else\r
1372     {\r
1373         if (pOldHover && pPointBtn != pOldHover) {\r
1374             pOldHover->SetNormal();\r
1375             rtInvalidate = pOldHover->m_rtBtn;\r
1376         }\r
1377         if (pPointBtn && pPointBtn != pOldHover) {\r
1378             pPointBtn->SetHover();\r
1379             if (rtInvalidate.IsEmpty()) {\r
1380                 rtInvalidate = pPointBtn->m_rtBtn;\r
1381             } else {\r
1382                 rtInvalidate.Union(pPointBtn->m_rtBtn);\r
1383             }\r
1384         }\r
1385     }\r
1386 #endif\r
1387     if (!rtInvalidate.IsEmpty()) {\r
1388         m_pOwner->Repaint(&rtInvalidate);\r
1389     }\r
1390 }\r
1391 void CFWL_FormDelegate::OnMouseHover(CFWL_MsgMouse *pMsg)\r
1392 {\r
1393     m_pOwner->SetCursor(pMsg->m_fx, pMsg->m_fy);\r
1394 }\r
1395 void CFWL_FormDelegate::OnMouseLeave(CFWL_MsgMouse *pMsg)\r
1396 {\r
1397     CFWL_SysBtn *pHover = m_pOwner->GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover);\r
1398     if (pHover) {\r
1399         pHover->SetNormal();\r
1400         m_pOwner->Repaint(&pHover->m_rtBtn);\r
1401     }\r
1402     if (pMsg->m_dwCmd == FWL_MSGMOUSECMD_MouseLeave && !m_pOwner->m_bLButtonDown) {\r
1403         m_pOwner->SetCursor(pMsg->m_fx, pMsg->m_fy);\r
1404     }\r
1405 }\r
1406 void CFWL_FormDelegate::OnLButtonDblClk(CFWL_MsgMouse *pMsg)\r
1407 {\r
1408     if ((m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize) && m_pOwner->HitTest(pMsg->m_fx, pMsg->m_fy) == FWL_WGTHITTEST_Titlebar) {\r
1409         if (m_pOwner->m_bMaximized) {\r
1410             m_pOwner->SetWidgetRect(m_pOwner->m_rtRestore);\r
1411         } else {\r
1412             m_pOwner->SetWorkAreaRect();\r
1413         }\r
1414         m_pOwner->Update();\r
1415         m_pOwner->m_bMaximized = !m_pOwner->m_bMaximized;\r
1416     }\r
1417 }\r
1418 void CFWL_FormDelegate::OnWindowMove(CFWL_MsgWindowMove *pMsg)\r
1419 {\r
1420     m_pOwner->m_pProperties->m_rtWidget.left = pMsg->m_fx;\r
1421     m_pOwner->m_pProperties->m_rtWidget.top = pMsg->m_fy;\r
1422 }\r
1423 void CFWL_FormDelegate::OnClose(CFWL_MsgClose *pMsg)\r
1424 {\r
1425     CFWL_EvtClose eClose;\r
1426     eClose.m_pSrcTarget = m_pOwner->m_pInterface;\r
1427     m_pOwner->DispatchEvent(&eClose);\r
1428 }\r
1429 FWL_ERR FWL_Accelerator_SetForm(IFWL_Form *pFrom, CFX_MapAccelerators *pMapAccel)\r
1430 {\r
1431     CFWL_FormImp *pImp = (CFWL_FormImp*)((IFWL_TargetData*)pFrom)->GetData();\r
1432     _FWL_RETURN_VALUE_IF_FAIL(pImp, FWL_ERR_Indefinite);\r
1433     return FWL_ERR_Succeeded;\r
1434 }\r