From 082e8e7f4c615d5a3fd65971f2f7106ff72396dc Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 29 Sep 2009 14:01:03 +0200 Subject: Ported some basic IPF units to Free Pascal. Signed-off-by: Graeme Geldenhuys --- src/DataTypes.pas | 58 +++++++++++++++++++++++++ src/HelpFileHeader.pas | 105 ++++++++++++++++++++++++++++++++++++++++++++ src/HelpWindow.pas | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ src/IPFEscapeCodes.pas | 47 ++++++++++++++++++++ src/frm_main.pas | 30 ++++++++++++- src/newview_fpgui.lpi | 22 +++++++++- src/newview_fpgui.lpr | 2 +- 7 files changed, 375 insertions(+), 4 deletions(-) create mode 100644 src/DataTypes.pas create mode 100644 src/HelpFileHeader.pas create mode 100644 src/HelpWindow.pas create mode 100644 src/IPFEscapeCodes.pas (limited to 'src') diff --git a/src/DataTypes.pas b/src/DataTypes.pas new file mode 100644 index 00000000..be4de565 --- /dev/null +++ b/src/DataTypes.pas @@ -0,0 +1,58 @@ +Unit DataTypes; + +{$mode objfpc}{$H+} +{$ASMMODE intel} + +// NewView - a new OS/2 Help Viewer +// Copyright 2001 Aaron Lawrence (aaronl at consultant dot com) +// This software is released under the Gnu Public License - see readme.txt + +Interface + +// Just defines various types useful in manipulating help files. + +type + int32 = longword; + int16 = word; + int8 = byte; + pInt16 = ^int16; + pInt32 = ^int32; + pInt8 = ^byte; + + PCharArray = array[ 0..0 ] of PCHar; + Int32Array = array[ 0..0 ] of Int32; + Int16Array = array[ 0..0 ] of Int16; + Int8Array = array[ 0..0 ] of Int8; + + PCharArrayPointer = ^PCharArray; + Int32ArrayPointer = ^Int32Array; + Int16ArrayPointer = ^Int16Array; + Int8ArrayPointer = ^Int8Array; + + TBooleanArray = array[ 0..0 ] of boolean; + BooleanArrayPointer = ^TBooleanArray; + +procedure FillInt32Array( pArray: Int32ArrayPointer; + Size: longint; + Value: Int32 ); + +Implementation + +// This is a nice fast implementation of filling an +// array of dwords (Int32/longword) +procedure FillInt32Array( pArray: Int32ArrayPointer; + Size: longint; + Value: Int32 ); +begin + assert( Size > 0 ); + Asm + Mov EAX, Value + Mov EDI, pArray + Mov ECX, Size + CLD // direction = up + REP STOSD // store double word, until ECX = 0 + End; +end; + +Initialization +End. diff --git a/src/HelpFileHeader.pas b/src/HelpFileHeader.pas new file mode 100644 index 00000000..592ccef9 --- /dev/null +++ b/src/HelpFileHeader.pas @@ -0,0 +1,105 @@ +Unit HelpFileHeader; + +{$mode objfpc}{$H+} + +// NewView - a new OS/2 Help Viewer +// Copyright 2001 Aaron Lawrence (aaronl at consultant dot com) +// This software is released under the Gnu Public License - see readme.txt + +Interface + +// Definition of IPF file header and other structures + +uses + DataTypes; + +Type + THelpFileHeader = record + ID: int16; // ID magic word (5348h = "HS") + unknown1: int8; // unknown purpose, could be third letter of ID + flags: int8; // probably a flag word... + // bit 0: set if INF style file + // bit 4: set if HLP style file + // patching this byte allows reading HLP files + // using the VIEW command, while help files + // seem to work with INF settings here as well. + hdrsize: int16; // total size of header + unknown2: int16; // unknown purpose + + ntoc: int16; // number of entries in the tocarray + tocstart: int32; // file offset of the start of the toc + toclen: int32; // number of bytes in file occupied by the toc + tocoffsetsstart: int32; // file offset of the start of array of toc offsets + nres: int16; // number of panels with ressource numbers + resstart: int32; // 32 bit file offset of ressource number table + nname: int16; // number of panels with textual name + namestart: int32; // 32 bit file offset to panel name table + nindex: int16; // number of index entries + indexstart: int32; // 32 bit file offset to index table + indexlen: int32; // size of index table + unknown3: array[ 0..9 ] of int8; // unknown purpose + searchstart: int32; // 32 bit file offset of full text search table + searchlen: int32; // size of full text search table + nslots: int16; // number of "slots" + slotsstart: int32; // file offset of the slots array + dictlen: int32; // number of bytes occupied by the "dictionary" + ndict: int16; // number of entries in the dictionary + dictstart: int32; // file offset of the start of the dictionary + imgstart: int32; // file offset of image data + unknown4: int8; // unknown purpose + nlsstart: int32; // 32 bit file offset of NLS table + nlslen: int32; // size of NLS table + extstart: int32; // 32 bit file offset of extended data block + reserved: array[ 0..2 ] of int32; // for future use. set to zero. + title: array[ 0..47 ] of char; // ASCII title of database + end; + +Type + TTOCEntryStart = record + length: int8; // length of the entry including this byte + flags: int8; // flag byte, description folows (MSB first) + // bit1 haschildren; // following nodes are a higher level + // bit1 hidden; // this entry doesn't appear in VIEW.EXE's + // presentation of the toc + // bit1 extended; // extended entry format + // bit1 stuff; // ?? + // int4 level; // nesting level + numSlots: int8; // number of "slots" occupied by the text for + // this toc entry + end; + pTTOCEntryStart = ^TTOCEntryStart; + + TExtendedTOCEntry = record + w1: int8; + w2: int8; + end; + pExtendedTOCEntry = ^TExtendedTOCEntry; + + TTOCEntryOffsetArray = array[ 0..0 ] of int32; + pTTOCEntryOffsetArray = ^ TTOCEntryOffsetArray; + +Const + TOCEntryExtended = 32; + TOCEntryHidden = 64; + TOCEntryHasChildren = 128; + +type + THelpXYPair = record + Flags: int8; + X: int16; + Y: int16; + end; + pHelpXYPair = ^ THelpXYPair; + + TSlotHeader = record + stuff: int8; // always 0?? + localdictpos: int32; // file offset of the local dictionary + nlocaldict: int8; // number of entries in the local dict + ntext: int16; // number of bytes in the text + end; + pSlotHeader = ^TSlotHeader; + +Implementation + +Initialization +End. diff --git a/src/HelpWindow.pas b/src/HelpWindow.pas new file mode 100644 index 00000000..8f39dbf9 --- /dev/null +++ b/src/HelpWindow.pas @@ -0,0 +1,115 @@ +Unit HelpWindow; + +{$mode objfpc}{$H+} + +// NewView - a new OS/2 Help Viewer +// Copyright 2001 Aaron Lawrence (aaronl at consultant dot com) +// This software is released under the Gnu Public License - see readme.txt + +Interface + +// What a misnomer. This really just contains a few definitions +// and functions relevant to helpwindow dimensions. + +uses + DataTypes, HelpFileHeader; + +const + ptCharacters = 0; + ptPercentage = 1; + ptPixels = 2; + ptPoints = 3; + ptDynamic = 4; + + XPosRight = 577; + YPosTop = 577; + XYPosCenter = 578; + +type + THelpWindowRect = class + Left: longint; + Bottom: longint; + Width: longint; + Height: longint; + constructor Create; + end; + +procedure SetFootnoteRect( Var Rect: THelpWindowRect ); + +procedure ReadHelpSize( const XY: THelpXYPair; + Var Rect: THelpWindowRect ); +procedure ReadHelpPosition( const XY: THelpXYPair; + Var Rect: THelpWindowRect ); + + +Implementation + +constructor THelpWindowRect.Create; +begin + Left:= -1; + Bottom:= -1; + Width:= -1; + Height:= -1; +end; + +function GetPos( const PositionType: int8; + const Value: longint ): longint; +begin + case PositionType of + ptCharacters: + Result:= Value; + ptPercentage: + Result:= Value; + ptPixels: + Result:= Value * 5; + ptPoints: + Result:= Value; + ptDynamic: + case Value of + 1: Result:= 0; // left + 2: Result:= XPosRight; // right + 4: Result:= 0; // bottom + 8: Result:= YPosTop; // top + 16: Result:= 50; //XYPosCenter; // center. + end; + end; +end; + +procedure ReadHelpPosition( const XY: THelpXYPair; + Var Rect: THelpWindowRect ); +var + XPositionType: int8; + YPositionType: int8; +begin + // read origin + XPositionType:= XY.Flags div 16; + YPositionType:= XY.Flags and 15; + + if XY.X <> -1 then + Rect.Left:= GetPos( XPositionType, XY.X ); + if XY.Y <> -1 then + Rect.Bottom:= GetPos( YPositionType, XY.Y ); +end; + +procedure ReadHelpSize( const XY: THelpXYPair; + Var Rect: THelpWindowRect ); +begin + if XY.X <> -1 then + Rect.Width:= XY.X; + if XY.Y <> -1 then + Rect.Height:= XY.Y; +end; + +procedure SetFootnoteRect( Var Rect: THelpWindowRect ); +begin + with Rect do + begin + Left:= 10; + Width:= 80; + Bottom:= 10; + Height:= 40; + end; +end; + +Initialization +End. diff --git a/src/IPFEscapeCodes.pas b/src/IPFEscapeCodes.pas new file mode 100644 index 00000000..41e743d4 --- /dev/null +++ b/src/IPFEscapeCodes.pas @@ -0,0 +1,47 @@ +Unit IPFEscapeCodes; + +{$mode objfpc}{$H+} + + +// NewView - a new OS/2 Help Viewer +// Copyright 2001 Aaron Lawrence (aaronl at consultant dot com) +// This software is released under the Gnu Public License - see readme.txt + +Interface + +// List of IPF escape codes. Not complete! Many are just used +// as magic numbers in HelpTopic.pas + +const + // Basic byte codes + IPF_END_PARA = $fa; + IPF_CENTER = $fb; + IPF_INVERT_SPACING = $fc; + IPF_LINEBREAK = $fd; + IPF_SPACE = $fe; + IPF_ESC = $ff; + + // Subescape codes of + HPART_DEFINE = 0; + HPART_PT_HDREF = 1; + HPART_PT_FNREF = 2; + HPART_PT_SPREF = 3; + HPART_HDREF = 4; + HPART_FNREF = 5; + HPART_SPREF = 6; + HPART_LAUNCH = 7; + HPART_PT_LAUNCH = 8; + HPART_INFORM = 9; + HPART_PT_INFORM = 10; + // ?? 11 ?? + HPART_EXTERN_PT_HDREF = 12; + HPART_EXTERN_PT_SPREF = 13; + HPART_EXTERN_HDREF = 14; + HPART_EXTERN_SPREF = 15; + HPART_GLOBAL_HDREF = 16; + HPART_GLOBAL_PT_HDREF = 17; + +Implementation + +Initialization +End. diff --git a/src/frm_main.pas b/src/frm_main.pas index 43d4a203..a8ccd689 100644 --- a/src/frm_main.pas +++ b/src/frm_main.pas @@ -6,7 +6,7 @@ interface uses SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_panel, fpg_tab, - fpg_tree, fpg_splitter, fpg_menu, fpg_memo; + fpg_tree, fpg_splitter, fpg_menu, fpg_memo, fpg_button; type @@ -29,6 +29,7 @@ type miSettings: TfpgPopupMenu; miBookmarks: TfpgPopupMenu; miHelp: TfpgPopupMenu; + btnIndex: TfpgButton; FHelpFile: TfpgString; {@VFD_HEAD_END: MainForm} procedure MainFormShow(Sender: TObject); @@ -37,6 +38,7 @@ type procedure miHelpProdInfoClicked(Sender: TObject); procedure miHelpAboutFPGui(Sender: TObject); procedure SetHelpFile(const AValue: TfpgString); + procedure btnShowIndex(Sender: TObject); public constructor Create(AOwner: TComponent); override; procedure AfterCreate; override; @@ -50,11 +52,13 @@ implementation uses fpg_dialogs, fpg_constants; + {@VFD_NEWFORM_IMPL} procedure TMainForm.MainFormShow(Sender: TObject); begin bvlBody.Realign; + end; procedure TMainForm.miFileQuitClicked(Sender: TObject); @@ -96,6 +100,15 @@ begin FHelpFile := AValue; end; +procedure TMainForm.btnShowIndex(Sender: TObject); +var + Count: integer; + i: integer; + s: TfpgString; +begin +// +end; + constructor TMainForm.Create(AOwner: TComponent); begin inherited Create(AOwner); @@ -134,7 +147,7 @@ begin begin Name := 'PageControl1'; SetPosition(0, 0, 222, 300); - ActivePageIndex := 3; + ActivePageIndex := 1; TabOrder := 0; Align := alLeft; end; @@ -257,6 +270,19 @@ begin AddMenuItem('Product Information...', '', @miHelpProdInfoClicked); end; + btnIndex := TfpgButton.Create(tsIndex); + with btnIndex do + begin + Name := 'btnIndex'; + SetPosition(120, 0, 80, 24); + Text := 'Show'; + FontDesc := '#Label1'; + Hint := ''; + ImageName := ''; + TabOrder := 1; + OnClick := @btnShowIndex; + end; + {@VFD_BODY_END: MainForm} {%endregion} diff --git a/src/newview_fpgui.lpi b/src/newview_fpgui.lpi index b16e7f8b..5b4b451d 100644 --- a/src/newview_fpgui.lpi +++ b/src/newview_fpgui.lpi @@ -32,7 +32,7 @@ - + @@ -43,6 +43,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/newview_fpgui.lpr b/src/newview_fpgui.lpr index 48ec709b..95fa99da 100644 --- a/src/newview_fpgui.lpr +++ b/src/newview_fpgui.lpr @@ -6,7 +6,7 @@ uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} - Classes, fpg_main, frm_main; + Classes, fpg_main, frm_main, DataTypes, HelpFileHeader, HelpWindow, IPFEscapeCodes; procedure MainProc; -- cgit v1.2.3-70-g09d2