1 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
2 | * Version: CDDL 1.0/LGPL 2.1 |
---|
3 | * |
---|
4 | * The contents of this file are subject to the COMMON DEVELOPMENT AND |
---|
5 | * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use |
---|
6 | * this file except in compliance with the License. You may obtain a copy of |
---|
7 | * the License at http://www.sun.com/cddl/ |
---|
8 | * |
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis, |
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
---|
11 | * for the specific language governing rights and limitations under the |
---|
12 | * License. |
---|
13 | * |
---|
14 | * The Initial Developer of the Original Code is |
---|
15 | * Eugene Romanenko, netlabs.org. |
---|
16 | * Portions created by the Initial Developer are Copyright (C) 2006 |
---|
17 | * the Initial Developer. All Rights Reserved. |
---|
18 | * |
---|
19 | * Contributor(s): |
---|
20 | * |
---|
21 | * Alternatively, the contents of this file may be used under the terms of |
---|
22 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
---|
23 | * in which case the provisions of the LGPL are applicable instead of those |
---|
24 | * above. If you wish to allow use of your version of this file only under the |
---|
25 | * terms of the LGPL, and not to allow others to use your version of this file |
---|
26 | * under the terms of the CDDL, indicate your decision by deleting the |
---|
27 | * provisions above and replace them with the notice and other provisions |
---|
28 | * required by the LGPL. If you do not delete the provisions above, a recipient |
---|
29 | * may use your version of this file under the terms of any one of the CDDL |
---|
30 | * or the LGPL. |
---|
31 | * |
---|
32 | * ***** END LICENSE BLOCK ***** */ |
---|
33 | |
---|
34 | |
---|
35 | #define INCL_WIN |
---|
36 | #define INCL_DOS |
---|
37 | #define INCL_SPL |
---|
38 | #define INCL_SPLDOSPRINT |
---|
39 | #define INCL_DEV |
---|
40 | #include <os2.h> |
---|
41 | |
---|
42 | #include <string> |
---|
43 | #include <set> |
---|
44 | #include <stdio.h> |
---|
45 | #include <stdlib.h> |
---|
46 | #include <process.h> |
---|
47 | #include <dos.h> |
---|
48 | |
---|
49 | #include <ludoc.xh> |
---|
50 | |
---|
51 | #include "Lucide.h" |
---|
52 | #include "pluginman.h" |
---|
53 | #include "pluginViewDlg.h" |
---|
54 | #include "fontsInfoDlg.h" |
---|
55 | #include "docInfoDlg.h" |
---|
56 | #include "findDlg.h" |
---|
57 | #include "printDlg.h" |
---|
58 | #include "progressDlg.h" |
---|
59 | #include "settingsDlg.h" |
---|
60 | #include "passwordDlg.h" |
---|
61 | #include "docViewer.h" |
---|
62 | #include "indexWindow.h" |
---|
63 | #include "recent.h" |
---|
64 | #include "lusettings.h" |
---|
65 | #include "luutils.h" |
---|
66 | #include "tb_spl.h" |
---|
67 | #include "Lucide_res.h" |
---|
68 | #include "messages.h" |
---|
69 | |
---|
70 | |
---|
71 | #define ID_SPLITTER 1 |
---|
72 | |
---|
73 | const char *appName = "Lucide"; |
---|
74 | const char *appVersion = VERSION; |
---|
75 | const char *fwp = "FrameWindowPos"; |
---|
76 | const char *lvd = "LastViewedDir"; |
---|
77 | const char *splpos = "SplitterPos"; |
---|
78 | const char *showind = "ShowIndex"; |
---|
79 | |
---|
80 | HWND createToolbar( HWND hwnd ); |
---|
81 | void AboutBox( HWND hWndFrame ); |
---|
82 | void initPipeMon( HWND hWndFrame ); |
---|
83 | void unInitPipeMon(); |
---|
84 | HWND LcdFileDlg( HWND hwndP, HWND hwndO, FILEDLG *pfild ); |
---|
85 | |
---|
86 | |
---|
87 | HAB hab = NULLHANDLE; |
---|
88 | HWND hWndFrame = NULLHANDLE; |
---|
89 | HWND hWndMenu = NULLHANDLE; |
---|
90 | HWND hToolBar = NULLHANDLE; |
---|
91 | HWND hVertSplitter = NULLHANDLE; |
---|
92 | HWND hFrameSysmenu = NULLHANDLE; |
---|
93 | HWND hFrameTitlebar = NULLHANDLE; |
---|
94 | HWND hFrameMinMax = NULLHANDLE; |
---|
95 | |
---|
96 | Environment *ev = somGetGlobalEnvironment(); |
---|
97 | LuDocument *doc = NULL; |
---|
98 | PluginManager *pluginMan = NULL; |
---|
99 | DocumentViewer *docViewer = NULL; |
---|
100 | IndexWindow *indexWin = NULL; |
---|
101 | FindDlg *findDlg = NULL; |
---|
102 | LuSettings *settings = NULL; |
---|
103 | RecentFiles *recent = NULL; |
---|
104 | char *title = NULL; |
---|
105 | |
---|
106 | |
---|
107 | bool Lucide::dontSwitchPage = false; |
---|
108 | SHORT Lucide::splitterPos = 100; |
---|
109 | bool Lucide::showIndex = true; |
---|
110 | bool Lucide::isMaxview = false; |
---|
111 | bool Lucide::isFullscreen = false; |
---|
112 | LuWindowPos Lucide::winPos = {0}; |
---|
113 | char Lucide::docFullName[ CCHMAXPATH ] = ""; |
---|
114 | char Lucide::docFileName[ CCHMAXPATHCOMP ] = ""; |
---|
115 | char Lucide::docDirName[ CCHMAXPATHCOMP ] = ""; |
---|
116 | char *Lucide::password = NULL; |
---|
117 | ActiveWindow Lucide::activeWindow = AwView; |
---|
118 | // static data for asynch loading document |
---|
119 | ProgressDlg *Lucide::loadProgressDlg = NULL; |
---|
120 | bool Lucide::docLoaded = false;; |
---|
121 | char *Lucide::loadError = NULL; |
---|
122 | long Lucide::loadErrorCode = LU_LDERR_NO_ERROR; |
---|
123 | void *Lucide::thumbnailData = NULL; |
---|
124 | int Lucide::thumbnailDataLen = 0; |
---|
125 | |
---|
126 | // List of files in current directory |
---|
127 | static std::set<std::string> fileList; |
---|
128 | static std::set<std::string>::const_iterator fileListIterator; |
---|
129 | |
---|
130 | HMODULE _hmod = NULLHANDLE; |
---|
131 | |
---|
132 | unsigned APIENTRY LibMain( unsigned hmod, unsigned termination ) |
---|
133 | { |
---|
134 | if ( termination ) { |
---|
135 | // DLL is detaching from process |
---|
136 | } else { |
---|
137 | // DLL is attaching to process |
---|
138 | _hmod = hmod; |
---|
139 | } |
---|
140 | return( 1 ); |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | PFNWP pOldSplProc; |
---|
145 | |
---|
146 | void Lucide::enableCopy( bool enable ) |
---|
147 | { |
---|
148 | WinEnableMenuItem( hWndMenu, CM_COPY, enable ); |
---|
149 | } |
---|
150 | |
---|
151 | void Lucide::setOfPages( long pages ) |
---|
152 | { |
---|
153 | char *pgfrm = newstrdupL( TB_PAGENUM ); |
---|
154 | char pgnum[ 32 ]; |
---|
155 | snprintf( pgnum, sizeof( pgnum ), pgfrm, pages ); |
---|
156 | delete pgfrm; |
---|
157 | WinSetDlgItemText( hToolBar, TBID_OFPAGES, pgnum ); |
---|
158 | WinSendDlgItemMsg( hToolBar, TBID_PAGENUM, SPBM_SETLIMITS, |
---|
159 | MPFROMLONG( pages ), MPFROMLONG( 1 ) ); |
---|
160 | } |
---|
161 | |
---|
162 | void Lucide::checkNavigationMenus() |
---|
163 | { |
---|
164 | WinEnableMenuItem( hWndMenu, CM_GOTOPAGE, TRUE ); |
---|
165 | BOOL enfirst = ( docViewer->getCurrentPage() != 0 ); |
---|
166 | BOOL enlast = ( docViewer->getCurrentPage() != ( doc->getPageCount( ev ) - 1 ) ); |
---|
167 | WinEnableMenuItem( hWndMenu, CM_FIRSTPAGE, enfirst ); |
---|
168 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_FIRSTPAGE), (MPARAM)enfirst ); |
---|
169 | WinEnableMenuItem( hWndMenu, CM_PREVPAGE, enfirst ); |
---|
170 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_PREVPAGE), (MPARAM)enfirst ); |
---|
171 | WinEnableMenuItem( hWndMenu, CM_NEXTPAGE, enlast ); |
---|
172 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_NEXTPAGE), (MPARAM)enlast ); |
---|
173 | WinEnableMenuItem( hWndMenu, CM_LASTPAGE, enlast ); |
---|
174 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_LASTPAGE), (MPARAM)enlast ); |
---|
175 | |
---|
176 | bool tmp = dontSwitchPage; |
---|
177 | dontSwitchPage = true; |
---|
178 | WinSendDlgItemMsg( hToolBar, TBID_PAGENUM, SPBM_SETCURRENTVALUE, |
---|
179 | MPFROMLONG( docViewer->getCurrentPage() + 1 ), MPVOID ); |
---|
180 | dontSwitchPage = tmp; |
---|
181 | indexWin->goToPage( NULL, docViewer->getCurrentPage() ); |
---|
182 | } |
---|
183 | |
---|
184 | void Lucide::enableZoomMenus() |
---|
185 | { |
---|
186 | BOOL scalable = doc->isScalable( ev ); |
---|
187 | WinEnableMenuItem( hWndMenu, CM_FITWINDOW, scalable ); |
---|
188 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_FITWINDOW), (MPARAM)scalable ); |
---|
189 | WinEnableMenuItem( hWndMenu, CM_ACTSIZE, scalable ); |
---|
190 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_ACTSIZE), (MPARAM)scalable ); |
---|
191 | WinEnableMenuItem( hWndMenu, CM_FITWIDTH, scalable ); |
---|
192 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_FITWIDTH), (MPARAM)scalable ); |
---|
193 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_ZOOM_IN_OUT), (MPARAM)scalable ); |
---|
194 | WinEnableMenuItem( hWndMenu, CM_ZOOM_IN, scalable ); |
---|
195 | WinEnableMenuItem( hWndMenu, CM_ZOOM_OUT, scalable ); |
---|
196 | WinEnableControl( hToolBar, TBID_ZOOM, scalable ); |
---|
197 | BOOL rotable = doc->isRotable( ev ); |
---|
198 | WinEnableMenuItem( hWndMenu, CM_ROTATE90CW, rotable ); |
---|
199 | WinEnableMenuItem( hWndMenu, CM_ROTATE90CCW, rotable ); |
---|
200 | } |
---|
201 | |
---|
202 | |
---|
203 | void Lucide::setZoomChecks( SHORT cmd, SHORT cbind, double zoom ) |
---|
204 | { |
---|
205 | if ( cmd != -1 ) |
---|
206 | { |
---|
207 | WinCheckMenuItem( hWndMenu, cmd, TRUE ); |
---|
208 | WinSendMsg( hToolBar, TBM_SETCHECK, MPFROMSHORT( cmd ), (MPARAM)TRUE ); |
---|
209 | } |
---|
210 | |
---|
211 | if ( cbind != -1 ) |
---|
212 | { |
---|
213 | char buf[ 255 ] = ""; |
---|
214 | WinSendDlgItemMsg( hToolBar, TBID_ZOOM, LM_QUERYITEMTEXT, |
---|
215 | MPFROM2SHORT( cbind, sizeof( buf ) ), MPFROMP( buf ) ); |
---|
216 | WinSetDlgItemText( hToolBar, TBID_ZOOM, buf ); |
---|
217 | } |
---|
218 | |
---|
219 | if ( zoom != 0 ) |
---|
220 | { |
---|
221 | std::string z = str( zoom * 100.0 ) + "%"; |
---|
222 | WinSetDlgItemText( hToolBar, TBID_ZOOM, z.c_str() ); |
---|
223 | } |
---|
224 | } |
---|
225 | |
---|
226 | void Lucide::checkZoomMenus() |
---|
227 | { |
---|
228 | double zoom = docViewer->getZoom(); |
---|
229 | |
---|
230 | WinCheckMenuItem( hWndMenu, CM_FITWINDOW, FALSE ); |
---|
231 | WinSendMsg( hToolBar, TBM_SETCHECK, MPFROMSHORT(CM_FITWINDOW), (MPARAM)FALSE ); |
---|
232 | WinCheckMenuItem( hWndMenu, CM_ACTSIZE, FALSE ); |
---|
233 | WinSendMsg( hToolBar, TBM_SETCHECK, MPFROMSHORT(CM_ACTSIZE), (MPARAM)FALSE ); |
---|
234 | WinCheckMenuItem( hWndMenu, CM_FITWIDTH, FALSE ); |
---|
235 | WinSendMsg( hToolBar, TBM_SETCHECK, MPFROMSHORT(CM_FITWIDTH), (MPARAM)FALSE ); |
---|
236 | |
---|
237 | if ( zoom == -2 ) { |
---|
238 | setZoomChecks( CM_FITWINDOW, 1, 0 ); |
---|
239 | } else if ( zoom == -1 ) { |
---|
240 | setZoomChecks( CM_FITWIDTH, 2, 0 ); |
---|
241 | } else if ( zoom == 1 ) { |
---|
242 | setZoomChecks( CM_ACTSIZE, 0, 0 ); |
---|
243 | } else { |
---|
244 | setZoomChecks( -1, -1, zoom ); |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | void Lucide::checkMenus( bool initial ) |
---|
249 | { |
---|
250 | if ( initial ) |
---|
251 | { |
---|
252 | // pre-set "Actual size" |
---|
253 | setZoomChecks( CM_ACTSIZE, 0, 0 ); |
---|
254 | } |
---|
255 | |
---|
256 | if ( doc == NULL ) |
---|
257 | { |
---|
258 | if ( initial ) |
---|
259 | { |
---|
260 | // "single page" mode by default |
---|
261 | WinCheckMenuItem( hWndMenu, CM_SINGLEPAGE, TRUE ); |
---|
262 | } |
---|
263 | |
---|
264 | WinEnableMenuItem( hWndMenu, CM_SAVEAS, FALSE ); |
---|
265 | WinEnableMenuItem( hWndMenu, CM_CLOSE, FALSE ); |
---|
266 | WinEnableMenuItem( hWndMenu, CM_PRINT, FALSE ); |
---|
267 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_PRINT), (MPARAM)FALSE ); |
---|
268 | WinEnableMenuItem( hWndMenu, CM_DOCINFO, FALSE ); |
---|
269 | WinEnableMenuItem( hWndMenu, CM_FONTSINFO, FALSE ); |
---|
270 | |
---|
271 | WinEnableMenuItem( hWndMenu, CM_COPY, FALSE ); |
---|
272 | WinEnableMenuItem( hWndMenu, CM_SELECTALL, FALSE ); |
---|
273 | WinEnableMenuItem( hWndMenu, CM_FIND, FALSE ); |
---|
274 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_FIND), (MPARAM)FALSE ); |
---|
275 | WinEnableMenuItem( hWndMenu, CM_FINDAGAIN, FALSE ); |
---|
276 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_FINDAGAIN), (MPARAM)FALSE ); |
---|
277 | |
---|
278 | WinEnableMenuItem( hWndMenu, CM_FIRSTPAGE, FALSE ); |
---|
279 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_FIRSTPAGE), (MPARAM)FALSE ); |
---|
280 | WinEnableMenuItem( hWndMenu, CM_PREVPAGE, FALSE ); |
---|
281 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_PREVPAGE), (MPARAM)FALSE ); |
---|
282 | WinEnableMenuItem( hWndMenu, CM_NEXTPAGE, FALSE ); |
---|
283 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_NEXTPAGE), (MPARAM)FALSE ); |
---|
284 | WinEnableMenuItem( hWndMenu, CM_LASTPAGE, FALSE ); |
---|
285 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_LASTPAGE), (MPARAM)FALSE ); |
---|
286 | WinEnableMenuItem( hWndMenu, CM_GOTOPAGE, FALSE ); |
---|
287 | |
---|
288 | WinEnableMenuItem( hWndMenu, CM_FITWINDOW, FALSE ); |
---|
289 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_FITWINDOW), (MPARAM)FALSE ); |
---|
290 | WinEnableMenuItem( hWndMenu, CM_ACTSIZE, FALSE ); |
---|
291 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_ACTSIZE), (MPARAM)FALSE ); |
---|
292 | WinEnableMenuItem( hWndMenu, CM_FITWIDTH, FALSE ); |
---|
293 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_FITWIDTH), (MPARAM)FALSE ); |
---|
294 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_ZOOM_IN_OUT), (MPARAM)FALSE ); |
---|
295 | WinEnableMenuItem( hWndMenu, CM_ZOOM_IN, FALSE ); |
---|
296 | WinEnableMenuItem( hWndMenu, CM_ZOOM_OUT, FALSE ); |
---|
297 | WinEnableControl( hToolBar, TBID_ZOOM, FALSE ); |
---|
298 | |
---|
299 | WinEnableMenuItem( hWndMenu, CM_ROTATE90CW, FALSE ); |
---|
300 | WinEnableMenuItem( hWndMenu, CM_ROTATE90CCW, FALSE ); |
---|
301 | WinEnableMenuItem( hWndMenu, CM_SINGLEPAGE, FALSE ); |
---|
302 | WinEnableMenuItem( hWndMenu, CM_CONTINUOUS, FALSE ); |
---|
303 | |
---|
304 | setOfPages( 0 ); |
---|
305 | return; |
---|
306 | } |
---|
307 | |
---|
308 | |
---|
309 | checkNavigationMenus(); |
---|
310 | enableZoomMenus(); |
---|
311 | checkZoomMenus(); |
---|
312 | |
---|
313 | WinEnableMenuItem( hWndMenu, CM_PRINT, TRUE ); |
---|
314 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_PRINT), (MPARAM)TRUE ); |
---|
315 | WinEnableMenuItem( hWndMenu, CM_SAVEAS, doc->isSaveable( ev ) ); |
---|
316 | WinEnableMenuItem( hWndMenu, CM_CLOSE, TRUE ); |
---|
317 | setOfPages( doc->getPageCount( ev ) ); |
---|
318 | WinEnableMenuItem( hWndMenu, CM_FONTSINFO, doc->isHaveFontInfo( ev ) ); |
---|
319 | WinEnableMenuItem( hWndMenu, CM_DOCINFO, TRUE ); |
---|
320 | |
---|
321 | BOOL haveText = doc->isHaveText( ev ); |
---|
322 | WinEnableMenuItem( hWndMenu, CM_FIND, haveText ); |
---|
323 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_FIND), (MPARAM)haveText ); |
---|
324 | WinEnableMenuItem( hWndMenu, CM_SELECTALL, haveText ); |
---|
325 | |
---|
326 | WinEnableMenuItem( hWndMenu, CM_SINGLEPAGE, TRUE ); |
---|
327 | WinEnableMenuItem( hWndMenu, CM_CONTINUOUS, TRUE ); |
---|
328 | } |
---|
329 | |
---|
330 | void Lucide::goToPage( long page ) |
---|
331 | { |
---|
332 | if ( docViewer != NULL ) { |
---|
333 | docViewer->goToPage( page ); |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | void Lucide::setZoom( double zoom ) |
---|
338 | { |
---|
339 | if ( docViewer != NULL ) { |
---|
340 | docViewer->setZoom( zoom ); |
---|
341 | checkZoomMenus(); |
---|
342 | } |
---|
343 | } |
---|
344 | |
---|
345 | void Lucide::setDocument( LuDocument *_doc ) |
---|
346 | { |
---|
347 | docViewer->setDocument( _doc ); |
---|
348 | indexWin->setDocument( _doc ); |
---|
349 | checkMenus( false ); |
---|
350 | } |
---|
351 | |
---|
352 | void Lucide::setPageLayout( PgLayout layout ) |
---|
353 | { |
---|
354 | if ( layout == SinglePage ) { |
---|
355 | WinCheckMenuItem( hWndMenu, CM_SINGLEPAGE, TRUE ); |
---|
356 | WinCheckMenuItem( hWndMenu, CM_CONTINUOUS, FALSE ); |
---|
357 | } |
---|
358 | else { |
---|
359 | WinCheckMenuItem( hWndMenu, CM_SINGLEPAGE, FALSE ); |
---|
360 | WinCheckMenuItem( hWndMenu, CM_CONTINUOUS, TRUE ); |
---|
361 | } |
---|
362 | |
---|
363 | docViewer->setPageLayout( layout ); |
---|
364 | } |
---|
365 | |
---|
366 | |
---|
367 | void Lucide::closeDocument() |
---|
368 | { |
---|
369 | if ( doc != NULL ) { |
---|
370 | docViewer->close(); |
---|
371 | delete doc; |
---|
372 | doc = NULL; |
---|
373 | WinSetWindowText( hWndFrame, title ); |
---|
374 | checkMenus( false ); |
---|
375 | } |
---|
376 | |
---|
377 | if ( thumbnailData != NULL ) { |
---|
378 | writeThumbnail( docFullName ); |
---|
379 | delete thumbnailData; |
---|
380 | thumbnailData = NULL; |
---|
381 | thumbnailDataLen = 0; |
---|
382 | } |
---|
383 | } |
---|
384 | |
---|
385 | void Lucide::loadthread( void* ) |
---|
386 | { |
---|
387 | HAB thab = WinInitialize( 0 ); |
---|
388 | HMQ thmq = WinCreateMsgQueue( thab, 0 ); |
---|
389 | |
---|
390 | docLoaded = doc->loadFile( ev, docFullName, password, &loadErrorCode, &loadError ); |
---|
391 | if ( docLoaded ) { |
---|
392 | if ( doc->isCreateFileThumbnail( ev ) && isThumbNeeded( docFullName ) ) { |
---|
393 | loadProgressDlg->setText( getLocalizedString( MSGS_CREATING_THUMBNAIL ).c_str() ); |
---|
394 | createThumbnail( doc ); |
---|
395 | } |
---|
396 | } |
---|
397 | loadProgressDlg->hide(); |
---|
398 | |
---|
399 | WinDestroyMsgQueue( thmq ); |
---|
400 | WinTerminate( thab ); |
---|
401 | _endthread(); |
---|
402 | } |
---|
403 | |
---|
404 | void Lucide::loadDocument( const char *fn ) |
---|
405 | { |
---|
406 | char *msg = newstrdupL( MSGS_NO_SUIT_PLUG ); |
---|
407 | |
---|
408 | // test if file supported and then close previous opened document |
---|
409 | if ( pluginMan->createDocumentForFile( fn, true ) == NULL ) |
---|
410 | { |
---|
411 | WinMessageBox( HWND_DESKTOP, hWndFrame, msg, |
---|
412 | NULL, 0, MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE ); |
---|
413 | } |
---|
414 | else |
---|
415 | { |
---|
416 | closeDocument(); |
---|
417 | |
---|
418 | doc = pluginMan->createDocumentForFile( fn, false ); |
---|
419 | if ( doc == NULL ) |
---|
420 | { |
---|
421 | WinMessageBox( HWND_DESKTOP, hWndFrame, msg, |
---|
422 | NULL, 0, MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE ); |
---|
423 | } |
---|
424 | else |
---|
425 | { |
---|
426 | _fullpath( docFullName, fn, CCHMAXPATH ); |
---|
427 | |
---|
428 | if ( password != NULL ) { |
---|
429 | delete password; |
---|
430 | password = NULL; |
---|
431 | } |
---|
432 | bool once = true; |
---|
433 | while ( once || ( password != NULL ) ) |
---|
434 | { |
---|
435 | once = false; |
---|
436 | docLoaded = false; |
---|
437 | loadError = NULL; |
---|
438 | |
---|
439 | // Load document asynchronously |
---|
440 | loadProgressDlg = new ProgressDlg( hWndFrame ); |
---|
441 | char *ldmsg = newstrdupL( MSGS_LOADING_DOCUMENT ); |
---|
442 | loadProgressDlg->setText( ldmsg ); |
---|
443 | delete ldmsg; |
---|
444 | loadProgressDlg->show( loadthread, NULL ); // doc will be loaded |
---|
445 | delete loadProgressDlg; |
---|
446 | |
---|
447 | if ( password != NULL ) { |
---|
448 | delete password; |
---|
449 | password = NULL; |
---|
450 | } |
---|
451 | |
---|
452 | if ( docLoaded ) |
---|
453 | { |
---|
454 | char *t = new char[ 2048 ]; |
---|
455 | char _dr[ _MAX_DRIVE ]; |
---|
456 | char _di[ _MAX_DIR ]; |
---|
457 | char _fn[ _MAX_FNAME ]; |
---|
458 | char _ex[ _MAX_EXT ]; |
---|
459 | _splitpath( docFullName, _dr, _di, _fn, _ex ); |
---|
460 | strcpy( docDirName, _dr ); |
---|
461 | strcat( docDirName, _di ); |
---|
462 | strcpy( docFileName, _fn ); |
---|
463 | strcat( docFileName, _ex ); |
---|
464 | snprintf( t, 2048, "%s - %s", docFileName, title ); |
---|
465 | WinSetWindowText( hWndFrame, t ); |
---|
466 | delete t; |
---|
467 | recent->addFile( docFullName ); |
---|
468 | setDocument( doc ); |
---|
469 | } |
---|
470 | else |
---|
471 | { |
---|
472 | if ( loadErrorCode == LU_LDERR_NO_ERROR ) |
---|
473 | { |
---|
474 | char *m = newstrdupL( MSGS_FILE_LOAD_ERROR ); |
---|
475 | WinMessageBox( HWND_DESKTOP, hWndFrame, m, |
---|
476 | NULL, 0, MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE ); |
---|
477 | delete m; |
---|
478 | } |
---|
479 | else |
---|
480 | { |
---|
481 | std::string msgTempl = getLocalizedString( MSGS_LDERR ); |
---|
482 | |
---|
483 | const int errmsgLen = 1024; |
---|
484 | char *errmsg = new char[ errmsgLen ]; |
---|
485 | memset( errmsg, 0, errmsgLen ); |
---|
486 | |
---|
487 | if ( loadErrorCode == LU_LDERR_CUSTOM ) |
---|
488 | { |
---|
489 | snprintf( errmsg, errmsgLen, msgTempl.c_str(), loadError ); |
---|
490 | SOMFree( loadError ); |
---|
491 | } |
---|
492 | else |
---|
493 | { |
---|
494 | const char *lmsg = NULL; |
---|
495 | switch ( loadErrorCode ) |
---|
496 | { |
---|
497 | case LU_LDERR_OUT_OF_MEMORY: |
---|
498 | lmsg = MSGS_LDERR_OUT_OF_MEMORY; |
---|
499 | break; |
---|
500 | case LU_LDERR_OPEN_ERROR: |
---|
501 | lmsg = MSGS_LDERR_OPEN_ERROR; |
---|
502 | break; |
---|
503 | case LU_LDERR_READ_ERROR: |
---|
504 | lmsg = MSGS_LDERR_READ_ERROR; |
---|
505 | break; |
---|
506 | case LU_LDERR_DAMAGED: |
---|
507 | lmsg = MSGS_LDERR_DAMAGED; |
---|
508 | break; |
---|
509 | case LU_LDERR_WRONG_FORMAT: |
---|
510 | lmsg = MSGS_LDERR_WRONG_FORMAT; |
---|
511 | break; |
---|
512 | case LU_LDERR_ENCRYPTED: |
---|
513 | { |
---|
514 | lmsg = MSGS_LDERR_ENCRYPTED; |
---|
515 | |
---|
516 | PasswordDlg *pd = new PasswordDlg( hWndFrame ); |
---|
517 | if ( pd->showDialog() == DID_OK ) { |
---|
518 | password = newstrdup( pd->getPassword() ); |
---|
519 | } |
---|
520 | delete pd; |
---|
521 | } |
---|
522 | break; |
---|
523 | } |
---|
524 | |
---|
525 | if ( lmsg != NULL ) { |
---|
526 | snprintf( errmsg, errmsgLen, msgTempl.c_str(), |
---|
527 | getLocalizedString( lmsg ).c_str() ); |
---|
528 | } |
---|
529 | } |
---|
530 | |
---|
531 | if ( password == NULL ) |
---|
532 | { |
---|
533 | WinMessageBox( HWND_DESKTOP, hWndFrame, errmsg, NULL, 0, |
---|
534 | MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE ); |
---|
535 | } |
---|
536 | delete errmsg; |
---|
537 | } // ( loadErrorCode == LU_LDERR_NO_ERROR ) |
---|
538 | |
---|
539 | if ( password == NULL ) { |
---|
540 | delete doc; |
---|
541 | doc = NULL; |
---|
542 | } |
---|
543 | } // ( docLoaded ) |
---|
544 | } // while ( once || ( password != NULL ) ) |
---|
545 | } // ( doc == NULL ) |
---|
546 | } // ( pluginMan->createDocumentForFile( fn, true ) == NULL ) |
---|
547 | delete msg; |
---|
548 | |
---|
549 | loadFileList(); |
---|
550 | } |
---|
551 | |
---|
552 | void Lucide::readMask( const char *mask ) |
---|
553 | { |
---|
554 | char *buf = new char[ CCHMAXPATH ]; |
---|
555 | strcpy( buf, docFullName ); |
---|
556 | char *r = strrchr( buf, '\\' ); |
---|
557 | if ( r != NULL ) |
---|
558 | { |
---|
559 | *( r + 1 ) = 0; |
---|
560 | strcat( buf, mask ); |
---|
561 | |
---|
562 | struct find_t ffblk; |
---|
563 | unsigned done = _dos_findfirst( buf, _A_RDONLY | _A_NORMAL, &ffblk ); |
---|
564 | while ( done == 0 ) |
---|
565 | { |
---|
566 | fileList.insert( ffblk.name ); |
---|
567 | done = _dos_findnext( &ffblk ); |
---|
568 | } |
---|
569 | _dos_findclose( &ffblk ); |
---|
570 | |
---|
571 | } |
---|
572 | delete buf; |
---|
573 | } |
---|
574 | |
---|
575 | void Lucide::loadFileList() |
---|
576 | { |
---|
577 | fileList.clear(); |
---|
578 | |
---|
579 | char *exts = newstrdup( pluginMan->getExtsMask().c_str() ); |
---|
580 | |
---|
581 | char *p = strtok( exts, ";" ); |
---|
582 | while ( p != NULL ) |
---|
583 | { |
---|
584 | readMask( p ); |
---|
585 | p = strtok( NULL, ";" ); |
---|
586 | } |
---|
587 | delete exts; |
---|
588 | |
---|
589 | fileListIterator = fileList.find( docFileName ); |
---|
590 | } |
---|
591 | |
---|
592 | void Lucide::openDocument() |
---|
593 | { |
---|
594 | PFILEDLG fd = new FILEDLG; |
---|
595 | memset( fd, 0, sizeof( FILEDLG ) ); |
---|
596 | fd->cbSize = sizeof( FILEDLG ); |
---|
597 | fd->fl = FDS_CENTER | FDS_OPEN_DIALOG; |
---|
598 | PrfQueryProfileString( HINI_USERPROFILE, appName, lvd, "", |
---|
599 | fd->szFullFile, sizeof( fd->szFullFile ) ); |
---|
600 | LcdFileDlg( HWND_DESKTOP, hWndFrame, fd ); |
---|
601 | if ( fd->lReturn == DID_OK ) |
---|
602 | { |
---|
603 | char drv[ _MAX_DRIVE ] = ""; |
---|
604 | char dir[ _MAX_PATH ] = ""; |
---|
605 | char buf[ _MAX_PATH ] = ""; |
---|
606 | _splitpath( fd->szFullFile, drv, dir, NULL, NULL ); |
---|
607 | _makepath( buf, drv, dir, NULL, NULL ); |
---|
608 | PrfWriteProfileString( HINI_USERPROFILE, appName, lvd, buf ); |
---|
609 | |
---|
610 | loadDocument( fd->szFullFile ); |
---|
611 | } |
---|
612 | delete fd; |
---|
613 | } |
---|
614 | |
---|
615 | void Lucide::saveDocumentAs() |
---|
616 | { |
---|
617 | char dirbuf[ CCHMAXPATH ]; |
---|
618 | PFILEDLG fd = new FILEDLG; |
---|
619 | memset( fd, 0, sizeof( FILEDLG ) ); |
---|
620 | fd->cbSize = sizeof( FILEDLG ); |
---|
621 | fd->fl = FDS_CENTER | FDS_SAVEAS_DIALOG; |
---|
622 | PrfQueryProfileString( HINI_USERPROFILE, appName, lvd, "", |
---|
623 | dirbuf, sizeof( dirbuf ) ); |
---|
624 | char fil[ _MAX_FNAME ] = ""; |
---|
625 | char ext[ _MAX_EXT ] = ""; |
---|
626 | _splitpath( docFullName, NULL, NULL, fil, ext ); |
---|
627 | snprintf( fd->szFullFile, sizeof( fd->szFullFile ), |
---|
628 | "%s%s%s", dirbuf, fil, ext ); |
---|
629 | WinFileDlg( HWND_DESKTOP, hWndFrame, fd ); |
---|
630 | if ( fd->lReturn == DID_OK ) |
---|
631 | { |
---|
632 | bool doSave = true; |
---|
633 | if ( access( fd->szFullFile, F_OK ) == 0 ) |
---|
634 | { |
---|
635 | char *t = newstrdupL( MSGS_WARNING ); |
---|
636 | char *m = newstrdupL( MSGS_OVERWRITE_FILE ); |
---|
637 | ULONG response = WinMessageBox( HWND_DESKTOP, hWndFrame, m, t, |
---|
638 | 0, MB_YESNO | MB_WARNING | MB_MOVEABLE ); |
---|
639 | delete m; |
---|
640 | delete t; |
---|
641 | |
---|
642 | doSave = ( response == MBID_YES ); |
---|
643 | } |
---|
644 | if ( doSave ) |
---|
645 | { |
---|
646 | if ( !doc->saveAs( ev, fd->szFullFile ) ) |
---|
647 | { |
---|
648 | char *m = newstrdupL( MSGS_FILE_SAVE_ERROR ); |
---|
649 | WinMessageBox( HWND_DESKTOP, hWndFrame, m, NULL, |
---|
650 | 0, MB_OK | MB_ERROR | MB_MOVEABLE ); |
---|
651 | delete m; |
---|
652 | } |
---|
653 | } |
---|
654 | } |
---|
655 | delete fd; |
---|
656 | } |
---|
657 | |
---|
658 | void Lucide::checkNavpane() |
---|
659 | { |
---|
660 | if ( Lucide::showIndex ) { |
---|
661 | WinCheckMenuItem( hWndMenu, CM_NAVPANE, TRUE ); |
---|
662 | WinSendMsg( hToolBar, TBM_SETCHECK, MPFROMSHORT( CM_NAVPANE ), (MPARAM)TRUE ); |
---|
663 | } |
---|
664 | else { |
---|
665 | WinCheckMenuItem( hWndMenu, CM_NAVPANE, FALSE ); |
---|
666 | WinSendMsg( hToolBar, TBM_SETCHECK, MPFROMSHORT( CM_NAVPANE ), (MPARAM)FALSE ); |
---|
667 | } |
---|
668 | } |
---|
669 | |
---|
670 | |
---|
671 | void Lucide::toggleMaxview() |
---|
672 | { |
---|
673 | ULONG ulFrameStyle = WinQueryWindowULong( hWndFrame, QWL_STYLE ); |
---|
674 | |
---|
675 | if ( isMaxview ) |
---|
676 | { |
---|
677 | WinSetParent( hFrameSysmenu, hWndFrame, FALSE ); |
---|
678 | WinSetParent( hFrameTitlebar, hWndFrame, FALSE ); |
---|
679 | WinSetParent( hFrameMinMax, hWndFrame, FALSE ); |
---|
680 | ulFrameStyle |= FS_SIZEBORDER; |
---|
681 | } |
---|
682 | else |
---|
683 | { |
---|
684 | WinQueryWindowPos( hWndFrame, &winPos.Swp ); |
---|
685 | winPos.XRestore = WinQueryWindowUShort( hWndFrame, QWS_XRESTORE ); |
---|
686 | winPos.YRestore = WinQueryWindowUShort( hWndFrame, QWS_YRESTORE ); |
---|
687 | winPos.CXRestore = WinQueryWindowUShort( hWndFrame, QWS_CXRESTORE ); |
---|
688 | winPos.CYRestore = WinQueryWindowUShort( hWndFrame, QWS_CYRESTORE ); |
---|
689 | winPos.XMinimize = WinQueryWindowUShort( hWndFrame, QWS_XMINIMIZE ); |
---|
690 | winPos.YMinimize = WinQueryWindowUShort( hWndFrame, QWS_YMINIMIZE ); |
---|
691 | |
---|
692 | WinSetParent( hFrameSysmenu, HWND_OBJECT, FALSE ); |
---|
693 | WinSetParent( hFrameTitlebar, HWND_OBJECT, FALSE ); |
---|
694 | WinSetParent( hFrameMinMax, HWND_OBJECT, FALSE ); |
---|
695 | ulFrameStyle &= ~FS_SIZEBORDER; |
---|
696 | } |
---|
697 | |
---|
698 | WinSetWindowULong( hWndFrame, QWL_STYLE, ulFrameStyle ); |
---|
699 | WinSendMsg( hWndFrame, WM_UPDATEFRAME, |
---|
700 | MPFROMLONG( FCF_TITLEBAR | FCF_SIZEBORDER | FCF_SYSMENU | FCF_MINMAX ), |
---|
701 | MPVOID ); |
---|
702 | |
---|
703 | if ( isMaxview ) |
---|
704 | { |
---|
705 | WinSetWindowUShort( hWndFrame, QWS_XRESTORE, winPos.XRestore ); |
---|
706 | WinSetWindowUShort( hWndFrame, QWS_YRESTORE, winPos.YRestore ); |
---|
707 | WinSetWindowUShort( hWndFrame, QWS_CXRESTORE, winPos.CXRestore ); |
---|
708 | WinSetWindowUShort( hWndFrame, QWS_CYRESTORE, winPos.CYRestore ); |
---|
709 | WinSetWindowUShort( hWndFrame, QWS_XMINIMIZE, winPos.XMinimize ); |
---|
710 | WinSetWindowUShort( hWndFrame, QWS_YMINIMIZE, winPos.YMinimize ); |
---|
711 | ULONG swpopt = SWP_MOVE | SWP_SIZE | SWP_SHOW; |
---|
712 | WinSetWindowPos( hWndFrame, NULLHANDLE, |
---|
713 | winPos.Swp.x, winPos.Swp.y, winPos.Swp.cx, winPos.Swp.cy, |
---|
714 | swpopt ); |
---|
715 | } |
---|
716 | else |
---|
717 | { |
---|
718 | WinSetWindowPos( hWndFrame, HWND_TOP, 0, 0, |
---|
719 | WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ), |
---|
720 | WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ), |
---|
721 | SWP_SIZE | SWP_MOVE | SWP_ZORDER ); |
---|
722 | } |
---|
723 | |
---|
724 | isMaxview = !isMaxview; |
---|
725 | } |
---|
726 | |
---|
727 | |
---|
728 | void Lucide::toggleFullscreen() |
---|
729 | { |
---|
730 | if ( isFullscreen ) |
---|
731 | { |
---|
732 | docViewer->setFullscreen( false ); |
---|
733 | WinSetParent( docViewer->getFrameHWND(), hWndFrame, TRUE ); |
---|
734 | WinSendMsg( hVertSplitter, SBM_SETWINDOWS, |
---|
735 | MPFROMHWND( indexWin->getHWND() ), |
---|
736 | MPFROMHWND( docViewer->getFrameHWND() ) ); |
---|
737 | } |
---|
738 | else |
---|
739 | { |
---|
740 | docViewer->setFullscreen( true ); |
---|
741 | WinSendMsg( hVertSplitter, SBM_SETWINDOWS, |
---|
742 | MPFROMHWND( indexWin->getHWND() ), |
---|
743 | MPFROMHWND( NULLHANDLE ) ); |
---|
744 | WinSetParent( docViewer->getFrameHWND(), HWND_DESKTOP, FALSE ); |
---|
745 | WinSetWindowPos( docViewer->getFrameHWND(), HWND_TOP, 0, 0, |
---|
746 | WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ), |
---|
747 | WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ), |
---|
748 | SWP_SIZE | SWP_MOVE | SWP_ZORDER ); |
---|
749 | } |
---|
750 | |
---|
751 | isFullscreen = !isFullscreen; |
---|
752 | } |
---|
753 | |
---|
754 | void Lucide::focusDocview() |
---|
755 | { |
---|
756 | WinSetFocus( HWND_DESKTOP, docViewer->getViewHWND() ); |
---|
757 | } |
---|
758 | |
---|
759 | void Lucide::focusIndex() |
---|
760 | { |
---|
761 | WinSetFocus( HWND_DESKTOP, indexWin->getIndexHWND() ); |
---|
762 | } |
---|
763 | |
---|
764 | void Lucide::cmdSwitchWindow() |
---|
765 | { |
---|
766 | if ( activeWindow == AwIndex ) { |
---|
767 | focusDocview(); |
---|
768 | } else { |
---|
769 | focusIndex(); |
---|
770 | } |
---|
771 | } |
---|
772 | |
---|
773 | void Lucide::toggleZoom() |
---|
774 | { |
---|
775 | if ( ( doc != NULL ) && doc->isScalable( ev ) ) |
---|
776 | { |
---|
777 | bool isZoom = !docViewer->isZoomMode(); |
---|
778 | WinSendMsg( hToolBar, TBM_SETCHECK, MPFROMSHORT( CM_ZOOM_IN_OUT ), (MPARAM)isZoom ); |
---|
779 | docViewer->setZoomMode( isZoom ); |
---|
780 | } |
---|
781 | } |
---|
782 | |
---|
783 | void Lucide::cmdMinimize() |
---|
784 | { |
---|
785 | if ( isFullscreen ) { |
---|
786 | toggleFullscreen(); |
---|
787 | } |
---|
788 | WinSetWindowPos( hWndFrame, HWND_TOP, 0, 0, 0, 0, SWP_MINIMIZE ); |
---|
789 | } |
---|
790 | |
---|
791 | void Lucide::cmdSwitchToFullscreen() |
---|
792 | { |
---|
793 | if ( !isFullscreen ) |
---|
794 | { |
---|
795 | SWP pos = {0}; |
---|
796 | WinQueryWindowPos( hWndFrame, &pos ); |
---|
797 | |
---|
798 | if ( pos.fl & SWP_MINIMIZE ) { |
---|
799 | WinSetWindowPos( hWndFrame, HWND_TOP, 0, 0, 0, 0, |
---|
800 | SWP_SHOW | SWP_ACTIVATE | SWP_RESTORE | SWP_ZORDER ); |
---|
801 | } |
---|
802 | toggleFullscreen(); |
---|
803 | } |
---|
804 | } |
---|
805 | |
---|
806 | void Lucide::newWindow( char *file, bool addDir ) |
---|
807 | { |
---|
808 | char *param = NULL; |
---|
809 | |
---|
810 | if ( file != NULL ) |
---|
811 | { |
---|
812 | if ( addDir ) |
---|
813 | { |
---|
814 | param = new char[ CCHMAXPATH ]; |
---|
815 | strcpy( param, docFullName ); |
---|
816 | char *lastSlash = strrchr( param, '\\' ); |
---|
817 | if ( lastSlash != NULL ) { |
---|
818 | *( lastSlash + 1 ) = 0; |
---|
819 | } |
---|
820 | strcat( param, file ); |
---|
821 | } |
---|
822 | else { |
---|
823 | param = newstrdup( file ); |
---|
824 | } |
---|
825 | } |
---|
826 | |
---|
827 | PROGDETAILS pd; |
---|
828 | pd.Length = sizeof( PROGDETAILS ); |
---|
829 | pd.progt.progc = PROG_DEFAULT; |
---|
830 | pd.progt.fbVisible = SHE_VISIBLE; |
---|
831 | pd.pszTitle = NULL; |
---|
832 | pd.pszExecutable = __argv[0]; |
---|
833 | pd.pszParameters = NULL; |
---|
834 | pd.pszStartupDir = NULL; |
---|
835 | pd.pszIcon = NULL; |
---|
836 | pd.pszEnvironment = NULL; |
---|
837 | pd.swpInitial.fl = SWP_ACTIVATE; |
---|
838 | pd.swpInitial.cy = 0; |
---|
839 | pd.swpInitial.cx = 0; |
---|
840 | pd.swpInitial.y = 0; |
---|
841 | pd.swpInitial.x = 0; |
---|
842 | pd.swpInitial.hwndInsertBehind = HWND_TOP; |
---|
843 | pd.swpInitial.hwnd = NULLHANDLE; |
---|
844 | pd.swpInitial.ulReserved1 = 0; |
---|
845 | pd.swpInitial.ulReserved2 = 0; |
---|
846 | |
---|
847 | WinStartApp( NULLHANDLE, &pd, param, NULL, 0 ); |
---|
848 | |
---|
849 | delete param; |
---|
850 | } |
---|
851 | |
---|
852 | void Lucide::gotoFile( FileList file ) |
---|
853 | { |
---|
854 | if ( fileList.size() == 0 ) { |
---|
855 | return; |
---|
856 | } |
---|
857 | |
---|
858 | if ( fileListIterator == fileList.end() ) { |
---|
859 | // If viewed file extension not in supported extensions |
---|
860 | // list - fileListIterator will equal fileList.end() |
---|
861 | fileListIterator = fileList.begin(); |
---|
862 | } |
---|
863 | |
---|
864 | if ( file == ListFirst ) { |
---|
865 | fileListIterator = fileList.begin(); |
---|
866 | } |
---|
867 | else if ( file == ListPrevious ) |
---|
868 | { |
---|
869 | if ( fileListIterator == fileList.begin() ) { |
---|
870 | fileListIterator = fileList.end(); |
---|
871 | } |
---|
872 | fileListIterator--; |
---|
873 | } |
---|
874 | else if ( file == ListNext ) |
---|
875 | { |
---|
876 | fileListIterator++; |
---|
877 | if ( fileListIterator == fileList.end() ) { |
---|
878 | fileListIterator = fileList.begin(); |
---|
879 | } |
---|
880 | } |
---|
881 | else if ( file == ListLast ) { |
---|
882 | fileListIterator = fileList.end(); |
---|
883 | fileListIterator--; |
---|
884 | } |
---|
885 | |
---|
886 | std::string fname = *fileListIterator; |
---|
887 | char *fn = new char[ CCHMAXPATH ]; |
---|
888 | strcpy( fn, docDirName ); |
---|
889 | strcat( fn, fname.c_str() ); |
---|
890 | |
---|
891 | loadDocument( fn ); |
---|
892 | delete fn; |
---|
893 | } |
---|
894 | |
---|
895 | static MRESULT EXPENTRY splProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) |
---|
896 | { |
---|
897 | switch ( msg ) |
---|
898 | { |
---|
899 | case WM_CONTROL: |
---|
900 | { |
---|
901 | if ( ( SHORT1FROMMP( mp1 ) == ID_SPLITTER ) && |
---|
902 | ( SHORT2FROMMP( mp1 ) == SBN_POSITIONCHANGED ) ) |
---|
903 | { |
---|
904 | SHORT pos = SHORT1FROMMP( mp2 ); |
---|
905 | if ( pos > 0 ) { |
---|
906 | Lucide::splitterPos = pos; |
---|
907 | Lucide::showIndex = true; |
---|
908 | } |
---|
909 | else { |
---|
910 | Lucide::showIndex = false; |
---|
911 | } |
---|
912 | Lucide::checkNavpane(); |
---|
913 | } |
---|
914 | } |
---|
915 | break; |
---|
916 | |
---|
917 | case WM_COMMAND: |
---|
918 | { |
---|
919 | switch ( SHORT1FROMMP(mp1) ) |
---|
920 | { |
---|
921 | case CM_NEW_WINDOW: |
---|
922 | Lucide::newWindow( NULL, false ); |
---|
923 | return (MRESULT)FALSE; |
---|
924 | |
---|
925 | case CM_OPEN: |
---|
926 | Lucide::openDocument(); |
---|
927 | return (MRESULT)FALSE; |
---|
928 | |
---|
929 | case CM_FILEFIRST: |
---|
930 | Lucide::gotoFile( ListFirst ); |
---|
931 | return (MRESULT)FALSE; |
---|
932 | |
---|
933 | case CM_FILEPREVIOUS: |
---|
934 | Lucide::gotoFile( ListPrevious ); |
---|
935 | return (MRESULT)FALSE; |
---|
936 | |
---|
937 | case CM_FILENEXT: |
---|
938 | Lucide::gotoFile( ListNext ); |
---|
939 | return (MRESULT)FALSE; |
---|
940 | |
---|
941 | case CM_FILELAST: |
---|
942 | Lucide::gotoFile( ListLast ); |
---|
943 | return (MRESULT)FALSE; |
---|
944 | |
---|
945 | case CM_RECENT + 1: |
---|
946 | case CM_RECENT + 2: |
---|
947 | case CM_RECENT + 3: |
---|
948 | case CM_RECENT + 4: |
---|
949 | case CM_RECENT + 5: |
---|
950 | case CM_RECENT + 6: |
---|
951 | case CM_RECENT + 7: |
---|
952 | case CM_RECENT + 8: |
---|
953 | case CM_RECENT + 9: |
---|
954 | { |
---|
955 | std::string f = recent->getFile( SHORT1FROMMP(mp1) ); |
---|
956 | Lucide::loadDocument( f.c_str() ); |
---|
957 | return (MRESULT)FALSE; |
---|
958 | } |
---|
959 | |
---|
960 | case CM_RECENTCLEAR: |
---|
961 | recent->clear(); |
---|
962 | return (MRESULT)FALSE; |
---|
963 | |
---|
964 | case CM_SAVEAS: |
---|
965 | Lucide::saveDocumentAs(); |
---|
966 | return (MRESULT)FALSE; |
---|
967 | |
---|
968 | case CM_CLOSE: |
---|
969 | Lucide::closeDocument(); |
---|
970 | return (MRESULT)FALSE; |
---|
971 | |
---|
972 | case CM_PRINT: |
---|
973 | { |
---|
974 | PrintDlg *d = new PrintDlg( hWndFrame, doc, Lucide::docFileName, |
---|
975 | docViewer->getCurrentPage() + 1 ); |
---|
976 | if ( d->showDialog() == DID_OK ) |
---|
977 | { |
---|
978 | // print |
---|
979 | PrintSetup *p = new PrintSetup; |
---|
980 | memset( p, 0, sizeof( PrintSetup ) ); |
---|
981 | d->getPrintSetup( p ); |
---|
982 | printDocument( hWndFrame, doc, Lucide::docFileName, p ); |
---|
983 | delete p; |
---|
984 | } |
---|
985 | delete d; |
---|
986 | return (MRESULT)FALSE; |
---|
987 | } |
---|
988 | |
---|
989 | case CM_EXIT: |
---|
990 | WinPostMsg( hWndFrame, WM_CLOSE, NULL, NULL ); |
---|
991 | return (MRESULT)FALSE; |
---|
992 | |
---|
993 | case CM_DOCINFO: |
---|
994 | { |
---|
995 | LuDocumentInfo *dinfo = doc->getDocumentInfo( ev ); |
---|
996 | DocInfoDlg *d = new DocInfoDlg( hWndFrame, dinfo ); |
---|
997 | d->doDialog(); |
---|
998 | LuDocument::freeDocumentInfo( ev, dinfo ); |
---|
999 | return (MRESULT)FALSE; |
---|
1000 | } |
---|
1001 | |
---|
1002 | case CM_FONTSINFO: |
---|
1003 | { |
---|
1004 | FontsInfoDlg *d = new FontsInfoDlg( hWndFrame, doc ); |
---|
1005 | d->doDialog(); |
---|
1006 | return (MRESULT)FALSE; |
---|
1007 | } |
---|
1008 | |
---|
1009 | case CM_PLUGINSLIST: |
---|
1010 | { |
---|
1011 | PluginViewDlg *d = new PluginViewDlg( hWndFrame, |
---|
1012 | pluginMan->getPluginsList() ); |
---|
1013 | d->doDialog(); |
---|
1014 | return (MRESULT)FALSE; |
---|
1015 | } |
---|
1016 | |
---|
1017 | case CM_COPY: |
---|
1018 | docViewer->copyToClipbrd(); |
---|
1019 | return (MRESULT)FALSE; |
---|
1020 | |
---|
1021 | case CM_SELECTALL: |
---|
1022 | docViewer->selectAll(); |
---|
1023 | return (MRESULT)FALSE; |
---|
1024 | |
---|
1025 | case CM_FIND: |
---|
1026 | if ( findDlg->showDialog() == DID_OK ) { |
---|
1027 | if ( strlen( findDlg->getSearchString() ) > 0 ) |
---|
1028 | { |
---|
1029 | docViewer->searchDocument( findDlg->getSearchString(), |
---|
1030 | findDlg->isCaseSensitive(), false ); |
---|
1031 | |
---|
1032 | WinEnableMenuItem( hWndMenu, CM_FINDAGAIN, TRUE ); |
---|
1033 | WinSendMsg( hToolBar, TBM_ENABLEITEM, MPFROMSHORT(CM_FINDAGAIN), (MPARAM)TRUE ); |
---|
1034 | } |
---|
1035 | } |
---|
1036 | return (MRESULT)FALSE; |
---|
1037 | |
---|
1038 | case CM_FINDAGAIN: |
---|
1039 | docViewer->searchDocument( findDlg->getSearchString(), |
---|
1040 | findDlg->isCaseSensitive(), true ); |
---|
1041 | return (MRESULT)FALSE; |
---|
1042 | |
---|
1043 | case CM_SETTINGS: |
---|
1044 | { |
---|
1045 | SettingsDlg *d = new SettingsDlg( hWndFrame, settings ); |
---|
1046 | d->doDialog(); |
---|
1047 | return (MRESULT)FALSE; |
---|
1048 | } |
---|
1049 | |
---|
1050 | case CM_FIRSTPAGE: |
---|
1051 | Lucide::goToPage( 0 ); |
---|
1052 | return (MRESULT)FALSE; |
---|
1053 | |
---|
1054 | case CM_NEXTPAGE: |
---|
1055 | Lucide::goToPage( docViewer->getCurrentPage() + 1 ); |
---|
1056 | return (MRESULT)FALSE; |
---|
1057 | |
---|
1058 | case CM_PREVPAGE: |
---|
1059 | Lucide::goToPage( docViewer->getCurrentPage() - 1 ); |
---|
1060 | return (MRESULT)FALSE; |
---|
1061 | |
---|
1062 | case CM_LASTPAGE: |
---|
1063 | Lucide::goToPage( doc->getPageCount( ev ) - 1 ); |
---|
1064 | return (MRESULT)FALSE; |
---|
1065 | |
---|
1066 | case CM_GOTOPAGE: |
---|
1067 | { |
---|
1068 | GotoDlg *d = new GotoDlg( hWndFrame, doc->getPageCount( ev ), |
---|
1069 | docViewer->getCurrentPage() + 1 ); |
---|
1070 | if ( d->showDialog() == DID_OK ) { |
---|
1071 | long pg = d->getPage(); |
---|
1072 | if ( pg > 0 ) { |
---|
1073 | Lucide::goToPage( pg - 1 ); |
---|
1074 | } |
---|
1075 | } |
---|
1076 | delete d; |
---|
1077 | return (MRESULT)FALSE; |
---|
1078 | } |
---|
1079 | |
---|
1080 | case CM_FITWINDOW: |
---|
1081 | Lucide::setZoom( -2 ); |
---|
1082 | return (MRESULT)FALSE; |
---|
1083 | |
---|
1084 | case CM_ACTSIZE: |
---|
1085 | Lucide::setZoom( 1 ); |
---|
1086 | return (MRESULT)FALSE; |
---|
1087 | |
---|
1088 | case CM_FITWIDTH: |
---|
1089 | Lucide::setZoom( -1 ); |
---|
1090 | return (MRESULT)FALSE; |
---|
1091 | |
---|
1092 | case CM_ZOOM_IN_OUT: |
---|
1093 | Lucide::toggleZoom(); |
---|
1094 | return (MRESULT)FALSE; |
---|
1095 | |
---|
1096 | case CM_ZOOM_IN: |
---|
1097 | docViewer->zoomInOut( true ); |
---|
1098 | return (MRESULT)FALSE; |
---|
1099 | |
---|
1100 | case CM_ZOOM_OUT: |
---|
1101 | docViewer->zoomInOut( false ); |
---|
1102 | return (MRESULT)FALSE; |
---|
1103 | |
---|
1104 | case CM_SINGLEPAGE: |
---|
1105 | Lucide::setPageLayout( SinglePage ); |
---|
1106 | return (MRESULT)FALSE; |
---|
1107 | |
---|
1108 | case CM_CONTINUOUS: |
---|
1109 | Lucide::setPageLayout( Continuous ); |
---|
1110 | return (MRESULT)FALSE; |
---|
1111 | |
---|
1112 | case CM_ROTATE90CW: |
---|
1113 | docViewer->setRotation( docViewer->getRotation() + 90 ); |
---|
1114 | return (MRESULT)FALSE; |
---|
1115 | |
---|
1116 | case CM_ROTATE90CCW: |
---|
1117 | docViewer->setRotation( docViewer->getRotation() - 90 ); |
---|
1118 | return (MRESULT)FALSE; |
---|
1119 | |
---|
1120 | case CM_NAVPANE: |
---|
1121 | { |
---|
1122 | Lucide::showIndex = !Lucide::showIndex; |
---|
1123 | Lucide::checkNavpane(); |
---|
1124 | WinSendMsg( hVertSplitter, SBM_SETSPLITTERPOS, |
---|
1125 | MPFROMSHORT( Lucide::showIndex ? Lucide::splitterPos : 0 ), MPVOID ); |
---|
1126 | if ( !Lucide::showIndex ) { |
---|
1127 | Lucide::focusDocview(); |
---|
1128 | } |
---|
1129 | } |
---|
1130 | return (MRESULT)FALSE; |
---|
1131 | |
---|
1132 | case CM_MAXVIEW: |
---|
1133 | Lucide::toggleMaxview(); |
---|
1134 | return (MRESULT)FALSE; |
---|
1135 | |
---|
1136 | case CM_FULLSCREEN: |
---|
1137 | Lucide::toggleFullscreen(); |
---|
1138 | return (MRESULT)FALSE; |
---|
1139 | |
---|
1140 | case CM_PRODINFO: |
---|
1141 | AboutBox( hWndFrame ); |
---|
1142 | return (MRESULT)FALSE; |
---|
1143 | |
---|
1144 | case CM_MINIMIZE: |
---|
1145 | Lucide::cmdMinimize(); |
---|
1146 | return (MRESULT)FALSE; |
---|
1147 | |
---|
1148 | case CM_TOFULLSCREEN: |
---|
1149 | Lucide::cmdSwitchToFullscreen(); |
---|
1150 | return (MRESULT)FALSE; |
---|
1151 | |
---|
1152 | case CM_SWITCHWINDOW: |
---|
1153 | Lucide::cmdSwitchWindow(); |
---|
1154 | return (MRESULT)FALSE; |
---|
1155 | } |
---|
1156 | } |
---|
1157 | break; |
---|
1158 | } |
---|
1159 | return pOldSplProc( hwnd, msg, mp1, mp2 ); |
---|
1160 | } |
---|
1161 | |
---|
1162 | |
---|
1163 | char deffont[] = "9.WarpSans"; |
---|
1164 | int deffontlen = sizeof( deffont ); |
---|
1165 | |
---|
1166 | extern "C" APIRET APIENTRY LucideMain( int argc, char *argv[] ) |
---|
1167 | { |
---|
1168 | HMQ hmq; |
---|
1169 | QMSG qmsg; |
---|
1170 | hab = WinInitialize( 0 ); |
---|
1171 | hmq = WinCreateMsgQueue( hab, 0 ); |
---|
1172 | |
---|
1173 | loadLang(); |
---|
1174 | |
---|
1175 | settings = new LuSettings; |
---|
1176 | settings->load(); |
---|
1177 | |
---|
1178 | pluginMan = new PluginManager; |
---|
1179 | |
---|
1180 | InitPMSplitterClass( hab ); |
---|
1181 | InitPMToolbarClass( hab ); |
---|
1182 | |
---|
1183 | ULONG ulFrameFlags = FCF_TITLEBAR | FCF_SIZEBORDER | FCF_SYSMENU | |
---|
1184 | FCF_MINMAX | FCF_TASKLIST | FCF_NOBYTEALIGN | FCF_ICON; |
---|
1185 | title = newstrdupL( MSGS_MAIN_WIN_TITLE ); |
---|
1186 | hWndFrame = WinCreateStdWindow( HWND_DESKTOP, 0, &ulFrameFlags, NULL, title, |
---|
1187 | WS_SYNCPAINT|WS_VISIBLE, _hmod, IDI_MAIN_ICON, NULL ); |
---|
1188 | hFrameSysmenu = WinWindowFromID( hWndFrame, FID_SYSMENU ); |
---|
1189 | hFrameTitlebar = WinWindowFromID( hWndFrame, FID_TITLEBAR ); |
---|
1190 | hFrameMinMax = WinWindowFromID( hWndFrame, FID_MINMAX ); |
---|
1191 | WinSetAccelTable( hab, WinLoadAccelTable( hab, _hmod, IDA_MAINACCEL ), hWndFrame ); |
---|
1192 | hWndMenu = WinLoadMenu( hWndFrame, _hmod, IDM_MAINMENU ); |
---|
1193 | localizeMenu( hWndMenu ); |
---|
1194 | WinSetWindowUShort( hWndMenu, QWS_ID, FID_MENU ); |
---|
1195 | |
---|
1196 | // Vertical splitter and his windows - Index and Document view |
---|
1197 | hVertSplitter = WinCreateWindow( hWndFrame, WC_ER_SPLITTER, "", |
---|
1198 | WS_VISIBLE | SBS_VSPLIT, |
---|
1199 | 0, 0, 0, 0, hWndFrame, HWND_TOP, |
---|
1200 | ID_SPLITTER, NULL, NULL ); |
---|
1201 | |
---|
1202 | indexWin = new IndexWindow( hWndFrame ); |
---|
1203 | |
---|
1204 | DocumentViewer::registerClass(); |
---|
1205 | |
---|
1206 | docViewer = new DocumentViewer( hWndFrame ); |
---|
1207 | |
---|
1208 | WinSendMsg( hVertSplitter, SBM_SETWINDOWS, |
---|
1209 | MPFROMHWND( indexWin->getHWND() ), MPFROMHWND( docViewer->getFrameHWND() ) ); |
---|
1210 | Lucide::splitterPos = PrfQueryProfileInt( HINI_USERPROFILE, appName, splpos, Lucide::splitterPos ); |
---|
1211 | Lucide::showIndex = PrfQueryProfileInt( HINI_USERPROFILE, appName, showind, Lucide::showIndex ); |
---|
1212 | WinSendMsg( hVertSplitter, SBM_SETSPLITTERPOS, |
---|
1213 | MPFROMSHORT( Lucide::showIndex ? Lucide::splitterPos : 0 ), MPVOID ); |
---|
1214 | |
---|
1215 | // Horizontal splitter and its windows - Toolbar and Vertical splitter |
---|
1216 | // Horizontal splitter is client window |
---|
1217 | HWND hHorizSplitter = WinCreateWindow( hWndFrame, WC_ER_SPLITTER, "", |
---|
1218 | WS_VISIBLE | SBS_HSPLIT | SBS_SECONDFIXED, |
---|
1219 | 0, 0, 0, 0, hWndFrame, HWND_TOP, |
---|
1220 | FID_CLIENT, NULL, NULL ); |
---|
1221 | pOldSplProc = WinSubclassWindow( hHorizSplitter, splProc ); |
---|
1222 | |
---|
1223 | hToolBar = createToolbar( hWndFrame ); |
---|
1224 | |
---|
1225 | WinSendMsg( hHorizSplitter, SBM_SETWINDOWS, |
---|
1226 | MPFROMHWND( hVertSplitter ), MPFROMHWND( hToolBar ) ); |
---|
1227 | // ãáâ ®¢šâì 䚪ášà®¢ ë© à §¬¥à €«ï âã«¡ à |
---|
1228 | WinSendMsg( hHorizSplitter, SBM_SETFIXEDSIZE, |
---|
1229 | MPFROMSHORT( DEFAULT_PICTSIZE + TOOLBAR_HEIGHT_ADD ), MPVOID ); |
---|
1230 | |
---|
1231 | Lucide::checkMenus( true ); |
---|
1232 | Lucide::setPageLayout( settings->layout ); |
---|
1233 | Lucide::setZoom( settings->zoom ); |
---|
1234 | |
---|
1235 | findDlg = new FindDlg( hWndFrame ); |
---|
1236 | recent = new RecentFiles( hWndMenu ); |
---|
1237 | |
---|
1238 | // ®ª § âì ®ª® ¯à®£à ¬¬ë |
---|
1239 | if ( !PMRestoreWindowPos( NULL, appName, fwp, hWndFrame, |
---|
1240 | TRUE, TRUE, FALSE, FALSE, FALSE ) ) { |
---|
1241 | WinSetWindowPos( hWndFrame, HWND_TOP, 100, 100, 630, 400, |
---|
1242 | SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ACTIVATE ); |
---|
1243 | } |
---|
1244 | |
---|
1245 | Lucide::focusDocview(); |
---|
1246 | |
---|
1247 | if ( argc > 1 ) { |
---|
1248 | Lucide::loadDocument( argv[1] ); |
---|
1249 | } |
---|
1250 | |
---|
1251 | Lucide::checkNavpane(); |
---|
1252 | initPipeMon( hWndFrame ); |
---|
1253 | |
---|
1254 | // Messsage loop |
---|
1255 | while ( WinGetMsg( hab, &qmsg, 0, 0, 0 ) ) { |
---|
1256 | WinDispatchMsg( hab, &qmsg ); |
---|
1257 | } |
---|
1258 | |
---|
1259 | if ( WinIsWindow( hab, hWndFrame ) ) |
---|
1260 | { |
---|
1261 | char valbuf[ 3 ] = ""; |
---|
1262 | PrfWriteProfileString( HINI_USERPROFILE, appName, splpos, |
---|
1263 | itoa( Lucide::splitterPos, valbuf, 10 ) ); |
---|
1264 | PrfWriteProfileString( HINI_USERPROFILE, appName, showind, |
---|
1265 | itoa( Lucide::showIndex, valbuf, 10 ) ); |
---|
1266 | PMStoreWindowPos( NULL, appName, fwp, hWndFrame ); |
---|
1267 | } |
---|
1268 | |
---|
1269 | WinDestroyWindow( hWndFrame ); |
---|
1270 | |
---|
1271 | recent->save(); |
---|
1272 | |
---|
1273 | Lucide::closeDocument(); |
---|
1274 | delete docViewer; |
---|
1275 | delete indexWin; |
---|
1276 | |
---|
1277 | // must be freed _after_ document |
---|
1278 | delete pluginMan; |
---|
1279 | |
---|
1280 | delete findDlg; |
---|
1281 | delete recent; |
---|
1282 | delete title; |
---|
1283 | delete settings; |
---|
1284 | unInitPipeMon(); |
---|
1285 | |
---|
1286 | WinDestroyMsgQueue( hmq ); |
---|
1287 | WinTerminate( hab ); |
---|
1288 | return 0; |
---|
1289 | } |
---|
1290 | |
---|