├── .gitattributes
├── .gitignore
├── AdSafeDemo.sln
├── AdSafeDemo
├── AdSafeDemo.rc
├── AdSafeDemo.vcxproj
├── AdSafeDemo.vcxproj.filters
├── AdSafeFrameWnd.h
├── Calculator.h
├── DuiMenu.h
├── MenuNotify.cpp
├── MenuNotify.h
├── Setting.h
├── UICrack.cpp
├── UICrack.h
├── UIMenu.cpp
├── UIMenu.h
├── config.ini
├── main.cpp
├── menu.xml
├── observer_impl_base.h
├── observer_impl_base.hpp
├── resource.h
├── src.h
└── tray.ico
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 | [Dd]ebug/
11 | [Dd]ebugPublic/
12 | [Rr]elease/
13 | x64/
14 | build/
15 | bld/
16 | [Bb]in/
17 | [Oo]bj/
18 |
19 | # Roslyn cache directories
20 | *.ide/
21 |
22 | # MSTest test Results
23 | [Tt]est[Rr]esult*/
24 | [Bb]uild[Ll]og.*
25 |
26 | #NUNIT
27 | *.VisualState.xml
28 | TestResult.xml
29 |
30 | # Build Results of an ATL Project
31 | [Dd]ebugPS/
32 | [Rr]eleasePS/
33 | dlldata.c
34 |
35 | *_i.c
36 | *_p.c
37 | *_i.h
38 | *.ilk
39 | *.meta
40 | *.obj
41 | *.pch
42 | *.pdb
43 | *.pgc
44 | *.pgd
45 | *.rsp
46 | *.sbr
47 | *.tlb
48 | *.tli
49 | *.tlh
50 | *.tmp
51 | *.tmp_proj
52 | *.log
53 | *.vspscc
54 | *.vssscc
55 | .builds
56 | *.pidb
57 | *.svclog
58 | *.scc
59 |
60 | # Chutzpah Test files
61 | _Chutzpah*
62 |
63 | # Visual C++ cache files
64 | ipch/
65 | *.aps
66 | *.ncb
67 | *.opensdf
68 | *.sdf
69 | *.cachefile
70 |
71 | # Visual Studio profiler
72 | *.psess
73 | *.vsp
74 | *.vspx
75 |
76 | # TFS 2012 Local Workspace
77 | $tf/
78 |
79 | # Guidance Automation Toolkit
80 | *.gpState
81 |
82 | # ReSharper is a .NET coding add-in
83 | _ReSharper*/
84 | *.[Rr]e[Ss]harper
85 | *.DotSettings.user
86 |
87 | # JustCode is a .NET coding addin-in
88 | .JustCode
89 |
90 | # TeamCity is a build add-in
91 | _TeamCity*
92 |
93 | # DotCover is a Code Coverage Tool
94 | *.dotCover
95 |
96 | # NCrunch
97 | _NCrunch_*
98 | .*crunch*.local.xml
99 |
100 | # MightyMoose
101 | *.mm.*
102 | AutoTest.Net/
103 |
104 | # Web workbench (sass)
105 | .sass-cache/
106 |
107 | # Installshield output folder
108 | [Ee]xpress/
109 |
110 | # DocProject is a documentation generator add-in
111 | DocProject/buildhelp/
112 | DocProject/Help/*.HxT
113 | DocProject/Help/*.HxC
114 | DocProject/Help/*.hhc
115 | DocProject/Help/*.hhk
116 | DocProject/Help/*.hhp
117 | DocProject/Help/Html2
118 | DocProject/Help/html
119 |
120 | # Click-Once directory
121 | publish/
122 |
123 | # Publish Web Output
124 | *.[Pp]ublish.xml
125 | *.azurePubxml
126 | ## TODO: Comment the next line if you want to checkin your
127 | ## web deploy settings but do note that will include unencrypted
128 | ## passwords
129 | #*.pubxml
130 |
131 | # NuGet Packages Directory
132 | packages/*
133 | ## TODO: If the tool you use requires repositories.config
134 | ## uncomment the next line
135 | #!packages/repositories.config
136 |
137 | # Enable "build/" folder in the NuGet Packages folder since
138 | # NuGet packages use it for MSBuild targets.
139 | # This line needs to be after the ignore of the build folder
140 | # (and the packages folder if the line above has been uncommented)
141 | !packages/build/
142 |
143 | # Windows Azure Build Output
144 | csx/
145 | *.build.csdef
146 |
147 | # Windows Store app package directory
148 | AppPackages/
149 |
150 | # Others
151 | sql/
152 | *.Cache
153 | ClientBin/
154 | [Ss]tyle[Cc]op.*
155 | ~$*
156 | *~
157 | *.dbmdl
158 | *.dbproj.schemaview
159 | *.pfx
160 | *.publishsettings
161 | node_modules/
162 |
163 | # RIA/Silverlight projects
164 | Generated_Code/
165 |
166 | # Backup & report files from converting an old project file
167 | # to a newer Visual Studio version. Backup files are not needed,
168 | # because we have git ;-)
169 | _UpgradeReport_Files/
170 | Backup*/
171 | UpgradeLog*.XML
172 | UpgradeLog*.htm
173 |
174 | # SQL Server files
175 | *.mdf
176 | *.ldf
177 |
178 | # Business Intelligence projects
179 | *.rdl.data
180 | *.bim.layout
181 | *.bim_*.settings
182 |
183 | # Microsoft Fakes
184 | FakesAssemblies/
185 |
186 | # LightSwitch generated files
187 | GeneratedArtifacts/
188 | _Pvt_Extensions/
189 | ModelManifest.xml
--------------------------------------------------------------------------------
/AdSafeDemo.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.40629.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AdSafeDemo", "AdSafeDemo\AdSafeDemo.vcxproj", "{FC27263D-D598-4164-94E6-E6C3B7B6CFB9}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Win32 = Debug|Win32
11 | Release|Win32 = Release|Win32
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {FC27263D-D598-4164-94E6-E6C3B7B6CFB9}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {FC27263D-D598-4164-94E6-E6C3B7B6CFB9}.Debug|Win32.Build.0 = Debug|Win32
16 | {FC27263D-D598-4164-94E6-E6C3B7B6CFB9}.Release|Win32.ActiveCfg = Release|Win32
17 | {FC27263D-D598-4164-94E6-E6C3B7B6CFB9}.Release|Win32.Build.0 = Release|Win32
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/AdSafeDemo/AdSafeDemo.rc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sirzdy/AdSafeDemo/4bf18f5c986fe386437ce98abf93bd6928711182/AdSafeDemo/AdSafeDemo.rc
--------------------------------------------------------------------------------
/AdSafeDemo/AdSafeDemo.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {FC27263D-D598-4164-94E6-E6C3B7B6CFB9}
15 | Win32Proj
16 | AdSafeDemo
17 |
18 |
19 |
20 | Application
21 | true
22 | v120
23 | Unicode
24 | false
25 |
26 |
27 | Application
28 | false
29 | v120
30 | true
31 | Unicode
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | true
45 | C:\Users\zdy\Documents\Duilib\Duilib\DuiLib;$(IncludePath)
46 | C:\Users\zdy\Documents\Duilib\Duilib\lib;$(LibraryPath)
47 |
48 |
49 | false
50 | D:\WorkSpace\DuiLib\duilib-master\DuiLib;$(IncludePath)
51 | D:\WorkSpace\DuiLib\duilib-master\Lib;$(LibraryPath)
52 |
53 |
54 |
55 |
56 |
57 | Level3
58 | Disabled
59 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
60 | false
61 |
62 |
63 | Windows
64 | true
65 |
66 |
67 |
68 |
69 | Level3
70 |
71 |
72 | MaxSpeed
73 | true
74 | true
75 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
76 | true
77 |
78 |
79 | Windows
80 | true
81 | true
82 | true
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/AdSafeDemo/AdSafeDemo.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | 源文件
20 |
21 |
22 |
23 |
24 | 头文件
25 |
26 |
27 | 头文件
28 |
29 |
30 | 头文件
31 |
32 |
33 | 头文件
34 |
35 |
36 | 头文件
37 |
38 |
39 |
40 |
41 | 资源文件
42 |
43 |
44 |
45 |
46 | 资源文件
47 |
48 |
49 |
--------------------------------------------------------------------------------
/AdSafeDemo/AdSafeFrameWnd.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sirzdy/AdSafeDemo/4bf18f5c986fe386437ce98abf93bd6928711182/AdSafeDemo/AdSafeFrameWnd.h
--------------------------------------------------------------------------------
/AdSafeDemo/Calculator.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sirzdy/AdSafeDemo/4bf18f5c986fe386437ce98abf93bd6928711182/AdSafeDemo/Calculator.h
--------------------------------------------------------------------------------
/AdSafeDemo/DuiMenu.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sirzdy/AdSafeDemo/4bf18f5c986fe386437ce98abf93bd6928711182/AdSafeDemo/DuiMenu.h
--------------------------------------------------------------------------------
/AdSafeDemo/MenuNotify.cpp:
--------------------------------------------------------------------------------
1 | #include "MenuNotify.h"
2 | #include "UIMenu.h"
3 | CMenuNotify::CMenuNotify(void)
4 | {
5 | }
6 |
7 |
8 | CMenuNotify::~CMenuNotify(void)
9 | {
10 | }
11 |
12 | void CMenuNotify::Notify(TNotifyUI& msg)
13 | {
14 | if (msg.sType == DUI_MSGTYPE_ITEMCLICK)
15 | {
16 | CMenuElementUI *pMenuElement = (CMenuElementUI*)msg.pSender;
17 | CPaintManagerUI *m_pm = pMenuElement->GetManager();
18 | if (m_pm != NULL)
19 | {
20 |
21 | CControlUI *pRootControl = m_pm->GetRoot();
22 | if (pRootControl != NULL)
23 | {
24 |
25 | CDuiString szMenuName = pRootControl->GetName();
26 |
27 | //if (szMenuName == _T("workstation_menu"))
28 | //{
29 | CDuiString szText = pMenuElement->GetText();
30 | int index = pMenuElement->GetIndex();
31 | bool bTickStatus = false;
32 | switch (index)
33 | {
34 | case 0:
35 | break;
36 | }
37 |
38 | //}
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/AdSafeDemo/MenuNotify.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | using namespace DuiLib;
4 | class CMenuNotify : public INotifyUI
5 | {
6 | public:
7 | CMenuNotify(void);
8 | ~CMenuNotify(void);
9 | protected:
10 | void Notify(TNotifyUI& msg);
11 | };
12 |
13 |
--------------------------------------------------------------------------------
/AdSafeDemo/Setting.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sirzdy/AdSafeDemo/4bf18f5c986fe386437ce98abf93bd6928711182/AdSafeDemo/Setting.h
--------------------------------------------------------------------------------
/AdSafeDemo/UICrack.cpp:
--------------------------------------------------------------------------------
1 | #include "UICrack.h"
2 |
3 | namespace DuiLib {
4 |
5 |
6 | /////////////////////////////////////////////////////////////////////////////////////
7 | //
8 | //
9 | // constrol class name and interface name
10 |
11 | // UIActiveX
12 | const TCHAR* const kUIActiveXClassName = _T("ActiveXUI");
13 | const TCHAR* const kUIActiveXInterfaceName = _T("ActiveX");
14 |
15 | // ComboUI
16 | const TCHAR* const kComboUIClassName = _T("ComboUI");
17 | const TCHAR* const kComboUIInterfaceName = _T("Combo");
18 |
19 | // LabelUI
20 | const TCHAR* const kLabelUIClassName = _T("LabelUI");
21 | const TCHAR* const kLabelUIInterfaceName = _T("Label");
22 |
23 | // ButtonUI
24 | const TCHAR* const kButtonUIClassName = _T("ButtonUI");
25 | const TCHAR* const kButtonUIInterfaceName = _T("Button");
26 |
27 | // OptionUI
28 | const TCHAR* const kOptionUIClassName = _T("OptionUI");
29 | const TCHAR* const kOptionUIInterfaceName = _T("Option");
30 |
31 | // TextUI
32 | const TCHAR* const kTextUIClassName = _T("TextUI");
33 | const TCHAR* const kTextUIInterfaceName = _T("Text");
34 |
35 | // ProgressUI
36 | const TCHAR* const kProgressUIClassName = _T("ProgressUI");
37 | const TCHAR* const kProgressUIInterfaceName = _T("Progress");
38 |
39 | // SliderUI
40 | const TCHAR* const kSliderUIClassName = _T("SliderUI");
41 | const TCHAR* const kSliderUIInterfaceName = _T("Slider");
42 |
43 | // EditUI
44 | const TCHAR* const kEditUIClassName = _T("EditUI");
45 | const TCHAR* const kEditUIInterfaceName = _T("Edit");
46 |
47 | // IEditUI
48 | const TCHAR* const kIEditUIInterfaceName = _T("Edit");
49 |
50 | // ScrollBarUI
51 | const TCHAR* const kScrollBarUIClassName = _T("ScrollBarUI");
52 | const TCHAR* const kScrollBarUIInterfaceName = _T("ScrollBar");
53 |
54 | // ContainerUI
55 | const TCHAR* const kContainerUIClassName = _T("ContainerUI");
56 | const TCHAR* const kContainerUIInterfaceName = _T("Container");
57 |
58 | // IContainerUI
59 | const TCHAR* const kIContainerUIInterfaceName = _T("IContainer");
60 |
61 | // VerticalLayoutUI
62 | const TCHAR* const kVerticalLayoutUIClassName = _T("VerticalLayoutUI");
63 | const TCHAR* const kVerticalLayoutUIInterfaceName = _T("VerticalLayout");
64 |
65 | // HorizontalLayoutUI
66 | const TCHAR* const kHorizontalLayoutUIClassName = _T("HorizontalLayoutUI");
67 | const TCHAR* const kHorizontalLayoutUIInterfaceName = _T("HorizontalLayout");
68 |
69 | // TileLayoutUI
70 | const TCHAR* const kTileLayoutUIClassName = _T("TileLayoutUI");
71 | const TCHAR* const kTileLayoutUIInterfaceName = _T("TileLayout");
72 |
73 | // DialogLayoutUI
74 | const TCHAR* const kDialogLayoutUIClassName = _T("DialogLayoutUI");
75 | const TCHAR* const kDialogLayoutUIInterfaceName = _T("DialogLayout");
76 |
77 | // TabLayoutUI
78 | const TCHAR* const kTabLayoutUIClassName = _T("TabLayoutUI");
79 | const TCHAR* const kTabLayoutUIInterfaceName = _T("TabLayout");
80 |
81 | // ControlUI
82 | const TCHAR* const kControlUIClassName = _T("ControlUI");
83 | const TCHAR* const kControlUIInterfaceName = _T("Control");
84 |
85 | // ListUI
86 | const TCHAR* const kListUIClassName = _T("ListUI");
87 | const TCHAR* const kListUIInterfaceName = _T("List");
88 |
89 | // IListUI
90 | const TCHAR* const kIListUIInterfaceName = _T("IList");
91 |
92 | // IListOwnerUI
93 | const TCHAR* const kIListOwnerUIInterfaceName = _T("IListOwner");
94 |
95 | // ListHeaderUI
96 | const TCHAR* const kListHeaderUIClassName = _T("ListHeaderUI");
97 | const TCHAR* const kListHeaderUIInterfaceName = _T("ListHeader");
98 |
99 | // ListHeaderItemUI
100 | const TCHAR* const kListHeaderItemUIClassName = _T("ListHeaderItemUI");
101 | const TCHAR* const kListHeaderItemUIInterfaceName = _T("ListHeaderItem");
102 |
103 | // ListElementUI
104 | const TCHAR* const kListElementUIClassName = _T("ListElementUI");
105 | const TCHAR* const kListElementUIInterfaceName = _T("ListElement");
106 |
107 | // IListItemUI
108 | const TCHAR* const kIListItemUIInterfaceName = _T("ListItem");
109 |
110 | // ListLabelElementUI
111 | const TCHAR* const kListLabelElementUIClassName = _T("ListLabelElementUI");
112 | const TCHAR* const kListLabelElementUIInterfaceName = _T("ListLabelElement");
113 |
114 | // ListTextElementUI
115 | const TCHAR* const kListTextElementUIClassName = _T("ListTextElementUI");
116 | const TCHAR* const kListTextElementUIInterfaceName = _T("ListTextElement");
117 |
118 | // ListExpandElementUI
119 | //const TCHAR* const kListExpandElementUIClassName = _T("ListExpandElementUI");
120 | //const TCHAR* const kListExpandElementUIInterfaceName = _T("ListExpandElement");
121 |
122 | // ListContainerElementUI
123 | const TCHAR* const kListContainerElementUIClassName = _T("ListContainerElementUI");
124 | const TCHAR* const kListContainerElementUIInterfaceName = _T("ListContainerElement");
125 |
126 | // RichEditUI
127 | const TCHAR* const kRichEditUIClassName = _T("RichEditUI");
128 | const TCHAR* const kRichEditUIInterfaceName = _T("RichEdit");
129 |
130 | /////////////////////////////////////////////////////////////////////////////////////
131 | //
132 | //
133 | // control related message
134 | const TCHAR* const kWindowInit = _T("windowinit");
135 | const TCHAR* const kClick = _T("click");
136 | const TCHAR* const kSelectChanged = _T("selectchanged");
137 | const TCHAR* const kItemSelect = _T("itemselect");
138 | const TCHAR* const kItemActivate = _T("itemactivate");
139 | const TCHAR* const kItemClick = _T("itemclick");
140 | const TCHAR* const kDropDown = _T("dropdown");
141 | const TCHAR* const kTimer = _T("timer");
142 | const TCHAR* const kMenu = _T("menu");
143 | const TCHAR* const kReturn = _T("return");
144 | const TCHAR* const kTextChanged = _T("textchanged");
145 | const TCHAR* const kKillFocus = _T("killfocus");
146 | const TCHAR* const kSetFocus = _T("setfocus");
147 | const TCHAR* const kValueChanged = _T("valuechanged");
148 |
149 | }; // namespace DuiLib
--------------------------------------------------------------------------------
/AdSafeDemo/UICrack.h:
--------------------------------------------------------------------------------
1 | #ifndef _UICRACK_H_
2 | #define _UICRACK_H_
3 |
4 | #ifdef _MSC_VER
5 | #pragma once
6 | #endif
7 |
8 | #include
9 | using namespace DuiLib;
10 |
11 | namespace DuiLib {
12 |
13 | /////////////////////////////////////////////////////////////////////////////////////
14 | //
15 | //
16 | // constrol class name and interface name
17 |
18 | // UIActiveX
19 | extern const TCHAR* const kUIActiveXClassName;// = _T("ActiveXUI");
20 | extern const TCHAR* const kUIActiveXInterfaceName;// = _T("ActiveX");
21 |
22 | // ComboUI
23 | extern const TCHAR* const kComboUIClassName;// = _T("ComboUI");
24 | extern const TCHAR* const kComboUIInterfaceName;// = _T("Combo");
25 |
26 | // LabelUI
27 | extern const TCHAR* const kLabelUIClassName;// = _T("LabelUI");
28 | extern const TCHAR* const kLabelUIInterfaceName;// = _T("Label");
29 |
30 |
31 | // ButtonUI
32 | extern const TCHAR* const kButtonUIClassName;// = _T("ButtonUI");
33 | extern const TCHAR* const kButtonUIInterfaceName;// = _T("Button");
34 |
35 | // OptionUI
36 | extern const TCHAR* const kOptionUIClassName;// = _T("OptionUI");
37 | extern const TCHAR* const kOptionUIInterfaceName;// = _T("Option");
38 |
39 | // TextUI
40 | extern const TCHAR* const kTextUIClassName;// = _T("TextUI");
41 | extern const TCHAR* const kTextUIInterfaceName;// = _T("Text");
42 |
43 | // ProgressUI
44 | extern const TCHAR* const kProgressUIClassName;// = _T("ProgressUI");
45 | extern const TCHAR* const kProgressUIInterfaceName;// = _T("Progress");
46 |
47 | // SliderUI
48 | extern const TCHAR* const kSliderUIClassName;// = _T("SliderUI");
49 | extern const TCHAR* const kSliderUIInterfaceName;// = _T("Slider");
50 |
51 | // EditUI
52 | extern const TCHAR* const kEditUIClassName;// = _T("EditUI");
53 | extern const TCHAR* const kEditUIInterfaceName;// = _T("Edit");
54 |
55 | // IEditUI
56 | extern const TCHAR* const kIEditUIInterfaceName;// = _T("Edit");
57 |
58 | // ScrollBarUI
59 | extern const TCHAR* const kScrollBarUIClassName;// = _T("ScrollBarUI");
60 | extern const TCHAR* const kScrollBarUIInterfaceName;// = _T("ScrollBar");
61 |
62 | // ContainerUI
63 | extern const TCHAR* const kContainerUIClassName;// = _T("ContainerUI");
64 | extern const TCHAR* const kContainerUIInterfaceName;// = _T("Container");
65 |
66 | // IContainerUI
67 | extern const TCHAR* const kIContainerUIInterfaceName;// = _T("IContainer");
68 |
69 | // VerticalLayoutUI
70 | extern const TCHAR* const kVerticalLayoutUIClassName;// = _T("VerticalLayoutUI");
71 | extern const TCHAR* const kVerticalLayoutUIInterfaceName;// = _T("VerticalLayout");
72 |
73 | // HorizontalLayoutUI
74 | extern const TCHAR* const kHorizontalLayoutUIClassName;// = _T("HorizontalLayoutUI");
75 | extern const TCHAR* const kHorizontalLayoutUIInterfaceName;// = _T("HorizontalLayout");
76 |
77 | // TileLayoutUI
78 | extern const TCHAR* const kTileLayoutUIClassName;// = _T("TileLayoutUI");
79 | extern const TCHAR* const kTileLayoutUIInterfaceName;// = _T("TileLayout");
80 |
81 | // DialogLayoutUI
82 | extern const TCHAR* const kDialogLayoutUIClassName;// = _T("DialogLayoutUI");
83 | extern const TCHAR* const kDialogLayoutUIInterfaceName;// = _T("DialogLayout");
84 |
85 | // TabLayoutUI
86 | extern const TCHAR* const kTabLayoutUIClassName;// = _T("TabLayoutUI");
87 | extern const TCHAR* const kTabLayoutUIInterfaceName;// = _T("TabLayout");
88 |
89 | // ControlUI
90 | extern const TCHAR* const kControlUIClassName;// = _T("ControlUI");
91 | extern const TCHAR* const kControlUIInterfaceName;// = _T("Control");
92 |
93 | // ListUI
94 | extern const TCHAR* const kListUIClassName;// = _T("ListUI");
95 | extern const TCHAR* const kListUIInterfaceName;// = _T("List");
96 |
97 | // IListUI
98 | extern const TCHAR* const kIListUIInterfaceName;// = _T("IList");
99 |
100 | // IListOwnerUI
101 | extern const TCHAR* const kIListOwnerUIInterfaceName;// = _T("IListOwner");
102 |
103 | // ListHeaderUI
104 | extern const TCHAR* const kListHeaderUIClassName;// = _T("ListHeaderUI");
105 | extern const TCHAR* const kListHeaderUIInterfaceName;// = _T("ListHeader");
106 |
107 | // ListHeaderItemUI
108 | extern const TCHAR* const kListHeaderItemUIClassName;// = _T("ListHeaderItemUI");
109 | extern const TCHAR* const kListHeaderItemUIInterfaceName;// = _T("ListHeaderItem");
110 |
111 | // ListElementUI
112 | extern const TCHAR* const kListElementUIClassName;// = _T("ListElementUI");
113 | extern const TCHAR* const kListElementUIInterfaceName;// = _T("ListElement");
114 |
115 | // IListItemUI
116 | extern const TCHAR* const kIListItemUIInterfaceName;// = _T("ListItem");
117 |
118 | // ListLabelElementUI
119 | extern const TCHAR* const kListLabelElementUIClassName;// = _T("ListLabelElementUI");
120 | extern const TCHAR* const kListLabelElementUIInterfaceName;// = _T("ListLabelElement");
121 |
122 | // ListTextElementUI
123 | extern const TCHAR* const kListTextElementUIClassName;// = _T("ListTextElementUI");
124 | extern const TCHAR* const kListTextElementUIInterfaceName;// = _T("ListTextElement");
125 |
126 | // ListExpandElementUI
127 | //extern const TCHAR* const kListExpandElementUIClassName;// = _T("ListExpandElementUI");
128 | //extern const TCHAR* const kListExpandElementUIInterfaceName;// = _T("ListExpandElement");
129 |
130 | // ListContainerElementUI
131 | extern const TCHAR* const kListContainerElementUIClassName;// = _T("ListContainerElementUI");
132 | extern const TCHAR* const kListContainerElementUIInterfaceName;// = _T("ListContainerElement");
133 |
134 | // RichEditUI
135 | extern const TCHAR* const kRichEditUIClassName;// = _T("RichEditUI");
136 | extern const TCHAR* const kRichEditUIInterfaceName;// = _T("RichEdit");
137 |
138 | /////////////////////////////////////////////////////////////////////////////////////
139 | //
140 | //
141 | // control related message
142 | extern const TCHAR* const kWindowInit;// = _T("windowinit");
143 | extern const TCHAR* const kClick;// = _T("click");
144 | extern const TCHAR* const kSelectChanged;// = _T("selectchanged");
145 | extern const TCHAR* const kItemSelect;// = _T("itemselect");
146 | extern const TCHAR* const kItemActivate;// = _T("itemactivate");
147 | extern const TCHAR* const kItemClick;// = _T("itemclick");
148 | extern const TCHAR* const kDropDown;// = _T("dropdown");
149 | extern const TCHAR* const kTimer;// = _T("timer");
150 | extern const TCHAR* const kMenu;// = _T("menu");
151 | extern const TCHAR* const kReturn;// = _T("return");
152 | extern const TCHAR* const kTextChanged;// = _T("textchanged");
153 | extern const TCHAR* const kKillFocus; // = _T("killfocus");
154 | extern const TCHAR* const kSetFocus; // = _T("setfocus");
155 | extern const TCHAR* const kValueChanged; // = _T("valuechanged");
156 |
157 | }; // namespace DuiLib
158 |
159 | #endif // _UICRACK_H_
--------------------------------------------------------------------------------
/AdSafeDemo/UIMenu.cpp:
--------------------------------------------------------------------------------
1 | #include "UICrack.h"
2 | #include "UIMenu.h"
3 | #define MAX(a,b) (((a) > (b)) ? (a) : (b))
4 | namespace DuiLib {
5 |
6 | /////////////////////////////////////////////////////////////////////////////////////
7 | //
8 | ContextMenuObserver s_context_menu_observer;
9 |
10 | // MenuUI
11 | const TCHAR* const kMenuUIClassName = _T("MenuUI");
12 | const TCHAR* const kMenuUIInterfaceName = _T("Menu");
13 |
14 | CMenuUI::CMenuUI()
15 | {
16 | if (GetHeader() != NULL)
17 | GetHeader()->SetVisible(false);
18 | }
19 |
20 | CMenuUI::~CMenuUI()
21 | {}
22 |
23 | LPCTSTR CMenuUI::GetClass() const
24 | {
25 | return kMenuUIClassName;
26 | }
27 |
28 | LPVOID CMenuUI::GetInterface(LPCTSTR pstrName)
29 | {
30 | if (_tcsicmp(pstrName, kMenuUIInterfaceName) == 0) return static_cast(this);
31 | return CListUI::GetInterface(pstrName);
32 | }
33 |
34 | void CMenuUI::DoEvent(TEventUI& event)
35 | {
36 | return __super::DoEvent(event);
37 | }
38 |
39 | bool CMenuUI::Add(CControlUI* pControl)
40 | {
41 | CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName));
42 | if (pMenuItem == NULL)
43 | return false;
44 |
45 | for (int i = 0; i < pMenuItem->GetCount(); ++i)
46 | {
47 | if (pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL)
48 | {
49 | (static_cast(pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(false);
50 | }
51 | }
52 | return CListUI::Add(pControl);
53 | }
54 |
55 | bool CMenuUI::AddAt(CControlUI* pControl, int iIndex)
56 | {
57 | CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName));
58 | if (pMenuItem == NULL)
59 | return false;
60 |
61 | for (int i = 0; i < pMenuItem->GetCount(); ++i)
62 | {
63 | if (pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL)
64 | {
65 | (static_cast(pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(false);
66 | }
67 | }
68 | return CListUI::AddAt(pControl, iIndex);
69 | }
70 |
71 | int CMenuUI::GetItemIndex(CControlUI* pControl) const
72 | {
73 | CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName));
74 | if (pMenuItem == NULL)
75 | return -1;
76 |
77 | return __super::GetItemIndex(pControl);
78 | }
79 |
80 | bool CMenuUI::SetItemIndex(CControlUI* pControl, int iIndex)
81 | {
82 | CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName));
83 | if (pMenuItem == NULL)
84 | return false;
85 |
86 | return __super::SetItemIndex(pControl, iIndex);
87 | }
88 |
89 | bool CMenuUI::Remove(CControlUI* pControl, bool bDoNotDestroy)
90 | {
91 | CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName));
92 | if (pMenuItem == NULL)
93 | return false;
94 |
95 | return __super::Remove(pControl, bDoNotDestroy);
96 | }
97 |
98 | SIZE CMenuUI::EstimateSize(SIZE szAvailable)
99 | {
100 | int cxFixed = 0;
101 | int cyFixed = 0;
102 | for (int it = 0; it < GetCount(); it++) {
103 | CControlUI* pControl = static_cast(GetItemAt(it));
104 | if (!pControl->IsVisible()) continue;
105 | SIZE sz = pControl->EstimateSize(szAvailable);
106 | cyFixed += sz.cy;
107 | if (cxFixed < sz.cx)
108 | cxFixed = sz.cx;
109 | }
110 | return CDuiSize(cxFixed, cyFixed);
111 | }
112 |
113 | void CMenuUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
114 | {
115 | CListUI::SetAttribute(pstrName, pstrValue);
116 | }
117 |
118 | /////////////////////////////////////////////////////////////////////////////////////
119 | //
120 | class CMenuBuilderCallback : public IDialogBuilderCallback
121 | {
122 | CControlUI* CreateControl(LPCTSTR pstrClass)
123 | {
124 | if (_tcsicmp(pstrClass, kMenuUIInterfaceName) == 0)
125 | {
126 | return new CMenuUI();
127 | }
128 | else if (_tcsicmp(pstrClass, kMenuElementUIInterfaceName) == 0)
129 | {
130 | return new CMenuElementUI();
131 | }
132 | return NULL;
133 | }
134 | };
135 |
136 | CMenuWnd::CMenuWnd(HWND hParent) :
137 | m_hParent(hParent),
138 | m_pOwner(NULL),
139 | m_pLayout(),
140 | m_xml(_T(""))
141 | {}
142 |
143 | BOOL CMenuWnd::Receive(ContextMenuParam param)
144 | {
145 | switch (param.wParam)
146 | {
147 | case 1:
148 | Close();
149 | break;
150 | case 2:
151 | {
152 | HWND hParent = GetParent(m_hWnd);
153 | while (hParent != NULL)
154 | {
155 | if (hParent == param.hWnd)
156 | {
157 | Close();
158 | break;
159 | }
160 | hParent = GetParent(hParent);
161 | }
162 | }
163 | break;
164 | default:
165 | break;
166 | }
167 |
168 | return TRUE;
169 | }
170 |
171 | void CMenuWnd::Init(CMenuElementUI* pOwner, STRINGorID xml, LPCTSTR pSkinType, POINT point)
172 | {
173 | m_BasedPoint = point;
174 | m_pOwner = pOwner;
175 | m_pLayout = NULL;
176 |
177 | if (pSkinType != NULL)
178 | m_sType = pSkinType;
179 |
180 | m_xml = xml;
181 |
182 | s_context_menu_observer.AddReceiver(this);
183 |
184 | Create((m_pOwner == NULL) ? m_hParent : m_pOwner->GetManager()->GetPaintWindow(), NULL, WS_POPUP, WS_EX_TOOLWINDOW | WS_EX_TOPMOST, CDuiRect());
185 | // HACK: Don't deselect the parent's caption
186 | HWND hWndParent = m_hWnd;
187 | while (::GetParent(hWndParent) != NULL) hWndParent = ::GetParent(hWndParent);
188 | ::ShowWindow(m_hWnd, SW_SHOW);
189 | #if defined(WIN32) && !defined(UNDER_CE)
190 | ::SendMessage(hWndParent, WM_NCACTIVATE, TRUE, 0L);
191 | #endif
192 | }
193 |
194 | LPCTSTR CMenuWnd::GetWindowClassName() const
195 | {
196 | return _T("MenuWnd");
197 | }
198 |
199 | void CMenuWnd::OnFinalMessage(HWND hWnd)
200 | {
201 | RemoveObserver();
202 | if (m_pOwner != NULL) {
203 | for (int i = 0; i < m_pOwner->GetCount(); i++) {
204 | if (static_cast(m_pOwner->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)) != NULL) {
205 | (static_cast(m_pOwner->GetItemAt(i)))->SetOwner(m_pOwner->GetParent());
206 | (static_cast(m_pOwner->GetItemAt(i)))->SetVisible(false);
207 | (static_cast(m_pOwner->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(false);
208 | }
209 | }
210 | m_pOwner->m_pWindow = NULL;
211 | m_pOwner->m_uButtonState &= ~UISTATE_PUSHED;
212 | m_pOwner->Invalidate();
213 | }
214 | delete this;
215 | }
216 |
217 | LRESULT CMenuWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
218 | {
219 | if (uMsg == WM_CREATE) {
220 | if (m_pOwner != NULL) {
221 | LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
222 | styleValue &= ~WS_CAPTION;
223 | ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
224 | RECT rcClient;
225 | ::GetClientRect(*this, &rcClient);
226 | ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, \
227 | rcClient.bottom - rcClient.top, SWP_FRAMECHANGED);
228 |
229 | m_pm.Init(m_hWnd);
230 | // The trick is to add the items to the new container. Their owner gets
231 | // reassigned by this operation - which is why it is important to reassign
232 | // the items back to the righfull owner/manager when the window closes.
233 | m_pLayout = new CMenuUI();
234 | m_pLayout->SetManager(&m_pm, NULL, true);
235 | LPCTSTR pDefaultAttributes = m_pOwner->GetManager()->GetDefaultAttributeList(kMenuUIInterfaceName);
236 | if (pDefaultAttributes) {
237 | m_pLayout->SetAttributeList(pDefaultAttributes);
238 | }
239 | m_pLayout->SetBkColor(0xFFFFFFFF);
240 | m_pLayout->SetBorderColor(0xFF85E4FF);
241 | m_pLayout->SetBorderSize(0);
242 | m_pLayout->SetAutoDestroy(false);
243 | m_pLayout->EnableScrollBar();
244 | for (int i = 0; i < m_pOwner->GetCount(); i++) {
245 | if (m_pOwner->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL){
246 | (static_cast(m_pOwner->GetItemAt(i)))->SetOwner(m_pLayout);
247 | m_pLayout->Add(static_cast(m_pOwner->GetItemAt(i)));
248 | }
249 | }
250 | m_pm.AttachDialog(m_pLayout);
251 |
252 | // Position the popup window in absolute space
253 | RECT rcOwner = m_pOwner->GetPos();
254 | RECT rc = rcOwner;
255 |
256 | int cxFixed = 0;
257 | int cyFixed = 0;
258 |
259 | #if defined(WIN32) && !defined(UNDER_CE)
260 | MONITORINFO oMonitor = {};
261 | oMonitor.cbSize = sizeof(oMonitor);
262 | ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);
263 | CDuiRect rcWork = oMonitor.rcWork;
264 | #else
265 | CDuiRect rcWork;
266 | GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWork);
267 | #endif
268 | SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top };
269 |
270 | for (int it = 0; it < m_pOwner->GetCount(); it++) {
271 | if (m_pOwner->GetItemAt(it)->GetInterface(kMenuElementUIInterfaceName) != NULL){
272 | CControlUI* pControl = static_cast(m_pOwner->GetItemAt(it));
273 | SIZE sz = pControl->EstimateSize(szAvailable);
274 | cyFixed += sz.cy;
275 |
276 | if (cxFixed < sz.cx)
277 | cxFixed = sz.cx;
278 | }
279 | }
280 | cyFixed += 4;
281 | cxFixed += 4;
282 |
283 | RECT rcWindow;
284 | GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWindow);
285 |
286 | rc.top = rcOwner.top;
287 | rc.bottom = rc.top + cyFixed;
288 | ::MapWindowRect(m_pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc);
289 | rc.left = rcWindow.right;
290 | rc.right = rc.left + cxFixed;
291 | rc.right += 2;
292 |
293 | bool bReachBottom = false;
294 | bool bReachRight = false;
295 | LONG chRightAlgin = 0;
296 | LONG chBottomAlgin = 0;
297 |
298 | RECT rcPreWindow = { 0 };
299 | ContextMenuObserver::Iterator iterator(s_context_menu_observer);
300 | ReceiverImplBase* pReceiver = iterator.next();
301 | while (pReceiver != NULL) {
302 | CMenuWnd* pContextMenu = dynamic_cast(pReceiver);
303 | if (pContextMenu != NULL) {
304 | GetWindowRect(pContextMenu->GetHWND(), &rcPreWindow);
305 |
306 | bReachRight = rcPreWindow.left >= rcWindow.right;
307 | bReachBottom = rcPreWindow.top >= rcWindow.bottom;
308 | if (pContextMenu->GetHWND() == m_pOwner->GetManager()->GetPaintWindow()
309 | || bReachBottom || bReachRight)
310 | break;
311 | }
312 | pReceiver = iterator.next();
313 | }
314 |
315 | if (bReachBottom)
316 | {
317 | rc.bottom = rcWindow.top;
318 | rc.top = rc.bottom - cyFixed;
319 | }
320 |
321 | if (bReachRight)
322 | {
323 | rc.right = rcWindow.left;
324 | rc.left = rc.right - cxFixed;
325 | }
326 |
327 | if (rc.bottom > rcWork.bottom)
328 | {
329 | rc.bottom = rc.top;
330 | rc.top = rc.bottom - cyFixed;
331 | }
332 |
333 | if (rc.right > rcWork.right)
334 | {
335 | rc.right = rcWindow.left;
336 | rc.left = rc.right - cxFixed;
337 |
338 | rc.top = rcWindow.bottom;
339 | rc.bottom = rc.top + cyFixed;
340 | }
341 |
342 | if (rc.top < rcWork.top)
343 | {
344 | rc.top = rcOwner.top;
345 | rc.bottom = rc.top + cyFixed;
346 | }
347 |
348 | if (rc.left < rcWork.left)
349 | {
350 | rc.left = rcWindow.right;
351 | rc.right = rc.left + cxFixed;
352 | }
353 |
354 | MoveWindow(m_hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE);
355 | }
356 | else {
357 | m_pm.Init(m_hWnd);
358 |
359 | CDialogBuilder builder;
360 | CMenuBuilderCallback menuCallback;
361 |
362 | CControlUI* pRoot = builder.Create(m_xml, m_sType.GetData(), &menuCallback, &m_pm);
363 | m_pm.AttachDialog(pRoot);
364 |
365 | #if defined(WIN32) && !defined(UNDER_CE)
366 | MONITORINFO oMonitor = {};
367 | oMonitor.cbSize = sizeof(oMonitor);
368 | ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);
369 | CDuiRect rcWork = oMonitor.rcWork;
370 | #else
371 | CDuiRect rcWork;
372 | GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWork);
373 | #endif
374 | SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top };
375 | szAvailable = pRoot->EstimateSize(szAvailable);
376 | m_pm.SetInitSize(szAvailable.cx, szAvailable.cy);
377 |
378 | DWORD dwAlignment = eMenuAlignment_Left | eMenuAlignment_Top;
379 |
380 | SIZE szInit = m_pm.GetInitSize();
381 | CDuiRect rc;
382 | CDuiPoint point = m_BasedPoint;
383 | rc.left = point.x;
384 | rc.top = point.y;
385 | rc.right = rc.left + szInit.cx;
386 | rc.bottom = rc.top + szInit.cy;
387 |
388 | int nWidth = rc.GetWidth();
389 | int nHeight = rc.GetHeight();
390 |
391 | if (dwAlignment & eMenuAlignment_Right)
392 | {
393 | rc.right = point.x;
394 | rc.left = rc.right - nWidth;
395 | }
396 |
397 | if (dwAlignment & eMenuAlignment_Bottom)
398 | {
399 | rc.bottom = point.y;
400 | rc.top = rc.bottom - nHeight;
401 | }
402 |
403 | SetForegroundWindow(m_hWnd);
404 | MoveWindow(m_hWnd, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), FALSE);
405 | SetWindowPos(m_hWnd, HWND_TOPMOST, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), SWP_SHOWWINDOW);
406 | }
407 |
408 | return 0;
409 | }
410 | else if (uMsg == WM_CLOSE) {
411 | if (m_pOwner != NULL)
412 | {
413 | m_pOwner->SetManager(m_pOwner->GetManager(), m_pOwner->GetParent(), false);
414 | m_pOwner->SetPos(m_pOwner->GetPos(), false);
415 | m_pOwner->SetFocus();
416 | }
417 | }
418 | else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_CONTEXTMENU || uMsg == WM_RBUTTONUP || uMsg == WM_RBUTTONDBLCLK)
419 | {
420 | return 0L;
421 | }
422 | else if (uMsg == WM_KILLFOCUS)
423 | {
424 | HWND hFocusWnd = (HWND)wParam;
425 |
426 | BOOL bInMenuWindowList = FALSE;
427 | ContextMenuParam param;
428 | param.hWnd = GetHWND();
429 |
430 | ContextMenuObserver::Iterator iterator(s_context_menu_observer);
431 | ReceiverImplBase* pReceiver = iterator.next();
432 | while (pReceiver != NULL) {
433 | CMenuWnd* pContextMenu = dynamic_cast(pReceiver);
434 | if (pContextMenu != NULL && pContextMenu->GetHWND() == hFocusWnd) {
435 | bInMenuWindowList = TRUE;
436 | break;
437 | }
438 | pReceiver = iterator.next();
439 | }
440 |
441 | if (!bInMenuWindowList) {
442 | param.wParam = 1;
443 | s_context_menu_observer.RBroadcast(param);
444 |
445 | return 0;
446 | }
447 | }
448 | else if (uMsg == WM_KEYDOWN)
449 | {
450 | if (wParam == VK_ESCAPE)
451 | {
452 | Close();
453 | }
454 | }
455 |
456 | LRESULT lRes = 0;
457 | if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes;
458 | return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
459 | }
460 |
461 | /////////////////////////////////////////////////////////////////////////////////////
462 | //
463 |
464 | // MenuElementUI
465 | const TCHAR* const kMenuElementUIClassName = _T("MenuElement");
466 | const TCHAR* const kMenuElementUIInterfaceName = _T("MenuElement");
467 |
468 | CMenuElementUI::CMenuElementUI() :
469 | m_pWindow(NULL)
470 | {
471 | m_cxyFixed.cy = 25;
472 | m_bMouseChildEnabled = true;
473 |
474 | //SetMouseChildEnabled(false);
475 | }
476 |
477 | CMenuElementUI::~CMenuElementUI()
478 | {}
479 |
480 | LPCTSTR CMenuElementUI::GetClass() const
481 | {
482 | return kMenuElementUIClassName;
483 | }
484 |
485 | LPVOID CMenuElementUI::GetInterface(LPCTSTR pstrName)
486 | {
487 | if (_tcsicmp(pstrName, kMenuElementUIInterfaceName) == 0) return static_cast(this);
488 | return CListContainerElementUI::GetInterface(pstrName);
489 | }
490 |
491 | bool CMenuElementUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl)
492 | {
493 | RECT rcTemp = { 0 };
494 | if (!::IntersectRect(&rcTemp, &rcPaint, &m_rcItem)) return true;
495 |
496 | CRenderClip clip;
497 | CRenderClip::GenerateClip(hDC, rcTemp, clip);
498 | CMenuElementUI::DrawItemBk(hDC, m_rcItem);
499 | DrawItemText(hDC, m_rcItem);
500 |
501 | if (m_items.GetSize() > 0) {
502 | RECT rc = m_rcItem;
503 | rc.left += m_rcInset.left;
504 | rc.top += m_rcInset.top;
505 | rc.right -= m_rcInset.right;
506 | rc.bottom -= m_rcInset.bottom;
507 | if (m_pVerticalScrollBar && m_pVerticalScrollBar->IsVisible()) rc.right -= m_pVerticalScrollBar->GetFixedWidth();
508 | if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible()) rc.bottom -= m_pHorizontalScrollBar->GetFixedHeight();
509 |
510 | if (!::IntersectRect(&rcTemp, &rcPaint, &rc)) {
511 | for (int it = 0; it < m_items.GetSize(); it++) {
512 | CControlUI* pControl = static_cast(m_items[it]);
513 | if (pControl == pStopControl) return false;
514 | if (!pControl->IsVisible()) continue;
515 | if (pControl->GetInterface(kMenuElementUIInterfaceName) != NULL) continue;
516 | if (!::IntersectRect(&rcTemp, &rcPaint, &pControl->GetPos())) continue;
517 | if (pControl->IsFloat()) {
518 | if (!::IntersectRect(&rcTemp, &m_rcItem, &pControl->GetPos())) continue;
519 | if (!pControl->Paint(hDC, rcPaint, pStopControl)) return false;
520 | }
521 | }
522 | }
523 | else {
524 | CRenderClip childClip;
525 | CRenderClip::GenerateClip(hDC, rcTemp, childClip);
526 | for (int it = 0; it < m_items.GetSize(); it++) {
527 | CControlUI* pControl = static_cast(m_items[it]);
528 | if (pControl == pStopControl) return false;
529 | if (!pControl->IsVisible()) continue;
530 | if (pControl->GetInterface(kMenuElementUIInterfaceName) != NULL) continue;
531 | if (!::IntersectRect(&rcTemp, &rcPaint, &pControl->GetPos())) continue;
532 | if (pControl->IsFloat()) {
533 | if (!::IntersectRect(&rcTemp, &m_rcItem, &pControl->GetPos())) continue;
534 | CRenderClip::UseOldClipBegin(hDC, childClip);
535 | if (!pControl->Paint(hDC, rcPaint, pStopControl)) return false;
536 | CRenderClip::UseOldClipEnd(hDC, childClip);
537 | }
538 | else {
539 | if (!::IntersectRect(&rcTemp, &rc, &pControl->GetPos())) continue;
540 | if (!pControl->Paint(hDC, rcPaint, pStopControl)) return false;
541 | }
542 | }
543 | }
544 | }
545 |
546 | if (m_pVerticalScrollBar != NULL) {
547 | if (m_pVerticalScrollBar == pStopControl) return false;
548 | if (m_pVerticalScrollBar->IsVisible()) {
549 | if (::IntersectRect(&rcTemp, &rcPaint, &m_pVerticalScrollBar->GetPos())) {
550 | if (!m_pVerticalScrollBar->Paint(hDC, rcPaint, pStopControl)) return false;
551 | }
552 | }
553 | }
554 |
555 | if (m_pHorizontalScrollBar != NULL) {
556 | if (m_pHorizontalScrollBar == pStopControl) return false;
557 | if (m_pHorizontalScrollBar->IsVisible()) {
558 | if (::IntersectRect(&rcTemp, &rcPaint, &m_pHorizontalScrollBar->GetPos())) {
559 | if (!m_pHorizontalScrollBar->Paint(hDC, rcPaint, pStopControl)) return false;
560 | }
561 | }
562 | }
563 | return true;
564 | }
565 |
566 | void CMenuElementUI::DrawItemText(HDC hDC, const RECT& rcItem)
567 | {
568 | if (m_sText.IsEmpty()) return;
569 |
570 | if (m_pOwner == NULL) return;
571 | TListInfoUI* pInfo = m_pOwner->GetListInfo();
572 | DWORD iTextColor = pInfo->dwTextColor;
573 | if ((m_uButtonState & UISTATE_HOT) != 0) {
574 | iTextColor = pInfo->dwHotTextColor;
575 | }
576 | if (IsSelected()) {
577 | iTextColor = pInfo->dwSelectedTextColor;
578 | }
579 | if (!IsEnabled()) {
580 | iTextColor = pInfo->dwDisabledTextColor;
581 | }
582 | int nLinks = 0;
583 | RECT rcText = rcItem;
584 | rcText.left += pInfo->rcTextPadding.left;
585 | rcText.right -= pInfo->rcTextPadding.right;
586 | rcText.top += pInfo->rcTextPadding.top;
587 | rcText.bottom -= pInfo->rcTextPadding.bottom;
588 |
589 | if (pInfo->bShowHtml)
590 | CRenderEngine::DrawHtmlText(hDC, m_pManager, rcText, m_sText, iTextColor, \
591 | NULL, NULL, nLinks, pInfo->nFont, DT_SINGLELINE | pInfo->uTextStyle);
592 | else
593 | CRenderEngine::DrawText(hDC, m_pManager, rcText, m_sText, iTextColor, \
594 | pInfo->nFont, DT_SINGLELINE | pInfo->uTextStyle);
595 | }
596 |
597 |
598 | SIZE CMenuElementUI::EstimateSize(SIZE szAvailable)
599 | {
600 | SIZE cXY = { 0 };
601 | for (int it = 0; it < GetCount(); it++) {
602 | CControlUI* pControl = static_cast(GetItemAt(it));
603 | if (!pControl->IsVisible()) continue;
604 | SIZE sz = pControl->EstimateSize(szAvailable);
605 | cXY.cy += sz.cy;
606 | if (cXY.cx < sz.cx)
607 | cXY.cx = sz.cx;
608 | }
609 | if (cXY.cy == 0) {
610 | TListInfoUI* pInfo = m_pOwner->GetListInfo();
611 |
612 | DWORD iTextColor = pInfo->dwTextColor;
613 | if ((m_uButtonState & UISTATE_HOT) != 0) {
614 | iTextColor = pInfo->dwHotTextColor;
615 | }
616 | if (IsSelected()) {
617 | iTextColor = pInfo->dwSelectedTextColor;
618 | }
619 | if (!IsEnabled()) {
620 | iTextColor = pInfo->dwDisabledTextColor;
621 | }
622 |
623 | RECT rcText = { 0, 0, MAX(szAvailable.cx, m_cxyFixed.cx), 9999 };
624 | rcText.left += pInfo->rcTextPadding.left;
625 | rcText.right -= pInfo->rcTextPadding.right;
626 | if (pInfo->bShowHtml) {
627 | int nLinks = 0;
628 | CRenderEngine::DrawHtmlText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, iTextColor, NULL, NULL, nLinks, pInfo->nFont, DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER);
629 | }
630 | else {
631 | CRenderEngine::DrawText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, iTextColor, pInfo->nFont, DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER);
632 | }
633 | cXY.cx = rcText.right - rcText.left + pInfo->rcTextPadding.left + pInfo->rcTextPadding.right + 20;
634 | cXY.cy = rcText.bottom - rcText.top + pInfo->rcTextPadding.top + pInfo->rcTextPadding.bottom;
635 | }
636 |
637 | if (m_cxyFixed.cy != 0) cXY.cy = m_cxyFixed.cy;
638 | return cXY;
639 | }
640 |
641 | void CMenuElementUI::DoEvent(TEventUI& event)
642 | {
643 | if (event.Type == UIEVENT_MOUSEENTER)
644 | {
645 | CListContainerElementUI::DoEvent(event);
646 | if (m_pWindow) return;
647 | bool hasSubMenu = false;
648 | for (int i = 0; i < GetCount(); ++i)
649 | {
650 | if (GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL)
651 | {
652 | (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetVisible(true);
653 | (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(true);
654 |
655 | hasSubMenu = true;
656 | }
657 | }
658 | if (hasSubMenu)
659 | {
660 | m_pOwner->SelectItem(GetIndex(), true);
661 | CreateMenuWnd();
662 | }
663 | else
664 | {
665 | ContextMenuParam param;
666 | param.hWnd = m_pManager->GetPaintWindow();
667 | param.wParam = 2;
668 | s_context_menu_observer.RBroadcast(param);
669 | m_pOwner->SelectItem(GetIndex(), true);
670 | }
671 | }
672 |
673 | if (event.Type == UIEVENT_BUTTONDOWN)
674 | {
675 | if (IsEnabled()){
676 | CListContainerElementUI::DoEvent(event);
677 |
678 | if (m_pWindow) return;
679 |
680 | bool hasSubMenu = false;
681 | for (int i = 0; i < GetCount(); ++i) {
682 | if (GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL) {
683 | (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetVisible(true);
684 | (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(true);
685 |
686 | hasSubMenu = true;
687 | }
688 | }
689 | if (hasSubMenu)
690 | {
691 | CreateMenuWnd();
692 | }
693 | else
694 | {
695 | ContextMenuParam param;
696 | param.hWnd = m_pManager->GetPaintWindow();
697 | param.wParam = 1;
698 | s_context_menu_observer.RBroadcast(param);
699 | }
700 | }
701 | return;
702 | }
703 |
704 | CListContainerElementUI::DoEvent(event);
705 | }
706 |
707 | bool CMenuElementUI::Activate()
708 | {
709 | if (CListContainerElementUI::Activate() && m_bSelected)
710 | {
711 | if (m_pWindow) return true;
712 | bool hasSubMenu = false;
713 | for (int i = 0; i < GetCount(); ++i)
714 | {
715 | if (GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL)
716 | {
717 | (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetVisible(true);
718 | (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(true);
719 |
720 | hasSubMenu = true;
721 | }
722 | }
723 | if (hasSubMenu)
724 | {
725 | CreateMenuWnd();
726 | }
727 | else
728 | {
729 | ContextMenuParam param;
730 | param.hWnd = m_pManager->GetPaintWindow();
731 | param.wParam = 1;
732 | s_context_menu_observer.RBroadcast(param);
733 | }
734 |
735 | return true;
736 | }
737 | return false;
738 | }
739 |
740 | CMenuWnd* CMenuElementUI::GetMenuWnd()
741 | {
742 | return m_pWindow;
743 | }
744 |
745 | void CMenuElementUI::CreateMenuWnd()
746 | {
747 | if (m_pWindow) return;
748 |
749 | m_pWindow = new CMenuWnd(m_pManager->GetPaintWindow());
750 | ASSERT(m_pWindow);
751 |
752 | ContextMenuParam param;
753 | param.hWnd = m_pManager->GetPaintWindow();
754 | param.wParam = 2;
755 | s_context_menu_observer.RBroadcast(param);
756 |
757 | m_pWindow->Init(static_cast(this), _T(""), _T(""), CDuiPoint());
758 | }
759 |
760 |
761 | } // namespace DuiLib
762 |
--------------------------------------------------------------------------------
/AdSafeDemo/UIMenu.h:
--------------------------------------------------------------------------------
1 | #ifndef __UIMENU_H__
2 | #define __UIMENU_H__
3 |
4 | #ifdef _MSC_VER
5 | #pragma once
6 | #endif
7 |
8 | #include
9 | using namespace DuiLib;
10 | #include "observer_impl_base.h"
11 |
12 | namespace DuiLib {
13 |
14 | /////////////////////////////////////////////////////////////////////////////////////
15 | //
16 | struct ContextMenuParam
17 | {
18 | // 1: remove all
19 | // 2: remove the sub menu
20 | WPARAM wParam;
21 | HWND hWnd;
22 | };
23 |
24 | enum MenuAlignment
25 | {
26 | eMenuAlignment_Left = 1 << 1,
27 | eMenuAlignment_Top = 1 << 2,
28 | eMenuAlignment_Right = 1 << 3,
29 | eMenuAlignment_Bottom = 1 << 4,
30 | };
31 |
32 | typedef class ObserverImpl ContextMenuObserver;
33 | typedef class ReceiverImpl ContextMenuReceiver;
34 |
35 | extern ContextMenuObserver s_context_menu_observer;
36 |
37 | // MenuUI
38 | extern const TCHAR* const kMenuUIClassName;// = _T("MenuUI");
39 | extern const TCHAR* const kMenuUIInterfaceName;// = _T("Menu");
40 |
41 | class CListUI;
42 | class CMenuUI : public CListUI
43 | {
44 | public:
45 | CMenuUI();
46 | ~CMenuUI();
47 |
48 | LPCTSTR GetClass() const;
49 | LPVOID GetInterface(LPCTSTR pstrName);
50 |
51 | virtual void DoEvent(TEventUI& event);
52 |
53 | virtual bool Add(CControlUI* pControl);
54 | virtual bool AddAt(CControlUI* pControl, int iIndex);
55 |
56 | virtual int GetItemIndex(CControlUI* pControl) const;
57 | virtual bool SetItemIndex(CControlUI* pControl, int iIndex);
58 | virtual bool Remove(CControlUI* pControl, bool bDoNotDestroy = false);
59 |
60 | SIZE EstimateSize(SIZE szAvailable);
61 |
62 | void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
63 | };
64 |
65 | /////////////////////////////////////////////////////////////////////////////////////
66 | //
67 |
68 | // MenuElementUI
69 | extern const TCHAR* const kMenuElementUIClassName;// = _T("MenuElement");
70 | extern const TCHAR* const kMenuElementUIInterfaceName;// = _T("MenuElement);
71 |
72 | class CMenuElementUI;
73 | class CMenuWnd : public CWindowWnd, public ContextMenuReceiver
74 | {
75 | public:
76 | CMenuWnd(HWND hParent = NULL);
77 | void Init(CMenuElementUI* pOwner, STRINGorID xml, LPCTSTR pSkinType, POINT point);
78 | LPCTSTR GetWindowClassName() const;
79 | void OnFinalMessage(HWND hWnd);
80 |
81 | LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
82 |
83 | BOOL Receive(ContextMenuParam param);
84 |
85 | public:
86 | HWND m_hParent;
87 | POINT m_BasedPoint;
88 | STRINGorID m_xml;
89 | CDuiString m_sType;
90 | CPaintManagerUI m_pm;
91 | CMenuElementUI* m_pOwner;
92 | CMenuUI* m_pLayout;
93 | };
94 |
95 | class CListContainerElementUI;
96 | class CMenuElementUI : public CListContainerElementUI
97 | {
98 | friend CMenuWnd;
99 | public:
100 | CMenuElementUI();
101 | ~CMenuElementUI();
102 |
103 | LPCTSTR GetClass() const;
104 | LPVOID GetInterface(LPCTSTR pstrName);
105 |
106 | bool DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl);
107 |
108 | void DrawItemText(HDC hDC, const RECT& rcItem);
109 |
110 | SIZE EstimateSize(SIZE szAvailable);
111 |
112 | bool Activate();
113 |
114 | void DoEvent(TEventUI& event);
115 |
116 |
117 | CMenuWnd* GetMenuWnd();
118 |
119 | void CreateMenuWnd();
120 |
121 | protected:
122 | CMenuWnd* m_pWindow;
123 | };
124 |
125 | } // namespace DuiLib
126 |
127 | #endif // __UIMENU_H__
128 |
--------------------------------------------------------------------------------
/AdSafeDemo/config.ini:
--------------------------------------------------------------------------------
1 | [ControlMessage]
2 | status=0
3 | [ControlMode]
4 | status=0
5 | [CloseStatus]
6 | status=0
7 | [AutoRun]
8 | status=0
9 | [Key]
10 | acctype=0
11 | [Update]
12 | frequency=0
13 |
--------------------------------------------------------------------------------
/AdSafeDemo/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sirzdy/AdSafeDemo/4bf18f5c986fe386437ce98abf93bd6928711182/AdSafeDemo/main.cpp
--------------------------------------------------------------------------------
/AdSafeDemo/menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/AdSafeDemo/observer_impl_base.h:
--------------------------------------------------------------------------------
1 | #ifndef OBSERVER_IMPL_BASE_HPP
2 | #define OBSERVER_IMPL_BASE_HPP
3 |
4 | #include