mirror of
https://github.com/N3xoX1/sciterui.git
synced 2026-06-17 04:16:14 -07:00
Add initial version of the sciterui project
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
#include "sciter_ui.h"
|
||||
#include "sciter_value.h"
|
||||
|
||||
class SciterElement
|
||||
{
|
||||
public:
|
||||
enum SET_ELEMENT_HTML
|
||||
{
|
||||
SIH_REPLACE_CONTENT = 0,
|
||||
SIH_INSERT_AT_START = 1,
|
||||
SIH_APPEND_AFTER_LAST = 2,
|
||||
SOH_REPLACE = 3,
|
||||
SOH_INSERT_BEFORE = 4,
|
||||
SOH_INSERT_AFTER = 5
|
||||
};
|
||||
|
||||
SciterElement();
|
||||
SciterElement(SCITER_ELEMENT h);
|
||||
SciterElement(const SciterElement & e);
|
||||
~SciterElement();
|
||||
|
||||
SciterElement & operator=(SCITER_ELEMENT h);
|
||||
SciterElement & operator=(const SciterElement & e);
|
||||
|
||||
operator bool() const;
|
||||
operator SCITER_ELEMENT() const;
|
||||
bool operator==(const SciterElement & rs) const;
|
||||
bool operator==(SCITER_ELEMENT rs) const;
|
||||
bool operator!=(const SciterElement & rs) const;
|
||||
bool operator!=(SCITER_ELEMENT rs) const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
SciterElement FindFirst(const char * selector, ...) const;
|
||||
void SetHTML(const uint8_t * hHtml, size_t htmlLength, int where = SIH_REPLACE_CONTENT) const;
|
||||
SciterValue Eval(const char * script);
|
||||
|
||||
private:
|
||||
void Use(SCITER_ELEMENT h);
|
||||
void Unuse();
|
||||
void Set(SCITER_ELEMENT h);
|
||||
|
||||
SCITER_ELEMENT m_he;
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
typedef const void * SCITER_ELEMENT;
|
||||
typedef const void * HWINDOW;
|
||||
|
||||
__interface IWindowDestroySink
|
||||
{
|
||||
void OnWindowDestroy(HWINDOW hWnd);
|
||||
};
|
||||
|
||||
__interface ISciterWindow
|
||||
{
|
||||
void CenterWindow(void) = 0;
|
||||
HWINDOW GetHandle() const = 0;
|
||||
SCITER_ELEMENT GetRootElement(void) const = 0;
|
||||
void OnDestroySinkAdd(IWindowDestroySink * Sink) = 0;
|
||||
void OnDestroySinkRemove(IWindowDestroySink * Sink) = 0;
|
||||
};
|
||||
|
||||
__interface ISciterUI
|
||||
{
|
||||
bool WindowCreate(HWINDOW parent, const char * baseHtml, int x, int y, int width, int height, ISciterWindow *& window) = 0;
|
||||
void Run() = 0;
|
||||
void Stop() = 0;
|
||||
void Shutdown() = 0;
|
||||
};
|
||||
|
||||
bool SciterUIInit(const char * languageDir, const char * baseLanguage, const char * currentLanguage, bool Console, ISciterUI *& sciterUI);
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
class SciterValue
|
||||
{
|
||||
enum VALUE_TYPE
|
||||
{
|
||||
TYPE_UNDEFINED = 0,
|
||||
TYPE_BOOL = 1,
|
||||
TYPE_INT32_T = 2,
|
||||
TYPE_STRING = 3,
|
||||
};
|
||||
|
||||
public:
|
||||
SciterValue();
|
||||
SciterValue(bool Value);
|
||||
SciterValue(int32_t Value);
|
||||
SciterValue(std::string Value);
|
||||
~SciterValue();
|
||||
|
||||
int32_t GetValueInt(void) const;
|
||||
|
||||
private:
|
||||
uint32_t m_type;
|
||||
uint32_t m_valueInt;
|
||||
std::string m_valueStr;
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>_DEBUG;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
|
||||
<IntrinsicFunctions>false</IntrinsicFunctions>
|
||||
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>false</OmitFramePointers>
|
||||
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<SmallerTypeCheck Condition="'$(PlatformToolsetVersion)'<140">true</SmallerTypeCheck>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Midl>
|
||||
<PreprocessorDefinitions>_DEBUG;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</Midl>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>_DEBUG;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
</ItemDefinitionGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="Platform.props" />
|
||||
<Import Project="Debug.props" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,219 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<PropertyGroup Label="Configuration">
|
||||
<PlatformToolset Condition="'$(DefaultPlatformToolset)'!=''">$(DefaultPlatformToolset)</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
|
||||
<!-- All platforms settings -->
|
||||
<PropertyGroup>
|
||||
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
|
||||
<ExtensionsToDeleteOnClean>*.obj;*.ilk;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;$(TargetPath);$(ExtensionsToDeleteOnClean)</ExtensionsToDeleteOnClean>
|
||||
<IgnoreImportLibrary>false</IgnoreImportLibrary>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<EmbedManifest>true</EmbedManifest>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(ConfigurationType)'=='StaticLibrary'">
|
||||
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\lib\</OutDir>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;_WIN32;_WINDOWS;WIN32_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
<PropertyGroup Label="UserMacros">
|
||||
<ROOT>$(SolutionDir)</ROOT>
|
||||
<SRC>$(ROOT)Source\</SRC>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<BuildMacro Include="ROOT">
|
||||
<Value>$(ROOT)</Value>
|
||||
</BuildMacro>
|
||||
<BuildMacro Include="SRC">
|
||||
<Value>$(SRC)</Value>
|
||||
</BuildMacro>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemDefinitionGroup>
|
||||
<BuildLog>
|
||||
<Path>$(IntDir)BuildLog.htm</Path>
|
||||
</BuildLog>
|
||||
<Bscmake>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<OutputFile>$(OutDir)$(ProjectName).bsc</OutputFile>
|
||||
</Bscmake>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>.\;$(SolutionDir)\src;$(SolutionDir)\src\3rd_party;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
|
||||
<PreprocessToFile>false</PreprocessToFile>
|
||||
<PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers>
|
||||
<PreprocessKeepComments>false</PreprocessKeepComments>
|
||||
<StringPooling>true</StringPooling>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<ExceptionHandling>Async</ExceptionHandling>
|
||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||
<StructMemberAlignment>Default</StructMemberAlignment>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<EnableEnhancedInstructionSet Condition="'$(Platform)'=='Win32'">NoExtensions</EnableEnhancedInstructionSet>
|
||||
<EnableEnhancedInstructionSet Condition="'$(Platform)'=='Win32' AND $(PlatformToolsetVersion)<110">NotSet</EnableEnhancedInstructionSet>
|
||||
<FloatingPointModel>Precise</FloatingPointModel>
|
||||
<FloatingPointExceptions>false</FloatingPointExceptions>
|
||||
<DisableLanguageExtensions>false</DisableLanguageExtensions>
|
||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
|
||||
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
||||
<OpenMPSupport>false</OpenMPSupport>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile>
|
||||
<ExpandAttributedSource>false</ExpandAttributedSource>
|
||||
<AssemblerListingLocation>$(IntDir)</AssemblerListingLocation>
|
||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
||||
<ProgramDataBaseFileName>$(IntDir)vc$(VisualStudioVersion).pdb</ProgramDataBaseFileName>
|
||||
<GenerateXMLDocumentationFiles>false</GenerateXMLDocumentationFiles>
|
||||
<XMLDocumentationFileName>$(IntDir)</XMLDocumentationFileName>
|
||||
<BrowseInformationFile>$(IntDir)</BrowseInformationFile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<TreatWarningAsError>false</TreatWarningAsError>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<CallingConvention>Cdecl</CallingConvention>
|
||||
<CompileAs>Default</CompileAs>
|
||||
<ShowIncludes>false</ShowIncludes>
|
||||
<UndefineAllPreprocessorDefinitions>false</UndefineAllPreprocessorDefinitions>
|
||||
<EnablePREfast>false</EnablePREfast>
|
||||
<UseFullPaths>false</UseFullPaths>
|
||||
<OmitDefaultLibName>false</OmitDefaultLibName>
|
||||
<ErrorReporting>Prompt</ErrorReporting>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Lib>
|
||||
<OutputFile>$(OutDir)$(TargetName).lib</OutputFile>
|
||||
<UseUnicodeResponseFiles>true</UseUnicodeResponseFiles>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
</Lib>
|
||||
<ProjectReference>
|
||||
<LinkLibraryDependencies>true</LinkLibraryDependencies>
|
||||
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
|
||||
</ProjectReference>
|
||||
<Link>
|
||||
<RegisterOutput>false</RegisterOutput>
|
||||
<PerUserRedirection>false</PerUserRedirection>
|
||||
<AdditionalOptions>/IGNORE:4199 /OPT:ICF=3 %(AdditionalOptions)</AdditionalOptions>
|
||||
<ShowProgress>NotSet</ShowProgress>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<ManifestFile>$(IntDir)$(TargetFileName).intermediate.manifest</ManifestFile>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ModuleDefinitionFile />
|
||||
<DelayLoadDLLs>advapi32.dll;userenv.dll;shell32.dll;shlwapi.dll;ws2_32.dll;version.dll;wtsapi32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
<IgnoreEmbeddedIDL>false</IgnoreEmbeddedIDL>
|
||||
<TypeLibraryResourceID>1</TypeLibraryResourceID>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>$(TargetDir)pdb/$(TargetName).pdb</ProgramDatabaseFile>
|
||||
<GenerateMapFile>true</GenerateMapFile>
|
||||
<MapFileName>$(TargetDir)map/$(TargetName).map</MapFileName>
|
||||
<MapExports>false</MapExports>
|
||||
<HeapReserveSize />
|
||||
<HeapCommitSize />
|
||||
<StackReserveSize />
|
||||
<StackCommitSize />
|
||||
<SwapRunFromCD>false</SwapRunFromCD>
|
||||
<SwapRunFromNET>false</SwapRunFromNET>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<NoEntryPoint>false</NoEntryPoint>
|
||||
<SetChecksum>false</SetChecksum>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
<FixedBaseAddress>false</FixedBaseAddress>
|
||||
<TurnOffAssemblyGeneration>false</TurnOffAssemblyGeneration>
|
||||
<SupportUnloadOfDelayLoadedDLL>false</SupportUnloadOfDelayLoadedDLL>
|
||||
<ImportLibrary>$(TargetDir)lib/$(TargetName).lib</ImportLibrary>
|
||||
<Profile>false</Profile>
|
||||
<CLRThreadAttribute>DefaultThreadingAttribute</CLRThreadAttribute>
|
||||
<CLRImageType>Default</CLRImageType>
|
||||
<LinkErrorReporting>PromptImmediately</LinkErrorReporting>
|
||||
<CLRUnmanagedCodeCheck>false</CLRUnmanagedCodeCheck>
|
||||
</Link>
|
||||
<Midl>
|
||||
<AdditionalIncludeDirectories>.;$(SRC);$(SRC)\3rdParty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
|
||||
<MkTypLibCompatible>false</MkTypLibCompatible>
|
||||
<WarningLevel>3</WarningLevel>
|
||||
<WarnAsError>false</WarnAsError>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<DefaultCharType>Unsigned</DefaultCharType>
|
||||
<GenerateStublessProxies>true</GenerateStublessProxies>
|
||||
<GenerateTypeLibrary>true</GenerateTypeLibrary>
|
||||
<TypeLibraryName>$(IntDir)%(Filename).tlb</TypeLibraryName>
|
||||
<HeaderFileName>%(Filename)_h.h</HeaderFileName>
|
||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
||||
<EnableErrorChecks>All</EnableErrorChecks>
|
||||
<ErrorCheckAllocations>false</ErrorCheckAllocations>
|
||||
<ErrorCheckBounds>false</ErrorCheckBounds>
|
||||
<ErrorCheckEnumRange>false</ErrorCheckEnumRange>
|
||||
<ErrorCheckRefPointers>false</ErrorCheckRefPointers>
|
||||
<ErrorCheckStubData>false</ErrorCheckStubData>
|
||||
<ValidateAllParameters>true</ValidateAllParameters>
|
||||
<StructMemberAlignment>NotSet</StructMemberAlignment>
|
||||
</Midl>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0000</Culture>
|
||||
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
|
||||
<ShowProgress>false</ShowProgress>
|
||||
<ResourceOutputFileName>$(IntDir)%(Filename).res</ResourceOutputFileName>
|
||||
</ResourceCompile>
|
||||
<Manifest>
|
||||
<OutputManifestFile>$(IntDir)$(TargetFileName).embed.manifest</OutputManifestFile>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<VerboseOutput>false</VerboseOutput>
|
||||
<GenerateCatalogFiles>false</GenerateCatalogFiles>
|
||||
<UpdateFileHashes>false</UpdateFileHashes>
|
||||
</Manifest>
|
||||
<ManifestResourceCompile>
|
||||
<ResourceOutputFileName>$(IntDir)$(TargetFileName).embed.manifest.res</ResourceOutputFileName>
|
||||
</ManifestResourceCompile>
|
||||
<Xdcmake>
|
||||
<DocumentLibraryDependencies>true</DocumentLibraryDependencies>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<OutputFile>$(TargetDir)$(TargetName).xml</OutputFile>
|
||||
</Xdcmake>
|
||||
</ItemDefinitionGroup>
|
||||
<!-- END common platform settings -->
|
||||
|
||||
<!-- Win32 -->
|
||||
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
|
||||
<Lib>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Lib>
|
||||
<Link>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<!-- END Win32 -->
|
||||
|
||||
<!-- x64 -->
|
||||
<ItemDefinitionGroup Condition="'$(Platform)'=='x64'">
|
||||
<Lib>
|
||||
<TargetMachine>MachineX64</TargetMachine>
|
||||
</Lib>
|
||||
<Link>
|
||||
<TargetMachine>MachineX64</TargetMachine>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<!-- END x64 -->
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="Platform.props" />
|
||||
<Import Project="Release.props" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Optimization>MinSpace</Optimization>
|
||||
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>false</OmitFramePointers>
|
||||
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Midl>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</Midl>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
</ItemDefinitionGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34018.315
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sciterui", "src\sciterui\sciterui.vcxproj", "{847B64EE-2C78-48F9-912B-D700F2A5CB91}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{847B64EE-2C78-48F9-912B-D700F2A5CB91}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{847B64EE-2C78-48F9-912B-D700F2A5CB91}.Debug|x64.Build.0 = Debug|x64
|
||||
{847B64EE-2C78-48F9-912B-D700F2A5CB91}.Release|x64.ActiveCfg = Release|x64
|
||||
{847B64EE-2C78-48F9-912B-D700F2A5CB91}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {D8D8B133-4C3D-4DA2-8535-893D482E95F9}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,118 @@
|
||||
#include "file.h"
|
||||
#include <Windows.h>
|
||||
|
||||
namespace SciterUI
|
||||
{
|
||||
|
||||
File::File() :
|
||||
m_file(INVALID_HANDLE_VALUE)
|
||||
{
|
||||
}
|
||||
|
||||
File::~File()
|
||||
{
|
||||
if (m_file != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
bool File::Open(const char* fileName, uint32_t openFlags)
|
||||
{
|
||||
if (!Close())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fileName == nullptr || strlen(fileName) == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_file = INVALID_HANDLE_VALUE;
|
||||
|
||||
ULONG dwAccess = 0;
|
||||
switch (openFlags & 3)
|
||||
{
|
||||
case modeRead:
|
||||
dwAccess = GENERIC_READ;
|
||||
break;
|
||||
case modeWrite:
|
||||
dwAccess = GENERIC_WRITE;
|
||||
break;
|
||||
case modeReadWrite:
|
||||
dwAccess = GENERIC_READ | GENERIC_WRITE;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
ULONG shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
||||
if ((openFlags & shareDenyWrite) == shareDenyWrite)
|
||||
{
|
||||
shareMode &= ~FILE_SHARE_WRITE;
|
||||
}
|
||||
if ((openFlags & shareDenyRead) == shareDenyRead)
|
||||
{
|
||||
shareMode &= ~FILE_SHARE_READ;
|
||||
}
|
||||
if ((openFlags & shareExclusive) == shareExclusive)
|
||||
{
|
||||
shareMode = 0;
|
||||
}
|
||||
|
||||
// map modeNoInherit flag
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
sa.nLength = sizeof(sa);
|
||||
sa.lpSecurityDescriptor = nullptr;
|
||||
sa.bInheritHandle = (openFlags & modeNoInherit) == 0;
|
||||
|
||||
// map creation flags
|
||||
ULONG createFlag = OPEN_EXISTING;
|
||||
if (openFlags & modeCreate)
|
||||
{
|
||||
createFlag = ((openFlags & modeNoTruncate) != 0) ? OPEN_ALWAYS : CREATE_ALWAYS;
|
||||
}
|
||||
|
||||
HANDLE hFile = ::CreateFileA(fileName, dwAccess, shareMode, &sa, createFlag, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_file = hFile;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool File::Close()
|
||||
{
|
||||
bool bError = true;
|
||||
if (m_file != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
bError = !::CloseHandle(m_file);
|
||||
}
|
||||
m_file = INVALID_HANDLE_VALUE;
|
||||
return bError;
|
||||
}
|
||||
|
||||
uint32_t File::GetLength() const
|
||||
{
|
||||
DWORD hiWord = 0;
|
||||
return GetFileSize(m_file, &hiWord);
|
||||
}
|
||||
|
||||
uint32_t File::Read(void* lpBuf, uint32_t nCount)
|
||||
{
|
||||
if (nCount == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
DWORD read = 0;
|
||||
if (!::ReadFile(m_file, lpBuf, nCount, &read, nullptr))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (uint32_t)read;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
namespace SciterUI
|
||||
{
|
||||
|
||||
class File
|
||||
{
|
||||
public:
|
||||
enum OpenFlags
|
||||
{
|
||||
modeRead = 0x0000,
|
||||
modeWrite = 0x0001,
|
||||
modeReadWrite = 0x0002,
|
||||
shareCompat = 0x0000,
|
||||
shareExclusive = 0x0010,
|
||||
shareDenyWrite = 0x0020,
|
||||
shareDenyRead = 0x0030,
|
||||
shareDenyNone = 0x0040,
|
||||
modeNoInherit = 0x0080,
|
||||
modeCreate = 0x1000,
|
||||
modeNoTruncate = 0x2000,
|
||||
};
|
||||
|
||||
File();
|
||||
File(void* fileHandle);
|
||||
File(const char* fileName, uint32_t openFlags);
|
||||
~File();
|
||||
|
||||
bool Open(const char* fileName, uint32_t openFlags);
|
||||
bool Close();
|
||||
|
||||
uint32_t GetLength() const;
|
||||
|
||||
uint32_t Read(void* buffer, uint32_t bufferSize);
|
||||
|
||||
private:
|
||||
File(const File&) = delete;
|
||||
File& operator=(const File&) = delete;
|
||||
|
||||
void* m_file;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
#include "module_disk.h"
|
||||
#include "file.h"
|
||||
#include "resource_manager.h"
|
||||
#include "std_string.h"
|
||||
|
||||
namespace SciterUI
|
||||
{
|
||||
|
||||
ModuleDisk::ModuleDisk() :
|
||||
m_loaded(false)
|
||||
{
|
||||
}
|
||||
|
||||
ModuleDisk::~ModuleDisk()
|
||||
{
|
||||
}
|
||||
|
||||
bool ModuleDisk::LoadModule(const char * path)
|
||||
{
|
||||
if (m_loaded)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_path = Path(path, "");
|
||||
if (!m_path.DirectoryExists())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_loaded = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModuleDisk::LoadResource(const wchar_t * name, const wchar_t * type, std::unique_ptr<uint8_t> & data, uint32_t & size)
|
||||
{
|
||||
Path ResPath = GetResPath(name, type);
|
||||
if (!ResPath.FileExists())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
File resFile;
|
||||
if (!resFile.Open(ResPath, File::modeRead))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
uint32_t ulLen = resFile.GetLength();
|
||||
if (ulLen <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
data.reset(new uint8_t[ulLen]);
|
||||
size = resFile.Read(data.get(), ulLen);
|
||||
return true;
|
||||
}
|
||||
|
||||
Path ModuleDisk::GetResPath(const wchar_t * name, const wchar_t * type)
|
||||
{
|
||||
Path path(m_path);
|
||||
|
||||
if ((uint64_t)type <= 0xFFFF)
|
||||
{
|
||||
if (type == (const wchar_t *)ResourceManager::RT_BITMAP || type == (const wchar_t *)ResourceManager::RT_GROUP_ICON || type == (const wchar_t *)ResourceManager::RT_GROUP_CURSOR)
|
||||
{
|
||||
path.AppendDirectory("image");
|
||||
}
|
||||
else if (type == (const wchar_t *)ResourceManager::RT_HTML)
|
||||
{
|
||||
path.AppendDirectory("html");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_wcsicmp(type, L"png") == 0 || _wcsicmp(type, L"jpg") == 0 || _wcsicmp(type, L"gif") == 0 || _wcsicmp(type, L"svg") == 0)
|
||||
{
|
||||
path.AppendDirectory("image");
|
||||
}
|
||||
else if (_wcsicmp(type, L"css") == 0)
|
||||
{
|
||||
path.AppendDirectory("css");
|
||||
}
|
||||
else if (_wcsicmp(type, L"lang") == 0)
|
||||
{
|
||||
path.AppendDirectory("lang");
|
||||
}
|
||||
}
|
||||
std::wstring fileName = name;
|
||||
if (_wcsnicmp(fileName.c_str(), L"file://", 7) == 0)
|
||||
{
|
||||
fileName = fileName.substr(7, fileName.size() - 7);
|
||||
}
|
||||
path.SetNameExtension(stdstr().FromUTF16(fileName.c_str()).c_str());
|
||||
if (path.FileExists())
|
||||
{
|
||||
return path;
|
||||
}
|
||||
return Path();
|
||||
}
|
||||
|
||||
} // namespace SciterUI
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include "module_resource.h"
|
||||
#include "path.h"
|
||||
|
||||
namespace SciterUI
|
||||
{
|
||||
|
||||
class ModuleDisk :
|
||||
public IModuleResource
|
||||
{
|
||||
public:
|
||||
ModuleDisk();
|
||||
~ModuleDisk();
|
||||
|
||||
bool LoadModule(const char * path);
|
||||
|
||||
// IResourceModule
|
||||
bool LoadResource(const wchar_t * name, const wchar_t * type, std::unique_ptr<uint8_t> & data, uint32_t & size);
|
||||
|
||||
private:
|
||||
ModuleDisk(const ModuleDisk &) = delete;
|
||||
ModuleDisk & operator=(const ModuleDisk &) = delete;
|
||||
|
||||
Path GetResPath(const wchar_t * name, const wchar_t * type);
|
||||
bool m_loaded;
|
||||
Path m_path;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
namespace SciterUI
|
||||
{
|
||||
__interface IModuleResource
|
||||
{
|
||||
bool LoadResource(const wchar_t* name, const wchar_t* type, std::unique_ptr<uint8_t>& data, uint32_t& size);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
#include "path.h"
|
||||
#include "std_string.h"
|
||||
#include <Windows.h>
|
||||
|
||||
namespace SciterUI
|
||||
{
|
||||
const char DRIVE_DELIMITER = ':';
|
||||
const char * const DIR_DOUBLEDELIM = "\\\\";
|
||||
const char DIRECTORY_DELIMITER = '\\';
|
||||
const char DIRECTORY_DELIMITER2 = '/';
|
||||
|
||||
Path::Path()
|
||||
{
|
||||
}
|
||||
|
||||
Path::Path(const char * path)
|
||||
{
|
||||
m_path = path ? path : "";
|
||||
CleanPath(m_path);
|
||||
}
|
||||
|
||||
Path::Path(const char * path, const char * fileName)
|
||||
{
|
||||
SetDriveDirectory(path);
|
||||
SetNameExtension(fileName);
|
||||
}
|
||||
|
||||
Path::operator const char *() const
|
||||
{
|
||||
return (const char *)m_path.c_str();
|
||||
}
|
||||
|
||||
Path::operator const std::string &()
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
void Path::GetDirectory(std::string & directory) const
|
||||
{
|
||||
GetComponents(nullptr, &directory);
|
||||
}
|
||||
|
||||
void Path::GetComponents(std::string * drive, std::string * directory, std::string * name, std::string * extension) const
|
||||
{
|
||||
char driveBuff[_MAX_DRIVE + 1] = {0}, dirBuff[_MAX_DIR + 1] = {0}, nameBuff[_MAX_FNAME + 1] = {0}, extBuff[_MAX_EXT + 1] = {0};
|
||||
|
||||
const char * basePath = m_path.c_str();
|
||||
const char * driveDir = strrchr(basePath, DRIVE_DELIMITER);
|
||||
if (driveDir != nullptr)
|
||||
{
|
||||
size_t len = sizeof(dirBuff) < (driveDir - basePath) ? sizeof(driveBuff) : driveDir - basePath;
|
||||
strncpy(driveBuff, basePath, len);
|
||||
basePath += len + 1;
|
||||
}
|
||||
|
||||
const char * last = strrchr(basePath, DIRECTORY_DELIMITER);
|
||||
if (last != nullptr)
|
||||
{
|
||||
size_t len = sizeof(dirBuff) < (last - basePath) ? sizeof(dirBuff) : last - basePath;
|
||||
if (len > 0)
|
||||
{
|
||||
strncpy(dirBuff, basePath, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
dirBuff[0] = DIRECTORY_DELIMITER;
|
||||
dirBuff[1] = '\0';
|
||||
}
|
||||
strncpy(nameBuff, last + 1, sizeof(nameBuff));
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(dirBuff, basePath, sizeof(dirBuff));
|
||||
}
|
||||
char * ext = strrchr(nameBuff, '.');
|
||||
if (ext != nullptr)
|
||||
{
|
||||
strncpy(extBuff, ext + 1, sizeof(extBuff));
|
||||
*ext = '\0';
|
||||
}
|
||||
|
||||
if (drive)
|
||||
{
|
||||
*drive = driveBuff;
|
||||
}
|
||||
if (directory)
|
||||
{
|
||||
*directory = dirBuff;
|
||||
}
|
||||
if (name)
|
||||
{
|
||||
*name = nameBuff;
|
||||
}
|
||||
if (extension)
|
||||
{
|
||||
*extension = extBuff;
|
||||
}
|
||||
}
|
||||
|
||||
void Path::SetDriveDirectory(const char * driveDirectory)
|
||||
{
|
||||
std::string driveDirectoryStr = driveDirectory;
|
||||
if (driveDirectoryStr.length() > 0)
|
||||
{
|
||||
EnsureTrailingBackslash(driveDirectoryStr);
|
||||
CleanPath(driveDirectoryStr);
|
||||
}
|
||||
|
||||
std::string name, extension;
|
||||
GetComponents(nullptr, nullptr, &name, &extension);
|
||||
SetComponents(nullptr, driveDirectoryStr.c_str(), name.c_str(), extension.c_str());
|
||||
}
|
||||
|
||||
void Path::SetDirectory(const char * directory, bool ensureAbsolute)
|
||||
{
|
||||
std::string newDirectory = directory;
|
||||
if (ensureAbsolute)
|
||||
{
|
||||
EnsureLeadingBackslash(newDirectory);
|
||||
}
|
||||
if (newDirectory.length() > 0)
|
||||
{
|
||||
EnsureTrailingBackslash(newDirectory);
|
||||
}
|
||||
std::string drive, name, extension;
|
||||
GetComponents(&drive, nullptr, &name, &extension);
|
||||
SetComponents(drive.c_str(), newDirectory.c_str(), name.c_str(), extension.c_str());
|
||||
}
|
||||
|
||||
void Path::SetNameExtension(const char * nameExtension)
|
||||
{
|
||||
std::string directory, drive;
|
||||
GetComponents(&drive, &directory);
|
||||
SetComponents(drive.c_str(), directory.c_str(), nameExtension, nullptr);
|
||||
}
|
||||
|
||||
void Path::SetComponents(const char * drive, const char * directory, const char * name, const char * extension)
|
||||
{
|
||||
char fullname[MAX_PATH];
|
||||
|
||||
memset(fullname, 0, sizeof(fullname));
|
||||
if (directory == nullptr || strlen(directory) == 0)
|
||||
{
|
||||
static char emptyDir[] = {DIRECTORY_DELIMITER, '\0'};
|
||||
directory = emptyDir;
|
||||
}
|
||||
|
||||
_makepath(fullname, drive, directory, name, extension);
|
||||
m_path = fullname;
|
||||
}
|
||||
|
||||
void Path::AppendDirectory(const char * subDirectory)
|
||||
{
|
||||
std::string newSubDirectory = subDirectory;
|
||||
if (newSubDirectory.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StripLeadingBackslash(newSubDirectory);
|
||||
EnsureTrailingBackslash(newSubDirectory);
|
||||
|
||||
std::string drive, directory, name, extension;
|
||||
GetComponents(&drive, &directory, &name, &extension);
|
||||
EnsureTrailingBackslash(directory);
|
||||
directory += newSubDirectory;
|
||||
SetComponents(drive.c_str(), directory.c_str(), name.c_str(), extension.c_str());
|
||||
}
|
||||
|
||||
bool Path::FileExists() const
|
||||
{
|
||||
WIN32_FIND_DATA FindData;
|
||||
HANDLE hFindFile = FindFirstFile(stdstr(m_path).ToUTF16().c_str(), &FindData);
|
||||
bool bSuccess = (hFindFile != INVALID_HANDLE_VALUE);
|
||||
|
||||
if (hFindFile != nullptr) // Make sure we close the search
|
||||
{
|
||||
FindClose(hFindFile);
|
||||
}
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
bool Path::DirectoryExists() const
|
||||
{
|
||||
Path path(m_path.c_str());
|
||||
|
||||
std::string directory;
|
||||
path.DirectoryUp(&directory);
|
||||
path.SetNameExtension(directory.c_str());
|
||||
|
||||
WIN32_FIND_DATA FindData;
|
||||
HANDLE findFile = FindFirstFile(stdstr((const char *)path).ToUTF16().c_str(), &FindData);
|
||||
bool res = (findFile != INVALID_HANDLE_VALUE);
|
||||
if (findFile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FindClose(findFile);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void Path::DirectoryUp(std::string * lastDir)
|
||||
{
|
||||
std::string directory;
|
||||
GetDirectory(directory);
|
||||
StripTrailingBackslash(directory);
|
||||
if (directory.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::string::size_type delimiter = directory.rfind(DIRECTORY_DELIMITER);
|
||||
if (lastDir != nullptr)
|
||||
{
|
||||
*lastDir = directory.substr(delimiter);
|
||||
StripLeadingBackslash(*lastDir);
|
||||
}
|
||||
|
||||
if (delimiter != std::string::npos)
|
||||
{
|
||||
directory = directory.substr(0, delimiter);
|
||||
}
|
||||
SetDirectory(directory.c_str());
|
||||
}
|
||||
|
||||
void Path::CleanPath(std::string & path) const
|
||||
{
|
||||
std::string::size_type pos = path.find(DIRECTORY_DELIMITER2);
|
||||
while (pos != std::string::npos)
|
||||
{
|
||||
path.replace(pos, 1, &DIRECTORY_DELIMITER);
|
||||
pos = path.find(DIRECTORY_DELIMITER2, pos + 1);
|
||||
}
|
||||
|
||||
bool appendEnd = !_strnicmp(path.c_str(), DIR_DOUBLEDELIM, 2);
|
||||
pos = path.find(DIR_DOUBLEDELIM);
|
||||
while (pos != std::string::npos)
|
||||
{
|
||||
path.replace(pos, 2, &DIRECTORY_DELIMITER);
|
||||
pos = path.find(DIR_DOUBLEDELIM, pos + 1);
|
||||
}
|
||||
if (appendEnd)
|
||||
{
|
||||
path.insert(0, stdstr_f("%c", DIRECTORY_DELIMITER).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Path::EnsureLeadingBackslash(std::string & directory) const
|
||||
{
|
||||
if (directory.empty() || (directory[0] != DIRECTORY_DELIMITER))
|
||||
{
|
||||
directory = stdstr_f("%c%s", DIRECTORY_DELIMITER, directory.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Path::EnsureTrailingBackslash(std::string & directory) const
|
||||
{
|
||||
std::string::size_type length = directory.length();
|
||||
|
||||
if (directory.empty() || (directory[length - 1] != DIRECTORY_DELIMITER))
|
||||
{
|
||||
directory += DIRECTORY_DELIMITER;
|
||||
}
|
||||
}
|
||||
|
||||
void Path::StripLeadingBackslash(std::string & directory) const
|
||||
{
|
||||
if (directory.length() <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (directory[0] == DIRECTORY_DELIMITER)
|
||||
{
|
||||
directory = directory.substr(1);
|
||||
}
|
||||
}
|
||||
|
||||
void Path::StripTrailingBackslash(std::string & directory) const
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
std::string::size_type length = directory.length();
|
||||
if (length <= 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (directory[length - 1] == DIRECTORY_DELIMITER || directory[length - 1] == DIRECTORY_DELIMITER2)
|
||||
{
|
||||
directory.resize(length - 1);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace SciterUI
|
||||
{
|
||||
|
||||
class Path
|
||||
{
|
||||
public:
|
||||
Path();
|
||||
Path(const char * path);
|
||||
Path(const char * path, const char * fileName);
|
||||
|
||||
operator const char *() const;
|
||||
operator const std::string &();
|
||||
|
||||
void GetDirectory(std::string & directory) const;
|
||||
void GetComponents(std::string * drive = nullptr, std::string * directory = nullptr, std::string * name = nullptr, std::string * extension = nullptr) const;
|
||||
|
||||
void SetDriveDirectory(const char * driveDirectory);
|
||||
void SetDirectory(const char * directory, bool ensureAbsolute = false);
|
||||
void SetNameExtension(const char * nameExtension);
|
||||
void SetComponents(const char * drive, const char * directory, const char * name, const char * extension);
|
||||
void AppendDirectory(const char * subDirectory);
|
||||
|
||||
bool FileExists() const;
|
||||
|
||||
bool DirectoryExists() const;
|
||||
void DirectoryUp(std::string * lastDir = nullptr);
|
||||
|
||||
private:
|
||||
void CleanPath(std::string & path) const;
|
||||
void EnsureLeadingBackslash(std::string & directory) const;
|
||||
void EnsureTrailingBackslash(std::string & directory) const;
|
||||
void StripLeadingBackslash(std::string & path) const;
|
||||
void StripTrailingBackslash(std::string & rDirectory) const;
|
||||
|
||||
std::string m_path;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#include "resource_manager.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace SciterUI
|
||||
{
|
||||
|
||||
ResourceManager::ResourceManager(const char * languageDir) :
|
||||
m_languageDir(languageDir, "")
|
||||
{
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"PNG", L"PNG"));
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"JPG", L"JPG"));
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"GIF", L"GIF"));
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"SVG", L"SVG"));
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"BMP", (const wchar_t*)RT_BITMAP));
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"ICO", (const wchar_t*)RT_GROUP_ICON));
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"CUR", (const wchar_t*)RT_GROUP_CURSOR));
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"HTM", (const wchar_t*)RT_HTML));
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"HTML", (const wchar_t*)RT_HTML));
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"CSS", L"CSS"));
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"INI", L"LANG"));
|
||||
m_resourceMap.emplace(RESOURCE_MAP::value_type(L"LNG", L"LANG"));
|
||||
}
|
||||
|
||||
bool ResourceManager::Initialize(const char * baseLanguage, const char * currentLanguage)
|
||||
{
|
||||
if (!m_languageDir.DirectoryExists())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_moduleBase = LoadLanguageFile(baseLanguage);
|
||||
if (m_moduleBase == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_stricmp(baseLanguage, currentLanguage) != 0)
|
||||
{
|
||||
m_moduleCurrent = LoadLanguageFile(currentLanguage);
|
||||
if (m_moduleCurrent == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_moduleCurrent = m_moduleBase;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ResourceManager::LoadResource(const wchar_t * uri, std::unique_ptr<uint8_t> & data, uint32_t & size)
|
||||
{
|
||||
if (m_moduleBase == nullptr || m_moduleCurrent == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const wchar_t * ResourceType = wcsrchr(uri, '.');
|
||||
if (ResourceType == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ResourceType += 1;
|
||||
std::wstring resourceTypeUpper = ResourceType;
|
||||
std::transform(resourceTypeUpper.begin(), resourceTypeUpper.end(), resourceTypeUpper.begin(), (wchar_t(*)(int))towupper);
|
||||
|
||||
RESOURCE_MAP::const_iterator iter = m_resourceMap.find(resourceTypeUpper);
|
||||
if (iter == m_resourceMap.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
std::unique_ptr<uint8_t> ResourceData;
|
||||
uint32_t ResourceSize = 0;
|
||||
if (!m_moduleCurrent->LoadResource(uri, iter->second, ResourceData, ResourceSize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
data.reset(ResourceData.release());
|
||||
size = ResourceSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
IModuleResource * ResourceManager::LoadLanguageFile(const char * language)
|
||||
{
|
||||
Path moduleDir(m_languageDir);
|
||||
moduleDir.AppendDirectory(language);
|
||||
if (moduleDir.DirectoryExists())
|
||||
{
|
||||
std::unique_ptr<ModuleDisk> diskModule(new ModuleDisk());
|
||||
if (diskModule.get() != nullptr)
|
||||
{
|
||||
if (!diskModule->LoadModule(moduleDir))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
IModuleResource * module = diskModule.get();
|
||||
m_modulesDisk.emplace_back(std::move(diskModule));
|
||||
return module;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace SciterUI
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
#include "module_disk.h"
|
||||
#include "path.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace SciterUI
|
||||
{
|
||||
|
||||
__interface IModuleResource;
|
||||
|
||||
class ResourceManager
|
||||
{
|
||||
typedef std::map<std::wstring, const wchar_t *> RESOURCE_MAP;
|
||||
typedef std::vector<std::unique_ptr<ModuleDisk>> ModulesDisk;
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
RT_BITMAP = 2,
|
||||
RT_GROUP_CURSOR = 12,
|
||||
RT_GROUP_ICON = 14,
|
||||
RT_HTML = 23
|
||||
};
|
||||
|
||||
ResourceManager(const char * languageDir);
|
||||
|
||||
bool Initialize(const char * baseLanguage, const char * currentLanguage);
|
||||
bool LoadResource(const wchar_t * uri, std::unique_ptr<uint8_t> & data, uint32_t & size);
|
||||
|
||||
private:
|
||||
ResourceManager(void) = delete;
|
||||
ResourceManager(const ResourceManager &) = delete;
|
||||
ResourceManager & operator=(const ResourceManager &) = delete;
|
||||
|
||||
IModuleResource * LoadLanguageFile(const char * language);
|
||||
ModulesDisk m_modulesDisk;
|
||||
RESOURCE_MAP m_resourceMap;
|
||||
Path m_languageDir;
|
||||
IModuleResource * m_moduleBase;
|
||||
IModuleResource * m_moduleCurrent;
|
||||
};
|
||||
|
||||
} // namespace SciterUI
|
||||
@@ -0,0 +1,76 @@
|
||||
#include "sciter.h"
|
||||
#include "sciter_window.h"
|
||||
|
||||
#include "sciter-x-api.h"
|
||||
|
||||
#undef HWINDOW
|
||||
|
||||
namespace SciterUI
|
||||
{
|
||||
|
||||
Sciter::Sciter(const char * languageDir) :
|
||||
m_resourceManager(languageDir)
|
||||
{
|
||||
}
|
||||
|
||||
bool Sciter::Initialize(const char * baseLanguage, const char * currentLanguage, bool /*console*/)
|
||||
{
|
||||
if (!m_resourceManager.Initialize(baseLanguage, currentLanguage))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
SciterExec(SCITER_APP_INIT, (UINT_PTR)0, (UINT_PTR) nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Sciter::WindowCreated(SciterWindow * window)
|
||||
{
|
||||
m_windows.insert(window);
|
||||
}
|
||||
|
||||
void Sciter::WindowDestroyed(SciterWindow * window)
|
||||
{
|
||||
WindowSet::iterator itr = m_windows.find(window);
|
||||
if (itr != m_windows.end())
|
||||
{
|
||||
if (!window->GetDestroyed())
|
||||
{
|
||||
window->SetDestroyed();
|
||||
}
|
||||
m_windows.erase(itr);
|
||||
}
|
||||
}
|
||||
|
||||
bool Sciter::WindowCreate(HWINDOW parent, const char * baseHtml, int x, int y, int width, int height, ISciterWindow *& window)
|
||||
{
|
||||
std::unique_ptr<SciterWindow> sciterWindow(new SciterWindow(*this));
|
||||
if (!sciterWindow->Create(parent, baseHtml, x, y, width, height))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
window = sciterWindow.get();
|
||||
m_CreatedWindows.emplace_back(std::move(sciterWindow));
|
||||
return true;
|
||||
}
|
||||
|
||||
void Sciter::Run()
|
||||
{
|
||||
SciterExec(SCITER_APP_LOOP, 0, 0);
|
||||
}
|
||||
|
||||
void Sciter::Stop()
|
||||
{
|
||||
SciterExec(SCITER_APP_STOP, 0, 0);
|
||||
}
|
||||
|
||||
void Sciter::Shutdown()
|
||||
{
|
||||
SciterExec(SCITER_APP_SHUTDOWN, 0, 0);
|
||||
}
|
||||
|
||||
ResourceManager & Sciter::GetResourceManager(void)
|
||||
{
|
||||
return m_resourceManager;
|
||||
}
|
||||
|
||||
} // namespace SciterUI
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "resource_manager.h"
|
||||
#include "sciter_window.h"
|
||||
#include <memory>
|
||||
#include <sciter_ui.h>
|
||||
#include <set>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
namespace SciterUI
|
||||
{
|
||||
|
||||
class Sciter :
|
||||
public ISciterUI
|
||||
{
|
||||
typedef std::set<SciterWindow *> WindowSet;
|
||||
typedef std::vector<std::unique_ptr<SciterWindow>> WindowList;
|
||||
|
||||
public:
|
||||
|
||||
Sciter(const char * languageDir);
|
||||
|
||||
bool Initialize(const char * baseLanguage, const char * currentLanguage, bool console);
|
||||
void WindowCreated(SciterWindow * window);
|
||||
void WindowDestroyed(SciterWindow * window);
|
||||
|
||||
// ISciterUI
|
||||
bool WindowCreate(HWINDOW parent, const char * baseHtml, int x, int y, int width, int height, ISciterWindow *& window);
|
||||
void Run();
|
||||
void Stop();
|
||||
void Shutdown();
|
||||
|
||||
ResourceManager & GetResourceManager(void);
|
||||
|
||||
private:
|
||||
Sciter() = delete;
|
||||
Sciter(const Sciter &) = delete;
|
||||
Sciter & operator=(const Sciter &) = delete;
|
||||
|
||||
ResourceManager m_resourceManager;
|
||||
WindowSet m_windows;
|
||||
WindowList m_CreatedWindows;
|
||||
};
|
||||
|
||||
} // namespace SciterUI
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user