1 /************************************************************************/
2 /* Ted: interaction with the page layout tool. */
3 /************************************************************************/
4
5 # include "tedConfig.h"
6
7 # include "tedApp.h"
8 # include "tedSelect.h"
9 # include "tedAppResources.h"
10 # include "tedLayout.h"
11 # include "tedDocument.h"
12 # include <docScreenLayout.h>
13 # include <guiWidgetDrawingSurface.h>
14 # include <guiDrawingWidget.h>
15 # include <docTreeNode.h>
16
17 # include <appDebugon.h>
18
19 /************************************************************************/
20 /* */
21 /* Reformat and redisplay the document because of a major format */
22 /* change. etc. */
23 /* */
24 /************************************************************************/
25
tedRedoDocumentLayout(EditDocument * ed)26 void tedRedoDocumentLayout( EditDocument * ed )
27 {
28 TedDocument * td= (TedDocument *)ed->edPrivateData;
29 BufferDocument * bd= td->tdDocument;
30
31 int hasSelection= tedHasSelection( ed );
32 int reachedBottom= 0;
33
34 LayoutContext lc;
35
36 layoutInitContext( &lc );
37 tedSetScreenLayoutContext( &lc, ed );
38
39 tedLayoutDocumentBody( &reachedBottom, &lc );
40
41 if ( tedOpenTreeObjects( &(bd->bdBody), &lc ) )
42 { LDEB(1); }
43
44 if ( reachedBottom )
45 {
46 BufferItem * rootNode= bd->bdBody.dtRoot;
47
48 docGetPixelRectangleForPages( &(ed->edFullRect), &lc,
49 rootNode->biTopPosition.lpPage,
50 rootNode->biBelowPosition.lpPage );
51 }
52
53 if ( hasSelection )
54 { tedDelimitCurrentSelection( ed ); }
55
56 appDocSetScrollbarValues( ed );
57
58 if ( hasSelection )
59 {
60 DocumentSelection ds;
61 SelectionGeometry sg;
62 SelectionDescription sd;
63 BufferItem * bodySectNode;
64
65 if ( tedGetSelection( &ds, &sg, &sd,
66 (DocumentTree **)0, &bodySectNode, ed ) )
67 { LDEB(1); return; }
68
69 tedDocAdaptTopRuler( ed, &ds, &sg, &sd, bodySectNode );
70
71 tedScrollToSelection( ed, (int *)0, (int *)0 );
72
73 tedDescribeSelection( ed );
74
75 if ( td->tdSelectionDescription.sdIsObjectSelection )
76 { tedMoveObjectWindows( ed ); }
77 }
78
79 guiExposeDrawingWidget( ed->edDocumentWidget.dwWidget );
80
81 return;
82 }
83
84 /************************************************************************/
85 /* */
86 /* Adapt the page tool to a document. */
87 /* */
88 /************************************************************************/
89
tedAdaptPageToolToDocument(EditApplication * ea,EditDocument * ed)90 void tedAdaptPageToolToDocument( EditApplication * ea,
91 EditDocument * ed )
92 {
93 TedDocument * td;
94 BufferDocument * bd;
95 DocumentProperties * dp;
96
97 if ( ! ea->eaPageTool )
98 { return; }
99
100 td= (TedDocument *)ed->edPrivateData;
101 bd= td->tdDocument;
102 dp= &(bd->bdProperties);
103
104 appPageToolSetProperties( ea->eaPageTool, &(dp->dpGeometry) );
105
106 appEnablePageTool( ea->eaPageTool, ! ed->edIsReadonly );
107
108 return;
109 }
110
111 /************************************************************************/
112 /* */
113 /* (re)Calculate the layout of a whole document. */
114 /* */
115 /************************************************************************/
116
tedLayoutDocumentBody(int * pReachedBottom,const LayoutContext * lc)117 int tedLayoutDocumentBody( int * pReachedBottom,
118 const LayoutContext * lc )
119 {
120 return docScreenLayoutDocumentBody( pReachedBottom, lc->lcDocument, lc );
121 }
122
123 /************************************************************************/
124 /* */
125 /* Get a suggestion about the line height: Used for the initial value */
126 /* for space before/after in the format tool. */
127 /* */
128 /************************************************************************/
129
tedGetParaLineHeight(int * pLineHeight,EditDocument * ed)130 int tedGetParaLineHeight( int * pLineHeight,
131 EditDocument * ed )
132 {
133 DocumentSelection ds;
134 SelectionGeometry sg;
135 SelectionDescription sd;
136 int fontSize= 0;
137
138 LayoutContext lc;
139
140 layoutInitContext( &lc );
141 tedSetScreenLayoutContext( &lc, ed );
142
143 if ( tedGetSelection( &ds, &sg, &sd,
144 (DocumentTree **)0, (BufferItem **)0, ed ) )
145 { LDEB(1); return -1; }
146
147 if ( docLayoutParagraphLineExtents( &fontSize, &lc, ds.dsHead.dpNode ) )
148 { LDEB(1); return -1; }
149
150 *pLineHeight= fontSize;
151 return 0;
152 }
153
154