NSIS Menu source
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2575 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
4cb488964d
commit
190bc67448
29 changed files with 12193 additions and 0 deletions
10
Contrib/NSIS Menu/Info.txt
Normal file
10
Contrib/NSIS Menu/Info.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
NSIS Menu - by Joost Verburg
|
||||||
|
|
||||||
|
Based on wxWindows 2.4.0 / wxHtml
|
||||||
|
|
||||||
|
Compile using the wxWindows framework: http://www.wxwindows.org/
|
||||||
|
|
||||||
|
Modified wxWindows / wxHtml sources included.
|
||||||
|
Copy the data from this folder to the wxWindows folder.
|
||||||
|
|
||||||
|
The NSIS Menu binary is compressed using UPX: http://upx.sourceforge.net/
|
1236
Contrib/NSIS Menu/include/wx/msw/setup.h
Normal file
1236
Contrib/NSIS Menu/include/wx/msw/setup.h
Normal file
File diff suppressed because it is too large
Load diff
BIN
Contrib/NSIS Menu/nsismenu/nsisicon.ico
Normal file
BIN
Contrib/NSIS Menu/nsismenu/nsisicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
139
Contrib/NSIS Menu/nsismenu/nsismenu.cpp
Normal file
139
Contrib/NSIS Menu/nsismenu/nsismenu.cpp
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// NSIS MENU
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
||||||
|
#pragma implementation "test.cpp"
|
||||||
|
#pragma interface "test.cpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// For compilers that support precompilation, includes "wx/wx.h".
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// for all others, include the necessary headers (this file is usually all you
|
||||||
|
// need because it includes almost all "standard" wxWindows headers
|
||||||
|
#ifndef WX_PRECOMP
|
||||||
|
#include "wx/wx.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/image.h"
|
||||||
|
#include "wx/html/htmlwin.h"
|
||||||
|
#include "wx/html/htmlproc.h"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// private classes
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Define a new application type, each program should derive a class from wxApp
|
||||||
|
class MyApp : public wxApp
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// override base class virtuals
|
||||||
|
// ----------------------------
|
||||||
|
|
||||||
|
// this one is called on application startup and is a good place for the app
|
||||||
|
// initialization (doing it here and not in the ctor allows to have an error
|
||||||
|
// return: if OnInit() returns false, the application terminates)
|
||||||
|
virtual bool OnInit();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define a new frame type: this is going to be our main frame
|
||||||
|
class MyFrame : public wxFrame
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// ctor(s)
|
||||||
|
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxHtmlWindow *m_Html;
|
||||||
|
|
||||||
|
// any class wishing to process wxWindows events must use this macro
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// constants
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// IDs for the controls and the menu commands
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
// controls start here (the numbers are, of course, arbitrary)
|
||||||
|
Minimal_Text = 1000
|
||||||
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// event tables and other macros for wxWindows
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// the event tables connect the wxWindows events with the functions (event
|
||||||
|
// handlers) which process them. It can be also done at run-time, but for the
|
||||||
|
// simple menu events like this the static method is much simpler.
|
||||||
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
// Create a new application object: this macro will allow wxWindows to create
|
||||||
|
// the application object during program execution (it's better than using a
|
||||||
|
// static object for many reasons) and also declares the accessor function
|
||||||
|
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
|
||||||
|
// not wxApp)
|
||||||
|
IMPLEMENT_APP(MyApp)
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// implementation
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// the application class
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// `Main program' equivalent: the program execution "starts" here
|
||||||
|
bool MyApp::OnInit()
|
||||||
|
{
|
||||||
|
wxInitAllImageHandlers();
|
||||||
|
|
||||||
|
// Create the main application window
|
||||||
|
MyFrame *frame = new MyFrame(_("NSIS Menu"),
|
||||||
|
wxPoint(50, 50), wxSize(612 + (GetSystemMetrics(SM_CXEDGE) * 2), 353 + GetSystemMetrics(SM_CYSIZE) + (GetSystemMetrics(SM_CXEDGE) * 2)));
|
||||||
|
|
||||||
|
// Show it and tell the application that it's our main window
|
||||||
|
|
||||||
|
frame->Show(TRUE);
|
||||||
|
SetTopWindow(frame);
|
||||||
|
|
||||||
|
// success: wxApp::OnRun() will be called which will enter the main message
|
||||||
|
// loop and the application will run. If we returned FALSE here, the
|
||||||
|
// application would exit immediately.
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// main frame
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
// frame constructor
|
||||||
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||||
|
: wxFrame((wxFrame *)NULL, -1, title, pos, size, wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION,
|
||||||
|
wxT("nsis_menu"))
|
||||||
|
{
|
||||||
|
m_Html = new wxHtmlWindow(this);
|
||||||
|
m_Html->SetRelatedFrame(this, _("NSIS Menu"));
|
||||||
|
m_Html->SetBorders(0);
|
||||||
|
|
||||||
|
// Set font size
|
||||||
|
wxWindow UnitConvert;
|
||||||
|
wxSize DialogSize(1000, 1000);
|
||||||
|
DialogSize = UnitConvert.ConvertDialogToPixels(DialogSize);
|
||||||
|
int fonts[7] = {0, 0, 20000 / (DialogSize.GetWidth()), 25000 / (DialogSize.GetWidth()), 0, 0, 0};
|
||||||
|
m_Html->SetFonts("", "", fonts);
|
||||||
|
|
||||||
|
m_Html->LoadPage(wxT("Menu/index.html"));
|
||||||
|
|
||||||
|
this->Centre(wxBOTH);
|
||||||
|
this->SetIcon(wxICON(nsisicon));
|
||||||
|
|
||||||
|
}
|
2
Contrib/NSIS Menu/nsismenu/nsismenu.rc
Normal file
2
Contrib/NSIS Menu/nsismenu/nsismenu.rc
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
nsisicon ICON "nsisicon.ico"
|
||||||
|
WXCURSOR_HAND CURSOR DISCARDABLE "wx/msw/hand.cur"
|
21
Contrib/NSIS Menu/nsismenu/nsismenu.sln
Normal file
21
Contrib/NSIS Menu/nsismenu/nsismenu.sln
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 7.00
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nsismenu", "nsismenu.vcproj", "{598BB726-F3FC-43A4-9E39-A1F9AD153F05}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfiguration) = preSolution
|
||||||
|
ConfigName.0 = Debug
|
||||||
|
ConfigName.1 = Release
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectDependencies) = postSolution
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfiguration) = postSolution
|
||||||
|
{598BB726-F3FC-43A4-9E39-A1F9AD153F05}.Debug.ActiveCfg = Debug|Win32
|
||||||
|
{598BB726-F3FC-43A4-9E39-A1F9AD153F05}.Debug.Build.0 = Debug|Win32
|
||||||
|
{598BB726-F3FC-43A4-9E39-A1F9AD153F05}.Release.ActiveCfg = Release|Win32
|
||||||
|
{598BB726-F3FC-43A4-9E39-A1F9AD153F05}.Release.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
150
Contrib/NSIS Menu/nsismenu/nsismenu.vcproj
Normal file
150
Contrib/NSIS Menu/nsismenu/nsismenu.vcproj
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
<?xml version="1.0" encoding = "Windows-1252"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="7.00"
|
||||||
|
Name="nsismenu"
|
||||||
|
SccProjectName=""
|
||||||
|
SccLocalPath="">
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"/>
|
||||||
|
</Platforms>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory=".\Release"
|
||||||
|
IntermediateDirectory=".\Release"
|
||||||
|
ConfigurationType="1"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="FALSE">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalOptions="/I..\lib\msw "
|
||||||
|
Optimization="2"
|
||||||
|
InlineFunctionExpansion="1"
|
||||||
|
AdditionalIncludeDirectories="../include"
|
||||||
|
PreprocessorDefinitions="NDEBUG,WIN32,_WINDOWS,WINVER=0x400,_MT,wxUSE_GUI=1"
|
||||||
|
StringPooling="TRUE"
|
||||||
|
RuntimeLibrary="0"
|
||||||
|
EnableFunctionLevelLinking="TRUE"
|
||||||
|
UsePrecompiledHeader="2"
|
||||||
|
PrecompiledHeaderFile=".\Release/nsismenu.pch"
|
||||||
|
AssemblerListingLocation=".\Release/"
|
||||||
|
ObjectFile=".\Release/"
|
||||||
|
ProgramDataBaseFileName=".\Release/"
|
||||||
|
WarningLevel="4"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
CompileAs="0"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
AdditionalOptions="/MACHINE:I386"
|
||||||
|
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib ../../..\lib\zlib.lib ../../..\lib\regex.lib ../../..\lib\png.lib ../../..\lib\jpeg.lib ../../..\lib\tiff.lib ../../..\lib\wxmsw.lib"
|
||||||
|
OutputFile=".\Release\NSIS.exe"
|
||||||
|
LinkIncremental="1"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
ProgramDatabaseFile=".\Release/nsismenu.pdb"
|
||||||
|
SubSystem="2"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
PreprocessorDefinitions="NDEBUG"
|
||||||
|
MkTypLibCompatible="TRUE"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
TargetEnvironment="1"
|
||||||
|
TypeLibraryName=".\Release/nsismenu.tlb"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="NDEBUG"
|
||||||
|
Culture="1033"
|
||||||
|
AdditionalIncludeDirectories="../include"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebDeploymentTool"/>
|
||||||
|
</Configuration>
|
||||||
|
<Configuration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
OutputDirectory=".\Debug"
|
||||||
|
IntermediateDirectory=".\Debug"
|
||||||
|
ConfigurationType="1"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="FALSE">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalOptions="/I..\lib\mswd "
|
||||||
|
Optimization="1"
|
||||||
|
AdditionalIncludeDirectories="../include"
|
||||||
|
PreprocessorDefinitions="_DEBUG,WIN32,_WINDOWS,WINVER=0x400,_MT,wxUSE_GUI=1,__WXDEBUG__,WXDEBUG=1"
|
||||||
|
RuntimeLibrary="3"
|
||||||
|
UsePrecompiledHeader="2"
|
||||||
|
PrecompiledHeaderFile=".\Debug/nsismenu.pch"
|
||||||
|
AssemblerListingLocation=".\Debug/"
|
||||||
|
ObjectFile=".\Debug/"
|
||||||
|
ProgramDataBaseFileName=".\Debug/"
|
||||||
|
WarningLevel="4"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
DebugInformationFormat="3"
|
||||||
|
CompileAs="0"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
AdditionalOptions="/MACHINE:I386"
|
||||||
|
AdditionalDependencies="odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib ../../..\lib\zlibd.lib ../../..\lib\regexd.lib ../../..\lib\pngd.lib ../../..\lib\jpegd.lib ../../..\lib\tiffd.lib ../../..\lib\wxmswd.lib"
|
||||||
|
OutputFile=".\Debug\NSIS.exe"
|
||||||
|
LinkIncremental="2"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
GenerateDebugInformation="TRUE"
|
||||||
|
ProgramDatabaseFile=".\Debug/nsismenu.pdb"
|
||||||
|
SubSystem="2"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
PreprocessorDefinitions="_DEBUG"
|
||||||
|
MkTypLibCompatible="TRUE"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
TargetEnvironment="1"
|
||||||
|
TypeLibraryName=".\Debug/nsismenu.tlb"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="_DEBUG"
|
||||||
|
Culture="1033"
|
||||||
|
AdditionalIncludeDirectories="../include"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebDeploymentTool"/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<Files>
|
||||||
|
<File
|
||||||
|
RelativePath="wx\msw\hand.cur">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="nsisicon.ico">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="resource.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="nsismenu.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="nsismenu.rc">
|
||||||
|
</File>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
15
Contrib/NSIS Menu/nsismenu/resource.h
Normal file
15
Contrib/NSIS Menu/nsismenu/resource.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
//{{NO_DEPENDENCIES}}
|
||||||
|
// Microsoft Visual C++ generated include file.
|
||||||
|
// Used by test.rc
|
||||||
|
|
||||||
|
// Next default values for new objects
|
||||||
|
//
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
#define _APS_NO_MFC 1
|
||||||
|
#define _APS_NEXT_RESOURCE_VALUE 104
|
||||||
|
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||||
|
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||||
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
|
#endif
|
||||||
|
#endif
|
331
Contrib/NSIS Menu/src/html/helpctrl.cpp
Normal file
331
Contrib/NSIS Menu/src/html/helpctrl.cpp
Normal file
|
@ -0,0 +1,331 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: helpctrl.cpp
|
||||||
|
// Purpose: wxHtmlHelpController
|
||||||
|
// Notes: Based on htmlhelp.cpp, implementing a monolithic
|
||||||
|
// HTML Help controller class, by Vaclav Slavik
|
||||||
|
// Author: Harm van der Heijden and Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: helpctrl.cpp,v 1.26.2.3 2002/12/29 05:52:26 RL Exp $
|
||||||
|
// Copyright: (c) Harm van der Heijden and Vaclav Slavik
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "helpctrl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if wxUSE_WXHTML_HELP
|
||||||
|
|
||||||
|
#ifndef WX_PRECOMP
|
||||||
|
#include "wx/app.h"
|
||||||
|
#include "wx/intl.h"
|
||||||
|
#endif // WX_PRECOMP
|
||||||
|
|
||||||
|
#include "wx/html/helpctrl.h"
|
||||||
|
#include "wx/busyinfo.h"
|
||||||
|
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
// for the hack in AddGrabIfNeeded()
|
||||||
|
#include "wx/dialog.h"
|
||||||
|
#endif // __WXGTK__
|
||||||
|
|
||||||
|
#if wxUSE_HELP
|
||||||
|
#include "wx/tipwin.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
|
||||||
|
|
||||||
|
wxHtmlHelpController::wxHtmlHelpController(int style)
|
||||||
|
{
|
||||||
|
m_helpFrame = NULL;
|
||||||
|
m_Config = NULL;
|
||||||
|
m_ConfigRoot = wxEmptyString;
|
||||||
|
m_titleFormat = _("Help: %s");
|
||||||
|
m_FrameStyle = style;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlHelpController::~wxHtmlHelpController()
|
||||||
|
{
|
||||||
|
if (m_Config)
|
||||||
|
WriteCustomization(m_Config, m_ConfigRoot);
|
||||||
|
if (m_helpFrame)
|
||||||
|
DestroyHelpWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlHelpController::DestroyHelpWindow()
|
||||||
|
{
|
||||||
|
//if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
|
||||||
|
if (m_helpFrame)
|
||||||
|
m_helpFrame->Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
|
||||||
|
{
|
||||||
|
evt.Skip();
|
||||||
|
|
||||||
|
OnQuit();
|
||||||
|
|
||||||
|
m_helpFrame->SetController((wxHelpControllerBase*) NULL);
|
||||||
|
m_helpFrame = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlHelpController::SetTitleFormat(const wxString& title)
|
||||||
|
{
|
||||||
|
m_titleFormat = title;
|
||||||
|
if (m_helpFrame)
|
||||||
|
m_helpFrame->SetTitleFormat(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::AddBook(const wxFileName& book_file, bool show_wait_msg)
|
||||||
|
{
|
||||||
|
return AddBook(wxFileSystem::FileNameToURL(book_file), show_wait_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
|
||||||
|
{
|
||||||
|
wxBusyCursor cur;
|
||||||
|
#if wxUSE_BUSYINFO
|
||||||
|
wxBusyInfo* busy = NULL;
|
||||||
|
wxString info;
|
||||||
|
if (show_wait_msg)
|
||||||
|
{
|
||||||
|
info.Printf(_("Adding book %s"), book.c_str());
|
||||||
|
busy = new wxBusyInfo(info);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
bool retval = m_helpData.AddBook(book);
|
||||||
|
#if wxUSE_BUSYINFO
|
||||||
|
if (show_wait_msg)
|
||||||
|
delete busy;
|
||||||
|
#endif
|
||||||
|
if (m_helpFrame)
|
||||||
|
m_helpFrame->RefreshLists();
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
|
||||||
|
{
|
||||||
|
return new wxHtmlHelpFrame(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlHelpController::CreateHelpWindow()
|
||||||
|
{
|
||||||
|
if (m_helpFrame)
|
||||||
|
{
|
||||||
|
m_helpFrame->Raise();
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_Config == NULL)
|
||||||
|
{
|
||||||
|
m_Config = wxConfigBase::Get(FALSE);
|
||||||
|
if (m_Config != NULL)
|
||||||
|
m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_helpFrame = CreateHelpFrame(&m_helpData);
|
||||||
|
m_helpFrame->SetController(this);
|
||||||
|
|
||||||
|
if (m_Config)
|
||||||
|
m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
|
||||||
|
|
||||||
|
m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
|
||||||
|
m_helpFrame->SetTitleFormat(m_titleFormat);
|
||||||
|
m_helpFrame->Show(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
|
||||||
|
{
|
||||||
|
/* should not be called by the user; call UseConfig, and the controller
|
||||||
|
* will do the rest */
|
||||||
|
if (m_helpFrame && cfg)
|
||||||
|
m_helpFrame->ReadCustomization(cfg, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
|
||||||
|
{
|
||||||
|
/* typically called by the controllers OnCloseFrame handler */
|
||||||
|
if (m_helpFrame && cfg)
|
||||||
|
m_helpFrame->WriteCustomization(cfg, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
|
||||||
|
{
|
||||||
|
m_Config = config;
|
||||||
|
m_ConfigRoot = rootpath;
|
||||||
|
if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
|
||||||
|
ReadCustomization(config, rootpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
//// Backward compatibility with wxHelpController API
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::Initialize(const wxString& file)
|
||||||
|
{
|
||||||
|
wxString dir, filename, ext;
|
||||||
|
wxSplitPath(file, & dir, & filename, & ext);
|
||||||
|
|
||||||
|
if (!dir.IsEmpty())
|
||||||
|
dir = dir + wxFILE_SEP_PATH;
|
||||||
|
|
||||||
|
// Try to find a suitable file
|
||||||
|
wxString actualFilename = dir + filename + wxString(wxT(".zip"));
|
||||||
|
if (!wxFileExists(actualFilename))
|
||||||
|
{
|
||||||
|
actualFilename = dir + filename + wxString(wxT(".htb"));
|
||||||
|
if (!wxFileExists(actualFilename))
|
||||||
|
{
|
||||||
|
actualFilename = dir + filename + wxString(wxT(".hhp"));
|
||||||
|
if (!wxFileExists(actualFilename))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return AddBook(wxFileName(actualFilename));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
|
||||||
|
{
|
||||||
|
// Don't reload the file or we'll have it appear again, presumably.
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::DisplaySection(int sectionNo)
|
||||||
|
{
|
||||||
|
return Display(sectionNo);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
|
||||||
|
{
|
||||||
|
#if wxUSE_TIPWINDOW
|
||||||
|
static wxTipWindow* s_tipWindow = NULL;
|
||||||
|
|
||||||
|
if (s_tipWindow)
|
||||||
|
{
|
||||||
|
// Prevent s_tipWindow being nulled in OnIdle,
|
||||||
|
// thereby removing the chance for the window to be closed by ShowHelp
|
||||||
|
s_tipWindow->SetTipWindowPtr(NULL);
|
||||||
|
s_tipWindow->Close();
|
||||||
|
}
|
||||||
|
s_tipWindow = NULL;
|
||||||
|
|
||||||
|
if ( !text.empty() )
|
||||||
|
{
|
||||||
|
s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
#endif // wxUSE_TIPWINDOW
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlHelpController::SetFrameParameters(const wxString& title,
|
||||||
|
const wxSize& size,
|
||||||
|
const wxPoint& pos,
|
||||||
|
bool WXUNUSED(newFrameEachTime))
|
||||||
|
{
|
||||||
|
SetTitleFormat(title);
|
||||||
|
if (m_helpFrame)
|
||||||
|
{
|
||||||
|
m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
|
||||||
|
wxPoint *pos,
|
||||||
|
bool *newFrameEachTime)
|
||||||
|
{
|
||||||
|
if (newFrameEachTime)
|
||||||
|
(* newFrameEachTime) = FALSE;
|
||||||
|
if (size && m_helpFrame)
|
||||||
|
(* size) = m_helpFrame->GetSize();
|
||||||
|
if (pos && m_helpFrame)
|
||||||
|
(* pos) = m_helpFrame->GetPosition();
|
||||||
|
return m_helpFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::Quit()
|
||||||
|
{
|
||||||
|
DestroyHelpWindow();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the help controller's frame 'modal' if
|
||||||
|
// needed
|
||||||
|
void wxHtmlHelpController::AddGrabIfNeeded()
|
||||||
|
{
|
||||||
|
// So far, wxGTK only
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
bool needGrab = FALSE;
|
||||||
|
|
||||||
|
// Check if there are any modal windows present,
|
||||||
|
// in which case we need to add a grab.
|
||||||
|
for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
|
||||||
|
node;
|
||||||
|
node = node->GetNext() )
|
||||||
|
{
|
||||||
|
wxWindow *win = node->GetData();
|
||||||
|
wxDialog *dialog = wxDynamicCast(win, wxDialog);
|
||||||
|
|
||||||
|
if (dialog && dialog->IsModal())
|
||||||
|
needGrab = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needGrab && m_helpFrame)
|
||||||
|
m_helpFrame->AddGrab();
|
||||||
|
#endif // __WXGTK__
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::Display(const wxString& x)
|
||||||
|
{
|
||||||
|
CreateHelpWindow();
|
||||||
|
bool success = m_helpFrame->Display(x);
|
||||||
|
AddGrabIfNeeded();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::Display(int id)
|
||||||
|
{
|
||||||
|
CreateHelpWindow();
|
||||||
|
bool success = m_helpFrame->Display(id);
|
||||||
|
AddGrabIfNeeded();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::DisplayContents()
|
||||||
|
{
|
||||||
|
CreateHelpWindow();
|
||||||
|
bool success = m_helpFrame->DisplayContents();
|
||||||
|
AddGrabIfNeeded();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::DisplayIndex()
|
||||||
|
{
|
||||||
|
CreateHelpWindow();
|
||||||
|
bool success = m_helpFrame->DisplayIndex();
|
||||||
|
AddGrabIfNeeded();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpController::KeywordSearch(const wxString& keyword)
|
||||||
|
{
|
||||||
|
CreateHelpWindow();
|
||||||
|
bool success = m_helpFrame->KeywordSearch(keyword);
|
||||||
|
AddGrabIfNeeded();
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxUSE_WXHTML_HELP
|
||||||
|
|
866
Contrib/NSIS Menu/src/html/helpdata.cpp
Normal file
866
Contrib/NSIS Menu/src/html/helpdata.cpp
Normal file
|
@ -0,0 +1,866 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: helpdata.cpp
|
||||||
|
// Purpose: wxHtmlHelpData
|
||||||
|
// Notes: Based on htmlhelp.cpp, implementing a monolithic
|
||||||
|
// HTML Help controller class, by Vaclav Slavik
|
||||||
|
// Author: Harm van der Heijden and Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: helpdata.cpp,v 1.59.2.5 2002/12/16 10:23:20 JS Exp $
|
||||||
|
// Copyright: (c) Harm van der Heijden and Vaclav Slavik
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "helpdata.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#include "wx/intl.h"
|
||||||
|
#include "wx/log.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "wx/html/helpdata.h"
|
||||||
|
#include "wx/tokenzr.h"
|
||||||
|
#include "wx/wfstream.h"
|
||||||
|
#include "wx/busyinfo.h"
|
||||||
|
#include "wx/encconv.h"
|
||||||
|
#include "wx/fontmap.h"
|
||||||
|
#include "wx/log.h"
|
||||||
|
#include "wx/html/htmlpars.h"
|
||||||
|
#include "wx/html/htmldefs.h"
|
||||||
|
#include "wx/html/htmlfilt.h"
|
||||||
|
#include "wx/filename.h"
|
||||||
|
|
||||||
|
#include "wx/arrimpl.cpp"
|
||||||
|
WX_DEFINE_OBJARRAY(wxHtmlBookRecArray)
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// static helper functions
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Reads one line, stores it into buf and returns pointer to new line or NULL.
|
||||||
|
static const wxChar* ReadLine(const wxChar *line, wxChar *buf, size_t bufsize)
|
||||||
|
{
|
||||||
|
wxChar *writeptr = buf;
|
||||||
|
wxChar *endptr = buf + bufsize - 1;
|
||||||
|
const wxChar *readptr = line;
|
||||||
|
|
||||||
|
while (*readptr != 0 && *readptr != _T('\r') && *readptr != _T('\n') &&
|
||||||
|
writeptr != endptr)
|
||||||
|
*(writeptr++) = *(readptr++);
|
||||||
|
*writeptr = 0;
|
||||||
|
while (*readptr == _T('\r') || *readptr == _T('\n'))
|
||||||
|
readptr++;
|
||||||
|
if (*readptr == 0)
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return readptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" int LINKAGEMODE
|
||||||
|
wxHtmlHelpIndexCompareFunc(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
return wxStricmp(((wxHtmlContentsItem*)a)->m_Name, ((wxHtmlContentsItem*)b)->m_Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// HP_Parser
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class HP_Parser : public wxHtmlParser
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxObject* GetProduct() { return NULL; }
|
||||||
|
protected:
|
||||||
|
virtual void AddText(const wxChar* WXUNUSED(txt)) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// HP_TagHandler
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class HP_TagHandler : public wxHtmlTagHandler
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
wxString m_Name, m_Page;
|
||||||
|
int m_Level;
|
||||||
|
int m_ID;
|
||||||
|
int m_Index;
|
||||||
|
wxHtmlContentsItem *m_Items;
|
||||||
|
int m_ItemsCnt;
|
||||||
|
wxHtmlBookRecord *m_Book;
|
||||||
|
|
||||||
|
public:
|
||||||
|
HP_TagHandler(wxHtmlBookRecord *b) : wxHtmlTagHandler()
|
||||||
|
{ m_Book = b; m_Items = NULL; m_ItemsCnt = 0; m_Name = m_Page = wxEmptyString;
|
||||||
|
m_Level = 0; m_ID = -1; }
|
||||||
|
wxString GetSupportedTags() { return wxT("UL,OBJECT,PARAM"); }
|
||||||
|
bool HandleTag(const wxHtmlTag& tag);
|
||||||
|
void WriteOut(wxHtmlContentsItem*& array, int& size);
|
||||||
|
void ReadIn(wxHtmlContentsItem* array, int size);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
bool HP_TagHandler::HandleTag(const wxHtmlTag& tag)
|
||||||
|
{
|
||||||
|
if (tag.GetName() == wxT("UL"))
|
||||||
|
{
|
||||||
|
m_Level++;
|
||||||
|
ParseInner(tag);
|
||||||
|
m_Level--;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else if (tag.GetName() == wxT("OBJECT"))
|
||||||
|
{
|
||||||
|
m_Name = m_Page = wxEmptyString;
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (!m_Page.IsEmpty())
|
||||||
|
/* Valid HHW's file may contain only two object tags:
|
||||||
|
|
||||||
|
<OBJECT type="text/site properties">
|
||||||
|
<param name="ImageType" value="Folder">
|
||||||
|
</OBJECT>
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
<OBJECT type="text/sitemap">
|
||||||
|
<param name="Name" value="main page">
|
||||||
|
<param name="Local" value="another.htm">
|
||||||
|
</OBJECT>
|
||||||
|
|
||||||
|
We're interested in the latter. !m_Page.IsEmpty() is valid
|
||||||
|
condition because text/site properties does not contain Local param
|
||||||
|
*/
|
||||||
|
#endif
|
||||||
|
if (tag.GetParam(wxT("TYPE")) == wxT("text/sitemap"))
|
||||||
|
{
|
||||||
|
if (m_ItemsCnt % wxHTML_REALLOC_STEP == 0)
|
||||||
|
m_Items = (wxHtmlContentsItem*) realloc(m_Items,
|
||||||
|
(m_ItemsCnt + wxHTML_REALLOC_STEP) *
|
||||||
|
sizeof(wxHtmlContentsItem));
|
||||||
|
|
||||||
|
m_Items[m_ItemsCnt].m_Level = m_Level;
|
||||||
|
m_Items[m_ItemsCnt].m_ID = m_ID;
|
||||||
|
m_Items[m_ItemsCnt].m_Page = new wxChar[m_Page.Length() + 1];
|
||||||
|
wxStrcpy(m_Items[m_ItemsCnt].m_Page, m_Page.c_str());
|
||||||
|
m_Items[m_ItemsCnt].m_Name = new wxChar [m_Name.Length() + 1];
|
||||||
|
wxStrcpy(m_Items[m_ItemsCnt].m_Name, m_Name.c_str());
|
||||||
|
m_Items[m_ItemsCnt].m_Book = m_Book;
|
||||||
|
m_ItemsCnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // "PARAM"
|
||||||
|
if (m_Name == wxEmptyString && tag.GetParam(wxT("NAME")) == wxT("Name"))
|
||||||
|
m_Name = tag.GetParam(wxT("VALUE"));
|
||||||
|
if (tag.GetParam(wxT("NAME")) == wxT("Local"))
|
||||||
|
m_Page = tag.GetParam(wxT("VALUE"));
|
||||||
|
if (tag.GetParam(wxT("NAME")) == wxT("ID"))
|
||||||
|
tag.GetParamAsInt(wxT("VALUE"), &m_ID);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void HP_TagHandler::WriteOut(wxHtmlContentsItem*& array, int& size)
|
||||||
|
{
|
||||||
|
array = m_Items;
|
||||||
|
size = m_ItemsCnt;
|
||||||
|
m_Items = NULL;
|
||||||
|
m_ItemsCnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HP_TagHandler::ReadIn(wxHtmlContentsItem* array, int size)
|
||||||
|
{
|
||||||
|
m_Items = array;
|
||||||
|
m_ItemsCnt = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlHelpData
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxString wxHtmlBookRecord::GetFullPath(const wxString &page) const
|
||||||
|
{
|
||||||
|
if (wxIsAbsolutePath(page))
|
||||||
|
return page;
|
||||||
|
else
|
||||||
|
return m_BasePath + page;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpData, wxObject)
|
||||||
|
|
||||||
|
wxHtmlHelpData::wxHtmlHelpData()
|
||||||
|
{
|
||||||
|
m_TempPath = wxEmptyString;
|
||||||
|
|
||||||
|
m_Contents = NULL;
|
||||||
|
m_ContentsCnt = 0;
|
||||||
|
m_Index = NULL;
|
||||||
|
m_IndexCnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlHelpData::~wxHtmlHelpData()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
m_BookRecords.Empty();
|
||||||
|
if (m_Contents)
|
||||||
|
{
|
||||||
|
for (i = 0; i < m_ContentsCnt; i++)
|
||||||
|
{
|
||||||
|
delete[] m_Contents[i].m_Page;
|
||||||
|
delete[] m_Contents[i].m_Name;
|
||||||
|
}
|
||||||
|
free(m_Contents);
|
||||||
|
}
|
||||||
|
if (m_Index)
|
||||||
|
{
|
||||||
|
for (i = 0; i < m_IndexCnt; i++)
|
||||||
|
{
|
||||||
|
delete[] m_Index[i].m_Page;
|
||||||
|
delete[] m_Index[i].m_Name;
|
||||||
|
}
|
||||||
|
free(m_Index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, const wxString& indexfile, const wxString& contentsfile)
|
||||||
|
{
|
||||||
|
wxFSFile *f;
|
||||||
|
wxHtmlFilterHTML filter;
|
||||||
|
wxString buf;
|
||||||
|
wxString string;
|
||||||
|
|
||||||
|
HP_Parser parser;
|
||||||
|
HP_TagHandler *handler = new HP_TagHandler(book);
|
||||||
|
parser.AddTagHandler(handler);
|
||||||
|
|
||||||
|
f = ( contentsfile.IsEmpty() ? (wxFSFile*) NULL : fsys.OpenFile(contentsfile) );
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
buf.clear();
|
||||||
|
buf = filter.ReadFile(*f);
|
||||||
|
delete f;
|
||||||
|
handler->ReadIn(m_Contents, m_ContentsCnt);
|
||||||
|
parser.Parse(buf);
|
||||||
|
handler->WriteOut(m_Contents, m_ContentsCnt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxLogError(_("Cannot open contents file: %s"), contentsfile.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
f = ( indexfile.IsEmpty() ? (wxFSFile*) NULL : fsys.OpenFile(indexfile) );
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
buf.clear();
|
||||||
|
buf = filter.ReadFile(*f);
|
||||||
|
delete f;
|
||||||
|
handler->ReadIn(m_Index, m_IndexCnt);
|
||||||
|
parser.Parse(buf);
|
||||||
|
handler->WriteOut(m_Index, m_IndexCnt);
|
||||||
|
}
|
||||||
|
else if (!indexfile.IsEmpty())
|
||||||
|
{
|
||||||
|
wxLogError(_("Cannot open index file: %s"), indexfile.c_str());
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
inline static void CacheWriteInt32(wxOutputStream *f, wxInt32 value)
|
||||||
|
{
|
||||||
|
wxInt32 x = wxINT32_SWAP_ON_BE(value);
|
||||||
|
f->Write(&x, sizeof(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static wxInt32 CacheReadInt32(wxInputStream *f)
|
||||||
|
{
|
||||||
|
wxInt32 x;
|
||||||
|
f->Read(&x, sizeof(x));
|
||||||
|
return wxINT32_SWAP_ON_BE(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static void CacheWriteString(wxOutputStream *f, const wxChar *str)
|
||||||
|
{
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
wxWX2MBbuf mbstr(wxConvUTF8.cWX2MB(str));
|
||||||
|
#else
|
||||||
|
const wxChar *mbstr = str;
|
||||||
|
#endif
|
||||||
|
size_t len = strlen(mbstr)+1;
|
||||||
|
CacheWriteInt32(f, len);
|
||||||
|
f->Write(mbstr, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static wxChar* CacheReadString(wxInputStream *f)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
size_t len = (size_t)CacheReadInt32(f);
|
||||||
|
str = new char[len];
|
||||||
|
f->Read(str, len);
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
return str;
|
||||||
|
#else
|
||||||
|
wxMB2WXbuf wxstr(wxConvUTF8.cMB2WX(str));
|
||||||
|
wxChar *outstr = new wxChar[wxStrlen(wxstr)+1];
|
||||||
|
wxStrcpy(outstr, wxstr);
|
||||||
|
return outstr;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CURRENT_CACHED_BOOK_VERSION 3
|
||||||
|
|
||||||
|
bool wxHtmlHelpData::LoadCachedBook(wxHtmlBookRecord *book, wxInputStream *f)
|
||||||
|
{
|
||||||
|
int i, st;
|
||||||
|
wxInt32 version;
|
||||||
|
|
||||||
|
/* load header - version info : */
|
||||||
|
version = CacheReadInt32(f);
|
||||||
|
|
||||||
|
if (version != CURRENT_CACHED_BOOK_VERSION)
|
||||||
|
{
|
||||||
|
// NB: We can just silently return FALSE here and don't worry about
|
||||||
|
// it anymore, because AddBookParam will load the MS project in
|
||||||
|
// absence of (properly versioned) .cached file and automatically
|
||||||
|
// create new .cached file immediately afterward.
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* load contents : */
|
||||||
|
st = m_ContentsCnt;
|
||||||
|
m_ContentsCnt += CacheReadInt32(f);
|
||||||
|
m_Contents = (wxHtmlContentsItem*) realloc(m_Contents,
|
||||||
|
(m_ContentsCnt / wxHTML_REALLOC_STEP + 1) *
|
||||||
|
wxHTML_REALLOC_STEP * sizeof(wxHtmlContentsItem));
|
||||||
|
for (i = st; i < m_ContentsCnt; i++)
|
||||||
|
{
|
||||||
|
m_Contents[i].m_Level = CacheReadInt32(f);
|
||||||
|
m_Contents[i].m_ID = CacheReadInt32(f);
|
||||||
|
m_Contents[i].m_Name = CacheReadString(f);
|
||||||
|
m_Contents[i].m_Page = CacheReadString(f);
|
||||||
|
m_Contents[i].m_Book = book;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* load index : */
|
||||||
|
st = m_IndexCnt;
|
||||||
|
m_IndexCnt += CacheReadInt32(f);
|
||||||
|
m_Index = (wxHtmlContentsItem*) realloc(m_Index, (m_IndexCnt / wxHTML_REALLOC_STEP + 1) *
|
||||||
|
wxHTML_REALLOC_STEP * sizeof(wxHtmlContentsItem));
|
||||||
|
for (i = st; i < m_IndexCnt; i++)
|
||||||
|
{
|
||||||
|
m_Index[i].m_Name = CacheReadString(f);
|
||||||
|
m_Index[i].m_Page = CacheReadString(f);
|
||||||
|
m_Index[i].m_Book = book;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlHelpData::SaveCachedBook(wxHtmlBookRecord *book, wxOutputStream *f)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
wxInt32 cnt;
|
||||||
|
|
||||||
|
/* save header - version info : */
|
||||||
|
CacheWriteInt32(f, CURRENT_CACHED_BOOK_VERSION);
|
||||||
|
|
||||||
|
/* save contents : */
|
||||||
|
for (cnt = 0, i = 0; i < m_ContentsCnt; i++)
|
||||||
|
if (m_Contents[i].m_Book == book && m_Contents[i].m_Level > 0)
|
||||||
|
cnt++;
|
||||||
|
CacheWriteInt32(f, cnt);
|
||||||
|
|
||||||
|
for (i = 0; i < m_ContentsCnt; i++)
|
||||||
|
{
|
||||||
|
if (m_Contents[i].m_Book != book || m_Contents[i].m_Level == 0)
|
||||||
|
continue;
|
||||||
|
CacheWriteInt32(f, m_Contents[i].m_Level);
|
||||||
|
CacheWriteInt32(f, m_Contents[i].m_ID);
|
||||||
|
CacheWriteString(f, m_Contents[i].m_Name);
|
||||||
|
CacheWriteString(f, m_Contents[i].m_Page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* save index : */
|
||||||
|
for (cnt = 0, i = 0; i < m_IndexCnt; i++)
|
||||||
|
if (m_Index[i].m_Book == book && m_Index[i].m_Level > 0)
|
||||||
|
cnt++;
|
||||||
|
CacheWriteInt32(f, cnt);
|
||||||
|
|
||||||
|
for (i = 0; i < m_IndexCnt; i++)
|
||||||
|
{
|
||||||
|
if (m_Index[i].m_Book != book || m_Index[i].m_Level == 0)
|
||||||
|
continue;
|
||||||
|
CacheWriteString(f, m_Index[i].m_Name);
|
||||||
|
CacheWriteString(f, m_Index[i].m_Page);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlHelpData::SetTempDir(const wxString& path)
|
||||||
|
{
|
||||||
|
if (path == wxEmptyString) m_TempPath = path;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (wxIsAbsolutePath(path)) m_TempPath = path;
|
||||||
|
else m_TempPath = wxGetCwd() + _T("/") + path;
|
||||||
|
|
||||||
|
if (m_TempPath[m_TempPath.Length() - 1] != _T('/'))
|
||||||
|
m_TempPath << _T('/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static wxString SafeFileName(const wxString& s)
|
||||||
|
{
|
||||||
|
wxString res(s);
|
||||||
|
res.Replace(wxT("#"), wxT("_"));
|
||||||
|
res.Replace(wxT(":"), wxT("_"));
|
||||||
|
res.Replace(wxT("\\"), wxT("_"));
|
||||||
|
res.Replace(wxT("/"), wxT("_"));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile,
|
||||||
|
wxFontEncoding encoding,
|
||||||
|
const wxString& title, const wxString& contfile,
|
||||||
|
const wxString& indexfile, const wxString& deftopic,
|
||||||
|
const wxString& path)
|
||||||
|
{
|
||||||
|
wxFileSystem fsys;
|
||||||
|
wxFSFile *fi;
|
||||||
|
wxHtmlBookRecord *bookr;
|
||||||
|
|
||||||
|
int IndexOld = m_IndexCnt,
|
||||||
|
ContentsOld = m_ContentsCnt;
|
||||||
|
|
||||||
|
if (!path.IsEmpty())
|
||||||
|
fsys.ChangePathTo(path, TRUE);
|
||||||
|
|
||||||
|
size_t booksCnt = m_BookRecords.GetCount();
|
||||||
|
for (size_t i = 0; i < booksCnt; i++)
|
||||||
|
{
|
||||||
|
if ( m_BookRecords[i].GetBookFile() == bookfile.GetLocation() )
|
||||||
|
return TRUE; // book is (was) loaded
|
||||||
|
}
|
||||||
|
|
||||||
|
bookr = new wxHtmlBookRecord(bookfile.GetLocation(), fsys.GetPath(), title, deftopic);
|
||||||
|
|
||||||
|
if (m_ContentsCnt % wxHTML_REALLOC_STEP == 0)
|
||||||
|
m_Contents = (wxHtmlContentsItem*) realloc(m_Contents, (m_ContentsCnt + wxHTML_REALLOC_STEP) * sizeof(wxHtmlContentsItem));
|
||||||
|
m_Contents[m_ContentsCnt].m_Level = 0;
|
||||||
|
m_Contents[m_ContentsCnt].m_ID = 0;
|
||||||
|
m_Contents[m_ContentsCnt].m_Page = new wxChar[deftopic.Length() + 1];
|
||||||
|
wxStrcpy(m_Contents[m_ContentsCnt].m_Page, deftopic.c_str());
|
||||||
|
m_Contents[m_ContentsCnt].m_Name = new wxChar [title.Length() + 1];
|
||||||
|
wxStrcpy(m_Contents[m_ContentsCnt].m_Name, title.c_str());
|
||||||
|
m_Contents[m_ContentsCnt].m_Book = bookr;
|
||||||
|
|
||||||
|
// store the contents index for later
|
||||||
|
int cont_start = m_ContentsCnt++;
|
||||||
|
|
||||||
|
// Try to find cached binary versions:
|
||||||
|
// 1. save file as book, but with .hhp.cached extension
|
||||||
|
// 2. same as 1. but in temp path
|
||||||
|
// 3. otherwise or if cache load failed, load it from MS.
|
||||||
|
|
||||||
|
fi = fsys.OpenFile(bookfile.GetLocation() + wxT(".cached"));
|
||||||
|
|
||||||
|
if (fi == NULL ||
|
||||||
|
fi->GetModificationTime() < bookfile.GetModificationTime() ||
|
||||||
|
!LoadCachedBook(bookr, fi->GetStream()))
|
||||||
|
{
|
||||||
|
if (fi != NULL) delete fi;
|
||||||
|
fi = fsys.OpenFile(m_TempPath + wxFileNameFromPath(bookfile.GetLocation()) + wxT(".cached"));
|
||||||
|
if (m_TempPath == wxEmptyString || fi == NULL ||
|
||||||
|
fi->GetModificationTime() < bookfile.GetModificationTime() ||
|
||||||
|
!LoadCachedBook(bookr, fi->GetStream()))
|
||||||
|
{
|
||||||
|
LoadMSProject(bookr, fsys, indexfile, contfile);
|
||||||
|
if (m_TempPath != wxEmptyString)
|
||||||
|
{
|
||||||
|
wxFileOutputStream *outs = new wxFileOutputStream(m_TempPath +
|
||||||
|
SafeFileName(wxFileNameFromPath(bookfile.GetLocation())) + wxT(".cached"));
|
||||||
|
SaveCachedBook(bookr, outs);
|
||||||
|
delete outs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fi != NULL) delete fi;
|
||||||
|
|
||||||
|
// Now store the contents range
|
||||||
|
bookr->SetContentsRange(cont_start, m_ContentsCnt);
|
||||||
|
|
||||||
|
// Convert encoding, if neccessary:
|
||||||
|
if (encoding != wxFONTENCODING_SYSTEM)
|
||||||
|
{
|
||||||
|
wxFontEncodingArray a = wxEncodingConverter::GetPlatformEquivalents(encoding);
|
||||||
|
if (a.GetCount() != 0 && a[0] != encoding)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
wxEncodingConverter conv;
|
||||||
|
conv.Init(encoding, a[0]);
|
||||||
|
|
||||||
|
for (i = IndexOld; i < m_IndexCnt; i++)
|
||||||
|
conv.Convert(m_Index[i].m_Name);
|
||||||
|
for (i = ContentsOld; i < m_ContentsCnt; i++)
|
||||||
|
conv.Convert(m_Contents[i].m_Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_BookRecords.Add(bookr);
|
||||||
|
if (m_IndexCnt > 0)
|
||||||
|
qsort(m_Index, m_IndexCnt, sizeof(wxHtmlContentsItem), wxHtmlHelpIndexCompareFunc);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlHelpData::AddBook(const wxString& book)
|
||||||
|
{
|
||||||
|
if (book.Right(4).Lower() == wxT(".zip") ||
|
||||||
|
book.Right(4).Lower() == wxT(".htb") /*html book*/)
|
||||||
|
{
|
||||||
|
wxFileSystem fsys;
|
||||||
|
wxString s;
|
||||||
|
bool rt = FALSE;
|
||||||
|
|
||||||
|
s = fsys.FindFirst(book + wxT("#zip:") + wxT("*.hhp"), wxFILE);
|
||||||
|
while (!s.IsEmpty())
|
||||||
|
{
|
||||||
|
if (AddBook(s)) rt = TRUE;
|
||||||
|
s = fsys.FindNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rt;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxFSFile *fi;
|
||||||
|
wxFileSystem fsys;
|
||||||
|
|
||||||
|
wxString title = _("noname"),
|
||||||
|
safetitle,
|
||||||
|
start = wxEmptyString,
|
||||||
|
contents = wxEmptyString,
|
||||||
|
index = wxEmptyString,
|
||||||
|
charset = wxEmptyString;
|
||||||
|
|
||||||
|
fi = fsys.OpenFile(book);
|
||||||
|
if (fi == NULL)
|
||||||
|
{
|
||||||
|
wxLogError(_("Cannot open HTML help book: %s"), book.c_str());
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
fsys.ChangePathTo(book);
|
||||||
|
|
||||||
|
const wxChar *lineptr;
|
||||||
|
wxChar linebuf[300];
|
||||||
|
wxString tmp;
|
||||||
|
wxHtmlFilterPlainText filter;
|
||||||
|
tmp = filter.ReadFile(*fi);
|
||||||
|
lineptr = tmp.c_str();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
lineptr = ReadLine(lineptr, linebuf, 300);
|
||||||
|
|
||||||
|
for (wxChar *ch = linebuf; *ch != wxT('\0') && *ch != wxT('='); ch++)
|
||||||
|
*ch = tolower(*ch);
|
||||||
|
|
||||||
|
if (wxStrstr(linebuf, _T("title=")) == linebuf)
|
||||||
|
title = linebuf + wxStrlen(_T("title="));
|
||||||
|
if (wxStrstr(linebuf, _T("default topic=")) == linebuf)
|
||||||
|
start = linebuf + wxStrlen(_T("default topic="));
|
||||||
|
if (wxStrstr(linebuf, _T("index file=")) == linebuf)
|
||||||
|
index = linebuf + wxStrlen(_T("index file="));
|
||||||
|
if (wxStrstr(linebuf, _T("contents file=")) == linebuf)
|
||||||
|
contents = linebuf + wxStrlen(_T("contents file="));
|
||||||
|
if (wxStrstr(linebuf, _T("charset=")) == linebuf)
|
||||||
|
charset = linebuf + wxStrlen(_T("charset="));
|
||||||
|
} while (lineptr != NULL);
|
||||||
|
|
||||||
|
wxFontEncoding enc;
|
||||||
|
if (charset == wxEmptyString) enc = wxFONTENCODING_SYSTEM;
|
||||||
|
else enc = wxFontMapper::Get()->CharsetToEncoding(charset);
|
||||||
|
bool rtval = AddBookParam(*fi, enc,
|
||||||
|
title, contents, index, start, fsys.GetPath());
|
||||||
|
delete fi;
|
||||||
|
return rtval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxHtmlHelpData::FindPageByName(const wxString& x)
|
||||||
|
{
|
||||||
|
int cnt;
|
||||||
|
int i;
|
||||||
|
wxFileSystem fsys;
|
||||||
|
wxFSFile *f;
|
||||||
|
wxString url(wxEmptyString);
|
||||||
|
|
||||||
|
/* 1. try to open given file: */
|
||||||
|
|
||||||
|
cnt = m_BookRecords.GetCount();
|
||||||
|
for (i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
f = fsys.OpenFile(m_BookRecords[i].GetFullPath(x));
|
||||||
|
if (f)
|
||||||
|
{
|
||||||
|
url = m_BookRecords[i].GetFullPath(x);
|
||||||
|
delete f;
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* 2. try to find a book: */
|
||||||
|
|
||||||
|
for (i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
if (m_BookRecords[i].GetTitle() == x)
|
||||||
|
{
|
||||||
|
url = m_BookRecords[i].GetFullPath(m_BookRecords[i].GetStart());
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 3. try to find in contents: */
|
||||||
|
|
||||||
|
cnt = m_ContentsCnt;
|
||||||
|
for (i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
if (wxStrcmp(m_Contents[i].m_Name, x) == 0)
|
||||||
|
{
|
||||||
|
url = m_Contents[i].GetFullPath();
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* 4. try to find in index: */
|
||||||
|
|
||||||
|
cnt = m_IndexCnt;
|
||||||
|
for (i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
if (wxStrcmp(m_Index[i].m_Name, x) == 0)
|
||||||
|
{
|
||||||
|
url = m_Index[i].GetFullPath();
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxHtmlHelpData::FindPageById(int id)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
wxString url(wxEmptyString);
|
||||||
|
|
||||||
|
for (i = 0; i < m_ContentsCnt; i++)
|
||||||
|
{
|
||||||
|
if (m_Contents[i].m_ID == id)
|
||||||
|
{
|
||||||
|
url = m_Contents[i].GetFullPath();
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// wxHtmlSearchStatus functions
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData* data, const wxString& keyword,
|
||||||
|
bool case_sensitive, bool whole_words_only,
|
||||||
|
const wxString& book)
|
||||||
|
{
|
||||||
|
m_Data = data;
|
||||||
|
m_Keyword = keyword;
|
||||||
|
wxHtmlBookRecord* bookr = NULL;
|
||||||
|
if (book != wxEmptyString)
|
||||||
|
{
|
||||||
|
// we have to search in a specific book. Find it first
|
||||||
|
int i, cnt = data->m_BookRecords.GetCount();
|
||||||
|
for (i = 0; i < cnt; i++)
|
||||||
|
if (data->m_BookRecords[i].GetTitle() == book)
|
||||||
|
{
|
||||||
|
bookr = &(data->m_BookRecords[i]);
|
||||||
|
m_CurIndex = bookr->GetContentsStart();
|
||||||
|
m_MaxIndex = bookr->GetContentsEnd();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// check; we won't crash if the book doesn't exist, but it's Bad Anyway.
|
||||||
|
wxASSERT(bookr);
|
||||||
|
}
|
||||||
|
if (! bookr)
|
||||||
|
{
|
||||||
|
// no book specified; search all books
|
||||||
|
m_CurIndex = 0;
|
||||||
|
m_MaxIndex = m_Data->m_ContentsCnt;
|
||||||
|
}
|
||||||
|
m_Engine.LookFor(keyword, case_sensitive, whole_words_only);
|
||||||
|
m_Active = (m_CurIndex < m_MaxIndex);
|
||||||
|
m_LastPage = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlSearchStatus::Search()
|
||||||
|
{
|
||||||
|
wxFSFile *file;
|
||||||
|
int i = m_CurIndex; // shortcut
|
||||||
|
bool found = FALSE;
|
||||||
|
wxChar *thepage;
|
||||||
|
|
||||||
|
if (!m_Active)
|
||||||
|
{
|
||||||
|
// sanity check. Illegal use, but we'll try to prevent a crash anyway
|
||||||
|
wxASSERT(m_Active);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Name = wxEmptyString;
|
||||||
|
m_ContentsItem = NULL;
|
||||||
|
thepage = m_Data->m_Contents[i].m_Page;
|
||||||
|
|
||||||
|
m_Active = (++m_CurIndex < m_MaxIndex);
|
||||||
|
// check if it is same page with different anchor:
|
||||||
|
if (m_LastPage != NULL)
|
||||||
|
{
|
||||||
|
wxChar *p1, *p2;
|
||||||
|
for (p1 = thepage, p2 = m_LastPage;
|
||||||
|
*p1 != 0 && *p1 != _T('#') && *p1 == *p2; p1++, p2++) {}
|
||||||
|
|
||||||
|
m_LastPage = thepage;
|
||||||
|
|
||||||
|
if (*p1 == 0 || *p1 == _T('#'))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else m_LastPage = thepage;
|
||||||
|
|
||||||
|
wxFileSystem fsys;
|
||||||
|
file = fsys.OpenFile(m_Data->m_Contents[i].m_Book->GetFullPath(thepage));
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
|
if (m_Engine.Scan(*file))
|
||||||
|
{
|
||||||
|
m_Name = m_Data->m_Contents[i].m_Name;
|
||||||
|
m_ContentsItem = m_Data->m_Contents + i;
|
||||||
|
found = TRUE;
|
||||||
|
}
|
||||||
|
delete file;
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlSearchEngine
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void wxHtmlSearchEngine::LookFor(const wxString& keyword, bool case_sensitive, bool whole_words_only)
|
||||||
|
{
|
||||||
|
m_CaseSensitive = case_sensitive;
|
||||||
|
m_WholeWords = whole_words_only;
|
||||||
|
if (m_Keyword) delete[] m_Keyword;
|
||||||
|
m_Keyword = new wxChar[keyword.Length() + 1];
|
||||||
|
wxStrcpy(m_Keyword, keyword.c_str());
|
||||||
|
|
||||||
|
if (!m_CaseSensitive)
|
||||||
|
{
|
||||||
|
for (int i = wxStrlen(m_Keyword) - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if ((m_Keyword[i] >= wxT('A')) && (m_Keyword[i] <= wxT('Z')))
|
||||||
|
m_Keyword[i] += wxT('a') - wxT('A');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline bool WHITESPACE(wxChar c)
|
||||||
|
{
|
||||||
|
return c == _T(' ') || c == _T('\n') || c == _T('\r') || c == _T('\t');
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlSearchEngine::Scan(const wxFSFile& file)
|
||||||
|
{
|
||||||
|
wxASSERT_MSG(m_Keyword != NULL, wxT("wxHtmlSearchEngine::LookFor must be called before scanning!"));
|
||||||
|
|
||||||
|
int i, j;
|
||||||
|
int wrd = wxStrlen(m_Keyword);
|
||||||
|
bool found = FALSE;
|
||||||
|
wxHtmlFilterHTML filter;
|
||||||
|
wxString tmp = filter.ReadFile(file);
|
||||||
|
int lng = tmp.length();
|
||||||
|
const wxChar *buf = tmp.c_str();
|
||||||
|
|
||||||
|
if (!m_CaseSensitive)
|
||||||
|
for (i = 0; i < lng; i++)
|
||||||
|
tmp[(size_t)i] = (wxChar)wxTolower(tmp[(size_t)i]);
|
||||||
|
|
||||||
|
if (m_WholeWords)
|
||||||
|
{
|
||||||
|
for (i = 0; i < lng - wrd; i++)
|
||||||
|
{
|
||||||
|
if (WHITESPACE(buf[i])) continue;
|
||||||
|
j = 0;
|
||||||
|
while ((j < wrd) && (buf[i + j] == m_Keyword[j])) j++;
|
||||||
|
if (j == wrd && WHITESPACE(buf[i + j])) { found = TRUE; break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < lng - wrd; i++)
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while ((j < wrd) && (buf[i + j] == m_Keyword[j])) j++;
|
||||||
|
if (j == wrd) { found = TRUE; break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
1515
Contrib/NSIS Menu/src/html/helpfrm.cpp
Normal file
1515
Contrib/NSIS Menu/src/html/helpfrm.cpp
Normal file
File diff suppressed because it is too large
Load diff
728
Contrib/NSIS Menu/src/html/htmlcell.cpp
Normal file
728
Contrib/NSIS Menu/src/html/htmlcell.cpp
Normal file
|
@ -0,0 +1,728 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: htmlcell.cpp
|
||||||
|
// Purpose: wxHtmlCell - basic element of HTML output
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: htmlcell.cpp,v 1.50.2.10 2002/12/19 22:15:45 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "htmlcell.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#include "wx/brush.h"
|
||||||
|
#include "wx/colour.h"
|
||||||
|
#include "wx/dc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/htmlcell.h"
|
||||||
|
#include "wx/html/htmlwin.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlCell
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxHtmlCell::wxHtmlCell() : wxObject()
|
||||||
|
{
|
||||||
|
m_Next = NULL;
|
||||||
|
m_Parent = NULL;
|
||||||
|
m_Width = m_Height = m_Descent = 0;
|
||||||
|
m_CanLiveOnPagebreak = TRUE;
|
||||||
|
m_Link = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlCell::~wxHtmlCell()
|
||||||
|
{
|
||||||
|
delete m_Link;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlCell::OnMouseClick(wxWindow *parent, int x, int y,
|
||||||
|
const wxMouseEvent& event)
|
||||||
|
{
|
||||||
|
wxHtmlLinkInfo *lnk = GetLink(x, y);
|
||||||
|
if (lnk != NULL)
|
||||||
|
{
|
||||||
|
wxHtmlLinkInfo lnk2(*lnk);
|
||||||
|
lnk2.SetEvent(&event);
|
||||||
|
lnk2.SetHtmlCell(this);
|
||||||
|
|
||||||
|
// note : this cast is legal because parent is *always* wxHtmlWindow
|
||||||
|
wxStaticCast(parent, wxHtmlWindow)->OnLinkClicked(lnk2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlCell::AdjustPagebreak(int *pagebreak) const
|
||||||
|
{
|
||||||
|
if ((!m_CanLiveOnPagebreak) &&
|
||||||
|
m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak)
|
||||||
|
{
|
||||||
|
*pagebreak = m_PosY;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlCell::SetLink(const wxHtmlLinkInfo& link)
|
||||||
|
{
|
||||||
|
if (m_Link) delete m_Link;
|
||||||
|
m_Link = NULL;
|
||||||
|
if (link.GetHref() != wxEmptyString)
|
||||||
|
m_Link = new wxHtmlLinkInfo(link);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlCell::Layout(int WXUNUSED(w))
|
||||||
|
{
|
||||||
|
SetPos(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlCell::GetHorizontalConstraints(int *left, int *right) const
|
||||||
|
{
|
||||||
|
if (left)
|
||||||
|
*left = m_PosX;
|
||||||
|
if (right)
|
||||||
|
*right = m_PosX + m_Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED(param)) const
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlCell *wxHtmlCell::FindCellByPos(wxCoord x, wxCoord y) const
|
||||||
|
{
|
||||||
|
if ( x >= 0 && x < m_Width && y >= 0 && y < m_Height )
|
||||||
|
return wxConstCast(this, wxHtmlCell);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlWordCell
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell()
|
||||||
|
{
|
||||||
|
m_Word = word;
|
||||||
|
dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent);
|
||||||
|
SetCanLiveOnPagebreak(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, int WXUNUSED(view_y1), int WXUNUSED(view_y2))
|
||||||
|
{
|
||||||
|
dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlContainerCell
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCell()
|
||||||
|
{
|
||||||
|
m_Cells = m_LastCell = NULL;
|
||||||
|
m_Parent = parent;
|
||||||
|
if (m_Parent) m_Parent->InsertCell(this);
|
||||||
|
m_AlignHor = wxHTML_ALIGN_LEFT;
|
||||||
|
m_AlignVer = wxHTML_ALIGN_BOTTOM;
|
||||||
|
m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0;
|
||||||
|
m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT;
|
||||||
|
m_UseBkColour = FALSE;
|
||||||
|
m_UseBorder = FALSE;
|
||||||
|
m_MinHeight = 0;
|
||||||
|
m_MinHeightAlign = wxHTML_ALIGN_TOP;
|
||||||
|
m_LastLayout = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlContainerCell::~wxHtmlContainerCell()
|
||||||
|
{
|
||||||
|
wxHtmlCell *cell = m_Cells;
|
||||||
|
while ( cell )
|
||||||
|
{
|
||||||
|
wxHtmlCell *cellNext = cell->GetNext();
|
||||||
|
delete cell;
|
||||||
|
cell = cellNext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlContainerCell::SetIndent(int i, int what, int units)
|
||||||
|
{
|
||||||
|
int val = (units == wxHTML_UNITS_PIXELS) ? i : -i;
|
||||||
|
if (what & wxHTML_INDENT_LEFT) m_IndentLeft = val;
|
||||||
|
if (what & wxHTML_INDENT_RIGHT) m_IndentRight = val;
|
||||||
|
if (what & wxHTML_INDENT_TOP) m_IndentTop = val;
|
||||||
|
if (what & wxHTML_INDENT_BOTTOM) m_IndentBottom = val;
|
||||||
|
m_LastLayout = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int wxHtmlContainerCell::GetIndent(int ind) const
|
||||||
|
{
|
||||||
|
if (ind & wxHTML_INDENT_LEFT) return m_IndentLeft;
|
||||||
|
else if (ind & wxHTML_INDENT_RIGHT) return m_IndentRight;
|
||||||
|
else if (ind & wxHTML_INDENT_TOP) return m_IndentTop;
|
||||||
|
else if (ind & wxHTML_INDENT_BOTTOM) return m_IndentBottom;
|
||||||
|
else return -1; /* BUG! Should not be called... */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int wxHtmlContainerCell::GetIndentUnits(int ind) const
|
||||||
|
{
|
||||||
|
bool p = FALSE;
|
||||||
|
if (ind & wxHTML_INDENT_LEFT) p = m_IndentLeft < 0;
|
||||||
|
else if (ind & wxHTML_INDENT_RIGHT) p = m_IndentRight < 0;
|
||||||
|
else if (ind & wxHTML_INDENT_TOP) p = m_IndentTop < 0;
|
||||||
|
else if (ind & wxHTML_INDENT_BOTTOM) p = m_IndentBottom < 0;
|
||||||
|
if (p) return wxHTML_UNITS_PERCENT;
|
||||||
|
else return wxHTML_UNITS_PIXELS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak) const
|
||||||
|
{
|
||||||
|
if (!m_CanLiveOnPagebreak)
|
||||||
|
return wxHtmlCell::AdjustPagebreak(pagebreak);
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxHtmlCell *c = GetFirstCell();
|
||||||
|
bool rt = FALSE;
|
||||||
|
int pbrk = *pagebreak - m_PosY;
|
||||||
|
|
||||||
|
while (c)
|
||||||
|
{
|
||||||
|
if (c->AdjustPagebreak(&pbrk))
|
||||||
|
rt = TRUE;
|
||||||
|
c = c->GetNext();
|
||||||
|
}
|
||||||
|
if (rt)
|
||||||
|
*pagebreak = pbrk + m_PosY;
|
||||||
|
return rt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlContainerCell::Layout(int w)
|
||||||
|
{
|
||||||
|
wxHtmlCell::Layout(w);
|
||||||
|
|
||||||
|
if (m_LastLayout == w) return;
|
||||||
|
|
||||||
|
// VS: Any attempt to layout with negative or zero width leads to hell,
|
||||||
|
// but we can't ignore such attempts completely, since it sometimes
|
||||||
|
// happen (e.g. when trying how small a table can be). The best thing we
|
||||||
|
// can do is to set the width of child cells to zero
|
||||||
|
if (w < 1)
|
||||||
|
{
|
||||||
|
m_Width = 0;
|
||||||
|
for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
|
||||||
|
cell->Layout(0);
|
||||||
|
// this does two things: it recursively calls this code on all
|
||||||
|
// child contrainers and resets children's position to (0,0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlCell *cell = m_Cells, *line = m_Cells;
|
||||||
|
long xpos = 0, ypos = m_IndentTop;
|
||||||
|
int xdelta = 0, ybasicpos = 0, ydiff;
|
||||||
|
int s_width, s_indent;
|
||||||
|
int ysizeup = 0, ysizedown = 0;
|
||||||
|
int MaxLineWidth = 0;
|
||||||
|
int xcnt = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
WIDTH ADJUSTING :
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT)
|
||||||
|
{
|
||||||
|
if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100;
|
||||||
|
else m_Width = m_WidthFloat * w / 100;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_WidthFloat < 0) m_Width = w + m_WidthFloat;
|
||||||
|
else m_Width = m_WidthFloat;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_Cells)
|
||||||
|
{
|
||||||
|
int l = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
|
||||||
|
int r = (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight;
|
||||||
|
for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
|
||||||
|
cell->Layout(m_Width - (l + r));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
LAYOUTING :
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// adjust indentation:
|
||||||
|
s_indent = (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
|
||||||
|
s_width = m_Width - s_indent - ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
|
||||||
|
|
||||||
|
// my own layouting:
|
||||||
|
while (cell != NULL)
|
||||||
|
{
|
||||||
|
switch (m_AlignVer)
|
||||||
|
{
|
||||||
|
case wxHTML_ALIGN_TOP : ybasicpos = 0; break;
|
||||||
|
case wxHTML_ALIGN_BOTTOM : ybasicpos = - cell->GetHeight(); break;
|
||||||
|
case wxHTML_ALIGN_CENTER : ybasicpos = - cell->GetHeight() / 2; break;
|
||||||
|
}
|
||||||
|
ydiff = cell->GetHeight() + ybasicpos;
|
||||||
|
|
||||||
|
if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff;
|
||||||
|
if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent());
|
||||||
|
|
||||||
|
cell->SetPos(xpos, ybasicpos + cell->GetDescent());
|
||||||
|
xpos += cell->GetWidth();
|
||||||
|
cell = cell->GetNext();
|
||||||
|
xcnt++;
|
||||||
|
|
||||||
|
// force new line if occured:
|
||||||
|
if ((cell == NULL) || (xpos + cell->GetWidth() > s_width))
|
||||||
|
{
|
||||||
|
if (xpos > MaxLineWidth) MaxLineWidth = xpos;
|
||||||
|
if (ysizeup < 0) ysizeup = 0;
|
||||||
|
if (ysizedown < 0) ysizedown = 0;
|
||||||
|
switch (m_AlignHor) {
|
||||||
|
case wxHTML_ALIGN_LEFT :
|
||||||
|
case wxHTML_ALIGN_JUSTIFY :
|
||||||
|
xdelta = 0;
|
||||||
|
break;
|
||||||
|
case wxHTML_ALIGN_RIGHT :
|
||||||
|
xdelta = 0 + (s_width - xpos);
|
||||||
|
break;
|
||||||
|
case wxHTML_ALIGN_CENTER :
|
||||||
|
xdelta = 0 + (s_width - xpos) / 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (xdelta < 0) xdelta = 0;
|
||||||
|
xdelta += s_indent;
|
||||||
|
|
||||||
|
ypos += ysizeup;
|
||||||
|
|
||||||
|
if (m_AlignHor != wxHTML_ALIGN_JUSTIFY || cell == NULL)
|
||||||
|
while (line != cell)
|
||||||
|
{
|
||||||
|
line->SetPos(line->GetPosX() + xdelta,
|
||||||
|
ypos + line->GetPosY());
|
||||||
|
line = line->GetNext();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int counter = 0;
|
||||||
|
int step = (s_width - xpos);
|
||||||
|
if (step < 0) step = 0;
|
||||||
|
xcnt--;
|
||||||
|
if (xcnt > 0) while (line != cell)
|
||||||
|
{
|
||||||
|
line->SetPos(line->GetPosX() + s_indent +
|
||||||
|
(counter++ * step / xcnt),
|
||||||
|
ypos + line->GetPosY());
|
||||||
|
line = line->GetNext();
|
||||||
|
}
|
||||||
|
xcnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ypos += ysizedown;
|
||||||
|
xpos = xcnt = 0;
|
||||||
|
ysizeup = ysizedown = 0;
|
||||||
|
line = cell;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup height & width, depending on container layout:
|
||||||
|
m_Height = ypos + (ysizedown + ysizeup) + m_IndentBottom;
|
||||||
|
|
||||||
|
if (m_Height < m_MinHeight)
|
||||||
|
{
|
||||||
|
if (m_MinHeightAlign != wxHTML_ALIGN_TOP)
|
||||||
|
{
|
||||||
|
int diff = m_MinHeight - m_Height;
|
||||||
|
if (m_MinHeightAlign == wxHTML_ALIGN_CENTER) diff /= 2;
|
||||||
|
cell = m_Cells;
|
||||||
|
while (cell)
|
||||||
|
{
|
||||||
|
cell->SetPos(cell->GetPosX(), cell->GetPosY() + diff);
|
||||||
|
cell = cell->GetNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_Height = m_MinHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaxLineWidth += s_indent + ((m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight);
|
||||||
|
if (m_Width < MaxLineWidth) m_Width = MaxLineWidth;
|
||||||
|
|
||||||
|
m_LastLayout = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define mMin(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
|
#define mMax(a, b) (((a) < (b)) ? (b) : (a))
|
||||||
|
|
||||||
|
void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
|
||||||
|
{
|
||||||
|
// container visible, draw it:
|
||||||
|
if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1))
|
||||||
|
{
|
||||||
|
if (m_UseBkColour)
|
||||||
|
{
|
||||||
|
wxBrush myb = wxBrush(m_BkColour, wxSOLID);
|
||||||
|
|
||||||
|
int real_y1 = mMax(y + m_PosY, view_y1);
|
||||||
|
int real_y2 = mMin(y + m_PosY + m_Height - 1, view_y2);
|
||||||
|
|
||||||
|
dc.SetBrush(myb);
|
||||||
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||||
|
dc.DrawRectangle(x + m_PosX, real_y1, m_Width, real_y2 - real_y1 + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_UseBorder)
|
||||||
|
{
|
||||||
|
wxPen mypen1(m_BorderColour1, 1, wxSOLID);
|
||||||
|
wxPen mypen2(m_BorderColour2, 1, wxSOLID);
|
||||||
|
|
||||||
|
dc.SetPen(mypen1);
|
||||||
|
dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX, y + m_PosY + m_Height - 1);
|
||||||
|
dc.DrawLine(x + m_PosX, y + m_PosY, x + m_PosX + m_Width, y + m_PosY);
|
||||||
|
dc.SetPen(mypen2);
|
||||||
|
dc.DrawLine(x + m_PosX + m_Width - 1, y + m_PosY, x + m_PosX + m_Width - 1, y + m_PosY + m_Height - 1);
|
||||||
|
dc.DrawLine(x + m_PosX, y + m_PosY + m_Height - 1, x + m_PosX + m_Width, y + m_PosY + m_Height - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_Cells)
|
||||||
|
{
|
||||||
|
for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
|
||||||
|
cell->Draw(dc, x + m_PosX, y + m_PosY, view_y1, view_y2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// container invisible, just proceed font+color changing:
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_Cells)
|
||||||
|
{
|
||||||
|
for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
|
||||||
|
cell->DrawInvisible(dc, x + m_PosX, y + m_PosY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y)
|
||||||
|
{
|
||||||
|
if (m_Cells)
|
||||||
|
{
|
||||||
|
for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
|
||||||
|
cell->DrawInvisible(dc, x + m_PosX, y + m_PosY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxColour wxHtmlContainerCell::GetBackgroundColour()
|
||||||
|
{
|
||||||
|
if (m_UseBkColour)
|
||||||
|
return m_BkColour;
|
||||||
|
else
|
||||||
|
return wxNullColour;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlLinkInfo *wxHtmlContainerCell::GetLink(int x, int y) const
|
||||||
|
{
|
||||||
|
wxHtmlCell *cell = FindCellByPos(x, y);
|
||||||
|
|
||||||
|
// VZ: I don't know if we should pass absolute or relative coords to
|
||||||
|
// wxHtmlCell::GetLink()? As the base class version just ignores them
|
||||||
|
// anyhow, it hardly matters right now but should still be clarified
|
||||||
|
return cell ? cell->GetLink(x, y) : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlContainerCell::InsertCell(wxHtmlCell *f)
|
||||||
|
{
|
||||||
|
if (!m_Cells) m_Cells = m_LastCell = f;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_LastCell->SetNext(f);
|
||||||
|
m_LastCell = f;
|
||||||
|
if (m_LastCell) while (m_LastCell->GetNext()) m_LastCell = m_LastCell->GetNext();
|
||||||
|
}
|
||||||
|
f->SetParent(this);
|
||||||
|
m_LastLayout = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
|
||||||
|
{
|
||||||
|
if (tag.HasParam(wxT("ALIGN")))
|
||||||
|
{
|
||||||
|
wxString alg = tag.GetParam(wxT("ALIGN"));
|
||||||
|
alg.MakeUpper();
|
||||||
|
if (alg == wxT("CENTER"))
|
||||||
|
SetAlignHor(wxHTML_ALIGN_CENTER);
|
||||||
|
else if (alg == wxT("LEFT"))
|
||||||
|
SetAlignHor(wxHTML_ALIGN_LEFT);
|
||||||
|
else if (alg == wxT("JUSTIFY"))
|
||||||
|
SetAlignHor(wxHTML_ALIGN_JUSTIFY);
|
||||||
|
else if (alg == wxT("RIGHT"))
|
||||||
|
SetAlignHor(wxHTML_ALIGN_RIGHT);
|
||||||
|
m_LastLayout = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale)
|
||||||
|
{
|
||||||
|
if (tag.HasParam(wxT("WIDTH")))
|
||||||
|
{
|
||||||
|
int wdi;
|
||||||
|
wxString wd = tag.GetParam(wxT("WIDTH"));
|
||||||
|
|
||||||
|
if (wd[wd.Length()-1] == wxT('%'))
|
||||||
|
{
|
||||||
|
wxSscanf(wd.c_str(), wxT("%i%%"), &wdi);
|
||||||
|
SetWidthFloat(wdi, wxHTML_UNITS_PERCENT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxSscanf(wd.c_str(), wxT("%i"), &wdi);
|
||||||
|
SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS);
|
||||||
|
}
|
||||||
|
m_LastLayout = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) const
|
||||||
|
{
|
||||||
|
if (m_Cells)
|
||||||
|
{
|
||||||
|
const wxHtmlCell *r = NULL;
|
||||||
|
|
||||||
|
for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
|
||||||
|
{
|
||||||
|
r = cell->Find(condition, param);
|
||||||
|
if (r) return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y) const
|
||||||
|
{
|
||||||
|
for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
|
||||||
|
{
|
||||||
|
int cx = cell->GetPosX(),
|
||||||
|
cy = cell->GetPosY();
|
||||||
|
|
||||||
|
if ( (cx <= x) && (cx + cell->GetWidth() > x) &&
|
||||||
|
(cy <= y) && (cy + cell->GetHeight() > y) )
|
||||||
|
{
|
||||||
|
return cell->FindCellByPos(x - cx, y - cy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlContainerCell::OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event)
|
||||||
|
{
|
||||||
|
wxHtmlCell *cell = FindCellByPos(x, y);
|
||||||
|
if ( cell )
|
||||||
|
cell->OnMouseClick(parent, x, y, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlContainerCell::GetHorizontalConstraints(int *left, int *right) const
|
||||||
|
{
|
||||||
|
int cleft = m_PosX + m_Width, cright = m_PosX; // worst case
|
||||||
|
int l, r;
|
||||||
|
|
||||||
|
for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
|
||||||
|
{
|
||||||
|
cell->GetHorizontalConstraints(&l, &r);
|
||||||
|
if (l < cleft)
|
||||||
|
cleft = l;
|
||||||
|
if (r > cright)
|
||||||
|
cright = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleft -= (m_IndentLeft < 0) ? (-m_IndentLeft * m_Width / 100) : m_IndentLeft;
|
||||||
|
cright += (m_IndentRight < 0) ? (-m_IndentRight * m_Width / 100) : m_IndentRight;
|
||||||
|
|
||||||
|
if (left)
|
||||||
|
*left = cleft;
|
||||||
|
if (right)
|
||||||
|
*right = cright;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlColourCell
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void wxHtmlColourCell::Draw(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2))
|
||||||
|
{
|
||||||
|
if (m_Flags & wxHTML_CLR_FOREGROUND)
|
||||||
|
dc.SetTextForeground(m_Colour);
|
||||||
|
if (m_Flags & wxHTML_CLR_BACKGROUND)
|
||||||
|
{
|
||||||
|
dc.SetBackground(wxBrush(m_Colour, wxSOLID));
|
||||||
|
dc.SetTextBackground(m_Colour);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlColourCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y))
|
||||||
|
{
|
||||||
|
if (m_Flags & wxHTML_CLR_FOREGROUND)
|
||||||
|
dc.SetTextForeground(m_Colour);
|
||||||
|
if (m_Flags & wxHTML_CLR_BACKGROUND)
|
||||||
|
{
|
||||||
|
dc.SetBackground(wxBrush(m_Colour, wxSOLID));
|
||||||
|
dc.SetTextBackground(m_Colour);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlFontCell
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void wxHtmlFontCell::Draw(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2))
|
||||||
|
{
|
||||||
|
dc.SetFont(m_Font);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y))
|
||||||
|
{
|
||||||
|
dc.SetFont(m_Font);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlWidgetCell
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w)
|
||||||
|
{
|
||||||
|
int sx, sy;
|
||||||
|
m_Wnd = wnd;
|
||||||
|
m_Wnd->GetSize(&sx, &sy);
|
||||||
|
m_Width = sx, m_Height = sy;
|
||||||
|
m_WidthFloat = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2))
|
||||||
|
{
|
||||||
|
int absx = 0, absy = 0, stx, sty;
|
||||||
|
wxHtmlCell *c = this;
|
||||||
|
|
||||||
|
while (c)
|
||||||
|
{
|
||||||
|
absx += c->GetPosX();
|
||||||
|
absy += c->GetPosY();
|
||||||
|
c = c->GetParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
|
||||||
|
m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y))
|
||||||
|
{
|
||||||
|
int absx = 0, absy = 0, stx, sty;
|
||||||
|
wxHtmlCell *c = this;
|
||||||
|
|
||||||
|
while (c)
|
||||||
|
{
|
||||||
|
absx += c->GetPosX();
|
||||||
|
absy += c->GetPosY();
|
||||||
|
c = c->GetParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
((wxScrolledWindow*)(m_Wnd->GetParent()))->GetViewStart(&stx, &sty);
|
||||||
|
m_Wnd->SetSize(absx - wxHTML_SCROLL_STEP * stx, absy - wxHTML_SCROLL_STEP * sty, m_Width, m_Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWidgetCell::Layout(int w)
|
||||||
|
{
|
||||||
|
if (m_WidthFloat != 0)
|
||||||
|
{
|
||||||
|
m_Width = (w * m_WidthFloat) / 100;
|
||||||
|
m_Wnd->SetSize(m_Width, m_Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlCell::Layout(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
229
Contrib/NSIS Menu/src/html/htmlfilt.cpp
Normal file
229
Contrib/NSIS Menu/src/html/htmlfilt.cpp
Normal file
|
@ -0,0 +1,229 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: htmlfilt.cpp
|
||||||
|
// Purpose: wxHtmlFilter - input filter for translating into HTML format
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: htmlfilt.cpp,v 1.16.2.4 2002/11/11 00:15:57 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "htmlfilt.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#include "wx/log.h"
|
||||||
|
#include "wx/intl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/strconv.h"
|
||||||
|
#include "wx/html/htmlfilt.h"
|
||||||
|
#include "wx/html/htmlwin.h"
|
||||||
|
|
||||||
|
// utility function: read a wxString from a wxInputStream
|
||||||
|
static void ReadString(wxString& str, wxInputStream* s, wxMBConv& conv)
|
||||||
|
{
|
||||||
|
size_t streamSize = s->GetSize();
|
||||||
|
|
||||||
|
if (streamSize == ~(size_t)0)
|
||||||
|
{
|
||||||
|
const size_t bufSize = 4095;
|
||||||
|
char buffer[bufSize+1];
|
||||||
|
size_t lastRead;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
s->Read(buffer, bufSize);
|
||||||
|
lastRead = s->LastRead();
|
||||||
|
buffer[lastRead] = 0;
|
||||||
|
str.Append(wxString(buffer, conv));
|
||||||
|
}
|
||||||
|
while (lastRead == bufSize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char* src = new char[streamSize+1];
|
||||||
|
s->Read(src, streamSize);
|
||||||
|
src[streamSize] = 0;
|
||||||
|
str = wxString(src, conv);
|
||||||
|
delete[] src;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
There is code for several default filters:
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
IMPLEMENT_ABSTRACT_CLASS(wxHtmlFilter, wxObject)
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlFilterPlainText
|
||||||
|
// filter for text/plain or uknown
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterPlainText, wxHtmlFilter)
|
||||||
|
|
||||||
|
bool wxHtmlFilterPlainText::CanRead(const wxFSFile& WXUNUSED(file)) const
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxString wxHtmlFilterPlainText::ReadFile(const wxFSFile& file) const
|
||||||
|
{
|
||||||
|
wxInputStream *s = file.GetStream();
|
||||||
|
wxString doc, doc2;
|
||||||
|
|
||||||
|
if (s == NULL) return wxEmptyString;
|
||||||
|
ReadString(doc, s, wxConvISO8859_1);
|
||||||
|
|
||||||
|
doc.Replace(wxT("&"), wxT("&"), TRUE);
|
||||||
|
doc.Replace(wxT("<"), wxT("<"), TRUE);
|
||||||
|
doc.Replace(wxT(">"), wxT(">"), TRUE);
|
||||||
|
doc2 = wxT("<HTML><BODY><PRE>\n") + doc + wxT("\n</PRE></BODY></HTML>");
|
||||||
|
return doc2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlFilterImage
|
||||||
|
// filter for image/*
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxHtmlFilterImage : public wxHtmlFilter
|
||||||
|
{
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxHtmlFilterImage)
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual bool CanRead(const wxFSFile& file) const;
|
||||||
|
virtual wxString ReadFile(const wxFSFile& file) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterImage, wxHtmlFilter)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlFilterImage::CanRead(const wxFSFile& file) const
|
||||||
|
{
|
||||||
|
return (file.GetMimeType().Left(6) == wxT("image/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxString wxHtmlFilterImage::ReadFile(const wxFSFile& file) const
|
||||||
|
{
|
||||||
|
wxString res = wxT("<HTML><BODY><IMG SRC=\"") + file.GetLocation() + wxT("\"></BODY></HTML>");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlFilterHTML
|
||||||
|
// filter for text/html
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterHTML, wxHtmlFilter)
|
||||||
|
|
||||||
|
bool wxHtmlFilterHTML::CanRead(const wxFSFile& file) const
|
||||||
|
{
|
||||||
|
// return (file.GetMimeType() == "text/html");
|
||||||
|
// This is true in most case but some page can return:
|
||||||
|
// "text/html; char-encoding=...."
|
||||||
|
// So we use Find instead
|
||||||
|
return (file.GetMimeType().Find(wxT("text/html")) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxString wxHtmlFilterHTML::ReadFile(const wxFSFile& file) const
|
||||||
|
{
|
||||||
|
wxInputStream *s = file.GetStream();
|
||||||
|
wxString doc;
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
{
|
||||||
|
wxLogError(_("Cannot open HTML document: %s"), file.GetLocation().c_str());
|
||||||
|
return wxEmptyString;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NB: We convert input file to wchar_t here in Unicode mode, based on
|
||||||
|
// either Content-Type header or <meta> tags. In ANSI mode, we don't
|
||||||
|
// do it as it is done by wxHtmlParser (for this reason, we add <meta>
|
||||||
|
// tag if we used Content-Type header).
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
int charsetPos;
|
||||||
|
if ((charsetPos = file.GetMimeType().Find(_T("; charset="))) != wxNOT_FOUND)
|
||||||
|
{
|
||||||
|
wxString charset = file.GetMimeType().Mid(charsetPos + 10);
|
||||||
|
wxCSConv conv(charset);
|
||||||
|
ReadString(doc, s, conv);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxString tmpdoc;
|
||||||
|
ReadString(tmpdoc, s, wxConvISO8859_1);
|
||||||
|
wxString charset = wxHtmlParser::ExtractCharsetInformation(tmpdoc);
|
||||||
|
if (charset.empty())
|
||||||
|
doc = tmpdoc;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxCSConv conv(charset);
|
||||||
|
doc = wxString(tmpdoc.mb_str(wxConvISO8859_1), conv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else // !wxUSE_UNICODE
|
||||||
|
ReadString(doc, s, wxConvLibc);
|
||||||
|
// add meta tag if we obtained this through http:
|
||||||
|
if (!file.GetMimeType().empty())
|
||||||
|
{
|
||||||
|
wxString hdr;
|
||||||
|
wxString mime = file.GetMimeType();
|
||||||
|
hdr.Printf(_T("<meta http-equiv=\"Content-Type\" content=\"%s\">"), mime.c_str());
|
||||||
|
return hdr+doc;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///// Module:
|
||||||
|
|
||||||
|
class wxHtmlFilterModule : public wxModule
|
||||||
|
{
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxHtmlFilterModule)
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual bool OnInit()
|
||||||
|
{
|
||||||
|
wxHtmlWindow::AddFilter(new wxHtmlFilterHTML);
|
||||||
|
wxHtmlWindow::AddFilter(new wxHtmlFilterImage);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
virtual void OnExit() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxHtmlFilterModule, wxModule)
|
||||||
|
|
||||||
|
#endif
|
888
Contrib/NSIS Menu/src/html/htmlpars.cpp
Normal file
888
Contrib/NSIS Menu/src/html/htmlpars.cpp
Normal file
|
@ -0,0 +1,888 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: htmlpars.cpp
|
||||||
|
// Purpose: wxHtmlParser class (generic parser)
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: htmlpars.cpp,v 1.28.2.5 2002/11/10 00:05:39 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "htmlpars.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#include "wx/log.h"
|
||||||
|
#include "wx/intl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/tokenzr.h"
|
||||||
|
#include "wx/wfstream.h"
|
||||||
|
#include "wx/url.h"
|
||||||
|
#include "wx/fontmap.h"
|
||||||
|
#include "wx/html/htmldefs.h"
|
||||||
|
#include "wx/html/htmlpars.h"
|
||||||
|
#include "wx/dynarray.h"
|
||||||
|
#include "wx/arrimpl.cpp"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlParser helpers
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxHtmlTextPiece
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxHtmlTextPiece(int pos, int lng) : m_pos(pos), m_lng(lng) {}
|
||||||
|
int m_pos, m_lng;
|
||||||
|
};
|
||||||
|
|
||||||
|
WX_DECLARE_OBJARRAY(wxHtmlTextPiece, wxHtmlTextPieces);
|
||||||
|
WX_DEFINE_OBJARRAY(wxHtmlTextPieces);
|
||||||
|
|
||||||
|
class wxHtmlParserState
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxHtmlTag *m_curTag;
|
||||||
|
wxHtmlTag *m_tags;
|
||||||
|
wxHtmlTextPieces *m_textPieces;
|
||||||
|
int m_curTextPiece;
|
||||||
|
wxString m_source;
|
||||||
|
wxHtmlParserState *m_nextState;
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlParser
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_ABSTRACT_CLASS(wxHtmlParser,wxObject)
|
||||||
|
|
||||||
|
wxHtmlParser::wxHtmlParser()
|
||||||
|
: wxObject(), m_HandlersHash(wxKEY_STRING),
|
||||||
|
m_FS(NULL), m_HandlersStack(NULL)
|
||||||
|
{
|
||||||
|
m_entitiesParser = new wxHtmlEntitiesParser;
|
||||||
|
m_Tags = NULL;
|
||||||
|
m_CurTag = NULL;
|
||||||
|
m_TextPieces = NULL;
|
||||||
|
m_CurTextPiece = 0;
|
||||||
|
m_SavedStates = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlParser::~wxHtmlParser()
|
||||||
|
{
|
||||||
|
while (RestoreState()) {}
|
||||||
|
DestroyDOMTree();
|
||||||
|
|
||||||
|
delete m_HandlersStack;
|
||||||
|
m_HandlersHash.Clear();
|
||||||
|
m_HandlersList.DeleteContents(TRUE);
|
||||||
|
m_HandlersList.Clear();
|
||||||
|
delete m_entitiesParser;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxObject* wxHtmlParser::Parse(const wxString& source)
|
||||||
|
{
|
||||||
|
InitParser(source);
|
||||||
|
DoParsing();
|
||||||
|
wxObject *result = GetProduct();
|
||||||
|
DoneParser();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::InitParser(const wxString& source)
|
||||||
|
{
|
||||||
|
SetSource(source);
|
||||||
|
m_stopParsing = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::DoneParser()
|
||||||
|
{
|
||||||
|
DestroyDOMTree();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::SetSource(const wxString& src)
|
||||||
|
{
|
||||||
|
DestroyDOMTree();
|
||||||
|
m_Source = src;
|
||||||
|
CreateDOMTree();
|
||||||
|
m_CurTag = NULL;
|
||||||
|
m_CurTextPiece = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::CreateDOMTree()
|
||||||
|
{
|
||||||
|
wxHtmlTagsCache cache(m_Source);
|
||||||
|
m_TextPieces = new wxHtmlTextPieces;
|
||||||
|
CreateDOMSubTree(NULL, 0, m_Source.Length(), &cache);
|
||||||
|
m_CurTextPiece = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::CreateDOMSubTree(wxHtmlTag *cur,
|
||||||
|
int begin_pos, int end_pos,
|
||||||
|
wxHtmlTagsCache *cache)
|
||||||
|
{
|
||||||
|
if (end_pos <= begin_pos) return;
|
||||||
|
|
||||||
|
wxChar c;
|
||||||
|
int i = begin_pos;
|
||||||
|
int textBeginning = begin_pos;
|
||||||
|
|
||||||
|
while (i < end_pos)
|
||||||
|
{
|
||||||
|
c = m_Source.GetChar(i);
|
||||||
|
|
||||||
|
if (c == wxT('<'))
|
||||||
|
{
|
||||||
|
// add text to m_TextPieces:
|
||||||
|
if (i - textBeginning > 0)
|
||||||
|
m_TextPieces->Add(
|
||||||
|
wxHtmlTextPiece(textBeginning, i - textBeginning));
|
||||||
|
|
||||||
|
// if it is a comment, skip it:
|
||||||
|
if (i < end_pos-6 && m_Source.GetChar(i+1) == wxT('!') &&
|
||||||
|
m_Source.GetChar(i+2) == wxT('-') &&
|
||||||
|
m_Source.GetChar(i+3) == wxT('-'))
|
||||||
|
{
|
||||||
|
// Comments begin with "<!--" and end with "--[ \t\r\n]*>"
|
||||||
|
// according to HTML 4.0
|
||||||
|
int dashes = 0;
|
||||||
|
i += 4;
|
||||||
|
while (i < end_pos)
|
||||||
|
{
|
||||||
|
c = m_Source.GetChar(i++);
|
||||||
|
if ((c == wxT(' ') || c == wxT('\n') ||
|
||||||
|
c == wxT('\r') || c == wxT('\t')) && dashes >= 2) {}
|
||||||
|
else if (c == wxT('>') && dashes >= 2)
|
||||||
|
{
|
||||||
|
textBeginning = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (c == wxT('-'))
|
||||||
|
dashes++;
|
||||||
|
else
|
||||||
|
dashes = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add another tag to the tree:
|
||||||
|
else if (i < end_pos-1 && m_Source.GetChar(i+1) != wxT('/'))
|
||||||
|
{
|
||||||
|
wxHtmlTag *chd;
|
||||||
|
if (cur)
|
||||||
|
chd = new wxHtmlTag(cur, m_Source,
|
||||||
|
i, end_pos, cache, m_entitiesParser);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
chd = new wxHtmlTag(NULL, m_Source,
|
||||||
|
i, end_pos, cache, m_entitiesParser);
|
||||||
|
if (!m_Tags)
|
||||||
|
{
|
||||||
|
// if this is the first tag to be created make the root
|
||||||
|
// m_Tags point to it:
|
||||||
|
m_Tags = chd;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// if there is already a root tag add this tag as
|
||||||
|
// the last sibling:
|
||||||
|
chd->m_Prev = m_Tags->GetLastSibling();
|
||||||
|
chd->m_Prev->m_Next = chd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chd->HasEnding())
|
||||||
|
{
|
||||||
|
CreateDOMSubTree(chd,
|
||||||
|
chd->GetBeginPos(), chd->GetEndPos1(),
|
||||||
|
cache);
|
||||||
|
i = chd->GetEndPos2();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
i = chd->GetBeginPos();
|
||||||
|
textBeginning = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... or skip ending tag:
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (i < end_pos && m_Source.GetChar(i) != wxT('>')) i++;
|
||||||
|
textBeginning = i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add remaining text to m_TextPieces:
|
||||||
|
if (end_pos - textBeginning > 0)
|
||||||
|
m_TextPieces->Add(
|
||||||
|
wxHtmlTextPiece(textBeginning, end_pos - textBeginning));
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::DestroyDOMTree()
|
||||||
|
{
|
||||||
|
wxHtmlTag *t1, *t2;
|
||||||
|
t1 = m_Tags;
|
||||||
|
while (t1)
|
||||||
|
{
|
||||||
|
t2 = t1->GetNextSibling();
|
||||||
|
delete t1;
|
||||||
|
t1 = t2;
|
||||||
|
}
|
||||||
|
m_Tags = m_CurTag = NULL;
|
||||||
|
|
||||||
|
delete m_TextPieces;
|
||||||
|
m_TextPieces = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::DoParsing()
|
||||||
|
{
|
||||||
|
m_CurTag = m_Tags;
|
||||||
|
m_CurTextPiece = 0;
|
||||||
|
DoParsing(0, m_Source.Length());
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::DoParsing(int begin_pos, int end_pos)
|
||||||
|
{
|
||||||
|
if (end_pos <= begin_pos) return;
|
||||||
|
|
||||||
|
wxHtmlTextPieces& pieces = *m_TextPieces;
|
||||||
|
size_t piecesCnt = pieces.GetCount();
|
||||||
|
|
||||||
|
while (begin_pos < end_pos)
|
||||||
|
{
|
||||||
|
while (m_CurTag && m_CurTag->GetBeginPos() < begin_pos)
|
||||||
|
m_CurTag = m_CurTag->GetNextTag();
|
||||||
|
while (m_CurTextPiece < piecesCnt &&
|
||||||
|
pieces[m_CurTextPiece].m_pos < begin_pos)
|
||||||
|
m_CurTextPiece++;
|
||||||
|
|
||||||
|
if (m_CurTextPiece < piecesCnt &&
|
||||||
|
(!m_CurTag ||
|
||||||
|
pieces[m_CurTextPiece].m_pos < m_CurTag->GetBeginPos()))
|
||||||
|
{
|
||||||
|
// Add text:
|
||||||
|
AddText(GetEntitiesParser()->Parse(
|
||||||
|
m_Source.Mid(pieces[m_CurTextPiece].m_pos,
|
||||||
|
pieces[m_CurTextPiece].m_lng)));
|
||||||
|
begin_pos = pieces[m_CurTextPiece].m_pos +
|
||||||
|
pieces[m_CurTextPiece].m_lng;
|
||||||
|
m_CurTextPiece++;
|
||||||
|
}
|
||||||
|
else if (m_CurTag)
|
||||||
|
{
|
||||||
|
// Add tag:
|
||||||
|
if (m_CurTag)
|
||||||
|
{
|
||||||
|
if (m_CurTag->HasEnding())
|
||||||
|
begin_pos = m_CurTag->GetEndPos2();
|
||||||
|
else
|
||||||
|
begin_pos = m_CurTag->GetBeginPos();
|
||||||
|
}
|
||||||
|
wxHtmlTag *t = m_CurTag;
|
||||||
|
m_CurTag = m_CurTag->GetNextTag();
|
||||||
|
AddTag(*t);
|
||||||
|
if (m_stopParsing)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::AddTag(const wxHtmlTag& tag)
|
||||||
|
{
|
||||||
|
wxHtmlTagHandler *h;
|
||||||
|
bool inner = FALSE;
|
||||||
|
|
||||||
|
h = (wxHtmlTagHandler*) m_HandlersHash.Get(tag.GetName());
|
||||||
|
if (h)
|
||||||
|
{
|
||||||
|
inner = h->HandleTag(tag);
|
||||||
|
if (m_stopParsing)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!inner)
|
||||||
|
{
|
||||||
|
if (tag.HasEnding())
|
||||||
|
DoParsing(tag.GetBeginPos(), tag.GetEndPos1());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler)
|
||||||
|
{
|
||||||
|
wxString s(handler->GetSupportedTags());
|
||||||
|
wxStringTokenizer tokenizer(s, wxT(", "));
|
||||||
|
|
||||||
|
while (tokenizer.HasMoreTokens())
|
||||||
|
m_HandlersHash.Put(tokenizer.GetNextToken(), handler);
|
||||||
|
|
||||||
|
if (m_HandlersList.IndexOf(handler) == wxNOT_FOUND)
|
||||||
|
m_HandlersList.Append(handler);
|
||||||
|
|
||||||
|
handler->SetParser(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::PushTagHandler(wxHtmlTagHandler *handler, wxString tags)
|
||||||
|
{
|
||||||
|
wxStringTokenizer tokenizer(tags, wxT(", "));
|
||||||
|
wxString key;
|
||||||
|
|
||||||
|
if (m_HandlersStack == NULL)
|
||||||
|
{
|
||||||
|
m_HandlersStack = new wxList;
|
||||||
|
m_HandlersStack->DeleteContents(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_HandlersStack->Insert(new wxHashTable(m_HandlersHash));
|
||||||
|
|
||||||
|
while (tokenizer.HasMoreTokens())
|
||||||
|
{
|
||||||
|
key = tokenizer.GetNextToken();
|
||||||
|
m_HandlersHash.Delete(key);
|
||||||
|
m_HandlersHash.Put(key, handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::PopTagHandler()
|
||||||
|
{
|
||||||
|
wxNode *first;
|
||||||
|
|
||||||
|
if (m_HandlersStack == NULL ||
|
||||||
|
(first = m_HandlersStack->GetFirst()) == NULL)
|
||||||
|
{
|
||||||
|
wxLogWarning(_("Warning: attempt to remove HTML tag handler from empty stack."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_HandlersHash = *((wxHashTable*) first->GetData());
|
||||||
|
m_HandlersStack->DeleteNode(first);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlParser::SetSourceAndSaveState(const wxString& src)
|
||||||
|
{
|
||||||
|
wxHtmlParserState *s = new wxHtmlParserState;
|
||||||
|
|
||||||
|
s->m_curTag = m_CurTag;
|
||||||
|
s->m_tags = m_Tags;
|
||||||
|
s->m_textPieces = m_TextPieces;
|
||||||
|
s->m_curTextPiece = m_CurTextPiece;
|
||||||
|
s->m_source = m_Source;
|
||||||
|
|
||||||
|
s->m_nextState = m_SavedStates;
|
||||||
|
m_SavedStates = s;
|
||||||
|
|
||||||
|
m_CurTag = NULL;
|
||||||
|
m_Tags = NULL;
|
||||||
|
m_TextPieces = NULL;
|
||||||
|
m_CurTextPiece = 0;
|
||||||
|
m_Source = wxEmptyString;
|
||||||
|
|
||||||
|
SetSource(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlParser::RestoreState()
|
||||||
|
{
|
||||||
|
if (!m_SavedStates) return FALSE;
|
||||||
|
|
||||||
|
DestroyDOMTree();
|
||||||
|
|
||||||
|
wxHtmlParserState *s = m_SavedStates;
|
||||||
|
m_SavedStates = s->m_nextState;
|
||||||
|
|
||||||
|
m_CurTag = s->m_curTag;
|
||||||
|
m_Tags = s->m_tags;
|
||||||
|
m_TextPieces = s->m_textPieces;
|
||||||
|
m_CurTextPiece = s->m_curTextPiece;
|
||||||
|
m_Source = s->m_source;
|
||||||
|
|
||||||
|
delete s;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlTagHandler
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_ABSTRACT_CLASS(wxHtmlTagHandler,wxObject)
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlEntitiesParser
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxHtmlEntitiesParser,wxObject)
|
||||||
|
|
||||||
|
wxHtmlEntitiesParser::wxHtmlEntitiesParser()
|
||||||
|
#if wxUSE_WCHAR_T && !wxUSE_UNICODE
|
||||||
|
: m_conv(NULL), m_encoding(wxFONTENCODING_SYSTEM)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlEntitiesParser::~wxHtmlEntitiesParser()
|
||||||
|
{
|
||||||
|
#if wxUSE_WCHAR_T && !wxUSE_UNICODE
|
||||||
|
delete m_conv;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlEntitiesParser::SetEncoding(wxFontEncoding encoding)
|
||||||
|
{
|
||||||
|
#if wxUSE_WCHAR_T && !wxUSE_UNICODE
|
||||||
|
if (encoding == m_encoding)
|
||||||
|
return;
|
||||||
|
|
||||||
|
delete m_conv;
|
||||||
|
|
||||||
|
m_encoding = encoding;
|
||||||
|
if (m_encoding == wxFONTENCODING_SYSTEM)
|
||||||
|
m_conv = NULL;
|
||||||
|
else
|
||||||
|
m_conv = new wxCSConv(wxFontMapper::GetEncodingName(m_encoding));
|
||||||
|
#else
|
||||||
|
(void) encoding;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxHtmlEntitiesParser::Parse(const wxString& input)
|
||||||
|
{
|
||||||
|
const wxChar *c, *last;
|
||||||
|
const wxChar *in_str = input.c_str();
|
||||||
|
wxString output;
|
||||||
|
|
||||||
|
output.reserve(input.length());
|
||||||
|
|
||||||
|
for (c = in_str, last = in_str; *c != wxT('\0'); c++)
|
||||||
|
{
|
||||||
|
if (*c == wxT('&'))
|
||||||
|
{
|
||||||
|
if (c - last > 0)
|
||||||
|
output.append(last, c - last);
|
||||||
|
if (++c == wxT('\0')) break;
|
||||||
|
|
||||||
|
wxString entity;
|
||||||
|
const wxChar *ent_s = c;
|
||||||
|
wxChar entity_char;
|
||||||
|
|
||||||
|
for (; (*c >= wxT('a') && *c <= wxT('z')) ||
|
||||||
|
(*c >= wxT('A') && *c <= wxT('Z')) ||
|
||||||
|
(*c >= wxT('0') && *c <= wxT('9')) ||
|
||||||
|
*c == wxT('_') || *c == wxT('#'); c++) {}
|
||||||
|
entity.append(ent_s, c - ent_s);
|
||||||
|
if (*c != wxT(';')) c--;
|
||||||
|
last = c+1;
|
||||||
|
entity_char = GetEntityChar(entity);
|
||||||
|
if (entity_char)
|
||||||
|
output << entity_char;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output.append(ent_s-1, c-ent_s+2);
|
||||||
|
wxLogDebug(wxT("Unrecognized HTML entity: '%s'"), entity.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (*last != wxT('\0'))
|
||||||
|
output.append(last);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wxHtmlEntityInfo
|
||||||
|
{
|
||||||
|
const wxChar *name;
|
||||||
|
unsigned code;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "C" int LINKAGEMODE wxHtmlEntityCompare(const void *key, const void *item)
|
||||||
|
{
|
||||||
|
return wxStrcmp((wxChar*)key, ((wxHtmlEntityInfo*)item)->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
wxChar wxHtmlEntitiesParser::GetCharForCode(unsigned code)
|
||||||
|
{
|
||||||
|
#if wxUSE_WCHAR_T
|
||||||
|
char buf[2];
|
||||||
|
wchar_t wbuf[2];
|
||||||
|
wbuf[0] = (wchar_t)code;
|
||||||
|
wbuf[1] = 0;
|
||||||
|
wxMBConv *conv = m_conv ? m_conv : &wxConvLocal;
|
||||||
|
if (conv->WC2MB(buf, wbuf, 2) == (size_t)-1)
|
||||||
|
return '?';
|
||||||
|
return buf[0];
|
||||||
|
#else
|
||||||
|
return (code < 256) ? (wxChar)code : '?';
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
wxChar wxHtmlEntitiesParser::GetEntityChar(const wxString& entity)
|
||||||
|
{
|
||||||
|
unsigned code = 0;
|
||||||
|
|
||||||
|
if (entity[0] == wxT('#'))
|
||||||
|
{
|
||||||
|
const wxChar *ent_s = entity.c_str();
|
||||||
|
const wxChar *format;
|
||||||
|
|
||||||
|
if (ent_s[1] == wxT('x') || ent_s[1] == wxT('X'))
|
||||||
|
{
|
||||||
|
format = wxT("%x");
|
||||||
|
ent_s++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
format = wxT("%u");
|
||||||
|
ent_s++;
|
||||||
|
|
||||||
|
if (wxSscanf(ent_s, format, &code) != 1)
|
||||||
|
code = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
static wxHtmlEntityInfo substitutions[] = {
|
||||||
|
{ wxT("AElig"),198 },
|
||||||
|
{ wxT("Aacute"),193 },
|
||||||
|
{ wxT("Acirc"),194 },
|
||||||
|
{ wxT("Agrave"),192 },
|
||||||
|
{ wxT("Alpha"),913 },
|
||||||
|
{ wxT("Aring"),197 },
|
||||||
|
{ wxT("Atilde"),195 },
|
||||||
|
{ wxT("Auml"),196 },
|
||||||
|
{ wxT("Beta"),914 },
|
||||||
|
{ wxT("Ccedil"),199 },
|
||||||
|
{ wxT("Chi"),935 },
|
||||||
|
{ wxT("Dagger"),8225 },
|
||||||
|
{ wxT("Delta"),916 },
|
||||||
|
{ wxT("ETH"),208 },
|
||||||
|
{ wxT("Eacute"),201 },
|
||||||
|
{ wxT("Ecirc"),202 },
|
||||||
|
{ wxT("Egrave"),200 },
|
||||||
|
{ wxT("Epsilon"),917 },
|
||||||
|
{ wxT("Eta"),919 },
|
||||||
|
{ wxT("Euml"),203 },
|
||||||
|
{ wxT("Gamma"),915 },
|
||||||
|
{ wxT("Iacute"),205 },
|
||||||
|
{ wxT("Icirc"),206 },
|
||||||
|
{ wxT("Igrave"),204 },
|
||||||
|
{ wxT("Iota"),921 },
|
||||||
|
{ wxT("Iuml"),207 },
|
||||||
|
{ wxT("Kappa"),922 },
|
||||||
|
{ wxT("Lambda"),923 },
|
||||||
|
{ wxT("Mu"),924 },
|
||||||
|
{ wxT("Ntilde"),209 },
|
||||||
|
{ wxT("Nu"),925 },
|
||||||
|
{ wxT("OElig"),338 },
|
||||||
|
{ wxT("Oacute"),211 },
|
||||||
|
{ wxT("Ocirc"),212 },
|
||||||
|
{ wxT("Ograve"),210 },
|
||||||
|
{ wxT("Omega"),937 },
|
||||||
|
{ wxT("Omicron"),927 },
|
||||||
|
{ wxT("Oslash"),216 },
|
||||||
|
{ wxT("Otilde"),213 },
|
||||||
|
{ wxT("Ouml"),214 },
|
||||||
|
{ wxT("Phi"),934 },
|
||||||
|
{ wxT("Pi"),928 },
|
||||||
|
{ wxT("Prime"),8243 },
|
||||||
|
{ wxT("Psi"),936 },
|
||||||
|
{ wxT("Rho"),929 },
|
||||||
|
{ wxT("Scaron"),352 },
|
||||||
|
{ wxT("Sigma"),931 },
|
||||||
|
{ wxT("THORN"),222 },
|
||||||
|
{ wxT("Tau"),932 },
|
||||||
|
{ wxT("Theta"),920 },
|
||||||
|
{ wxT("Uacute"),218 },
|
||||||
|
{ wxT("Ucirc"),219 },
|
||||||
|
{ wxT("Ugrave"),217 },
|
||||||
|
{ wxT("Upsilon"),933 },
|
||||||
|
{ wxT("Uuml"),220 },
|
||||||
|
{ wxT("Xi"),926 },
|
||||||
|
{ wxT("Yacute"),221 },
|
||||||
|
{ wxT("Yuml"),376 },
|
||||||
|
{ wxT("Zeta"),918 },
|
||||||
|
{ wxT("aacute"),225 },
|
||||||
|
{ wxT("acirc"),226 },
|
||||||
|
{ wxT("acute"),180 },
|
||||||
|
{ wxT("aelig"),230 },
|
||||||
|
{ wxT("agrave"),224 },
|
||||||
|
{ wxT("alefsym"),8501 },
|
||||||
|
{ wxT("alpha"),945 },
|
||||||
|
{ wxT("amp"),38 },
|
||||||
|
{ wxT("and"),8743 },
|
||||||
|
{ wxT("ang"),8736 },
|
||||||
|
{ wxT("aring"),229 },
|
||||||
|
{ wxT("asymp"),8776 },
|
||||||
|
{ wxT("atilde"),227 },
|
||||||
|
{ wxT("auml"),228 },
|
||||||
|
{ wxT("bdquo"),8222 },
|
||||||
|
{ wxT("beta"),946 },
|
||||||
|
{ wxT("brvbar"),166 },
|
||||||
|
{ wxT("bull"),8226 },
|
||||||
|
{ wxT("cap"),8745 },
|
||||||
|
{ wxT("ccedil"),231 },
|
||||||
|
{ wxT("cedil"),184 },
|
||||||
|
{ wxT("cent"),162 },
|
||||||
|
{ wxT("chi"),967 },
|
||||||
|
{ wxT("circ"),710 },
|
||||||
|
{ wxT("clubs"),9827 },
|
||||||
|
{ wxT("cong"),8773 },
|
||||||
|
{ wxT("copy"),169 },
|
||||||
|
{ wxT("crarr"),8629 },
|
||||||
|
{ wxT("cup"),8746 },
|
||||||
|
{ wxT("curren"),164 },
|
||||||
|
{ wxT("dArr"),8659 },
|
||||||
|
{ wxT("dagger"),8224 },
|
||||||
|
{ wxT("darr"),8595 },
|
||||||
|
{ wxT("deg"),176 },
|
||||||
|
{ wxT("delta"),948 },
|
||||||
|
{ wxT("diams"),9830 },
|
||||||
|
{ wxT("divide"),247 },
|
||||||
|
{ wxT("eacute"),233 },
|
||||||
|
{ wxT("ecirc"),234 },
|
||||||
|
{ wxT("egrave"),232 },
|
||||||
|
{ wxT("empty"),8709 },
|
||||||
|
{ wxT("emsp"),8195 },
|
||||||
|
{ wxT("ensp"),8194 },
|
||||||
|
{ wxT("epsilon"),949 },
|
||||||
|
{ wxT("equiv"),8801 },
|
||||||
|
{ wxT("eta"),951 },
|
||||||
|
{ wxT("eth"),240 },
|
||||||
|
{ wxT("euml"),235 },
|
||||||
|
{ wxT("euro"),8364 },
|
||||||
|
{ wxT("exist"),8707 },
|
||||||
|
{ wxT("fnof"),402 },
|
||||||
|
{ wxT("forall"),8704 },
|
||||||
|
{ wxT("frac12"),189 },
|
||||||
|
{ wxT("frac14"),188 },
|
||||||
|
{ wxT("frac34"),190 },
|
||||||
|
{ wxT("frasl"),8260 },
|
||||||
|
{ wxT("gamma"),947 },
|
||||||
|
{ wxT("ge"),8805 },
|
||||||
|
{ wxT("gt"),62 },
|
||||||
|
{ wxT("hArr"),8660 },
|
||||||
|
{ wxT("harr"),8596 },
|
||||||
|
{ wxT("hearts"),9829 },
|
||||||
|
{ wxT("hellip"),8230 },
|
||||||
|
{ wxT("iacute"),237 },
|
||||||
|
{ wxT("icirc"),238 },
|
||||||
|
{ wxT("iexcl"),161 },
|
||||||
|
{ wxT("igrave"),236 },
|
||||||
|
{ wxT("image"),8465 },
|
||||||
|
{ wxT("infin"),8734 },
|
||||||
|
{ wxT("int"),8747 },
|
||||||
|
{ wxT("iota"),953 },
|
||||||
|
{ wxT("iquest"),191 },
|
||||||
|
{ wxT("isin"),8712 },
|
||||||
|
{ wxT("iuml"),239 },
|
||||||
|
{ wxT("kappa"),954 },
|
||||||
|
{ wxT("lArr"),8656 },
|
||||||
|
{ wxT("lambda"),955 },
|
||||||
|
{ wxT("lang"),9001 },
|
||||||
|
{ wxT("laquo"),171 },
|
||||||
|
{ wxT("larr"),8592 },
|
||||||
|
{ wxT("lceil"),8968 },
|
||||||
|
{ wxT("ldquo"),8220 },
|
||||||
|
{ wxT("le"),8804 },
|
||||||
|
{ wxT("lfloor"),8970 },
|
||||||
|
{ wxT("lowast"),8727 },
|
||||||
|
{ wxT("loz"),9674 },
|
||||||
|
{ wxT("lrm"),8206 },
|
||||||
|
{ wxT("lsaquo"),8249 },
|
||||||
|
{ wxT("lsquo"),8216 },
|
||||||
|
{ wxT("lt"),60 },
|
||||||
|
{ wxT("macr"),175 },
|
||||||
|
{ wxT("mdash"),8212 },
|
||||||
|
{ wxT("micro"),181 },
|
||||||
|
{ wxT("middot"),183 },
|
||||||
|
{ wxT("minus"),8722 },
|
||||||
|
{ wxT("mu"),956 },
|
||||||
|
{ wxT("nabla"),8711 },
|
||||||
|
{ wxT("nbsp"),160 },
|
||||||
|
{ wxT("ndash"),8211 },
|
||||||
|
{ wxT("ne"),8800 },
|
||||||
|
{ wxT("ni"),8715 },
|
||||||
|
{ wxT("not"),172 },
|
||||||
|
{ wxT("notin"),8713 },
|
||||||
|
{ wxT("nsub"),8836 },
|
||||||
|
{ wxT("ntilde"),241 },
|
||||||
|
{ wxT("nu"),957 },
|
||||||
|
{ wxT("oacute"),243 },
|
||||||
|
{ wxT("ocirc"),244 },
|
||||||
|
{ wxT("oelig"),339 },
|
||||||
|
{ wxT("ograve"),242 },
|
||||||
|
{ wxT("oline"),8254 },
|
||||||
|
{ wxT("omega"),969 },
|
||||||
|
{ wxT("omicron"),959 },
|
||||||
|
{ wxT("oplus"),8853 },
|
||||||
|
{ wxT("or"),8744 },
|
||||||
|
{ wxT("ordf"),170 },
|
||||||
|
{ wxT("ordm"),186 },
|
||||||
|
{ wxT("oslash"),248 },
|
||||||
|
{ wxT("otilde"),245 },
|
||||||
|
{ wxT("otimes"),8855 },
|
||||||
|
{ wxT("ouml"),246 },
|
||||||
|
{ wxT("para"),182 },
|
||||||
|
{ wxT("part"),8706 },
|
||||||
|
{ wxT("permil"),8240 },
|
||||||
|
{ wxT("perp"),8869 },
|
||||||
|
{ wxT("phi"),966 },
|
||||||
|
{ wxT("pi"),960 },
|
||||||
|
{ wxT("piv"),982 },
|
||||||
|
{ wxT("plusmn"),177 },
|
||||||
|
{ wxT("pound"),163 },
|
||||||
|
{ wxT("prime"),8242 },
|
||||||
|
{ wxT("prod"),8719 },
|
||||||
|
{ wxT("prop"),8733 },
|
||||||
|
{ wxT("psi"),968 },
|
||||||
|
{ wxT("quot"),34 },
|
||||||
|
{ wxT("rArr"),8658 },
|
||||||
|
{ wxT("radic"),8730 },
|
||||||
|
{ wxT("rang"),9002 },
|
||||||
|
{ wxT("raquo"),187 },
|
||||||
|
{ wxT("rarr"),8594 },
|
||||||
|
{ wxT("rceil"),8969 },
|
||||||
|
{ wxT("rdquo"),8221 },
|
||||||
|
{ wxT("real"),8476 },
|
||||||
|
{ wxT("reg"),174 },
|
||||||
|
{ wxT("rfloor"),8971 },
|
||||||
|
{ wxT("rho"),961 },
|
||||||
|
{ wxT("rlm"),8207 },
|
||||||
|
{ wxT("rsaquo"),8250 },
|
||||||
|
{ wxT("rsquo"),8217 },
|
||||||
|
{ wxT("sbquo"),8218 },
|
||||||
|
{ wxT("scaron"),353 },
|
||||||
|
{ wxT("sdot"),8901 },
|
||||||
|
{ wxT("sect"),167 },
|
||||||
|
{ wxT("shy"),173 },
|
||||||
|
{ wxT("sigma"),963 },
|
||||||
|
{ wxT("sigmaf"),962 },
|
||||||
|
{ wxT("sim"),8764 },
|
||||||
|
{ wxT("spades"),9824 },
|
||||||
|
{ wxT("sub"),8834 },
|
||||||
|
{ wxT("sube"),8838 },
|
||||||
|
{ wxT("sum"),8721 },
|
||||||
|
{ wxT("sup"),8835 },
|
||||||
|
{ wxT("sup1"),185 },
|
||||||
|
{ wxT("sup2"),178 },
|
||||||
|
{ wxT("sup3"),179 },
|
||||||
|
{ wxT("supe"),8839 },
|
||||||
|
{ wxT("szlig"),223 },
|
||||||
|
{ wxT("tau"),964 },
|
||||||
|
{ wxT("there4"),8756 },
|
||||||
|
{ wxT("theta"),952 },
|
||||||
|
{ wxT("thetasym"),977 },
|
||||||
|
{ wxT("thinsp"),8201 },
|
||||||
|
{ wxT("thorn"),254 },
|
||||||
|
{ wxT("tilde"),732 },
|
||||||
|
{ wxT("times"),215 },
|
||||||
|
{ wxT("trade"),8482 },
|
||||||
|
{ wxT("uArr"),8657 },
|
||||||
|
{ wxT("uacute"),250 },
|
||||||
|
{ wxT("uarr"),8593 },
|
||||||
|
{ wxT("ucirc"),251 },
|
||||||
|
{ wxT("ugrave"),249 },
|
||||||
|
{ wxT("uml"),168 },
|
||||||
|
{ wxT("upsih"),978 },
|
||||||
|
{ wxT("upsilon"),965 },
|
||||||
|
{ wxT("uuml"),252 },
|
||||||
|
{ wxT("weierp"),8472 },
|
||||||
|
{ wxT("xi"),958 },
|
||||||
|
{ wxT("yacute"),253 },
|
||||||
|
{ wxT("yen"),165 },
|
||||||
|
{ wxT("yuml"),255 },
|
||||||
|
{ wxT("zeta"),950 },
|
||||||
|
{ wxT("zwj"),8205 },
|
||||||
|
{ wxT("zwnj"),8204 },
|
||||||
|
{NULL, 0}};
|
||||||
|
static size_t substitutions_cnt = 0;
|
||||||
|
|
||||||
|
if (substitutions_cnt == 0)
|
||||||
|
while (substitutions[substitutions_cnt].code != 0)
|
||||||
|
substitutions_cnt++;
|
||||||
|
|
||||||
|
wxHtmlEntityInfo *info;
|
||||||
|
info = (wxHtmlEntityInfo*) bsearch(entity.c_str(), substitutions,
|
||||||
|
substitutions_cnt,
|
||||||
|
sizeof(wxHtmlEntityInfo),
|
||||||
|
wxHtmlEntityCompare);
|
||||||
|
if (info)
|
||||||
|
code = info->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code == 0)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return GetCharForCode(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxFSFile *wxHtmlParser::OpenURL(wxHtmlURLType WXUNUSED(type),
|
||||||
|
const wxString& url) const
|
||||||
|
{
|
||||||
|
return GetFS()->OpenFile(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlParser::ExtractCharsetInformation
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxMetaTagParser : public wxHtmlParser
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxObject* GetProduct() { return NULL; }
|
||||||
|
protected:
|
||||||
|
virtual void AddText(const wxChar* WXUNUSED(txt)) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class wxMetaTagHandler : public wxHtmlTagHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxMetaTagHandler(wxString *retval) : wxHtmlTagHandler(), m_retval(retval) {}
|
||||||
|
wxString GetSupportedTags() { return wxT("META,BODY"); }
|
||||||
|
bool HandleTag(const wxHtmlTag& tag);
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxString *m_retval;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool wxMetaTagHandler::HandleTag(const wxHtmlTag& tag)
|
||||||
|
{
|
||||||
|
if (tag.GetName() == _T("BODY"))
|
||||||
|
{
|
||||||
|
m_Parser->StopParsing();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.HasParam(_T("HTTP-EQUIV")) &&
|
||||||
|
tag.GetParam(_T("HTTP-EQUIV")) == _T("Content-Type") &&
|
||||||
|
tag.HasParam(_T("CONTENT")))
|
||||||
|
{
|
||||||
|
wxString content = tag.GetParam(_T("CONTENT"));
|
||||||
|
if (content.Left(19) == _T("text/html; charset="))
|
||||||
|
{
|
||||||
|
*m_retval = content.Mid(19);
|
||||||
|
m_Parser->StopParsing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/
|
||||||
|
wxString wxHtmlParser::ExtractCharsetInformation(const wxString& markup)
|
||||||
|
{
|
||||||
|
wxString charset;
|
||||||
|
wxMetaTagParser parser;
|
||||||
|
parser.AddTagHandler(new wxMetaTagHandler(&charset));
|
||||||
|
parser.Parse(markup);
|
||||||
|
return charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
450
Contrib/NSIS Menu/src/html/htmltag.cpp
Normal file
450
Contrib/NSIS Menu/src/html/htmltag.cpp
Normal file
|
@ -0,0 +1,450 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: htmltag.cpp
|
||||||
|
// Purpose: wxHtmlTag class (represents single tag)
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: htmltag.cpp,v 1.30.2.1 2002/11/04 22:46:22 VZ Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "htmltag.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/htmltag.h"
|
||||||
|
#include "wx/html/htmlpars.h"
|
||||||
|
#include "wx/colour.h"
|
||||||
|
#include <stdio.h> // for vsscanf
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlTagsCache
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct wxHtmlCacheItem
|
||||||
|
{
|
||||||
|
// this is "pos" value passed to wxHtmlTag's constructor.
|
||||||
|
// it is position of '<' character of the tag
|
||||||
|
int Key;
|
||||||
|
|
||||||
|
// end positions for the tag:
|
||||||
|
// end1 is '<' of ending tag,
|
||||||
|
// end2 is '>' or both are
|
||||||
|
// -1 if there is no ending tag for this one...
|
||||||
|
// or -2 if this is ending tag </...>
|
||||||
|
int End1, End2;
|
||||||
|
|
||||||
|
// name of this tag
|
||||||
|
wxChar *Name;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
IMPLEMENT_CLASS(wxHtmlTagsCache,wxObject)
|
||||||
|
|
||||||
|
#define CACHE_INCREMENT 64
|
||||||
|
|
||||||
|
wxHtmlTagsCache::wxHtmlTagsCache(const wxString& source)
|
||||||
|
{
|
||||||
|
const wxChar *src = source.c_str();
|
||||||
|
int tg, stpos;
|
||||||
|
int lng = source.Length();
|
||||||
|
wxChar tagBuffer[256];
|
||||||
|
|
||||||
|
m_Cache = NULL;
|
||||||
|
m_CacheSize = 0;
|
||||||
|
m_CachePos = 0;
|
||||||
|
|
||||||
|
int pos = 0;
|
||||||
|
while (pos < lng)
|
||||||
|
{
|
||||||
|
if (src[pos] == wxT('<')) // tag found:
|
||||||
|
{
|
||||||
|
if (m_CacheSize % CACHE_INCREMENT == 0)
|
||||||
|
m_Cache = (wxHtmlCacheItem*) realloc(m_Cache, (m_CacheSize + CACHE_INCREMENT) * sizeof(wxHtmlCacheItem));
|
||||||
|
tg = m_CacheSize++;
|
||||||
|
m_Cache[tg].Key = stpos = pos++;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for ( i = 0;
|
||||||
|
pos < lng && i < (int)WXSIZEOF(tagBuffer) - 1 &&
|
||||||
|
src[pos] != wxT('>') && !wxIsspace(src[pos]);
|
||||||
|
i++, pos++ )
|
||||||
|
{
|
||||||
|
tagBuffer[i] = wxToupper(src[pos]);
|
||||||
|
}
|
||||||
|
tagBuffer[i] = _T('\0');
|
||||||
|
|
||||||
|
m_Cache[tg].Name = new wxChar[i+1];
|
||||||
|
memcpy(m_Cache[tg].Name, tagBuffer, (i+1)*sizeof(wxChar));
|
||||||
|
|
||||||
|
while (pos < lng && src[pos] != wxT('>')) pos++;
|
||||||
|
|
||||||
|
if (src[stpos+1] == wxT('/')) // ending tag:
|
||||||
|
{
|
||||||
|
m_Cache[tg].End1 = m_Cache[tg].End2 = -2;
|
||||||
|
// find matching begin tag:
|
||||||
|
for (i = tg; i >= 0; i--)
|
||||||
|
if ((m_Cache[i].End1 == -1) && (wxStrcmp(m_Cache[i].Name, tagBuffer+1) == 0))
|
||||||
|
{
|
||||||
|
m_Cache[i].End1 = stpos;
|
||||||
|
m_Cache[i].End2 = pos + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_Cache[tg].End1 = m_Cache[tg].End2 = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ok, we're done, now we'll free .Name members of cache - we don't need it anymore:
|
||||||
|
for (int i = 0; i < m_CacheSize; i++)
|
||||||
|
{
|
||||||
|
delete[] m_Cache[i].Name;
|
||||||
|
m_Cache[i].Name = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlTagsCache::QueryTag(int at, int* end1, int* end2)
|
||||||
|
{
|
||||||
|
if (m_Cache == NULL) return;
|
||||||
|
if (m_Cache[m_CachePos].Key != at)
|
||||||
|
{
|
||||||
|
int delta = (at < m_Cache[m_CachePos].Key) ? -1 : 1;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
m_CachePos += delta;
|
||||||
|
}
|
||||||
|
while (m_Cache[m_CachePos].Key != at);
|
||||||
|
}
|
||||||
|
*end1 = m_Cache[m_CachePos].End1;
|
||||||
|
*end2 = m_Cache[m_CachePos].End2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlTag
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_CLASS(wxHtmlTag,wxObject)
|
||||||
|
|
||||||
|
wxHtmlTag::wxHtmlTag(wxHtmlTag *parent,
|
||||||
|
const wxString& source, int pos, int end_pos,
|
||||||
|
wxHtmlTagsCache *cache,
|
||||||
|
wxHtmlEntitiesParser *entParser) : wxObject()
|
||||||
|
{
|
||||||
|
/* Setup DOM relations */
|
||||||
|
|
||||||
|
m_Next = NULL;
|
||||||
|
m_FirstChild = m_LastChild = NULL;
|
||||||
|
m_Parent = parent;
|
||||||
|
if (parent)
|
||||||
|
{
|
||||||
|
m_Prev = m_Parent->m_LastChild;
|
||||||
|
if (m_Prev == NULL)
|
||||||
|
m_Parent->m_FirstChild = this;
|
||||||
|
else
|
||||||
|
m_Prev->m_Next = this;
|
||||||
|
m_Parent->m_LastChild = this;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_Prev = NULL;
|
||||||
|
|
||||||
|
/* Find parameters and their values: */
|
||||||
|
|
||||||
|
int i;
|
||||||
|
wxChar c;
|
||||||
|
|
||||||
|
// fill-in name, params and begin pos:
|
||||||
|
i = pos+1;
|
||||||
|
|
||||||
|
// find tag's name and convert it to uppercase:
|
||||||
|
while ((i < end_pos) &&
|
||||||
|
((c = source[i++]) != wxT(' ') && c != wxT('\r') &&
|
||||||
|
c != wxT('\n') && c != wxT('\t') &&
|
||||||
|
c != wxT('>')))
|
||||||
|
{
|
||||||
|
if ((c >= wxT('a')) && (c <= wxT('z')))
|
||||||
|
c -= (wxT('a') - wxT('A'));
|
||||||
|
m_Name << c;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the tag has parameters, read them and "normalize" them,
|
||||||
|
// i.e. convert to uppercase, replace whitespaces by spaces and
|
||||||
|
// remove whitespaces around '=':
|
||||||
|
if (source[i-1] != wxT('>'))
|
||||||
|
{
|
||||||
|
#define IS_WHITE(c) (c == wxT(' ') || c == wxT('\r') || \
|
||||||
|
c == wxT('\n') || c == wxT('\t'))
|
||||||
|
wxString pname, pvalue;
|
||||||
|
wxChar quote;
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ST_BEFORE_NAME = 1,
|
||||||
|
ST_NAME,
|
||||||
|
ST_BEFORE_EQ,
|
||||||
|
ST_BEFORE_VALUE,
|
||||||
|
ST_VALUE
|
||||||
|
} state;
|
||||||
|
|
||||||
|
quote = 0;
|
||||||
|
state = ST_BEFORE_NAME;
|
||||||
|
while (i < end_pos)
|
||||||
|
{
|
||||||
|
c = source[i++];
|
||||||
|
|
||||||
|
if (c == wxT('>') && !(state == ST_VALUE && quote != 0))
|
||||||
|
{
|
||||||
|
if (state == ST_BEFORE_EQ || state == ST_NAME)
|
||||||
|
{
|
||||||
|
m_ParamNames.Add(pname);
|
||||||
|
m_ParamValues.Add(wxEmptyString);
|
||||||
|
}
|
||||||
|
else if (state == ST_VALUE && quote == 0)
|
||||||
|
{
|
||||||
|
m_ParamNames.Add(pname);
|
||||||
|
if (entParser)
|
||||||
|
m_ParamValues.Add(entParser->Parse(pvalue));
|
||||||
|
else
|
||||||
|
m_ParamValues.Add(pvalue);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case ST_BEFORE_NAME:
|
||||||
|
if (!IS_WHITE(c))
|
||||||
|
{
|
||||||
|
pname = c;
|
||||||
|
state = ST_NAME;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ST_NAME:
|
||||||
|
if (IS_WHITE(c))
|
||||||
|
state = ST_BEFORE_EQ;
|
||||||
|
else if (c == wxT('='))
|
||||||
|
state = ST_BEFORE_VALUE;
|
||||||
|
else
|
||||||
|
pname << c;
|
||||||
|
break;
|
||||||
|
case ST_BEFORE_EQ:
|
||||||
|
if (c == wxT('='))
|
||||||
|
state = ST_BEFORE_VALUE;
|
||||||
|
else if (!IS_WHITE(c))
|
||||||
|
{
|
||||||
|
m_ParamNames.Add(pname);
|
||||||
|
m_ParamValues.Add(wxEmptyString);
|
||||||
|
pname = c;
|
||||||
|
state = ST_NAME;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ST_BEFORE_VALUE:
|
||||||
|
if (!IS_WHITE(c))
|
||||||
|
{
|
||||||
|
if (c == wxT('"') || c == wxT('\''))
|
||||||
|
quote = c, pvalue = wxEmptyString;
|
||||||
|
else
|
||||||
|
quote = 0, pvalue = c;
|
||||||
|
state = ST_VALUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ST_VALUE:
|
||||||
|
if ((quote != 0 && c == quote) ||
|
||||||
|
(quote == 0 && IS_WHITE(c)))
|
||||||
|
{
|
||||||
|
m_ParamNames.Add(pname);
|
||||||
|
if (quote == 0)
|
||||||
|
{
|
||||||
|
// VS: backward compatibility, no real reason,
|
||||||
|
// but wxHTML code relies on this... :(
|
||||||
|
pvalue.MakeUpper();
|
||||||
|
}
|
||||||
|
if (entParser)
|
||||||
|
m_ParamValues.Add(entParser->Parse(pvalue));
|
||||||
|
else
|
||||||
|
m_ParamValues.Add(pvalue);
|
||||||
|
state = ST_BEFORE_NAME;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
pvalue << c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef IS_WHITE
|
||||||
|
}
|
||||||
|
m_Begin = i;
|
||||||
|
|
||||||
|
cache->QueryTag(pos, &m_End1, &m_End2);
|
||||||
|
if (m_End1 > end_pos) m_End1 = end_pos;
|
||||||
|
if (m_End2 > end_pos) m_End2 = end_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlTag::~wxHtmlTag()
|
||||||
|
{
|
||||||
|
wxHtmlTag *t1, *t2;
|
||||||
|
t1 = m_FirstChild;
|
||||||
|
while (t1)
|
||||||
|
{
|
||||||
|
t2 = t1->GetNextSibling();
|
||||||
|
delete t1;
|
||||||
|
t1 = t2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlTag::HasParam(const wxString& par) const
|
||||||
|
{
|
||||||
|
return (m_ParamNames.Index(par, FALSE) != wxNOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxHtmlTag::GetParam(const wxString& par, bool with_commas) const
|
||||||
|
{
|
||||||
|
int index = m_ParamNames.Index(par, FALSE);
|
||||||
|
if (index == wxNOT_FOUND)
|
||||||
|
return wxEmptyString;
|
||||||
|
if (with_commas)
|
||||||
|
{
|
||||||
|
// VS: backward compatibility, seems to be never used by wxHTML...
|
||||||
|
wxString s;
|
||||||
|
s << wxT('"') << m_ParamValues[index] << wxT('"');
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return m_ParamValues[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxHtmlTag::ScanParam(const wxString& par,
|
||||||
|
const wxChar *format,
|
||||||
|
void *param) const
|
||||||
|
{
|
||||||
|
wxString parval = GetParam(par);
|
||||||
|
return wxSscanf(parval, format, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlTag::GetParamAsColour(const wxString& par, wxColour *clr) const
|
||||||
|
{
|
||||||
|
wxString str = GetParam(par);
|
||||||
|
|
||||||
|
if (str.IsEmpty()) return FALSE;
|
||||||
|
if (str.GetChar(0) == wxT('#'))
|
||||||
|
{
|
||||||
|
unsigned long tmp;
|
||||||
|
if (ScanParam(par, wxT("#%lX"), &tmp) != 1)
|
||||||
|
return FALSE;
|
||||||
|
*clr = wxColour((unsigned char)((tmp & 0xFF0000) >> 16),
|
||||||
|
(unsigned char)((tmp & 0x00FF00) >> 8),
|
||||||
|
(unsigned char)(tmp & 0x0000FF));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Handle colours defined in HTML 4.0:
|
||||||
|
#define HTML_COLOUR(name,r,g,b) \
|
||||||
|
if (str.IsSameAs(wxT(name), FALSE)) \
|
||||||
|
{ *clr = wxColour(r,g,b); return TRUE; }
|
||||||
|
HTML_COLOUR("black", 0x00,0x00,0x00)
|
||||||
|
HTML_COLOUR("silver", 0xC0,0xC0,0xC0)
|
||||||
|
HTML_COLOUR("gray", 0x80,0x80,0x80)
|
||||||
|
HTML_COLOUR("white", 0xFF,0xFF,0xFF)
|
||||||
|
HTML_COLOUR("maroon", 0x80,0x00,0x00)
|
||||||
|
HTML_COLOUR("red", 0xFF,0x00,0x00)
|
||||||
|
HTML_COLOUR("purple", 0x80,0x00,0x80)
|
||||||
|
HTML_COLOUR("fuchsia", 0xFF,0x00,0xFF)
|
||||||
|
HTML_COLOUR("green", 0x00,0x80,0x00)
|
||||||
|
HTML_COLOUR("lime", 0x00,0xFF,0x00)
|
||||||
|
HTML_COLOUR("olive", 0x80,0x80,0x00)
|
||||||
|
HTML_COLOUR("yellow", 0xFF,0xFF,0x00)
|
||||||
|
HTML_COLOUR("navy", 0x00,0x00,0x80)
|
||||||
|
HTML_COLOUR("blue", 0x00,0x00,0xFF)
|
||||||
|
HTML_COLOUR("teal", 0x00,0x80,0x80)
|
||||||
|
HTML_COLOUR("aqua", 0x00,0xFF,0xFF)
|
||||||
|
#undef HTML_COLOUR
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlTag::GetParamAsInt(const wxString& par, int *clr) const
|
||||||
|
{
|
||||||
|
if (!HasParam(par)) return FALSE;
|
||||||
|
long i;
|
||||||
|
bool succ = GetParam(par).ToLong(&i);
|
||||||
|
*clr = (int)i;
|
||||||
|
return succ;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString wxHtmlTag::GetAllParams() const
|
||||||
|
{
|
||||||
|
// VS: this function is for backward compatiblity only,
|
||||||
|
// never used by wxHTML
|
||||||
|
wxString s;
|
||||||
|
size_t cnt = m_ParamNames.GetCount();
|
||||||
|
for (size_t i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
s << m_ParamNames[i];
|
||||||
|
s << wxT('=');
|
||||||
|
if (m_ParamValues[i].Find(wxT('"')) != wxNOT_FOUND)
|
||||||
|
s << wxT('\'') << m_ParamValues[i] << wxT('\'');
|
||||||
|
else
|
||||||
|
s << wxT('"') << m_ParamValues[i] << wxT('"');
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlTag *wxHtmlTag::GetFirstSibling() const
|
||||||
|
{
|
||||||
|
if (m_Parent)
|
||||||
|
return m_Parent->m_FirstChild;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxHtmlTag *cur = (wxHtmlTag*)this;
|
||||||
|
while (cur->m_Prev)
|
||||||
|
cur = cur->m_Prev;
|
||||||
|
return cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlTag *wxHtmlTag::GetLastSibling() const
|
||||||
|
{
|
||||||
|
if (m_Parent)
|
||||||
|
return m_Parent->m_LastChild;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxHtmlTag *cur = (wxHtmlTag*)this;
|
||||||
|
while (cur->m_Next)
|
||||||
|
cur = cur->m_Next;
|
||||||
|
return cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlTag *wxHtmlTag::GetNextTag() const
|
||||||
|
{
|
||||||
|
if (m_FirstChild) return m_FirstChild;
|
||||||
|
if (m_Next) return m_Next;
|
||||||
|
wxHtmlTag *cur = m_Parent;
|
||||||
|
if (!cur) return NULL;
|
||||||
|
while (cur->m_Parent && !cur->m_Next)
|
||||||
|
cur = cur->m_Parent;
|
||||||
|
return cur->m_Next;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
826
Contrib/NSIS Menu/src/html/htmlwin.cpp
Normal file
826
Contrib/NSIS Menu/src/html/htmlwin.cpp
Normal file
|
@ -0,0 +1,826 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: htmlwin.cpp
|
||||||
|
// Purpose: wxHtmlWindow class for parsing & displaying HTML (implementation)
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: htmlwin.cpp,v 1.62.2.1 2002/11/04 22:46:22 VZ Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "htmlwin.h"
|
||||||
|
#pragma implementation "htmlproc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#include "wx/log.h"
|
||||||
|
#include "wx/intl.h"
|
||||||
|
#include "wx/dcclient.h"
|
||||||
|
#include "wx/frame.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/htmlwin.h"
|
||||||
|
#include "wx/html/htmlproc.h"
|
||||||
|
#include "wx/list.h"
|
||||||
|
|
||||||
|
#include "wx/arrimpl.cpp"
|
||||||
|
#include "wx/listimpl.cpp"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlHistoryItem
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// item of history list
|
||||||
|
class WXDLLEXPORT wxHtmlHistoryItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxHtmlHistoryItem(const wxString& p, const wxString& a) {m_Page = p, m_Anchor = a, m_Pos = 0;}
|
||||||
|
int GetPos() const {return m_Pos;}
|
||||||
|
void SetPos(int p) {m_Pos = p;}
|
||||||
|
const wxString& GetPage() const {return m_Page;}
|
||||||
|
const wxString& GetAnchor() const {return m_Anchor;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxString m_Page;
|
||||||
|
wxString m_Anchor;
|
||||||
|
int m_Pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// our private arrays:
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
WX_DECLARE_OBJARRAY(wxHtmlHistoryItem, wxHtmlHistoryArray);
|
||||||
|
WX_DEFINE_OBJARRAY(wxHtmlHistoryArray);
|
||||||
|
|
||||||
|
WX_DECLARE_LIST(wxHtmlProcessor, wxHtmlProcessorList);
|
||||||
|
WX_DEFINE_LIST(wxHtmlProcessorList);
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlWindow
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::Init()
|
||||||
|
{
|
||||||
|
m_tmpMouseMoved = FALSE;
|
||||||
|
m_tmpLastLink = NULL;
|
||||||
|
m_tmpLastCell = NULL;
|
||||||
|
m_tmpCanDrawLocks = 0;
|
||||||
|
m_FS = new wxFileSystem();
|
||||||
|
m_RelatedStatusBar = -1;
|
||||||
|
m_RelatedFrame = NULL;
|
||||||
|
m_TitleFormat = wxT("%s");
|
||||||
|
m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString;
|
||||||
|
m_Cell = NULL;
|
||||||
|
m_Parser = new wxHtmlWinParser(this);
|
||||||
|
m_Parser->SetFS(m_FS);
|
||||||
|
m_HistoryPos = -1;
|
||||||
|
m_HistoryOn = TRUE;
|
||||||
|
m_History = new wxHtmlHistoryArray;
|
||||||
|
m_Processors = NULL;
|
||||||
|
m_Style = 0;
|
||||||
|
SetBorders(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlWindow::Create(wxWindow *parent, wxWindowID id,
|
||||||
|
const wxPoint& pos, const wxSize& size,
|
||||||
|
long style, const wxString& name)
|
||||||
|
{
|
||||||
|
if (!wxScrolledWindow::Create(parent, id, pos, size,
|
||||||
|
style | wxVSCROLL | wxHSCROLL, name))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
m_Style = style;
|
||||||
|
SetPage(wxT("<html><body></body></html>"));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlWindow::~wxHtmlWindow()
|
||||||
|
{
|
||||||
|
HistoryClear();
|
||||||
|
|
||||||
|
if (m_Cell) delete m_Cell;
|
||||||
|
|
||||||
|
delete m_Parser;
|
||||||
|
delete m_FS;
|
||||||
|
delete m_History;
|
||||||
|
delete m_Processors;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::SetRelatedFrame(wxFrame* frame, const wxString& format)
|
||||||
|
{
|
||||||
|
m_RelatedFrame = frame;
|
||||||
|
m_TitleFormat = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::SetRelatedStatusBar(int bar)
|
||||||
|
{
|
||||||
|
m_RelatedStatusBar = bar;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::SetFonts(wxString normal_face, wxString fixed_face, const int *sizes)
|
||||||
|
{
|
||||||
|
wxString op = m_OpenedPage;
|
||||||
|
|
||||||
|
m_Parser->SetFonts(normal_face, fixed_face, sizes);
|
||||||
|
// fonts changed => contents invalid, so reload the page:
|
||||||
|
SetPage(wxT("<html><body></body></html>"));
|
||||||
|
if (!op.IsEmpty()) LoadPage(op);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlWindow::SetPage(const wxString& source)
|
||||||
|
{
|
||||||
|
wxString newsrc(source);
|
||||||
|
|
||||||
|
// pass HTML through registered processors:
|
||||||
|
if (m_Processors || m_GlobalProcessors)
|
||||||
|
{
|
||||||
|
wxHtmlProcessorList::Node *nodeL, *nodeG;
|
||||||
|
int prL, prG;
|
||||||
|
|
||||||
|
nodeL = (m_Processors) ? m_Processors->GetFirst() : NULL;
|
||||||
|
nodeG = (m_GlobalProcessors) ? m_GlobalProcessors->GetFirst() : NULL;
|
||||||
|
|
||||||
|
// VS: there are two lists, global and local, both of them sorted by
|
||||||
|
// priority. Since we have to go through _both_ lists with
|
||||||
|
// decreasing priority, we "merge-sort" the lists on-line by
|
||||||
|
// processing that one of the two heads that has higher priority
|
||||||
|
// in every iteration
|
||||||
|
while (nodeL || nodeG)
|
||||||
|
{
|
||||||
|
prL = (nodeL) ? nodeL->GetData()->GetPriority() : -1;
|
||||||
|
prG = (nodeG) ? nodeG->GetData()->GetPriority() : -1;
|
||||||
|
if (prL > prG)
|
||||||
|
{
|
||||||
|
if (nodeL->GetData()->IsEnabled())
|
||||||
|
newsrc = nodeL->GetData()->Process(newsrc);
|
||||||
|
nodeL = nodeL->GetNext();
|
||||||
|
}
|
||||||
|
else // prL <= prG
|
||||||
|
{
|
||||||
|
if (nodeG->GetData()->IsEnabled())
|
||||||
|
newsrc = nodeG->GetData()->Process(newsrc);
|
||||||
|
nodeG = nodeG->GetNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ...and run the parser on it:
|
||||||
|
wxClientDC *dc = new wxClientDC(this);
|
||||||
|
dc->SetMapMode(wxMM_TEXT);
|
||||||
|
SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF));
|
||||||
|
m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString;
|
||||||
|
m_Parser->SetDC(dc);
|
||||||
|
if (m_Cell)
|
||||||
|
{
|
||||||
|
delete m_Cell;
|
||||||
|
m_Cell = NULL;
|
||||||
|
}
|
||||||
|
m_Cell = (wxHtmlContainerCell*) m_Parser->Parse(newsrc);
|
||||||
|
delete dc;
|
||||||
|
m_Cell->SetIndent(m_Borders, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS);
|
||||||
|
m_Cell->SetAlignHor(wxHTML_ALIGN_CENTER);
|
||||||
|
CreateLayout();
|
||||||
|
if (m_tmpCanDrawLocks == 0)
|
||||||
|
Refresh();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlWindow::AppendToPage(const wxString& source)
|
||||||
|
{
|
||||||
|
return SetPage(*(GetParser()->GetSource()) + source);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlWindow::LoadPage(const wxString& location)
|
||||||
|
{
|
||||||
|
wxBusyCursor busyCursor;
|
||||||
|
|
||||||
|
wxFSFile *f;
|
||||||
|
bool rt_val;
|
||||||
|
bool needs_refresh = FALSE;
|
||||||
|
|
||||||
|
m_tmpCanDrawLocks++;
|
||||||
|
if (m_HistoryOn && (m_HistoryPos != -1))
|
||||||
|
{
|
||||||
|
// store scroll position into history item:
|
||||||
|
int x, y;
|
||||||
|
GetViewStart(&x, &y);
|
||||||
|
(*m_History)[m_HistoryPos].SetPos(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location[0] == wxT('#'))
|
||||||
|
{
|
||||||
|
// local anchor:
|
||||||
|
wxString anch = location.Mid(1) /*1 to end*/;
|
||||||
|
m_tmpCanDrawLocks--;
|
||||||
|
rt_val = ScrollToAnchor(anch);
|
||||||
|
m_tmpCanDrawLocks++;
|
||||||
|
}
|
||||||
|
else if (location.Find(wxT('#')) != wxNOT_FOUND && location.BeforeFirst(wxT('#')) == m_OpenedPage)
|
||||||
|
{
|
||||||
|
wxString anch = location.AfterFirst(wxT('#'));
|
||||||
|
m_tmpCanDrawLocks--;
|
||||||
|
rt_val = ScrollToAnchor(anch);
|
||||||
|
m_tmpCanDrawLocks++;
|
||||||
|
}
|
||||||
|
else if (location.Find(wxT('#')) != wxNOT_FOUND &&
|
||||||
|
(m_FS->GetPath() + location.BeforeFirst(wxT('#'))) == m_OpenedPage)
|
||||||
|
{
|
||||||
|
wxString anch = location.AfterFirst(wxT('#'));
|
||||||
|
m_tmpCanDrawLocks--;
|
||||||
|
rt_val = ScrollToAnchor(anch);
|
||||||
|
m_tmpCanDrawLocks++;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
needs_refresh = TRUE;
|
||||||
|
// load&display it:
|
||||||
|
if (m_RelatedStatusBar != -1)
|
||||||
|
{
|
||||||
|
m_RelatedFrame->SetStatusText(_("Connecting..."), m_RelatedStatusBar);
|
||||||
|
Refresh(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
f = m_Parser->OpenURL(wxHTML_URL_PAGE, location);
|
||||||
|
|
||||||
|
if (f == NULL)
|
||||||
|
{
|
||||||
|
wxLogError(_("Unable to open requested HTML document: %s"), location.c_str());
|
||||||
|
m_tmpCanDrawLocks--;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxNode *node;
|
||||||
|
wxString src = wxEmptyString;
|
||||||
|
|
||||||
|
if (m_RelatedStatusBar != -1)
|
||||||
|
{
|
||||||
|
wxString msg = _("Loading : ") + location;
|
||||||
|
m_RelatedFrame->SetStatusText(msg, m_RelatedStatusBar);
|
||||||
|
Refresh(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
node = m_Filters.GetFirst();
|
||||||
|
while (node)
|
||||||
|
{
|
||||||
|
wxHtmlFilter *h = (wxHtmlFilter*) node->GetData();
|
||||||
|
if (h->CanRead(*f))
|
||||||
|
{
|
||||||
|
src = h->ReadFile(*f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
node = node->GetNext();
|
||||||
|
}
|
||||||
|
if (src == wxEmptyString)
|
||||||
|
{
|
||||||
|
if (m_DefaultFilter == NULL) m_DefaultFilter = GetDefaultFilter();
|
||||||
|
src = m_DefaultFilter->ReadFile(*f);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_FS->ChangePathTo(f->GetLocation());
|
||||||
|
rt_val = SetPage(src);
|
||||||
|
m_OpenedPage = f->GetLocation();
|
||||||
|
if (f->GetAnchor() != wxEmptyString)
|
||||||
|
{
|
||||||
|
ScrollToAnchor(f->GetAnchor());
|
||||||
|
}
|
||||||
|
|
||||||
|
delete f;
|
||||||
|
|
||||||
|
if (m_RelatedStatusBar != -1) m_RelatedFrame->SetStatusText(_("Done"), m_RelatedStatusBar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_HistoryOn) // add this page to history there:
|
||||||
|
{
|
||||||
|
int c = m_History->GetCount() - (m_HistoryPos + 1);
|
||||||
|
|
||||||
|
if (m_HistoryPos < 0 ||
|
||||||
|
(*m_History)[m_HistoryPos].GetPage() != m_OpenedPage ||
|
||||||
|
(*m_History)[m_HistoryPos].GetAnchor() != m_OpenedAnchor)
|
||||||
|
{
|
||||||
|
m_HistoryPos++;
|
||||||
|
for (int i = 0; i < c; i++)
|
||||||
|
m_History->RemoveAt(m_HistoryPos);
|
||||||
|
m_History->Add(new wxHtmlHistoryItem(m_OpenedPage, m_OpenedAnchor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_OpenedPageTitle == wxEmptyString)
|
||||||
|
OnSetTitle(wxFileNameFromPath(m_OpenedPage));
|
||||||
|
|
||||||
|
if (needs_refresh)
|
||||||
|
{
|
||||||
|
m_tmpCanDrawLocks--;
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_tmpCanDrawLocks--;
|
||||||
|
|
||||||
|
return rt_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlWindow::ScrollToAnchor(const wxString& anchor)
|
||||||
|
{
|
||||||
|
const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor);
|
||||||
|
if (!c)
|
||||||
|
{
|
||||||
|
wxLogWarning(_("HTML anchor %s does not exist."), anchor.c_str());
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int y;
|
||||||
|
|
||||||
|
for (y = 0; c != NULL; c = c->GetParent()) y += c->GetPosY();
|
||||||
|
Scroll(-1, y / wxHTML_SCROLL_STEP);
|
||||||
|
m_OpenedAnchor = anchor;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::OnSetTitle(const wxString& title)
|
||||||
|
{
|
||||||
|
if (m_RelatedFrame)
|
||||||
|
{
|
||||||
|
wxString tit;
|
||||||
|
tit.Printf(m_TitleFormat, title.c_str());
|
||||||
|
m_RelatedFrame->SetTitle(tit);
|
||||||
|
}
|
||||||
|
m_OpenedPageTitle = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::CreateLayout()
|
||||||
|
{
|
||||||
|
int ClientWidth, ClientHeight;
|
||||||
|
|
||||||
|
if (!m_Cell) return;
|
||||||
|
|
||||||
|
if (m_Style & wxHW_SCROLLBAR_NEVER)
|
||||||
|
{
|
||||||
|
SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // always off
|
||||||
|
GetClientSize(&ClientWidth, &ClientHeight);
|
||||||
|
m_Cell->Layout(ClientWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
GetClientSize(&ClientWidth, &ClientHeight);
|
||||||
|
m_Cell->Layout(ClientWidth);
|
||||||
|
if (ClientHeight < m_Cell->GetHeight() + GetCharHeight())
|
||||||
|
{
|
||||||
|
SetScrollbars(
|
||||||
|
wxHTML_SCROLL_STEP, wxHTML_SCROLL_STEP,
|
||||||
|
m_Cell->GetWidth() / wxHTML_SCROLL_STEP,
|
||||||
|
(m_Cell->GetHeight() + GetCharHeight()) / wxHTML_SCROLL_STEP
|
||||||
|
/*cheat: top-level frag is always container*/);
|
||||||
|
}
|
||||||
|
else /* we fit into window, no need for scrollbars */
|
||||||
|
{
|
||||||
|
SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // disable...
|
||||||
|
GetClientSize(&ClientWidth, &ClientHeight);
|
||||||
|
m_Cell->Layout(ClientWidth); // ...and relayout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::ReadCustomization(wxConfigBase *cfg, wxString path)
|
||||||
|
{
|
||||||
|
wxString oldpath;
|
||||||
|
wxString tmp;
|
||||||
|
int p_fontsizes[7];
|
||||||
|
wxString p_fff, p_ffn;
|
||||||
|
|
||||||
|
if (path != wxEmptyString)
|
||||||
|
{
|
||||||
|
oldpath = cfg->GetPath();
|
||||||
|
cfg->SetPath(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Borders = cfg->Read(wxT("wxHtmlWindow/Borders"), m_Borders);
|
||||||
|
p_fff = cfg->Read(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser->m_FontFaceFixed);
|
||||||
|
p_ffn = cfg->Read(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser->m_FontFaceNormal);
|
||||||
|
for (int i = 0; i < 7; i++)
|
||||||
|
{
|
||||||
|
tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i);
|
||||||
|
p_fontsizes[i] = cfg->Read(tmp, m_Parser->m_FontsSizes[i]);
|
||||||
|
}
|
||||||
|
SetFonts(p_ffn, p_fff, p_fontsizes);
|
||||||
|
|
||||||
|
if (path != wxEmptyString)
|
||||||
|
cfg->SetPath(oldpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::WriteCustomization(wxConfigBase *cfg, wxString path)
|
||||||
|
{
|
||||||
|
wxString oldpath;
|
||||||
|
wxString tmp;
|
||||||
|
|
||||||
|
if (path != wxEmptyString)
|
||||||
|
{
|
||||||
|
oldpath = cfg->GetPath();
|
||||||
|
cfg->SetPath(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg->Write(wxT("wxHtmlWindow/Borders"), (long) m_Borders);
|
||||||
|
cfg->Write(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser->m_FontFaceFixed);
|
||||||
|
cfg->Write(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser->m_FontFaceNormal);
|
||||||
|
for (int i = 0; i < 7; i++)
|
||||||
|
{
|
||||||
|
tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i);
|
||||||
|
cfg->Write(tmp, (long) m_Parser->m_FontsSizes[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path != wxEmptyString)
|
||||||
|
cfg->SetPath(oldpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlWindow::HistoryBack()
|
||||||
|
{
|
||||||
|
wxString a, l;
|
||||||
|
|
||||||
|
if (m_HistoryPos < 1) return FALSE;
|
||||||
|
|
||||||
|
// store scroll position into history item:
|
||||||
|
int x, y;
|
||||||
|
GetViewStart(&x, &y);
|
||||||
|
(*m_History)[m_HistoryPos].SetPos(y);
|
||||||
|
|
||||||
|
// go to previous position:
|
||||||
|
m_HistoryPos--;
|
||||||
|
|
||||||
|
l = (*m_History)[m_HistoryPos].GetPage();
|
||||||
|
a = (*m_History)[m_HistoryPos].GetAnchor();
|
||||||
|
m_HistoryOn = FALSE;
|
||||||
|
m_tmpCanDrawLocks++;
|
||||||
|
if (a == wxEmptyString) LoadPage(l);
|
||||||
|
else LoadPage(l + wxT("#") + a);
|
||||||
|
m_HistoryOn = TRUE;
|
||||||
|
m_tmpCanDrawLocks--;
|
||||||
|
Scroll(0, (*m_History)[m_HistoryPos].GetPos());
|
||||||
|
Refresh();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlWindow::HistoryCanBack()
|
||||||
|
{
|
||||||
|
if (m_HistoryPos < 1) return FALSE;
|
||||||
|
return TRUE ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlWindow::HistoryForward()
|
||||||
|
{
|
||||||
|
wxString a, l;
|
||||||
|
|
||||||
|
if (m_HistoryPos == -1) return FALSE;
|
||||||
|
if (m_HistoryPos >= (int)m_History->GetCount() - 1)return FALSE;
|
||||||
|
|
||||||
|
m_OpenedPage = wxEmptyString; // this will disable adding new entry into history in LoadPage()
|
||||||
|
|
||||||
|
m_HistoryPos++;
|
||||||
|
l = (*m_History)[m_HistoryPos].GetPage();
|
||||||
|
a = (*m_History)[m_HistoryPos].GetAnchor();
|
||||||
|
m_HistoryOn = FALSE;
|
||||||
|
m_tmpCanDrawLocks++;
|
||||||
|
if (a == wxEmptyString) LoadPage(l);
|
||||||
|
else LoadPage(l + wxT("#") + a);
|
||||||
|
m_HistoryOn = TRUE;
|
||||||
|
m_tmpCanDrawLocks--;
|
||||||
|
Scroll(0, (*m_History)[m_HistoryPos].GetPos());
|
||||||
|
Refresh();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxHtmlWindow::HistoryCanForward()
|
||||||
|
{
|
||||||
|
if (m_HistoryPos == -1) return FALSE;
|
||||||
|
if (m_HistoryPos >= (int)m_History->GetCount() - 1)return FALSE;
|
||||||
|
return TRUE ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::HistoryClear()
|
||||||
|
{
|
||||||
|
m_History->Empty();
|
||||||
|
m_HistoryPos = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlWindow::AddProcessor(wxHtmlProcessor *processor)
|
||||||
|
{
|
||||||
|
if (!m_Processors)
|
||||||
|
{
|
||||||
|
m_Processors = new wxHtmlProcessorList;
|
||||||
|
m_Processors->DeleteContents(TRUE);
|
||||||
|
}
|
||||||
|
wxHtmlProcessorList::Node *node;
|
||||||
|
|
||||||
|
for (node = m_Processors->GetFirst(); node; node = node->GetNext())
|
||||||
|
{
|
||||||
|
if (processor->GetPriority() > node->GetData()->GetPriority())
|
||||||
|
{
|
||||||
|
m_Processors->Insert(node, processor);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_Processors->Append(processor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*static */ void wxHtmlWindow::AddGlobalProcessor(wxHtmlProcessor *processor)
|
||||||
|
{
|
||||||
|
if (!m_GlobalProcessors)
|
||||||
|
{
|
||||||
|
m_GlobalProcessors = new wxHtmlProcessorList;
|
||||||
|
m_GlobalProcessors->DeleteContents(TRUE);
|
||||||
|
}
|
||||||
|
wxHtmlProcessorList::Node *node;
|
||||||
|
|
||||||
|
for (node = m_GlobalProcessors->GetFirst(); node; node = node->GetNext())
|
||||||
|
{
|
||||||
|
if (processor->GetPriority() > node->GetData()->GetPriority())
|
||||||
|
{
|
||||||
|
m_GlobalProcessors->Insert(node, processor);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_GlobalProcessors->Append(processor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxList wxHtmlWindow::m_Filters;
|
||||||
|
wxHtmlFilter *wxHtmlWindow::m_DefaultFilter = NULL;
|
||||||
|
wxCursor *wxHtmlWindow::s_cur_hand = NULL;
|
||||||
|
wxCursor *wxHtmlWindow::s_cur_arrow = NULL;
|
||||||
|
wxHtmlProcessorList *wxHtmlWindow::m_GlobalProcessors = NULL;
|
||||||
|
|
||||||
|
void wxHtmlWindow::CleanUpStatics()
|
||||||
|
{
|
||||||
|
delete m_DefaultFilter;
|
||||||
|
m_DefaultFilter = NULL;
|
||||||
|
m_Filters.DeleteContents(TRUE);
|
||||||
|
m_Filters.Clear();
|
||||||
|
delete m_GlobalProcessors;
|
||||||
|
m_GlobalProcessors = NULL;
|
||||||
|
delete s_cur_hand;
|
||||||
|
delete s_cur_arrow;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::AddFilter(wxHtmlFilter *filter)
|
||||||
|
{
|
||||||
|
m_Filters.Append(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link)
|
||||||
|
{
|
||||||
|
char apppath[MAX_PATH],*temp;
|
||||||
|
GetModuleFileName(NULL,apppath,sizeof(apppath));
|
||||||
|
temp=strrchr(apppath,'\\');
|
||||||
|
if(temp!=NULL) *temp=0;
|
||||||
|
|
||||||
|
char fullpath[MAX_PATH];
|
||||||
|
|
||||||
|
if (link.GetHref().Left(3).Cmp("EX:") == 0)
|
||||||
|
{
|
||||||
|
// External
|
||||||
|
|
||||||
|
if ((link.GetHref().Left(10).Cmp("EX:http://") == 0) || (link.GetHref().Left(9).Cmp("EX:irc://") == 0))
|
||||||
|
{
|
||||||
|
// Internet
|
||||||
|
ShellExecute(0, "open", link.GetHref().Mid(3), NULL, NULL, SW_SHOW);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
_snprintf(fullpath,sizeof(fullpath),"%s\\%s",apppath,link.GetHref().Mid(3));
|
||||||
|
|
||||||
|
if (wxFileExists(fullpath) || wxDirExists(fullpath))
|
||||||
|
{
|
||||||
|
ShellExecute(0, "open", fullpath, NULL, NULL, SW_SHOW);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Feature not installed
|
||||||
|
_snprintf(fullpath,sizeof(fullpath),"%s\\Menu\\notinstalled.html",apppath,link.GetHref());
|
||||||
|
LoadPage(fullpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_snprintf(fullpath,sizeof(fullpath),"%s\\Menu\\%s",apppath,link.GetHref());
|
||||||
|
LoadPage(fullpath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlWindow::OnCellClicked(wxHtmlCell *cell,
|
||||||
|
wxCoord x, wxCoord y,
|
||||||
|
const wxMouseEvent& event)
|
||||||
|
{
|
||||||
|
wxCHECK_RET( cell, _T("can't be called with NULL cell") );
|
||||||
|
|
||||||
|
cell->OnMouseClick(this, x, y, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlWindow::OnCellMouseHover(wxHtmlCell * WXUNUSED(cell),
|
||||||
|
wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
|
||||||
|
{
|
||||||
|
// do nothing here
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlWindow::OnDraw(wxDC& dc)
|
||||||
|
{
|
||||||
|
if (m_tmpCanDrawLocks > 0 || m_Cell == NULL) return;
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
wxRect rect = GetUpdateRegion().GetBox();
|
||||||
|
|
||||||
|
dc.SetMapMode(wxMM_TEXT);
|
||||||
|
dc.SetBackgroundMode(wxTRANSPARENT);
|
||||||
|
GetViewStart(&x, &y);
|
||||||
|
|
||||||
|
m_Cell->Draw(dc, 0, 0,
|
||||||
|
y * wxHTML_SCROLL_STEP + rect.GetTop(),
|
||||||
|
y * wxHTML_SCROLL_STEP + rect.GetBottom());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::OnSize(wxSizeEvent& event)
|
||||||
|
{
|
||||||
|
wxScrolledWindow::OnSize(event);
|
||||||
|
CreateLayout();
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::OnMouseEvent(wxMouseEvent& event)
|
||||||
|
{
|
||||||
|
m_tmpMouseMoved = TRUE;
|
||||||
|
|
||||||
|
if (event.ButtonDown())
|
||||||
|
{
|
||||||
|
SetFocus();
|
||||||
|
if ( m_Cell )
|
||||||
|
{
|
||||||
|
int sx, sy;
|
||||||
|
GetViewStart(&sx, &sy);
|
||||||
|
sx *= wxHTML_SCROLL_STEP;
|
||||||
|
sy *= wxHTML_SCROLL_STEP;
|
||||||
|
|
||||||
|
wxPoint pos = event.GetPosition();
|
||||||
|
pos.x += sx;
|
||||||
|
pos.y += sy;
|
||||||
|
|
||||||
|
wxHtmlCell *cell = m_Cell->FindCellByPos(pos.x, pos.y);
|
||||||
|
|
||||||
|
// VZ: is it possible that we don't find anything at all?
|
||||||
|
// VS: yes. FindCellByPos returns terminal cell and
|
||||||
|
// containers may have empty borders
|
||||||
|
if ( cell )
|
||||||
|
OnCellClicked(cell, pos.x, pos.y, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
if (s_cur_hand == NULL)
|
||||||
|
{
|
||||||
|
s_cur_hand = new wxCursor(wxCURSOR_HAND);
|
||||||
|
s_cur_arrow = new wxCursor(wxCURSOR_ARROW);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_tmpMouseMoved && (m_Cell != NULL))
|
||||||
|
{
|
||||||
|
int sx, sy;
|
||||||
|
GetViewStart(&sx, &sy);
|
||||||
|
sx *= wxHTML_SCROLL_STEP;
|
||||||
|
sy *= wxHTML_SCROLL_STEP;
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
wxGetMousePosition(&x, &y);
|
||||||
|
ScreenToClient(&x, &y);
|
||||||
|
x += sx;
|
||||||
|
y += sy;
|
||||||
|
|
||||||
|
wxHtmlCell *cell = m_Cell->FindCellByPos(x, y);
|
||||||
|
if ( cell != m_tmpLastCell )
|
||||||
|
{
|
||||||
|
wxHtmlLinkInfo *lnk = cell ? cell->GetLink(x, y) : NULL;
|
||||||
|
|
||||||
|
if (lnk != m_tmpLastLink)
|
||||||
|
{
|
||||||
|
if (lnk == NULL)
|
||||||
|
{
|
||||||
|
SetCursor(*s_cur_arrow);
|
||||||
|
if (m_RelatedStatusBar != -1)
|
||||||
|
m_RelatedFrame->SetStatusText(wxEmptyString, m_RelatedStatusBar);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetCursor(*s_cur_hand);
|
||||||
|
if (m_RelatedStatusBar != -1)
|
||||||
|
m_RelatedFrame->SetStatusText(lnk->GetHref(), m_RelatedStatusBar);
|
||||||
|
}
|
||||||
|
m_tmpLastLink = lnk;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_tmpLastCell = cell;
|
||||||
|
}
|
||||||
|
else // mouse moved but stayed in the same cell
|
||||||
|
{
|
||||||
|
if ( cell )
|
||||||
|
OnCellMouseHover(cell, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_tmpMouseMoved = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor,wxObject)
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindow,wxScrolledWindow)
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(wxHtmlWindow, wxScrolledWindow)
|
||||||
|
EVT_SIZE(wxHtmlWindow::OnSize)
|
||||||
|
EVT_LEFT_DOWN(wxHtmlWindow::OnMouseEvent)
|
||||||
|
EVT_RIGHT_DOWN(wxHtmlWindow::OnMouseEvent)
|
||||||
|
EVT_MOTION(wxHtmlWindow::OnMouseEvent)
|
||||||
|
EVT_IDLE(wxHtmlWindow::OnIdle)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// A module to allow initialization/cleanup
|
||||||
|
// without calling these functions from app.cpp or from
|
||||||
|
// the user's application.
|
||||||
|
|
||||||
|
class wxHtmlWinModule: public wxModule
|
||||||
|
{
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxHtmlWinModule)
|
||||||
|
public:
|
||||||
|
wxHtmlWinModule() : wxModule() {}
|
||||||
|
bool OnInit() { return TRUE; }
|
||||||
|
void OnExit() { wxHtmlWindow::CleanUpStatics(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule, wxModule)
|
||||||
|
|
||||||
|
|
||||||
|
// This hack forces the linker to always link in m_* files
|
||||||
|
// (wxHTML doesn't work without handlers from these files)
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
FORCE_WXHTML_MODULES()
|
||||||
|
|
||||||
|
#endif
|
599
Contrib/NSIS Menu/src/html/htmprint.cpp
Normal file
599
Contrib/NSIS Menu/src/html/htmprint.cpp
Normal file
|
@ -0,0 +1,599 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: htmprint.cpp
|
||||||
|
// Purpose: html printing classes
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// Created: 25/09/99
|
||||||
|
// RCS-ID: $Id: htmprint.cpp,v 1.27.2.2 2002/11/11 00:01:23 VS Exp $
|
||||||
|
// Copyright: (c) Vaclav Slavik, 1999
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "htmprint.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// For compilers that support precompilation, includes "wx/wx.h".
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WX_PRECOMP
|
||||||
|
#include "wx/log.h"
|
||||||
|
#include "wx/intl.h"
|
||||||
|
#include "wx/dc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if wxUSE_HTML && wxUSE_PRINTING_ARCHITECTURE && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#include "wx/dc.h"
|
||||||
|
#include "wx/print.h"
|
||||||
|
#include "wx/printdlg.h"
|
||||||
|
#include "wx/html/htmprint.h"
|
||||||
|
#include "wx/wxhtml.h"
|
||||||
|
#include "wx/wfstream.h"
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlDCRenderer
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlDCRenderer::wxHtmlDCRenderer() : wxObject()
|
||||||
|
{
|
||||||
|
m_DC = NULL;
|
||||||
|
m_Width = m_Height = 0;
|
||||||
|
m_Cells = NULL;
|
||||||
|
m_Parser = new wxHtmlWinParser(NULL);
|
||||||
|
m_FS = new wxFileSystem();
|
||||||
|
m_Parser->SetFS(m_FS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlDCRenderer::~wxHtmlDCRenderer()
|
||||||
|
{
|
||||||
|
if (m_Cells) delete m_Cells;
|
||||||
|
if (m_Parser) delete m_Parser;
|
||||||
|
if (m_FS) delete m_FS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlDCRenderer::SetDC(wxDC *dc, double pixel_scale)
|
||||||
|
{
|
||||||
|
m_DC = dc;
|
||||||
|
m_Parser->SetDC(m_DC, pixel_scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlDCRenderer::SetSize(int width, int height)
|
||||||
|
{
|
||||||
|
m_Width = width;
|
||||||
|
m_Height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlDCRenderer::SetHtmlText(const wxString& html, const wxString& basepath, bool isdir)
|
||||||
|
{
|
||||||
|
if (m_DC == NULL) return;
|
||||||
|
|
||||||
|
if (m_Cells != NULL) delete m_Cells;
|
||||||
|
|
||||||
|
m_FS->ChangePathTo(basepath, isdir);
|
||||||
|
m_Cells = (wxHtmlContainerCell*) m_Parser->Parse(html);
|
||||||
|
m_Cells->SetIndent(0, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS);
|
||||||
|
m_Cells->Layout(m_Width);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int wxHtmlDCRenderer::Render(int x, int y, int from, int dont_render)
|
||||||
|
{
|
||||||
|
int pbreak, hght;
|
||||||
|
|
||||||
|
if (m_Cells == NULL || m_DC == NULL) return 0;
|
||||||
|
|
||||||
|
pbreak = (int)(from + m_Height);
|
||||||
|
while (m_Cells->AdjustPagebreak(&pbreak)) {}
|
||||||
|
hght = pbreak - from;
|
||||||
|
|
||||||
|
if (!dont_render)
|
||||||
|
{
|
||||||
|
m_DC->SetBrush(*wxWHITE_BRUSH);
|
||||||
|
|
||||||
|
m_DC->SetClippingRegion(x, y, m_Width, hght);
|
||||||
|
m_Cells->Draw(*m_DC,
|
||||||
|
x, (y - from),
|
||||||
|
y, pbreak + (y /*- from*/));
|
||||||
|
m_DC->DestroyClippingRegion();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pbreak < m_Cells->GetHeight()) return pbreak;
|
||||||
|
else return GetTotalHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int wxHtmlDCRenderer::GetTotalHeight()
|
||||||
|
{
|
||||||
|
if (m_Cells) return m_Cells->GetHeight();
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlPrintout
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlPrintout::wxHtmlPrintout(const wxString& title) : wxPrintout(title)
|
||||||
|
{
|
||||||
|
m_Renderer = new wxHtmlDCRenderer;
|
||||||
|
m_RendererHdr = new wxHtmlDCRenderer;
|
||||||
|
m_NumPages = wxHTML_PRINT_MAX_PAGES;
|
||||||
|
m_Document = m_BasePath = wxEmptyString; m_BasePathIsDir = TRUE;
|
||||||
|
m_Headers[0] = m_Headers[1] = wxEmptyString;
|
||||||
|
m_Footers[0] = m_Footers[1] = wxEmptyString;
|
||||||
|
m_HeaderHeight = m_FooterHeight = 0;
|
||||||
|
SetMargins(); // to default values
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlPrintout::~wxHtmlPrintout()
|
||||||
|
{
|
||||||
|
delete m_Renderer;
|
||||||
|
delete m_RendererHdr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlPrintout::OnBeginDocument(int startPage, int endPage)
|
||||||
|
{
|
||||||
|
int pageWidth, pageHeight, mm_w, mm_h, scr_w, scr_h, dc_w, dc_h;
|
||||||
|
float ppmm_h, ppmm_v;
|
||||||
|
|
||||||
|
if (!wxPrintout::OnBeginDocument(startPage, endPage)) return FALSE;
|
||||||
|
|
||||||
|
GetPageSizePixels(&pageWidth, &pageHeight);
|
||||||
|
GetPageSizeMM(&mm_w, &mm_h);
|
||||||
|
ppmm_h = (float)pageWidth / mm_w;
|
||||||
|
ppmm_v = (float)pageHeight / mm_h;
|
||||||
|
|
||||||
|
int ppiPrinterX, ppiPrinterY;
|
||||||
|
GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
|
||||||
|
int ppiScreenX, ppiScreenY;
|
||||||
|
GetPPIScreen(&ppiScreenX, &ppiScreenY);
|
||||||
|
|
||||||
|
wxDisplaySize(&scr_w, &scr_h);
|
||||||
|
GetDC()->GetSize(&dc_w, &dc_h);
|
||||||
|
|
||||||
|
GetDC()->SetUserScale((double)dc_w / (double)pageWidth, (double)dc_w / (double)pageWidth);
|
||||||
|
|
||||||
|
/* prepare headers/footers renderer: */
|
||||||
|
|
||||||
|
m_RendererHdr->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY);
|
||||||
|
m_RendererHdr->SetSize((int) (ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)),
|
||||||
|
(int) (ppmm_v * (mm_h - m_MarginTop - m_MarginBottom)));
|
||||||
|
if (m_Headers[0] != wxEmptyString)
|
||||||
|
{
|
||||||
|
m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[0], 1));
|
||||||
|
m_HeaderHeight = m_RendererHdr->GetTotalHeight();
|
||||||
|
}
|
||||||
|
else if (m_Headers[1] != wxEmptyString)
|
||||||
|
{
|
||||||
|
m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[1], 1));
|
||||||
|
m_HeaderHeight = m_RendererHdr->GetTotalHeight();
|
||||||
|
}
|
||||||
|
if (m_Footers[0] != wxEmptyString)
|
||||||
|
{
|
||||||
|
m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[0], 1));
|
||||||
|
m_FooterHeight = m_RendererHdr->GetTotalHeight();
|
||||||
|
}
|
||||||
|
else if (m_Footers[1] != wxEmptyString)
|
||||||
|
{
|
||||||
|
m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[1], 1));
|
||||||
|
m_FooterHeight = m_RendererHdr->GetTotalHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* prepare main renderer: */
|
||||||
|
m_Renderer->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY);
|
||||||
|
m_Renderer->SetSize((int) (ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)),
|
||||||
|
(int) (ppmm_v * (mm_h - m_MarginTop - m_MarginBottom) -
|
||||||
|
m_FooterHeight - m_HeaderHeight -
|
||||||
|
((m_HeaderHeight == 0) ? 0 : m_MarginSpace * ppmm_v) -
|
||||||
|
((m_FooterHeight == 0) ? 0 : m_MarginSpace * ppmm_v)
|
||||||
|
));
|
||||||
|
m_Renderer->SetHtmlText(m_Document, m_BasePath, m_BasePathIsDir);
|
||||||
|
CountPages();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlPrintout::OnPrintPage(int page)
|
||||||
|
{
|
||||||
|
wxDC *dc = GetDC();
|
||||||
|
if (dc)
|
||||||
|
{
|
||||||
|
if (HasPage(page))
|
||||||
|
RenderPage(dc, page);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
|
||||||
|
{
|
||||||
|
*minPage = 1;
|
||||||
|
*maxPage = wxHTML_PRINT_MAX_PAGES;
|
||||||
|
*selPageFrom = 1;
|
||||||
|
*selPageTo = wxHTML_PRINT_MAX_PAGES;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlPrintout::HasPage(int pageNum)
|
||||||
|
{
|
||||||
|
return (pageNum >= 1 && pageNum <= m_NumPages);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlPrintout::SetHtmlText(const wxString& html, const wxString &basepath, bool isdir)
|
||||||
|
{
|
||||||
|
m_Document = html;
|
||||||
|
m_BasePath = basepath;
|
||||||
|
m_BasePathIsDir = isdir;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlPrintout::SetHtmlFile(const wxString& htmlfile)
|
||||||
|
{
|
||||||
|
wxFileSystem fs;
|
||||||
|
wxFSFile *ff = fs.OpenFile(htmlfile);
|
||||||
|
|
||||||
|
if (ff == NULL)
|
||||||
|
{
|
||||||
|
wxLogError(htmlfile + _(": file does not exist!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlFilterHTML filter;
|
||||||
|
wxString doc = filter.ReadFile(*ff);
|
||||||
|
|
||||||
|
SetHtmlText(doc, htmlfile, FALSE);
|
||||||
|
delete ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlPrintout::SetHeader(const wxString& header, int pg)
|
||||||
|
{
|
||||||
|
if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
|
||||||
|
m_Headers[0] = header;
|
||||||
|
if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
|
||||||
|
m_Headers[1] = header;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlPrintout::SetFooter(const wxString& footer, int pg)
|
||||||
|
{
|
||||||
|
if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
|
||||||
|
m_Footers[0] = footer;
|
||||||
|
if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
|
||||||
|
m_Footers[1] = footer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlPrintout::CountPages()
|
||||||
|
{
|
||||||
|
wxBusyCursor wait;
|
||||||
|
int pageWidth, pageHeight, mm_w, mm_h;
|
||||||
|
float ppmm_h, ppmm_v;
|
||||||
|
|
||||||
|
GetPageSizePixels(&pageWidth, &pageHeight);
|
||||||
|
GetPageSizeMM(&mm_w, &mm_h);
|
||||||
|
ppmm_h = (float)pageWidth / mm_w;
|
||||||
|
ppmm_v = (float)pageHeight / mm_h;
|
||||||
|
|
||||||
|
int pos = 0;
|
||||||
|
|
||||||
|
m_NumPages = 0;
|
||||||
|
|
||||||
|
m_PageBreaks[0] = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
pos = m_Renderer->Render((int)( ppmm_h * m_MarginLeft),
|
||||||
|
(int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight),
|
||||||
|
pos, TRUE);
|
||||||
|
m_PageBreaks[++m_NumPages] = pos;
|
||||||
|
} while (pos < m_Renderer->GetTotalHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlPrintout::RenderPage(wxDC *dc, int page)
|
||||||
|
{
|
||||||
|
wxBusyCursor wait;
|
||||||
|
|
||||||
|
int pageWidth, pageHeight, mm_w, mm_h, scr_w, scr_h, dc_w, dc_h;
|
||||||
|
float ppmm_h, ppmm_v;
|
||||||
|
|
||||||
|
GetPageSizePixels(&pageWidth, &pageHeight);
|
||||||
|
GetPageSizeMM(&mm_w, &mm_h);
|
||||||
|
ppmm_h = (float)pageWidth / mm_w;
|
||||||
|
ppmm_v = (float)pageHeight / mm_h;
|
||||||
|
wxDisplaySize(&scr_w, &scr_h);
|
||||||
|
dc->GetSize(&dc_w, &dc_h);
|
||||||
|
|
||||||
|
int ppiPrinterX, ppiPrinterY;
|
||||||
|
GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
|
||||||
|
int ppiScreenX, ppiScreenY;
|
||||||
|
GetPPIScreen(&ppiScreenX, &ppiScreenY);
|
||||||
|
|
||||||
|
dc->SetUserScale((double)dc_w / (double)pageWidth, (double)dc_w / (double)pageWidth);
|
||||||
|
|
||||||
|
m_Renderer->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY);
|
||||||
|
|
||||||
|
dc->SetBackgroundMode(wxTRANSPARENT);
|
||||||
|
|
||||||
|
m_Renderer->Render((int) (ppmm_h * m_MarginLeft),
|
||||||
|
(int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight),
|
||||||
|
m_PageBreaks[page-1]);
|
||||||
|
|
||||||
|
m_RendererHdr->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY);
|
||||||
|
if (m_Headers[page % 2] != wxEmptyString)
|
||||||
|
{
|
||||||
|
m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[page % 2], page));
|
||||||
|
m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (ppmm_v * m_MarginTop));
|
||||||
|
}
|
||||||
|
if (m_Footers[page % 2] != wxEmptyString)
|
||||||
|
{
|
||||||
|
m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[page % 2], page));
|
||||||
|
m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (pageHeight - ppmm_v * m_MarginBottom - m_FooterHeight));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxString wxHtmlPrintout::TranslateHeader(const wxString& instr, int page)
|
||||||
|
{
|
||||||
|
wxString r = instr;
|
||||||
|
wxString num;
|
||||||
|
|
||||||
|
num.Printf(wxT("%i"), page);
|
||||||
|
r.Replace(wxT("@PAGENUM@"), num);
|
||||||
|
|
||||||
|
num.Printf(wxT("%i"), m_NumPages);
|
||||||
|
r.Replace(wxT("@PAGESCNT@"), num);
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlPrintout::SetMargins(float top, float bottom, float left, float right, float spaces)
|
||||||
|
{
|
||||||
|
m_MarginTop = top;
|
||||||
|
m_MarginBottom = bottom;
|
||||||
|
m_MarginLeft = left;
|
||||||
|
m_MarginRight = right;
|
||||||
|
m_MarginSpace = spaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlEasyPrinting
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlEasyPrinting::wxHtmlEasyPrinting(const wxString& name, wxFrame *parent_frame)
|
||||||
|
{
|
||||||
|
m_Frame = parent_frame;
|
||||||
|
m_Name = name;
|
||||||
|
m_PrintData = new wxPrintData;
|
||||||
|
m_PageSetupData = new wxPageSetupDialogData;
|
||||||
|
m_Headers[0] = m_Headers[1] = m_Footers[0] = m_Footers[1] = wxEmptyString;
|
||||||
|
|
||||||
|
m_PageSetupData->EnableMargins(TRUE);
|
||||||
|
m_PageSetupData->SetMarginTopLeft(wxPoint(25, 25));
|
||||||
|
m_PageSetupData->SetMarginBottomRight(wxPoint(25, 25));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlEasyPrinting::~wxHtmlEasyPrinting()
|
||||||
|
{
|
||||||
|
delete m_PrintData;
|
||||||
|
delete m_PageSetupData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlEasyPrinting::PreviewFile(const wxString &htmlfile)
|
||||||
|
{
|
||||||
|
wxHtmlPrintout *p1 = CreatePrintout();
|
||||||
|
p1->SetHtmlFile(htmlfile);
|
||||||
|
wxHtmlPrintout *p2 = CreatePrintout();
|
||||||
|
p2->SetHtmlFile(htmlfile);
|
||||||
|
return DoPreview(p1, p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlEasyPrinting::PreviewText(const wxString &htmltext, const wxString &basepath)
|
||||||
|
{
|
||||||
|
wxHtmlPrintout *p1 = CreatePrintout();
|
||||||
|
p1->SetHtmlText(htmltext, basepath, TRUE);
|
||||||
|
wxHtmlPrintout *p2 = CreatePrintout();
|
||||||
|
p2->SetHtmlText(htmltext, basepath, TRUE);
|
||||||
|
return DoPreview(p1, p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlEasyPrinting::PrintFile(const wxString &htmlfile)
|
||||||
|
{
|
||||||
|
wxHtmlPrintout *p = CreatePrintout();
|
||||||
|
p->SetHtmlFile(htmlfile);
|
||||||
|
bool ret = DoPrint(p);
|
||||||
|
delete p;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlEasyPrinting::PrintText(const wxString &htmltext, const wxString &basepath)
|
||||||
|
{
|
||||||
|
wxHtmlPrintout *p = CreatePrintout();
|
||||||
|
p->SetHtmlText(htmltext, basepath, TRUE);
|
||||||
|
bool ret = DoPrint(p);
|
||||||
|
delete p;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlEasyPrinting::DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2)
|
||||||
|
{
|
||||||
|
// Pass two printout objects: for preview, and possible printing.
|
||||||
|
wxPrintDialogData printDialogData(*m_PrintData);
|
||||||
|
wxPrintPreview *preview = new wxPrintPreview(printout1, printout2, &printDialogData);
|
||||||
|
if (!preview->Ok())
|
||||||
|
{
|
||||||
|
delete preview;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxPreviewFrame *frame = new wxPreviewFrame(preview, m_Frame,
|
||||||
|
m_Name + _(" Preview"),
|
||||||
|
wxPoint(100, 100), wxSize(650, 500));
|
||||||
|
frame->Centre(wxBOTH);
|
||||||
|
frame->Initialize();
|
||||||
|
frame->Show(TRUE);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlEasyPrinting::DoPrint(wxHtmlPrintout *printout)
|
||||||
|
{
|
||||||
|
wxPrintDialogData printDialogData(*m_PrintData);
|
||||||
|
wxPrinter printer(&printDialogData);
|
||||||
|
|
||||||
|
if (!printer.Print(m_Frame, printout, TRUE))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*m_PrintData) = printer.GetPrintDialogData().GetPrintData();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlEasyPrinting::PrinterSetup()
|
||||||
|
{
|
||||||
|
wxPrintDialogData printDialogData(*m_PrintData);
|
||||||
|
wxPrintDialog printerDialog(m_Frame, &printDialogData);
|
||||||
|
|
||||||
|
printerDialog.GetPrintDialogData().SetSetupDialog(TRUE);
|
||||||
|
|
||||||
|
if (printerDialog.ShowModal() == wxID_OK)
|
||||||
|
(*m_PrintData) = printerDialog.GetPrintDialogData().GetPrintData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlEasyPrinting::PageSetup()
|
||||||
|
{
|
||||||
|
if (!m_PrintData->Ok())
|
||||||
|
{
|
||||||
|
wxLogError(_("There was a problem during page setup: you may need to set a default printer."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_PageSetupData->SetPrintData(*m_PrintData);
|
||||||
|
wxPageSetupDialog pageSetupDialog(m_Frame, m_PageSetupData);
|
||||||
|
|
||||||
|
if (pageSetupDialog.ShowModal() == wxID_OK)
|
||||||
|
{
|
||||||
|
(*m_PrintData) = pageSetupDialog.GetPageSetupData().GetPrintData();
|
||||||
|
(*m_PageSetupData) = pageSetupDialog.GetPageSetupData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlEasyPrinting::SetHeader(const wxString& header, int pg)
|
||||||
|
{
|
||||||
|
if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
|
||||||
|
m_Headers[0] = header;
|
||||||
|
if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
|
||||||
|
m_Headers[1] = header;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlEasyPrinting::SetFooter(const wxString& footer, int pg)
|
||||||
|
{
|
||||||
|
if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
|
||||||
|
m_Footers[0] = footer;
|
||||||
|
if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
|
||||||
|
m_Footers[1] = footer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlPrintout *wxHtmlEasyPrinting::CreatePrintout()
|
||||||
|
{
|
||||||
|
wxHtmlPrintout *p = new wxHtmlPrintout(m_Name);
|
||||||
|
|
||||||
|
p->SetHeader(m_Headers[0], wxPAGE_EVEN);
|
||||||
|
p->SetHeader(m_Headers[1], wxPAGE_ODD);
|
||||||
|
p->SetFooter(m_Footers[0], wxPAGE_EVEN);
|
||||||
|
p->SetFooter(m_Footers[1], wxPAGE_ODD);
|
||||||
|
|
||||||
|
p->SetMargins(m_PageSetupData->GetMarginTopLeft().y,
|
||||||
|
m_PageSetupData->GetMarginBottomRight().y,
|
||||||
|
m_PageSetupData->GetMarginTopLeft().x,
|
||||||
|
m_PageSetupData->GetMarginBottomRight().x);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This hack forces the linker to always link in m_* files
|
||||||
|
// (wxHTML doesn't work without handlers from these files)
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
FORCE_WXHTML_MODULES()
|
||||||
|
|
||||||
|
#endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
|
90
Contrib/NSIS Menu/src/html/m_dflist.cpp
Normal file
90
Contrib/NSIS Menu/src/html/m_dflist.cpp
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: m_dflist.cpp
|
||||||
|
// Purpose: wxHtml module for definition lists (DL,DT,DD)
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: m_dflist.cpp,v 1.6.2.3 2002/11/09 00:07:31 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
#include "wx/html/m_templ.h"
|
||||||
|
|
||||||
|
#include "wx/html/htmlcell.h"
|
||||||
|
|
||||||
|
FORCE_LINK_ME(m_dflist)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(DEFLIST, "DL,DT,DD" )
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
wxHtmlContainerCell *c;
|
||||||
|
|
||||||
|
|
||||||
|
if (tag.GetName() == wxT("DL"))
|
||||||
|
{
|
||||||
|
if (m_WParser->GetContainer()->GetFirstCell() != NULL)
|
||||||
|
{
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
}
|
||||||
|
m_WParser->GetContainer()->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
|
||||||
|
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
if (m_WParser->GetContainer()->GetFirstCell() != NULL)
|
||||||
|
{
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
}
|
||||||
|
m_WParser->GetContainer()->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else if (tag.GetName() == wxT("DT"))
|
||||||
|
{
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
c = m_WParser->OpenContainer();
|
||||||
|
c->SetAlignHor(wxHTML_ALIGN_LEFT);
|
||||||
|
c->SetMinHeight(m_WParser->GetCharHeight());
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else // "DD"
|
||||||
|
{
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
c = m_WParser->OpenContainer();
|
||||||
|
c->SetIndent(5 * m_WParser->GetCharWidth(), wxHTML_INDENT_LEFT);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(DEFLIST)
|
||||||
|
|
||||||
|
|
||||||
|
TAGS_MODULE_BEGIN(DefinitionList)
|
||||||
|
|
||||||
|
TAGS_MODULE_ADD(DEFLIST)
|
||||||
|
|
||||||
|
TAGS_MODULE_END(DefinitionList)
|
||||||
|
|
||||||
|
#endif
|
321
Contrib/NSIS Menu/src/html/m_fonts.cpp
Normal file
321
Contrib/NSIS Menu/src/html/m_fonts.cpp
Normal file
|
@ -0,0 +1,321 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: m_fonts.cpp
|
||||||
|
// Purpose: wxHtml module for fonts & colors of fonts
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: m_fonts.cpp,v 1.18.2.3 2002/11/09 00:07:31 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
#include "wx/html/m_templ.h"
|
||||||
|
#include "wx/fontenum.h"
|
||||||
|
#include "wx/tokenzr.h"
|
||||||
|
|
||||||
|
FORCE_LINK_ME(m_fonts)
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(FONT, "FONT" )
|
||||||
|
|
||||||
|
TAG_HANDLER_VARS
|
||||||
|
wxArrayString m_Faces;
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
wxColour oldclr = m_WParser->GetActualColor();
|
||||||
|
int oldsize = m_WParser->GetFontSize();
|
||||||
|
wxString oldface = m_WParser->GetFontFace();
|
||||||
|
|
||||||
|
if (tag.HasParam(wxT("COLOR")))
|
||||||
|
{
|
||||||
|
wxColour clr;
|
||||||
|
if (tag.GetParamAsColour(wxT("COLOR"), &clr))
|
||||||
|
{
|
||||||
|
m_WParser->SetActualColor(clr);
|
||||||
|
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.HasParam(wxT("SIZE")))
|
||||||
|
{
|
||||||
|
int tmp = 0;
|
||||||
|
wxChar c = tag.GetParam(wxT("SIZE")).GetChar(0);
|
||||||
|
if (tag.GetParamAsInt(wxT("SIZE"), &tmp))
|
||||||
|
{
|
||||||
|
if (c == wxT('+') || c == wxT('-'))
|
||||||
|
m_WParser->SetFontSize(oldsize+tmp);
|
||||||
|
else
|
||||||
|
m_WParser->SetFontSize(tmp);
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.HasParam(wxT("FACE")))
|
||||||
|
{
|
||||||
|
if (m_Faces.GetCount() == 0)
|
||||||
|
{
|
||||||
|
wxFontEnumerator enu;
|
||||||
|
enu.EnumerateFacenames();
|
||||||
|
m_Faces = *enu.GetFacenames();
|
||||||
|
}
|
||||||
|
wxStringTokenizer tk(tag.GetParam(wxT("FACE")), wxT(","));
|
||||||
|
int index;
|
||||||
|
|
||||||
|
while (tk.HasMoreTokens())
|
||||||
|
{
|
||||||
|
if ((index = m_Faces.Index(tk.GetNextToken(), FALSE)) != wxNOT_FOUND)
|
||||||
|
{
|
||||||
|
m_WParser->SetFontFace(m_Faces[index]);
|
||||||
|
m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
if (oldface != m_WParser->GetFontFace())
|
||||||
|
{
|
||||||
|
m_WParser->SetFontFace(oldface);
|
||||||
|
m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
}
|
||||||
|
if (oldsize != m_WParser->GetFontSize())
|
||||||
|
{
|
||||||
|
m_WParser->SetFontSize(oldsize);
|
||||||
|
m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
}
|
||||||
|
if (oldclr != m_WParser->GetActualColor())
|
||||||
|
{
|
||||||
|
m_WParser->SetActualColor(oldclr);
|
||||||
|
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr));
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(FONT)
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(FACES_U, "U,STRIKE")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
int underlined = m_WParser->GetFontUnderlined();
|
||||||
|
|
||||||
|
m_WParser->SetFontUnderlined(TRUE);
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
m_WParser->SetFontUnderlined(underlined);
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(FACES_U)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(FACES_B, "B,STRONG")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
int bold = m_WParser->GetFontBold();
|
||||||
|
|
||||||
|
m_WParser->SetFontBold(TRUE);
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
m_WParser->SetFontBold(bold);
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(FACES_B)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE,ADDRESS")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
int italic = m_WParser->GetFontItalic();
|
||||||
|
|
||||||
|
m_WParser->SetFontItalic(TRUE);
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
m_WParser->SetFontItalic(italic);
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(FACES_I)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(FACES_TT, "TT,CODE,KBD,SAMP")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
int fixed = m_WParser->GetFontFixed();
|
||||||
|
|
||||||
|
m_WParser->SetFontFixed(TRUE);
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
m_WParser->SetFontFixed(fixed);
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(FACES_TT)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(Hx, "H1,H2,H3,H4,H5,H6")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
int old_size, old_b, old_i, old_u, old_f, old_al;
|
||||||
|
wxHtmlContainerCell *c;
|
||||||
|
|
||||||
|
old_size = m_WParser->GetFontSize();
|
||||||
|
old_b = m_WParser->GetFontBold();
|
||||||
|
old_i = m_WParser->GetFontItalic();
|
||||||
|
old_u = m_WParser->GetFontUnderlined();
|
||||||
|
old_f = m_WParser->GetFontFixed();
|
||||||
|
old_al = m_WParser->GetAlign();
|
||||||
|
|
||||||
|
m_WParser->SetFontBold(TRUE);
|
||||||
|
m_WParser->SetFontItalic(FALSE);
|
||||||
|
m_WParser->SetFontUnderlined(FALSE);
|
||||||
|
m_WParser->SetFontFixed(FALSE);
|
||||||
|
|
||||||
|
if (tag.GetName() == wxT("H1"))
|
||||||
|
m_WParser->SetFontSize(7);
|
||||||
|
else if (tag.GetName() == wxT("H2"))
|
||||||
|
m_WParser->SetFontSize(6);
|
||||||
|
else if (tag.GetName() == wxT("H3"))
|
||||||
|
m_WParser->SetFontSize(5);
|
||||||
|
else if (tag.GetName() == wxT("H4"))
|
||||||
|
{
|
||||||
|
m_WParser->SetFontSize(5);
|
||||||
|
m_WParser->SetFontItalic(TRUE);
|
||||||
|
m_WParser->SetFontBold(FALSE);
|
||||||
|
}
|
||||||
|
else if (tag.GetName() == wxT("H5"))
|
||||||
|
m_WParser->SetFontSize(4);
|
||||||
|
else if (tag.GetName() == wxT("H6"))
|
||||||
|
{
|
||||||
|
m_WParser->SetFontSize(4);
|
||||||
|
m_WParser->SetFontItalic(TRUE);
|
||||||
|
m_WParser->SetFontBold(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
c = m_WParser->GetContainer();
|
||||||
|
if (c->GetFirstCell())
|
||||||
|
{
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
c = m_WParser->GetContainer();
|
||||||
|
}
|
||||||
|
c = m_WParser->GetContainer();
|
||||||
|
|
||||||
|
c->SetAlign(tag);
|
||||||
|
c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
|
||||||
|
m_WParser->SetAlign(c->GetAlignHor());
|
||||||
|
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
m_WParser->SetFontSize(old_size);
|
||||||
|
m_WParser->SetFontBold(old_b);
|
||||||
|
m_WParser->SetFontItalic(old_i);
|
||||||
|
m_WParser->SetFontUnderlined(old_u);
|
||||||
|
m_WParser->SetFontFixed(old_f);
|
||||||
|
m_WParser->SetAlign(old_al);
|
||||||
|
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
c = m_WParser->GetContainer();
|
||||||
|
c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(Hx)
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(BIGSMALL, "BIG,SMALL")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
int oldsize = m_WParser->GetFontSize();
|
||||||
|
int sz = (tag.GetName() == wxT("BIG")) ? +1 : -1;
|
||||||
|
|
||||||
|
m_WParser->SetFontSize(sz);
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
m_WParser->SetFontSize(oldsize);
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(BIGSMALL)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAGS_MODULE_BEGIN(Fonts)
|
||||||
|
|
||||||
|
TAGS_MODULE_ADD(FONT)
|
||||||
|
TAGS_MODULE_ADD(FACES_U)
|
||||||
|
TAGS_MODULE_ADD(FACES_I)
|
||||||
|
TAGS_MODULE_ADD(FACES_B)
|
||||||
|
TAGS_MODULE_ADD(FACES_TT)
|
||||||
|
TAGS_MODULE_ADD(Hx)
|
||||||
|
TAGS_MODULE_ADD(BIGSMALL)
|
||||||
|
|
||||||
|
TAGS_MODULE_END(Fonts)
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
34
Contrib/NSIS Menu/src/html/m_hline.cpp
Normal file
34
Contrib/NSIS Menu/src/html/m_hline.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: m_hline.cpp
|
||||||
|
// Purpose: wxHtml module for horizontal line (HR tag)
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: m_hline.cpp,v 1.15.2.3 2002/11/09 00:07:32 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#include "wx/brush.h"
|
||||||
|
#include "wx/pen.h"
|
||||||
|
#include "wx/dc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
#include "wx/html/m_templ.h"
|
||||||
|
|
||||||
|
#include "wx/html/htmlcell.h"
|
||||||
|
|
||||||
|
#endif
|
727
Contrib/NSIS Menu/src/html/m_image.cpp
Normal file
727
Contrib/NSIS Menu/src/html/m_image.cpp
Normal file
|
@ -0,0 +1,727 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: m_image.cpp
|
||||||
|
// Purpose: wxHtml module for displaying images
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: m_image.cpp,v 1.37.2.3 2002/11/09 00:07:32 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik, Joel Lucsy
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#include "wx/dc.h"
|
||||||
|
#include "wx/scrolwin.h"
|
||||||
|
#include "wx/timer.h"
|
||||||
|
#include "wx/dcmemory.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
#include "wx/html/m_templ.h"
|
||||||
|
#include "wx/html/htmlwin.h"
|
||||||
|
|
||||||
|
#include "wx/image.h"
|
||||||
|
#include "wx/gifdecod.h"
|
||||||
|
#include "wx/dynarray.h"
|
||||||
|
#include "wx/log.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
FORCE_LINK_ME(m_image)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
WX_DECLARE_OBJARRAY(int, CoordArray);
|
||||||
|
#include "wx/arrimpl.cpp" // this is a magic incantation which must be done!
|
||||||
|
WX_DEFINE_OBJARRAY(CoordArray);
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlImageMapAreaCell
|
||||||
|
// 0-width, 0-height cell that represents single area in imagemap
|
||||||
|
// (it's GetLink is called from wxHtmlImageCell's)
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxHtmlImageMapAreaCell : public wxHtmlCell
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum celltype { CIRCLE, RECT, POLY };
|
||||||
|
protected:
|
||||||
|
CoordArray coords;
|
||||||
|
celltype type;
|
||||||
|
int radius;
|
||||||
|
public:
|
||||||
|
wxHtmlImageMapAreaCell( celltype t, wxString &coords, double pixel_scale = 1.0);
|
||||||
|
virtual wxHtmlLinkInfo *GetLink( int x = 0, int y = 0 ) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlImageMapAreaCell::wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::celltype t, wxString &incoords, double pixel_scale )
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
wxString x = incoords, y;
|
||||||
|
|
||||||
|
type = t;
|
||||||
|
while ((i = x.Find( ',' )) != -1)
|
||||||
|
{
|
||||||
|
coords.Add( (int)(pixel_scale * (double)wxAtoi( x.Left( i ).c_str())) );
|
||||||
|
x = x.Mid( i + 1 );
|
||||||
|
}
|
||||||
|
coords.Add( (int)(pixel_scale * (double)wxAtoi( x.c_str())) );
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlLinkInfo *wxHtmlImageMapAreaCell::GetLink( int x, int y ) const
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case RECT:
|
||||||
|
{
|
||||||
|
int l, t, r, b;
|
||||||
|
|
||||||
|
l = coords[ 0 ];
|
||||||
|
t = coords[ 1 ];
|
||||||
|
r = coords[ 2 ];
|
||||||
|
b = coords[ 3 ];
|
||||||
|
if (x >= l && x <= r && y >= t && y <= b)
|
||||||
|
{
|
||||||
|
return m_Link;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CIRCLE:
|
||||||
|
{
|
||||||
|
int l, t, r;
|
||||||
|
double d;
|
||||||
|
|
||||||
|
l = coords[ 0 ];
|
||||||
|
t = coords[ 1 ];
|
||||||
|
r = coords[ 2 ];
|
||||||
|
d = sqrt( (double) (((x - l) * (x - l)) + ((y - t) * (y - t))) );
|
||||||
|
if (d < (double)r)
|
||||||
|
{
|
||||||
|
return m_Link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case POLY:
|
||||||
|
{
|
||||||
|
if (coords.GetCount() >= 6)
|
||||||
|
{
|
||||||
|
int intersects = 0;
|
||||||
|
int wherex = x;
|
||||||
|
int wherey = y;
|
||||||
|
int totalv = coords.GetCount() / 2;
|
||||||
|
int totalc = totalv * 2;
|
||||||
|
int xval = coords[totalc - 2];
|
||||||
|
int yval = coords[totalc - 1];
|
||||||
|
int end = totalc;
|
||||||
|
int pointer = 1;
|
||||||
|
|
||||||
|
if ((yval >= wherey) != (coords[pointer] >= wherey))
|
||||||
|
{
|
||||||
|
if ((xval >= wherex) == (coords[0] >= wherex))
|
||||||
|
{
|
||||||
|
intersects += (xval >= wherex) ? 1 : 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
intersects += ((xval - (yval - wherey) *
|
||||||
|
(coords[0] - xval) /
|
||||||
|
(coords[pointer] - yval)) >= wherex) ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (pointer < end)
|
||||||
|
{
|
||||||
|
yval = coords[pointer];
|
||||||
|
pointer += 2;
|
||||||
|
if (yval >= wherey)
|
||||||
|
{
|
||||||
|
while ((pointer < end) && (coords[pointer] >= wherey))
|
||||||
|
{
|
||||||
|
pointer += 2;
|
||||||
|
}
|
||||||
|
if (pointer >= end)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((coords[pointer - 3] >= wherex) ==
|
||||||
|
(coords[pointer - 1] >= wherex)) {
|
||||||
|
intersects += (coords[pointer - 3] >= wherex) ? 1 : 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
intersects +=
|
||||||
|
((coords[pointer - 3] - (coords[pointer - 2] - wherey) *
|
||||||
|
(coords[pointer - 1] - coords[pointer - 3]) /
|
||||||
|
(coords[pointer] - coords[pointer - 2])) >= wherex) ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while ((pointer < end) && (coords[pointer] < wherey))
|
||||||
|
{
|
||||||
|
pointer += 2;
|
||||||
|
}
|
||||||
|
if (pointer >= end)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((coords[pointer - 3] >= wherex) ==
|
||||||
|
(coords[pointer - 1] >= wherex))
|
||||||
|
{
|
||||||
|
intersects += (coords[pointer - 3] >= wherex) ? 1 : 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
intersects +=
|
||||||
|
((coords[pointer - 3] - (coords[pointer - 2] - wherey) *
|
||||||
|
(coords[pointer - 1] - coords[pointer - 3]) /
|
||||||
|
(coords[pointer] - coords[pointer - 2])) >= wherex) ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((intersects & 1) != 0)
|
||||||
|
{
|
||||||
|
return m_Link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_Next)
|
||||||
|
{
|
||||||
|
wxHtmlImageMapAreaCell *a = (wxHtmlImageMapAreaCell*)m_Next;
|
||||||
|
return a->GetLink( x, y );
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlImageMapCell
|
||||||
|
// 0-width, 0-height cell that represents map from imagemaps
|
||||||
|
// it is always placed before wxHtmlImageMapAreaCells
|
||||||
|
// It responds to Find(wxHTML_COND_ISIMAGEMAP)
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class wxHtmlImageMapCell : public wxHtmlCell
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxHtmlImageMapCell( wxString &name );
|
||||||
|
protected:
|
||||||
|
wxString m_Name;
|
||||||
|
public:
|
||||||
|
virtual wxHtmlLinkInfo *GetLink( int x = 0, int y = 0 ) const;
|
||||||
|
virtual const wxHtmlCell *Find( int cond, const void *param ) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlImageMapCell::wxHtmlImageMapCell( wxString &name )
|
||||||
|
{
|
||||||
|
m_Name = name ;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlLinkInfo *wxHtmlImageMapCell::GetLink( int x, int y ) const
|
||||||
|
{
|
||||||
|
wxHtmlImageMapAreaCell *a = (wxHtmlImageMapAreaCell*)m_Next;
|
||||||
|
if (a)
|
||||||
|
return a->GetLink( x, y );
|
||||||
|
return wxHtmlCell::GetLink( x, y );
|
||||||
|
}
|
||||||
|
|
||||||
|
const wxHtmlCell *wxHtmlImageMapCell::Find( int cond, const void *param ) const
|
||||||
|
{
|
||||||
|
if (cond == wxHTML_COND_ISIMAGEMAP)
|
||||||
|
{
|
||||||
|
if (m_Name == *((wxString*)(param)))
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return wxHtmlCell::Find(cond, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlImageCell
|
||||||
|
// Image/bitmap
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxHtmlImageCell : public wxHtmlCell
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxHtmlImageCell(wxWindow *window,
|
||||||
|
wxFSFile *input, int w = -1, int h = -1,
|
||||||
|
double scale = 1.0, int align = wxHTML_ALIGN_BOTTOM,
|
||||||
|
const wxString& mapname = wxEmptyString);
|
||||||
|
~wxHtmlImageCell();
|
||||||
|
void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
|
||||||
|
virtual wxHtmlLinkInfo *GetLink(int x = 0, int y = 0) const;
|
||||||
|
|
||||||
|
void SetImage(const wxImage& img);
|
||||||
|
#if wxUSE_GIF && wxUSE_TIMER
|
||||||
|
void AdvanceAnimation(wxTimer *timer);
|
||||||
|
virtual void Layout(int w);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxBitmap *m_bitmap;
|
||||||
|
int m_bmpW, m_bmpH;
|
||||||
|
bool m_showFrame:1;
|
||||||
|
wxScrolledWindow *m_window;
|
||||||
|
#if wxUSE_GIF && wxUSE_TIMER
|
||||||
|
wxGIFDecoder *m_gifDecoder;
|
||||||
|
wxTimer *m_gifTimer;
|
||||||
|
int m_physX, m_physY;
|
||||||
|
#endif
|
||||||
|
double m_scale;
|
||||||
|
wxHtmlImageMapCell *m_imageMap;
|
||||||
|
wxString m_mapName;
|
||||||
|
};
|
||||||
|
|
||||||
|
#if wxUSE_GIF && wxUSE_TIMER
|
||||||
|
class wxGIFTimer : public wxTimer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxGIFTimer(wxHtmlImageCell *cell) : m_cell(cell) {}
|
||||||
|
virtual void Notify()
|
||||||
|
{
|
||||||
|
m_cell->AdvanceAnimation(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxHtmlImageCell *m_cell;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// wxHtmlImageCell
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/* XPM */
|
||||||
|
static const char * broken_image_xpm[] = {
|
||||||
|
"29 31 7 1",
|
||||||
|
" c None",
|
||||||
|
". c #808080",
|
||||||
|
"+ c #FFFFFF",
|
||||||
|
"@ c #C0C0C0",
|
||||||
|
"# c #000000",
|
||||||
|
"$ c #333366",
|
||||||
|
"% c #B2B2B2",
|
||||||
|
"..................... ",
|
||||||
|
".+++++++++++++++++++.. ",
|
||||||
|
".+++++++++++++++++++.@. ",
|
||||||
|
".++@@@@@@@@@@@@@@@@@.+@. ",
|
||||||
|
".++@@@@@@@@@@@@@@@@@.++@. ",
|
||||||
|
".++@@@@@.@@@@.@@@@@@.+++@. ",
|
||||||
|
".++@@@@@@@@@@@@@@@@@.++++@. ",
|
||||||
|
".++@@@@@@@@@@@@@@@@@.+++++@. ",
|
||||||
|
".++@@.@@@@@@@@@@.@@@######## ",
|
||||||
|
".++@@@@@@@@@@@@@@@@@@$$$$$$#.",
|
||||||
|
".######@@@@@@@@@@@@@@@.....#.",
|
||||||
|
" ###@@@@@@@@@@@@@@@++#.",
|
||||||
|
" #####@@@@@@@@@@++#.",
|
||||||
|
" #@.@@@@@@@@++#.",
|
||||||
|
".. ###@@@@@@@++#.",
|
||||||
|
".+.... #@@@@@@++#.",
|
||||||
|
".++@@@... ####@@++#.",
|
||||||
|
".++@@@@@@.. #####.",
|
||||||
|
".++@@@@@@@@... ",
|
||||||
|
".++@@@@@@%%%%@. ",
|
||||||
|
".++@@@@@@%%%%@@.... ",
|
||||||
|
".++@@@@@@%%%%@@@@@@.... ",
|
||||||
|
".++@@@@@@%%%%@@@@@@@@@@.... ",
|
||||||
|
".++@@@@@@@@@@@@@@@@@@@@@@++#.",
|
||||||
|
".++@@@@@@@@@@@@@@@@@@@@@@++#.",
|
||||||
|
".++@@@@@@@@@@@@@@@@@@@@@@++#.",
|
||||||
|
".++@@@@@@@@@@@@@@@@@@@@@@++#.",
|
||||||
|
".++@@@@@@@@@@@@@@@@@@@@@@++#.",
|
||||||
|
".++++++++++++++++++++++++++#.",
|
||||||
|
".++++++++++++++++++++++++++#.",
|
||||||
|
"############################."};
|
||||||
|
|
||||||
|
wxHtmlImageCell::wxHtmlImageCell(wxWindow *window, wxFSFile *input,
|
||||||
|
int w, int h, double scale, int align,
|
||||||
|
const wxString& mapname) : wxHtmlCell()
|
||||||
|
{
|
||||||
|
m_window = window ? wxStaticCast(window, wxScrolledWindow) : NULL;
|
||||||
|
m_scale = scale;
|
||||||
|
m_showFrame = FALSE;
|
||||||
|
m_bitmap = NULL;
|
||||||
|
m_bmpW = w;
|
||||||
|
m_bmpH = h;
|
||||||
|
m_imageMap = NULL;
|
||||||
|
m_mapName = mapname;
|
||||||
|
SetCanLiveOnPagebreak(FALSE);
|
||||||
|
#if wxUSE_GIF && wxUSE_TIMER
|
||||||
|
m_gifDecoder = NULL;
|
||||||
|
m_gifTimer = NULL;
|
||||||
|
m_physX = m_physY = -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ( m_bmpW && m_bmpH )
|
||||||
|
{
|
||||||
|
if ( input )
|
||||||
|
{
|
||||||
|
wxInputStream *s = input->GetStream();
|
||||||
|
|
||||||
|
if ( s )
|
||||||
|
{
|
||||||
|
bool readImg = TRUE;
|
||||||
|
|
||||||
|
#if wxUSE_GIF && wxUSE_TIMER
|
||||||
|
if ( (input->GetLocation().Matches(wxT("*.gif")) ||
|
||||||
|
input->GetLocation().Matches(wxT("*.GIF"))) && m_window )
|
||||||
|
{
|
||||||
|
m_gifDecoder = new wxGIFDecoder(s, TRUE);
|
||||||
|
if ( m_gifDecoder->ReadGIF() == wxGIF_OK )
|
||||||
|
{
|
||||||
|
wxImage img;
|
||||||
|
if ( m_gifDecoder->ConvertToImage(&img) )
|
||||||
|
SetImage(img);
|
||||||
|
|
||||||
|
readImg = FALSE;
|
||||||
|
|
||||||
|
if ( m_gifDecoder->IsAnimation() )
|
||||||
|
{
|
||||||
|
m_gifTimer = new wxGIFTimer(this);
|
||||||
|
m_gifTimer->Start(m_gifDecoder->GetDelay(), TRUE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxDELETE(m_gifDecoder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxDELETE(m_gifDecoder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( readImg )
|
||||||
|
#endif // wxUSE_GIF && wxUSE_TIMER
|
||||||
|
{
|
||||||
|
wxImage image(*s, wxBITMAP_TYPE_ANY);
|
||||||
|
if ( image.Ok() )
|
||||||
|
SetImage(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // input==NULL, use "broken image" bitmap
|
||||||
|
{
|
||||||
|
if ( m_bmpW == -1 && m_bmpH == -1 )
|
||||||
|
{
|
||||||
|
m_bmpW = 29;
|
||||||
|
m_bmpH = 31;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_showFrame = TRUE;
|
||||||
|
if ( m_bmpW == -1 ) m_bmpW = 31;
|
||||||
|
if ( m_bmpH == -1 ) m_bmpH = 33;
|
||||||
|
}
|
||||||
|
m_bitmap = new wxBitmap(broken_image_xpm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//else: ignore the 0-sized images used sometimes on the Web pages
|
||||||
|
|
||||||
|
m_Width = (int)(scale * (double)m_bmpW);
|
||||||
|
m_Height = (int)(scale * (double)m_bmpH);
|
||||||
|
|
||||||
|
switch (align)
|
||||||
|
{
|
||||||
|
case wxHTML_ALIGN_TOP :
|
||||||
|
m_Descent = m_Height;
|
||||||
|
break;
|
||||||
|
case wxHTML_ALIGN_CENTER :
|
||||||
|
m_Descent = m_Height / 2;
|
||||||
|
break;
|
||||||
|
case wxHTML_ALIGN_BOTTOM :
|
||||||
|
default :
|
||||||
|
m_Descent = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlImageCell::SetImage(const wxImage& img)
|
||||||
|
{
|
||||||
|
if ( img.Ok() )
|
||||||
|
{
|
||||||
|
delete m_bitmap;
|
||||||
|
|
||||||
|
int ww, hh;
|
||||||
|
ww = img.GetWidth();
|
||||||
|
hh = img.GetHeight();
|
||||||
|
|
||||||
|
if ( m_bmpW == -1 )
|
||||||
|
m_bmpW = ww;
|
||||||
|
if ( m_bmpH == -1 )
|
||||||
|
m_bmpH = hh;
|
||||||
|
|
||||||
|
if ((m_bmpW != ww) || (m_bmpH != hh))
|
||||||
|
{
|
||||||
|
wxImage img2 = img.Scale(m_bmpW, m_bmpH);
|
||||||
|
m_bitmap = new wxBitmap(img2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_bitmap = new wxBitmap(img);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if wxUSE_GIF && wxUSE_TIMER
|
||||||
|
void wxHtmlImageCell::AdvanceAnimation(wxTimer *timer)
|
||||||
|
{
|
||||||
|
wxImage img;
|
||||||
|
|
||||||
|
m_gifDecoder->GoNextFrame(TRUE);
|
||||||
|
|
||||||
|
if ( m_physX == -1 )
|
||||||
|
{
|
||||||
|
m_physX = m_physY = 0;
|
||||||
|
for (wxHtmlCell *cell = this; cell; cell = cell->GetParent())
|
||||||
|
{
|
||||||
|
m_physX += cell->GetPosX();
|
||||||
|
m_physY += cell->GetPosY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
m_window->CalcScrolledPosition(m_physX, m_physY, &x, &y);
|
||||||
|
wxRect rect(x, y, m_Width, m_Height);
|
||||||
|
|
||||||
|
if ( m_window->GetClientRect().Intersects(rect) &&
|
||||||
|
m_gifDecoder->ConvertToImage(&img) )
|
||||||
|
{
|
||||||
|
if ( (int)m_gifDecoder->GetWidth() != m_Width ||
|
||||||
|
(int)m_gifDecoder->GetHeight() != m_Height ||
|
||||||
|
m_gifDecoder->GetLeft() != 0 || m_gifDecoder->GetTop() != 0 )
|
||||||
|
{
|
||||||
|
wxBitmap bmp(img);
|
||||||
|
wxMemoryDC dc;
|
||||||
|
dc.SelectObject(*m_bitmap);
|
||||||
|
dc.DrawBitmap(bmp, m_gifDecoder->GetLeft(), m_gifDecoder->GetTop());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SetImage(img);
|
||||||
|
m_window->Refresh(img.HasMask(), &rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
timer->Start(m_gifDecoder->GetDelay(), TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlImageCell::Layout(int w)
|
||||||
|
{
|
||||||
|
wxHtmlCell::Layout(w);
|
||||||
|
m_physX = m_physY = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
wxHtmlImageCell::~wxHtmlImageCell()
|
||||||
|
{
|
||||||
|
delete m_bitmap;
|
||||||
|
#if wxUSE_GIF && wxUSE_TIMER
|
||||||
|
delete m_gifTimer;
|
||||||
|
delete m_gifDecoder;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlImageCell::Draw(wxDC& dc, int x, int y, int WXUNUSED(view_y1), int WXUNUSED(view_y2))
|
||||||
|
{
|
||||||
|
if ( m_showFrame )
|
||||||
|
{
|
||||||
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||||
|
dc.SetPen(*wxBLACK_PEN);
|
||||||
|
dc.DrawRectangle(x + m_PosX, y + m_PosY, m_Width, m_Height);
|
||||||
|
x++, y++;
|
||||||
|
}
|
||||||
|
if ( m_bitmap )
|
||||||
|
{
|
||||||
|
double us_x, us_y;
|
||||||
|
dc.GetUserScale(&us_x, &us_y);
|
||||||
|
dc.SetUserScale(us_x * m_scale, us_y * m_scale);
|
||||||
|
|
||||||
|
dc.DrawBitmap(*m_bitmap, (int) ((x + m_PosX) / m_scale),
|
||||||
|
(int) ((y + m_PosY) / m_scale), TRUE);
|
||||||
|
dc.SetUserScale(us_x, us_y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlLinkInfo *wxHtmlImageCell::GetLink( int x, int y ) const
|
||||||
|
{
|
||||||
|
if (m_mapName.IsEmpty())
|
||||||
|
return wxHtmlCell::GetLink( x, y );
|
||||||
|
if (!m_imageMap)
|
||||||
|
{
|
||||||
|
wxHtmlContainerCell *p, *op;
|
||||||
|
op = p = GetParent();
|
||||||
|
while (p)
|
||||||
|
{
|
||||||
|
op = p;
|
||||||
|
p = p->GetParent();
|
||||||
|
}
|
||||||
|
p = op;
|
||||||
|
wxHtmlCell *cell = (wxHtmlCell*)p->Find(wxHTML_COND_ISIMAGEMAP,
|
||||||
|
(const void*)(&m_mapName));
|
||||||
|
if (!cell)
|
||||||
|
{
|
||||||
|
((wxString&)m_mapName).Clear();
|
||||||
|
return wxHtmlCell::GetLink( x, y );
|
||||||
|
}
|
||||||
|
{ // dirty hack, ask Joel why he fills m_ImageMap in this place
|
||||||
|
// THE problem is that we're in const method and we can't modify m_ImageMap
|
||||||
|
wxHtmlImageMapCell **cx = (wxHtmlImageMapCell**)(&m_imageMap);
|
||||||
|
*cx = (wxHtmlImageMapCell*)cell;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_imageMap->GetLink(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// tag handler
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
if (tag.GetName() == wxT("IMG"))
|
||||||
|
{
|
||||||
|
if (tag.HasParam(wxT("SRC")))
|
||||||
|
{
|
||||||
|
int w = -1, h = -1;
|
||||||
|
int al;
|
||||||
|
wxFSFile *str;
|
||||||
|
wxString tmp = tag.GetParam(wxT("SRC"));
|
||||||
|
wxString mn = wxEmptyString;
|
||||||
|
|
||||||
|
str = m_WParser->OpenURL(wxHTML_URL_IMAGE, tmp);
|
||||||
|
|
||||||
|
if (tag.HasParam(wxT("WIDTH")))
|
||||||
|
tag.GetParamAsInt(wxT("WIDTH"), &w);
|
||||||
|
if (tag.HasParam(wxT("HEIGHT")))
|
||||||
|
tag.GetParamAsInt(wxT("HEIGHT"), &h);
|
||||||
|
al = wxHTML_ALIGN_BOTTOM;
|
||||||
|
if (tag.HasParam(wxT("ALIGN")))
|
||||||
|
{
|
||||||
|
wxString alstr = tag.GetParam(wxT("ALIGN"));
|
||||||
|
alstr.MakeUpper(); // for the case alignment was in ".."
|
||||||
|
if (alstr == wxT("TEXTTOP"))
|
||||||
|
al = wxHTML_ALIGN_TOP;
|
||||||
|
else if ((alstr == wxT("CENTER")) || (alstr == wxT("ABSCENTER")))
|
||||||
|
al = wxHTML_ALIGN_CENTER;
|
||||||
|
}
|
||||||
|
if (tag.HasParam(wxT("USEMAP")))
|
||||||
|
{
|
||||||
|
mn = tag.GetParam( wxT("USEMAP") );
|
||||||
|
if (mn.GetChar(0) == wxT('#'))
|
||||||
|
{
|
||||||
|
mn = mn.Mid( 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wxHtmlImageCell *cel = new wxHtmlImageCell(
|
||||||
|
m_WParser->GetWindow(),
|
||||||
|
str, w, h,
|
||||||
|
m_WParser->GetPixelScale(),
|
||||||
|
al, mn);
|
||||||
|
cel->SetLink(m_WParser->GetLink());
|
||||||
|
cel->SetId(tag.GetParam(wxT("id"))); // may be empty
|
||||||
|
m_WParser->GetContainer()->InsertCell(cel);
|
||||||
|
if (str)
|
||||||
|
delete str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tag.GetName() == wxT("MAP"))
|
||||||
|
{
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
if (tag.HasParam(wxT("NAME")))
|
||||||
|
{
|
||||||
|
wxString tmp = tag.GetParam(wxT("NAME"));
|
||||||
|
wxHtmlImageMapCell *cel = new wxHtmlImageMapCell( tmp );
|
||||||
|
m_WParser->GetContainer()->InsertCell( cel );
|
||||||
|
}
|
||||||
|
ParseInner( tag );
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
}
|
||||||
|
if (tag.GetName() == wxT("AREA"))
|
||||||
|
{
|
||||||
|
if (tag.HasParam(wxT("SHAPE")))
|
||||||
|
{
|
||||||
|
wxString tmp = tag.GetParam(wxT("SHAPE"));
|
||||||
|
wxString coords = wxEmptyString;
|
||||||
|
tmp.MakeUpper();
|
||||||
|
wxHtmlImageMapAreaCell *cel = NULL;
|
||||||
|
if (tag.HasParam(wxT("COORDS")))
|
||||||
|
{
|
||||||
|
coords = tag.GetParam(wxT("COORDS"));
|
||||||
|
}
|
||||||
|
if (tmp == wxT("POLY"))
|
||||||
|
{
|
||||||
|
cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::POLY, coords, m_WParser->GetPixelScale() );
|
||||||
|
}
|
||||||
|
else if (tmp == wxT("CIRCLE"))
|
||||||
|
{
|
||||||
|
cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::CIRCLE, coords, m_WParser->GetPixelScale() );
|
||||||
|
}
|
||||||
|
else if (tmp == wxT("RECT"))
|
||||||
|
{
|
||||||
|
cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::RECT, coords, m_WParser->GetPixelScale() );
|
||||||
|
}
|
||||||
|
if (cel != NULL && tag.HasParam(wxT("HREF")))
|
||||||
|
{
|
||||||
|
wxString tmp = tag.GetParam(wxT("HREF"));
|
||||||
|
wxString target = wxEmptyString;
|
||||||
|
if (tag.HasParam(wxT("TARGET"))) target = tag.GetParam(wxT("TARGET"));
|
||||||
|
cel->SetLink( wxHtmlLinkInfo(tmp, target));
|
||||||
|
}
|
||||||
|
if (cel != NULL) m_WParser->GetContainer()->InsertCell( cel );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(IMG)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAGS_MODULE_BEGIN(Image)
|
||||||
|
|
||||||
|
TAGS_MODULE_ADD(IMG)
|
||||||
|
|
||||||
|
TAGS_MODULE_END(Image)
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
242
Contrib/NSIS Menu/src/html/m_layout.cpp
Normal file
242
Contrib/NSIS Menu/src/html/m_layout.cpp
Normal file
|
@ -0,0 +1,242 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: m_layout.cpp
|
||||||
|
// Purpose: wxHtml module for basic paragraphs/layout handling
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: m_layout.cpp,v 1.16.2.3 2002/11/09 00:07:33 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
#include "wx/html/m_templ.h"
|
||||||
|
|
||||||
|
#include "wx/html/htmlwin.h"
|
||||||
|
|
||||||
|
FORCE_LINK_ME(m_layout)
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(P, "P")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
if (m_WParser->GetContainer()->GetFirstCell() != NULL)
|
||||||
|
{
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
}
|
||||||
|
m_WParser->GetContainer()->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
|
||||||
|
m_WParser->GetContainer()->SetAlign(tag);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(P)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(BR, "BR")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
int al = m_WParser->GetContainer()->GetAlignHor();
|
||||||
|
wxHtmlContainerCell *c;
|
||||||
|
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
c = m_WParser->OpenContainer();
|
||||||
|
c->SetAlignHor(al);
|
||||||
|
c->SetAlign(tag);
|
||||||
|
c->SetMinHeight(m_WParser->GetCharHeight());
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(BR)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(CENTER, "CENTER")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
int old = m_WParser->GetAlign();
|
||||||
|
wxHtmlContainerCell *c = m_WParser->GetContainer();
|
||||||
|
|
||||||
|
m_WParser->SetAlign(wxHTML_ALIGN_CENTER);
|
||||||
|
if (c->GetFirstCell() != NULL)
|
||||||
|
{
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
c->SetAlignHor(wxHTML_ALIGN_CENTER);
|
||||||
|
|
||||||
|
if (tag.HasEnding())
|
||||||
|
{
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
m_WParser->SetAlign(old);
|
||||||
|
if (c->GetFirstCell() != NULL)
|
||||||
|
{
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
c->SetAlignHor(old);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(CENTER)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(DIV, "DIV")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
int old = m_WParser->GetAlign();
|
||||||
|
wxHtmlContainerCell *c = m_WParser->GetContainer();
|
||||||
|
if (c->GetFirstCell() != NULL)
|
||||||
|
{
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
c = m_WParser->GetContainer();
|
||||||
|
c->SetAlign(tag);
|
||||||
|
m_WParser->SetAlign(c->GetAlignHor());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c->SetAlign(tag);
|
||||||
|
m_WParser->SetAlign(c->GetAlignHor());
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
m_WParser->SetAlign(old);
|
||||||
|
if (c->GetFirstCell() != NULL)
|
||||||
|
{
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
c->SetAlignHor(old);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(DIV)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(TITLE, "TITLE")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
if (m_WParser->GetWindow())
|
||||||
|
{
|
||||||
|
wxHtmlWindow *wfr = (wxHtmlWindow*)(m_WParser->GetWindow());
|
||||||
|
if (wfr)
|
||||||
|
{
|
||||||
|
const wxString& src = *m_WParser->GetSource();
|
||||||
|
wfr->OnSetTitle(src.Mid(tag.GetBeginPos(),
|
||||||
|
tag.GetEndPos1()-tag.GetBeginPos()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(TITLE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(BODY, "BODY")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
wxColour clr;
|
||||||
|
|
||||||
|
if (tag.GetParamAsColour(wxT("TEXT"), &clr))
|
||||||
|
{
|
||||||
|
m_WParser->SetActualColor(clr);
|
||||||
|
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.GetParamAsColour(wxT("LINK"), &clr))
|
||||||
|
m_WParser->SetLinkColor(clr);
|
||||||
|
|
||||||
|
if (tag.GetParamAsColour(wxT("BGCOLOR"), &clr))
|
||||||
|
{
|
||||||
|
m_WParser->GetContainer()->InsertCell(
|
||||||
|
new wxHtmlColourCell(clr, wxHTML_CLR_BACKGROUND));
|
||||||
|
if (m_WParser->GetWindow() != NULL)
|
||||||
|
m_WParser->GetWindow()->SetBackgroundColour(clr);
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(BODY)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(BLOCKQUOTE, "BLOCKQUOTE")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
wxHtmlContainerCell *c;
|
||||||
|
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
c = m_WParser->OpenContainer();
|
||||||
|
|
||||||
|
if (c->GetAlignHor() == wxHTML_ALIGN_RIGHT)
|
||||||
|
c->SetIndent(5 * m_WParser->GetCharWidth(), wxHTML_INDENT_RIGHT);
|
||||||
|
else
|
||||||
|
c->SetIndent(5 * m_WParser->GetCharWidth(), wxHTML_INDENT_LEFT);
|
||||||
|
|
||||||
|
c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
ParseInner(tag);
|
||||||
|
c = m_WParser->CloseContainer();
|
||||||
|
c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_BOTTOM);
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(BLOCKQUOTE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAGS_MODULE_BEGIN(Layout)
|
||||||
|
|
||||||
|
TAGS_MODULE_ADD(P)
|
||||||
|
TAGS_MODULE_ADD(BR)
|
||||||
|
TAGS_MODULE_ADD(CENTER)
|
||||||
|
TAGS_MODULE_ADD(DIV)
|
||||||
|
TAGS_MODULE_ADD(TITLE)
|
||||||
|
TAGS_MODULE_ADD(BODY)
|
||||||
|
TAGS_MODULE_ADD(BLOCKQUOTE)
|
||||||
|
|
||||||
|
TAGS_MODULE_END(Layout)
|
||||||
|
|
||||||
|
#endif
|
138
Contrib/NSIS Menu/src/html/m_links.cpp
Normal file
138
Contrib/NSIS Menu/src/html/m_links.cpp
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: m_links.cpp
|
||||||
|
// Purpose: wxHtml module for links & anchors
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: m_links.cpp,v 1.8.2.3 2002/11/09 00:07:34 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
#include "wx/html/m_templ.h"
|
||||||
|
|
||||||
|
|
||||||
|
FORCE_LINK_ME(m_links)
|
||||||
|
|
||||||
|
|
||||||
|
class wxHtmlAnchorCell : public wxHtmlCell
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
wxString m_AnchorName;
|
||||||
|
|
||||||
|
public:
|
||||||
|
wxHtmlAnchorCell(const wxString& name) : wxHtmlCell() {m_AnchorName = name;}
|
||||||
|
virtual const wxHtmlCell* Find(int condition, const void* param) const
|
||||||
|
{
|
||||||
|
if ((condition == wxHTML_COND_ISANCHOR) && (m_AnchorName == (*((const wxString*)param))))
|
||||||
|
return this;
|
||||||
|
else
|
||||||
|
return wxHtmlCell::Find(condition, param);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(A, "A")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
if (tag.HasParam( wxT("NAME") ))
|
||||||
|
{
|
||||||
|
m_WParser->GetContainer()->InsertCell(new wxHtmlAnchorCell(tag.GetParam( wxT("NAME") )));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.HasParam( wxT("HREF") ))
|
||||||
|
{
|
||||||
|
wxHtmlLinkInfo oldlnk = m_WParser->GetLink();
|
||||||
|
wxColour oldclr = m_WParser->GetActualColor();
|
||||||
|
int oldund = m_WParser->GetFontUnderlined();
|
||||||
|
wxString name(tag.GetParam( wxT("HREF") )), target;
|
||||||
|
|
||||||
|
wxColor LinkColor;
|
||||||
|
LinkColor.Set(0x19, 0x56, 0xB1);
|
||||||
|
|
||||||
|
char apppath[MAX_PATH],*temp;
|
||||||
|
GetModuleFileName(NULL,apppath,sizeof(apppath));
|
||||||
|
temp=strrchr(apppath,'\\');
|
||||||
|
if(temp!=NULL) *temp=0;
|
||||||
|
|
||||||
|
char fullpath[MAX_PATH];
|
||||||
|
|
||||||
|
if (name.Left(3).Cmp("EX:") == 0)
|
||||||
|
{
|
||||||
|
// External
|
||||||
|
|
||||||
|
if ((name.Left(10).Cmp("EX:http://") == 0) || (name.Left(9).Cmp("EX:irc://") == 0))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
_snprintf(fullpath,sizeof(fullpath),"%s\\%s",apppath,name.Mid(3));
|
||||||
|
|
||||||
|
if (wxFileExists(fullpath) || wxDirExists(fullpath))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Feature not installed
|
||||||
|
LinkColor.Set(0x80, 0x80, 0x80);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.HasParam( wxT("TARGET") )) target = tag.GetParam( wxT("TARGET") );
|
||||||
|
m_WParser->SetActualColor(LinkColor);
|
||||||
|
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(LinkColor));
|
||||||
|
m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
m_WParser->SetLink(wxHtmlLinkInfo(name, target));
|
||||||
|
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
m_WParser->SetLink(oldlnk);
|
||||||
|
m_WParser->SetFontUnderlined(oldund);
|
||||||
|
m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
|
||||||
|
m_WParser->SetActualColor(oldclr);
|
||||||
|
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr));
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(A)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAGS_MODULE_BEGIN(Links)
|
||||||
|
|
||||||
|
TAGS_MODULE_ADD(A)
|
||||||
|
|
||||||
|
TAGS_MODULE_END(Links)
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
33
Contrib/NSIS Menu/src/html/m_list.cpp
Normal file
33
Contrib/NSIS Menu/src/html/m_list.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: m_list.cpp
|
||||||
|
// Purpose: wxHtml module for lists
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: m_list.cpp,v 1.15.2.3 2002/11/09 00:07:34 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#include "wx/brush.h"
|
||||||
|
#include "wx/dc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
#include "wx/html/m_templ.h"
|
||||||
|
|
||||||
|
#include "wx/html/htmlcell.h"
|
||||||
|
|
||||||
|
#endif
|
32
Contrib/NSIS Menu/src/html/m_pre.cpp
Normal file
32
Contrib/NSIS Menu/src/html/m_pre.cpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: m_pre.cpp
|
||||||
|
// Purpose: wxHtml module for <PRE> ... </PRE> tag (code citation)
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: m_pre.cpp,v 1.21.2.3 2002/11/09 00:07:35 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
#include "wx/html/m_templ.h"
|
||||||
|
|
||||||
|
#include "wx/html/htmlcell.h"
|
||||||
|
#include "wx/tokenzr.h"
|
||||||
|
#include "wx/encconv.h"
|
||||||
|
|
||||||
|
#endif
|
51
Contrib/NSIS Menu/src/html/m_style.cpp
Normal file
51
Contrib/NSIS Menu/src/html/m_style.cpp
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: m_style.cpp
|
||||||
|
// Purpose: wxHtml module for parsing <style> tag
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: m_style.cpp,v 1.2.2.3 2002/11/09 00:07:35 VS Exp $
|
||||||
|
// Copyright: (c) 2002 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
#include "wx/html/m_templ.h"
|
||||||
|
|
||||||
|
FORCE_LINK_ME(m_style)
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(STYLE, "STYLE")
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(WXUNUSED(tag))
|
||||||
|
{
|
||||||
|
// VS: Ignore styles for now. We must have this handler present,
|
||||||
|
// because CSS style text would be rendered verbatim otherwise
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(STYLE)
|
||||||
|
|
||||||
|
|
||||||
|
TAGS_MODULE_BEGIN(StyleTag)
|
||||||
|
|
||||||
|
TAGS_MODULE_ADD(STYLE)
|
||||||
|
|
||||||
|
TAGS_MODULE_END(StyleTag)
|
||||||
|
|
||||||
|
#endif
|
623
Contrib/NSIS Menu/src/html/m_tables.cpp
Normal file
623
Contrib/NSIS Menu/src/html/m_tables.cpp
Normal file
|
@ -0,0 +1,623 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: m_tables.cpp
|
||||||
|
// Purpose: wxHtml module for tables
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: m_tables.cpp,v 1.29 2003/01/02 23:38:05 VZ Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
REMARKS:
|
||||||
|
1. This version of m_tables doesn't support auto-layout algorithm.
|
||||||
|
This means that all columns are of same width unless explicitly specified.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "wx/html/forcelnk.h"
|
||||||
|
#include "wx/html/m_templ.h"
|
||||||
|
|
||||||
|
#include "wx/html/htmlcell.h"
|
||||||
|
|
||||||
|
FORCE_LINK_ME(m_tables)
|
||||||
|
|
||||||
|
|
||||||
|
#define TABLE_BORDER_CLR_1 wxColour(0xC5, 0xC2, 0xC5)
|
||||||
|
#define TABLE_BORDER_CLR_2 wxColour(0x62, 0x61, 0x62)
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlTableCell
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
struct colStruct
|
||||||
|
{
|
||||||
|
int width, units;
|
||||||
|
// width of the column either in pixels or percents
|
||||||
|
// ('width' is the number, 'units' determines its meaning)
|
||||||
|
int minWidth, maxWidth;
|
||||||
|
// minimal/maximal column width. This is needed by HTML 4.0
|
||||||
|
// layouting algorithm and can be determined by trying to
|
||||||
|
// layout table cells with width=1 and width=infinity
|
||||||
|
int leftpos, pixwidth, maxrealwidth;
|
||||||
|
// temporary (depends on actual width of table)
|
||||||
|
};
|
||||||
|
|
||||||
|
enum cellState
|
||||||
|
{
|
||||||
|
cellSpan,
|
||||||
|
cellUsed,
|
||||||
|
cellFree
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cellStruct
|
||||||
|
{
|
||||||
|
wxHtmlContainerCell *cont;
|
||||||
|
int colspan, rowspan;
|
||||||
|
int minheight, valign;
|
||||||
|
cellState flag;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class wxHtmlTableCell : public wxHtmlContainerCell
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
/* These are real attributes: */
|
||||||
|
|
||||||
|
// should we draw borders or not?
|
||||||
|
bool m_HasBorders;
|
||||||
|
// number of columns; rows
|
||||||
|
int m_NumCols, m_NumRows;
|
||||||
|
// array of column information
|
||||||
|
colStruct *m_ColsInfo;
|
||||||
|
// 2D array of all cells in the table : m_CellInfo[row][column]
|
||||||
|
cellStruct **m_CellInfo;
|
||||||
|
// spaces between cells
|
||||||
|
int m_Spacing;
|
||||||
|
// cells internal indentation
|
||||||
|
int m_Padding;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/* ...and these are valid only when parsing the table: */
|
||||||
|
|
||||||
|
// number of actual column (ranging from 0..m_NumCols)
|
||||||
|
int m_ActualCol, m_ActualRow;
|
||||||
|
|
||||||
|
// default values (for table and row):
|
||||||
|
wxColour m_tBkg, m_rBkg;
|
||||||
|
wxString m_tValign, m_rValign;
|
||||||
|
|
||||||
|
double m_PixelScale;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
wxHtmlTableCell(wxHtmlContainerCell *parent, const wxHtmlTag& tag, double pixel_scale = 1.0);
|
||||||
|
~wxHtmlTableCell();
|
||||||
|
virtual void Layout(int w);
|
||||||
|
|
||||||
|
void AddRow(const wxHtmlTag& tag);
|
||||||
|
void AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Reallocates memory to given number of cols/rows
|
||||||
|
// and changes m_NumCols/m_NumRows value to reflect this change
|
||||||
|
// NOTE! You CAN'T change m_NumCols/m_NumRows before calling this!!
|
||||||
|
void ReallocCols(int cols);
|
||||||
|
void ReallocRows(int rows);
|
||||||
|
|
||||||
|
// Computes minimal and maximal widths of columns. Needs to be called
|
||||||
|
// only once, before first Layout().
|
||||||
|
void ComputeMinMaxWidths();
|
||||||
|
|
||||||
|
DECLARE_NO_COPY_CLASS(wxHtmlTableCell)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlTableCell::wxHtmlTableCell(wxHtmlContainerCell *parent, const wxHtmlTag& tag, double pixel_scale)
|
||||||
|
: wxHtmlContainerCell(parent)
|
||||||
|
{
|
||||||
|
m_PixelScale = pixel_scale;
|
||||||
|
m_HasBorders =
|
||||||
|
(tag.HasParam(wxT("BORDER")) && tag.GetParam(wxT("BORDER")) != wxT("0"));
|
||||||
|
m_ColsInfo = NULL;
|
||||||
|
m_NumCols = m_NumRows = 0;
|
||||||
|
m_CellInfo = NULL;
|
||||||
|
m_ActualCol = m_ActualRow = -1;
|
||||||
|
|
||||||
|
/* scan params: */
|
||||||
|
if (tag.HasParam(wxT("BGCOLOR")))
|
||||||
|
tag.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg);
|
||||||
|
if (tag.HasParam(wxT("VALIGN")))
|
||||||
|
m_tValign = tag.GetParam(wxT("VALIGN"));
|
||||||
|
else
|
||||||
|
m_tValign = wxEmptyString;
|
||||||
|
if (!tag.GetParamAsInt(wxT("CELLSPACING"), &m_Spacing))
|
||||||
|
m_Spacing = 2;
|
||||||
|
if (!tag.GetParamAsInt(wxT("CELLPADDING"), &m_Padding))
|
||||||
|
m_Padding = 3;
|
||||||
|
m_Spacing = (int)(m_PixelScale * (double)m_Spacing);
|
||||||
|
m_Padding = (int)(m_PixelScale * (double)m_Padding);
|
||||||
|
|
||||||
|
if (m_HasBorders)
|
||||||
|
SetBorder(TABLE_BORDER_CLR_1, TABLE_BORDER_CLR_2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlTableCell::~wxHtmlTableCell()
|
||||||
|
{
|
||||||
|
if (m_ColsInfo) free(m_ColsInfo);
|
||||||
|
if (m_CellInfo)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_NumRows; i++)
|
||||||
|
free(m_CellInfo[i]);
|
||||||
|
free(m_CellInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlTableCell::ReallocCols(int cols)
|
||||||
|
{
|
||||||
|
int i,j;
|
||||||
|
|
||||||
|
for (i = 0; i < m_NumRows; i++)
|
||||||
|
{
|
||||||
|
m_CellInfo[i] = (cellStruct*) realloc(m_CellInfo[i], sizeof(cellStruct) * cols);
|
||||||
|
for (j = m_NumCols; j < cols; j++)
|
||||||
|
m_CellInfo[i][j].flag = cellFree;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ColsInfo = (colStruct*) realloc(m_ColsInfo, sizeof(colStruct) * cols);
|
||||||
|
for (j = m_NumCols; j < cols; j++)
|
||||||
|
{
|
||||||
|
m_ColsInfo[j].width = 0;
|
||||||
|
m_ColsInfo[j].units = wxHTML_UNITS_PERCENT;
|
||||||
|
m_ColsInfo[j].minWidth = m_ColsInfo[j].maxWidth = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_NumCols = cols;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlTableCell::ReallocRows(int rows)
|
||||||
|
{
|
||||||
|
m_CellInfo = (cellStruct**) realloc(m_CellInfo, sizeof(cellStruct*) * rows);
|
||||||
|
for (int row = m_NumRows; row < rows ; row++)
|
||||||
|
{
|
||||||
|
if (m_NumCols == 0)
|
||||||
|
m_CellInfo[row] = NULL;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_CellInfo[row] = (cellStruct*) malloc(sizeof(cellStruct) * m_NumCols);
|
||||||
|
for (int col = 0; col < m_NumCols; col++)
|
||||||
|
m_CellInfo[row][col].flag = cellFree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_NumRows = rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlTableCell::AddRow(const wxHtmlTag& tag)
|
||||||
|
{
|
||||||
|
m_ActualCol = -1;
|
||||||
|
// VS: real allocation of row entry is done in AddCell in order
|
||||||
|
// to correctly handle empty rows (i.e. "<tr></tr>")
|
||||||
|
// m_ActualCol == -1 indicates that AddCell has to allocate new row.
|
||||||
|
|
||||||
|
// scan params:
|
||||||
|
m_rBkg = m_tBkg;
|
||||||
|
if (tag.HasParam(wxT("BGCOLOR")))
|
||||||
|
tag.GetParamAsColour(wxT("BGCOLOR"), &m_rBkg);
|
||||||
|
if (tag.HasParam(wxT("VALIGN")))
|
||||||
|
m_rValign = tag.GetParam(wxT("VALIGN"));
|
||||||
|
else
|
||||||
|
m_rValign = m_tValign;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
|
||||||
|
{
|
||||||
|
// Is this cell in new row?
|
||||||
|
// VS: we can't do it in AddRow, see my comment there
|
||||||
|
if (m_ActualCol == -1)
|
||||||
|
{
|
||||||
|
if (m_ActualRow + 1 > m_NumRows - 1)
|
||||||
|
ReallocRows(m_ActualRow + 2);
|
||||||
|
m_ActualRow++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cells & columns:
|
||||||
|
do
|
||||||
|
{
|
||||||
|
m_ActualCol++;
|
||||||
|
} while ((m_ActualCol < m_NumCols) &&
|
||||||
|
(m_CellInfo[m_ActualRow][m_ActualCol].flag != cellFree));
|
||||||
|
|
||||||
|
if (m_ActualCol > m_NumCols - 1)
|
||||||
|
ReallocCols(m_ActualCol + 1);
|
||||||
|
|
||||||
|
int r = m_ActualRow, c = m_ActualCol;
|
||||||
|
|
||||||
|
m_CellInfo[r][c].cont = cell;
|
||||||
|
m_CellInfo[r][c].colspan = 1;
|
||||||
|
m_CellInfo[r][c].rowspan = 1;
|
||||||
|
m_CellInfo[r][c].flag = cellUsed;
|
||||||
|
m_CellInfo[r][c].minheight = 0;
|
||||||
|
m_CellInfo[r][c].valign = wxHTML_ALIGN_TOP;
|
||||||
|
|
||||||
|
/* scan for parameters: */
|
||||||
|
|
||||||
|
// width:
|
||||||
|
{
|
||||||
|
if (tag.HasParam(wxT("WIDTH")))
|
||||||
|
{
|
||||||
|
wxString wd = tag.GetParam(wxT("WIDTH"));
|
||||||
|
|
||||||
|
if (wd[wd.Length()-1] == wxT('%'))
|
||||||
|
{
|
||||||
|
wxSscanf(wd.c_str(), wxT("%i%%"), &m_ColsInfo[c].width);
|
||||||
|
m_ColsInfo[c].units = wxHTML_UNITS_PERCENT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxSscanf(wd.c_str(), wxT("%i"), &m_ColsInfo[c].width);
|
||||||
|
m_ColsInfo[c].width = (int)(m_PixelScale * (double)m_ColsInfo[c].width);
|
||||||
|
m_ColsInfo[c].units = wxHTML_UNITS_PIXELS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// spanning:
|
||||||
|
{
|
||||||
|
tag.GetParamAsInt(wxT("COLSPAN"), &m_CellInfo[r][c].colspan);
|
||||||
|
tag.GetParamAsInt(wxT("ROWSPAN"), &m_CellInfo[r][c].rowspan);
|
||||||
|
|
||||||
|
// VS: the standard says this about col/rowspan:
|
||||||
|
// "This attribute specifies the number of rows spanned by the
|
||||||
|
// current cell. The default value of this attribute is one ("1").
|
||||||
|
// The value zero ("0") means that the cell spans all rows from the
|
||||||
|
// current row to the last row of the table." All mainstream
|
||||||
|
// browsers act as if 0==1, though, and so does wxHTML.
|
||||||
|
if (m_CellInfo[r][c].colspan < 1)
|
||||||
|
m_CellInfo[r][c].colspan = 1;
|
||||||
|
if (m_CellInfo[r][c].rowspan < 1)
|
||||||
|
m_CellInfo[r][c].rowspan = 1;
|
||||||
|
|
||||||
|
if ((m_CellInfo[r][c].colspan > 1) || (m_CellInfo[r][c].rowspan > 1))
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
if (r + m_CellInfo[r][c].rowspan > m_NumRows)
|
||||||
|
ReallocRows(r + m_CellInfo[r][c].rowspan);
|
||||||
|
if (c + m_CellInfo[r][c].colspan > m_NumCols)
|
||||||
|
ReallocCols(c + m_CellInfo[r][c].colspan);
|
||||||
|
for (i = r; i < r + m_CellInfo[r][c].rowspan; i++)
|
||||||
|
for (j = c; j < c + m_CellInfo[r][c].colspan; j++)
|
||||||
|
m_CellInfo[i][j].flag = cellSpan;
|
||||||
|
m_CellInfo[r][c].flag = cellUsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//background color:
|
||||||
|
{
|
||||||
|
wxColour bk = m_rBkg;
|
||||||
|
if (tag.HasParam(wxT("BGCOLOR")))
|
||||||
|
tag.GetParamAsColour(wxT("BGCOLOR"), &bk);
|
||||||
|
if (bk.Ok())
|
||||||
|
cell->SetBackgroundColour(bk);
|
||||||
|
}
|
||||||
|
if (m_HasBorders)
|
||||||
|
cell->SetBorder(TABLE_BORDER_CLR_2, TABLE_BORDER_CLR_1);
|
||||||
|
|
||||||
|
// vertical alignment:
|
||||||
|
{
|
||||||
|
wxString valign;
|
||||||
|
if (tag.HasParam(wxT("VALIGN")))
|
||||||
|
valign = tag.GetParam(wxT("VALIGN"));
|
||||||
|
else
|
||||||
|
valign = m_tValign;
|
||||||
|
valign.MakeUpper();
|
||||||
|
if (valign == wxT("TOP"))
|
||||||
|
m_CellInfo[r][c].valign = wxHTML_ALIGN_TOP;
|
||||||
|
else if (valign == wxT("BOTTOM"))
|
||||||
|
m_CellInfo[r][c].valign = wxHTML_ALIGN_BOTTOM;
|
||||||
|
else m_CellInfo[r][c].valign = wxHTML_ALIGN_CENTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
cell->SetIndent(m_Padding, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlTableCell::ComputeMinMaxWidths()
|
||||||
|
{
|
||||||
|
if (m_NumCols == 0 || m_ColsInfo[0].minWidth != -1) return;
|
||||||
|
|
||||||
|
int left, right, width;
|
||||||
|
|
||||||
|
for (int c = 0; c < m_NumCols; c++)
|
||||||
|
{
|
||||||
|
for (int r = 0; r < m_NumRows; r++)
|
||||||
|
{
|
||||||
|
cellStruct& cell = m_CellInfo[r][c];
|
||||||
|
if (cell.flag == cellUsed)
|
||||||
|
{
|
||||||
|
cell.cont->Layout(2*m_Padding + 1);
|
||||||
|
cell.cont->GetHorizontalConstraints(&left, &right);
|
||||||
|
width = right - left;
|
||||||
|
width -= (cell.colspan-1) * m_Spacing;
|
||||||
|
// HTML 4.0 says it is acceptable to distribute min/max
|
||||||
|
// width of spanning cells evently
|
||||||
|
width /= cell.colspan;
|
||||||
|
for (int j = 0; j < cell.colspan; j++)
|
||||||
|
if (width > m_ColsInfo[c+j].minWidth)
|
||||||
|
m_ColsInfo[c+j].minWidth = width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME -- compute maxWidth as well. Not needed yet, so there's no
|
||||||
|
// point in computing it.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlTableCell::Layout(int w)
|
||||||
|
{
|
||||||
|
ComputeMinMaxWidths();
|
||||||
|
|
||||||
|
wxHtmlCell::Layout(w);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
WIDTH ADJUSTING :
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT)
|
||||||
|
{
|
||||||
|
if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100;
|
||||||
|
else m_Width = m_WidthFloat * w / 100;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_WidthFloat < 0) m_Width = w + m_WidthFloat;
|
||||||
|
else m_Width = m_WidthFloat;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
LAYOUTING :
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 1. setup columns widths: */
|
||||||
|
{
|
||||||
|
int wpix = m_Width - (m_NumCols + 1) * m_Spacing;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
// 1a. setup fixed-width columns:
|
||||||
|
for (i = 0; i < m_NumCols; i++)
|
||||||
|
if (m_ColsInfo[i].units == wxHTML_UNITS_PIXELS)
|
||||||
|
{
|
||||||
|
m_ColsInfo[i].pixwidth = wxMax(m_ColsInfo[i].width,
|
||||||
|
m_ColsInfo[i].minWidth);
|
||||||
|
wpix -= m_ColsInfo[i].pixwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1b. setup floating-width columns:
|
||||||
|
int wtemp = 0;
|
||||||
|
for (i = 0; i < m_NumCols; i++)
|
||||||
|
if ((m_ColsInfo[i].units == wxHTML_UNITS_PERCENT) && (m_ColsInfo[i].width != 0))
|
||||||
|
{
|
||||||
|
m_ColsInfo[i].pixwidth = wxMax(m_ColsInfo[i].width * wpix / 100,
|
||||||
|
m_ColsInfo[i].minWidth);
|
||||||
|
wtemp += m_ColsInfo[i].pixwidth;
|
||||||
|
}
|
||||||
|
wpix -= wtemp;
|
||||||
|
|
||||||
|
// 1c. setup defalut columns (no width specification supplied):
|
||||||
|
// NOTE! This algorithm doesn't conform to HTML standard : it assigns equal widths
|
||||||
|
// instead of optimal
|
||||||
|
for (i = j = 0; i < m_NumCols; i++)
|
||||||
|
if (m_ColsInfo[i].width == 0) j++;
|
||||||
|
for (i = 0; i < m_NumCols; i++)
|
||||||
|
if (m_ColsInfo[i].width == 0)
|
||||||
|
m_ColsInfo[i].pixwidth = wpix / j;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 2. compute positions of columns: */
|
||||||
|
{
|
||||||
|
int wpos = m_Spacing;
|
||||||
|
for (int i = 0; i < m_NumCols; i++)
|
||||||
|
{
|
||||||
|
m_ColsInfo[i].leftpos = wpos;
|
||||||
|
wpos += m_ColsInfo[i].pixwidth + m_Spacing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 3. sub-layout all cells: */
|
||||||
|
{
|
||||||
|
int *ypos = new int[m_NumRows + 1];
|
||||||
|
|
||||||
|
int actcol, actrow;
|
||||||
|
int fullwid;
|
||||||
|
wxHtmlContainerCell *actcell;
|
||||||
|
|
||||||
|
ypos[0] = m_Spacing;
|
||||||
|
for (actrow = 1; actrow <= m_NumRows; actrow++) ypos[actrow] = -1;
|
||||||
|
for (actrow = 0; actrow < m_NumRows; actrow++)
|
||||||
|
{
|
||||||
|
if (ypos[actrow] == -1) ypos[actrow] = ypos[actrow-1];
|
||||||
|
// 3a. sub-layout and detect max height:
|
||||||
|
|
||||||
|
for (actcol = 0; actcol < m_NumCols; actcol++) {
|
||||||
|
if (m_CellInfo[actrow][actcol].flag != cellUsed) continue;
|
||||||
|
actcell = m_CellInfo[actrow][actcol].cont;
|
||||||
|
fullwid = 0;
|
||||||
|
for (int i = actcol; i < m_CellInfo[actrow][actcol].colspan + actcol; i++)
|
||||||
|
fullwid += m_ColsInfo[i].pixwidth;
|
||||||
|
fullwid += (m_CellInfo[actrow][actcol].colspan - 1) * m_Spacing;
|
||||||
|
actcell->SetMinHeight(m_CellInfo[actrow][actcol].minheight, m_CellInfo[actrow][actcol].valign);
|
||||||
|
actcell->Layout(fullwid);
|
||||||
|
|
||||||
|
if (ypos[actrow] + actcell->GetHeight() + m_CellInfo[actrow][actcol].rowspan * m_Spacing > ypos[actrow + m_CellInfo[actrow][actcol].rowspan])
|
||||||
|
ypos[actrow + m_CellInfo[actrow][actcol].rowspan] =
|
||||||
|
ypos[actrow] + actcell->GetHeight() + m_CellInfo[actrow][actcol].rowspan * m_Spacing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (actrow = 0; actrow < m_NumRows; actrow++)
|
||||||
|
{
|
||||||
|
// 3b. place cells in row & let'em all have same height:
|
||||||
|
|
||||||
|
for (actcol = 0; actcol < m_NumCols; actcol++)
|
||||||
|
{
|
||||||
|
if (m_CellInfo[actrow][actcol].flag != cellUsed) continue;
|
||||||
|
actcell = m_CellInfo[actrow][actcol].cont;
|
||||||
|
actcell->SetMinHeight(
|
||||||
|
ypos[actrow + m_CellInfo[actrow][actcol].rowspan] - ypos[actrow] - m_Spacing,
|
||||||
|
m_CellInfo[actrow][actcol].valign);
|
||||||
|
fullwid = 0;
|
||||||
|
for (int i = actcol; i < m_CellInfo[actrow][actcol].colspan + actcol; i++)
|
||||||
|
fullwid += m_ColsInfo[i].pixwidth;
|
||||||
|
fullwid += (m_CellInfo[actrow][actcol].colspan - 1) * m_Spacing;
|
||||||
|
actcell->Layout(fullwid);
|
||||||
|
actcell->SetPos(m_ColsInfo[actcol].leftpos, ypos[actrow]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_Height = ypos[m_NumRows];
|
||||||
|
delete[] ypos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// The tables handler:
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
|
||||||
|
|
||||||
|
TAG_HANDLER_VARS
|
||||||
|
wxHtmlTableCell* m_Table;
|
||||||
|
wxString m_tAlign, m_rAlign;
|
||||||
|
|
||||||
|
TAG_HANDLER_CONSTR(TABLE)
|
||||||
|
{
|
||||||
|
m_Table = NULL;
|
||||||
|
m_tAlign = m_rAlign = wxEmptyString;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TAG_HANDLER_PROC(tag)
|
||||||
|
{
|
||||||
|
wxHtmlContainerCell *c;
|
||||||
|
|
||||||
|
// new table started, backup upper-level table (if any) and create new:
|
||||||
|
if (tag.GetName() == wxT("TABLE"))
|
||||||
|
{
|
||||||
|
wxHtmlTableCell *oldt = m_Table;
|
||||||
|
wxHtmlContainerCell *oldcont;
|
||||||
|
|
||||||
|
oldcont = c = m_WParser->OpenContainer();
|
||||||
|
|
||||||
|
c->SetWidthFloat(tag, m_WParser->GetPixelScale());
|
||||||
|
m_Table = new wxHtmlTableCell(c, tag, m_WParser->GetPixelScale());
|
||||||
|
int oldAlign = m_WParser->GetAlign();
|
||||||
|
m_tAlign = wxEmptyString;
|
||||||
|
if (tag.HasParam(wxT("ALIGN")))
|
||||||
|
m_tAlign = tag.GetParam(wxT("ALIGN"));
|
||||||
|
|
||||||
|
ParseInner(tag);
|
||||||
|
|
||||||
|
m_WParser->SetAlign(oldAlign);
|
||||||
|
m_WParser->SetContainer(oldcont);
|
||||||
|
m_WParser->CloseContainer();
|
||||||
|
|
||||||
|
m_Table = oldt;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
else if (m_Table)
|
||||||
|
{
|
||||||
|
// new row in table
|
||||||
|
if (tag.GetName() == wxT("TR"))
|
||||||
|
{
|
||||||
|
m_Table->AddRow(tag);
|
||||||
|
m_rAlign = m_tAlign;
|
||||||
|
if (tag.HasParam(wxT("ALIGN")))
|
||||||
|
m_rAlign = tag.GetParam(wxT("ALIGN"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// new cell
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c = m_WParser->SetContainer(new wxHtmlContainerCell(m_Table));
|
||||||
|
m_Table->AddCell(c, tag);
|
||||||
|
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
|
||||||
|
if (tag.GetName() == wxT("TH")) /*header style*/
|
||||||
|
m_WParser->SetAlign(wxHTML_ALIGN_CENTER);
|
||||||
|
else
|
||||||
|
m_WParser->SetAlign(wxHTML_ALIGN_LEFT);
|
||||||
|
|
||||||
|
wxString als;
|
||||||
|
|
||||||
|
als = m_rAlign;
|
||||||
|
if (tag.HasParam(wxT("ALIGN")))
|
||||||
|
als = tag.GetParam(wxT("ALIGN"));
|
||||||
|
als.MakeUpper();
|
||||||
|
if (als == wxT("RIGHT"))
|
||||||
|
m_WParser->SetAlign(wxHTML_ALIGN_RIGHT);
|
||||||
|
else if (als == wxT("LEFT"))
|
||||||
|
m_WParser->SetAlign(wxHTML_ALIGN_LEFT);
|
||||||
|
else if (als == wxT("CENTER"))
|
||||||
|
m_WParser->SetAlign(wxHTML_ALIGN_CENTER);
|
||||||
|
|
||||||
|
m_WParser->OpenContainer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAG_HANDLER_END(TABLE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TAGS_MODULE_BEGIN(Tables)
|
||||||
|
|
||||||
|
TAGS_MODULE_ADD(TABLE)
|
||||||
|
|
||||||
|
TAGS_MODULE_END(Tables)
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
511
Contrib/NSIS Menu/src/html/winpars.cpp
Normal file
511
Contrib/NSIS Menu/src/html/winpars.cpp
Normal file
|
@ -0,0 +1,511 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: winpars.cpp
|
||||||
|
// Purpose: wxHtmlParser class (generic parser)
|
||||||
|
// Author: Vaclav Slavik
|
||||||
|
// RCS-ID: $Id: winpars.cpp,v 1.35.2.5 2002/12/30 18:55:33 VS Exp $
|
||||||
|
// Copyright: (c) 1999 Vaclav Slavik
|
||||||
|
// Licence: wxWindows Licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "winpars.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/defs.h"
|
||||||
|
#if wxUSE_HTML && wxUSE_STREAMS
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WXPRECOMP
|
||||||
|
#include "wx/intl.h"
|
||||||
|
#include "wx/dc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/html/htmldefs.h"
|
||||||
|
#include "wx/html/winpars.h"
|
||||||
|
#include "wx/html/htmlwin.h"
|
||||||
|
#include "wx/fontmap.h"
|
||||||
|
#include "wx/log.h"
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlWinParser
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
wxList wxHtmlWinParser::m_Modules;
|
||||||
|
|
||||||
|
wxHtmlWinParser::wxHtmlWinParser(wxHtmlWindow *wnd) : wxHtmlParser()
|
||||||
|
{
|
||||||
|
m_tmpStrBuf = NULL;
|
||||||
|
m_tmpStrBufSize = 0;
|
||||||
|
m_Window = wnd;
|
||||||
|
m_Container = NULL;
|
||||||
|
m_DC = NULL;
|
||||||
|
m_CharHeight = m_CharWidth = 0;
|
||||||
|
m_UseLink = FALSE;
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
m_EncConv = NULL;
|
||||||
|
m_InputEnc = wxFONTENCODING_ISO8859_1;
|
||||||
|
m_OutputEnc = wxFONTENCODING_DEFAULT;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
{
|
||||||
|
int i, j, k, l, m;
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
for (j = 0; j < 2; j++)
|
||||||
|
for (k = 0; k < 2; k++)
|
||||||
|
for (l = 0; l < 2; l++)
|
||||||
|
for (m = 0; m < 7; m++)
|
||||||
|
{
|
||||||
|
m_FontsTable[i][j][k][l][m] = NULL;
|
||||||
|
m_FontsFacesTable[i][j][k][l][m] = wxEmptyString;
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
m_FontsEncTable[i][j][k][l][m] = wxFONTENCODING_DEFAULT;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
static int default_sizes[7] = {7, 8, 10, 12, 16, 22, 30};
|
||||||
|
#elif defined(__WXMAC__)
|
||||||
|
static int default_sizes[7] = {9, 12, 14, 18, 24, 30, 36};
|
||||||
|
#else
|
||||||
|
static int default_sizes[7] = {10, 12, 14, 16, 19, 24, 32};
|
||||||
|
#endif
|
||||||
|
SetFonts(wxT(""), wxT(""), default_sizes);
|
||||||
|
}
|
||||||
|
|
||||||
|
// fill in wxHtmlParser's tables:
|
||||||
|
wxNode *node = m_Modules.GetFirst();
|
||||||
|
while (node)
|
||||||
|
{
|
||||||
|
wxHtmlTagsModule *mod = (wxHtmlTagsModule*) node->GetData();
|
||||||
|
mod->FillHandlersTable(this);
|
||||||
|
node = node->GetNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wxHtmlWinParser::~wxHtmlWinParser()
|
||||||
|
{
|
||||||
|
int i, j, k, l, m;
|
||||||
|
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
for (j = 0; j < 2; j++)
|
||||||
|
for (k = 0; k < 2; k++)
|
||||||
|
for (l = 0; l < 2; l++)
|
||||||
|
for (m = 0; m < 7; m++)
|
||||||
|
{
|
||||||
|
if (m_FontsTable[i][j][k][l][m] != NULL)
|
||||||
|
delete m_FontsTable[i][j][k][l][m];
|
||||||
|
}
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
delete m_EncConv;
|
||||||
|
#endif
|
||||||
|
delete[] m_tmpStrBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlWinParser::AddModule(wxHtmlTagsModule *module)
|
||||||
|
{
|
||||||
|
m_Modules.Append(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlWinParser::RemoveModule(wxHtmlTagsModule *module)
|
||||||
|
{
|
||||||
|
m_Modules.DeleteObject(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlWinParser::SetFonts(wxString normal_face, wxString fixed_face, const int *sizes)
|
||||||
|
{
|
||||||
|
int i, j, k, l, m;
|
||||||
|
|
||||||
|
for (i = 0; i < 7; i++) m_FontsSizes[i] = sizes[i];
|
||||||
|
m_FontFaceFixed = fixed_face;
|
||||||
|
m_FontFaceNormal = normal_face;
|
||||||
|
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
SetInputEncoding(m_InputEnc);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
for (j = 0; j < 2; j++)
|
||||||
|
for (k = 0; k < 2; k++)
|
||||||
|
for (l = 0; l < 2; l++)
|
||||||
|
for (m = 0; m < 7; m++) {
|
||||||
|
if (m_FontsTable[i][j][k][l][m] != NULL)
|
||||||
|
{
|
||||||
|
delete m_FontsTable[i][j][k][l][m];
|
||||||
|
m_FontsTable[i][j][k][l][m] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlWinParser::InitParser(const wxString& source)
|
||||||
|
{
|
||||||
|
wxHtmlParser::InitParser(source);
|
||||||
|
wxASSERT_MSG(m_DC != NULL, wxT("no DC assigned to wxHtmlWinParser!!"));
|
||||||
|
|
||||||
|
m_FontBold = m_FontItalic = m_FontUnderlined = m_FontFixed = FALSE;
|
||||||
|
m_FontSize = 3; //default one
|
||||||
|
CreateCurrentFont(); // we're selecting default font into
|
||||||
|
m_DC->GetTextExtent( wxT("H"), &m_CharWidth, &m_CharHeight);
|
||||||
|
/* NOTE : we're not using GetCharWidth/Height() because
|
||||||
|
of differences under X and win
|
||||||
|
*/
|
||||||
|
|
||||||
|
m_UseLink = FALSE;
|
||||||
|
m_Link = wxHtmlLinkInfo( wxT(""), wxT("") );
|
||||||
|
m_LinkColor.Set(0x19, 0x56, 0xB1);
|
||||||
|
m_ActualColor.Set(0, 0, 0);
|
||||||
|
m_Align = wxHTML_ALIGN_LEFT;
|
||||||
|
m_tmpLastWasSpace = FALSE;
|
||||||
|
|
||||||
|
OpenContainer();
|
||||||
|
OpenContainer();
|
||||||
|
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
wxString charset = ExtractCharsetInformation(source);
|
||||||
|
if (!charset.empty())
|
||||||
|
{
|
||||||
|
wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(charset);
|
||||||
|
if (enc != wxFONTENCODING_SYSTEM)
|
||||||
|
SetInputEncoding(enc);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
m_Container->InsertCell(new wxHtmlColourCell(m_ActualColor));
|
||||||
|
m_Container->InsertCell(new wxHtmlFontCell(CreateCurrentFont()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlWinParser::DoneParser()
|
||||||
|
{
|
||||||
|
m_Container = NULL;
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
SetInputEncoding(wxFONTENCODING_ISO8859_1); // for next call
|
||||||
|
#endif
|
||||||
|
wxHtmlParser::DoneParser();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxObject* wxHtmlWinParser::GetProduct()
|
||||||
|
{
|
||||||
|
wxHtmlContainerCell *top;
|
||||||
|
|
||||||
|
CloseContainer();
|
||||||
|
OpenContainer();
|
||||||
|
|
||||||
|
top = m_Container;
|
||||||
|
while (top->GetParent()) top = top->GetParent();
|
||||||
|
return top;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxFSFile *wxHtmlWinParser::OpenURL(wxHtmlURLType type,
|
||||||
|
const wxString& url) const
|
||||||
|
{
|
||||||
|
// FIXME - normalize the URL to full path before passing to
|
||||||
|
// OnOpeningURL!!
|
||||||
|
if ( m_Window )
|
||||||
|
{
|
||||||
|
wxString myurl(url);
|
||||||
|
wxHtmlOpeningStatus status;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
wxString redirect;
|
||||||
|
status = m_Window->OnOpeningURL(type, myurl, &redirect);
|
||||||
|
if ( status != wxHTML_REDIRECT )
|
||||||
|
break;
|
||||||
|
|
||||||
|
myurl = redirect;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( status == wxHTML_BLOCK )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return GetFS()->OpenFile(myurl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wxHtmlParser::OpenURL(type, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlWinParser::AddText(const wxChar* txt)
|
||||||
|
{
|
||||||
|
wxHtmlCell *c;
|
||||||
|
size_t i = 0,
|
||||||
|
x,
|
||||||
|
lng = wxStrlen(txt);
|
||||||
|
register wxChar d;
|
||||||
|
int templen = 0;
|
||||||
|
wxChar nbsp = GetEntitiesParser()->GetCharForCode(160 /* nbsp */);
|
||||||
|
|
||||||
|
if (lng+1 > m_tmpStrBufSize)
|
||||||
|
{
|
||||||
|
delete[] m_tmpStrBuf;
|
||||||
|
m_tmpStrBuf = new wxChar[lng+1];
|
||||||
|
m_tmpStrBufSize = lng+1;
|
||||||
|
}
|
||||||
|
wxChar *temp = m_tmpStrBuf;
|
||||||
|
|
||||||
|
if (m_tmpLastWasSpace)
|
||||||
|
{
|
||||||
|
while ((i < lng) &&
|
||||||
|
((txt[i] == wxT('\n')) || (txt[i] == wxT('\r')) || (txt[i] == wxT(' ')) ||
|
||||||
|
(txt[i] == wxT('\t')))) i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (i < lng)
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
d = temp[templen++] = txt[i];
|
||||||
|
if ((d == wxT('\n')) || (d == wxT('\r')) || (d == wxT(' ')) || (d == wxT('\t')))
|
||||||
|
{
|
||||||
|
i++, x++;
|
||||||
|
while ((i < lng) && ((txt[i] == wxT('\n')) || (txt[i] == wxT('\r')) ||
|
||||||
|
(txt[i] == wxT(' ')) || (txt[i] == wxT('\t')))) i++, x++;
|
||||||
|
}
|
||||||
|
else i++;
|
||||||
|
|
||||||
|
if (x)
|
||||||
|
{
|
||||||
|
temp[templen-1] = wxT(' ');
|
||||||
|
temp[templen] = 0;
|
||||||
|
#if 0 // VS - WHY was this here?!
|
||||||
|
if (templen == 1) continue;
|
||||||
|
#endif
|
||||||
|
templen = 0;
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
if (m_EncConv)
|
||||||
|
m_EncConv->Convert(temp);
|
||||||
|
#endif
|
||||||
|
size_t len = wxStrlen(temp);
|
||||||
|
for (size_t j = 0; j < len; j++)
|
||||||
|
if (temp[j] == nbsp)
|
||||||
|
temp[j] = wxT(' ');
|
||||||
|
c = new wxHtmlWordCell(temp, *(GetDC()));
|
||||||
|
if (m_UseLink)
|
||||||
|
c->SetLink(m_Link);
|
||||||
|
m_Container->InsertCell(c);
|
||||||
|
m_tmpLastWasSpace = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (templen && (templen > 1 || temp[0] != wxT(' ')))
|
||||||
|
{
|
||||||
|
temp[templen] = 0;
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
if (m_EncConv)
|
||||||
|
m_EncConv->Convert(temp);
|
||||||
|
#endif
|
||||||
|
size_t len = wxStrlen(temp);
|
||||||
|
for (size_t j = 0; j < len; j++)
|
||||||
|
if (temp[j] == nbsp)
|
||||||
|
temp[j] = wxT(' ');
|
||||||
|
c = new wxHtmlWordCell(temp, *(GetDC()));
|
||||||
|
if (m_UseLink)
|
||||||
|
c->SetLink(m_Link);
|
||||||
|
m_Container->InsertCell(c);
|
||||||
|
m_tmpLastWasSpace = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlContainerCell* wxHtmlWinParser::OpenContainer()
|
||||||
|
{
|
||||||
|
m_Container = new wxHtmlContainerCell(m_Container);
|
||||||
|
m_Container->SetAlignHor(m_Align);
|
||||||
|
m_tmpLastWasSpace = TRUE;
|
||||||
|
/* to avoid space being first character in paragraph */
|
||||||
|
return m_Container;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlContainerCell* wxHtmlWinParser::SetContainer(wxHtmlContainerCell *c)
|
||||||
|
{
|
||||||
|
m_tmpLastWasSpace = TRUE;
|
||||||
|
/* to avoid space being first character in paragraph */
|
||||||
|
return m_Container = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxHtmlContainerCell* wxHtmlWinParser::CloseContainer()
|
||||||
|
{
|
||||||
|
m_Container = m_Container->GetParent();
|
||||||
|
return m_Container;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWinParser::SetFontSize(int s)
|
||||||
|
{
|
||||||
|
if (s < 1) s = 1;
|
||||||
|
else if (s > 7) s = 7;
|
||||||
|
m_FontSize = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxFont* wxHtmlWinParser::CreateCurrentFont()
|
||||||
|
{
|
||||||
|
int fb = GetFontBold(),
|
||||||
|
fi = GetFontItalic(),
|
||||||
|
fu = GetFontUnderlined(),
|
||||||
|
ff = GetFontFixed(),
|
||||||
|
fs = GetFontSize() - 1 /*remap from <1;7> to <0;6>*/ ;
|
||||||
|
|
||||||
|
wxString face = ff ? m_FontFaceFixed : m_FontFaceNormal;
|
||||||
|
wxString *faceptr = &(m_FontsFacesTable[fb][fi][fu][ff][fs]);
|
||||||
|
wxFont **fontptr = &(m_FontsTable[fb][fi][fu][ff][fs]);
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
wxFontEncoding *encptr = &(m_FontsEncTable[fb][fi][fu][ff][fs]);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (*fontptr != NULL && (*faceptr != face
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
|| *encptr != m_OutputEnc
|
||||||
|
#endif
|
||||||
|
))
|
||||||
|
{
|
||||||
|
delete *fontptr;
|
||||||
|
*fontptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*fontptr == NULL)
|
||||||
|
{
|
||||||
|
*faceptr = face;
|
||||||
|
*fontptr = new wxFont(
|
||||||
|
(int) (m_FontsSizes[fs] * m_PixelScale),
|
||||||
|
ff ? wxMODERN : wxSWISS,
|
||||||
|
fi ? wxITALIC : wxNORMAL,
|
||||||
|
fb ? wxBOLD : wxNORMAL,
|
||||||
|
fu ? TRUE : FALSE, face
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
);
|
||||||
|
#else
|
||||||
|
, m_OutputEnc);
|
||||||
|
*encptr = m_OutputEnc;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
m_DC->SetFont(**fontptr);
|
||||||
|
return (*fontptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWinParser::SetLink(const wxHtmlLinkInfo& link)
|
||||||
|
{
|
||||||
|
m_Link = link;
|
||||||
|
m_UseLink = (link.GetHref() != wxEmptyString);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxHtmlWinParser::SetFontFace(const wxString& face)
|
||||||
|
{
|
||||||
|
if (GetFontFixed()) m_FontFaceFixed = face;
|
||||||
|
else m_FontFaceNormal = face;
|
||||||
|
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
if (m_InputEnc != wxFONTENCODING_DEFAULT)
|
||||||
|
SetInputEncoding(m_InputEnc);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if !wxUSE_UNICODE
|
||||||
|
void wxHtmlWinParser::SetInputEncoding(wxFontEncoding enc)
|
||||||
|
{
|
||||||
|
m_InputEnc = m_OutputEnc = wxFONTENCODING_DEFAULT;
|
||||||
|
if (m_EncConv)
|
||||||
|
{
|
||||||
|
delete m_EncConv;
|
||||||
|
m_EncConv = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enc == wxFONTENCODING_DEFAULT) return;
|
||||||
|
|
||||||
|
wxFontEncoding altfix, altnorm;
|
||||||
|
bool availfix, availnorm;
|
||||||
|
|
||||||
|
// exact match?
|
||||||
|
availnorm = wxFontMapper::Get()->IsEncodingAvailable(enc, m_FontFaceNormal);
|
||||||
|
availfix = wxFontMapper::Get()->IsEncodingAvailable(enc, m_FontFaceFixed);
|
||||||
|
if (availnorm && availfix)
|
||||||
|
m_OutputEnc = enc;
|
||||||
|
|
||||||
|
// alternatives?
|
||||||
|
else if (wxFontMapper::Get()->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, FALSE) &&
|
||||||
|
wxFontMapper::Get()->GetAltForEncoding(enc, &altfix, m_FontFaceFixed, FALSE) &&
|
||||||
|
altnorm == altfix)
|
||||||
|
m_OutputEnc = altnorm;
|
||||||
|
|
||||||
|
// at least normal face?
|
||||||
|
else if (availnorm)
|
||||||
|
m_OutputEnc = enc;
|
||||||
|
else if (wxFontMapper::Get()->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, FALSE))
|
||||||
|
m_OutputEnc = altnorm;
|
||||||
|
|
||||||
|
// okay, let convert to ISO_8859-1, available always
|
||||||
|
else
|
||||||
|
m_OutputEnc = wxFONTENCODING_DEFAULT;
|
||||||
|
|
||||||
|
m_InputEnc = enc;
|
||||||
|
if (m_OutputEnc == wxFONTENCODING_DEFAULT)
|
||||||
|
GetEntitiesParser()->SetEncoding(wxFONTENCODING_SYSTEM);
|
||||||
|
else
|
||||||
|
GetEntitiesParser()->SetEncoding(m_OutputEnc);
|
||||||
|
|
||||||
|
if (m_InputEnc == m_OutputEnc) return;
|
||||||
|
|
||||||
|
m_EncConv = new wxEncodingConverter();
|
||||||
|
if (!m_EncConv->Init(m_InputEnc,
|
||||||
|
(m_OutputEnc == wxFONTENCODING_DEFAULT) ?
|
||||||
|
wxFONTENCODING_ISO8859_1 : m_OutputEnc,
|
||||||
|
wxCONVERT_SUBSTITUTE))
|
||||||
|
{ // total failture :-(
|
||||||
|
wxLogError(_("Failed to display HTML document in %s encoding"),
|
||||||
|
wxFontMapper::GetEncodingName(enc).c_str());
|
||||||
|
m_InputEnc = m_OutputEnc = wxFONTENCODING_DEFAULT;
|
||||||
|
delete m_EncConv;
|
||||||
|
m_EncConv = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlWinTagHandler
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinTagHandler, wxHtmlTagHandler)
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxHtmlTagsModule
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// NB: This is *NOT* winpars.cpp's initialization and shutdown code!!
|
||||||
|
// This module is an ancestor for tag handlers modules defined
|
||||||
|
// in m_*.cpp files with TAGS_MODULE_BEGIN...TAGS_MODULE_END construct.
|
||||||
|
//
|
||||||
|
// Do not add any winpars.cpp shutdown or initialization code to it,
|
||||||
|
// create a new module instead!
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxHtmlTagsModule, wxModule)
|
||||||
|
|
||||||
|
bool wxHtmlTagsModule::OnInit()
|
||||||
|
{
|
||||||
|
wxHtmlWinParser::AddModule(this);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxHtmlTagsModule::OnExit()
|
||||||
|
{
|
||||||
|
wxHtmlWinParser::RemoveModule(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
1386
Contrib/NSIS Menu/src/msw/app.cpp
Normal file
1386
Contrib/NSIS Menu/src/msw/app.cpp
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue