1 | /****************************** Module Header *******************************
|
---|
2 | *
|
---|
3 | * Module Name: reflow.e
|
---|
4 | *
|
---|
5 | * Copyright (c) Netlabs EPM Distribution Project 2002
|
---|
6 | *
|
---|
7 | * $Id: reflow.e 2869 2018-01-14 17:56:30Z aschn $
|
---|
8 | *
|
---|
9 | * ===========================================================================
|
---|
10 | *
|
---|
11 | * This file is part of the Netlabs EPM Distribution package and is free
|
---|
12 | * software. You can redistribute it and/or modify it under the terms of the
|
---|
13 | * GNU General Public License as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * Netlabs EPM Distribution. This library is distributed in the hope that it
|
---|
16 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
---|
17 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
18 | * General Public License for more details.
|
---|
19 | *
|
---|
20 | ****************************************************************************/
|
---|
21 | ;Source: http://groups.google.com/groups?selm=5ebbc3%24g98%241%40news-s01.ca.us.ibm.net
|
---|
22 |
|
---|
23 | include 'stdconst.e'
|
---|
24 | include 'english.e'
|
---|
25 |
|
---|
26 | const
|
---|
27 | reflow2window_prompt = 'Do a WYSIWYG reflow to window width'
|
---|
28 | reflow2size_prompt = 'Do a WYSIWYG reflow to a specific width'
|
---|
29 | reflow2size_prompt2 = '(provided as the parameter). Default unit is pels.'
|
---|
30 | reflow_prompt_prompt = 'Do a WYSIWYG reflow, prompting for width'
|
---|
31 |
|
---|
32 | defc reflow_actionlist
|
---|
33 | universal ActionsList_FileID
|
---|
34 |
|
---|
35 | insertline '|reflow2window|'reflow2window_prompt'|reflow|', ActionsList_FileID.last+1, ActionsList_FileID
|
---|
36 | insertline '|reflow2size|'reflow2size_prompt||reflow2size_prompt2'|reflow|', ActionsList_FileID.last+1, ActionsList_FileID
|
---|
37 | insertline '|reflow_prompt|'reflow_prompt_prompt'|reflow|', ActionsList_FileID.last+1, ActionsList_FileID
|
---|
38 |
|
---|
39 | defc reflow2window
|
---|
40 | if arg(1) = 'S' then
|
---|
41 | sayerror 0
|
---|
42 | 'reflow'
|
---|
43 | elseif arg(1) = 'I' then
|
---|
44 | 'SayHint' reflow2window_prompt
|
---|
45 | elseif arg(1) = 'H' then
|
---|
46 | 'compiler_help_add REFLOW.hlp'
|
---|
47 | 'helpmenu 32100'
|
---|
48 | endif
|
---|
49 |
|
---|
50 | defc reflow2size
|
---|
51 | parse arg arg1 rest
|
---|
52 | if arg1 = 'S' then
|
---|
53 | 'reflow' rest
|
---|
54 | elseif arg1 = 'I' then
|
---|
55 | 'SayHint' reflow2size_prompt
|
---|
56 | elseif arg1 = 'H' then
|
---|
57 | 'compiler_help_add REFLOW.hlp'
|
---|
58 | 'helpmenu 32100'
|
---|
59 | endif
|
---|
60 |
|
---|
61 | defc reflow_prompt
|
---|
62 | if arg(1) = 'S' then
|
---|
63 | 'reflow *'
|
---|
64 | elseif arg(1) = 'I' then
|
---|
65 | 'SayHint Do a WYSIWYG reflow, prompting for width'
|
---|
66 | elseif arg(1) = 'H' then
|
---|
67 | 'compiler_help_add REFLOW.hlp'
|
---|
68 | 'helpmenu 32100'
|
---|
69 | endif
|
---|
70 |
|
---|
71 | defmain
|
---|
72 | 'reflow' arg(1)
|
---|
73 |
|
---|
74 | const
|
---|
75 | map_WindowToDoc = 1 -- x, y in; x, y out
|
---|
76 | map_DocToLCO = 2 -- x, y in; l, c, o out
|
---|
77 | map_LCOToDoc = 3 -- l, c, o in; x, y out
|
---|
78 | map_Doc2Win = 4 -- x, y in; x, y out
|
---|
79 | map_Win2LCO = 5 -- x, y in; l, c, o out
|
---|
80 | map_LCO2Win = 6 -- l, c, o in; x, y out
|
---|
81 |
|
---|
82 | defc reflow
|
---|
83 | universal last_reflow_width
|
---|
84 |
|
---|
85 | KeyPath = '\NEPMD\User\Reflow\Next'
|
---|
86 | ReflowNext = QueryConfigKey( KeyPath)
|
---|
87 |
|
---|
88 | par_width = arg(1)
|
---|
89 | units_width = ''
|
---|
90 | if par_width = '=' then
|
---|
91 | par_width = last_reflow_width
|
---|
92 | endif
|
---|
93 | if par_width = '*' then
|
---|
94 | 'compiler_help_add REFLOW.hlp' -- Have to make sure help file is loaded, just in case...
|
---|
95 | parse value entrybox( 'Paragraph width',
|
---|
96 | '/'OK__MSG'/'Cancel__MSG'/'Help__MSG'/',
|
---|
97 | last_reflow_width,
|
---|
98 | '',
|
---|
99 | 200,
|
---|
100 | atoi(1) || atoi(32101) || gethwndc(APP_HANDLE) ||
|
---|
101 | 'Enter a width; leave blank to reflow to window.') with button 2 par_width \0
|
---|
102 | if button <> \1 then
|
---|
103 | return
|
---|
104 | endif
|
---|
105 | last_reflow_width = par_width
|
---|
106 | endif
|
---|
107 | save_width = par_width -- Save original units
|
---|
108 |
|
---|
109 | if par_width = '' then -- query current window width
|
---|
110 | swpFrame = copies(\0, 36)
|
---|
111 | swpScrollbar = copies(\0, 36)
|
---|
112 | call dynalink32( 'PMWIN',
|
---|
113 | '#837',
|
---|
114 | gethwndc(EPMINFO_EDITCLIENT) ||
|
---|
115 | address(swpFrame))
|
---|
116 | call dynalink32( 'PMWIN',
|
---|
117 | '#837',
|
---|
118 | gethwndc(EPMINFO_EDITORVSCROLL) ||
|
---|
119 | address(swpScrollbar))
|
---|
120 |
|
---|
121 | par_width = ltoa( substr( swpFrame, 9, 4), 10) - ltoa( substr( swpScrollbar, 9, 4), 10);
|
---|
122 | ; sayerror 'width =' par_width 'pels'
|
---|
123 | elseif isnum(par_width) then
|
---|
124 | -- nop
|
---|
125 | else
|
---|
126 | units_width = par_width'='
|
---|
127 | y = verify( par_width, '0123456789. ')
|
---|
128 | x = leftstr( par_width, y - 1)
|
---|
129 | if not isnum(x) then
|
---|
130 | sayerror -263 -- 'Invalid argument'
|
---|
131 | return
|
---|
132 | endif
|
---|
133 | y = upcase(substr( par_width, y))
|
---|
134 | out_array = copies( \0, 4) -- reserve space for 1 long
|
---|
135 | call dynalink32( 'PMGPI',
|
---|
136 | '#606', -- Dev32QueryCaps
|
---|
137 | atol(dynalink32( 'PMWIN',
|
---|
138 | '#835' /*Win32QueryWindowDC*/,
|
---|
139 | gethwndc(EPMINFO_EDITCLIENT),
|
---|
140 | 2)) ||
|
---|
141 | atol(8) || -- start = 8 (horizontal resolution)
|
---|
142 | atol(1) || -- count = 1
|
---|
143 | address(out_array))
|
---|
144 | h = ltoa( out_array, 10) -- Horizontal res. in pels / meter
|
---|
145 | if abbrev( 'INCHES', y, 1) then
|
---|
146 | par_width = x * h * .0254
|
---|
147 | elseif abbrev( 'FOOT', y, 1) | abbrev('FEET', y, 1) then
|
---|
148 | par_width = x * h * .3048
|
---|
149 | elseif abbrev( 'METERS', y, 1) then
|
---|
150 | par_width = x * h
|
---|
151 | elseif y = 'CM' | abbrev( 'CENTIMETERS', y, 1) then
|
---|
152 | par_width = x * h / 100
|
---|
153 | elseif y = 'MM' | abbrev( 'MILLIMETERS', y, 2) then
|
---|
154 | par_width = x * h / 1000
|
---|
155 | else
|
---|
156 | sayerror 'Unrecognized unit: 'y
|
---|
157 | return
|
---|
158 | endif
|
---|
159 | sayerror arg(1) '=' par_width 'pels (there are' h 'pels / meter)'
|
---|
160 | parse value (par_width + 0.5) with par_width '.' -- round
|
---|
161 | endif
|
---|
162 | oldmargins = .margins
|
---|
163 | .margins = "1 1599 1"
|
---|
164 | x = .line; y = MAXMARGIN
|
---|
165 | map_point map_LCOToDoc, x, y -- Get y position of current line.
|
---|
166 | if par_width > x then
|
---|
167 | sayerror 'Reflow: 'units_width || par_width 'pels is too wide! Max is' x 'pels = column' MAXMARGIN
|
---|
168 | return
|
---|
169 | endif
|
---|
170 | if arg(1) <> '' then -- If not using windowwidth, save width for next time.
|
---|
171 | last_reflow_width = save_width
|
---|
172 | endif
|
---|
173 | display -1
|
---|
174 | call NextCmdAltersText()
|
---|
175 | oldcursory = .cursory
|
---|
176 |
|
---|
177 | start_col = .col
|
---|
178 | do forever
|
---|
179 | x = .line; y = 1
|
---|
180 | ;sayerror 'line' .line': Before map 1, line='x'; col='y
|
---|
181 | map_point map_LCOToDoc, x, y -- Get y position of current line.
|
---|
182 | ;sayerror 'line' .line': After map 1, x='x'; y='y
|
---|
183 | x = par_width
|
---|
184 | y = y + 5
|
---|
185 | ;sayerror 'line' .line': Before map 2, x='x'; y='y
|
---|
186 | map_point map_DocToLCO, x, y -- Get column corresponding to pel pos.
|
---|
187 | ;sayerror 'line' .line': After map 2, line='x'; col='y
|
---|
188 | getline line
|
---|
189 | if substr( line, y) = '' then -- Nothing past the given column.
|
---|
190 | if .line = .last then
|
---|
191 | next_blank = 1
|
---|
192 | else
|
---|
193 | next_blank = textline( .line + 1) = ''
|
---|
194 | endif
|
---|
195 | if next_blank then
|
---|
196 | display 1
|
---|
197 | leave
|
---|
198 | endif
|
---|
199 | ;; rc = 0
|
---|
200 | x = .last
|
---|
201 | display -2
|
---|
202 | call joinlines()
|
---|
203 | display 2
|
---|
204 | if x = .last then -- rc=-276 == Line too long to join, or
|
---|
205 | -- Must have hit MAXMARGIN, and JOIN split the line for us.
|
---|
206 | '+1'
|
---|
207 | if leftstr( textline(.line), 1) = ' ' then -- joinlines() added a blank
|
---|
208 | getsearch savesearch
|
---|
209 | .col = 1
|
---|
210 | 'xcom c/ //' -- Change first blank to null
|
---|
211 | setsearch savesearch
|
---|
212 | endif
|
---|
213 | getline line
|
---|
214 | x = wordindex( line, 2)
|
---|
215 | if x then -- More than one word
|
---|
216 | .col = x
|
---|
217 | split
|
---|
218 | '-1'
|
---|
219 | endif
|
---|
220 | endif
|
---|
221 | iterate
|
---|
222 | else
|
---|
223 | .col = y
|
---|
224 | if substr( line, y, 1) <> ' ' then
|
---|
225 | backtab_word
|
---|
226 | if .col = 1 then
|
---|
227 | .col = y
|
---|
228 | endif
|
---|
229 | endif
|
---|
230 | call splitlines()
|
---|
231 | '+1'
|
---|
232 | endif
|
---|
233 | enddo
|
---|
234 | ; call NewUndoRec()
|
---|
235 | .margins = oldmargins
|
---|
236 | if ReflowNext then -- position on next paragraph (like PE)
|
---|
237 | call pfind_blank_line()
|
---|
238 | for i = .line + 1 to .last
|
---|
239 | getline line, i
|
---|
240 | if line <> '' then
|
---|
241 | .lineg = i
|
---|
242 | .col = 1
|
---|
243 | .cursory = oldcursory
|
---|
244 | .line = i
|
---|
245 | leave
|
---|
246 | endif
|
---|
247 | endfor
|
---|
248 | else
|
---|
249 | .col = start_col
|
---|
250 | endif
|
---|
251 |
|
---|
252 |
|
---|
253 | EA_comment 'This defines the REFLOW command; it can be linked or executed directly. This is also a toolbar "actions" file.'
|
---|