Added wxWidgets HelpViewer Demo
This commit is contained in:
parent
9608b7c7be
commit
57ae8f5834
13
wx/help/Makefile
Normal file
13
wx/help/Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
all: help
|
||||
|
||||
CC = g++
|
||||
LDFLAGS = $(shell wx-config --libs --cflags)
|
||||
PLATFORM := $(shell uname -s)
|
||||
|
||||
help:
|
||||
$(CC) $(LDFLAGS) $@.cpp -o $@
|
||||
|
||||
clean:
|
||||
@$(RM) -f help
|
||||
@$(RM) -rf help.app
|
||||
|
BIN
wx/help/book.htb
Normal file
BIN
wx/help/book.htb
Normal file
Binary file not shown.
106
wx/help/header.inc
Normal file
106
wx/help/header.inc
Normal file
@ -0,0 +1,106 @@
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <setjmp.h>
|
||||
#include <time.h>
|
||||
#include <stdarg.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifndef _WIN32
|
||||
#include <sys/wait.h>
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
|
||||
/* DEFINES */
|
||||
#define MAIN int main (int argc, char** argv) {
|
||||
#define ENDMAIN }
|
||||
#define DECLARE
|
||||
#define FUNCTION
|
||||
#define ENDFUNCTION }
|
||||
#define DIM
|
||||
#define AS
|
||||
#define SUB void
|
||||
#define ENDSUB }
|
||||
#define BEGIN {
|
||||
#define END }
|
||||
#define AND &&
|
||||
#define OR ||
|
||||
#define CLASS class
|
||||
#define TYPE typedef struct
|
||||
#define ADDR &
|
||||
#define INCR ++
|
||||
#define DECR --
|
||||
#define BYREF *
|
||||
#define PTR *
|
||||
#define NOT not
|
||||
#define IF if
|
||||
#define THEN {
|
||||
#define ELSE } else {
|
||||
#define ENDIF }
|
||||
#define FOR for
|
||||
#define TO ;
|
||||
#define STEP ;
|
||||
#define SELECT switch
|
||||
#define CASE case
|
||||
#define _TO_ ...
|
||||
#define ENDCASE break;
|
||||
#define CASE_ELSE default
|
||||
#define ENDSELECT }
|
||||
#define WHILE while
|
||||
#define WEND }
|
||||
#define RETURN return
|
||||
#define CONSTANT const
|
||||
#define STR$( x ) dynamic_cast< std::ostringstream & >( ( std::ostringstream() << std::dec << x ) ).str()
|
||||
#define BOOL bool
|
||||
#define INT int
|
||||
#define UINT unsigned int
|
||||
#define VECTOR std::vector
|
||||
#define MAP std::map
|
||||
#define CHAR char
|
||||
#define ENUM enum {
|
||||
#define ENDENUM };
|
||||
#define EXIT exit
|
||||
#define BREAK break;
|
||||
#define SHORT short
|
||||
#define LPCHAR char*
|
||||
#define CLASS class
|
||||
#define ENDCLASS };
|
||||
#define CONSTRUCTOR
|
||||
#define ENDCONSTRUCTOR }
|
||||
#define DO {
|
||||
#define NEXT }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
/* TYPEDEFS */
|
||||
typedef std::string CSTRING;
|
||||
|
||||
|
||||
char LF [2]= {10,0}; // Line Feed
|
||||
|
||||
|
108
wx/help/help.cpp
Normal file
108
wx/help/help.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
|
||||
|
||||
/* This is how Im creating a MAC application bundle while testing
|
||||
Uncomment this if compiling under MacOS
|
||||
$onexit "rm -rf $FILE$.app && mkdir -p $FILE$.app/Contents/MacOS && cp $FILE$ $FILE$.app/Contents/MacOS && open $FILE$.app"
|
||||
*/
|
||||
#include "jade.h"
|
||||
#include <wx/wx.h>
|
||||
#include <wx/image.h>
|
||||
#include <wx/wxhtml.h>
|
||||
#include <wx/fs_zip.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/filedlg.h>
|
||||
|
||||
class MyApp: public wxApp {
|
||||
// override base class virtuals
|
||||
// ----------------------------
|
||||
public:
|
||||
virtual bool OnInit();
|
||||
virtual int OnExit();
|
||||
|
||||
/* Sub that Responds to idle event */
|
||||
void OnIdle(wxIdleEvent& event);
|
||||
|
||||
private:
|
||||
bool m_exitIfNoMainWindow;
|
||||
wxHtmlHelpController* help;
|
||||
wxFileName fName;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
/* Connect to idle event */
|
||||
BEGIN_EVENT_TABLE(MyApp, wxApp)
|
||||
EVT_IDLE(MyApp::OnIdle)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
/* Implement the Application Object */
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
/* Initialize Application */
|
||||
FUNCTION BOOL MyApp::OnInit() DO
|
||||
INT i;
|
||||
|
||||
/* Used as Exit status flag */
|
||||
m_exitIfNoMainWindow = FALSE;
|
||||
|
||||
/* Assign the name of the HelpFile to the wxFileName object */
|
||||
fName.Assign( wxT("book.htb") );
|
||||
|
||||
/* Dont exit immediately when app window is closed */
|
||||
SetExitOnFrameDelete(false);
|
||||
|
||||
/* Initialize all available image handlers */
|
||||
wxInitAllImageHandlers();
|
||||
|
||||
/* Enable virtual Zip FileSystem */
|
||||
wxFileSystem::AddHandler(new wxZipFSHandler);
|
||||
|
||||
/* Set the Application Name (NOT SHOWN ON TITLEBAR!) */
|
||||
SetAppName( wxT("Help Viewer") );
|
||||
|
||||
|
||||
|
||||
/* Initialize the HelpController Object */
|
||||
help = new wxHtmlHelpController(wxHF_DEFAULT_STYLE|wxHF_OPEN_FILES);
|
||||
|
||||
/* Add the HelpFile to the HelpController */
|
||||
help->AddBook(fName);
|
||||
|
||||
/* Show the HelpFile */
|
||||
help->DisplayContents();
|
||||
|
||||
/* Set the Help windows as topmost */
|
||||
SetTopWindow( help->GetFrame() );
|
||||
|
||||
|
||||
|
||||
/* Set the exit flag to true */
|
||||
m_exitIfNoMainWindow = TRUE;
|
||||
|
||||
RETURN TRUE;
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
/* Idle Event */
|
||||
SUB MyApp::OnIdle(wxIdleEvent &event) DO
|
||||
|
||||
/* Exit if Window is closed */
|
||||
IF (m_exitIfNoMainWindow AND NOT GetTopWindow()) THEN
|
||||
ExitMainLoop();
|
||||
ENDIF
|
||||
|
||||
/* Sort of like DoEvents */
|
||||
event.Skip();
|
||||
event.RequestMore();
|
||||
ENDSUB
|
||||
|
||||
|
||||
/* Called when Application Exits */
|
||||
FUNCTION INT MyApp::OnExit() DO
|
||||
|
||||
/* Delete the HelpController Object */
|
||||
delete help;
|
||||
|
||||
RETURN 0;
|
||||
ENDFUNCTION
|
3
wx/help/jade.h
Normal file
3
wx/help/jade.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include "header.inc"
|
||||
#include "runtime.inc"
|
||||
|
204
wx/help/runtime.inc
Normal file
204
wx/help/runtime.inc
Normal file
@ -0,0 +1,204 @@
|
||||
DECLARE FUNCTION CSTRING LTRIM$ (CSTRING);
|
||||
DECLARE FUNCTION CSTRING RTRIM$ (CSTRING);
|
||||
DECLARE FUNCTION CSTRING TRIM$ (CSTRING);
|
||||
DECLARE FUNCTION CSTRING LEFT$ (CSTRING, INT);
|
||||
DECLARE FUNCTION CSTRING MID$ (CSTRING, INT, INT);
|
||||
DECLARE FUNCTION CSTRING RIGHT$ (CSTRING, INT);
|
||||
DECLARE FUNCTION INT INSTR (CSTRING,CSTRING,size_t=0);
|
||||
DECLARE FUNCTION CSTRING LCASE$ (CSTRING);
|
||||
DECLARE FUNCTION CSTRING UCASE$ (CSTRING);
|
||||
DECLARE FUNCTION CSTRING MCASE$ (CSTRING);
|
||||
DECLARE FUNCTION CSTRING LOADFILE$ (CSTRING);
|
||||
DECLARE FUNCTION CSTRING SPLITPATH$ (CSTRING, INT);
|
||||
DECLARE FUNCTION CSTRING ENC$ (CSTRING,INT=34,INT=34);
|
||||
DECLARE FUNCTION CSTRING REVERSE$ (CSTRING);
|
||||
DECLARE FUNCTION CSTRING REPLACE$ (CSTRING subject, CONSTANT CSTRING& search, CONSTANT CSTRING& replace);
|
||||
DECLARE FUNCTION INT VAL (CSTRING);
|
||||
DECLARE SUB PRINT (CSTRING);
|
||||
DECLARE SUB SAVEFILE(CSTRING src, CSTRING fname);
|
||||
|
||||
|
||||
FUNCTION CSTRING REVERSE$ (CSTRING src) BEGIN
|
||||
RETURN CSTRING( src.rbegin(),src.rend() );
|
||||
ENDFUNCTION
|
||||
|
||||
SUB PRINT (CSTRING A="") BEGIN
|
||||
IF (A.empty()) THEN
|
||||
std::cout << std::endl;
|
||||
ELSE
|
||||
std::cout << A << std::endl;
|
||||
ENDIF
|
||||
ENDSUB
|
||||
|
||||
FUNCTION CSTRING LTRIM$ (CSTRING s) BEGIN
|
||||
s.erase(s.begin(),std::find_if(s.begin(),s.end(),std::not1(std::ptr_fun<INT,INT>(std::isspace))));
|
||||
RETURN s;
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
FUNCTION CSTRING RTRIM$ (CSTRING s) BEGIN
|
||||
s.erase(std::find_if(s.rbegin(),s.rend(),std::not1(std::ptr_fun<INT,INT>(std::isspace))).base(),s.end());
|
||||
RETURN s;
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
FUNCTION CSTRING TRIM$ (CSTRING s) BEGIN
|
||||
RETURN LTRIM$ (RTRIM$ (s));
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
FUNCTION CSTRING LEFT$ (CSTRING s, INT length) BEGIN
|
||||
RETURN s.substr(0,length);
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
FUNCTION CSTRING MID$ (CSTRING s, INT start, INT length) BEGIN
|
||||
RETURN s.substr(start,length);
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
FUNCTION CSTRING RIGHT$ (CSTRING s, INT length) BEGIN
|
||||
RETURN s.substr(s.size()-length);
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
FUNCTION INT INSTR (CSTRING s,CSTRING match, size_t offset) BEGIN
|
||||
IF (s.empty() OR match.empty() OR offset>s.length()) THEN
|
||||
RETURN 0;
|
||||
ENDIF
|
||||
RETURN s.find(match,offset);
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
FUNCTION CSTRING LCASE$ (CSTRING str) BEGIN
|
||||
DIM AS CSTRING name(str);
|
||||
std::transform(name.begin(),name.end(),name.begin(),::tolower);
|
||||
RETURN name;
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
FUNCTION CSTRING UCASE$ (CSTRING str) BEGIN
|
||||
DIM AS CSTRING name(str);
|
||||
std::transform(name.begin(),name.end(),name.begin(),::toupper);
|
||||
RETURN name;
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
FUNCTION CSTRING MCASE$ (CSTRING S) BEGIN
|
||||
DIM AS CSTRING tmpStr(S);
|
||||
DIM AS bool capFlag = FALSE;
|
||||
DIM AS register size_t i;
|
||||
|
||||
|
||||
std::transform(tmpStr.begin(),tmpStr.end(),tmpStr.begin(),::tolower);
|
||||
|
||||
FOR (i=0 TO i<=tmpStr.length() STEP i++) BEGIN
|
||||
IF (std::ispunct(tmpStr[i]) OR std::isspace(tmpStr[i])) THEN
|
||||
capFlag=FALSE;
|
||||
ENDIF
|
||||
|
||||
IF (capFlag==FALSE AND std::isalpha(tmpStr[i])) THEN
|
||||
tmpStr[i]=std::toupper(tmpStr[i]);
|
||||
capFlag=TRUE;
|
||||
ENDIF
|
||||
END
|
||||
RETURN tmpStr;
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
FUNCTION CSTRING LOADFILE$ (CSTRING N) BEGIN
|
||||
DIM AS CSTRING line, tmpStr;
|
||||
DIM AS std::ifstream myFile(N.c_str());
|
||||
|
||||
IF( NOT myFile.good()) BEGIN
|
||||
PRINT("Error opening file");
|
||||
RETURN "ERROR";
|
||||
ENDIF
|
||||
|
||||
WHILE ( NOT myFile.eof()) BEGIN
|
||||
getline(myFile,line);
|
||||
line+=LF;
|
||||
tmpStr+=line;
|
||||
WEND
|
||||
|
||||
myFile.close();
|
||||
|
||||
RETURN tmpStr;
|
||||
|
||||
ENDFUNCTION
|
||||
|
||||
SUB SAVEFILE (CSTRING src, CSTRING fname) BEGIN
|
||||
DIM AS std::ofstream outfile;
|
||||
|
||||
outfile.open(fname.c_str());
|
||||
outfile << src;
|
||||
outfile.close();
|
||||
|
||||
ENDSUB
|
||||
|
||||
FUNCTION CSTRING SPLITPATH$ (CSTRING FPATH, INT mask) BEGIN
|
||||
DIM AS CSTRING fullPath(FPATH);
|
||||
DIM AS CSTRING path, filename, extension;
|
||||
DIM AS CSTRING::size_type lastSlashPos, extPos;
|
||||
|
||||
lastSlashPos=fullPath.find_last_of("/");
|
||||
extPos=fullPath.find_last_of(".");
|
||||
IF (lastSlashPos==CSTRING::npos) THEN
|
||||
path.empty();
|
||||
filename=fullPath;
|
||||
ELSE
|
||||
path=fullPath.substr(0,lastSlashPos);
|
||||
filename=fullPath.substr(lastSlashPos+1,(extPos-lastSlashPos)-1);
|
||||
ENDIF
|
||||
|
||||
IF (extPos==CSTRING::npos) THEN
|
||||
extension.empty();
|
||||
ELSE
|
||||
extension=fullPath.substr(extPos+1,fullPath.size()-extPos-1);
|
||||
ENDIF
|
||||
|
||||
SELECT (mask) BEGIN
|
||||
CASE 4:
|
||||
RETURN path;
|
||||
ENDCASE
|
||||
|
||||
CASE 8:
|
||||
RETURN filename;
|
||||
ENDCASE
|
||||
|
||||
CASE 12:
|
||||
RETURN path.append("/").append(filename);
|
||||
ENDCASE
|
||||
|
||||
CASE 16:
|
||||
RETURN extension;
|
||||
ENDCASE
|
||||
|
||||
CASE_ELSE:
|
||||
RETURN "";
|
||||
|
||||
ENDSELECT
|
||||
|
||||
ENDFUNCTION
|
||||
|
||||
|
||||
FUNCTION CSTRING ENC$ (CSTRING A, INT L, INT R) BEGIN
|
||||
DIM AS std::stringstream buf;
|
||||
buf<<(char)L<<A<<(char)R;
|
||||
RETURN buf.str();
|
||||
ENDFUNCTION
|
||||
|
||||
FUNCTION CSTRING REPLACE$ (CSTRING subject, CONSTANT CSTRING& search, CONSTANT CSTRING& replace) BEGIN
|
||||
DIM AS size_t pos = 0;
|
||||
|
||||
|
||||
WHILE( ( pos = subject.find(search, pos) ) != CSTRING::npos) BEGIN
|
||||
subject.replace(pos, search.length(), replace);
|
||||
pos += replace.length();
|
||||
END
|
||||
RETURN subject;
|
||||
ENDFUNCTION
|
||||
|
||||
FUNCTION INT VAL (CSTRING str) BEGIN
|
||||
RETURN atoi(str.c_str());
|
||||
ENDFUNCTION
|
Loading…
Reference in New Issue
Block a user