├── .github └── workflows │ └── msbuild.yml ├── .gitignore ├── DuiLib.sln ├── DuiLib ├── 3rd │ └── CxImage │ │ ├── tif_xfile.cpp │ │ ├── xfile.h │ │ ├── ximabmp.cpp │ │ ├── ximabmp.h │ │ ├── ximacfg.h │ │ ├── ximadef.h │ │ ├── ximadsp.cpp │ │ ├── ximaenc.cpp │ │ ├── ximaexif.cpp │ │ ├── ximage.cpp │ │ ├── ximage.h │ │ ├── ximagif.cpp │ │ ├── ximagif.h │ │ ├── ximahist.cpp │ │ ├── ximaico.cpp │ │ ├── ximaico.h │ │ ├── ximainfo.cpp │ │ ├── ximaint.cpp │ │ ├── ximaiter.h │ │ ├── ximajas.cpp │ │ ├── ximajas.h │ │ ├── ximajbg.cpp │ │ ├── ximajbg.h │ │ ├── ximajpg.cpp │ │ ├── ximajpg.h │ │ ├── ximalpha.cpp │ │ ├── ximalyr.cpp │ │ ├── ximamng.cpp │ │ ├── ximamng.h │ │ ├── ximapal.cpp │ │ ├── ximapcx.cpp │ │ ├── ximapcx.h │ │ ├── ximapng.cpp │ │ ├── ximapng.h │ │ ├── ximapsd.cpp │ │ ├── ximapsd.h │ │ ├── ximaraw.cpp │ │ ├── ximaraw.h │ │ ├── ximasel.cpp │ │ ├── ximaska.cpp │ │ ├── ximaska.h │ │ ├── ximatga.cpp │ │ ├── ximatga.h │ │ ├── ximath.cpp │ │ ├── ximath.h │ │ ├── ximatif.cpp │ │ ├── ximatif.h │ │ ├── ximatran.cpp │ │ ├── ximawbmp.cpp │ │ ├── ximawbmp.h │ │ ├── ximawmf.cpp │ │ ├── ximawmf.h │ │ ├── ximawnd.cpp │ │ ├── xiofile.h │ │ ├── xmemfile.cpp │ │ └── xmemfile.h ├── Bind │ ├── BindBase.h │ ├── BindCtrls.hpp │ └── StdAfx.h ├── Control │ ├── StdAfx.h │ ├── UIActiveX.cpp │ ├── UIActiveX.h │ ├── UIAnimation.cpp │ ├── UIAnimation.h │ ├── UIButton.cpp │ ├── UIButton.h │ ├── UIColorPalette.cpp │ ├── UIColorPalette.h │ ├── UICombo.cpp │ ├── UICombo.h │ ├── UIComboBox.cpp │ ├── UIComboBox.h │ ├── UIDateTime.cpp │ ├── UIDateTime.h │ ├── UIEdit.cpp │ ├── UIEdit.h │ ├── UIFadeButton.cpp │ ├── UIFadeButton.h │ ├── UIFlash.cpp │ ├── UIFlash.h │ ├── UIGifAnim.cpp │ ├── UIGifAnim.h │ ├── UIGifAnimEx.cpp │ ├── UIGifAnimEx.h │ ├── UIGroupBox.cpp │ ├── UIGroupBox.h │ ├── UIHotKey.cpp │ ├── UIHotKey.h │ ├── UIIPAddress.cpp │ ├── UIIPAddress.h │ ├── UIIPAddressEx.cpp │ ├── UIIPAddressEx.h │ ├── UILabel.cpp │ ├── UILabel.h │ ├── UIList.cpp │ ├── UIList.h │ ├── UIListEx.cpp │ ├── UIListEx.h │ ├── UIMenu.cpp │ ├── UIMenu.h │ ├── UIOption.cpp │ ├── UIOption.h │ ├── UIProgress.cpp │ ├── UIProgress.h │ ├── UIRichEdit.cpp │ ├── UIRichEdit.h │ ├── UIRing.cpp │ ├── UIRing.h │ ├── UIRollText.cpp │ ├── UIRollText.h │ ├── UIScrollBar.cpp │ ├── UIScrollBar.h │ ├── UISlider.cpp │ ├── UISlider.h │ ├── UIText.cpp │ ├── UIText.h │ ├── UITreeView.cpp │ ├── UITreeView.h │ ├── UIWebBrowser.cpp │ └── UIWebBrowser.h ├── Core │ ├── ControlFactory.cpp │ ├── ControlFactory.h │ ├── StdAfx.h │ ├── UIBase.cpp │ ├── UIBase.h │ ├── UIContainer.cpp │ ├── UIContainer.h │ ├── UIControl.cpp │ ├── UIControl.h │ ├── UIDefine.h │ ├── UIDlgBuilder.cpp │ ├── UIDlgBuilder.h │ ├── UIManager.cpp │ ├── UIManager.h │ ├── UIMarkup.cpp │ ├── UIMarkup.h │ ├── UIRender.cpp │ ├── UIRender.h │ ├── UIResourceManager.cpp │ └── UIResourceManager.h ├── DuiLib.vcxproj ├── DuiLib.vcxproj.filters ├── Layout │ ├── StdAfx.h │ ├── UIAnimationTabLayout.cpp │ ├── UIAnimationTabLayout.h │ ├── UIChildLayout.cpp │ ├── UIChildLayout.h │ ├── UIHorizontalLayout.cpp │ ├── UIHorizontalLayout.h │ ├── UITabLayout.cpp │ ├── UITabLayout.h │ ├── UITileLayout.cpp │ ├── UITileLayout.h │ ├── UIVerticalLayout.cpp │ └── UIVerticalLayout.h ├── StdAfx.cpp ├── StdAfx.h ├── UIlib.cpp ├── UIlib.h └── Utils │ ├── DPI.cpp │ ├── DPI.h │ ├── DragDropImpl.cpp │ ├── DragDropImpl.h │ ├── FawTools.hpp │ ├── Flash11.tlb │ ├── FlashEventHandler.h │ ├── StdAfx.h │ ├── TrayIcon.cpp │ ├── TrayIcon.h │ ├── UIDelegate.cpp │ ├── UIDelegate.h │ ├── UIShadow.cpp │ ├── UIShadow.h │ ├── Utils.cpp │ ├── Utils.h │ ├── VersionHelpers.h │ ├── WebBrowserEventHandler.h │ ├── WinImplBase.cpp │ ├── WinImplBase.h │ ├── downloadmgr.h │ ├── flash11.tlh │ ├── observer_impl_base.h │ ├── stb_image.h │ ├── unzip.cpp │ └── unzip.h ├── LICENSE ├── README.md └── 属性列表.htm /.github/workflows/msbuild.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | name: MSBuild 7 | 8 | on: 9 | push: 10 | branches: [ "master" ] 11 | pull_request: 12 | branches: [ "master" ] 13 | 14 | env: 15 | # Path to the solution file relative to the root of the project. 16 | SOLUTION_FILE_PATH: . 17 | 18 | # Configuration type to build. 19 | # You can convert this to a build matrix if you need coverage of multiple configuration types. 20 | # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 21 | BUILD_CONFIGURATION: Release 22 | 23 | permissions: 24 | contents: read 25 | 26 | jobs: 27 | build: 28 | runs-on: windows-latest 29 | 30 | steps: 31 | - uses: actions/checkout@v3 32 | 33 | - name: Add MSBuild to PATH 34 | uses: microsoft/setup-msbuild@v1.0.2 35 | 36 | - name: Restore NuGet packages 37 | working-directory: ${{env.GITHUB_WORKSPACE}} 38 | run: nuget restore ${{env.SOLUTION_FILE_PATH}} 39 | 40 | - name: Build 41 | working-directory: ${{env.GITHUB_WORKSPACE}} 42 | # Add additional options to the MSBuild command line here (like platform or verbosity level). 43 | # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference 44 | run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}} 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.dll 2 | *.exe 3 | *.exp 4 | *.idb 5 | *.ilk 6 | *.ipch 7 | *.lastbuildstate 8 | *.lib 9 | *.log 10 | *.obj 11 | *.pch 12 | *.pdb 13 | *.res 14 | *.sdf 15 | *.suo 16 | *.tlog 17 | *.user 18 | .git/ 19 | .vs/ 20 | lib/ 21 | Temp/ 22 | x64/ 23 | -------------------------------------------------------------------------------- /DuiLib.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.32106.194 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DuiLib", "DuiLib\DuiLib.vcxproj", "{E106ACD7-4E53-4AEE-942B-D0DD426DB34E}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9101C649-E799-4728-B995-F70AFA4A83C0}" 9 | ProjectSection(SolutionItems) = preProject 10 | README.md = README.md 11 | 属性列表.htm = 属性列表.htm 12 | EndProjectSection 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|x64 = Debug|x64 17 | Debug|x86 = Debug|x86 18 | Release|x64 = Release|x64 19 | Release|x86 = Release|x86 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Debug|x64.ActiveCfg = SDebugA|x64 23 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Debug|x64.Build.0 = SDebugA|x64 24 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Debug|x86.ActiveCfg = SDebugA|Win32 25 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Debug|x86.Build.0 = SDebugA|Win32 26 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Release|x64.ActiveCfg = SReleaseA|x64 27 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Release|x64.Build.0 = SReleaseA|x64 28 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Release|x86.ActiveCfg = SReleaseA|Win32 29 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Release|x86.Build.0 = SReleaseA|Win32 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {7511F52B-4C30-4277-93D0-0E8DCE9160BB} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/xfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: xfile.h 3 | * Purpose: General Purpose File Class 4 | */ 5 | /* 6 | -------------------------------------------------------------------------------- 7 | 8 | COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: 9 | 10 | CxFile (c) 11/May/2002 Davide Pizzolato - www.xdp.it 11 | CxFile version 2.00 23/Aug/2002 12 | CxFile version 2.10 16/Dec/2007 13 | 14 | Special thanks to Chris Shearer Cooper for new features, enhancements and bugfixes 15 | 16 | Covered code is provided under this license on an "as is" basis, without warranty 17 | of any kind, either expressed or implied, including, without limitation, warranties 18 | that the covered code is free of defects, merchantable, fit for a particular purpose 19 | or non-infringing. The entire risk as to the quality and performance of the covered 20 | code is with you. Should any covered code prove defective in any respect, you (not 21 | the initial developer or any other contributor) assume the cost of any necessary 22 | servicing, repair or correction. This disclaimer of warranty constitutes an essential 23 | part of this license. No use of any covered code is authorized hereunder except under 24 | this disclaimer. 25 | 26 | Permission is hereby granted to use, copy, modify, and distribute this 27 | source code, or portions hereof, for any purpose, including commercial applications, 28 | freely and without fee, subject to the following restrictions: 29 | 30 | 1. The origin of this software must not be misrepresented; you must not 31 | claim that you wrote the original software. If you use this software 32 | in a product, an acknowledgment in the product documentation would be 33 | appreciated but is not required. 34 | 35 | 2. Altered source versions must be plainly marked as such, and must not be 36 | misrepresented as being the original software. 37 | 38 | 3. This notice may not be removed or altered from any source distribution. 39 | -------------------------------------------------------------------------------- 40 | */ 41 | #if !defined(__xfile_h) 42 | #define __xfile_h 43 | 44 | #if defined (WIN32) || defined (_WIN32_WCE) 45 | #include 46 | #endif 47 | 48 | #include 49 | #include 50 | 51 | #include "ximadef.h" 52 | 53 | class DLL_EXP CxFile 54 | { 55 | public: 56 | CxFile(void) { }; 57 | virtual ~CxFile() { }; 58 | 59 | virtual bool Close() = 0; 60 | virtual size_t Read(void *buffer, size_t size, size_t count) = 0; 61 | virtual size_t Write(const void *buffer, size_t size, size_t count) = 0; 62 | virtual bool Seek(int32_t offset, int32_t origin) = 0; 63 | virtual int32_t Tell() = 0; 64 | virtual int32_t Size() = 0; 65 | virtual bool Flush() = 0; 66 | virtual bool Eof() = 0; 67 | virtual int32_t Error() = 0; 68 | virtual bool PutC(uint8_t c) 69 | { 70 | // Default implementation 71 | size_t nWrote = Write(&c, 1, 1); 72 | return (bool)(nWrote == 1); 73 | } 74 | virtual int32_t GetC() = 0; 75 | virtual char * GetS(char *string, int32_t n) = 0; 76 | virtual int32_t Scanf(const char *format, void* output) = 0; 77 | }; 78 | 79 | #endif //__xfile_h 80 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximabmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximabmp.h 3 | * Purpose: BMP Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImageBMP (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * 9 | * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes 10 | * 11 | * original CImageBMP and CImageIterator implementation are: 12 | * Copyright: (c) 1995, Alejandro Aguilar Sierra 13 | * 14 | * ========================================================== 15 | */ 16 | 17 | #if !defined(__ximaBMP_h) 18 | #define __ximaBMP_h 19 | 20 | #include "ximage.h" 21 | 22 | const int32_t RLE_COMMAND = 0; 23 | const int32_t RLE_ENDOFLINE = 0; 24 | const int32_t RLE_ENDOFBITMAP = 1; 25 | const int32_t RLE_DELTA = 2; 26 | 27 | #if !defined(BI_RLE8) 28 | #define BI_RLE8 1L 29 | #endif 30 | #if !defined(BI_RLE4) 31 | #define BI_RLE4 2L 32 | #endif 33 | 34 | #if CXIMAGE_SUPPORT_BMP 35 | 36 | class CxImageBMP: public CxImage 37 | { 38 | public: 39 | CxImageBMP(): CxImage(CXIMAGE_FORMAT_BMP) {}; 40 | 41 | bool Decode(CxFile * hFile); 42 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 43 | 44 | #if CXIMAGE_SUPPORT_ENCODE 45 | bool Encode(CxFile * hFile); 46 | bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } 47 | #endif // CXIMAGE_SUPPORT_ENCODE 48 | 49 | protected: 50 | bool DibReadBitmapInfo(CxFile* fh, BITMAPINFOHEADER *pdib); 51 | }; 52 | 53 | #define BFT_ICON 0x4349 /* 'IC' */ 54 | #define BFT_BITMAP 0x4d42 /* 'BM' */ 55 | #define BFT_CURSOR 0x5450 /* 'PT' */ 56 | 57 | #ifndef WIDTHBYTES 58 | #define WIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */ 59 | #endif 60 | 61 | #endif 62 | 63 | #define DibWidthBytesN(lpbi, n) (uint32_t)WIDTHBYTES((uint32_t)(lpbi)->biWidth * (uint32_t)(n)) 64 | #define DibWidthBytes(lpbi) DibWidthBytesN(lpbi, (lpbi)->biBitCount) 65 | 66 | #define DibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \ 67 | ? ((uint32_t)(uint32_t)DibWidthBytes(lpbi) * (uint32_t)(uint32_t)(lpbi)->biHeight) \ 68 | : (lpbi)->biSizeImage) 69 | 70 | #define DibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \ 71 | ? (int32_t)(1 << (int32_t)(lpbi)->biBitCount) \ 72 | : (int32_t)(lpbi)->biClrUsed) 73 | 74 | #define FixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \ 75 | (lpbi)->biSizeImage = DibSizeImage(lpbi); \ 76 | if ((lpbi)->biClrUsed == 0) \ 77 | (lpbi)->biClrUsed = DibNumColors(lpbi); \ 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximacfg.h: -------------------------------------------------------------------------------- 1 | #if !defined(__ximaCFG_h) 2 | #define __ximaCFG_h 3 | 4 | ///////////////////////////////////////////////////////////////////////////// 5 | // CxImage supported features 6 | #define CXIMAGE_SUPPORT_ALPHA 0 7 | #define CXIMAGE_SUPPORT_SELECTION 0 8 | #define CXIMAGE_SUPPORT_TRANSFORMATION 0 9 | #define CXIMAGE_SUPPORT_DSP 0 10 | #define CXIMAGE_SUPPORT_LAYERS 0 11 | #define CXIMAGE_SUPPORT_INTERPOLATION 0 12 | 13 | #define CXIMAGE_SUPPORT_DECODE 1 14 | #define CXIMAGE_SUPPORT_ENCODE 0 // 15 | #define CXIMAGE_SUPPORT_WINDOWS 1 16 | #define CXIMAGE_SUPPORT_EXIF 0 17 | 18 | ///////////////////////////////////////////////////////////////////////////// 19 | // CxImage supported formats 20 | #define CXIMAGE_SUPPORT_BMP 0 21 | #define CXIMAGE_SUPPORT_GIF 1 22 | #define CXIMAGE_SUPPORT_JPG 0 23 | #define CXIMAGE_SUPPORT_PNG 0 24 | #define CXIMAGE_SUPPORT_ICO 0 25 | #define CXIMAGE_SUPPORT_TIF 0 26 | #define CXIMAGE_SUPPORT_TGA 0 27 | #define CXIMAGE_SUPPORT_PCX 0 28 | #define CXIMAGE_SUPPORT_WBMP 0 29 | #define CXIMAGE_SUPPORT_WMF 0 30 | 31 | #define CXIMAGE_SUPPORT_JP2 0 32 | #define CXIMAGE_SUPPORT_JPC 0 33 | #define CXIMAGE_SUPPORT_PGX 0 34 | #define CXIMAGE_SUPPORT_PNM 0 35 | #define CXIMAGE_SUPPORT_RAS 0 36 | 37 | #define CXIMAGE_SUPPORT_JBG 0 // GPL'd see ../jbig/copying.txt & ../jbig/patents.htm 38 | 39 | #define CXIMAGE_SUPPORT_MNG 0 40 | #define CXIMAGE_SUPPORT_SKA 0 41 | #define CXIMAGE_SUPPORT_RAW 0 42 | #define CXIMAGE_SUPPORT_PSD 0 43 | 44 | ///////////////////////////////////////////////////////////////////////////// 45 | #define CXIMAGE_MAX_MEMORY 268435456 46 | 47 | #define CXIMAGE_DEFAULT_DPI 96 48 | 49 | #define CXIMAGE_ERR_NOFILE "null file handler" 50 | #define CXIMAGE_ERR_NOIMAGE "null image!!!" 51 | 52 | #define CXIMAGE_SUPPORT_EXCEPTION_HANDLING 1 53 | 54 | ///////////////////////////////////////////////////////////////////////////// 55 | //color to grey mapping 56 | //#define RGB2GRAY(r,g,b) (((b)*114 + (g)*587 + (r)*299)/1000) 57 | #define RGB2GRAY(r,g,b) (((b)*117 + (g)*601 + (r)*306) >> 10) 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximaico.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximaico.h 3 | * Purpose: ICON Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImageICO (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * ========================================================== 9 | */ 10 | #if !defined(__ximaICO_h) 11 | #define __ximaICO_h 12 | 13 | #include "ximage.h" 14 | 15 | #if CXIMAGE_SUPPORT_ICO 16 | 17 | class CxImageICO: public CxImage 18 | { 19 | typedef struct tagIconDirectoryEntry { 20 | uint8_t bWidth; 21 | uint8_t bHeight; 22 | uint8_t bColorCount; 23 | uint8_t bReserved; 24 | uint16_t wPlanes; 25 | uint16_t wBitCount; 26 | uint32_t dwBytesInRes; 27 | uint32_t dwImageOffset; 28 | } ICONDIRENTRY; 29 | 30 | typedef struct tagIconDir { 31 | uint16_t idReserved; 32 | uint16_t idType; 33 | uint16_t idCount; 34 | } ICONHEADER; 35 | 36 | public: 37 | CxImageICO(): CxImage(CXIMAGE_FORMAT_ICO) {m_dwImageOffset=0;} 38 | 39 | // bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_ICO);} 40 | // bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_ICO);} 41 | bool Decode(CxFile * hFile); 42 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 43 | 44 | #if CXIMAGE_SUPPORT_ENCODE 45 | bool Encode(CxFile * hFile, bool bAppend=false, int32_t nPageCount=0); 46 | bool Encode(CxFile * hFile, CxImage ** pImages, int32_t nPageCount); 47 | bool Encode(FILE *hFile, bool bAppend=false, int32_t nPageCount=0) 48 | { CxIOFile file(hFile); return Encode(&file,bAppend,nPageCount); } 49 | bool Encode(FILE *hFile, CxImage ** pImages, int32_t nPageCount) 50 | { CxIOFile file(hFile); return Encode(&file, pImages, nPageCount); } 51 | #endif // CXIMAGE_SUPPORT_ENCODE 52 | protected: 53 | uint32_t m_dwImageOffset; 54 | }; 55 | 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximajas.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximajas.h 3 | * Purpose: Jasper Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImageJAS (c) 12/Apr/2003 Davide Pizzolato - www.xdp.it 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * 9 | * based on JasPer Copyright (c) 2001-2003 Michael David Adams - All rights reserved. 10 | * ========================================================== 11 | */ 12 | #if !defined(__ximaJAS_h) 13 | #define __ximaJAS_h 14 | 15 | #include "ximage.h" 16 | 17 | #if CXIMAGE_SUPPORT_JASPER 18 | 19 | #ifdef _LINUX 20 | #include 21 | #else 22 | #include "../jasper/include/jasper/jasper.h" 23 | #endif 24 | 25 | class CxImageJAS: public CxImage 26 | { 27 | public: 28 | CxImageJAS(): CxImage((uint32_t)0) {} // cast to uint32_t 29 | 30 | // bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,0);} 31 | // bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,0);} 32 | bool Decode(CxFile * hFile, uint32_t imagetype = 0); 33 | bool Decode(FILE *hFile, uint32_t imagetype = 0) { CxIOFile file(hFile); return Decode(&file,imagetype); } 34 | 35 | #if CXIMAGE_SUPPORT_ENCODE 36 | bool Encode(CxFile * hFile, uint32_t imagetype = 0); 37 | bool Encode(FILE *hFile, uint32_t imagetype = 0) { CxIOFile file(hFile); return Encode(&file,imagetype); } 38 | #endif // CXIMAGE_SUPPORT_ENCODE 39 | protected: 40 | 41 | class CxFileJas 42 | { 43 | public: 44 | CxFileJas(CxFile* pFile,jas_stream_t *stream) 45 | { 46 | if (stream->obj_) jas_free(stream->obj_); 47 | stream->obj_ = pFile; 48 | 49 | // - cannot set the stream->ops_->functions here, 50 | // because this overwrites a static structure in the Jasper library. 51 | // This structure is used by Jasper for internal operations too, e.g. tempfile. 52 | // However the ops_ pointer in the stream can be overwritten. 53 | 54 | //stream->ops_->close_ = JasClose; 55 | //stream->ops_->read_ = JasRead; 56 | //stream->ops_->seek_ = JasSeek; 57 | //stream->ops_->write_ = JasWrite; 58 | 59 | jas_stream_CxFile.close_ = JasClose; 60 | jas_stream_CxFile.read_ = JasRead; 61 | jas_stream_CxFile.seek_ = JasSeek; 62 | jas_stream_CxFile.write_ = JasWrite; 63 | 64 | stream->ops_ = &jas_stream_CxFile; 65 | 66 | // - end 67 | } 68 | static int32_t JasRead(jas_stream_obj_t *obj, char *buf, int32_t cnt) 69 | { return ((CxFile*)obj)->Read(buf,1,cnt); } 70 | static int32_t JasWrite(jas_stream_obj_t *obj, char *buf, int32_t cnt) 71 | { return ((CxFile*)obj)->Write(buf,1,cnt); } 72 | static long JasSeek(jas_stream_obj_t *obj, long offset, int32_t origin) 73 | { return ((CxFile*)obj)->Seek(offset,origin); } 74 | static int32_t JasClose(jas_stream_obj_t * /*obj*/) 75 | { return 1; } 76 | 77 | // 78 | private: 79 | jas_stream_ops_t jas_stream_CxFile; 80 | // - end 81 | 82 | }; 83 | 84 | }; 85 | 86 | #endif 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximajbg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximajbg.cpp 3 | * Purpose: Platform Independent JBG Image Class Loader and Writer 4 | * 18/Aug/2002 Davide Pizzolato - www.xdp.it 5 | * CxImage version 7.0.1 07/Jan/2011 6 | */ 7 | 8 | #include "ximajbg.h" 9 | 10 | #if CXIMAGE_SUPPORT_JBG 11 | 12 | #include "ximaiter.h" 13 | 14 | #define JBIG_BUFSIZE 8192 15 | 16 | //////////////////////////////////////////////////////////////////////////////// 17 | #if CXIMAGE_SUPPORT_DECODE 18 | //////////////////////////////////////////////////////////////////////////////// 19 | bool CxImageJBG::Decode(CxFile *hFile) 20 | { 21 | if (hFile == NULL) return false; 22 | 23 | struct jbg_dec_state jbig_state; 24 | uint32_t xmax = 4294967295UL, ymax = 4294967295UL; 25 | uint32_t len, cnt; 26 | uint8_t *buffer=0,*p; 27 | int32_t result; 28 | 29 | cx_try 30 | { 31 | jbg_dec_init(&jbig_state); 32 | jbg_dec_maxsize(&jbig_state, xmax, ymax); 33 | 34 | buffer = (uint8_t*)malloc(JBIG_BUFSIZE); 35 | if (!buffer) cx_throw("Sorry, not enough memory available!"); 36 | 37 | result = JBG_EAGAIN; 38 | do { 39 | len = hFile->Read(buffer, 1, JBIG_BUFSIZE); 40 | if (!len) break; 41 | cnt = 0; 42 | p = buffer; 43 | while (len > 0 && (result == JBG_EAGAIN || result == JBG_EOK)) { 44 | result = jbg_dec_in(&jbig_state, p, len, &cnt); 45 | p += cnt; 46 | len -= cnt; 47 | } 48 | } while (result == JBG_EAGAIN || result == JBG_EOK); 49 | 50 | if (hFile->Error()) 51 | cx_throw("Problem while reading input file"); 52 | if (result != JBG_EOK && result != JBG_EOK_INTR) 53 | cx_throw("Problem with input file"); 54 | 55 | int32_t w, h, bpp, planes, ew; 56 | 57 | w = jbg_dec_getwidth(&jbig_state); 58 | h = jbg_dec_getheight(&jbig_state); 59 | planes = jbg_dec_getplanes(&jbig_state); 60 | bpp = (planes+7)>>3; 61 | ew = (w + 7)>>3; 62 | 63 | if (info.nEscape == -1){ 64 | head.biWidth = w; 65 | head.biHeight= h; 66 | info.dwType = CXIMAGE_FORMAT_JBG; 67 | cx_throw("output dimensions returned"); 68 | } 69 | 70 | switch (planes){ 71 | case 1: 72 | { 73 | uint8_t* binary_image = jbg_dec_getimage(&jbig_state, 0); 74 | 75 | if (!Create(w,h,1,CXIMAGE_FORMAT_JBG)) 76 | cx_throw(""); 77 | 78 | SetPaletteColor(0,255,255,255); 79 | SetPaletteColor(1,0,0,0); 80 | 81 | CImageIterator iter(this); 82 | iter.Upset(); 83 | for (int32_t i=0;i>3; 124 | ew = (w + 7)>>3; 125 | 126 | uint8_t mask; 127 | RGBQUAD *rgb = GetPalette(); 128 | if (CompareColors(&rgb[0],&rgb[1])<0) mask=255; else mask=0; 129 | 130 | uint8_t *buffer = (uint8_t*)malloc(ew*h*2); 131 | if (!buffer) { 132 | strcpy(info.szLastError,"Sorry, not enough memory available!"); 133 | return false; 134 | } 135 | 136 | for (y=0; yError()){ 166 | strcpy(info.szLastError,"Problem while writing JBG file"); 167 | return false; 168 | } 169 | 170 | return true; 171 | } 172 | //////////////////////////////////////////////////////////////////////////////// 173 | #endif // CXIMAGE_SUPPORT_JBG 174 | 175 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximajbg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximajbg.h 3 | * Purpose: JBG Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImageJBG (c) 18/Aug/2002 Davide Pizzolato - www.xdp.it 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * 9 | * based on LIBJBG Copyright (c) 2002, Markus Kuhn - All rights reserved. 10 | * ========================================================== 11 | */ 12 | #if !defined(__ximaJBG_h) 13 | #define __ximaJBG_h 14 | 15 | #include "ximage.h" 16 | 17 | #if CXIMAGE_SUPPORT_JBG 18 | 19 | extern "C" { 20 | #include "../jbig/jbig.h" 21 | }; 22 | 23 | class CxImageJBG: public CxImage 24 | { 25 | public: 26 | CxImageJBG(): CxImage(CXIMAGE_FORMAT_JBG) {} 27 | 28 | // bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_JBG);} 29 | // bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_JBG);} 30 | bool Decode(CxFile * hFile); 31 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 32 | 33 | #if CXIMAGE_SUPPORT_ENCODE 34 | bool Encode(CxFile * hFile); 35 | bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } 36 | #endif // CXIMAGE_SUPPORT_ENCODE 37 | protected: 38 | static void jbig_data_out(uint8_t *buffer, uint32_t len, void *file) 39 | {((CxFile*)file)->Write(buffer,len,1);} 40 | }; 41 | 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximalyr.cpp: -------------------------------------------------------------------------------- 1 | // xImaLyr.cpp : Layers functions 2 | /* 21/04/2003 v1.00 - Davide Pizzolato - www.xdp.it 3 | * CxImage version 7.0.1 07/Jan/2011 4 | */ 5 | 6 | #include "ximage.h" 7 | 8 | #if CXIMAGE_SUPPORT_LAYERS 9 | 10 | //////////////////////////////////////////////////////////////////////////////// 11 | /** 12 | * If the object is an internal layer, GetParent return its parent in the hierarchy. 13 | */ 14 | CxImage* CxImage::GetParent() const 15 | { 16 | return info.pParent; 17 | } 18 | //////////////////////////////////////////////////////////////////////////////// 19 | /** 20 | * Number of layers allocated directly by the object. 21 | */ 22 | int32_t CxImage::GetNumLayers() const 23 | { 24 | return info.nNumLayers; 25 | } 26 | //////////////////////////////////////////////////////////////////////////////// 27 | /** 28 | * Creates an empty layer. If position is less than 0, the new layer will be placed in the last position 29 | */ 30 | bool CxImage::LayerCreate(int32_t position) 31 | { 32 | if ( position < 0 || position > info.nNumLayers ) position = info.nNumLayers; 33 | 34 | CxImage** ptmp = new CxImage*[info.nNumLayers + 1]; 35 | if (ptmp==0) return false; 36 | 37 | int32_t i=0; 38 | for (int32_t n=0; ninfo.pParent = this; 49 | } else { 50 | free(ptmp); 51 | return false; 52 | } 53 | 54 | info.nNumLayers++; 55 | delete [] ppLayers; 56 | ppLayers = ptmp; 57 | return true; 58 | } 59 | //////////////////////////////////////////////////////////////////////////////// 60 | /** 61 | * Deletes a layer. If position is less than 0, the last layer will be deleted 62 | */ 63 | bool CxImage::LayerDelete(int32_t position) 64 | { 65 | if ( position >= info.nNumLayers ) return false; 66 | if ( position < 0) position = info.nNumLayers - 1; 67 | if ( position < 0) return false; 68 | 69 | if (info.nNumLayers>1){ 70 | 71 | CxImage** ptmp = new CxImage*[info.nNumLayers - 1]; 72 | if (ptmp==0) return false; 73 | 74 | int32_t i=0; 75 | for (int32_t n=0; n= info.nNumLayers ) return NULL; 112 | if ( position < 0) position = info.nNumLayers - 1; 113 | return ppLayers[position]; 114 | } 115 | //////////////////////////////////////////////////////////////////////////////// 116 | #endif //CXIMAGE_SUPPORT_LAYERS 117 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximamng.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximamng.h 3 | * Purpose: Declaration of the MNG Image Class 4 | * Author: Davide Pizzolato - www.xdp.it 5 | * Created: 2001 6 | */ 7 | /* ========================================================== 8 | * CxImageMNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it 9 | * For conditions of distribution and use, see copyright notice in ximage.h 10 | * 11 | * Special thanks to Frank Haug for suggestions and code. 12 | * 13 | * original mng.cpp code created by Nikolaus Brennig, November 14th, 2000. 14 | * 15 | * LIBMNG Copyright (c) 2000,2001 Gerard Juyn (gerard@libmng.com) 16 | * ========================================================== 17 | */ 18 | 19 | #if !defined(__ximaMNG_h) 20 | #define __ximaMNG_h 21 | 22 | #include "ximage.h" 23 | 24 | #if CXIMAGE_SUPPORT_MNG 25 | 26 | //#define MNG_NO_CMS 27 | #define MNG_SUPPORT_DISPLAY 28 | #define MNG_SUPPORT_READ 29 | #define MNG_SUPPORT_WRITE 30 | #define MNG_ACCESS_CHUNKS 31 | #define MNG_STORE_CHUNKS 32 | 33 | extern "C" { 34 | #include "../mng/libmng.h" 35 | #include "../mng/libmng_data.h" 36 | #include "../mng/libmng_error.h" 37 | } 38 | 39 | //uint32_t _stdcall RunMNGThread(void *lpParam); 40 | 41 | typedef struct tagmngstuff 42 | { 43 | CxFile *file; 44 | uint8_t *image; 45 | uint8_t *alpha; 46 | HANDLE thread; 47 | mng_uint32 delay; 48 | mng_uint32 width; 49 | mng_uint32 height; 50 | mng_uint32 effwdt; 51 | mng_int16 bpp; 52 | mng_bool animation; 53 | mng_bool animation_enabled; 54 | float speed; 55 | int32_t nBkgndIndex; 56 | RGBQUAD nBkgndColor; 57 | } mngstuff; 58 | 59 | class CxImageMNG: public CxImage 60 | { 61 | public: 62 | CxImageMNG(); 63 | ~CxImageMNG(); 64 | 65 | bool Load(const TCHAR * imageFileName); 66 | 67 | bool Decode(CxFile * hFile); 68 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 69 | 70 | #if CXIMAGE_SUPPORT_ENCODE 71 | bool Encode(CxFile * hFile); 72 | bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } 73 | bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_MNG);} 74 | #endif // CXIMAGE_SUPPORT_ENCODE 75 | 76 | int32_t Resume(); 77 | void SetSpeed(float speed); 78 | 79 | mng_handle hmng; 80 | mngstuff mnginfo; 81 | protected: 82 | void WritePNG(mng_handle hMNG, int32_t Frame, int32_t FrameCount ); 83 | void SetCallbacks(mng_handle mng); 84 | }; 85 | 86 | #endif 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximapcx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximapcx.h 3 | * Purpose: PCX Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImagePCX (c) 05/Jan/2002 Davide Pizzolato - www.xdp.it 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * 9 | * Parts of the code come from Paintlib: Copyright (c) 1996-1998 Ulrich von Zadow 10 | * ========================================================== 11 | */ 12 | #if !defined(__ximaPCX_h) 13 | #define __ximaPCX_h 14 | 15 | #include "ximage.h" 16 | 17 | #if CXIMAGE_SUPPORT_PCX 18 | 19 | class CxImagePCX: public CxImage 20 | { 21 | // PCX Image File 22 | #pragma pack(1) 23 | typedef struct tagPCXHEADER 24 | { 25 | char Manufacturer; // always 0X0A 26 | char Version; // version number 27 | char Encoding; // always 1 28 | char BitsPerPixel; // color bits 29 | uint16_t Xmin, Ymin; // image origin 30 | uint16_t Xmax, Ymax; // image dimensions 31 | uint16_t Hres, Vres; // resolution values 32 | uint8_t ColorMap[16][3]; // color palette 33 | char Reserved; 34 | char ColorPlanes; // color planes 35 | uint16_t BytesPerLine; // line buffer size 36 | uint16_t PaletteType; // grey or color palette 37 | char Filter[58]; 38 | } PCXHEADER; 39 | #pragma pack() 40 | 41 | public: 42 | CxImagePCX(): CxImage(CXIMAGE_FORMAT_PCX) {} 43 | 44 | // bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PCX);} 45 | // bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PCX);} 46 | bool Decode(CxFile * hFile); 47 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 48 | 49 | #if CXIMAGE_SUPPORT_ENCODE 50 | bool Encode(CxFile * hFile); 51 | bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } 52 | #endif // CXIMAGE_SUPPORT_ENCODE 53 | protected: 54 | bool PCX_PlanesToPixels(uint8_t * pixels, uint8_t * bitplanes, int16_t bytesperline, int16_t planes, int16_t bitsperpixel); 55 | bool PCX_UnpackPixels(uint8_t * pixels, uint8_t * bitplanes, int16_t bytesperline, int16_t planes, int16_t bitsperpixel); 56 | void PCX_PackPixels(const int32_t p,uint8_t &c, uint8_t &n, CxFile &f); 57 | void PCX_PackPlanes(uint8_t* buff, const int32_t size, CxFile &f); 58 | void PCX_PixelsToPlanes(uint8_t* raw, int32_t width, uint8_t* buf, int32_t plane); 59 | void PCX_toh(PCXHEADER* p); 60 | }; 61 | 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximapng.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximapng.h 3 | * Purpose: PNG Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImagePNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * 9 | * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes 10 | * 11 | * original CImagePNG and CImageIterator implementation are: 12 | * Copyright: (c) 1995, Alejandro Aguilar Sierra 13 | * 14 | * libpng Copyright (c) 1998-2003 Glenn Randers-Pehrson 15 | * ========================================================== 16 | */ 17 | #if !defined(__ximaPNG_h) 18 | #define __ximaPNG_h 19 | 20 | #include "ximage.h" 21 | 22 | #if CXIMAGE_SUPPORT_PNG 23 | 24 | extern "C" { 25 | #ifdef _LINUX 26 | #undef _DLL 27 | #include 28 | #include 29 | #include 30 | #else 31 | #include "../png/png.h" 32 | #include "../png/pngstruct.h" 33 | #include "../png/pnginfo.h" 34 | #endif 35 | } 36 | 37 | class CxImagePNG: public CxImage 38 | { 39 | public: 40 | CxImagePNG(): CxImage(CXIMAGE_FORMAT_PNG) {} 41 | 42 | // bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PNG);} 43 | // bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PNG);} 44 | bool Decode(CxFile * hFile); 45 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 46 | 47 | #if CXIMAGE_SUPPORT_ENCODE 48 | bool Encode(CxFile * hFile); 49 | bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } 50 | #endif // CXIMAGE_SUPPORT_ENCODE 51 | 52 | enum CODEC_OPTION 53 | { 54 | ENCODE_INTERLACE = 0x01, 55 | // Exclusive compression types : 3 bit wide field 56 | ENCODE_COMPRESSION_MASK = 0x0E, 57 | ENCODE_NO_COMPRESSION = 1 << 1, 58 | ENCODE_BEST_SPEED = 2 << 1, 59 | ENCODE_BEST_COMPRESSION = 3 << 1, 60 | ENCODE_DEFAULT_COMPRESSION = 4 << 1 61 | }; 62 | 63 | protected: 64 | void ima_png_error(png_struct *png_ptr, char *message); 65 | void expand2to4bpp(uint8_t* prow); 66 | 67 | static void PNGAPI user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) 68 | { 69 | CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr); 70 | if (hFile == NULL || hFile->Read(data,1,length) != length) png_error(png_ptr, "Read Error"); 71 | } 72 | 73 | static void PNGAPI user_write_data(png_structp png_ptr, png_bytep data, png_size_t length) 74 | { 75 | CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr); 76 | if (hFile == NULL || hFile->Write(data,1,length) != length) png_error(png_ptr, "Write Error"); 77 | } 78 | 79 | static void PNGAPI user_flush_data(png_structp png_ptr) 80 | { 81 | CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr); 82 | if (hFile == NULL || !hFile->Flush()) png_error(png_ptr, "Flush Error"); 83 | } 84 | 85 | static void PNGAPI user_error_fn(png_structp png_ptr,png_const_charp error_msg) 86 | { 87 | strncpy((char*)png_ptr->error_ptr,error_msg,255); 88 | longjmp(png_ptr->png_jmpbuf, 1); 89 | } 90 | }; 91 | 92 | #endif 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximapsd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximapsd.h 3 | * Purpose: PSD Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImagePSD (c) Dec/2010 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * 9 | * libpsd (c) 2004-2007 Graphest Software 10 | * 11 | * ========================================================== 12 | */ 13 | #if !defined(__ximaPSD_h) 14 | #define __ximaPSD_h 15 | 16 | #include "ximage.h" 17 | 18 | #if CXIMAGE_SUPPORT_PSD 19 | 20 | #define CXIMAGE_USE_LIBPSD 0 21 | 22 | #if CXIMAGE_USE_LIBPSD 23 | extern "C" { 24 | #include "../libpsd/libpsd.h" 25 | } 26 | #endif 27 | 28 | class CxImagePSD: public CxImage 29 | { 30 | 31 | public: 32 | CxImagePSD(): CxImage(CXIMAGE_FORMAT_PSD) {} 33 | 34 | // bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PSD);} 35 | // bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PSD);} 36 | bool Decode(CxFile * hFile); 37 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 38 | 39 | //#if CXIMAGE_SUPPORT_EXIF 40 | // bool GetExifThumbnail(const TCHAR *filename, const TCHAR *outname, int32_t type); 41 | //#endif //CXIMAGE_SUPPORT_EXIF 42 | 43 | #if CXIMAGE_SUPPORT_ENCODE 44 | bool Encode(CxFile * hFile); 45 | bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } 46 | #endif // CXIMAGE_SUPPORT_ENCODE 47 | 48 | #if CXIMAGE_USE_LIBPSD 49 | protected: 50 | class CxFilePsd 51 | { 52 | public: 53 | CxFilePsd(CxFile* pFile,psd_context *context) 54 | { 55 | context->file = pFile; 56 | 57 | psd_CxFile_ops.size_ = psd_file_size; 58 | psd_CxFile_ops.seek_ = psd_file_seek; 59 | psd_CxFile_ops.read_ = psd_file_read; 60 | // psd_CxFile_ops.write_ = psd_file_write; 61 | // psd_CxFile_ops.close_ = psd_file_close; 62 | // psd_CxFile_ops.gets_ = psd_file_gets; 63 | // psd_CxFile_ops.eof_ = psd_file_eof; 64 | // psd_CxFile_ops.tell_ = psd_file_tell; 65 | // psd_CxFile_ops.getc_ = psd_file_getc; 66 | // psd_CxFile_ops.scanf_ = psd_file_scanf; 67 | 68 | context->ops_ = &psd_CxFile_ops; 69 | 70 | } 71 | 72 | static int32_t psd_file_size(psd_file_obj *obj) 73 | { return ((CxFile*)obj)->Size(); } 74 | 75 | static int32_t psd_file_seek(psd_file_obj *obj, int32_t offset, int32_t origin) 76 | { return ((CxFile*)obj)->Seek(offset,origin); } 77 | 78 | static int32_t psd_file_read(psd_file_obj *obj, void *buf, int32_t size, int32_t cnt) 79 | { return ((CxFile*)obj)->Read(buf,size,cnt); } 80 | 81 | // static int32_t psd_file_write(psd_file_obj *obj, void *buf, int32_t size, int32_t cnt) 82 | // { return ((CxFile*)obj)->Write(buf,size,cnt); } 83 | 84 | // static int32_t psd_file_close(psd_file_obj *obj) 85 | // { return 1; /*((CxFile*)obj)->Close();*/ } 86 | 87 | // static char* psd_file_gets(psd_file_obj *obj, char *string, int32_t n) 88 | // { return ((CxFile*)obj)->GetS(string,n); } 89 | 90 | // static int32_t psd_file_eof(psd_file_obj *obj) 91 | // { return ((CxFile*)obj)->Eof(); } 92 | 93 | // static long psd_file_tell(psd_file_obj *obj) 94 | // { return ((CxFile*)obj)->Tell(); } 95 | 96 | // static int32_t psd_file_getc(psd_file_obj *obj) 97 | // { return ((CxFile*)obj)->GetC(); } 98 | 99 | // static int32_t psd_file_scanf(psd_file_obj *obj,const char *format, void* output) 100 | // { return ((CxFile*)obj)->Scanf(format, output); } 101 | 102 | private: 103 | psd_file_ops psd_CxFile_ops; 104 | }; 105 | #endif //CXIMAGE_USE_LIBPSD 106 | }; 107 | 108 | #endif 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximaraw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximaraw.h 3 | * Purpose: RAW Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImageRAW (c) May/2006 pdw63 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * Special thanks to David Coffin for dcraw without which this class would not exist 9 | * 10 | * libdcr (c) Dec/2007 Davide Pizzolato - www.xdp.it 11 | * 12 | * based on dcraw.c -- Dave Coffin's raw photo decoder 13 | * Copyright 1997-2007 by Dave Coffin, dcoffin a cybercom o net 14 | * ========================================================== 15 | */ 16 | #if !defined(__ximaRAW_h) 17 | #define __ximaRAW_h 18 | 19 | #include "ximage.h" 20 | 21 | #if CXIMAGE_SUPPORT_RAW 22 | 23 | extern "C" { 24 | #include "../raw/libdcr.h" 25 | } 26 | 27 | class CxImageRAW: public CxImage 28 | { 29 | 30 | public: 31 | CxImageRAW(): CxImage(CXIMAGE_FORMAT_RAW) {} 32 | 33 | // bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_ICO);} 34 | // bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_ICO);} 35 | bool Decode(CxFile * hFile); 36 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 37 | 38 | #if CXIMAGE_SUPPORT_EXIF 39 | bool GetExifThumbnail(const TCHAR *filename, const TCHAR *outname, int32_t type); 40 | #endif //CXIMAGE_SUPPORT_EXIF 41 | 42 | #if CXIMAGE_SUPPORT_ENCODE 43 | bool Encode(CxFile * hFile); 44 | bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } 45 | #endif // CXIMAGE_SUPPORT_ENCODE 46 | 47 | enum CODEC_OPTION 48 | { 49 | DECODE_QUALITY_LIN = 0x00, 50 | DECODE_QUALITY_VNG = 0x01, 51 | DECODE_QUALITY_PPG = 0x02, 52 | DECODE_QUALITY_AHD = 0x03, 53 | }; 54 | 55 | protected: 56 | 57 | class CxFileRaw 58 | { 59 | public: 60 | CxFileRaw(CxFile* pFile,DCRAW *stream) 61 | { 62 | stream->obj_ = pFile; 63 | 64 | ras_stream_CxFile.read_ = raw_sfile_read; 65 | ras_stream_CxFile.write_ = raw_sfile_write; 66 | ras_stream_CxFile.seek_ = raw_sfile_seek; 67 | ras_stream_CxFile.close_ = raw_sfile_close; 68 | ras_stream_CxFile.gets_ = raw_sfile_gets; 69 | ras_stream_CxFile.eof_ = raw_sfile_eof; 70 | ras_stream_CxFile.tell_ = raw_sfile_tell; 71 | ras_stream_CxFile.getc_ = raw_sfile_getc; 72 | ras_stream_CxFile.scanf_ = raw_sfile_scanf; 73 | 74 | stream->ops_ = &ras_stream_CxFile; 75 | 76 | } 77 | 78 | static int32_t raw_sfile_read(dcr_stream_obj *obj, void *buf, int32_t size, int32_t cnt) 79 | { return ((CxFile*)obj)->Read(buf,size,cnt); } 80 | 81 | static int32_t raw_sfile_write(dcr_stream_obj *obj, void *buf, int32_t size, int32_t cnt) 82 | { return ((CxFile*)obj)->Write(buf,size,cnt); } 83 | 84 | static long raw_sfile_seek(dcr_stream_obj *obj, long offset, int32_t origin) 85 | { return ((CxFile*)obj)->Seek(offset,origin); } 86 | 87 | static int32_t raw_sfile_close(dcr_stream_obj *obj) 88 | { return 1; /*((CxFile*)obj)->Close();*/ } 89 | 90 | static char* raw_sfile_gets(dcr_stream_obj *obj, char *string, int32_t n) 91 | { return ((CxFile*)obj)->GetS(string,n); } 92 | 93 | static int32_t raw_sfile_eof(dcr_stream_obj *obj) 94 | { return ((CxFile*)obj)->Eof(); } 95 | 96 | static long raw_sfile_tell(dcr_stream_obj *obj) 97 | { return ((CxFile*)obj)->Tell(); } 98 | 99 | static int32_t raw_sfile_getc(dcr_stream_obj *obj) 100 | { return ((CxFile*)obj)->GetC(); } 101 | 102 | static int32_t raw_sfile_scanf(dcr_stream_obj *obj,const char *format, void* output) 103 | { return ((CxFile*)obj)->Scanf(format, output); } 104 | 105 | private: 106 | dcr_stream_ops ras_stream_CxFile; 107 | }; 108 | }; 109 | 110 | #endif 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximaska.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximaska.cpp 3 | * Purpose: Platform Independent SKA Image Class Loader and Writer 4 | * 25/Sep/2007 Davide Pizzolato - www.xdp.it 5 | * CxImage version 7.0.1 07/Jan/2011 6 | */ 7 | 8 | #include "ximaska.h" 9 | 10 | #if CXIMAGE_SUPPORT_SKA 11 | 12 | //////////////////////////////////////////////////////////////////////////////// 13 | #if CXIMAGE_SUPPORT_DECODE 14 | //////////////////////////////////////////////////////////////////////////////// 15 | bool CxImageSKA::Decode(CxFile *hFile) 16 | { 17 | if (hFile==NULL) 18 | return false; 19 | 20 | // read the header 21 | SKAHEADER ska_header; 22 | hFile->Read(&ska_header,sizeof(SKAHEADER),1); 23 | 24 | ska_header.Width = m_ntohs(ska_header.Width); 25 | ska_header.Height = m_ntohs(ska_header.Height); 26 | ska_header.dwUnknown = m_ntohl(ska_header.dwUnknown); 27 | 28 | // check header 29 | if (ska_header.dwUnknown != 0x01000000 || 30 | ska_header.Width > 0x7FFF || ska_header.Height > 0x7FFF || 31 | ska_header.BppExp != 3) 32 | return false; 33 | 34 | if (info.nEscape == -1){ 35 | head.biWidth = ska_header.Width ; 36 | head.biHeight= ska_header.Height; 37 | info.dwType = CXIMAGE_FORMAT_SKA; 38 | return true; 39 | } 40 | 41 | int32_t bpp = 1<Read(ppal,nColors*sizeof(rgb_color),1); 52 | SetPalette(ppal,nColors); 53 | free(ppal); 54 | 55 | //read the image 56 | hFile->Read(GetBits(),ska_header.Width*ska_header.Height,1); 57 | 58 | //reorder rows 59 | if (GetEffWidth() != ska_header.Width){ 60 | uint8_t *src,*dst; 61 | src = GetBits() + ska_header.Width*(ska_header.Height-1); 62 | dst = GetBits(ska_header.Height-1); 63 | for(int32_t y=0;y 8) { 84 | strcpy(info.szLastError,"SKA Images must be 8 bit or less"); 85 | return false; 86 | } 87 | 88 | SKAHEADER ska_header; 89 | 90 | ska_header.Width = (uint16_t)GetWidth(); 91 | ska_header.Height = (uint16_t)GetHeight(); 92 | ska_header.BppExp = 3; 93 | ska_header.dwUnknown = 0x01000000; 94 | 95 | ska_header.Width = m_ntohs(ska_header.Width); 96 | ska_header.Height = m_ntohs(ska_header.Height); 97 | ska_header.dwUnknown = m_ntohl(ska_header.dwUnknown); 98 | 99 | hFile->Write(&ska_header,sizeof(SKAHEADER),1); 100 | 101 | ska_header.Width = m_ntohs(ska_header.Width); 102 | ska_header.Height = m_ntohs(ska_header.Height); 103 | ska_header.dwUnknown = m_ntohl(ska_header.dwUnknown); 104 | 105 | if (head.biBitCount<8) IncreaseBpp(8); 106 | 107 | rgb_color pal[256]; 108 | for(int32_t idx=0; idx<256; idx++){ 109 | GetPaletteColor(idx,&(pal[idx].r),&(pal[idx].g),&(pal[idx].b)); 110 | } 111 | 112 | hFile->Write(pal,256*sizeof(rgb_color),1); 113 | 114 | uint8_t* src = GetBits(ska_header.Height-1); 115 | for(int32_t y=0;yWrite(src,ska_header.Width,1); 117 | src -= GetEffWidth(); 118 | } 119 | 120 | return true; 121 | } 122 | //////////////////////////////////////////////////////////////////////////////// 123 | #endif // CXIMAGE_SUPPORT_ENCODE 124 | //////////////////////////////////////////////////////////////////////////////// 125 | #endif // CXIMAGE_SUPPORT_SKA 126 | 127 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximaska.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximaska.h 3 | * Purpose: SKA Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImageSKA (c) 25/Sep/2007 Davide Pizzolato - www.xdp.it 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * ========================================================== 9 | */ 10 | #if !defined(__ximaSKA_h) 11 | #define __ximaSKA_h 12 | 13 | #include "ximage.h" 14 | 15 | #if CXIMAGE_SUPPORT_SKA 16 | 17 | class CxImageSKA: public CxImage 18 | { 19 | #pragma pack(1) 20 | typedef struct tagSkaHeader { 21 | uint16_t Width; 22 | uint16_t Height; 23 | uint8_t BppExp; 24 | uint32_t dwUnknown; 25 | } SKAHEADER; 26 | #pragma pack() 27 | 28 | public: 29 | CxImageSKA(): CxImage(CXIMAGE_FORMAT_SKA) {} 30 | 31 | // bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_ICO);} 32 | // bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_ICO);} 33 | bool Decode(CxFile * hFile); 34 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 35 | 36 | #if CXIMAGE_SUPPORT_ENCODE 37 | bool Encode(CxFile * hFile); 38 | bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } 39 | #endif // CXIMAGE_SUPPORT_ENCODE 40 | }; 41 | 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximatga.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximatga.h 3 | * Purpose: TARGA Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImageTGA (c) 05/Jan/2002 Davide Pizzolato - www.xdp.it 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * 9 | * Parts of the code come from Paintlib : Copyright (c) 1996-1998 Ulrich von Zadow 10 | * ========================================================== 11 | */ 12 | #if !defined(__ximaTGA_h) 13 | #define __ximaTGA_h 14 | 15 | #include "ximage.h" 16 | 17 | #if CXIMAGE_SUPPORT_TGA 18 | 19 | class CxImageTGA: public CxImage 20 | { 21 | #pragma pack(1) 22 | typedef struct tagTgaHeader 23 | { 24 | uint8_t IdLength; // Image ID Field Length 25 | uint8_t CmapType; // Color Map Type 26 | uint8_t ImageType; // Image Type 27 | 28 | uint16_t CmapIndex; // First Entry Index 29 | uint16_t CmapLength; // Color Map Length 30 | uint8_t CmapEntrySize; // Color Map Entry Size 31 | 32 | uint16_t X_Origin; // X-origin of Image 33 | uint16_t Y_Origin; // Y-origin of Image 34 | uint16_t ImageWidth; // Image Width 35 | uint16_t ImageHeight; // Image Height 36 | uint8_t PixelDepth; // Pixel Depth 37 | uint8_t ImagDesc; // Image Descriptor 38 | } TGAHEADER; 39 | #pragma pack() 40 | 41 | public: 42 | CxImageTGA(): CxImage(CXIMAGE_FORMAT_TGA) {} 43 | 44 | // bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_TGA);} 45 | // bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_TGA);} 46 | bool Decode(CxFile * hFile); 47 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 48 | 49 | #if CXIMAGE_SUPPORT_ENCODE 50 | bool Encode(CxFile * hFile); 51 | bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } 52 | #endif // CXIMAGE_SUPPORT_ENCODE 53 | protected: 54 | uint8_t ExpandCompressedLine(uint8_t* pDest,TGAHEADER* ptgaHead,CxFile *hFile,int32_t width, int32_t y, uint8_t rleLeftover); 55 | void ExpandUncompressedLine(uint8_t* pDest,TGAHEADER* ptgaHead,CxFile *hFile,int32_t width, int32_t y, int32_t xoffset); 56 | void tga_toh(TGAHEADER* p); 57 | }; 58 | 59 | #endif 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximath.cpp: -------------------------------------------------------------------------------- 1 | #include "ximage.h" 2 | #include "ximath.h" 3 | #include 4 | 5 | //this module should contain some classes for geometrical transformations 6 | //usable with selections, etc... once it's done, that is. :) 7 | 8 | CxPoint2::CxPoint2() 9 | { 10 | x=y=0.0f; 11 | } 12 | 13 | CxPoint2::CxPoint2(float const x_, float const y_) 14 | { 15 | x=x_; 16 | y=y_; 17 | } 18 | 19 | CxPoint2::CxPoint2(CxPoint2 const &p) 20 | { 21 | x=p.x; 22 | y=p.y; 23 | } 24 | 25 | float CxPoint2::Distance(CxPoint2 const p2) 26 | { 27 | return (float)sqrt((x-p2.x)*(x-p2.x)+(y-p2.y)*(y-p2.y)); 28 | } 29 | 30 | float CxPoint2::Distance(float const x_, float const y_) 31 | { 32 | return (float)sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_)); 33 | } 34 | 35 | CxRect2::CxRect2() 36 | { 37 | } 38 | 39 | CxRect2::CxRect2(float const x1_, float const y1_, float const x2_, float const y2_) 40 | { 41 | botLeft.x=x1_; 42 | botLeft.y=y1_; 43 | topRight.x=x2_; 44 | topRight.y=y2_; 45 | } 46 | 47 | CxRect2::CxRect2(CxRect2 const &p) 48 | { 49 | botLeft=p.botLeft; 50 | topRight=p.topRight; 51 | } 52 | 53 | float CxRect2::Surface() const 54 | /* 55 | * Returns the surface of rectangle. 56 | */ 57 | { 58 | return (topRight.x-botLeft.x)*(topRight.y-botLeft.y); 59 | } 60 | 61 | CxRect2 CxRect2::CrossSection(CxRect2 const &r2) const 62 | /* 63 | * Returns crossection with another rectangle. 64 | */ 65 | { 66 | CxRect2 cs; 67 | cs.botLeft.x=max(botLeft.x, r2.botLeft.x); 68 | cs.botLeft.y=max(botLeft.y, r2.botLeft.y); 69 | cs.topRight.x=min(topRight.x, r2.topRight.x); 70 | cs.topRight.y=min(topRight.y, r2.topRight.y); 71 | if (cs.botLeft.x<=cs.topRight.x && cs.botLeft.y<=cs.topRight.y) { 72 | return cs; 73 | } else { 74 | return CxRect2(0,0,0,0); 75 | }//if 76 | } 77 | 78 | CxPoint2 CxRect2::Center() const 79 | /* 80 | * Returns the center point of rectangle. 81 | */ 82 | { 83 | return CxPoint2((topRight.x+botLeft.x)/2.0f, (topRight.y+botLeft.y)/2.0f); 84 | } 85 | 86 | float CxRect2::Width() const 87 | //returns rectangle width 88 | { 89 | return topRight.x-botLeft.x; 90 | } 91 | 92 | float CxRect2::Height() const 93 | //returns rectangle height 94 | { 95 | return topRight.y-botLeft.y; 96 | } 97 | 98 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximath.h: -------------------------------------------------------------------------------- 1 | #if !defined(__ximath_h) 2 | #define __ximath_h 3 | 4 | #include "ximadef.h" 5 | 6 | //***bd*** simple floating point point 7 | class DLL_EXP CxPoint2 8 | { 9 | public: 10 | CxPoint2(); 11 | CxPoint2(float const x_, float const y_); 12 | CxPoint2(CxPoint2 const &p); 13 | 14 | float Distance(CxPoint2 const p2); 15 | float Distance(float const x_, float const y_); 16 | 17 | float x,y; 18 | }; 19 | 20 | //and simple rectangle 21 | class DLL_EXP CxRect2 22 | { 23 | public: 24 | CxRect2(); 25 | CxRect2(float const x1_, float const y1_, float const x2_, float const y2_); 26 | CxRect2(CxPoint2 const &bl, CxPoint2 const &tr); 27 | CxRect2(CxRect2 const &p); 28 | 29 | float Surface() const; 30 | CxRect2 CrossSection(CxRect2 const &r2) const; 31 | CxPoint2 Center() const; 32 | float Width() const; 33 | float Height() const; 34 | 35 | CxPoint2 botLeft; 36 | CxPoint2 topRight; 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximatif.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximatif.h 3 | * Purpose: TIFF Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImageTIF (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * 9 | * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes 10 | * 11 | * Special thanks to Abe for MultiPageTIFF code. 12 | * 13 | * LibTIFF is: 14 | * Copyright (c) 1988-1997 Sam Leffler 15 | * Copyright (c) 1991-1997 Silicon Graphics, Inc. 16 | * ========================================================== 17 | */ 18 | 19 | #if !defined(__ximatif_h) 20 | #define __ximatif_h 21 | 22 | #include "ximage.h" 23 | 24 | #if CXIMAGE_SUPPORT_TIF 25 | 26 | #include "../tiff/tiffio.h" 27 | 28 | class DLL_EXP CxImageTIF: public CxImage 29 | { 30 | public: 31 | CxImageTIF(): CxImage(CXIMAGE_FORMAT_TIF) {m_tif2=NULL; m_multipage=false; m_pages=0;} 32 | ~CxImageTIF(); 33 | 34 | TIFF* TIFFOpenEx(CxFile * hFile); 35 | void TIFFCloseEx(TIFF* tif); 36 | 37 | // bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_TIF);} 38 | // bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_TIF);} 39 | bool Decode(CxFile * hFile); 40 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 41 | 42 | #if CXIMAGE_SUPPORT_ENCODE 43 | bool Encode(CxFile * hFile, bool bAppend=false); 44 | bool Encode(CxFile * hFile, CxImage ** pImages, int32_t pagecount); 45 | bool Encode(FILE *hFile, bool bAppend=false) { CxIOFile file(hFile); return Encode(&file,bAppend); } 46 | bool Encode(FILE *hFile, CxImage ** pImages, int32_t pagecount) 47 | { CxIOFile file(hFile); return Encode(&file, pImages, pagecount); } 48 | #endif // CXIMAGE_SUPPORT_ENCODE 49 | 50 | protected: 51 | void TileToStrip(uint8* out, uint8* in, uint32 rows, uint32 cols, int32_t outskew, int32_t inskew); 52 | bool EncodeBody(TIFF *m_tif, bool multipage=false, int32_t page=0, int32_t pagecount=0); 53 | TIFF *m_tif2; 54 | bool m_multipage; 55 | int32_t m_pages; 56 | void MoveBits( uint8_t* dest, uint8_t* from, int32_t count, int32_t bpp ); 57 | void MoveBitsPal( uint8_t* dest, uint8_t*from, int32_t count, int32_t bpp, RGBQUAD* pal ); 58 | }; 59 | 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximawbmp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximawbmp.cpp 3 | * Purpose: Platform Independent WBMP Image Class Loader and Writer 4 | * 12/Jul/2002 Davide Pizzolato - www.xdp.it 5 | * CxImage version 7.0.1 07/Jan/2011 6 | */ 7 | 8 | #include "ximawbmp.h" 9 | 10 | #if CXIMAGE_SUPPORT_WBMP 11 | 12 | #include "ximaiter.h" 13 | 14 | //////////////////////////////////////////////////////////////////////////////// 15 | #if CXIMAGE_SUPPORT_DECODE 16 | //////////////////////////////////////////////////////////////////////////////// 17 | bool CxImageWBMP::Decode(CxFile *hFile) 18 | { 19 | if (hFile == NULL) return false; 20 | 21 | WBMPHEADER wbmpHead; 22 | 23 | cx_try 24 | { 25 | ReadOctet(hFile, &wbmpHead.Type); 26 | 27 | uint32_t dat; 28 | ReadOctet(hFile, &dat); 29 | wbmpHead.FixHeader = (uint8_t)dat; 30 | 31 | ReadOctet(hFile, &wbmpHead.ImageWidth); 32 | ReadOctet(hFile, &wbmpHead.ImageHeight); 33 | 34 | if (hFile->Eof()) 35 | cx_throw("Not a WBMP"); 36 | 37 | if (wbmpHead.Type != 0) 38 | cx_throw("Unsupported WBMP type"); 39 | 40 | head.biWidth = wbmpHead.ImageWidth; 41 | head.biHeight= wbmpHead.ImageHeight; 42 | 43 | if (head.biWidth<=0 || head.biHeight<=0) 44 | cx_throw("Corrupted WBMP"); 45 | 46 | if (info.nEscape == -1){ 47 | info.dwType = CXIMAGE_FORMAT_WBMP; 48 | return true; 49 | } 50 | 51 | Create(head.biWidth, head.biHeight, 1, CXIMAGE_FORMAT_WBMP); 52 | if (!IsValid()) cx_throw("WBMP Create failed"); 53 | SetGrayPalette(); 54 | 55 | int32_t linewidth=(head.biWidth+7)/8; 56 | CImageIterator iter(this); 57 | iter.Upset(); 58 | for (int32_t y=0; y < head.biHeight; y++){ 59 | hFile->Read(iter.GetRow(),linewidth,1); 60 | iter.PrevRow(); 61 | } 62 | 63 | } cx_catch { 64 | if (strcmp(message,"")) strncpy(info.szLastError,message,255); 65 | return FALSE; 66 | } 67 | return true; 68 | } 69 | //////////////////////////////////////////////////////////////////////////////// 70 | bool CxImageWBMP::ReadOctet(CxFile * hFile, uint32_t *data) 71 | { 72 | uint8_t c; 73 | *data = 0; 74 | do { 75 | if (hFile->Eof()) return false; 76 | c = (uint8_t)hFile->GetC(); 77 | *data <<= 7; 78 | *data |= (c & 0x7F); 79 | } while ((c&0x80)!=0); 80 | return true; 81 | } 82 | //////////////////////////////////////////////////////////////////////////////// 83 | #endif //CXIMAGE_SUPPORT_DECODE 84 | //////////////////////////////////////////////////////////////////////////////// 85 | #if CXIMAGE_SUPPORT_ENCODE 86 | //////////////////////////////////////////////////////////////////////////////// 87 | bool CxImageWBMP::Encode(CxFile * hFile) 88 | { 89 | if (EncodeSafeCheck(hFile)) return false; 90 | 91 | //check format limits 92 | if (head.biBitCount!=1){ 93 | strcpy(info.szLastError,"Can't save this image as WBMP"); 94 | return false; 95 | } 96 | 97 | WBMPHEADER wbmpHead; 98 | wbmpHead.Type=0; 99 | wbmpHead.FixHeader=0; 100 | wbmpHead.ImageWidth=head.biWidth; 101 | wbmpHead.ImageHeight=head.biHeight; 102 | 103 | // Write the file header 104 | hFile->PutC('\0'); 105 | hFile->PutC('\0'); 106 | WriteOctet(hFile,wbmpHead.ImageWidth); 107 | WriteOctet(hFile,wbmpHead.ImageHeight); 108 | // Write the pixels 109 | int32_t linewidth=(wbmpHead.ImageWidth+7)/8; 110 | CImageIterator iter(this); 111 | iter.Upset(); 112 | for (uint32_t y=0; y < wbmpHead.ImageHeight; y++){ 113 | hFile->Write(iter.GetRow(),linewidth,1); 114 | iter.PrevRow(); 115 | } 116 | return true; 117 | } 118 | //////////////////////////////////////////////////////////////////////////////// 119 | bool CxImageWBMP::WriteOctet(CxFile * hFile, const uint32_t data) 120 | { 121 | int32_t ns = 0; 122 | while (data>>(ns+7)) ns+=7; 123 | while (ns>0){ 124 | if (!hFile->PutC(0x80 | (uint8_t)(data>>ns))) return false; 125 | ns-=7; 126 | } 127 | if (!(hFile->PutC((uint8_t)(0x7F & data)))) return false; 128 | return true; 129 | } 130 | //////////////////////////////////////////////////////////////////////////////// 131 | #endif // CXIMAGE_SUPPORT_ENCODE 132 | //////////////////////////////////////////////////////////////////////////////// 133 | #endif // CXIMAGE_SUPPORT_WBMP 134 | 135 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/ximawbmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: ximawbmp.h 3 | * Purpose: WBMP Image Class Loader and Writer 4 | */ 5 | /* ========================================================== 6 | * CxImageWBMP (c) 12/Jul/2002 Davide Pizzolato - www.xdp.it 7 | * For conditions of distribution and use, see copyright notice in ximage.h 8 | * ========================================================== 9 | */ 10 | #if !defined(__ximaWBMP_h) 11 | #define __ximaWBMP_h 12 | 13 | #include "ximage.h" 14 | 15 | #if CXIMAGE_SUPPORT_WBMP 16 | 17 | class CxImageWBMP: public CxImage 18 | { 19 | #pragma pack(1) 20 | typedef struct tagWbmpHeader 21 | { 22 | uint32_t Type; // 0 23 | uint8_t FixHeader; // 0 24 | uint32_t ImageWidth; // Image Width 25 | uint32_t ImageHeight; // Image Height 26 | } WBMPHEADER; 27 | #pragma pack() 28 | public: 29 | CxImageWBMP(): CxImage(CXIMAGE_FORMAT_WBMP) {} 30 | 31 | // bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_WBMP);} 32 | // bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_WBMP);} 33 | bool Decode(CxFile * hFile); 34 | bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } 35 | protected: 36 | bool ReadOctet(CxFile * hFile, uint32_t *data); 37 | 38 | public: 39 | #if CXIMAGE_SUPPORT_ENCODE 40 | bool Encode(CxFile * hFile); 41 | bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } 42 | protected: 43 | bool WriteOctet(CxFile * hFile, const uint32_t data); 44 | #endif // CXIMAGE_SUPPORT_ENCODE 45 | }; 46 | 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/xiofile.h: -------------------------------------------------------------------------------- 1 | #if !defined(__xiofile_h) 2 | #define __xiofile_h 3 | 4 | #include "xfile.h" 5 | //#include 6 | 7 | class DLL_EXP CxIOFile : public CxFile 8 | { 9 | public: 10 | CxIOFile(FILE* fp = NULL) 11 | { 12 | m_fp = fp; 13 | m_bCloseFile = (bool)(fp==0); 14 | } 15 | 16 | ~CxIOFile() 17 | { 18 | Close(); 19 | } 20 | ////////////////////////////////////////////////////////// 21 | bool Open(const TCHAR * filename, const TCHAR * mode) 22 | { 23 | if (m_fp) return false; // Can't re-open without closing first 24 | 25 | m_fp = _tfopen(filename, mode); 26 | if (!m_fp) return false; 27 | 28 | m_bCloseFile = true; 29 | 30 | return true; 31 | } 32 | ////////////////////////////////////////////////////////// 33 | virtual bool Close() 34 | { 35 | int32_t iErr = 0; 36 | if ( (m_fp) && (m_bCloseFile) ){ 37 | iErr = fclose(m_fp); 38 | m_fp = NULL; 39 | } 40 | return (bool)(iErr==0); 41 | } 42 | ////////////////////////////////////////////////////////// 43 | virtual size_t Read(void *buffer, size_t size, size_t count) 44 | { 45 | if (!m_fp) return 0; 46 | return fread(buffer, size, count, m_fp); 47 | } 48 | ////////////////////////////////////////////////////////// 49 | virtual size_t Write(const void *buffer, size_t size, size_t count) 50 | { 51 | if (!m_fp) return 0; 52 | return fwrite(buffer, size, count, m_fp); 53 | } 54 | ////////////////////////////////////////////////////////// 55 | virtual bool Seek(int32_t offset, int32_t origin) 56 | { 57 | if (!m_fp) return false; 58 | return (bool)(fseek(m_fp, offset, origin) == 0); 59 | } 60 | ////////////////////////////////////////////////////////// 61 | virtual int32_t Tell() 62 | { 63 | if (!m_fp) return 0; 64 | return ftell(m_fp); 65 | } 66 | ////////////////////////////////////////////////////////// 67 | virtual int32_t Size() 68 | { 69 | if (!m_fp) return -1; 70 | int32_t pos,size; 71 | pos = ftell(m_fp); 72 | fseek(m_fp, 0, SEEK_END); 73 | size = ftell(m_fp); 74 | fseek(m_fp, pos,SEEK_SET); 75 | return size; 76 | } 77 | ////////////////////////////////////////////////////////// 78 | virtual bool Flush() 79 | { 80 | if (!m_fp) return false; 81 | return (bool)(fflush(m_fp) == 0); 82 | } 83 | ////////////////////////////////////////////////////////// 84 | virtual bool Eof() 85 | { 86 | if (!m_fp) return true; 87 | return (bool)(feof(m_fp) != 0); 88 | } 89 | ////////////////////////////////////////////////////////// 90 | virtual int32_t Error() 91 | { 92 | if (!m_fp) return -1; 93 | return ferror(m_fp); 94 | } 95 | ////////////////////////////////////////////////////////// 96 | virtual bool PutC(uint8_t c) 97 | { 98 | if (!m_fp) return false; 99 | return (bool)(fputc(c, m_fp) == c); 100 | } 101 | ////////////////////////////////////////////////////////// 102 | virtual int32_t GetC() 103 | { 104 | if (!m_fp) return EOF; 105 | return getc(m_fp); 106 | } 107 | ////////////////////////////////////////////////////////// 108 | virtual char * GetS(char *string, int32_t n) 109 | { 110 | if (!m_fp) return NULL; 111 | return fgets(string,n,m_fp); 112 | } 113 | ////////////////////////////////////////////////////////// 114 | virtual int32_t Scanf(const char *format, void* output) 115 | { 116 | if (!m_fp) return EOF; 117 | return fscanf(m_fp, format, output); 118 | } 119 | ////////////////////////////////////////////////////////// 120 | protected: 121 | FILE *m_fp; 122 | bool m_bCloseFile; 123 | }; 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /DuiLib/3rd/CxImage/xmemfile.h: -------------------------------------------------------------------------------- 1 | #if !defined(__xmemfile_h) 2 | #define __xmemfile_h 3 | 4 | #include "xfile.h" 5 | 6 | ////////////////////////////////////////////////////////// 7 | class DLL_EXP CxMemFile : public CxFile 8 | { 9 | public: 10 | CxMemFile(uint8_t* pBuffer = NULL, uint32_t size = 0); 11 | ~CxMemFile(); 12 | 13 | bool Open(); 14 | uint8_t* GetBuffer(bool bDetachBuffer = true); 15 | 16 | virtual bool Close(); 17 | virtual size_t Read(void *buffer, size_t size, size_t count); 18 | virtual size_t Write(const void *buffer, size_t size, size_t count); 19 | virtual bool Seek(int32_t offset, int32_t origin); 20 | virtual int32_t Tell(); 21 | virtual int32_t Size(); 22 | virtual bool Flush(); 23 | virtual bool Eof(); 24 | virtual int32_t Error(); 25 | virtual bool PutC(uint8_t c); 26 | virtual int32_t GetC(); 27 | virtual char * GetS(char *string, int32_t n); 28 | virtual int32_t Scanf(const char *format, void* output); 29 | 30 | protected: 31 | bool Alloc(uint32_t nBytes); 32 | void Free(); 33 | 34 | uint8_t* m_pBuffer; 35 | uint32_t m_Size; 36 | bool m_bFreeOnClose; 37 | int32_t m_Position; //current position 38 | int32_t m_Edge; //buffer size 39 | bool m_bEOF; 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /DuiLib/Bind/BindBase.h: -------------------------------------------------------------------------------- 1 | #ifndef __BIND_BASE_H__ 2 | #define __BIND_BASE_H__ 3 | 4 | #pragma once 5 | 6 | 7 | 8 | namespace DuiLib { 9 | class BindCtrlBase { 10 | //friend class WindowImplBase; 11 | public: 12 | BindCtrlBase (CControlUI *_ctrl): m_ctrl (_ctrl) {} 13 | BindCtrlBase (faw::string_t ctrl_name): m_ctrl_name (ctrl_name) {} 14 | virtual ~BindCtrlBase () {} 15 | 16 | protected: 17 | virtual faw::string_t GetClassType () const = 0; 18 | virtual void binded () {} 19 | CControlUI *m_ctrl = nullptr; 20 | faw::string_t m_ctrl_name; 21 | 22 | //static CPaintManagerUI *s_pm; 23 | private: 24 | //static std::map s_bind_ctrls; 25 | //static void init_binding (CPaintManagerUI *pm); 26 | }; 27 | 28 | 29 | 30 | //template 31 | //class BindVarBase: public BindCtrlBase { 32 | //public: 33 | // BindVarBase (faw::string_t ctrl_name): BindCtrlBase (ctrl_name) {} 34 | // virtual ~BindVarBase () = default; 35 | // faw::string_t GetVarType () const; 36 | 37 | // // 访问函数(未完成) 38 | // //void operator= (T &o); 39 | // //T &operator() (); 40 | 41 | //protected: 42 | // void binded () override; 43 | //}; 44 | } 45 | 46 | #endif //__BIND_BASE_H__ 47 | -------------------------------------------------------------------------------- /DuiLib/Bind/BindCtrls.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __BIND_CTRLS_HPP__ 2 | #define __BIND_CTRLS_HPP__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | #define DEF_BINDCTRL(CTRL_TYPE) \ 8 | class Bind##CTRL_TYPE##UI: public BindCtrlBase { \ 9 | public: \ 10 | Bind##CTRL_TYPE##UI (CControlUI *_ctrl): BindCtrlBase (_ctrl) {} \ 11 | Bind##CTRL_TYPE##UI (faw::string_t ctrl_name, CPaintManagerUI *pm = nullptr): BindCtrlBase (ctrl_name), m_pm (pm) {} \ 12 | C##CTRL_TYPE##UI *operator* () { \ 13 | if (!*this) \ 14 | throw std::exception ("BindControlUI bind failed"); \ 15 | return static_cast (m_ctrl); \ 16 | } \ 17 | C##CTRL_TYPE##UI *operator-> () { return operator* (); } \ 18 | operator bool () { \ 19 | if (m_ctrl) \ 20 | return true; \ 21 | if (!m_pm) \ 22 | m_pm = CPaintManagerUI::GetPaintManager (_T ("")); \ 23 | if (!m_pm) \ 24 | return false; \ 25 | m_ctrl = m_pm->FindControl (m_ctrl_name); \ 26 | return !!m_ctrl; \ 27 | } \ 28 | protected: \ 29 | faw::string_t GetClassType () const override { return _T (#CTRL_TYPE##"UI"); } \ 30 | CPaintManagerUI *m_pm = nullptr; \ 31 | } 32 | 33 | 34 | 35 | // Core 36 | DEF_BINDCTRL (Control); 37 | //class BindControlUI: public BindCtrlBase { 38 | //public: 39 | // BindControlUI (CControlUI *_ctrl): BindCtrlBase (_ctrl) {} 40 | // BindControlUI (faw::string_t ctrl_name, CPaintManagerUI *pm = nullptr): BindCtrlBase (ctrl_name), m_pm (pm) {} 41 | // CControlUI *operator* () { 42 | // if (!*this) 43 | // throw std::exception ("BindControlUI bind failed"); 44 | // return static_cast (m_ctrl); 45 | // } 46 | // CControlUI *operator-> () { return operator* (); } 47 | // operator bool () noexcept { 48 | // if (m_ctrl) 49 | // return true; 50 | // if (!m_pm) 51 | // m_pm = CPaintManagerUI::GetPaintManager (_T ("")); 52 | // if (!m_pm) 53 | // return false; 54 | // m_ctrl = m_pm->FindControl (m_ctrl_name); 55 | // return !!m_ctrl; 56 | // } 57 | //protected: 58 | // faw::string_t GetClassType () const override { return _T ("ControlUI"); } 59 | // CPaintManagerUI *m_pm = nullptr; 60 | //}; 61 | DEF_BINDCTRL (Container); 62 | 63 | // Control 64 | DEF_BINDCTRL (ActiveX); 65 | //DEF_BINDCTRL (Animation); 66 | DEF_BINDCTRL (Button); 67 | DEF_BINDCTRL (ColorPalette); 68 | DEF_BINDCTRL (Combo); 69 | DEF_BINDCTRL (ComboBox); 70 | DEF_BINDCTRL (DateTime); 71 | DEF_BINDCTRL (Edit); 72 | DEF_BINDCTRL (FadeButton); 73 | DEF_BINDCTRL (Flash); 74 | DEF_BINDCTRL (GifAnim); 75 | #ifdef USE_XIMAGE_EFFECT 76 | DEF_BINDCTRL (GifAnimEx); 77 | #endif 78 | DEF_BINDCTRL (GroupBox); 79 | DEF_BINDCTRL (HotKey); 80 | DEF_BINDCTRL (IPAddress); 81 | DEF_BINDCTRL (IPAddressEx); 82 | DEF_BINDCTRL (Label); 83 | DEF_BINDCTRL (List); 84 | DEF_BINDCTRL (ListEx); 85 | DEF_BINDCTRL (Menu); 86 | DEF_BINDCTRL (Option); 87 | DEF_BINDCTRL (CheckBox); 88 | DEF_BINDCTRL (Progress); 89 | DEF_BINDCTRL (RichEdit); 90 | DEF_BINDCTRL (Ring); 91 | DEF_BINDCTRL (RollText); 92 | DEF_BINDCTRL (ScrollBar); 93 | DEF_BINDCTRL (Slider); 94 | DEF_BINDCTRL (Text); 95 | DEF_BINDCTRL (TreeView); 96 | DEF_BINDCTRL (WebBrowser); 97 | 98 | // Layout 99 | DEF_BINDCTRL (AnimationTabLayout); 100 | DEF_BINDCTRL (ChildLayout); 101 | DEF_BINDCTRL (HorizontalLayout); 102 | DEF_BINDCTRL (TabLayout); 103 | DEF_BINDCTRL (TileLayout); 104 | DEF_BINDCTRL (VerticalLayout); 105 | } 106 | 107 | #endif //__BIND_CTRLS_HPP__ 108 | -------------------------------------------------------------------------------- /DuiLib/Bind/StdAfx.h: -------------------------------------------------------------------------------- 1 | #include "../StdAfx.h" -------------------------------------------------------------------------------- /DuiLib/Control/StdAfx.h: -------------------------------------------------------------------------------- 1 | #include "../StdAfx.h" -------------------------------------------------------------------------------- /DuiLib/Control/UIActiveX.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIACTIVEX_H__ 2 | #define __UIACTIVEX_H__ 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | struct IOleObject; 9 | 10 | 11 | namespace DuiLib { 12 | ///////////////////////////////////////////////////////////////////////////////////// 13 | // 14 | 15 | class CActiveXCtrl; 16 | 17 | template< class T > 18 | class CSafeRelease { 19 | public: 20 | CSafeRelease (T* p): m_p (p) {}; 21 | virtual ~CSafeRelease () { if (m_p) m_p->Release (); } 22 | T* Detach () { T* t = m_p; m_p = nullptr; return t; } 23 | T* m_p; 24 | }; 25 | 26 | ///////////////////////////////////////////////////////////////////////////////////// 27 | // 28 | 29 | class UILIB_API CActiveXUI: public CControlUI, public IMessageFilterUI { 30 | DECLARE_DUICONTROL (CActiveXUI) 31 | 32 | friend class CActiveXCtrl; 33 | public: 34 | CActiveXUI (); 35 | virtual ~CActiveXUI (); 36 | 37 | faw::string_t GetClass () const; 38 | LPVOID GetInterface (faw::string_t pstrName); 39 | 40 | HWND GetHostWindow () const; 41 | 42 | virtual bool IsDelayCreate () const; 43 | virtual void SetDelayCreate (bool bDelayCreate = true); 44 | virtual bool IsMFC () const; 45 | virtual void SetMFC (bool bMFC = false); 46 | 47 | bool CreateControl (const CLSID clsid); 48 | bool CreateControl (faw::string_t pstrCLSID); 49 | HRESULT GetControl (const IID iid, LPVOID* ppRet); 50 | CLSID GetClisd () const; 51 | faw::string_t GetModuleName () const; 52 | void SetModuleName (faw::string_t pstrText); 53 | 54 | void SetVisible (bool bVisible = true); 55 | void SetInternVisible (bool bVisible = true); 56 | void SetPos (RECT rc, bool bNeedInvalidate = true); 57 | void Move (SIZE szOffset, bool bNeedInvalidate = true); 58 | bool DoPaint (HDC hDC, const RECT& rcPaint, CControlUI* pStopControl); 59 | 60 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 61 | 62 | std::optional MessageHandler (UINT uMsg, WPARAM wParam, LPARAM lParam); 63 | 64 | protected: 65 | virtual void ReleaseControl (); 66 | virtual bool DoCreateControl (); 67 | 68 | protected: 69 | CLSID m_clsid = IID_NULL; 70 | faw::string_t m_sModuleName; 71 | bool m_bCreated = false; 72 | bool m_bDelayCreate = true; 73 | bool m_bMFC = false; 74 | IOleObject *m_pUnk = nullptr; 75 | CActiveXCtrl *m_pControl = nullptr; 76 | HWND m_hwndHost = NULL; 77 | }; 78 | 79 | } // namespace DuiLib 80 | 81 | #endif // __UIACTIVEX_H__ 82 | -------------------------------------------------------------------------------- /DuiLib/Control/UIAnimation.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "UIAnimation.h" 3 | #include 4 | #include 5 | 6 | namespace DuiLib { 7 | struct CUIAnimation::Imp { 8 | std::vector m_arAnimations; 9 | }; 10 | 11 | CUIAnimation::CUIAnimation (): m_pImp (new CUIAnimation::Imp ()) { 12 | m_pControl = nullptr; 13 | } 14 | CUIAnimation:: ~CUIAnimation () { 15 | if (m_pImp) { 16 | delete m_pImp; 17 | m_pImp = nullptr; 18 | } 19 | } 20 | 21 | void CUIAnimation::Attach (CControlUI* pOwner) { 22 | m_pControl = pOwner; 23 | } 24 | 25 | BOOL CUIAnimation::StartAnimation (int nElapse, int nTotalFrame, int nAnimationID /*= 0*/, BOOL bLoop/* = FALSE*/) { 26 | CAnimationData* pData = GetAnimationDataByID (nAnimationID); 27 | if (pData || nElapse <= 0 || nTotalFrame <= 0 || !m_pControl) { 28 | ASSERT (FALSE); 29 | return FALSE; 30 | } 31 | 32 | CAnimationData* pAnimation = new CAnimationData (nElapse, nTotalFrame, nAnimationID, bLoop); 33 | if (!pAnimation) return FALSE; 34 | 35 | if (m_pControl->GetManager ()->SetTimer (m_pControl, nAnimationID, nElapse)) { 36 | m_pImp->m_arAnimations.push_back (pAnimation); 37 | return TRUE; 38 | } 39 | return FALSE; 40 | } 41 | 42 | void CUIAnimation::StopAnimation (int nAnimationID /*= 0*/) { 43 | if (!m_pControl) return; 44 | 45 | if (nAnimationID != 0) { 46 | CAnimationData* pData = GetAnimationDataByID (nAnimationID); 47 | if (nullptr != pData) { 48 | m_pControl->GetManager ()->KillTimer (m_pControl, nAnimationID); 49 | m_pImp->m_arAnimations.erase (std::remove (m_pImp->m_arAnimations.begin (), m_pImp->m_arAnimations.end (), pData), m_pImp->m_arAnimations.end ()); 50 | if (pData) { 51 | delete pData; 52 | pData = nullptr; 53 | } 54 | return; 55 | } 56 | } else { 57 | size_t nCount = m_pImp->m_arAnimations.size (); 58 | for (size_t i = 0; i < nCount; ++i) { 59 | CAnimationData* pData = m_pImp->m_arAnimations[i]; 60 | if (pData) { 61 | m_pControl->GetManager ()->KillTimer (m_pControl, pData->m_nAnimationID); 62 | if (pData) { 63 | delete pData; 64 | pData = nullptr; 65 | } 66 | } 67 | } 68 | m_pImp->m_arAnimations.clear (); 69 | } 70 | } 71 | 72 | BOOL CUIAnimation::IsAnimationRunning (int nAnimationID) { 73 | CAnimationData* pData = GetAnimationDataByID (nAnimationID); 74 | return !!pData; 75 | } 76 | 77 | int CUIAnimation::GetCurrentFrame (int nAnimationID/* = 0*/) { 78 | CAnimationData* pData = GetAnimationDataByID (nAnimationID); 79 | if (!pData) { 80 | ASSERT (FALSE); 81 | return -1; 82 | } 83 | return pData->m_nCurFrame; 84 | } 85 | 86 | BOOL CUIAnimation::SetCurrentFrame (int nFrame, int nAnimationID/* = 0*/) { 87 | CAnimationData* pData = GetAnimationDataByID (nAnimationID); 88 | if (!pData) { 89 | ASSERT (FALSE); 90 | return FALSE; 91 | } 92 | 93 | if (nFrame >= 0 && nFrame <= pData->m_nTotalFrame) { 94 | pData->m_nCurFrame = nFrame; 95 | return TRUE; 96 | } else { 97 | ASSERT (FALSE); 98 | } 99 | return FALSE; 100 | } 101 | 102 | void CUIAnimation::OnAnimationElapse (int nAnimationID) { 103 | if (!m_pControl) return; 104 | 105 | CAnimationData* pData = GetAnimationDataByID (nAnimationID); 106 | if (!pData) return; 107 | 108 | int nCurFrame = pData->m_nCurFrame; 109 | if (nCurFrame == 0) { 110 | OnAnimationStart (nAnimationID, pData->m_bFirstLoop); 111 | pData->m_bFirstLoop = FALSE; 112 | } 113 | 114 | OnAnimationStep (pData->m_nTotalFrame, nCurFrame, nAnimationID); 115 | 116 | if (nCurFrame >= pData->m_nTotalFrame) { 117 | OnAnimationStop (nAnimationID); 118 | if (pData->m_bLoop) { 119 | pData->m_nCurFrame = 0; 120 | } else { 121 | m_pControl->GetManager ()->KillTimer (m_pControl, nAnimationID); 122 | m_pImp->m_arAnimations.erase (std::remove (m_pImp->m_arAnimations.begin (), m_pImp->m_arAnimations.end (), pData), m_pImp->m_arAnimations.end ()); 123 | delete pData; 124 | pData = nullptr; 125 | } 126 | } 127 | 128 | if (nullptr != pData) { 129 | ++(pData->m_nCurFrame); 130 | } 131 | } 132 | 133 | CAnimationData* CUIAnimation::GetAnimationDataByID (int nAnimationID) { 134 | CAnimationData* pRet = nullptr; 135 | size_t nCount = m_pImp->m_arAnimations.size (); 136 | for (size_t i = 0; i < nCount; ++i) { 137 | if (m_pImp->m_arAnimations[i]->m_nAnimationID == nAnimationID) { 138 | pRet = m_pImp->m_arAnimations[i]; 139 | break; 140 | } 141 | } 142 | 143 | return pRet; 144 | } 145 | 146 | } // namespace DuiLib -------------------------------------------------------------------------------- /DuiLib/Control/UIAnimation.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIANIMATION_H__ 2 | #define __UIANIMATION_H__ 3 | 4 | #include "UIButton.h" 5 | #pragma once 6 | 7 | namespace DuiLib { 8 | 9 | class UILIB_API IUIAnimation { 10 | public: 11 | virtual ~IUIAnimation () {} 12 | 13 | virtual BOOL StartAnimation (int nElapse, int nTotalFrame, int nAnimationID = 0, BOOL bLoop = FALSE) = 0; 14 | virtual void StopAnimation (int nAnimationID = 0) = 0; 15 | virtual BOOL IsAnimationRunning (int nAnimationID) = 0; 16 | virtual int GetCurrentFrame (int nAnimationID = 0) = 0; 17 | virtual BOOL SetCurrentFrame (int nFrame, int nAnimationID = 0) = 0; 18 | 19 | virtual void OnAnimationStep (int nTotalFrame, int nCurFrame, int nAnimationID) = 0; 20 | virtual void OnAnimationStart (int nAnimationID, BOOL bFirstLoop) = 0; 21 | virtual void OnAnimationStop (int nAnimationID) = 0; 22 | 23 | virtual void OnAnimationElapse (int nAnimationID) = 0; 24 | }; 25 | 26 | class UILIB_API CAnimationData { 27 | public: 28 | CAnimationData (int nElipse, int nFrame, int nID, BOOL bLoop) { 29 | m_nElapse = nElipse; 30 | m_nTotalFrame = nFrame; 31 | m_bLoop = bLoop; 32 | m_nAnimationID = nID; 33 | } 34 | 35 | //protected: 36 | public: 37 | friend class CDUIAnimation; 38 | 39 | int m_nAnimationID; 40 | int m_nElapse; 41 | 42 | int m_nTotalFrame; 43 | int m_nCurFrame = 0; 44 | 45 | BOOL m_bLoop; 46 | BOOL m_bFirstLoop = TRUE; 47 | }; 48 | 49 | class UILIB_API CUIAnimation: public IUIAnimation { 50 | struct Imp; 51 | public: 52 | CUIAnimation (); 53 | virtual ~CUIAnimation (); 54 | 55 | public: 56 | void Attach (CControlUI* pOwner); 57 | 58 | virtual BOOL StartAnimation (int nElapse, int nTotalFrame, int nAnimationID = 0, BOOL bLoop = FALSE); 59 | virtual void StopAnimation (int nAnimationID = 0); 60 | virtual BOOL IsAnimationRunning (int nAnimationID); 61 | virtual int GetCurrentFrame (int nAnimationID = 0); 62 | virtual BOOL SetCurrentFrame (int nFrame, int nAnimationID = 0); 63 | 64 | virtual void OnAnimationStart (int nAnimationID, BOOL bFirstLoop) {} 65 | virtual void OnAnimationStep (int nTotalFrame, int nCurFrame, int nAnimationID) {} 66 | virtual void OnAnimationStop (int nAnimationID) {} 67 | 68 | virtual void OnAnimationElapse (int nAnimationID); 69 | 70 | protected: 71 | CAnimationData* GetAnimationDataByID (int nAnimationID); 72 | 73 | protected: 74 | CControlUI *m_pControl; 75 | Imp *m_pImp; 76 | }; 77 | 78 | } // namespace DuiLib 79 | 80 | #endif // __UIANIMATION_H__ -------------------------------------------------------------------------------- /DuiLib/Control/UIButton.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIBUTTON_H__ 2 | #define __UIBUTTON_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CButtonUI: public CLabelUI { 8 | DECLARE_DUICONTROL (CButtonUI) 9 | 10 | public: 11 | CButtonUI (); 12 | 13 | faw::string_t GetClass () const; 14 | LPVOID GetInterface (faw::string_t pstrName); 15 | UINT GetControlFlags () const; 16 | 17 | bool Activate (); 18 | void SetEnabled (bool bEnable = true); 19 | void DoEvent (TEventUI& event); 20 | 21 | virtual faw::string_t GetNormalImage (); 22 | virtual void SetNormalImage (faw::string_t pStrImage); 23 | virtual faw::string_t GetHotImage (); 24 | virtual void SetHotImage (faw::string_t pStrImage); 25 | virtual faw::string_t GetPushedImage (); 26 | virtual void SetPushedImage (faw::string_t pStrImage); 27 | virtual faw::string_t GetFocusedImage (); 28 | virtual void SetFocusedImage (faw::string_t pStrImage); 29 | virtual faw::string_t GetDisabledImage (); 30 | virtual void SetDisabledImage (faw::string_t pStrImage); 31 | virtual faw::string_t GetHotForeImage (); 32 | virtual void SetHotForeImage (faw::string_t pStrImage); 33 | void SetStateCount (int nCount); 34 | int GetStateCount () const; 35 | virtual faw::string_t GetStateImage (); 36 | virtual void SetStateImage (faw::string_t pStrImage); 37 | 38 | void BindTabIndex (int _BindTabIndex); 39 | void BindTabLayoutName (faw::string_t _TabLayoutName); 40 | void BindTriggerTabSel (int _SetSelectIndex = -1); 41 | void RemoveBindTabIndex (); 42 | int GetBindTabLayoutIndex (); 43 | faw::string_t GetBindTabLayoutName (); 44 | 45 | void SetHotFont (int index); 46 | int GetHotFont () const; 47 | void SetPushedFont (int index); 48 | int GetPushedFont () const; 49 | void SetFocusedFont (int index); 50 | int GetFocusedFont () const; 51 | 52 | void SetHotBkColor (DWORD dwColor); 53 | DWORD GetHotBkColor () const; 54 | void SetPushedBkColor (DWORD dwColor); 55 | DWORD GetPushedBkColor () const; 56 | void SetDisabledBkColor (DWORD dwColor); 57 | DWORD GetDisabledBkColor () const; 58 | void SetHotTextColor (DWORD dwColor); 59 | DWORD GetHotTextColor () const; 60 | void SetPushedTextColor (DWORD dwColor); 61 | DWORD GetPushedTextColor () const; 62 | void SetFocusedTextColor (DWORD dwColor); 63 | DWORD GetFocusedTextColor () const; 64 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 65 | 66 | void PaintText (HDC hDC); 67 | 68 | void PaintBkColor (HDC hDC); 69 | void PaintStatusImage (HDC hDC); 70 | void PaintForeImage (HDC hDC); 71 | 72 | protected: 73 | UINT m_uButtonState = 0; 74 | 75 | int m_iHotFont = -1; 76 | int m_iPushedFont = -1; 77 | int m_iFocusedFont = -1; 78 | 79 | DWORD m_dwHotBkColor = 0; 80 | DWORD m_dwPushedBkColor = 0; 81 | DWORD m_dwDisabledBkColor = 0; 82 | DWORD m_dwHotTextColor = 0; 83 | DWORD m_dwPushedTextColor = 0; 84 | DWORD m_dwFocusedTextColor = 0; 85 | 86 | faw::string_t m_sNormalImage; 87 | faw::string_t m_sHotImage; 88 | faw::string_t m_sHotForeImage; 89 | faw::string_t m_sPushedImage; 90 | faw::string_t m_sPushedForeImage; 91 | faw::string_t m_sFocusedImage; 92 | faw::string_t m_sDisabledImage; 93 | int m_nStateCount = 0; 94 | faw::string_t m_sStateImage; 95 | 96 | int m_iBindTabIndex = -1; 97 | faw::string_t m_sBindTabLayoutName; 98 | }; 99 | 100 | } // namespace DuiLib 101 | 102 | #endif // __UIBUTTON_H__ -------------------------------------------------------------------------------- /DuiLib/Control/UIColorPalette.h: -------------------------------------------------------------------------------- 1 | #ifndef UI_PALLET_H 2 | #define UI_PALLET_H 3 | #pragma once 4 | 5 | namespace DuiLib { 6 | ///////////////////////////////////////////////////////////////////////////////////// 7 | // 8 | class UILIB_API CColorPaletteUI: public CControlUI { 9 | DECLARE_DUICONTROL (CColorPaletteUI) 10 | public: 11 | CColorPaletteUI (); 12 | virtual ~CColorPaletteUI (); 13 | 14 | //获取最终被选择的颜色,可以直接用于设置duilib背景色 15 | DWORD GetSelectColor (); 16 | void SetSelectColor (DWORD dwColor); 17 | 18 | virtual faw::string_t GetClass () const; 19 | virtual LPVOID GetInterface (faw::string_t pstrName); 20 | virtual void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 21 | 22 | //设置/获取 Pallet(调色板主界面)的高度 23 | void SetPalletHeight (int nHeight); 24 | int GetPalletHeight () const; 25 | 26 | //设置/获取 下方Bar(亮度选择栏)的高度 27 | void SetBarHeight (int nHeight); 28 | int GetBarHeight () const; 29 | //设置/获取 选择图标的路径 30 | void SetThumbImage (faw::string_t pszImage); 31 | faw::string_t GetThumbImage () const; 32 | 33 | virtual void SetPos (RECT rc, bool bNeedInvalidate = true); 34 | virtual void DoInit (); 35 | virtual void DoEvent (TEventUI& event); 36 | virtual void PaintBkColor (HDC hDC); 37 | virtual void PaintPallet (HDC hDC); 38 | 39 | protected: 40 | //更新数据 41 | void UpdatePalletData (); 42 | void UpdateBarData (); 43 | 44 | private: 45 | HDC m_MemDc; 46 | HBITMAP m_hMemBitmap = NULL; 47 | BITMAP m_bmInfo = { 0 }; 48 | BYTE *m_pBits = nullptr; 49 | UINT m_uButtonState = 0; 50 | bool m_bIsInBar = false; 51 | bool m_bIsInPallet = false; 52 | int m_nCurH = 180; 53 | int m_nCurS = 200; 54 | int m_nCurB = 100; 55 | 56 | int m_nPalletHeight = 200; 57 | int m_nBarHeight = 10; 58 | POINT m_ptLastPalletMouse; 59 | POINT m_ptLastBarMouse; 60 | faw::string_t m_strThumbImage; 61 | }; 62 | } 63 | 64 | #endif // UI_PALLET_H -------------------------------------------------------------------------------- /DuiLib/Control/UIComboBox.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "UIComboBox.h" 3 | 4 | namespace DuiLib { 5 | IMPLEMENT_DUICONTROL (CComboBoxUI) 6 | 7 | CComboBoxUI::CComboBoxUI () {} 8 | 9 | faw::string_t CComboBoxUI::GetClass () const { 10 | return _T ("ComboBoxUI"); 11 | } 12 | 13 | void CComboBoxUI::SetAttribute (faw::string_t pstrName, faw::string_t pstrValue) { 14 | if (pstrName == _T ("arrowimage")) 15 | m_sArrowImage = pstrValue; 16 | else 17 | CComboUI::SetAttribute (pstrName, pstrValue); 18 | } 19 | 20 | void CComboBoxUI::PaintStatusImage (HDC hDC) { 21 | if (m_sArrowImage.empty ()) 22 | CComboUI::PaintStatusImage (hDC); 23 | else { 24 | // get index 25 | if (IsFocused ()) m_uButtonState |= UISTATE_FOCUSED; 26 | else m_uButtonState &= ~UISTATE_FOCUSED; 27 | if (!IsEnabled ()) m_uButtonState |= UISTATE_DISABLED; 28 | else m_uButtonState &= ~UISTATE_DISABLED; 29 | 30 | int nIndex = 0; 31 | if ((m_uButtonState & UISTATE_DISABLED) != 0) 32 | nIndex = 4; 33 | else if ((m_uButtonState & UISTATE_PUSHED) != 0) 34 | nIndex = 2; 35 | else if ((m_uButtonState & UISTATE_HOT) != 0) 36 | nIndex = 1; 37 | else if ((m_uButtonState & UISTATE_FOCUSED) != 0) 38 | nIndex = 3; 39 | 40 | // make modify string 41 | faw::string_t sModify = m_sArrowImage; 42 | 43 | size_t nPos1 = sModify.find (_T ("source")); 44 | size_t nPos2 = sModify.find (_T ("'"), nPos1 + 7); 45 | if (nPos2 == faw::string_t::npos) return; //first 46 | size_t nPos3 = sModify.find (_T ("'"), nPos2 + 1); 47 | if (nPos3 == faw::string_t::npos) return; //second 48 | 49 | faw::string_t _str = &sModify [nPos2 + 1]; 50 | RECT rcBmpPart = FawTools::parse_rect (_str); 51 | 52 | m_nArrowWidth = (rcBmpPart.right - rcBmpPart.left) / 5; 53 | rcBmpPart.left += nIndex * m_nArrowWidth; 54 | rcBmpPart.right = rcBmpPart.left + m_nArrowWidth; 55 | 56 | RECT rcDest { 0, 0, m_rcItem.right - m_rcItem.left, m_rcItem.bottom - m_rcItem.top }; 57 | ::InflateRect (&rcDest, -GetBorderSize (), -GetBorderSize ()); 58 | rcDest.left = rcDest.right - m_nArrowWidth; 59 | 60 | faw::string_t sSource = sModify.substr (nPos1, nPos3 + 1 - nPos1); 61 | faw::string_t sReplace; 62 | sReplace = std::format (_T ("source='{},{},{},{}' dest='{},{},{},{}'"), 63 | rcBmpPart.left, rcBmpPart.top, rcBmpPart.right, rcBmpPart.bottom, 64 | rcDest.left, rcDest.top, rcDest.right, rcDest.bottom); 65 | 66 | FawTools::replace_self (sModify, sSource, sReplace); 67 | 68 | // draw image 69 | if (!DrawImage (hDC, m_sArrowImage, sModify)) { 70 | } 71 | } 72 | } 73 | 74 | void CComboBoxUI::PaintText (HDC hDC) { 75 | RECT rcText = m_rcItem; 76 | rcText.left += m_rcTextPadding.left; 77 | rcText.right -= m_rcTextPadding.right; 78 | rcText.top += m_rcTextPadding.top; 79 | rcText.bottom -= m_rcTextPadding.bottom; 80 | 81 | rcText.right -= m_nArrowWidth; // add this line than CComboUI::PaintText(HDC hDC) 82 | 83 | if (m_iCurSel >= 0) { 84 | CControlUI* pControl = static_cast(m_items[m_iCurSel]); 85 | IListItemUI* pElement = static_cast(pControl->GetInterface (_T ("ListItem"))); 86 | if (pElement) { 87 | pElement->DrawItemText (hDC, rcText); 88 | } else { 89 | RECT rcOldPos = pControl->GetPos (); 90 | pControl->SetPos (rcText); 91 | pControl->DoPaint (hDC, rcText, nullptr); 92 | pControl->SetPos (rcOldPos); 93 | } 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /DuiLib/Control/UIComboBox.h: -------------------------------------------------------------------------------- 1 | #ifndef __UICOMBOBOX_H__ 2 | #define __UICOMBOBOX_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | /// 扩展下拉列表框 8 | /// 增加arrowimage属性,一张图片平均分成5份,Normal/Hot/Pushed/Focused/Disabled(必须有source属性) 9 | /// 10 | class UILIB_API CComboBoxUI: public CComboUI { 11 | DECLARE_DUICONTROL (CComboBoxUI) 12 | public: 13 | CComboBoxUI (); 14 | faw::string_t GetClass () const; 15 | 16 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 17 | 18 | void PaintText (HDC hDC); 19 | void PaintStatusImage (HDC hDC); 20 | 21 | protected: 22 | faw::string_t m_sArrowImage; 23 | int m_nArrowWidth = 0; 24 | }; 25 | } 26 | 27 | #endif // __UICOMBOBOX_H__ 28 | -------------------------------------------------------------------------------- /DuiLib/Control/UIDateTime.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIDATETIME_H__ 2 | #define __UIDATETIME_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class CDateTimeWnd; 8 | 9 | /// 时间选择控件 10 | class UILIB_API CDateTimeUI: public CLabelUI { 11 | DECLARE_DUICONTROL (CDateTimeUI) 12 | friend class CDateTimeWnd; 13 | public: 14 | CDateTimeUI (); 15 | faw::string_t GetClass () const; 16 | LPVOID GetInterface (faw::string_t pstrName); 17 | 18 | SYSTEMTIME& GetTime (); 19 | void SetTime (SYSTEMTIME* pst); 20 | 21 | void SetReadOnly (bool bReadOnly); 22 | bool IsReadOnly () const; 23 | 24 | void UpdateText (); 25 | 26 | void DoEvent (TEventUI& event); 27 | 28 | protected: 29 | SYSTEMTIME m_sysTime; 30 | int m_nDTUpdateFlag; 31 | bool m_bReadOnly; 32 | 33 | CDateTimeWnd* m_pWindow; 34 | }; 35 | } 36 | #endif // __UIDATETIME_H__ -------------------------------------------------------------------------------- /DuiLib/Control/UIEdit.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIEDIT_H__ 2 | #define __UIEDIT_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class CEditWnd; 8 | 9 | class UILIB_API CEditUI: public CLabelUI { 10 | DECLARE_DUICONTROL (CEditUI) 11 | friend class CEditWnd; 12 | public: 13 | CEditUI (); 14 | 15 | faw::string_t GetClass () const; 16 | LPVOID GetInterface (faw::string_t pstrName); 17 | UINT GetControlFlags () const; 18 | 19 | void SetEnabled (bool bEnable = true); 20 | void SetText (faw::string_t pstrText); 21 | void SetMaxChar (UINT uMax); 22 | UINT GetMaxChar (); 23 | void SetReadOnly (bool bReadOnly); 24 | bool IsReadOnly () const; 25 | void SetPasswordMode (bool bPasswordMode); 26 | bool IsPasswordMode () const; 27 | void SetPasswordChar (TCHAR cPasswordChar); 28 | TCHAR GetPasswordChar () const; 29 | void SetNumberOnly (bool bNumberOnly); 30 | bool IsNumberOnly () const; 31 | int GetWindowStyls () const; 32 | 33 | faw::string_t GetNormalImage (); 34 | void SetNormalImage (faw::string_t pStrImage); 35 | faw::string_t GetHotImage (); 36 | void SetHotImage (faw::string_t pStrImage); 37 | faw::string_t GetFocusedImage (); 38 | void SetFocusedImage (faw::string_t pStrImage); 39 | faw::string_t GetDisabledImage (); 40 | void SetDisabledImage (faw::string_t pStrImage); 41 | 42 | bool IsAutoSelAll (); 43 | void SetAutoSelAll (bool bAutoSelAll); 44 | void SetSel (long nStartChar, long nEndChar); 45 | void SetSelAll (); 46 | void SetReplaceSel (faw::string_t lpszReplace); 47 | 48 | void SetTipValue (faw::string_t pStrTipValue); 49 | faw::string_t GetTipValue (); 50 | void SetTipValueColor (faw::string_t pStrColor); 51 | DWORD GetTipValueColor (); 52 | 53 | void SetPos (RECT rc, bool bNeedInvalidate = true); 54 | void Move (SIZE szOffset, bool bNeedInvalidate = true); 55 | void SetVisible (bool bVisible = true); 56 | void SetInternVisible (bool bVisible = true); 57 | SIZE EstimateSize (SIZE szAvailable); 58 | void DoEvent (TEventUI& event); 59 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 60 | 61 | void PaintStatusImage (HDC hDC); 62 | void PaintText (HDC hDC); 63 | 64 | protected: 65 | CEditWnd *m_pWindow = nullptr; 66 | 67 | UINT m_uMaxChar = 255; 68 | bool m_bReadOnly = false; 69 | bool m_bPasswordMode = false; 70 | bool m_bAutoSelAll = false; 71 | TCHAR m_cPasswordChar = _T ('*'); 72 | UINT m_uButtonState = 0; 73 | faw::string_t m_sNormalImage; 74 | faw::string_t m_sHotImage; 75 | faw::string_t m_sFocusedImage; 76 | faw::string_t m_sDisabledImage; 77 | faw::string_t m_sTipValue; 78 | DWORD m_dwTipValueColor = 0xFFBAC0C5; 79 | int m_iWindowStyls = 0; 80 | }; 81 | } 82 | #endif // __UIEDIT_H__ -------------------------------------------------------------------------------- /DuiLib/Control/UIFadeButton.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "UIFadeButton.h" 3 | 4 | namespace DuiLib { 5 | IMPLEMENT_DUICONTROL (CFadeButtonUI) 6 | 7 | CFadeButtonUI::CFadeButtonUI () { 8 | Attach (this); 9 | } 10 | 11 | CFadeButtonUI::~CFadeButtonUI () { 12 | StopAnimation (); 13 | } 14 | 15 | faw::string_t CFadeButtonUI::GetClass () const { 16 | return _T ("FadeButtonUI"); 17 | } 18 | 19 | LPVOID CFadeButtonUI::GetInterface (faw::string_t pstrName) { 20 | if (pstrName == _T ("FadeButton")) 21 | return static_cast(this); 22 | return CButtonUI::GetInterface (pstrName); 23 | } 24 | 25 | void CFadeButtonUI::SetNormalImage (faw::string_t pStrImage) { 26 | m_sNormalImage = pStrImage; 27 | m_sLastImage = m_sNormalImage; 28 | } 29 | 30 | void CFadeButtonUI::DoEvent (TEventUI& event) { 31 | if (IsEnabled ()) { 32 | if (event.Type == UIEVENT_MOUSEENTER && !IsAnimationRunning (FADE_IN_ID)) { 33 | m_bFadeAlpha = 0; 34 | m_bMouseHove = TRUE; 35 | StopAnimation (FADE_OUT_ID); 36 | StartAnimation (FADE_ELLAPSE, FADE_FRAME_COUNT, FADE_IN_ID); 37 | Invalidate (); 38 | return; 39 | } else if (event.Type == UIEVENT_MOUSELEAVE && !IsAnimationRunning (FADE_OUT_ID)) { 40 | m_bFadeAlpha = 0; 41 | m_bMouseLeave = TRUE; 42 | StopAnimation (FADE_IN_ID); 43 | StartAnimation (FADE_ELLAPSE, FADE_FRAME_COUNT, FADE_OUT_ID); 44 | Invalidate (); 45 | return; 46 | } 47 | } 48 | if (event.Type == UIEVENT_TIMER) { 49 | OnTimer ((int) event.wParam); 50 | } 51 | CButtonUI::DoEvent (event); 52 | } 53 | 54 | void CFadeButtonUI::OnTimer (int nTimerID) { 55 | OnAnimationElapse (nTimerID); 56 | } 57 | 58 | void CFadeButtonUI::PaintStatusImage (HDC hDC) { 59 | if (IsFocused ()) m_uButtonState |= UISTATE_FOCUSED; 60 | else m_uButtonState &= ~UISTATE_FOCUSED; 61 | if (!IsEnabled ()) m_uButtonState |= UISTATE_DISABLED; 62 | else m_uButtonState &= ~UISTATE_DISABLED; 63 | 64 | if ((m_uButtonState & UISTATE_DISABLED) != 0) { 65 | if (!m_sDisabledImage.empty ()) { 66 | if (DrawImage (hDC, m_sDisabledImage)) 67 | return; 68 | } 69 | } else if ((m_uButtonState & UISTATE_PUSHED) != 0) { 70 | if (!m_sPushedImage.empty ()) { 71 | if (DrawImage (hDC, m_sPushedImage)) 72 | return; 73 | } 74 | } else if ((m_uButtonState & UISTATE_FOCUSED) != 0) { 75 | if (!m_sFocusedImage.empty ()) { 76 | if (DrawImage (hDC, m_sFocusedImage)) 77 | return; 78 | } 79 | } 80 | 81 | if (!m_sNormalImage.empty ()) { 82 | if (IsAnimationRunning (FADE_IN_ID) || IsAnimationRunning (FADE_OUT_ID)) { 83 | if (m_bMouseHove) { 84 | m_bMouseHove = FALSE; 85 | m_sLastImage = m_sHotImage; 86 | DrawImage (hDC, m_sNormalImage); 87 | return; 88 | } else if (m_bMouseLeave) { 89 | m_bMouseLeave = FALSE; 90 | m_sLastImage = m_sNormalImage; 91 | DrawImage (hDC, m_sHotImage); 92 | return; 93 | } 94 | 95 | m_sOldImage = m_sNormalImage; 96 | m_sNewImage = m_sHotImage; 97 | if (IsAnimationRunning (FADE_OUT_ID)) { 98 | m_sOldImage = m_sHotImage; 99 | m_sNewImage = m_sNormalImage; 100 | } 101 | faw::string_t sFadeOut, sFadeIn; 102 | sFadeOut = std::format (_T ("fade='{}'"), 255 - m_bFadeAlpha); 103 | sFadeIn = std::format (_T ("fade='{}'"), m_bFadeAlpha); 104 | DrawImage (hDC, m_sOldImage, sFadeOut); 105 | DrawImage (hDC, m_sNewImage, sFadeIn); 106 | return; 107 | } else { 108 | if (m_bMouseHove) { 109 | m_bMouseHove = FALSE; 110 | m_sLastImage = m_sHotImage; 111 | DrawImage (hDC, m_sNormalImage); 112 | } else if (m_bMouseLeave) { 113 | m_bMouseLeave = FALSE; 114 | m_sLastImage = m_sNormalImage; 115 | DrawImage (hDC, m_sHotImage); 116 | } else { 117 | if (m_sLastImage.empty ()) 118 | m_sLastImage = m_sNormalImage; 119 | DrawImage (hDC, m_sLastImage); 120 | } 121 | } 122 | } 123 | } 124 | 125 | void CFadeButtonUI::OnAnimationStep (INT nTotalFrame, INT nCurFrame, INT nAnimationID) { 126 | m_bFadeAlpha = (BYTE) ((nCurFrame / (double) nTotalFrame) * 255); 127 | m_bFadeAlpha = m_bFadeAlpha == 0 ? 10 : m_bFadeAlpha; 128 | Invalidate (); 129 | } 130 | 131 | } // namespace DuiLib -------------------------------------------------------------------------------- /DuiLib/Control/UIFadeButton.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIFADEBUTTON_H__ 2 | #define __UIFADEBUTTON_H__ 3 | 4 | #include "UIAnimation.h" 5 | #pragma once 6 | 7 | namespace DuiLib { 8 | 9 | class UILIB_API CFadeButtonUI: public CButtonUI, public CUIAnimation { 10 | DECLARE_DUICONTROL (CFadeButtonUI) 11 | public: 12 | CFadeButtonUI (); 13 | virtual ~CFadeButtonUI (); 14 | 15 | faw::string_t GetClass () const; 16 | LPVOID GetInterface (faw::string_t pstrName); 17 | void SetNormalImage (faw::string_t pStrImage); 18 | 19 | void DoEvent (TEventUI& event); 20 | void OnTimer (int nTimerID); 21 | void PaintStatusImage (HDC hDC); 22 | 23 | virtual void OnAnimationStart (INT nAnimationID, BOOL bFirstLoop) {} 24 | virtual void OnAnimationStep (INT nTotalFrame, INT nCurFrame, INT nAnimationID); 25 | virtual void OnAnimationStop (INT nAnimationID) {} 26 | 27 | protected: 28 | faw::string_t m_sOldImage; 29 | faw::string_t m_sNewImage; 30 | faw::string_t m_sLastImage; 31 | BYTE m_bFadeAlpha; 32 | BOOL m_bMouseHove = FALSE; 33 | BOOL m_bMouseLeave = FALSE; 34 | enum { 35 | FADE_IN_ID = 8, 36 | FADE_OUT_ID = 9, 37 | FADE_ELLAPSE = 10, 38 | FADE_FRAME_COUNT = 30, 39 | }; 40 | }; 41 | 42 | } // namespace DuiLib 43 | 44 | #endif // __UIFADEBUTTON_H__ -------------------------------------------------------------------------------- /DuiLib/Control/UIFlash.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIFLASH_H__ 2 | #define __UIFLASH_H__ 3 | #pragma once 4 | 5 | // \Utils\Flash11.tlb 为Flash11接口文件,部分方法在低版本不存在,使用需注意 6 | // #import "PROGID:ShockwaveFlash.ShockwaveFlash" \ 7 | // raw_interfaces_only, /* Don't add raw_ to method names */ \ 8 | // named_guids, /* Named guids and declspecs */ \ 9 | // rename("IDispatchEx","IMyDispatchEx") /* fix conflicting with IDispatchEx ant dispex.h */ 10 | // using namespace ShockwaveFlashObjects; 11 | #include "../Utils/FlashEventHandler.h" 12 | #include "../Utils/flash11.tlh" 13 | 14 | class CActiveXCtrl; 15 | 16 | namespace DuiLib { 17 | class UILIB_API CFlashUI 18 | : public CActiveXUI 19 | // , public IOleInPlaceSiteWindowless // 透明模式绘图,需要实现这个接口 20 | , public _IShockwaveFlashEvents 21 | , public ITranslateAccelerator { 22 | DECLARE_DUICONTROL (CFlashUI) 23 | public: 24 | CFlashUI (void); 25 | virtual ~CFlashUI (void); 26 | 27 | void SetFlashEventHandler (CFlashEventHandler* pHandler); 28 | virtual bool DoCreateControl (); 29 | IShockwaveFlash *m_pFlash = nullptr; 30 | 31 | private: 32 | virtual faw::string_t GetClass () const; 33 | virtual LPVOID GetInterface (faw::string_t pstrName); 34 | 35 | virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount (__RPC__out UINT *pctinfo); 36 | virtual HRESULT STDMETHODCALLTYPE GetTypeInfo (UINT iTInfo, LCID lcid, __RPC__deref_out_opt ITypeInfo **ppTInfo); 37 | virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames (__RPC__in REFIID riid, __RPC__in_ecount_full (cNames) LPOLESTR *rgszNames, UINT cNames, LCID lcid, __RPC__out_ecount_full (cNames) DISPID *rgDispId); 38 | virtual HRESULT STDMETHODCALLTYPE Invoke (DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr); 39 | 40 | virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID riid, void **ppvObject); 41 | virtual ULONG STDMETHODCALLTYPE AddRef (void); 42 | virtual ULONG STDMETHODCALLTYPE Release (void); 43 | 44 | HRESULT OnReadyStateChange (long newState); 45 | HRESULT OnProgress (long percentDone); 46 | HRESULT FSCommand (_bstr_t command, _bstr_t args); 47 | HRESULT FlashCall (_bstr_t request); 48 | 49 | virtual void ReleaseControl (); 50 | HRESULT RegisterEventHandler (BOOL inAdvise); 51 | 52 | // ITranslateAccelerator 53 | // Duilib消息分发给WebBrowser 54 | virtual LRESULT TranslateAccelerator (MSG *pMsg); 55 | 56 | private: 57 | LONG m_dwRef = 0; 58 | DWORD m_dwCookie = 0; 59 | CFlashEventHandler *m_pFlashEventHandler = nullptr; 60 | }; 61 | } 62 | 63 | #endif // __UIFLASH_H__ 64 | -------------------------------------------------------------------------------- /DuiLib/Control/UIGifAnim.h: -------------------------------------------------------------------------------- 1 | #ifndef GifAnimUI_h__ 2 | #define GifAnimUI_h__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CGifAnimUI: public CControlUI { 8 | enum { 9 | EVENT_TIEM_ID = 100, 10 | }; 11 | DECLARE_DUICONTROL (CGifAnimUI) 12 | public: 13 | CGifAnimUI (void); 14 | virtual ~CGifAnimUI (void); 15 | 16 | faw::string_t GetClass () const; 17 | LPVOID GetInterface (faw::string_t pstrName); 18 | void DoInit () override; 19 | bool DoPaint (HDC hDC, const RECT& rcPaint, CControlUI* pStopControl); 20 | void DoEvent (TEventUI& event); 21 | void SetVisible (bool bVisible = true); 22 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 23 | void SetBkImage (faw::string_t pStrImage); 24 | faw::string_t GetBkImage (); 25 | 26 | void SetAutoPlay (bool bIsAuto = true); 27 | bool IsAutoPlay () const; 28 | void SetAutoSize (bool bIsAuto = true); 29 | bool IsAutoSize () const; 30 | void PlayGif (); 31 | void PauseGif (); 32 | void StopGif (); 33 | 34 | private: 35 | void InitGifImage (); 36 | void DeleteGif (); 37 | void OnTimer (UINT_PTR idEvent); 38 | void DrawFrame (HDC hDC); // 绘制GIF每帧 39 | Gdiplus::Image* LoadGifFromFile (faw::string_t pstrGifPath); 40 | Gdiplus::Image* LoadGifFromMemory (LPVOID pBuf, size_t dwSize); 41 | private: 42 | Gdiplus::Image *m_pGifImage = nullptr; 43 | UINT m_nFrameCount = 0; // gif图片总帧数 44 | UINT m_nFramePosition = 0; // 当前放到第几帧 45 | Gdiplus::PropertyItem *m_pPropertyItem = nullptr; // 帧与帧之间间隔时间 46 | 47 | faw::string_t m_sBkImage; 48 | bool m_bIsAutoPlay = true; // 是否自动播放gif 49 | bool m_bIsAutoSize = false; // 是否自动根据图片设置大小 50 | bool m_bIsPlaying = false; 51 | IStream *m_pStream = nullptr; 52 | }; 53 | } 54 | 55 | #endif // GifAnimUI_h__ -------------------------------------------------------------------------------- /DuiLib/Control/UIGifAnimEx.h: -------------------------------------------------------------------------------- 1 | #ifndef GifAnimUIEX_h__ 2 | #define GifAnimUIEX_h__ 3 | #pragma once 4 | /* write by wangji 2016.03.16 5 | ** 解决多个gif控件在gdi+环境下占用CPU过高的问题,本类采用ximage替代 6 | ** 注意:使用的时候在预编译头文件中包含UIlib.h前先定义宏USE_XIMAGE_EFFECT 7 | ** #define USE_XIMAGE_EFFECT 8 | ** #include "UIlib.h" 9 | */ 10 | #ifdef USE_XIMAGE_EFFECT 11 | namespace DuiLib { 12 | class CLabelUI; 13 | 14 | class UILIB_API CGifAnimExUI: public CLabelUI { 15 | DECLARE_DUICONTROL (CGifAnimExUI) 16 | public: 17 | CGifAnimExUI (void); 18 | virtual ~CGifAnimExUI (void); 19 | public: 20 | virtual faw::string_t GetClass () const; 21 | virtual LPVOID GetInterface (faw::string_t pstrName); 22 | virtual void Init (); 23 | virtual void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 24 | virtual void SetVisible (bool bVisible = true); 25 | virtual void SetInternVisible (bool bVisible = true); 26 | virtual bool DoPaint (HDC hDC, const RECT& rcPaint, CControlUI* pStopControl); 27 | virtual void DoEvent (TEventUI& event); 28 | public: 29 | void StartAnim (); 30 | void StopAnim (); 31 | protected: 32 | struct Imp; 33 | Imp* m_pImp; 34 | }; 35 | } 36 | #endif //USE_XIMAGE_EFFECT 37 | #endif // GifAnimUIEx_h__ 38 | -------------------------------------------------------------------------------- /DuiLib/Control/UIGroupBox.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIGROUPBOX_H__ 2 | #define __UIGROUPBOX_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | 8 | class UILIB_API CGroupBoxUI: public CVerticalLayoutUI { 9 | DECLARE_DUICONTROL (CGroupBoxUI) 10 | public: 11 | CGroupBoxUI (); 12 | virtual ~CGroupBoxUI (); 13 | faw::string_t GetClass () const; 14 | LPVOID GetInterface (faw::string_t pstrName); 15 | void SetTextColor (DWORD dwTextColor); 16 | DWORD GetTextColor () const; 17 | void SetDisabledTextColor (DWORD dwTextColor); 18 | DWORD GetDisabledTextColor () const; 19 | void SetFont (int index); 20 | int GetFont () const; 21 | 22 | protected: 23 | //Paint 24 | virtual void PaintText (HDC hDC); 25 | virtual void PaintBorder (HDC hDC); 26 | void PaintGroupBorder(HDC hDC, float x, float y, float width, float height, float arcSize, float lineWidth, Gdiplus::Color lineColor, RECT rcItemText, Gdiplus::Color fillColor); 27 | virtual void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 28 | 29 | private: 30 | SIZE CalcrectSize (SIZE szAvailable); 31 | 32 | protected: 33 | DWORD m_dwTextColor = 0; 34 | DWORD m_dwDisabledTextColor = 0; 35 | int m_iFont = -1; 36 | UINT m_uTextStyle; 37 | }; 38 | } 39 | #endif // __UIGROUPBOX_H__ -------------------------------------------------------------------------------- /DuiLib/Control/UIHotKey.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIHOTKEY_H__ 2 | #define __UIHOTKEY_H__ 3 | #pragma once 4 | 5 | namespace DuiLib { 6 | class CHotKeyUI; 7 | 8 | class UILIB_API CHotKeyWnd: public CWindowWnd { 9 | public: 10 | CHotKeyWnd (void); 11 | 12 | public: 13 | void Init (CHotKeyUI * pOwner); 14 | RECT CalPos (); 15 | LPCTSTR GetWindowClassName () const; 16 | void OnFinalMessage (HWND hWnd); 17 | LPCTSTR GetSuperClassName () const; 18 | LRESULT HandleMessage (UINT uMsg, WPARAM wParam, LPARAM lParam); 19 | std::optional OnKillFocus (UINT uMsg, WPARAM wParam, LPARAM lParam); 20 | std::optional OnEditChanged (UINT uMsg, WPARAM wParam, LPARAM lParam); 21 | public: 22 | void SetHotKey (WORD wVirtualKeyCode, WORD wModifiers); 23 | void GetHotKey (WORD &wVirtualKeyCode, WORD &wModifiers) const; 24 | DWORD GetHotKey (void) const; 25 | faw::string_t GetHotKeyName (); 26 | void SetRules (WORD wInvalidComb, WORD wModifiers); 27 | faw::string_t GetKeyName (UINT vk, BOOL fExtended); 28 | protected: 29 | CHotKeyUI * m_pOwner; 30 | HBRUSH m_hBkBrush; 31 | bool m_bInit; 32 | }; 33 | 34 | class UILIB_API CHotKeyUI: public CLabelUI { 35 | DECLARE_DUICONTROL (CHotKeyUI) 36 | friend CHotKeyWnd; 37 | public: 38 | CHotKeyUI (); 39 | faw::string_t GetClass () const; 40 | LPVOID GetInterface (faw::string_t pstrName); 41 | UINT GetControlFlags () const; 42 | void SetEnabled (bool bEnable = true); 43 | void SetText (faw::string_t pstrText); 44 | faw::string_t GetNormalImage (); 45 | void SetNormalImage (faw::string_t pStrImage); 46 | faw::string_t GetHotImage (); 47 | void SetHotImage (faw::string_t pStrImage); 48 | faw::string_t GetFocusedImage (); 49 | void SetFocusedImage (faw::string_t pStrImage); 50 | faw::string_t GetDisabledImage (); 51 | void SetDisabledImage (faw::string_t pStrImage); 52 | 53 | void SetPos (RECT rc); 54 | void SetVisible (bool bVisible = true); 55 | void SetInternVisible (bool bVisible = true); 56 | SIZE EstimateSize (SIZE szAvailable); 57 | void DoEvent (TEventUI& event); 58 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 59 | 60 | void PaintStatusImage (HDC hDC); 61 | void PaintText (HDC hDC); 62 | public: 63 | void GetHotKey (WORD &wVirtualKeyCode, WORD &wModifiers) const; 64 | DWORD GetHotKey (void) const; 65 | void SetHotKey (WORD wVirtualKeyCode, WORD wModifiers); 66 | 67 | protected: 68 | CHotKeyWnd * m_pWindow; 69 | UINT m_uButtonState; 70 | faw::string_t m_sNormalImage; 71 | faw::string_t m_sHotImage; 72 | faw::string_t m_sFocusedImage; 73 | faw::string_t m_sDisabledImage; 74 | 75 | protected: 76 | WORD m_wVirtualKeyCode; 77 | WORD m_wModifiers; 78 | }; 79 | } 80 | 81 | 82 | #endif -------------------------------------------------------------------------------- /DuiLib/Control/UIIPAddress.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIIPADDRESS_H__ 2 | #define __UIIPADDRESS_H__ 3 | 4 | #pragma once 5 | 6 | //给该控件添加一个属性dtstyle 7 | 8 | namespace DuiLib { 9 | class CIPAddressWnd; 10 | 11 | /// 时间选择控件 12 | class UILIB_API CIPAddressUI: public CLabelUI { 13 | DECLARE_DUICONTROL (CIPAddressUI) 14 | 15 | friend class CIPAddressWnd; 16 | public: 17 | CIPAddressUI (); 18 | faw::string_t GetClass () const; 19 | LPVOID GetInterface (faw::string_t pstrName); 20 | 21 | DWORD GetIP (); 22 | void SetIP (DWORD dwIP); 23 | 24 | void SetReadOnly (bool bReadOnly); 25 | bool IsReadOnly () const; 26 | 27 | void UpdateText (); 28 | 29 | void DoEvent (TEventUI& event); 30 | 31 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 32 | 33 | protected: 34 | DWORD m_dwIP; 35 | bool m_bReadOnly = false; 36 | int m_nIPUpdateFlag; 37 | 38 | CIPAddressWnd *m_pWindow = nullptr; 39 | }; 40 | } 41 | #endif // __UIIPADDRESS_H__ -------------------------------------------------------------------------------- /DuiLib/Control/UIIPAddressEx.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIIPADDRESSEX_H__ 2 | #define __UIIPADDRESSEX_H__ 3 | 4 | #pragma once 5 | 6 | //给该控件添加一个属性dtstyle 7 | 8 | namespace DuiLib { 9 | 10 | /// IP输入控件 11 | class UILIB_API CIPAddressExUI: public CEditUI { 12 | DECLARE_DUICONTROL (CIPAddressExUI) 13 | public: 14 | CIPAddressExUI (); 15 | faw::string_t GetClass () const; 16 | LPVOID GetInterface (faw::string_t pstrName); 17 | UINT GetControlFlags () const; 18 | void DoEvent (TEventUI& event); 19 | void PaintText (HDC hDC); 20 | 21 | void SetIP (LPCWSTR lpIP); 22 | faw::string_t GetIP (); 23 | 24 | private: 25 | void CharToInt (); 26 | void GetNumInput (TCHAR chKey); 27 | void UpdateText (); 28 | void IncNum (); 29 | void DecNum (); 30 | 31 | protected: 32 | int m_nFirst = 0; 33 | int m_nSecond = 0; 34 | int m_nThird = 0; 35 | int m_nFourth = 0; 36 | int m_nActiveSection = 0; 37 | 38 | TCHAR m_chNum; 39 | faw::string_t m_strNum; 40 | }; 41 | } 42 | #endif // __UIIPADDRESSEX_H__ -------------------------------------------------------------------------------- /DuiLib/Control/UILabel.h: -------------------------------------------------------------------------------- 1 | #ifndef __UILABEL_H__ 2 | #define __UILABEL_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CLabelUI: public CControlUI { 8 | DECLARE_DUICONTROL (CLabelUI) 9 | public: 10 | CLabelUI (); 11 | virtual ~CLabelUI (); 12 | 13 | faw::string_t GetClass () const; 14 | LPVOID GetInterface (faw::string_t pstrName); 15 | UINT GetControlFlags () const; 16 | 17 | void SetTextStyle (UINT uStyle); 18 | UINT GetTextStyle () const; 19 | void SetTextColor (DWORD dwTextColor); 20 | DWORD GetTextColor () const; 21 | void SetDisabledTextColor (DWORD dwTextColor); 22 | DWORD GetDisabledTextColor () const; 23 | void SetFont (int index); 24 | int GetFont () const; 25 | RECT GetTextPadding () const; 26 | void SetTextPadding (RECT rc); 27 | bool IsShowHtml (); 28 | void SetShowHtml (bool bShowHtml = true); 29 | 30 | SIZE EstimateSize (SIZE szAvailable); 31 | void DoEvent (TEventUI& event); 32 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 33 | 34 | void PaintText (HDC hDC); 35 | 36 | virtual bool GetAutoCalcWidth () const; 37 | virtual void SetAutoCalcWidth (bool bAutoCalcWidth); 38 | virtual bool GetAutoCalcHeight () const; 39 | virtual void SetAutoCalcHeight (bool bAutoCalcHeight); 40 | virtual void SetText (faw::string_t pstrText); 41 | 42 | protected: 43 | DWORD m_dwTextColor = 0; 44 | DWORD m_dwDisabledTextColor = 0; 45 | int m_iFont = -1; 46 | UINT m_uTextStyle; 47 | RECT m_rcTextPadding = { 0 }; 48 | bool m_bShowHtml = false; 49 | bool m_bAutoCalcWidth = false; 50 | bool m_bAutoCalcHeight = false; 51 | 52 | SIZE m_szAvailableLast = { 0, 0 }; 53 | SIZE m_cxyFixedLast = { 0, 0 }; 54 | bool m_bNeedEstimateSize = false; 55 | }; 56 | } 57 | 58 | #endif // __UILABEL_H__ 59 | -------------------------------------------------------------------------------- /DuiLib/Control/UIOption.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIOPTION_H__ 2 | #define __UIOPTION_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API COptionUI: public CButtonUI { 8 | DECLARE_DUICONTROL (COptionUI) 9 | public: 10 | COptionUI (); 11 | virtual ~COptionUI (); 12 | 13 | faw::string_t GetClass () const; 14 | LPVOID GetInterface (faw::string_t pstrName); 15 | 16 | void SetManager (CPaintManagerUI* pManager, CControlUI* pParent, bool bInit = true); 17 | 18 | bool Activate (); 19 | void SetEnabled (bool bEnable = true); 20 | 21 | faw::string_t GetSelectedImage (); 22 | void SetSelectedImage (faw::string_t pStrImage); 23 | 24 | faw::string_t GetSelectedHotImage (); 25 | void SetSelectedHotImage (faw::string_t pStrImage); 26 | 27 | faw::string_t GetSelectedPushedImage (); 28 | void SetSelectedPushedImage (faw::string_t pStrImage); 29 | 30 | void SetSelectedTextColor (DWORD dwTextColor); 31 | DWORD GetSelectedTextColor (); 32 | 33 | void SetSelectedBkColor (DWORD dwBkColor); 34 | DWORD GetSelectedBkColor (); 35 | 36 | faw::string_t GetSelectedForedImage (); 37 | void SetSelectedForedImage (faw::string_t pStrImage); 38 | 39 | void SetSelectedStateCount (int nCount); 40 | int GetSelectedStateCount () const; 41 | virtual faw::string_t GetSelectedStateImage (); 42 | virtual void SetSelectedStateImage (faw::string_t pStrImage); 43 | 44 | void SetSelectedFont (int index); 45 | int GetSelectedFont () const; 46 | 47 | faw::string_t GetGroup () const; 48 | void SetGroup (faw::string_t pStrGroupName = _T ("")); 49 | bool IsSelected () const; 50 | virtual void Selected (bool bSelected, bool bMsg = true); 51 | 52 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 53 | 54 | void PaintBkColor (HDC hDC); 55 | void PaintStatusImage (HDC hDC); 56 | void PaintForeImage (HDC hDC); 57 | void PaintText (HDC hDC); 58 | 59 | protected: 60 | bool m_bSelected = false; 61 | faw::string_t m_sGroupName; 62 | 63 | int m_iSelectedFont = -1; 64 | 65 | DWORD m_dwSelectedBkColor = 0; 66 | DWORD m_dwSelectedTextColor = 0; 67 | 68 | faw::string_t m_sSelectedImage; 69 | faw::string_t m_sSelectedHotImage; 70 | faw::string_t m_sSelectedPushedImage; 71 | faw::string_t m_sSelectedForeImage; 72 | 73 | int m_nSelectedStateCount = 0; 74 | faw::string_t m_sSelectedStateImage; 75 | }; 76 | 77 | class UILIB_API CCheckBoxUI: public COptionUI { 78 | DECLARE_DUICONTROL (CCheckBoxUI) 79 | public: 80 | CCheckBoxUI (); 81 | 82 | public: 83 | virtual faw::string_t GetClass () const; 84 | virtual LPVOID GetInterface (faw::string_t pstrName); 85 | 86 | void SetCheck (bool bCheck); 87 | bool GetCheck () const; 88 | 89 | public: 90 | virtual void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 91 | void SetAutoCheck (bool bEnable); 92 | virtual void DoEvent (TEventUI& event); 93 | virtual void Selected (bool bSelected, bool bMsg = true); 94 | 95 | protected: 96 | bool m_bAutoCheck; 97 | }; 98 | } // namespace DuiLib 99 | 100 | #endif // __UIOPTION_H__ -------------------------------------------------------------------------------- /DuiLib/Control/UIProgress.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "UIProgress.h" 3 | 4 | namespace DuiLib { 5 | IMPLEMENT_DUICONTROL (CProgressUI) 6 | 7 | CProgressUI::CProgressUI () { 8 | m_uTextStyle = DT_SINGLELINE | DT_CENTER; 9 | SetFixedHeight (12); 10 | } 11 | 12 | faw::string_t CProgressUI::GetClass () const { 13 | return _T ("ProgressUI"); 14 | } 15 | 16 | LPVOID CProgressUI::GetInterface (faw::string_t pstrName) { 17 | if (pstrName == DUI_CTRL_PROGRESS) return static_cast(this); 18 | return CLabelUI::GetInterface (pstrName); 19 | } 20 | 21 | bool CProgressUI::IsShowText () { 22 | return m_bShowText; 23 | } 24 | 25 | void CProgressUI::SetShowText (bool bShowText) { 26 | if (m_bShowText == bShowText) return; 27 | m_bShowText = bShowText; 28 | if (!m_bShowText) SetText (_T ("")); 29 | } 30 | 31 | bool CProgressUI::IsHorizontal () { 32 | return m_bHorizontal; 33 | } 34 | 35 | void CProgressUI::SetHorizontal (bool bHorizontal) { 36 | if (m_bHorizontal == bHorizontal) return; 37 | 38 | m_bHorizontal = bHorizontal; 39 | Invalidate (); 40 | } 41 | 42 | int CProgressUI::GetMinValue () const { 43 | return m_nMin; 44 | } 45 | 46 | void CProgressUI::SetMinValue (int nMin) { 47 | m_nMin = nMin; 48 | Invalidate (); 49 | } 50 | 51 | int CProgressUI::GetMaxValue () const { 52 | return m_nMax; 53 | } 54 | 55 | void CProgressUI::SetMaxValue (int nMax) { 56 | m_nMax = nMax; 57 | Invalidate (); 58 | } 59 | 60 | int CProgressUI::GetValue () const { 61 | return m_nValue; 62 | } 63 | 64 | void CProgressUI::SetValue (int nValue) { 65 | if (nValue == m_nValue || nValue m_nMax) { 66 | return; 67 | } 68 | m_nValue = nValue; 69 | Invalidate (); 70 | UpdateText (); 71 | } 72 | 73 | void CProgressUI::SetAttribute (faw::string_t pstrName, faw::string_t pstrValue) { 74 | if (pstrName == _T ("hor")) SetHorizontal (FawTools::parse_bool (pstrValue)); 75 | else if (pstrName == _T ("min")) SetMinValue (FawTools::parse_dec (pstrValue)); 76 | else if (pstrName == _T ("max")) SetMaxValue (FawTools::parse_dec (pstrValue)); 77 | else if (pstrName == _T ("value")) SetValue (FawTools::parse_dec (pstrValue)); 78 | else if (pstrName == _T ("isstretchfore")) SetStretchForeImage (FawTools::parse_bool (pstrValue)); 79 | else CLabelUI::SetAttribute (pstrName, pstrValue); 80 | } 81 | 82 | void CProgressUI::PaintForeColor (HDC hDC) { 83 | if (m_dwForeColor == 0) return; 84 | 85 | if (m_nMax <= m_nMin) m_nMax = m_nMin + 1; 86 | if (m_nValue > m_nMax) m_nValue = m_nMax; 87 | if (m_nValue < m_nMin) m_nValue = m_nMin; 88 | 89 | RECT rc = m_rcItem; 90 | if (m_bHorizontal) { 91 | rc.right = m_rcItem.left + (m_nValue - m_nMin) * (m_rcItem.right - m_rcItem.left) / (m_nMax - m_nMin); 92 | } else { 93 | rc.bottom = m_rcItem.top + (m_rcItem.bottom - m_rcItem.top) * (m_nMax - m_nValue) / (m_nMax - m_nMin); 94 | 95 | } 96 | 97 | CRenderEngine::DrawColor (hDC, rc, GetAdjustColor (m_dwForeColor)); 98 | } 99 | 100 | void CProgressUI::PaintForeImage (HDC hDC) { 101 | if (m_nMax <= m_nMin) m_nMax = m_nMin + 1; 102 | if (m_nValue > m_nMax) m_nValue = m_nMax; 103 | if (m_nValue < m_nMin) m_nValue = m_nMin; 104 | 105 | RECT rc = { 0 }; 106 | if (m_bHorizontal) { 107 | rc.right = (m_nValue - m_nMin) * (m_rcItem.right - m_rcItem.left) * 1.0f / (m_nMax - m_nMin); 108 | rc.bottom = m_rcItem.bottom - m_rcItem.top; 109 | } else { 110 | rc.top = (m_rcItem.bottom - m_rcItem.top) * (m_nMax - m_nValue) * 1.0f / (m_nMax - m_nMin); 111 | rc.right = m_rcItem.right - m_rcItem.left; 112 | rc.bottom = m_rcItem.bottom - m_rcItem.top; 113 | } 114 | 115 | if (!m_sForeImage.empty ()) { 116 | m_sForeImageModify.clear (); 117 | int sw = MulDiv (rc.right - rc.left, 100, GetManager ()->GetDPIObj ()->GetScale ()); 118 | int sh = MulDiv (rc.bottom - rc.top, 100, GetManager ()->GetDPIObj ()->GetScale ()); 119 | rc.left = MulDiv (rc.left, 100, GetManager ()->GetDPIObj ()->GetScale ()); 120 | rc.top = MulDiv (rc.top, 100, GetManager ()->GetDPIObj ()->GetScale ()); 121 | rc.right = rc.left + sw; 122 | rc.bottom = rc.top + sh; 123 | if (m_bStretchForeImage) { 124 | m_sForeImageModify = std::format (_T ("dest='{},{},{},{}'"), rc.left, rc.top, rc.right, rc.bottom); 125 | } else { 126 | m_sForeImageModify = std::format (_T ("dest='{},{},{},{}' source='{},{},{},{}'"), rc.left, rc.top, rc.right, rc.bottom, rc.left, rc.top, rc.right, rc.bottom); 127 | } 128 | 129 | if (DrawImage (hDC, m_sForeImage, m_sForeImageModify)) 130 | return; 131 | } 132 | } 133 | 134 | bool CProgressUI::IsStretchForeImage () { 135 | return m_bStretchForeImage; 136 | } 137 | 138 | void CProgressUI::SetStretchForeImage (bool bStretchForeImage /*= true*/) { 139 | if (m_bStretchForeImage == bStretchForeImage) return; 140 | m_bStretchForeImage = bStretchForeImage; 141 | Invalidate (); 142 | } 143 | 144 | void CProgressUI::UpdateText () { 145 | if (m_bShowText) { 146 | faw::string_t sText; 147 | sText = std::format (_T ("{:.02}%"), (m_nValue - m_nMin) * 100.0 / (m_nMax - m_nMin)); 148 | SetText (sText); 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /DuiLib/Control/UIProgress.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIPROGRESS_H__ 2 | #define __UIPROGRESS_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CProgressUI: public CLabelUI { 8 | DECLARE_DUICONTROL (CProgressUI) 9 | public: 10 | CProgressUI (); 11 | 12 | faw::string_t GetClass () const; 13 | LPVOID GetInterface (faw::string_t pstrName); 14 | 15 | bool IsShowText (); 16 | void SetShowText (bool bShowText = true); 17 | bool IsHorizontal (); 18 | void SetHorizontal (bool bHorizontal = true); 19 | bool IsStretchForeImage (); 20 | void SetStretchForeImage (bool bStretchForeImage = true); 21 | int GetMinValue () const; 22 | void SetMinValue (int nMin); 23 | int GetMaxValue () const; 24 | void SetMaxValue (int nMax); 25 | int GetValue () const; 26 | void SetValue (int nValue); 27 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 28 | void PaintForeColor (HDC hDC); 29 | void PaintForeImage (HDC hDC); 30 | virtual void UpdateText (); 31 | 32 | protected: 33 | bool m_bShowText = false; 34 | bool m_bHorizontal = true; 35 | bool m_bStretchForeImage = true; 36 | int m_nMax = 100; 37 | int m_nMin = 0; 38 | int m_nValue = 0; 39 | 40 | faw::string_t m_sForeImageModify; 41 | }; 42 | 43 | } // namespace DuiLib 44 | 45 | #endif // __UIPROGRESS_H__ 46 | -------------------------------------------------------------------------------- /DuiLib/Control/UIRing.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "UIRing.h" 3 | 4 | namespace DuiLib { 5 | IMPLEMENT_DUICONTROL (CRingUI) 6 | 7 | CRingUI::CRingUI () {} 8 | 9 | CRingUI::~CRingUI () { 10 | if (m_pManager) m_pManager->KillTimer (this, RING_TIMERID); 11 | 12 | DeleteImage (); 13 | } 14 | 15 | faw::string_t CRingUI::GetClass () const { 16 | return _T ("RingUI"); 17 | } 18 | 19 | LPVOID CRingUI::GetInterface (faw::string_t pstrName) { 20 | if (pstrName == _T ("Ring")) return static_cast(this); 21 | return CLabelUI::GetInterface (pstrName); 22 | } 23 | 24 | void CRingUI::SetAttribute (faw::string_t pstrName, faw::string_t pstrValue) { 25 | if (pstrName == _T ("bkimage")) SetBkImage (pstrValue); 26 | else CLabelUI::SetAttribute (pstrName, pstrValue); 27 | } 28 | 29 | void CRingUI::SetBkImage (faw::string_t pStrImage) { 30 | if (m_sBkImage == pStrImage) return; 31 | m_sBkImage = pStrImage; 32 | DeleteImage (); 33 | Invalidate (); 34 | } 35 | 36 | void CRingUI::PaintBkImage (HDC hDC) { 37 | if (!m_pBkimage) 38 | InitImage (); 39 | if (!m_pBkimage) 40 | return; 41 | 42 | RECT rcItem = m_rcItem; 43 | int iWidth = rcItem.right - rcItem.left; 44 | int iHeight = rcItem.bottom - rcItem.top; 45 | Gdiplus::PointF centerPos ((Gdiplus::REAL) (rcItem.left + iWidth / 2), (Gdiplus::REAL) (rcItem.top + iHeight / 2)); 46 | 47 | Gdiplus::Graphics graphics (hDC); 48 | graphics.TranslateTransform (centerPos.X, centerPos.Y); 49 | graphics.RotateTransform (m_fCurAngle); 50 | graphics.TranslateTransform (-centerPos.X, -centerPos.Y);//还原源点 51 | graphics.DrawImage (m_pBkimage, rcItem.left, rcItem.top, iWidth, iHeight); 52 | } 53 | 54 | void CRingUI::DoEvent (TEventUI& event) { 55 | if (event.Type == UIEVENT_TIMER && event.wParam == RING_TIMERID) { 56 | if (m_fCurAngle > 359) { 57 | m_fCurAngle = 0; 58 | } 59 | m_fCurAngle += 36.0; 60 | Invalidate (); 61 | } else { 62 | CLabelUI::DoEvent (event); 63 | } 64 | } 65 | 66 | void CRingUI::InitImage () { 67 | m_pBkimage = CRenderEngine::GdiplusLoadImage (GetBkImage ()); 68 | if (nullptr == m_pBkimage) return; 69 | if (m_pManager) m_pManager->SetTimer (this, RING_TIMERID, 100); 70 | } 71 | 72 | void CRingUI::DeleteImage () { 73 | if (m_pBkimage) { 74 | delete m_pBkimage; 75 | m_pBkimage = nullptr; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /DuiLib/Control/UIRing.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIROTATE_H__ 2 | #define __UIROTATE_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CRingUI: public CLabelUI { 8 | enum { 9 | RING_TIMERID = 100, 10 | }; 11 | DECLARE_DUICONTROL (CRingUI) 12 | public: 13 | CRingUI (); 14 | virtual ~CRingUI (); 15 | 16 | faw::string_t GetClass () const; 17 | LPVOID GetInterface (faw::string_t pstrName); 18 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 19 | void SetBkImage (faw::string_t pStrImage); 20 | virtual void DoEvent (TEventUI& event); 21 | virtual void PaintBkImage (HDC hDC); 22 | 23 | private: 24 | void InitImage (); 25 | void DeleteImage (); 26 | 27 | public: 28 | float m_fCurAngle = 0.0f; 29 | Gdiplus::Image *m_pBkimage = nullptr; 30 | }; 31 | } 32 | 33 | #endif // __UIROTATE_H__ -------------------------------------------------------------------------------- /DuiLib/Control/UIRollText.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "UIRollText.h" 3 | 4 | namespace DuiLib { 5 | IMPLEMENT_DUICONTROL (CRollTextUI) 6 | 7 | CRollTextUI::CRollTextUI (void) {} 8 | 9 | CRollTextUI::~CRollTextUI (void) { 10 | m_pManager->KillTimer (this, ROLLTEXT_ROLL_END); 11 | m_pManager->KillTimer (this, ROLLTEXT_TIMERID); 12 | } 13 | 14 | faw::string_t CRollTextUI::GetClass () const { 15 | return _T ("RollTextUI"); 16 | } 17 | 18 | LPVOID CRollTextUI::GetInterface (faw::string_t pstrName) { 19 | if (pstrName == _T ("RollText")) return static_cast(this); 20 | return CLabelUI::GetInterface (pstrName); 21 | } 22 | 23 | void CRollTextUI::BeginRoll (int nDirect, LONG lTimeSpan, LONG lMaxTimeLimited) { 24 | m_nRollDirection = nDirect; 25 | if (m_bUseRoll) { 26 | EndRoll (); 27 | } 28 | m_nText_W_H = 0; 29 | 30 | m_pManager->KillTimer (this, ROLLTEXT_TIMERID); 31 | m_pManager->SetTimer (this, ROLLTEXT_TIMERID, lTimeSpan); 32 | 33 | m_pManager->KillTimer (this, ROLLTEXT_ROLL_END); 34 | m_pManager->SetTimer (this, ROLLTEXT_ROLL_END, lMaxTimeLimited * 1000); 35 | 36 | m_bUseRoll = TRUE; 37 | } 38 | 39 | void CRollTextUI::EndRoll () { 40 | if (!m_bUseRoll) return; 41 | 42 | m_pManager->KillTimer (this, ROLLTEXT_ROLL_END); 43 | m_pManager->KillTimer (this, ROLLTEXT_TIMERID); 44 | 45 | m_bUseRoll = FALSE; 46 | } 47 | 48 | void CRollTextUI::SetPos (RECT rc) { 49 | CLabelUI::SetPos (rc); 50 | m_nText_W_H = 0; //布局变化重新计算 51 | } 52 | 53 | void CRollTextUI::SetText (faw::string_t pstrText) { 54 | CLabelUI::SetText (pstrText); 55 | m_nText_W_H = 0; //文本变化重新计算 56 | } 57 | 58 | void CRollTextUI::DoEvent (TEventUI& event) { 59 | if (event.Type == UIEVENT_TIMER && event.wParam == ROLLTEXT_ROLL_END) { 60 | m_pManager->KillTimer (this, ROLLTEXT_ROLL_END); 61 | m_pManager->SendNotify (this, DUI_MSGTYPE_TEXTROLLEND); 62 | } else if (event.Type == UIEVENT_TIMER && event.wParam == ROLLTEXT_TIMERID) { 63 | Invalidate (); 64 | return; 65 | } 66 | CLabelUI::DoEvent (event); 67 | } 68 | 69 | void CRollTextUI::PaintText (HDC hDC) { 70 | if (m_dwTextColor == 0) m_dwTextColor = m_pManager->GetDefaultFontColor (); 71 | if (m_dwDisabledTextColor == 0) m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor (); 72 | DWORD dwTextColor = IsEnabled () ? m_dwTextColor : m_dwDisabledTextColor; 73 | faw::string_t sText = GetText (); 74 | if (sText.empty ()) return; 75 | RECT rcTextPadding = GetTextPadding (); 76 | RECT rcClient; 77 | rcClient = m_rcItem; 78 | rcClient.left += rcTextPadding.left; 79 | rcClient.right -= rcTextPadding.right; 80 | rcClient.top += rcTextPadding.top; 81 | rcClient.bottom -= rcTextPadding.bottom; 82 | 83 | if (m_nText_W_H > 0) { 84 | int nScrollRange = 0; 85 | 86 | if (m_nRollDirection == ROLLTEXT_LEFT || m_nRollDirection == ROLLTEXT_RIGHT) { //左面移动 87 | nScrollRange = m_nText_W_H + rcClient.right - rcClient.left; 88 | LONG off_cx = (m_nRollDirection == ROLLTEXT_LEFT ? rcClient.right - rcClient.left : rcClient.left - rcClient.right); 89 | ::OffsetRect (&rcClient, off_cx, 0); 90 | off_cx = (m_nRollDirection == ROLLTEXT_LEFT ? -m_nScrollPos : m_nScrollPos); 91 | ::OffsetRect (&rcClient, off_cx, 0); 92 | rcClient.right += (m_nText_W_H - (rcClient.right - rcClient.left)); 93 | } else { //上下移动 94 | nScrollRange = m_nText_W_H + rcClient.bottom - rcClient.top; 95 | LONG off_cy = (m_nRollDirection == ROLLTEXT_UP ? rcClient.bottom - rcClient.top : rcClient.top - rcClient.bottom); 96 | ::OffsetRect (&rcClient, 0, off_cy); 97 | off_cy = (m_nRollDirection == ROLLTEXT_UP ? -m_nScrollPos : m_nScrollPos); 98 | ::OffsetRect (&rcClient, 0, off_cy); 99 | rcClient.bottom += (m_nText_W_H - (rcClient.bottom - rcClient.top)); 100 | } 101 | 102 | m_nScrollPos += m_nStep; 103 | if (m_nScrollPos > nScrollRange) { 104 | m_nScrollPos = 0; 105 | } 106 | } 107 | 108 | RECT rc = rcClient; 109 | 110 | UINT uTextStyle = DT_WORDBREAK | DT_EDITCONTROL; 111 | 112 | if (m_nText_W_H == 0) { 113 | uTextStyle |= DT_CALCRECT; //第一次计算文本宽度或高度 114 | if (m_nRollDirection == ROLLTEXT_LEFT || m_nRollDirection == ROLLTEXT_RIGHT) { //左面移动 115 | rc.right += 10000; 116 | } else { //上下移动 117 | rc.bottom += 10000; 118 | } 119 | } 120 | 121 | if (m_bShowHtml) { 122 | int nLinks = 0; 123 | CRenderEngine::DrawHtmlText (hDC, m_pManager, rc, sText, dwTextColor, nullptr, nullptr, nLinks, m_iFont, uTextStyle); 124 | } else { 125 | CRenderEngine::DrawText (hDC, m_pManager, rc, sText, dwTextColor, m_iFont, uTextStyle); 126 | } 127 | 128 | if (m_nText_W_H == 0) { 129 | m_nText_W_H = (m_nRollDirection == ROLLTEXT_LEFT || m_nRollDirection == ROLLTEXT_RIGHT) ? (rc.right - rc.left) : (rc.bottom - rc.top); //计算文本宽度或高度 130 | } 131 | } 132 | } -------------------------------------------------------------------------------- /DuiLib/Control/UIRollText.h: -------------------------------------------------------------------------------- 1 | #ifndef __UITEXTSCROLLH__ 2 | #define __UITEXTSCROLLH__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | #define ROLLTEXT_LEFT 0 8 | #define ROLLTEXT_RIGHT 1 9 | #define ROLLTEXT_UP 2 10 | #define ROLLTEXT_DOWN 3 11 | 12 | #define ROLLTEXT_TIMERID 20 13 | #define ROLLTEXT_TIMERID_SPAN 50U 14 | 15 | #define ROLLTEXT_ROLL_END 21 16 | #define ROLLTEXT_ROLL_END_SPAN 1000*6U 17 | 18 | class UILIB_API CRollTextUI: public CLabelUI { 19 | DECLARE_DUICONTROL (CRollTextUI) 20 | public: 21 | CRollTextUI (void); 22 | virtual ~CRollTextUI (void); 23 | 24 | public: 25 | faw::string_t GetClass () const; 26 | LPVOID GetInterface (faw::string_t pstrName); 27 | 28 | public: 29 | virtual void PaintText (HDC hDC); 30 | virtual void DoEvent (TEventUI& event); 31 | virtual void SetPos (RECT rc); 32 | virtual void SetText (faw::string_t pstrText); 33 | 34 | public: 35 | void BeginRoll (int nDirect = ROLLTEXT_RIGHT, LONG lTimeSpan = ROLLTEXT_TIMERID_SPAN, LONG lMaxTimeLimited = 60); 36 | void EndRoll (); 37 | 38 | private: 39 | int m_nStep = 5; 40 | int m_nScrollPos = 0; 41 | BOOL m_bUseRoll = FALSE; 42 | int m_nRollDirection = ROLLTEXT_LEFT; 43 | int m_nText_W_H = 0; 44 | }; 45 | 46 | } // namespace DuiLib 47 | 48 | #endif // __UITEXTSCROLLH__ -------------------------------------------------------------------------------- /DuiLib/Control/UISlider.h: -------------------------------------------------------------------------------- 1 | #ifndef __UISLIDER_H__ 2 | #define __UISLIDER_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CSliderUI: public CProgressUI { 8 | DECLARE_DUICONTROL (CSliderUI) 9 | public: 10 | CSliderUI (); 11 | 12 | faw::string_t GetClass () const; 13 | UINT GetControlFlags () const; 14 | LPVOID GetInterface (faw::string_t pstrName); 15 | 16 | void SetEnabled (bool bEnable = true); 17 | 18 | int GetChangeStep (); 19 | void SetChangeStep (int step); 20 | void SetThumbSize (SIZE szXY); 21 | RECT GetThumbRect () const; 22 | faw::string_t GetThumbImage () const; 23 | void SetThumbImage (faw::string_t pStrImage); 24 | faw::string_t GetThumbHotImage () const; 25 | void SetThumbHotImage (faw::string_t pStrImage); 26 | faw::string_t GetThumbPushedImage () const; 27 | void SetThumbPushedImage (faw::string_t pStrImage); 28 | 29 | void DoEvent (TEventUI& event); 30 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 31 | void PaintForeImage (HDC hDC); 32 | 33 | void SetValue (int nValue); 34 | void SetCanSendMove (bool bCanSend); 35 | bool GetCanSendMove () const; 36 | protected: 37 | SIZE m_szThumb = { 0 }; 38 | UINT m_uButtonState = 0; 39 | int m_nStep = 1; 40 | 41 | faw::string_t m_sThumbImage; 42 | faw::string_t m_sThumbHotImage; 43 | faw::string_t m_sThumbPushedImage; 44 | 45 | faw::string_t m_sImageModify; 46 | bool m_bSendMove = false; 47 | }; 48 | } 49 | 50 | #endif // __UISLIDER_H__ -------------------------------------------------------------------------------- /DuiLib/Control/UIText.h: -------------------------------------------------------------------------------- 1 | #ifndef __UITEXT_H__ 2 | #define __UITEXT_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CTextUI: public CLabelUI { 8 | DECLARE_DUICONTROL (CTextUI) 9 | public: 10 | CTextUI (); 11 | virtual ~CTextUI (); 12 | 13 | faw::string_t GetClass () const; 14 | UINT GetControlFlags () const; 15 | LPVOID GetInterface (faw::string_t pstrName); 16 | 17 | faw::string_t* GetLinkContent (int iIndex); 18 | 19 | void DoEvent (TEventUI& event); 20 | SIZE EstimateSize (SIZE szAvailable); 21 | 22 | void PaintText (HDC hDC); 23 | 24 | protected: 25 | enum { MAX_LINK = 8 }; 26 | int m_nLinks = 0; 27 | RECT m_rcLinks[MAX_LINK]; 28 | faw::string_t m_sLinks[MAX_LINK]; 29 | int m_nHoverLink = -1; 30 | }; 31 | 32 | } // namespace DuiLib 33 | 34 | #endif //__UITEXT_H__ -------------------------------------------------------------------------------- /DuiLib/Core/ControlFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "ControlFactory.h" 3 | 4 | namespace DuiLib { 5 | CControlFactory::CControlFactory () { 6 | INNER_REGISTER_DUICONTROL (CControlUI); 7 | INNER_REGISTER_DUICONTROL (CContainerUI); 8 | INNER_REGISTER_DUICONTROL (CButtonUI); 9 | INNER_REGISTER_DUICONTROL (CComboUI); 10 | INNER_REGISTER_DUICONTROL (CComboBoxUI); 11 | INNER_REGISTER_DUICONTROL (CDateTimeUI); 12 | INNER_REGISTER_DUICONTROL (CEditUI); 13 | INNER_REGISTER_DUICONTROL (CActiveXUI); 14 | INNER_REGISTER_DUICONTROL (CFlashUI); 15 | INNER_REGISTER_DUICONTROL (CGifAnimUI); 16 | #ifdef USE_XIMAGE_EFFECT 17 | INNER_REGISTER_DUICONTROL (CGifAnimExUI); 18 | #endif 19 | INNER_REGISTER_DUICONTROL (CGroupBoxUI); 20 | INNER_REGISTER_DUICONTROL (CIPAddressUI); 21 | INNER_REGISTER_DUICONTROL (CIPAddressExUI); 22 | INNER_REGISTER_DUICONTROL (CLabelUI); 23 | INNER_REGISTER_DUICONTROL (CListUI); 24 | INNER_REGISTER_DUICONTROL (CListHeaderUI); 25 | INNER_REGISTER_DUICONTROL (CListHeaderItemUI); 26 | INNER_REGISTER_DUICONTROL (CListLabelElementUI); 27 | INNER_REGISTER_DUICONTROL (CListTextElementUI); 28 | INNER_REGISTER_DUICONTROL (CListContainerElementUI); 29 | INNER_REGISTER_DUICONTROL (CMenuUI); 30 | INNER_REGISTER_DUICONTROL (CMenuElementUI); 31 | INNER_REGISTER_DUICONTROL (COptionUI); 32 | INNER_REGISTER_DUICONTROL (CCheckBoxUI); 33 | INNER_REGISTER_DUICONTROL (CProgressUI); 34 | INNER_REGISTER_DUICONTROL (CRichEditUI); 35 | INNER_REGISTER_DUICONTROL (CScrollBarUI); 36 | INNER_REGISTER_DUICONTROL (CSliderUI); 37 | INNER_REGISTER_DUICONTROL (CTextUI); 38 | INNER_REGISTER_DUICONTROL (CTreeNodeUI); 39 | INNER_REGISTER_DUICONTROL (CTreeViewUI); 40 | INNER_REGISTER_DUICONTROL (CWebBrowserUI); 41 | INNER_REGISTER_DUICONTROL (CAnimationTabLayoutUI); 42 | INNER_REGISTER_DUICONTROL (CChildLayoutUI); 43 | INNER_REGISTER_DUICONTROL (CHorizontalLayoutUI); 44 | INNER_REGISTER_DUICONTROL (CTabLayoutUI); 45 | INNER_REGISTER_DUICONTROL (CTileLayoutUI); 46 | INNER_REGISTER_DUICONTROL (CVerticalLayoutUI); 47 | INNER_REGISTER_DUICONTROL (CRollTextUI); 48 | INNER_REGISTER_DUICONTROL (CColorPaletteUI); 49 | INNER_REGISTER_DUICONTROL (CListExUI); 50 | INNER_REGISTER_DUICONTROL (CListContainerHeaderItemUI); 51 | INNER_REGISTER_DUICONTROL (CListTextExtElementUI); 52 | INNER_REGISTER_DUICONTROL (CHotKeyUI); 53 | INNER_REGISTER_DUICONTROL (CFadeButtonUI); 54 | INNER_REGISTER_DUICONTROL (CRingUI); 55 | } 56 | 57 | CControlFactory::~CControlFactory () {} 58 | 59 | CControlUI* CControlFactory::CreateControl (faw::string_t strClassName) { 60 | FawTools::lower (strClassName); 61 | MAP_DUI_CTRATECLASS::iterator iter = m_mapControl.find (strClassName); 62 | if (iter == m_mapControl.end ()) { 63 | return nullptr; 64 | } else { 65 | return (CControlUI*) (iter->second ()); 66 | } 67 | } 68 | 69 | void CControlFactory::RegistControl (faw::string_t strClassName, CreateClass pFunc) { 70 | FawTools::lower (strClassName); 71 | m_mapControl.insert (MAP_DUI_CTRATECLASS::value_type (strClassName, pFunc)); 72 | } 73 | 74 | CControlFactory* CControlFactory::GetInstance () { 75 | static CControlFactory* pInstance = new CControlFactory; 76 | return pInstance; 77 | } 78 | 79 | void CControlFactory::Release () { 80 | delete this; 81 | } 82 | } -------------------------------------------------------------------------------- /DuiLib/Core/ControlFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | namespace DuiLib { 4 | typedef CControlUI* (*CreateClass)(); 5 | typedef std::map MAP_DUI_CTRATECLASS; 6 | 7 | class UILIB_API CControlFactory { 8 | public: 9 | CControlUI* CreateControl (faw::string_t strClassName); 10 | void RegistControl (faw::string_t strClassName, CreateClass pFunc); 11 | 12 | static CControlFactory* GetInstance (); 13 | void Release (); 14 | 15 | private: 16 | CControlFactory (); 17 | virtual ~CControlFactory (); 18 | 19 | private: 20 | MAP_DUI_CTRATECLASS m_mapControl; 21 | }; 22 | 23 | #define DECLARE_DUICONTROL(class_name)\ 24 | public:\ 25 | static CControlUI* CreateControl(); 26 | 27 | #define IMPLEMENT_DUICONTROL(class_name)\ 28 | CControlUI* class_name::CreateControl()\ 29 | { return new class_name; } 30 | 31 | #define REGIST_DUICONTROL(class_name)\ 32 | CControlFactory::GetInstance()->RegistControl(_T(#class_name), (CreateClass)class_name::CreateControl); 33 | 34 | #define INNER_REGISTER_DUICONTROL(class_name)\ 35 | RegistControl(_T(#class_name), (CreateClass)class_name::CreateControl); 36 | } -------------------------------------------------------------------------------- /DuiLib/Core/StdAfx.h: -------------------------------------------------------------------------------- 1 | #include "../StdAfx.h" -------------------------------------------------------------------------------- /DuiLib/Core/UIBase.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIBASE_H__ 2 | #define __UIBASE_H__ 3 | 4 | 5 | #pragma once 6 | 7 | namespace DuiLib { 8 | ///////////////////////////////////////////////////////////////////////////////////// 9 | // 10 | 11 | #define UI_WNDSTYLE_CONTAINER (0) 12 | #define UI_WNDSTYLE_FRAME (WS_VISIBLE | WS_OVERLAPPEDWINDOW) 13 | #define UI_WNDSTYLE_CHILD (WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN) 14 | #define UI_WNDSTYLE_DIALOG (WS_VISIBLE | WS_POPUPWINDOW | WS_CAPTION | WS_DLGFRAME | WS_CLIPSIBLINGS | WS_CLIPCHILDREN) 15 | 16 | #define UI_WNDSTYLE_EX_FRAME (WS_EX_WINDOWEDGE) 17 | #define UI_WNDSTYLE_EX_DIALOG (WS_EX_TOOLWINDOW | WS_EX_DLGMODALFRAME) 18 | 19 | #define UI_CLASSSTYLE_CONTAINER (0) 20 | #define UI_CLASSSTYLE_FRAME (CS_VREDRAW | CS_HREDRAW) 21 | #define UI_CLASSSTYLE_CHILD (CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS | CS_SAVEBITS) 22 | #define UI_CLASSSTYLE_DIALOG (CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS | CS_SAVEBITS) 23 | 24 | 25 | ///////////////////////////////////////////////////////////////////////////////////// 26 | // 27 | #ifndef ASSERT 28 | #define ASSERT(expr) _ASSERTE(expr) 29 | #endif 30 | 31 | #ifdef _DEBUG 32 | #ifndef DUITRACE 33 | #define DUITRACE DUI__Trace 34 | #endif 35 | #define DUITRACEMSG DUI__TraceMsg 36 | #else 37 | #ifndef DUITRACE 38 | #define DUITRACE 39 | #endif 40 | #define DUITRACEMSG _T("") 41 | #endif 42 | 43 | void UILIB_API DUI__Trace (LPCTSTR pstrFormat, ...); 44 | LPCTSTR UILIB_API DUI__TraceMsg (UINT uMsg); 45 | 46 | ///////////////////////////////////////////////////////////////////////////////////// 47 | // 48 | 49 | class UILIB_API CNotifyPump { 50 | public: 51 | bool AddVirtualWnd (faw::string_t strName, CNotifyPump* pObject); 52 | bool RemoveVirtualWnd (faw::string_t strName); 53 | void NotifyPump (TNotifyUI& msg); 54 | bool LoopDispatch (TNotifyUI& msg); 55 | DUI_DECLARE_MESSAGE_MAP () 56 | private: 57 | CStdStringPtrMap m_VirtualWndMap; 58 | }; 59 | 60 | class UILIB_API CWindowWnd { 61 | public: 62 | CWindowWnd (); 63 | 64 | HWND GetHWND () const { return m_hWnd; } 65 | bool RegisterWindowClass (); 66 | bool RegisterSuperclass (); 67 | 68 | HWND Create (HWND hwndParent, faw::string_t pstrName, DWORD dwStyle, DWORD dwExStyle, const RECT rc, HMENU hMenu = NULL); 69 | HWND Create (HWND hwndParent, faw::string_t pstrName, DWORD dwStyle, DWORD dwExStyle, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT, int cx = CW_USEDEFAULT, int cy = CW_USEDEFAULT, HMENU hMenu = NULL); 70 | HWND CreateDuiWindow (HWND hwndParent, faw::string_t pstrWindowName, DWORD dwStyle = 0, DWORD dwExStyle = 0); 71 | HWND Subclass (HWND hWnd); 72 | void Unsubclass (); 73 | void ShowWindow (bool bShow = true, bool bTakeFocus = true); 74 | UINT ShowModal (); 75 | void Close (UINT nRet = IDOK); 76 | void CenterWindow (); // 居中,支持扩展屏幕 77 | void SetIcon (UINT nRes); 78 | void SetIcon (faw::string_t strIconPath); 79 | 80 | LRESULT SendMessage (UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0L); 81 | LRESULT PostMessage (UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0L); 82 | void ResizeClient (int cx = -1, int cy = -1); 83 | 84 | protected: 85 | virtual LPCTSTR GetWindowClassName () const = 0; 86 | virtual LPCTSTR GetSuperClassName () const { return nullptr; } 87 | virtual UINT GetClassStyle () const { return 0; } 88 | 89 | virtual LRESULT HandleMessage (UINT uMsg, WPARAM wParam, LPARAM lParam); 90 | virtual void OnFinalMessage (HWND hWnd); 91 | 92 | static LRESULT CALLBACK __WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 93 | static LRESULT CALLBACK __ControlProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 94 | 95 | protected: 96 | HWND m_hWnd; 97 | WNDPROC m_OldWndProc; 98 | bool m_bSubclassed; 99 | HICON m_hIcon; 100 | }; 101 | 102 | } // namespace DuiLib 103 | 104 | #endif // __UIBASE_H__ 105 | -------------------------------------------------------------------------------- /DuiLib/Core/UIDlgBuilder.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIDLGBUILDER_H__ 2 | #define __UIDLGBUILDER_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | 8 | class IDialogBuilderCallback { 9 | public: 10 | virtual CControlUI* CreateControl (faw::string_t pstrClass) = 0; 11 | }; 12 | 13 | 14 | class UILIB_API CDialogBuilder { 15 | public: 16 | CDialogBuilder (); 17 | CControlUI* Create (std::variant xml, faw::string_t type = _T (""), IDialogBuilderCallback* pCallback = nullptr, CPaintManagerUI* pManager = nullptr, CControlUI* pParent = nullptr); 18 | CControlUI* Create (IDialogBuilderCallback* pCallback = nullptr, CPaintManagerUI* pManager = nullptr, CControlUI* pParent = nullptr); 19 | 20 | CMarkup* GetMarkup (); 21 | 22 | faw::string_t GetLastErrorMessage () const; 23 | faw::string_t GetLastErrorLocation () const; 24 | void SetInstance (HINSTANCE instance) { m_instance = instance; }; 25 | private: 26 | CControlUI* _Parse (CMarkupNode* parent, CControlUI* pParent = nullptr, CPaintManagerUI* pManager = nullptr); 27 | 28 | CMarkup m_xml; 29 | IDialogBuilderCallback *m_pCallback = nullptr; 30 | faw::string_t m_pstrtype = _T (""); 31 | HINSTANCE m_instance = NULL; 32 | }; 33 | 34 | } // namespace DuiLib 35 | 36 | #endif // __UIDLGBUILDER_H__ 37 | -------------------------------------------------------------------------------- /DuiLib/Core/UIMarkup.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIMARKUP_H__ 2 | #define __UIMARKUP_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | 8 | enum { 9 | XMLFILE_ENCODING_UTF8 = 0, 10 | XMLFILE_ENCODING_UNICODE = 1, 11 | XMLFILE_ENCODING_ASNI = 2, 12 | }; 13 | 14 | class CMarkup; 15 | class CMarkupNode; 16 | 17 | 18 | class UILIB_API CMarkup { 19 | friend class CMarkupNode; 20 | public: 21 | CMarkup (faw::string_t pstrXML = _T ("")); 22 | virtual ~CMarkup (); 23 | 24 | bool Load (faw::string_t pstrXML); 25 | bool LoadFromMem (BYTE* pByte, DWORD dwSize, int encoding = XMLFILE_ENCODING_UTF8); 26 | bool LoadFromFile (faw::string_t pstrFilename, int encoding = XMLFILE_ENCODING_UTF8); 27 | void Release (); 28 | bool IsValid () const; 29 | 30 | void SetPreserveWhitespace (bool bPreserve = true); 31 | faw::string_t GetLastErrorMessage () const; 32 | faw::string_t GetLastErrorLocation () const; 33 | 34 | CMarkupNode GetRoot (); 35 | 36 | private: 37 | typedef struct tagXMLELEMENT { 38 | ULONG iStart; 39 | ULONG iChild; 40 | ULONG iNext; 41 | ULONG iParent; 42 | ULONG iData; 43 | } XMLELEMENT; 44 | 45 | faw::string_t m_pstrXML; 46 | XMLELEMENT* m_pElements; 47 | ULONG m_nElements; 48 | ULONG m_nReservedElements; 49 | faw::string_t m_szErrorMsg; 50 | faw::string_t m_szErrorXML; 51 | bool m_bPreserveWhitespace; 52 | 53 | private: 54 | bool _Parse (); 55 | bool _Parse (LPTSTR& pstrText, ULONG iParent); 56 | XMLELEMENT* _ReserveElement (); 57 | inline void _SkipWhitespace (LPTSTR& pstr) const; 58 | inline void _SkipWhitespace (LPCTSTR& pstr) const; 59 | inline void _SkipIdentifier (LPTSTR& pstr) const; 60 | inline void _SkipIdentifier (LPCTSTR& pstr) const; 61 | bool _ParseData (LPTSTR& pstrText, LPTSTR& pstrData, char cEnd); 62 | void _ParseMetaChar (LPTSTR& pstrText, LPTSTR& pstrDest); 63 | bool _ParseAttributes (LPTSTR& pstrText); 64 | bool _Failed (faw::string_t pstrError, faw::string_t pstrLocation = _T ("")); 65 | }; 66 | 67 | 68 | class UILIB_API CMarkupNode { 69 | friend class CMarkup; 70 | private: 71 | CMarkupNode (); 72 | CMarkupNode (CMarkup* pOwner, int iPos); 73 | 74 | public: 75 | bool IsValid () const; 76 | 77 | CMarkupNode GetParent (); 78 | CMarkupNode GetSibling (); 79 | CMarkupNode GetChild (); 80 | CMarkupNode GetChild (faw::string_t pstrName); 81 | 82 | bool HasSiblings () const; 83 | bool HasChildren () const; 84 | faw::string_t GetName () const; 85 | faw::string_t GetValue () const; 86 | 87 | bool HasAttributes (); 88 | bool HasAttribute (faw::string_t pstrName); 89 | int GetAttributeCount (); 90 | faw::string_t GetAttributeName (int iIndex); 91 | faw::string_t GetAttributeValue (int iIndex); 92 | faw::string_t GetAttributeValue (faw::string_t pstrName); 93 | 94 | private: 95 | void _MapAttributes (); 96 | 97 | enum { MAX_XML_ATTRIBUTES = 64 }; 98 | 99 | typedef struct { 100 | ULONG iName; 101 | ULONG iValue; 102 | } XMLATTRIBUTE; 103 | 104 | int m_iPos; 105 | int m_nAttributes; 106 | XMLATTRIBUTE m_aAttributes[MAX_XML_ATTRIBUTES]; 107 | CMarkup* m_pOwner; 108 | }; 109 | 110 | } // namespace DuiLib 111 | 112 | #endif // __UIMARKUP_H__ 113 | -------------------------------------------------------------------------------- /DuiLib/Core/UIRender.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIRENDER_H__ 2 | #define __UIRENDER_H__ 3 | 4 | #pragma once 5 | 6 | #ifdef USE_XIMAGE_EFFECT 7 | class CxImage; 8 | #endif 9 | namespace DuiLib { 10 | ///////////////////////////////////////////////////////////////////////////////////// 11 | // 12 | 13 | class UILIB_API CRenderClip { 14 | public: 15 | virtual ~CRenderClip (); 16 | RECT rcItem = { 0 }; 17 | HDC hDC; 18 | HRGN hRgn; 19 | HRGN hOldRgn; 20 | 21 | static void GenerateClip (HDC hDC, RECT rc, CRenderClip& clip); 22 | static void GenerateRoundClip (HDC hDC, RECT rc, RECT rcItem, int width, int height, CRenderClip& clip); 23 | static void UseOldClipBegin (HDC hDC, CRenderClip& clip); 24 | static void UseOldClipEnd (HDC hDC, CRenderClip& clip); 25 | }; 26 | 27 | ///////////////////////////////////////////////////////////////////////////////////// 28 | // 29 | 30 | class UILIB_API CRenderEngine { 31 | public: 32 | static DWORD AdjustColor (DWORD dwColor, short H, short S, short L); 33 | static HBITMAP CreateARGB32Bitmap (HDC hDC, int cx, int cy, BYTE** pBits); 34 | static void AdjustImage (bool bUseHSL, TImageInfo* imageInfo, short H, short S, short L); 35 | static TImageInfo* LoadImage (std::variant bitmap, faw::string_t type = _T (""), DWORD mask = 0, HINSTANCE instance = NULL); 36 | #ifdef USE_XIMAGE_EFFECT 37 | static CxImage *LoadGifImageX (std::variant bitmap, faw::string_t type = _T (""), DWORD mask = 0); 38 | #endif 39 | static void FreeImage (TImageInfo* bitmap, bool bDelete = true); 40 | static TImageInfo* LoadImage (faw::string_t pStrImage, faw::string_t type = _T (""), DWORD mask = 0, HINSTANCE instance = NULL); 41 | static TImageInfo* LoadImage (UINT nID, faw::string_t type = _T (""), DWORD mask = 0, HINSTANCE instance = NULL); 42 | 43 | static Gdiplus::Image *GdiplusLoadImage (faw::string_t pstrPath); 44 | static Gdiplus::Image* GdiplusLoadImage (LPVOID pBuf, size_t dwSize); 45 | static HICON GdiplusLoadIcon(LPVOID pBuf, size_t dwSize); 46 | static HICON GdiplusLoadIcon(faw::string_t pstrPath1); 47 | 48 | static bool DrawIconImageString (HDC hDC, CPaintManagerUI* pManager, const RECT& rcItem, const RECT& rcPaint, \ 49 | faw::string_t pStrImage, faw::string_t pStrModify = _T ("")); 50 | static bool MakeFitIconDest (const RECT& rcControl, const SIZE& szIcon, const faw::string_t& sAlign, RECT& rcDest); 51 | 52 | static void DrawText (HDC hDC, CPaintManagerUI* pManager, RECT& rc, faw::string_t pstrText, DWORD dwTextColor, \ 53 | int iFont, UINT uStyle, DWORD dwTextBKColor); 54 | 55 | static void DrawImage (HDC hDC, HBITMAP hBitmap, const RECT& rc, const RECT& rcPaint, \ 56 | const RECT& rcBmpPart, const RECT& rcCorners, bool bAlpha, BYTE uFade = 255, 57 | bool hole = false, bool xtiled = false, bool ytiled = false); 58 | 59 | static bool DrawImageInfo (HDC hDC, CPaintManagerUI* pManager, const RECT& rcItem, const RECT& rcPaint, const TDrawInfo* pDrawInfo, HINSTANCE instance = NULL); 60 | static bool DrawImageString (HDC hDC, CPaintManagerUI* pManager, const RECT& rcItem, const RECT& rcPaint, faw::string_t pStrImage, faw::string_t pStrModify = _T (""), HINSTANCE instance = NULL); 61 | 62 | static void DrawColor (HDC hDC, const RECT& rc, DWORD color); 63 | static void DrawGradient (HDC hDC, const RECT& rc, DWORD dwFirst, DWORD dwSecond, bool bVertical, int nSteps); 64 | 65 | // 以下函数中的颜色参数alpha值无效 66 | static void DrawLine (HDC hDC, const RECT& rc, int nSize, DWORD dwPenColor, int nStyle = PS_SOLID); 67 | static void DrawRect (HDC hDC, const RECT& rc, int nSize, DWORD dwPenColor, int nStyle = PS_SOLID); 68 | static void DrawRoundRectangle(HDC hDC, float x, float y, float width, float height, float arcSize, float lineWidth, Gdiplus::Color lineColor, bool fillPath, DWORD fillColor); 69 | static void DrawRoundRect (HDC hDC, const RECT& rc, int width, int height, int nSize, DWORD dwPenColor, int nStyle = PS_SOLID); 70 | static void DrawText (HDC hDC, CPaintManagerUI* pManager, RECT& rc, faw::string_t pstrText, \ 71 | DWORD dwTextColor, int iFont, UINT uStyle); 72 | static void DrawHtmlText (HDC hDC, CPaintManagerUI* pManager, RECT& rc, faw::string_t pstrText, 73 | DWORD dwTextColor, RECT* pLinks, faw::string_t* sLinks, int& nLinkRects, int iFont, UINT uStyle); 74 | static HBITMAP GenerateBitmap (CPaintManagerUI* pManager, RECT rc, CControlUI* pStopControl = nullptr, DWORD dwFilterColor = 0); 75 | static HBITMAP GenerateBitmap (CPaintManagerUI* pManager, CControlUI* pControl, RECT rc, DWORD dwFilterColor = 0); 76 | static SIZE GetTextSize (HDC hDC, CPaintManagerUI* pManager, faw::string_t pstrText, int iFont, UINT uStyle); 77 | 78 | //alpha utilities 79 | static void CheckAlphaColor (DWORD& dwColor); 80 | }; 81 | 82 | } // namespace DuiLib 83 | 84 | #endif // __UIRENDER_H__ 85 | -------------------------------------------------------------------------------- /DuiLib/Core/UIResourceManager.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIRESOURCEMANAGER_H__ 2 | #define __UIRESOURCEMANAGER_H__ 3 | #pragma once 4 | 5 | namespace DuiLib { 6 | // 控件文字查询接口 7 | class UILIB_API IQueryControlText { 8 | public: 9 | virtual faw::string_t QueryControlText (faw::string_t lpstrId, faw::string_t lpstrType) = 0; 10 | }; 11 | 12 | class UILIB_API CResourceManager { 13 | private: 14 | CResourceManager (void); 15 | virtual ~CResourceManager (void); 16 | 17 | public: 18 | static CResourceManager* GetInstance () { 19 | static CResourceManager * p = new CResourceManager; 20 | return p; 21 | }; 22 | void Release (void) { 23 | delete this; 24 | } 25 | 26 | public: 27 | BOOL LoadResource (std::variant xml, faw::string_t type = _T ("")); 28 | BOOL LoadResource (CMarkupNode Root); 29 | void ResetResourceMap (); 30 | faw::string_t GetImagePath (faw::string_t lpstrId); 31 | faw::string_t GetXmlPath (faw::string_t lpstrId); 32 | 33 | public: 34 | void SetLanguage (faw::string_t pstrLanguage) { m_sLauguage = pstrLanguage; } 35 | faw::string_t GetLanguage () { return m_sLauguage; } 36 | BOOL LoadLanguage (faw::string_t pstrXml); 37 | 38 | public: 39 | void SetTextQueryInterface (IQueryControlText* pInterface) { 40 | m_pQuerypInterface = pInterface; 41 | } 42 | faw::string_t GetText (faw::string_t lpstrId, faw::string_t lpstrType = _T ("")); 43 | void ReloadText (); 44 | void ResetTextMap (); 45 | 46 | private: 47 | CStdStringPtrMap m_mTextResourceHashMap; 48 | IQueryControlText *m_pQuerypInterface; 49 | CStdStringPtrMap m_mImageHashMap; 50 | CStdStringPtrMap m_mXmlHashMap; 51 | CMarkup m_xml; 52 | faw::string_t m_sLauguage; 53 | CStdStringPtrMap m_mTextHashMap; 54 | }; 55 | 56 | } // namespace DuiLib 57 | 58 | #endif // __UIRESOURCEMANAGER_H__ -------------------------------------------------------------------------------- /DuiLib/Layout/StdAfx.h: -------------------------------------------------------------------------------- 1 | #include "../StdAfx.h" -------------------------------------------------------------------------------- /DuiLib/Layout/UIAnimationTabLayout.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "UIAnimationTabLayout.h" 3 | 4 | namespace DuiLib { 5 | IMPLEMENT_DUICONTROL (CAnimationTabLayoutUI) 6 | 7 | CAnimationTabLayoutUI::CAnimationTabLayoutUI () { 8 | Attach (this); 9 | } 10 | 11 | faw::string_t CAnimationTabLayoutUI::GetClass () const { 12 | return _T ("AnimationTabLayoutUI"); 13 | } 14 | 15 | LPVOID CAnimationTabLayoutUI::GetInterface (faw::string_t pstrName) { 16 | if (pstrName == _T ("AnimationTabLayout")) 17 | return static_cast(this); 18 | return CTabLayoutUI::GetInterface (pstrName); 19 | } 20 | 21 | bool CAnimationTabLayoutUI::SelectItem (int iIndex) { 22 | if (iIndex < 0 || iIndex >= m_items.GetSize ()) return false; 23 | if (iIndex == m_iCurSel) return true; 24 | if (iIndex > m_iCurSel) m_nPositiveDirection = -1; 25 | if (iIndex < m_iCurSel) m_nPositiveDirection = 1; 26 | 27 | int iOldSel = m_iCurSel; 28 | m_iCurSel = iIndex; 29 | for (int it = 0; it < m_items.GetSize (); it++) { 30 | if (it == iIndex) { 31 | GetItemAt (it)->SetVisible (true); 32 | GetItemAt (it)->SetFocus (); 33 | m_bControlVisibleFlag = false; 34 | m_pCurrentControl = static_cast(m_items[it]); 35 | 36 | } else GetItemAt (it)->SetVisible (false); 37 | } 38 | 39 | NeedParentUpdate (); 40 | if (nullptr != m_pCurrentControl) m_pCurrentControl->SetVisible (false); 41 | AnimationSwitch (); 42 | 43 | if (m_pManager) { 44 | m_pManager->SetNextTabControl (); 45 | m_pManager->SendNotify (this, _T ("tabselect"), m_iCurSel, iOldSel); 46 | } 47 | return true; 48 | } 49 | 50 | void CAnimationTabLayoutUI::AnimationSwitch () { 51 | m_rcItemOld = m_rcItem; 52 | if (!m_bIsVerticalDirection) { 53 | m_rcCurPos.top = m_rcItem.top; 54 | m_rcCurPos.bottom = m_rcItem.bottom; 55 | m_rcCurPos.left = m_rcItem.left - (m_rcItem.right - m_rcItem.left) * m_nPositiveDirection + 52 * m_nPositiveDirection; 56 | m_rcCurPos.right = m_rcItem.right - (m_rcItem.right - m_rcItem.left) * m_nPositiveDirection + 52 * m_nPositiveDirection; 57 | } else { 58 | m_rcCurPos.left = m_rcItem.left; 59 | m_rcCurPos.right = m_rcItem.right; 60 | m_rcCurPos.top = m_rcItem.top - (m_rcItem.bottom - m_rcItem.top) * m_nPositiveDirection; 61 | m_rcCurPos.bottom = m_rcItem.bottom - (m_rcItem.bottom - m_rcItem.top) * m_nPositiveDirection; 62 | } 63 | 64 | StopAnimation (TAB_ANIMATION_ID); 65 | StartAnimation (TAB_ANIMATION_ELLAPSE, TAB_ANIMATION_FRAME_COUNT, TAB_ANIMATION_ID); 66 | } 67 | 68 | void CAnimationTabLayoutUI::DoEvent (TEventUI& event) { 69 | if (event.Type == UIEVENT_TIMER) { 70 | OnTimer ((int) event.wParam); 71 | } 72 | __super::DoEvent (event); 73 | } 74 | 75 | void CAnimationTabLayoutUI::OnTimer (int nTimerID) { 76 | OnAnimationElapse (nTimerID); 77 | } 78 | 79 | void CAnimationTabLayoutUI::OnAnimationStep (INT nTotalFrame, INT nCurFrame, INT nAnimationID) { 80 | if (!m_bControlVisibleFlag) { 81 | m_bControlVisibleFlag = true; 82 | m_pCurrentControl->SetVisible (true); 83 | } 84 | 85 | int iStepLen = 0; 86 | if (!m_bIsVerticalDirection) { 87 | iStepLen = (m_rcItemOld.right - m_rcItemOld.left) * m_nPositiveDirection / nTotalFrame; 88 | if (nCurFrame != nTotalFrame) { 89 | m_rcCurPos.left = m_rcCurPos.left + iStepLen; 90 | m_rcCurPos.right = m_rcCurPos.right + iStepLen; 91 | } else { 92 | m_rcItem = m_rcCurPos = m_rcItemOld; 93 | } 94 | } else { 95 | iStepLen = (m_rcItemOld.bottom - m_rcItemOld.top) * m_nPositiveDirection / nTotalFrame; 96 | if (nCurFrame != nTotalFrame) { 97 | m_rcCurPos.top = m_rcCurPos.top + iStepLen; 98 | m_rcCurPos.bottom = m_rcCurPos.bottom + iStepLen; 99 | } else { 100 | m_rcItem = m_rcCurPos = m_rcItemOld; 101 | } 102 | } 103 | SetPos (m_rcCurPos); 104 | } 105 | 106 | void CAnimationTabLayoutUI::OnAnimationStop (INT nAnimationID) { 107 | SetPos (m_rcItemOld); 108 | NeedParentUpdate (); 109 | } 110 | 111 | void CAnimationTabLayoutUI::SetAttribute (faw::string_t pstrName, faw::string_t pstrValue) { 112 | if (pstrName == _T ("animation_direction") && pstrValue == _T ("vertical")) m_bIsVerticalDirection = true; // pstrValue = "vertical" or "horizontal" 113 | return CTabLayoutUI::SetAttribute (pstrName, pstrValue); 114 | } 115 | } // namespace DuiLib -------------------------------------------------------------------------------- /DuiLib/Layout/UIAnimationTabLayout.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIANIMATIONTABLAYOUT_H__ 2 | #define __UIANIMATIONTABLAYOUT_H__ 3 | 4 | namespace DuiLib { 5 | class UILIB_API CAnimationTabLayoutUI: public CTabLayoutUI, public CUIAnimation { 6 | DECLARE_DUICONTROL (CAnimationTabLayoutUI) 7 | public: 8 | CAnimationTabLayoutUI (); 9 | 10 | faw::string_t GetClass () const; 11 | LPVOID GetInterface (faw::string_t pstrName); 12 | 13 | bool SelectItem (int iIndex); 14 | void AnimationSwitch (); 15 | void DoEvent (TEventUI& event); 16 | void OnTimer (int nTimerID); 17 | 18 | virtual void OnAnimationStart (INT nAnimationID, BOOL bFirstLoop) {} 19 | virtual void OnAnimationStep (INT nTotalFrame, INT nCurFrame, INT nAnimationID); 20 | virtual void OnAnimationStop (INT nAnimationID); 21 | 22 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 23 | 24 | protected: 25 | bool m_bIsVerticalDirection = false; 26 | int m_nPositiveDirection = 1; 27 | RECT m_rcCurPos = { 0 }; 28 | RECT m_rcItemOld = { 0 }; 29 | CControlUI *m_pCurrentControl = nullptr; 30 | bool m_bControlVisibleFlag = false; 31 | enum { 32 | TAB_ANIMATION_ID = 1, 33 | 34 | TAB_ANIMATION_ELLAPSE = 10, 35 | TAB_ANIMATION_FRAME_COUNT = 15, 36 | }; 37 | }; 38 | } 39 | #endif // __UIANIMATIONTABLAYOUT_H__ -------------------------------------------------------------------------------- /DuiLib/Layout/UIChildLayout.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "UIChildLayout.h" 3 | 4 | namespace DuiLib { 5 | IMPLEMENT_DUICONTROL (CChildLayoutUI) 6 | 7 | CChildLayoutUI::CChildLayoutUI () {} 8 | 9 | void CChildLayoutUI::Init () { 10 | if (!m_pstrXMLFile.empty ()) { 11 | CDialogBuilder builder; 12 | CContainerUI* pChildWindow = static_cast(builder.Create (m_pstrXMLFile, _T (""), nullptr, m_pManager)); 13 | if (pChildWindow) { 14 | this->Add (pChildWindow); 15 | } else { 16 | this->RemoveAll (); 17 | } 18 | } 19 | } 20 | 21 | void CChildLayoutUI::SetAttribute (faw::string_t pstrName, faw::string_t pstrValue) { 22 | if (pstrName == _T ("xmlfile")) 23 | SetChildLayoutXML (pstrValue); 24 | else 25 | CContainerUI::SetAttribute (pstrName, pstrValue); 26 | } 27 | 28 | void CChildLayoutUI::SetChildLayoutXML (faw::string_t pXML) { 29 | m_pstrXMLFile = pXML; 30 | } 31 | 32 | faw::string_t CChildLayoutUI::GetChildLayoutXML () { 33 | return m_pstrXMLFile; 34 | } 35 | 36 | LPVOID CChildLayoutUI::GetInterface (faw::string_t pstrName) { 37 | if (pstrName == DUI_CTRL_CHILDLAYOUT) return static_cast(this); 38 | return CControlUI::GetInterface (pstrName); 39 | } 40 | 41 | faw::string_t CChildLayoutUI::GetClass () const { 42 | return _T ("ChildLayoutUI"); 43 | } 44 | } // namespace DuiLib 45 | -------------------------------------------------------------------------------- /DuiLib/Layout/UIChildLayout.h: -------------------------------------------------------------------------------- 1 | #ifndef __UICHILDLAYOUT_H__ 2 | #define __UICHILDLAYOUT_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CChildLayoutUI: public CContainerUI { 8 | DECLARE_DUICONTROL (CChildLayoutUI) 9 | public: 10 | CChildLayoutUI (); 11 | 12 | void Init (); 13 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 14 | void SetChildLayoutXML (faw::string_t pXML); 15 | faw::string_t GetChildLayoutXML (); 16 | virtual LPVOID GetInterface (faw::string_t pstrName); 17 | virtual faw::string_t GetClass () const; 18 | 19 | private: 20 | faw::string_t m_pstrXMLFile; 21 | }; 22 | } // namespace DuiLib 23 | #endif // __UICHILDLAYOUT_H__ 24 | -------------------------------------------------------------------------------- /DuiLib/Layout/UIHorizontalLayout.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIHORIZONTALLAYOUT_H__ 2 | #define __UIHORIZONTALLAYOUT_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CHorizontalLayoutUI: public CContainerUI { 8 | DECLARE_DUICONTROL (CHorizontalLayoutUI) 9 | public: 10 | CHorizontalLayoutUI (); 11 | 12 | faw::string_t GetClass () const; 13 | LPVOID GetInterface (faw::string_t pstrName); 14 | UINT GetControlFlags () const; 15 | 16 | void SetSepWidth (int iWidth); 17 | int GetSepWidth () const; 18 | void SetSepImmMode (bool bImmediately); 19 | bool IsSepImmMode () const; 20 | void SetAutoCalcWidth (bool autoCalcWidth); 21 | bool IsAutoCalcWidth () const; 22 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 23 | void DoEvent (TEventUI& event); 24 | 25 | SIZE EstimateSize (SIZE szAvailable) override; 26 | void SetPos (RECT rc, bool bNeedInvalidate = true); 27 | void DoPostPaint (HDC hDC, const RECT& rcPaint); 28 | bool IsDynamic (POINT &pt) const override; 29 | 30 | RECT GetThumbRect (bool bUseNew = false) const; 31 | 32 | protected: 33 | int m_iSepWidth = 0; 34 | UINT m_uButtonState = 0; 35 | POINT ptLastMouse = { 0 }; 36 | RECT m_rcNewPos = { 0, 0, 0, 0 }; 37 | bool m_bImmMode = false; 38 | bool m_autoCalcWidth = false; 39 | }; 40 | } 41 | #endif // __UIHORIZONTALLAYOUT_H__ 42 | -------------------------------------------------------------------------------- /DuiLib/Layout/UITabLayout.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "UITabLayout.h" 3 | 4 | namespace DuiLib { 5 | IMPLEMENT_DUICONTROL (CTabLayoutUI) 6 | CTabLayoutUI::CTabLayoutUI () {} 7 | 8 | faw::string_t CTabLayoutUI::GetClass () const { 9 | return _T ("TabLayoutUI"); 10 | } 11 | 12 | LPVOID CTabLayoutUI::GetInterface (faw::string_t pstrName) { 13 | if (pstrName == DUI_CTRL_TABLAYOUT) return static_cast(this); 14 | return CContainerUI::GetInterface (pstrName); 15 | } 16 | 17 | bool CTabLayoutUI::Add (CControlUI* pControl) { 18 | bool ret = CContainerUI::Add (pControl); 19 | if (!ret) return ret; 20 | 21 | if (m_iCurSel == -1 && pControl->IsVisible ()) { 22 | m_iCurSel = GetItemIndex (pControl); 23 | } else { 24 | pControl->SetVisible (false); 25 | } 26 | 27 | return ret; 28 | } 29 | 30 | bool CTabLayoutUI::AddAt (CControlUI* pControl, int iIndex) { 31 | bool ret = CContainerUI::AddAt (pControl, iIndex); 32 | if (!ret) return ret; 33 | 34 | if (m_iCurSel == -1 && pControl->IsVisible ()) { 35 | m_iCurSel = GetItemIndex (pControl); 36 | } else if (m_iCurSel != -1 && iIndex <= m_iCurSel) { 37 | m_iCurSel += 1; 38 | } else { 39 | pControl->SetVisible (false); 40 | } 41 | 42 | return ret; 43 | } 44 | 45 | bool CTabLayoutUI::Remove (CControlUI* pControl) { 46 | if (!pControl) return false; 47 | 48 | int index = GetItemIndex (pControl); 49 | bool ret = CContainerUI::Remove (pControl); 50 | if (!ret) return false; 51 | 52 | if (m_iCurSel == index) { 53 | if (GetCount () > 0) { 54 | m_iCurSel = 0; 55 | GetItemAt (m_iCurSel)->SetVisible (true); 56 | } else 57 | m_iCurSel = -1; 58 | NeedParentUpdate (); 59 | } else if (m_iCurSel > index) { 60 | m_iCurSel -= 1; 61 | } 62 | 63 | return ret; 64 | } 65 | 66 | void CTabLayoutUI::RemoveAll () { 67 | m_iCurSel = -1; 68 | CContainerUI::RemoveAll (); 69 | NeedParentUpdate (); 70 | } 71 | 72 | int CTabLayoutUI::GetCurSel () const { 73 | return m_iCurSel; 74 | } 75 | 76 | bool CTabLayoutUI::SelectItem (int iIndex) { 77 | if (iIndex < 0 || iIndex >= m_items.GetSize ()) return false; 78 | if (iIndex == m_iCurSel) return true; 79 | 80 | int iOldSel = m_iCurSel; 81 | m_iCurSel = iIndex; 82 | for (int it = 0; it < m_items.GetSize (); it++) { 83 | if (it == iIndex) { 84 | GetItemAt (it)->SetVisible (true); 85 | GetItemAt (it)->SetFocus (); 86 | SetPos (m_rcItem); 87 | } else GetItemAt (it)->SetVisible (false); 88 | } 89 | NeedParentUpdate (); 90 | 91 | if (m_pManager) { 92 | m_pManager->SetNextTabControl (); 93 | m_pManager->SendNotify (this, DUI_MSGTYPE_TABSELECT, m_iCurSel, iOldSel); 94 | } 95 | return true; 96 | } 97 | 98 | bool CTabLayoutUI::SelectItem (CControlUI* pControl) { 99 | int iIndex = GetItemIndex (pControl); 100 | if (iIndex == -1) 101 | return false; 102 | else 103 | return SelectItem (iIndex); 104 | } 105 | 106 | void CTabLayoutUI::SetAttribute (faw::string_t pstrName, faw::string_t pstrValue) { 107 | if (pstrName == _T ("selectedid")) SelectItem (FawTools::parse_dec (pstrValue)); 108 | return CContainerUI::SetAttribute (pstrName, pstrValue); 109 | } 110 | 111 | void CTabLayoutUI::SetPos (RECT rc, bool bNeedInvalidate) { 112 | CControlUI::SetPos (rc, bNeedInvalidate); 113 | rc = m_rcItem; 114 | 115 | // Adjust for inset 116 | rc.left += m_rcInset.left; 117 | rc.top += m_rcInset.top; 118 | rc.right -= m_rcInset.right; 119 | rc.bottom -= m_rcInset.bottom; 120 | 121 | for (int it = 0; it < m_items.GetSize (); it++) { 122 | CControlUI* pControl = static_cast(m_items[it]); 123 | if (!pControl->IsVisible ()) continue; 124 | if (pControl->IsFloat ()) { 125 | SetFloatPos (it); 126 | continue; 127 | } 128 | 129 | if (it != m_iCurSel) continue; 130 | 131 | RECT rcPadding = pControl->GetPadding (); 132 | rc.left += rcPadding.left; 133 | rc.top += rcPadding.top; 134 | rc.right -= rcPadding.right; 135 | rc.bottom -= rcPadding.bottom; 136 | 137 | SIZE szAvailable = { rc.right - rc.left, rc.bottom - rc.top }; 138 | 139 | SIZE sz = pControl->EstimateSize (szAvailable); 140 | if (sz.cx == 0) { 141 | sz.cx = MAX (0, szAvailable.cx); 142 | } 143 | if (sz.cx < pControl->GetMinWidth ()) sz.cx = pControl->GetMinWidth (); 144 | if (sz.cx > pControl->GetMaxWidth ()) sz.cx = pControl->GetMaxWidth (); 145 | 146 | if (sz.cy == 0) { 147 | sz.cy = MAX (0, szAvailable.cy); 148 | } 149 | if (sz.cy < pControl->GetMinHeight ()) sz.cy = pControl->GetMinHeight (); 150 | if (sz.cy > pControl->GetMaxHeight ()) sz.cy = pControl->GetMaxHeight (); 151 | 152 | RECT rcCtrl = { rc.left, rc.top, rc.left + sz.cx, rc.top + sz.cy }; 153 | pControl->SetPos (rcCtrl); 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /DuiLib/Layout/UITabLayout.h: -------------------------------------------------------------------------------- 1 | #ifndef __UITABLAYOUT_H__ 2 | #define __UITABLAYOUT_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CTabLayoutUI: public CContainerUI { 8 | DECLARE_DUICONTROL (CTabLayoutUI) 9 | public: 10 | CTabLayoutUI (); 11 | 12 | faw::string_t GetClass () const; 13 | LPVOID GetInterface (faw::string_t pstrName); 14 | 15 | bool Add (CControlUI* pControl); 16 | bool AddAt (CControlUI* pControl, int iIndex); 17 | bool Remove (CControlUI* pControl); 18 | void RemoveAll (); 19 | int GetCurSel () const; 20 | virtual bool SelectItem (int iIndex); 21 | virtual bool SelectItem (CControlUI* pControl); 22 | 23 | void SetPos (RECT rc, bool bNeedInvalidate = true); 24 | 25 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 26 | 27 | protected: 28 | int m_iCurSel = -1; 29 | }; 30 | } 31 | #endif // __UITABLAYOUT_H__ 32 | -------------------------------------------------------------------------------- /DuiLib/Layout/UITileLayout.h: -------------------------------------------------------------------------------- 1 | #ifndef __UITILELAYOUT_H__ 2 | #define __UITILELAYOUT_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CTileLayoutUI: public CContainerUI { 8 | DECLARE_DUICONTROL (CTileLayoutUI) 9 | public: 10 | CTileLayoutUI (); 11 | 12 | faw::string_t GetClass () const; 13 | LPVOID GetInterface (faw::string_t pstrName); 14 | 15 | void SetPos (RECT rc, bool bNeedInvalidate = true); 16 | 17 | SIZE GetItemSize () const; 18 | void SetItemSize (SIZE szItem); 19 | int GetColumns () const; 20 | void SetColumns (int nCols); 21 | 22 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 23 | 24 | protected: 25 | SIZE m_szItem = { 0 }; 26 | int m_nColumns = 1; 27 | }; 28 | } 29 | #endif // __UITILELAYOUT_H__ 30 | -------------------------------------------------------------------------------- /DuiLib/Layout/UIVerticalLayout.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIVERTICALLAYOUT_H__ 2 | #define __UIVERTICALLAYOUT_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | class UILIB_API CVerticalLayoutUI: public CContainerUI { 8 | DECLARE_DUICONTROL (CVerticalLayoutUI) 9 | public: 10 | CVerticalLayoutUI (); 11 | 12 | faw::string_t GetClass () const; 13 | LPVOID GetInterface (faw::string_t pstrName); 14 | UINT GetControlFlags () const; 15 | 16 | void SetSepHeight (int iHeight); 17 | int GetSepHeight () const; 18 | void SetSepImmMode (bool bImmediately); 19 | bool IsSepImmMode () const; 20 | void SetAutoCalcHeight (bool autoCalcHeight); 21 | bool IsAutoCalcHeight () const; 22 | void SetAttribute (faw::string_t pstrName, faw::string_t pstrValue); 23 | void DoEvent (TEventUI& event); 24 | 25 | SIZE EstimateSize (SIZE szAvailable) override; 26 | void SetPos (RECT rc, bool bNeedInvalidate = true); 27 | void DoPostPaint (HDC hDC, const RECT& rcPaint); 28 | bool IsDynamic (POINT &pt) const override; 29 | 30 | RECT GetThumbRect (bool bUseNew = false) const; 31 | 32 | protected: 33 | int m_iSepHeight = 0; 34 | UINT m_uButtonState = 0; 35 | POINT ptLastMouse = { 0 }; 36 | RECT m_rcNewPos = { 0, 0, 0, 0 }; 37 | bool m_bImmMode = false; 38 | bool m_autoCalcHeight = false; 39 | }; 40 | } 41 | #endif // __UIVERTICALLAYOUT_H__ 42 | -------------------------------------------------------------------------------- /DuiLib/StdAfx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // UIlib.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "StdAfx.h" 6 | 7 | #pragma comment( lib, "winmm.lib" ) 8 | #pragma comment( lib, "comctl32.lib" ) -------------------------------------------------------------------------------- /DuiLib/StdAfx.h: -------------------------------------------------------------------------------- 1 | #ifndef __DUILIB_FAW__STDAFX_H__ 2 | #define __DUILIB_FAW__STDAFX_H__ 3 | 4 | 5 | 6 | #pragma warning (disable: 4251) 7 | 8 | #define _CRT_SECURE_NO_WARNINGS 9 | 10 | #ifdef __GNUC__ 11 | // 怎么都没找到min,max的头文件-_- 12 | #ifndef min 13 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 14 | #endif 15 | #ifndef max 16 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 17 | #endif 18 | #endif 19 | 20 | #ifndef __FILET__ 21 | #include 22 | #define __FILET__ _T (__FILE__) 23 | #define __FUNCTIONT__ _T (__FUNCTION__) 24 | #endif 25 | 26 | #include "UIlib.h" 27 | #include 28 | 29 | #define lengthof(x) (sizeof(x)/sizeof(*x)) 30 | #define MAX max 31 | #define MIN min 32 | #define CLAMP(x,a,b) (MIN(b,MAX(a,x))) 33 | 34 | #include 35 | 36 | #include "Utils/FawTools.hpp" 37 | #include 38 | 39 | 40 | 41 | #endif //__DUILIB_FAW__STDAFX_H__ 42 | -------------------------------------------------------------------------------- /DuiLib/UIlib.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010-2011, duilib develop team(www.duilib.com). 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or 5 | // without modification, are permitted provided that the 6 | // following conditions are met. 7 | // 8 | // Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // 11 | // Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following 13 | // disclaimer in the documentation and/or other materials 14 | // provided with the distribution. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 17 | // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 18 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // 31 | // DirectUI - UI Library 32 | // 33 | // Written by Bjarke Viksoe (bjarke@viksoe.dk) 34 | // Copyright (c) 2006-2007 Bjarke Viksoe. 35 | // 36 | // This code may be used in compiled form in any way you desire. These 37 | // source files may be redistributed by any means PROVIDING it is 38 | // not sold for profit without the authors written consent, and 39 | // providing that this notice and the authors name is included. 40 | // 41 | // This file is provided "as is" with no expressed or implied warranty. 42 | // The author accepts no liability if it causes any damage to you or your 43 | // computer whatsoever. It's free, so don't hassle me about it. 44 | // 45 | // Beware of bugs. 46 | // 47 | // 48 | 49 | 50 | #include "StdAfx.h" 51 | #include "UIlib.h" 52 | 53 | BOOL APIENTRY DllMain (HANDLE hModule, DWORD dwReason, LPVOID /*lpReserved*/) { 54 | switch (dwReason) { 55 | case DLL_PROCESS_ATTACH: 56 | case DLL_THREAD_ATTACH: 57 | case DLL_THREAD_DETACH: 58 | case DLL_PROCESS_DETACH: 59 | ::DisableThreadLibraryCalls ((HMODULE) hModule); 60 | break; 61 | } 62 | return TRUE; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /DuiLib/UIlib.h: -------------------------------------------------------------------------------- 1 | #ifdef UILIB_STATIC 2 | #define UILIB_API 3 | #else 4 | #if defined(UILIB_EXPORTS) 5 | # if defined(_MSC_VER) 6 | # define UILIB_API __declspec(dllexport) 7 | # else 8 | # define UILIB_API 9 | # endif 10 | #else 11 | # if defined(_MSC_VER) 12 | # define UILIB_API __declspec(dllimport) 13 | # else 14 | # define UILIB_API 15 | # endif 16 | #endif 17 | #endif 18 | #define UILIB_COMDAT __declspec(selectany) 19 | 20 | #if defined _M_IX86 21 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 22 | #elif defined _M_IA64 23 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") 24 | #elif defined _M_X64 25 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 26 | #else 27 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 28 | #endif 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | #pragma warning (disable : 4100) 52 | #pragma warning (disable : 4244) 53 | #pragma warning (disable : 4302) 54 | #pragma warning (disable : 4311) 55 | #pragma warning (disable : 4312) 56 | #pragma warning (disable : 4505) 57 | 58 | //#define USE_XIMAGE_EFFECT 59 | 60 | #ifndef _FAW_STRING_TYPE 61 | #define _FAW_STRING_TYPE 62 | namespace faw { 63 | #ifdef UNICODE 64 | typedef std::wstring string_t; 65 | #else 66 | typedef std::string string_t; 67 | #endif 68 | } 69 | 70 | #define _USE_STRING_VIEW 71 | #ifdef _USE_STRING_VIEW 72 | #include 73 | namespace faw { 74 | #ifdef UNICODE 75 | typedef std::wstring_view string_view_t; 76 | #else 77 | typedef std::string_view string_view_t; 78 | #endif 79 | } 80 | #else //_USE_STRING_VIEW 81 | namespace std { 82 | typedef string string_view; 83 | typedef wstring wstring_view; 84 | } 85 | namespace faw { 86 | typedef string_t string_view_t; 87 | } 88 | #endif //_USE_STRING_VIEW 89 | #endif 90 | 91 | #include "Utils/Utils.h" 92 | #include "Utils/unzip.h" 93 | #include "Utils/VersionHelpers.h" 94 | #include "Core/UIMarkup.h" 95 | #include "Utils/observer_impl_base.h" 96 | #include "Utils/UIShadow.h" 97 | #include "Utils/UIDelegate.h" 98 | #include "Utils/DragDropImpl.h" 99 | #include "Utils/TrayIcon.h" 100 | #include "Utils/DPI.h" 101 | 102 | #include "Core/UIDefine.h" 103 | #include "Core/UIResourceManager.h" 104 | #include "Core/UIManager.h" 105 | #include "Core/UIBase.h" 106 | #include "Core/ControlFactory.h" 107 | #include "Core/UIControl.h" 108 | #include "Core/UIContainer.h" 109 | 110 | #include "Core/UIDlgBuilder.h" 111 | #include "Core/UIRender.h" 112 | #include "Utils/WinImplBase.h" 113 | 114 | #include "Layout/UIVerticalLayout.h" 115 | #include "Layout/UIHorizontalLayout.h" 116 | #include "Layout/UITileLayout.h" 117 | #include "Layout/UITabLayout.h" 118 | #include "Layout/UIChildLayout.h" 119 | 120 | #include "Control/UIList.h" 121 | #include "Control/UICombo.h" 122 | #include "Control/UIScrollBar.h" 123 | #include "Control/UITreeView.h" 124 | 125 | #include "Control/UILabel.h" 126 | #include "Control/UIText.h" 127 | #include "Control/UIEdit.h" 128 | #include "Control/UIGifAnim.h" 129 | #include "Control/UIGifAnimEx.h" 130 | 131 | #include "Control/UIAnimation.h" 132 | #include "Layout/UIAnimationTabLayout.h" 133 | #include "Control/UIButton.h" 134 | #include "Control/UIOption.h" 135 | 136 | #include "Control/UIProgress.h" 137 | #include "Control/UISlider.h" 138 | 139 | #include "Control/UIComboBox.h" 140 | #include "Control/UIRichEdit.h" 141 | #include "Control/UIDateTime.h" 142 | #include "Control/UIIPAddress.h" 143 | #include "Control/UIIPAddressEx.h" 144 | 145 | #include "Control/UIActiveX.h" 146 | #include "Control/UIWebBrowser.h" 147 | #include "Control/UIFlash.h" 148 | 149 | #include "Control/UIMenu.h" 150 | #include "Control/UIGroupBox.h" 151 | #include "Control/UIRollText.h" 152 | #include "Control/UIColorPalette.h" 153 | #include "Control/UIListEx.h" 154 | #include "Control/UIHotKey.h" 155 | #include "Control/UIFadeButton.h" 156 | #include "Control/UIRing.h" 157 | 158 | #include "Utils/FawTools.hpp" 159 | #include "Bind/BindBase.h" 160 | #include "Bind/BindCtrls.hpp" 161 | 162 | #pragma comment (lib, "comctl32.lib") 163 | #pragma comment (lib, "GdiPlus.lib") 164 | #pragma comment (lib, "Imm32.lib") 165 | -------------------------------------------------------------------------------- /DuiLib/Utils/DPI.h: -------------------------------------------------------------------------------- 1 | #ifndef __DPI_H__ 2 | #define __DPI_H__ 3 | #pragma once 4 | 5 | #ifndef DPI_ENUMS_DECLARED 6 | 7 | typedef enum PROCESS_DPI_AWARENESS { 8 | PROCESS_DPI_UNAWARE = 0, 9 | PROCESS_SYSTEM_DPI_AWARE = 1, 10 | PROCESS_PER_MONITOR_DPI_AWARE = 2 11 | } PROCESS_DPI_AWARENESS; 12 | 13 | typedef enum MONITOR_DPI_TYPE { 14 | MDT_EFFECTIVE_DPI = 0, 15 | MDT_ANGULAR_DPI = 1, 16 | MDT_RAW_DPI = 2, 17 | MDT_DEFAULT = MDT_EFFECTIVE_DPI 18 | } MONITOR_DPI_TYPE; 19 | 20 | #define DPI_ENUMS_DECLARED 21 | #endif // (DPI_ENUMS_DECLARED) 22 | 23 | namespace DuiLib { 24 | class UILIB_API CDPI { 25 | public: 26 | CDPI (void); 27 | 28 | public: 29 | static int GetMainMonitorDPI (); 30 | static int GetDPIOfMonitor (HMONITOR hMonitor); 31 | static int GetDPIOfMonitorNearestToPoint (POINT pt); 32 | 33 | public: 34 | PROCESS_DPI_AWARENESS GetDPIAwareness (); 35 | BOOL SetDPIAwareness (PROCESS_DPI_AWARENESS Awareness); 36 | UINT GetDPI (); 37 | UINT GetScale (); 38 | void SetScale (UINT uDPI); 39 | RECT Scale (RECT rcRect); 40 | void Scale (RECT *pRect); 41 | POINT Scale (POINT ptPoint); 42 | void Scale (POINT *pPoint); 43 | SIZE Scale (SIZE szSize); 44 | void Scale (SIZE *pSize); 45 | int Scale (int iValue); 46 | 47 | int ScaleBack (int iValue); 48 | void ScaleBack (RECT *pRect); 49 | 50 | private: 51 | int m_nScaleFactor; 52 | int m_nScaleFactorSDA; 53 | PROCESS_DPI_AWARENESS m_Awareness; 54 | }; 55 | } 56 | #endif //__DPI_H__ -------------------------------------------------------------------------------- /DuiLib/Utils/Flash11.tlb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fawdlstty/DuiLib_Faw/8c86a5f389e444c1b45cb91418c07a72248236d2/DuiLib/Utils/Flash11.tlb -------------------------------------------------------------------------------- /DuiLib/Utils/FlashEventHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | 创建日期: 2012/11/05 15:09:48 3 | 作者: daviyang35@gmail.com 4 | 描述: FlashEventHandler 5 | */ 6 | #pragma once 7 | //#include 8 | 9 | namespace DuiLib { 10 | class CFlashEventHandler { 11 | public: 12 | CFlashEventHandler () {} 13 | virtual ~CFlashEventHandler () {} 14 | 15 | virtual ULONG STDMETHODCALLTYPE Release (void) { 16 | return S_OK; 17 | } 18 | virtual ULONG STDMETHODCALLTYPE AddRef (void) { 19 | return S_OK; 20 | } 21 | 22 | virtual HRESULT OnReadyStateChange (long newState) { 23 | return S_OK; 24 | } 25 | 26 | virtual HRESULT OnProgress (long percentDone) { 27 | return S_OK; 28 | } 29 | 30 | virtual HRESULT FSCommand (LPCTSTR command, LPCTSTR args) { 31 | return S_OK; 32 | } 33 | 34 | virtual HRESULT FlashCall (LPCTSTR request) { 35 | return S_OK; 36 | } 37 | }; 38 | } -------------------------------------------------------------------------------- /DuiLib/Utils/StdAfx.h: -------------------------------------------------------------------------------- 1 | #include "../StdAfx.h" -------------------------------------------------------------------------------- /DuiLib/Utils/TrayIcon.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "TrayIcon.h" 3 | 4 | namespace DuiLib { 5 | CTrayIcon::CTrayIcon (void): m_uMessage (UIMSG_TRAYICON) {} 6 | 7 | CTrayIcon::~CTrayIcon (void) { 8 | DeleteTrayIcon (); 9 | } 10 | 11 | void CTrayIcon::CreateTrayIcon (HWND _RecvHwnd, UINT _IconIDResource, faw::string_t _ToolTipText, UINT _Message) { 12 | if (!_RecvHwnd || _IconIDResource <= 0) { 13 | return; 14 | } 15 | if (_Message != 0) m_uMessage = _Message; 16 | m_hIcon = LoadIcon (CPaintManagerUI::GetInstance (), MAKEINTRESOURCE (_IconIDResource)); 17 | m_trayData.cbSize = sizeof (NOTIFYICONDATA); 18 | m_trayData.hWnd = _RecvHwnd; 19 | m_trayData.uID = _IconIDResource; 20 | m_trayData.hIcon = m_hIcon; 21 | m_trayData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; 22 | m_trayData.uCallbackMessage = m_uMessage; 23 | if (!_ToolTipText.empty ()) _tcscpy (m_trayData.szTip, _ToolTipText.data ()); 24 | Shell_NotifyIcon (NIM_ADD, &m_trayData); 25 | m_bEnabled = true; 26 | } 27 | 28 | void CTrayIcon::DeleteTrayIcon () { 29 | Shell_NotifyIcon (NIM_DELETE, &m_trayData); 30 | m_bEnabled = false; 31 | m_bVisible = false; 32 | m_hWnd = nullptr; 33 | m_uMessage = UIMSG_TRAYICON; 34 | } 35 | 36 | bool CTrayIcon::SetTooltipText (faw::string_t _ToolTipText) { 37 | if (!_ToolTipText.empty ()) _tcscpy (m_trayData.szTip, _ToolTipText.data ()); 38 | if (!m_bEnabled) return FALSE; 39 | m_trayData.uFlags = NIF_TIP; 40 | return Shell_NotifyIcon (NIM_MODIFY, &m_trayData) == TRUE; 41 | } 42 | 43 | bool CTrayIcon::SetTooltipText (UINT _IDResource) { 44 | TCHAR mbuf[256] = { 0 }; 45 | LoadString (CPaintManagerUI::GetInstance (), _IDResource, mbuf, 256); 46 | return SetTooltipText (mbuf); 47 | } 48 | 49 | faw::string_t CTrayIcon::GetTooltipText () const { 50 | return m_trayData.szTip; 51 | } 52 | 53 | bool CTrayIcon::SetIcon (HICON _Hicon) { 54 | if (_Hicon) m_hIcon = _Hicon; 55 | m_trayData.uFlags = NIF_ICON; 56 | m_trayData.hIcon = _Hicon; 57 | 58 | if (!m_bEnabled) return FALSE; 59 | return Shell_NotifyIcon (NIM_MODIFY, &m_trayData) == TRUE; 60 | 61 | return false; 62 | } 63 | 64 | bool CTrayIcon::SetIcon (faw::string_t _IconFile) { 65 | HICON hIcon = LoadIcon (CPaintManagerUI::GetInstance (), _IconFile.data ()); 66 | return SetIcon (hIcon); 67 | } 68 | 69 | bool CTrayIcon::SetIcon (UINT _IDResource) { 70 | HICON hIcon = LoadIcon (CPaintManagerUI::GetInstance (), MAKEINTRESOURCE (_IDResource)); 71 | return SetIcon (hIcon); 72 | } 73 | 74 | HICON CTrayIcon::GetIcon () const { 75 | HICON hIcon = nullptr; 76 | hIcon = m_trayData.hIcon; 77 | return hIcon; 78 | } 79 | 80 | void CTrayIcon::SetHideIcon () { 81 | if (IsVisible ()) { 82 | SetIcon ((HICON)nullptr); 83 | m_bVisible = TRUE; 84 | } 85 | } 86 | 87 | void CTrayIcon::SetShowIcon () { 88 | if (!IsVisible ()) { 89 | SetIcon (m_hIcon); 90 | m_bVisible = FALSE; 91 | } 92 | } 93 | 94 | void CTrayIcon::RemoveIcon () { 95 | m_trayData.uFlags = 0; 96 | Shell_NotifyIcon (NIM_DELETE, &m_trayData); 97 | m_bEnabled = FALSE; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /DuiLib/Utils/TrayIcon.h: -------------------------------------------------------------------------------- 1 | #ifndef __UITRAICON_H__ 2 | #define __UITRAICON_H__ 3 | 4 | #pragma once 5 | #include 6 | 7 | namespace DuiLib { 8 | class UILIB_API CTrayIcon { 9 | public: 10 | CTrayIcon (void); 11 | virtual ~CTrayIcon (void); 12 | 13 | public: 14 | void CreateTrayIcon (HWND _RecvHwnd, UINT _IconIDResource, faw::string_t _ToolTipText = _T (""), UINT _Message = 0); 15 | void DeleteTrayIcon (); 16 | bool SetTooltipText (faw::string_t _ToolTipText); 17 | bool SetTooltipText (UINT _IDResource); 18 | faw::string_t GetTooltipText () const; 19 | 20 | bool SetIcon (HICON _Hicon); 21 | bool SetIcon (faw::string_t _IconFile); 22 | bool SetIcon (UINT _IDResource); 23 | HICON GetIcon () const; 24 | void SetHideIcon (); 25 | void SetShowIcon (); 26 | void RemoveIcon (); 27 | bool Enabled () { 28 | return m_bEnabled; 29 | }; 30 | bool IsVisible () { 31 | return !m_bVisible; 32 | }; 33 | 34 | private: 35 | bool m_bEnabled = false; 36 | bool m_bVisible = false; 37 | HWND m_hWnd = NULL; 38 | UINT m_uMessage; 39 | HICON m_hIcon = NULL; 40 | NOTIFYICONDATA m_trayData = { 0 }; 41 | }; 42 | } 43 | #endif // 44 | 45 | -------------------------------------------------------------------------------- /DuiLib/Utils/UIDelegate.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | 3 | namespace DuiLib { 4 | 5 | CDelegateBase::CDelegateBase (void* pObject, void* pFn) { 6 | m_pObject = pObject; 7 | m_pFn = pFn; 8 | } 9 | 10 | CDelegateBase::CDelegateBase (const CDelegateBase& rhs) { 11 | m_pObject = rhs.m_pObject; 12 | m_pFn = rhs.m_pFn; 13 | } 14 | 15 | CDelegateBase::~CDelegateBase () { 16 | 17 | } 18 | 19 | bool CDelegateBase::Equals (const CDelegateBase& rhs) const { 20 | return m_pObject == rhs.m_pObject && m_pFn == rhs.m_pFn; 21 | } 22 | 23 | bool CDelegateBase::operator() (void* param) { 24 | return Invoke (param); 25 | } 26 | 27 | void* CDelegateBase::GetFn () { 28 | return m_pFn; 29 | } 30 | 31 | void* CDelegateBase::GetObject () { 32 | return m_pObject; 33 | } 34 | 35 | CEventSource::~CEventSource () { 36 | for (int i = 0; i < m_aDelegates.GetSize (); i++) { 37 | CDelegateBase* pObject = static_cast(m_aDelegates[i]); 38 | if (pObject) delete pObject; 39 | } 40 | } 41 | 42 | CEventSource::operator bool () { 43 | return m_aDelegates.GetSize () > 0; 44 | } 45 | 46 | void CEventSource::operator+= (const CDelegateBase& d) { 47 | for (int i = 0; i < m_aDelegates.GetSize (); i++) { 48 | CDelegateBase* pObject = static_cast(m_aDelegates[i]); 49 | if (pObject && pObject->Equals (d)) return; 50 | } 51 | 52 | m_aDelegates.Add (d.Copy ()); 53 | } 54 | 55 | void CEventSource::operator+= (FnType pFn) { 56 | (*this) += MakeDelegate (pFn); 57 | } 58 | 59 | void CEventSource::operator-= (const CDelegateBase& d) { 60 | for (int i = 0; i < m_aDelegates.GetSize (); i++) { 61 | CDelegateBase* pObject = static_cast(m_aDelegates[i]); 62 | if (pObject && pObject->Equals (d)) { 63 | delete pObject; 64 | m_aDelegates.Remove (i); 65 | return; 66 | } 67 | } 68 | } 69 | void CEventSource::operator-= (FnType pFn) { 70 | (*this) -= MakeDelegate (pFn); 71 | } 72 | 73 | bool CEventSource::operator() (void* param) { 74 | for (int i = 0; i < m_aDelegates.GetSize (); i++) { 75 | CDelegateBase* pObject = static_cast(m_aDelegates[i]); 76 | if (pObject && !(*pObject)(param)) return false; 77 | } 78 | return true; 79 | } 80 | void CEventSource::Clear () { 81 | for (int i = 0; i < m_aDelegates.GetSize (); i++) { 82 | CDelegateBase* pObject = static_cast(m_aDelegates[i]); 83 | if (pObject) delete pObject; 84 | } 85 | m_aDelegates.Empty (); 86 | } 87 | } // namespace DuiLib 88 | -------------------------------------------------------------------------------- /DuiLib/Utils/UIDelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef __UIDELEGATE_H__ 2 | #define __UIDELEGATE_H__ 3 | 4 | #pragma once 5 | 6 | namespace DuiLib { 7 | 8 | class UILIB_API CDelegateBase { 9 | public: 10 | CDelegateBase (void* pObject, void* pFn); 11 | CDelegateBase (const CDelegateBase& rhs); 12 | virtual ~CDelegateBase (); 13 | bool Equals (const CDelegateBase& rhs) const; 14 | bool operator() (void* param); 15 | virtual CDelegateBase* Copy () const = 0; // add const for gcc 16 | 17 | protected: 18 | void* GetFn (); 19 | void* GetObject (); 20 | virtual bool Invoke (void* param) = 0; 21 | 22 | private: 23 | void* m_pObject; 24 | void* m_pFn; 25 | }; 26 | 27 | class CDelegateStatic: public CDelegateBase { 28 | typedef bool (*Fn)(void*); 29 | public: 30 | CDelegateStatic (Fn pFn): CDelegateBase (nullptr, pFn) {} 31 | CDelegateStatic (const CDelegateStatic& rhs): CDelegateBase (rhs) {} 32 | virtual CDelegateBase* Copy () const { 33 | return new CDelegateStatic (*this); 34 | } 35 | 36 | protected: 37 | virtual bool Invoke (void* param) { 38 | Fn pFn = (Fn) GetFn (); 39 | return (*pFn)(param); 40 | } 41 | }; 42 | 43 | template 44 | class CDelegate: public CDelegateBase { 45 | typedef bool (T::* Fn)(void*); 46 | public: 47 | CDelegate (O* pObj, Fn pFn): CDelegateBase (pObj, &pFn), m_pFn (pFn) {} 48 | CDelegate (const CDelegate& rhs): CDelegateBase (rhs) { 49 | m_pFn = rhs.m_pFn; 50 | } 51 | virtual CDelegateBase* Copy () const { 52 | return new CDelegate (*this); 53 | } 54 | 55 | protected: 56 | virtual bool Invoke (void* param) { 57 | O* pObject = (O*) GetObject (); 58 | return (pObject->*m_pFn)(param); 59 | } 60 | 61 | private: 62 | Fn m_pFn; 63 | }; 64 | 65 | template 66 | CDelegate MakeDelegate (O* pObject, bool (T::* pFn)(void*)) { 67 | return CDelegate (pObject, pFn); 68 | } 69 | 70 | inline CDelegateStatic MakeDelegate (bool (*pFn)(void*)) { 71 | return CDelegateStatic (pFn); 72 | } 73 | 74 | class UILIB_API CEventSource { 75 | typedef bool (*FnType)(void*); 76 | public: 77 | ~CEventSource (); 78 | operator bool (); 79 | void operator+= (const CDelegateBase& d); // add const for gcc 80 | void operator+= (FnType pFn); 81 | void operator-= (const CDelegateBase& d); 82 | void operator-= (FnType pFn); 83 | bool operator() (void* param); 84 | void Clear (); 85 | 86 | protected: 87 | CStdPtrArray m_aDelegates; 88 | }; 89 | 90 | } // namespace DuiLib 91 | 92 | #endif // __UIDELEGATE_H__ -------------------------------------------------------------------------------- /DuiLib/Utils/UIShadow.h: -------------------------------------------------------------------------------- 1 | #ifndef __UISHADOW_H__ 2 | #define __UISHADOW_H__ 3 | 4 | #pragma once 5 | #include 6 | 7 | namespace DuiLib { 8 | 9 | class UILIB_API CShadowUI { 10 | public: 11 | friend class CPaintManagerUI; 12 | 13 | CShadowUI (void); 14 | virtual ~CShadowUI (void); 15 | 16 | public: 17 | // bShow为真时才会创建阴影 18 | void ShowShadow (bool bShow); 19 | bool IsShowShadow () const; 20 | 21 | void DisableShadow (bool bDisable); 22 | bool IsDisableShadow () const; 23 | 24 | // 算法阴影的函数 25 | bool SetSize (int NewSize = 0); 26 | bool SetSharpness (unsigned int NewSharpness = 5); 27 | bool SetDarkness (unsigned int NewDarkness = 200); 28 | bool SetPosition (int NewXOffset = 5, int NewYOffset = 5); 29 | bool SetColor (COLORREF NewColor = 0); 30 | 31 | // 图片阴影的函数 32 | bool SetImage (faw::string_t szImage); 33 | bool SetShadowCorner (RECT rcCorner); // 九宫格方式描述阴影 34 | 35 | // 把自己的阴影样式复制到传入参数 36 | bool CopyShadow (CShadowUI* pShadow); 37 | 38 | // 创建阴影窗体,由CPaintManagerUI自动调用,除非自己要单独创建阴影 39 | void Create (CPaintManagerUI* pPaintManager); 40 | protected: 41 | 42 | // 初始化并注册阴影类 43 | static bool Initialize (HINSTANCE hInstance); 44 | 45 | // 保存已经附加的窗体句柄和与其关联的阴影类,方便在ParentProc()函数中通过句柄得到阴影类 46 | static std::map& GetShadowMap (); 47 | 48 | // 子类化父窗体 49 | static LRESULT CALLBACK ParentProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 50 | 51 | // 父窗体改变大小,移动,或者主动重绘阴影时调用 52 | void Update (HWND hParent); 53 | 54 | // 通过算法计算阴影 55 | void MakeShadow (UINT32 *pShadBits, HWND hParent, RECT *rcParent); 56 | 57 | // 计算alpha预乘值 58 | inline DWORD PreMultiply (COLORREF cl, unsigned char nAlpha) { 59 | return (GetRValue (cl) * (DWORD) nAlpha / 255) | 60 | (GetGValue (cl) * (DWORD) nAlpha / 255) << 8 | 61 | (GetBValue (cl) * (DWORD) nAlpha / 255) << 16; 62 | } 63 | 64 | protected: 65 | enum ShadowStatus { 66 | SS_ENABLED = 1, // Shadow is enabled, if not, the following one is always false 67 | SS_VISABLE = 1 << 1, // Shadow window is visible 68 | SS_PARENTVISIBLE = 1 << 2 // Parent window is visible, if not, the above one is always false 69 | }; 70 | 71 | 72 | static bool s_bHasInit; 73 | 74 | CPaintManagerUI *m_pManager; // 父窗体的CPaintManagerUI,用来获取素材资源和父窗体句柄 75 | HWND m_hWnd = NULL; // 阴影窗体的句柄 76 | LONG_PTR m_OriParentProc = NULL; // 子类化父窗体 77 | BYTE m_Status = 0; 78 | bool m_bIsImageMode = false; // 是否为图片阴影模式 79 | bool m_bIsShowShadow = false; // 是否要显示阴影 80 | bool m_bIsDisableShadow = false; 81 | // 算法阴影成员变量 82 | unsigned char m_nDarkness = 150; // Darkness, transparency of blurred area 83 | unsigned char m_nSharpness = 5; // Sharpness, width of blurred border of shadow window 84 | signed char m_nSize = 0; // Shadow window size, relative to parent window size 85 | 86 | // The X and Y offsets of shadow window, 87 | // relative to the parent window, at center of both windows (not top-left corner), signed 88 | signed char m_nxOffset = 0; 89 | signed char m_nyOffset = 0; 90 | 91 | // Restore last parent window size, used to determine the update strategy when parent window is resized 92 | LPARAM m_WndSize = 0; 93 | 94 | // Set this to true if the shadow should not be update until next WM_PAINT is received 95 | bool m_bUpdate = false; 96 | 97 | COLORREF m_Color = RGB (0, 0, 0); // Color of shadow 98 | 99 | // 图片阴影成员变量 100 | faw::string_t m_sShadowImage; 101 | RECT m_rcShadowCorner = { 0 }; 102 | }; 103 | 104 | } 105 | 106 | #endif //__UISHADOW_H__ -------------------------------------------------------------------------------- /DuiLib/Utils/Utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTILS_H__ 2 | #define __UTILS_H__ 3 | 4 | #pragma once 5 | #include "OAIdl.h" 6 | #include 7 | 8 | namespace DuiLib { 9 | class UILIB_API CStdPtrArray { 10 | public: 11 | CStdPtrArray (int iPreallocSize = 0); 12 | CStdPtrArray (const CStdPtrArray& src); 13 | virtual ~CStdPtrArray (); 14 | 15 | void Empty (); 16 | void Resize (int iSize); 17 | bool empty () const; 18 | int Find (LPVOID iIndex) const; 19 | bool Add (LPVOID pData); 20 | bool SetAt (int iIndex, LPVOID pData); 21 | bool InsertAt (int iIndex, LPVOID pData); 22 | bool Remove (int iIndex); 23 | int GetSize () const; 24 | LPVOID* GetData (); 25 | 26 | LPVOID GetAt (int iIndex) const; 27 | LPVOID operator[] (int nIndex) const; 28 | 29 | protected: 30 | LPVOID* m_ppVoid; 31 | int m_nCount; 32 | int m_nAllocated; 33 | }; 34 | 35 | 36 | ///////////////////////////////////////////////////////////////////////////////////// 37 | // 38 | 39 | class UILIB_API CStdValArray { 40 | public: 41 | CStdValArray (int iElementSize, int iPreallocSize = 0); 42 | virtual ~CStdValArray (); 43 | 44 | void Empty (); 45 | bool empty () const; 46 | bool Add (LPCVOID pData); 47 | bool Remove (int iIndex); 48 | int GetSize () const; 49 | LPVOID GetData (); 50 | 51 | LPVOID GetAt (int iIndex) const; 52 | LPVOID operator[] (int nIndex) const; 53 | 54 | protected: 55 | LPBYTE m_pVoid; 56 | int m_iElementSize; 57 | int m_nCount; 58 | int m_nAllocated; 59 | }; 60 | 61 | ///////////////////////////////////////////////////////////////////////////////////// 62 | // 63 | 64 | struct TITEM { 65 | faw::string_t Key; 66 | LPVOID Data; 67 | struct TITEM* pPrev; 68 | struct TITEM* pNext; 69 | }; 70 | 71 | class UILIB_API CStdStringPtrMap { 72 | public: 73 | CStdStringPtrMap (int nSize = 83); 74 | virtual ~CStdStringPtrMap (); 75 | 76 | void Resize (int nSize = 83); 77 | LPVOID Find (faw::string_t key, bool optimize = true) const; 78 | bool Insert (faw::string_t key, LPVOID pData); 79 | LPVOID Set (faw::string_t key, LPVOID pData); 80 | bool Remove (faw::string_t key); 81 | void RemoveAll (); 82 | int GetSize () const; 83 | TITEM *GetAt (int iIndex) const; 84 | TITEM *operator[] (int nIndex) const; 85 | 86 | protected: 87 | TITEM** m_aT; 88 | int m_nBuckets; 89 | int m_nCount; 90 | }; 91 | 92 | ///////////////////////////////////////////////////////////////////////////////////// 93 | // 94 | 95 | class UILIB_API CWaitCursor { 96 | public: 97 | CWaitCursor (); 98 | virtual ~CWaitCursor (); 99 | 100 | protected: 101 | HCURSOR m_hOrigCursor; 102 | }; 103 | 104 | ///////////////////////////////////////////////////////////////////////////////////// 105 | // 106 | 107 | class CDuiVariant: public VARIANT { 108 | public: 109 | CDuiVariant () { 110 | VariantInit (this); 111 | } 112 | CDuiVariant (int i) { 113 | VariantInit (this); 114 | this->vt = VT_I4; 115 | this->intVal = i; 116 | } 117 | CDuiVariant (float f) { 118 | VariantInit (this); 119 | this->vt = VT_R4; 120 | this->fltVal = f; 121 | } 122 | CDuiVariant (LPOLESTR s) { 123 | VariantInit (this); 124 | this->vt = VT_BSTR; 125 | this->bstrVal = s; 126 | } 127 | CDuiVariant (IDispatch *disp) { 128 | VariantInit (this); 129 | this->vt = VT_DISPATCH; 130 | this->pdispVal = disp; 131 | } 132 | 133 | virtual ~CDuiVariant () { 134 | VariantClear (this); 135 | } 136 | }; 137 | 138 | /////////////////////////////////////////////////////////////////////////////////////// 139 | //// 140 | //struct TImageInfo; 141 | //class CPaintManagerUI; 142 | //class UILIB_API CImageString 143 | //{ 144 | //public: 145 | // CImageString(); 146 | // CImageString(const CImageString&); 147 | // const CImageString& operator=(const CImageString&); 148 | // virtual ~CImageString(); 149 | 150 | // const faw::string_t& GetAttributeString() const; 151 | // void SetAttributeString(faw::string_t pStrImageAttri); 152 | // void ModifyAttribute(faw::string_t pStrModify); 153 | // bool LoadImage(CPaintManagerUI* pManager); 154 | // bool IsLoadSuccess(); 155 | 156 | // RECT GetDest() const; 157 | // void SetDest(const RECT &rcDest); 158 | // const TImageInfo* GetImageInfo() const; 159 | 160 | //private: 161 | // void Clone(const CImageString&); 162 | // void Clear(); 163 | // void ParseAttribute(faw::string_t pStrImageAttri); 164 | 165 | //protected: 166 | // friend class CRenderEngine; 167 | // faw::string_t m_sImageAttribute; 168 | 169 | // faw::string_t m_sImage; 170 | // faw::string_t m_sResType; 171 | // TImageInfo *m_imageInfo; 172 | // bool m_bLoadSuccess; 173 | 174 | // RECT m_rcDest; 175 | // RECT m_rcSource; 176 | // RECT m_rcCorner; 177 | // BYTE m_bFade; 178 | // DWORD m_dwMask; 179 | // bool m_bHole; 180 | // bool m_bTiledX; 181 | // bool m_bTiledY; 182 | //}; 183 | }// namespace DuiLib 184 | 185 | #endif // __UTILS_H__ -------------------------------------------------------------------------------- /DuiLib/Utils/VersionHelpers.h: -------------------------------------------------------------------------------- 1 | #ifndef _VERSIONHELPERS_H_INCLUDED_ 2 | #define _VERSIONHELPERS_H_INCLUDED_ 3 | #include 4 | 5 | namespace DuiLib { 6 | #define _WIN32_WINNT_NT4 0x0400 7 | #define _WIN32_WINNT_WIN2K 0x0500 8 | #define _WIN32_WINNT_WINXP 0x0501 9 | #define _WIN32_WINNT_WS03 0x0502 10 | #define _WIN32_WINNT_WIN6 0x0600 11 | #define _WIN32_WINNT_VISTA 0x0600 12 | #define _WIN32_WINNT_WS08 0x0600 13 | #define _WIN32_WINNT_LONGHORN 0x0600 14 | #define _WIN32_WINNT_WIN7 0x0601 15 | #define _WIN32_WINNT_WIN8 0x0602 16 | #define _WIN32_WINNT_WINBLUE 0x0603 17 | #define _WIN32_WINNT_WINTHRESHOLD 0x0A00 /* ABRACADABRA_THRESHOLD*/ 18 | #define _WIN32_WINNT_WIN10 0x0A00 /* ABRACADABRA_THRESHOLD*/ 19 | 20 | #define WM_DPICHANGED 0x02E0 21 | 22 | static BOOL IsWindowsVersionOrGreater (WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor) { 23 | OSVERSIONINFOEXW osvi = { sizeof (osvi), 0, 0, 0, 0, { 0 }, 0, 0 }; 24 | DWORDLONG const dwlConditionMask = VerSetConditionMask (VerSetConditionMask (VerSetConditionMask (0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL), VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); 25 | osvi.dwMajorVersion = wMajorVersion; 26 | osvi.dwMinorVersion = wMinorVersion; 27 | osvi.wServicePackMajor = wServicePackMajor; 28 | return VerifyVersionInfoW (&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE; 29 | } 30 | 31 | static BOOL IsWindowsXPOrGreater () { 32 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_WINXP), LOBYTE (_WIN32_WINNT_WINXP), 0); 33 | } 34 | 35 | static BOOL IsWindowsXPSP1OrGreater () { 36 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_WINXP), LOBYTE (_WIN32_WINNT_WINXP), 1); 37 | } 38 | 39 | static BOOL IsWindowsXPSP2OrGreater () { 40 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_WINXP), LOBYTE (_WIN32_WINNT_WINXP), 2); 41 | } 42 | 43 | static BOOL IsWindowsXPSP3OrGreater () { 44 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_WINXP), LOBYTE (_WIN32_WINNT_WINXP), 3); 45 | } 46 | 47 | static BOOL IsWindowsVistaOrGreater () { 48 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_VISTA), LOBYTE (_WIN32_WINNT_VISTA), 0); 49 | } 50 | 51 | static BOOL IsWindowsVistaSP1OrGreater () { 52 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_VISTA), LOBYTE (_WIN32_WINNT_VISTA), 1); 53 | } 54 | 55 | static BOOL IsWindowsVistaSP2OrGreater () { 56 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_VISTA), LOBYTE (_WIN32_WINNT_VISTA), 2); 57 | } 58 | 59 | static BOOL IsWindows7OrGreater () { 60 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_WIN7), LOBYTE (_WIN32_WINNT_WIN7), 0); 61 | } 62 | 63 | static BOOL IsWindows7SP1OrGreater () { 64 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_WIN7), LOBYTE (_WIN32_WINNT_WIN7), 1); 65 | } 66 | 67 | static BOOL IsWindows8OrGreater () { 68 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_WIN8), LOBYTE (_WIN32_WINNT_WIN8), 0); 69 | } 70 | 71 | static BOOL IsWindows8Point1OrGreater () { 72 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_WINBLUE), LOBYTE (_WIN32_WINNT_WINBLUE), 0); 73 | } 74 | 75 | static BOOL IsWindowsThresholdOrGreater () { 76 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_WINTHRESHOLD), LOBYTE (_WIN32_WINNT_WINTHRESHOLD), 0); 77 | } 78 | 79 | static BOOL IsWindows10OrGreater () { 80 | return IsWindowsVersionOrGreater (HIBYTE (_WIN32_WINNT_WINTHRESHOLD), LOBYTE (_WIN32_WINNT_WINTHRESHOLD), 0); 81 | } 82 | 83 | static BOOL IsWindowsServer () { 84 | OSVERSIONINFOEXW osvi = { sizeof (osvi), 0, 0, 0, 0, { 0 }, 0, 0, 0, VER_NT_WORKSTATION }; 85 | DWORDLONG const dwlConditionMask = VerSetConditionMask (0, VER_PRODUCT_TYPE, VER_EQUAL); 86 | return !VerifyVersionInfoW (&osvi, VER_PRODUCT_TYPE, dwlConditionMask); 87 | } 88 | } 89 | #endif // _VERSIONHELPERS_H_INCLUDED_ 90 | -------------------------------------------------------------------------------- /DuiLib/Utils/WinImplBase.h: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include 3 | 4 | #ifndef WIN_IMPL_BASE_HPP 5 | #define WIN_IMPL_BASE_HPP 6 | 7 | namespace DuiLib { 8 | class UILIB_API WindowImplBase 9 | : public CWindowWnd 10 | , public CNotifyPump 11 | , public INotifyUI 12 | , public IMessageFilterUI 13 | , public IDialogBuilderCallback 14 | , public IQueryControlText { 15 | public: 16 | WindowImplBase () {}; 17 | virtual ~WindowImplBase () {}; 18 | // 只需主窗口重写(初始化资源与多语言接口) 19 | virtual void InitResource () {}; 20 | // 每个窗口都可以重写 21 | virtual void InitWindow () {}; 22 | virtual void OnFinalMessage (HWND hWnd); 23 | virtual void Notify (TNotifyUI& msg); 24 | 25 | DUI_DECLARE_MESSAGE_MAP () 26 | virtual void OnClick (TNotifyUI& msg); 27 | virtual void OnHeaderClick (TNotifyUI& msg) {} 28 | virtual void OnSelectChanged (TNotifyUI& msg) {} 29 | virtual void OnTextChanged (TNotifyUI& msg) {} 30 | virtual void OnItemSelect (TNotifyUI& msg) {} 31 | virtual void OnTimer (TNotifyUI& msg) {} 32 | virtual BOOL IsInStaticControl (CControlUI *pControl, POINT &pt); 33 | 34 | protected: 35 | virtual faw::string_t GetSkinType () { 36 | return _T (""); 37 | } 38 | virtual faw::string_t GetSkinFile () = 0; 39 | virtual LPCTSTR GetWindowClassName (void) const = 0; 40 | virtual faw::string_t GetManagerName () { return _T (""); } 41 | virtual LRESULT ResponseDefaultKeyEvent (WPARAM wParam); 42 | CPaintManagerUI m_pm; 43 | 44 | public: 45 | virtual UINT GetClassStyle () const; 46 | virtual CControlUI* CreateControl (faw::string_t pstrClass); 47 | LRESULT Invoke (std::function f) { return ::SendMessage (m_hWnd, WM_USER + 0x101, 1, (LPARAM) &f); } 48 | void AsyncInvoke (std::function f) { ::PostMessage (m_hWnd, WM_USER + 0x101, 0, (LPARAM) new decltype (f) (f)); } 49 | template 50 | void AsyncInvoke(Func func, Args... args) { 51 | auto boundFunc = std::bind(func, args...); 52 | auto* funcPtr = new std::function(boundFunc); 53 | ::PostMessage(m_hWnd, WM_USER + 0x101, 0, reinterpret_cast(funcPtr)); 54 | } 55 | virtual faw::string_t QueryControlText (faw::string_t lpstrId, faw::string_t lpstrType); 56 | 57 | virtual std::optional MessageHandler (UINT uMsg, WPARAM wParam, LPARAM /*lParam*/); 58 | virtual std::optional OnClose (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 59 | virtual std::optional OnDestroy (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 60 | 61 | #if defined(WIN32) && !defined(UNDER_CE) 62 | virtual std::optional OnNcActivate (UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/); 63 | virtual std::optional OnNcCalcSize (UINT uMsg, WPARAM wParam, LPARAM lParam); 64 | virtual std::optional OnNcPaint (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 65 | virtual std::optional OnNcHitTest (UINT uMsg, WPARAM wParam, LPARAM lParam); 66 | virtual std::optional OnGetMinMaxInfo (UINT uMsg, WPARAM wParam, LPARAM lParam); 67 | virtual std::optional OnMouseWheel (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 68 | virtual std::optional OnMouseHover (UINT uMsg, WPARAM wParam, LPARAM lParam); 69 | #endif 70 | virtual std::optional OnSize (UINT uMsg, WPARAM wParam, LPARAM lParam); 71 | virtual std::optional OnChar (UINT uMsg, WPARAM wParam, LPARAM lParam); 72 | virtual std::optional OnSysCommand (UINT uMsg, WPARAM wParam, LPARAM lParam); 73 | virtual std::optional OnCreate (UINT uMsg, WPARAM wParam, LPARAM lParam); 74 | virtual std::optional OnKeyDown (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 75 | virtual std::optional OnKillFocus (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 76 | virtual std::optional OnSetFocus (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 77 | virtual std::optional OnLButtonDown (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 78 | virtual std::optional OnLButtonUp (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 79 | virtual std::optional OnRButtonDown (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 80 | virtual std::optional OnRButtonUp (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 81 | virtual std::optional OnMouseMove (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/); 82 | virtual LRESULT HandleMessage (UINT uMsg, WPARAM wParam, LPARAM lParam); 83 | virtual std::optional HandleCustomMessage (UINT uMsg, WPARAM wParam, LPARAM lParam); 84 | virtual LONG GetStyle (); 85 | }; 86 | } 87 | 88 | #endif // WIN_IMPL_BASE_HPP 89 | -------------------------------------------------------------------------------- /DuiLib/Utils/observer_impl_base.h: -------------------------------------------------------------------------------- 1 | #ifndef OBSERVER_IMPL_BASE_HPP 2 | #define OBSERVER_IMPL_BASE_HPP 3 | 4 | #include 5 | #include 6 | 7 | template 8 | class ReceiverImplBase; 9 | 10 | template 11 | class ObserverImplBase { 12 | public: 13 | virtual void AddReceiver (ReceiverImplBase* receiver) = 0; 14 | virtual void RemoveReceiver (ReceiverImplBase* receiver) = 0; 15 | virtual ReturnT Broadcast (ParamT param) = 0; 16 | virtual ReturnT Notify (ParamT param) = 0; 17 | }; 18 | 19 | template 20 | class ReceiverImplBase { 21 | public: 22 | virtual void AddObserver (ObserverImplBase* observer) = 0; 23 | virtual void RemoveObserver () = 0; 24 | virtual ReturnT Receive (ParamT param) = 0; 25 | virtual ReturnT Respond (ParamT param, ObserverImplBase* observer) = 0; 26 | }; 27 | 28 | template 29 | class ReceiverImpl; 30 | 31 | template 32 | class ObserverImpl: public ObserverImplBase { 33 | public: 34 | ObserverImpl () 35 | : count_ (0) {} 36 | 37 | virtual ~ObserverImpl () {} 38 | 39 | virtual void AddReceiver (ReceiverImplBase* receiver) { 40 | if (!receiver) 41 | return; 42 | 43 | receivers_[count_] = receiver; 44 | receiver->AddObserver (this); 45 | count_++; 46 | } 47 | 48 | virtual void RemoveReceiver (ReceiverImplBase* receiver) { 49 | if (!receiver) 50 | return; 51 | 52 | for (auto it = receivers_.begin (); it != receivers_.end (); ++it) { 53 | if (it->second == receiver) { 54 | receivers_.erase (it); 55 | break; 56 | } 57 | } 58 | } 59 | 60 | virtual ReturnT Broadcast (ParamT param) { 61 | for (auto it = receivers_.begin (); it != receivers_.end (); ++it) { 62 | it->second->Receive (param); 63 | } 64 | 65 | return ReturnT (); 66 | } 67 | 68 | virtual ReturnT Notify (ParamT param) { 69 | for (auto it = receivers_.begin (); it != receivers_.end (); ++it) { 70 | it->second->Respond (param, this); 71 | } 72 | 73 | return ReturnT (); 74 | } 75 | 76 | protected: 77 | typedef std::map*> ReceiversMap; 78 | ReceiversMap receivers_; 79 | int count_; 80 | }; 81 | 82 | 83 | template 84 | class ReceiverImpl: public ReceiverImplBase { 85 | public: 86 | ReceiverImpl () 87 | : count_ (0) {} 88 | 89 | virtual ~ReceiverImpl () {} 90 | 91 | virtual void AddObserver (ObserverImplBase* observer) { 92 | observers_[count_] = observer; 93 | count_++; 94 | } 95 | 96 | virtual void RemoveObserver () { 97 | for (auto it = observers_.begin (); it != observers_.end (); ++it) { 98 | it->second->RemoveReceiver (this); 99 | } 100 | } 101 | 102 | virtual ReturnT Receive (ParamT param) { 103 | return ReturnT (); 104 | } 105 | 106 | virtual ReturnT Respond (ParamT param, ObserverImplBase* observer) { 107 | return ReturnT (); 108 | } 109 | 110 | protected: 111 | typedef std::map*> ObserversMap; 112 | ObserversMap observers_; 113 | int count_; 114 | }; 115 | 116 | #endif // OBSERVER_IMPL_BASE_HPP -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 fawdlstty 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | 24 | 25 | 26 | 27 | DirectUI - UI Library 28 | 29 | Written by Bjarke Viksoe (bjarke@viksoe.dk) 30 | Copyright (c) 2006-2007 Bjarke Viksoe. 31 | 32 | This code may be used in compiled form in any way you desire. These 33 | source files may be redistributed by any means PROVIDING it is 34 | not sold for profit without the authors written consent, and 35 | providing that this notice and the authors name is included. 36 | 37 | This file is provided "as is" with no expressed or implied warranty. 38 | The author accepts no liability if it causes any damage to you or your 39 | computer whatsoever. It's free, so don't hassle me about it. 40 | Beware of bugs. 41 | 42 | 43 | 44 | 45 | 46 | Copyright (c) 2010-2011, duilib develop team(https://github.com/duilib/duilib). 47 | All rights reserved. 48 | 49 | Redistribution and use in source and binary forms, with or without modification, 50 | are permitted provided that the following conditions are met. 51 | 52 | Redistributions of source code must retain the above copyright notice, 53 | this list of conditions and the following disclaimer. 54 | 55 | Redistributions in binary form must reproduce the above copyright notice, 56 | his list of conditions and the following disclaimer in the documentation 57 | and/or other materials provided with the distribution. 58 | 59 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 60 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 61 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 63 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 64 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 65 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 67 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 68 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 69 | 70 | 71 | 72 | 73 | 74 | MIT License 75 | 76 | Copyright (c) 2014 Troy 77 | 78 | Permission is hereby granted, free of charge, to any person obtaining a copy 79 | of this software and associated documentation files (the "Software"), to deal 80 | in the Software without restriction, including without limitation the rights 81 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 82 | copies of the Software, and to permit persons to whom the Software is 83 | furnished to do so, subject to the following conditions: 84 | 85 | The above copyright notice and this permission notice shall be included in all 86 | copies or substantial portions of the Software. 87 | 88 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 89 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 90 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 91 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 92 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 93 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 94 | SOFTWARE. 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **DuiLib_Faw** 2 | 3 | ## 描述 4 | 5 | 此项目是DuiLib的一个个人维护版本,使用Modern C++重写了整个项目。(至少需C++20支持,但部分代码还未完全使用C++20特性) 6 | 7 | 大众所熟知的DuiLib主分支处于较少更新的状态,几年前的激进更新派DuiLib_Ultimate、DuiLib_Redrain等也渐渐变成了保守派,也降低了更新速度,然而这个优秀的库也渐渐的无法满足当今的需要。 8 | 9 | 此仓库建立的目的是,对DuiLib做出较激进的更新优化,使得它能更好的满足当今开发的需要。 10 | 11 | 此项目的更新方式为,一方面项目自身激进的更新,另一方面原分支仓库有更新时,根据需要将更新内容同步至此仓库。 12 | 13 | 项目使用示例:[易大师网络工具箱](https://github.com/fawdlstty/NetToolbox) 14 | 15 | 此项目目前只支持vs2017环境下编译,如果使用clang、gcc或其他版本编译器需要自行建立项目文件。 16 | 17 | ## 使用 18 | 19 | ### 第一步:链接dll 20 | 21 | #### 动态链接(不推荐) 22 | 23 | 注意:因将CDuiString替换为std::string,动态链接方式编译将会出现严重的编译警告。我最近我正在尝试解决这个问题 24 | 25 | 使用动态链接的程序需在程序目录保留DuiLib*.dll,否则程序无法运行。 26 | 27 | 用法:主程序内引用如下代码 28 | 29 | ```C++ 30 | #if (defined _UNICODE) && (defined _DEBUG) && (defined _WIN64) 31 | # pragma comment (lib, "../lib/DuiLib_64d.lib") 32 | #elif (defined _UNICODE) && (defined _DEBUG) && (!defined _WIN64) 33 | # pragma comment (lib, "../lib/DuiLib_d.lib") 34 | #elif (defined _UNICODE) && (!defined _DEBUG) && (defined _WIN64) 35 | # pragma comment (lib, "../lib/DuiLib_64.lib") 36 | #elif (defined _UNICODE) && (!defined _DEBUG) && (!defined _WIN64) 37 | # pragma comment (lib, "../lib/DuiLib.lib") 38 | #elif (!defined _UNICODE) && (defined _DEBUG) && (defined _WIN64) 39 | # pragma comment (lib, "../lib/DuiLibA_64d.lib") 40 | #elif (!defined _UNICODE) && (defined _DEBUG) && (!defined _WIN64) 41 | # pragma comment (lib, "../lib/DuiLibA_d.lib") 42 | #elif (!defined _UNICODE) && (!defined _DEBUG) && (defined _WIN64) 43 | # pragma comment (lib, "../lib/DuiLibA_64.lib") 44 | #elif (!defined _UNICODE) && (!defined _DEBUG) && (!defined _WIN64) 45 | # pragma comment (lib, "../lib/DuiLibA.lib") 46 | #endif 47 | ``` 48 | 49 | #### 静态链接 50 | 51 | 静态链接具有诸多好处:依赖关系更少、程序体积更小等。极端的追求程序体积可以使用这种链接方式,使用VC_LTL优化项目引用并缩小程序体积,最后使用upx对程序进行压缩。 52 | 53 | 用法:主程序内引用如下代码 54 | 55 | ```C++ 56 | #if (defined _UNICODE) && (defined _DEBUG) && (defined _WIN64) 57 | # pragma comment (lib, "../lib/DuiLib_64sd.lib") 58 | #elif (defined _UNICODE) && (defined _DEBUG) && (!defined _WIN64) 59 | # pragma comment (lib, "../lib/DuiLib_sd.lib") 60 | #elif (defined _UNICODE) && (!defined _DEBUG) && (defined _WIN64) 61 | # pragma comment (lib, "../lib/DuiLib_64s.lib") 62 | #elif (defined _UNICODE) && (!defined _DEBUG) && (!defined _WIN64) 63 | # pragma comment (lib, "../lib/DuiLib_s.lib") 64 | #elif (!defined _UNICODE) && (defined _DEBUG) && (defined _WIN64) 65 | # pragma comment (lib, "../lib/DuiLibA_64sd.lib") 66 | #elif (!defined _UNICODE) && (defined _DEBUG) && (!defined _WIN64) 67 | # pragma comment (lib, "../lib/DuiLibA_sd.lib") 68 | #elif (!defined _UNICODE) && (!defined _DEBUG) && (defined _WIN64) 69 | # pragma comment (lib, "../lib/DuiLibA_64s.lib") 70 | #elif (!defined _UNICODE) && (!defined _DEBUG) && (!defined _WIN64) 71 | # pragma comment (lib, "../lib/DuiLibA_s.lib") 72 | #endif 73 | ``` 74 | 75 | 看需求加入预处理器定义UILIB_STATIC,然后将编译选项分别设置为/MT、/MTd即可。 76 | 77 | ### 第二步:增加变量绑定 78 | 79 | 需将所有的这种代码: 80 | 81 | ```cpp 82 | // InitWindow里面 83 | CEditUI *ctrl = dynamic_cast (parent->find_control (_T ("ctrl_name"))); 84 | ``` 85 | 86 | 替换为: 87 | 88 | ```cpp 89 | // 任意位置 90 | BindEditUI ctrl { _T ("ctrl_name") }; 91 | 92 | // 多窗口推荐传入m_pm,避免出现无法找到控件的问题 93 | BindEditUI ctrl { _T ("ctrl_name"), &m_pm }; 94 | ``` 95 | 96 | 需注意: 97 | 98 | 1. 绑定对象的创建位置不限,既可以在程序运行时绑定,也可以在InitWindow执行完后再绑定 99 | 2. 绑定对象在窗口及PaintManager创建前是无法使用的,只有在两者创建完成后才能使用 100 | 3. PaintManager对象不要设置名称,如果必须设置的场合,需要在Bind/BindCtrls.hpp代码中同步修改 101 | 4. BindXxxxxUI对象的使用方式与CXxxxxUI相同,BindXxxxxUI不能new,使用时直接使用->访问CXxxxxUI里的属性或方法 102 | 103 | ### 第三步:自定义控件绑定 104 | 105 | 假设XML节点为<UserCtrl name="ctrl_name" />,那么类名必须风格统一,为CUserCtrlUI;然后在头文件中加入以下代码: 106 | 107 | ```cpp 108 | #ifdef DEF_BINDCTRL 109 | DEF_BINDCTRL (UserCtrl); 110 | #endif //DEF_BINDCTRL 111 | ``` 112 | 113 | 大功告成,此时可以用以下代码实现自定义控件绑定 114 | 115 | ```cpp 116 | BindUserCtrlUI ctrl { _T ("ctrl_name") }; 117 | ``` 118 | 119 | ## 已更新内容 120 | 121 | 1. 完善链接方式,针对是否为Unicode、Debug、64位、动态或静态,4种条件16种链接方式做出完善的链接选项 122 | 2. GroupBox边框绘制时自动擦除文字位置,使得不用设置背景色,文字依旧不被边框遮盖 123 | 3. 修复容器子元素手动右对齐,方法为子控件加入代码:floatalign="right" 124 | 4. 修复Combo控件的SetText功能 125 | 5. 新增图片的dest可为负数,当为负数时,位置固定在目标控件的右边。比如Combo控件固定到右边的下拉箭头 126 | 6. 修改CDuiString实现方式的底层为faw::String,使得兼容性更强 127 | 7. Label控件新增autocalcheight,效果类似于autocalcwidth 128 | 8. 使用std::variant代替STRINGorID 129 | 9. 使用std::string_view代替了几乎所有的LPCTSTR 130 | 10. 移除了CDuiPoint、CDuiRect、CDuiSize 131 | 11. 整理出公共类FawTools,将大部分重复的代码合并 132 | 12. 实现控件绑定(经研究发现,因为语言的问题,值绑定的效果不好,所以这儿暂时不考虑,如果有好的建议可以提) 133 | 13. 修复Edit控件nativetextcolor属性无效的问题 134 | 14. 新增绘图引用,使得指定的背景图等可以动态改变 135 | 15. 修复设置背景色时移除图片资源的bug 136 | 16. 新增Dynamic属性,避免因caption覆盖内容时,可拖动边框失效的问题 137 | 17. VerticalLayout自动计算高度、HorizontalLayout自动计算宽度 138 | 139 | ## 待研究或待添加 140 | 141 | 1. 实现虚拟列表效果 142 | 2. 实现文字阴影效果 143 | 3. 图片没有autocalcwidth、autocalcheight 144 | 4. 容器不支持根据子元素大小来计算大小 145 | 5. 考虑新增Ribbon、Docker、MVC功能 146 | 147 | ## 许可证:MIT+原始许可 148 | --------------------------------------------------------------------------------