summaryrefslogtreecommitdiff
path: root/docview/src/HelpWindowDimensions.pas
blob: c83351762615849d3eb650e711ff5f095c940093 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
unit HelpWindowDimensions;

{$mode objfpc}{$H+}

 // NewView - a new OS/2 Help Viewer
 // Copyright 2003 Aaron Lawrence (aaronl at consultant dot com)
 // This software is released under the Gnu Public License - see readme.txt

interface

uses
  IPFFileFormatUnit;

const
  ptCharacters = 0;
  ptPercentage = 1;
  ptPixels     = 2;
  ptPoints     = 3;
  ptDynamic    = 4;

  XPosRight    = 577; // some random values as markers
  YPosTop      = 577;
  XYPosCenter  = 578;

type
  THelpWindowRect = class(TObject)
  public
    Left:   longint; // xposright means, right aligned
    Bottom: longint; // xpostop means top aligned
                     // both: xyposcenter means centered
    Width:  longint;
    Height: longint;
    constructor Create;
    procedure   Assign(Rect: THelpWindowRect);
  end;

var
  FootnoteRect: 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;

procedure THelpWindowRect.Assign(Rect: THelpWindowRect);
begin
  Left   := Rect.Left;
  Bottom := Rect.Bottom;
  Width  := Rect.Width;
  Height := Rect.Height;
end;

function GetPos(const PositionType: uint8; 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 := YPosTop;     // top
        8:
          Result := 0;           // bottom
        16:
          Result := XYPosCenter; // center.
      end;
  end;
end;

procedure ReadHelpPosition(const XY: THelpXYPair; var Rect: THelpWindowRect);
var
  XPositionType: uint8;
  YPositionType: uint8;
begin
  // read origin
  XPositionType := XY.Flags div 16;
  YPositionType := XY.Flags and 15;

  if XY.X <> $ffff then
    Rect.Left   := GetPos(XPositionType, XY.X);
  if XY.Y <> $ffff then
    Rect.Bottom := GetPos(YPositionType, XY.Y);
end;

procedure ReadHelpSize(const XY: THelpXYPair; var Rect: THelpWindowRect);
begin
  if XY.X <> $ffff then
    Rect.Width  := XY.X;
  if XY.Y <> $ffff then
    Rect.Height := XY.Y;
end;

initialization
  FootnoteRect := THelpWindowRect.Create;
  with FootnoteRect do
  begin
    Left   := 10;
    Width  := 80;
    Bottom := 10;
    Height := 40;
  end;

finalization
  FootnoteRect.Free;

end.