Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <ElementsDockingWindow.hxx>
21 :
22 : #include <starmath.hrc>
23 : #include <smmod.hxx>
24 : #include <config.hxx>
25 : #include <view.hxx>
26 : #include <visitors.hxx>
27 :
28 : #include <svl/stritem.hxx>
29 : #include <sfx2/dispatch.hxx>
30 : #include <vcl/settings.hxx>
31 :
32 : typedef tools::SvRef<SmDocShell> SmDocShellRef;
33 :
34 680 : SmElement::SmElement(SmNodePointer pNode, const OUString& aText, const OUString& aHelpText) :
35 : mpNode(pNode),
36 : maText(aText),
37 680 : maHelpText(aHelpText)
38 680 : {}
39 :
40 1292 : SmElement::~SmElement()
41 1292 : {}
42 :
43 918 : SmNodePointer SmElement::getNode()
44 : {
45 918 : return mpNode;
46 : }
47 :
48 68 : SmElementSeparator::SmElementSeparator() :
49 68 : SmElement(SmNodePointer(), OUString(), OUString())
50 68 : {}
51 :
52 : const sal_uInt16 SmElementsControl::aUnaryBinaryOperatorsList[][2] =
53 : {
54 : {RID_PLUSX, RID_PLUSX_HELP}, {RID_MINUSX, RID_MINUSX_HELP},
55 : {RID_PLUSMINUSX, RID_PLUSMINUSX_HELP}, {RID_MINUSPLUSX, RID_MINUSPLUSX_HELP},
56 : {0xFFFF, 0},
57 : {RID_XPLUSY, RID_XPLUSY_HELP}, {RID_XMINUSY, RID_XMINUSY_HELP},
58 : {RID_XCDOTY, RID_XCDOTY_HELP}, {RID_XTIMESY, RID_XTIMESY_HELP},
59 : {RID_XSYMTIMESY, RID_XSYMTIMESY_HELP}, {RID_XOVERY, RID_XOVERY_HELP},
60 : {RID_XDIVY, RID_XDIVY_HELP}, {RID_XSYMDIVIDEY, RID_XSYMDIVIDEY_HELP},
61 : {RID_XCIRCY, RID_XCIRCY_HELP}, {RID_XWIDESLASHY, RID_XWIDESLASHY_HELP},
62 : {RID_XWIDEBSLASHY, RID_XWIDEBSLASHY_HELP},
63 : {0xFFFF, 0},
64 : {RID_NEGX, RID_NEGX_HELP}, {RID_XANDY, RID_XANDY_HELP}, {RID_XORY, RID_XORY_HELP},
65 : };
66 :
67 : const sal_uInt16 SmElementsControl::aRelationsList[][2] =
68 : {
69 : {RID_XEQY, RID_XEQY_HELP}, {RID_XNEQY, RID_XNEQY_HELP}, {RID_XLTY, RID_XLTY_HELP},
70 : {RID_XLEY, RID_XLEY_HELP}, {RID_XLESLANTY, RID_XLESLANTY_HELP}, {RID_XGTY, RID_XGTY_HELP},
71 : {RID_XGEY, RID_XGEY_HELP}, {RID_XGESLANTY, RID_XGESLANTY_HELP},
72 : {RID_XLLY, RID_XLLY_HELP}, {RID_XGGY, RID_XGGY_HELP},
73 : {0xFFFF, 0},
74 : {RID_XAPPROXY, RID_XAPPROXY_HELP}, {RID_XSIMY, RID_XSIMY_HELP}, {RID_XSIMEQY, RID_XSIMEQY_HELP},
75 : {RID_XEQUIVY, RID_XEQUIVY_HELP}, {RID_XPROPY, RID_XPROPY_HELP}, {RID_XPARALLELY, RID_XPARALLELY_HELP},
76 : {RID_XORTHOY, RID_XORTHOY_HELP}, {RID_XDIVIDESY, RID_XDIVIDESY_HELP}, {RID_XNDIVIDESY, RID_XNDIVIDESY_HELP},
77 : {RID_XTOWARDY, RID_XTOWARDY_HELP},
78 : {0xFFFF, 0},
79 : {RID_DLARROW, RID_DLARROW_HELP}, {RID_DLRARROW, RID_DLRARROW_HELP}, {RID_DRARROW, RID_DRARROW_HELP},
80 : {0xFFFF, 0},
81 : {RID_XPRECEDESY, RID_XPRECEDESY_HELP}, {RID_XSUCCEEDSY, RID_XSUCCEEDSY_HELP},
82 : {RID_XPRECEDESEQUALY, RID_XPRECEDESEQUALY_HELP}, {RID_XSUCCEEDSEQUALY, RID_XSUCCEEDSEQUALY_HELP},
83 : {RID_XPRECEDESEQUIVY, RID_XPRECEDESEQUIVY_HELP}, {RID_XSUCCEEDSEQUIVY, RID_XSUCCEEDSEQUIVY_HELP},
84 : {RID_XNOTPRECEDESY, RID_XNOTPRECEDESY_HELP}, {RID_XNOTSUCCEEDSY, RID_XNOTSUCCEEDSY_HELP},
85 : };
86 :
87 : const sal_uInt16 SmElementsControl::aSetOperations[][2] =
88 : {
89 : {RID_XINY, RID_XINY_HELP}, {RID_XNOTINY, RID_XNOTINY_HELP}, {RID_XOWNSY, RID_XOWNSY_HELP},
90 : {0xFFFF, 0},
91 : {RID_XINTERSECTIONY, RID_XINTERSECTIONY_HELP}, {RID_XUNIONY, RID_XUNIONY_HELP},
92 : {RID_XSETMINUSY, RID_XSETMINUSY_HELP}, {RID_XSLASHY, RID_XSLASHY_HELP},
93 : {RID_XSUBSETY, RID_XSUBSETY_HELP}, {RID_XSUBSETEQY, RID_XSUBSETEQY_HELP},
94 : {RID_XSUPSETY, RID_XSUPSETY_HELP}, {RID_XSUPSETEQY, RID_XSUPSETEQY_HELP},
95 : {RID_XNSUBSETY, RID_XNSUBSETY_HELP}, {RID_XNSUBSETEQY, RID_XNSUBSETEQY_HELP},
96 : {RID_XNSUPSETY, RID_XNSUPSETY_HELP}, {RID_XNSUPSETEQY, RID_XNSUPSETEQY_HELP},
97 : {0xFFFF, 0},
98 : {RID_EMPTYSET, RID_EMPTYSET_HELP}, {RID_ALEPH, RID_ALEPH_HELP}, {RID_SETN, RID_SETN_HELP},
99 : {RID_SETZ, RID_SETZ_HELP}, {RID_SETQ, RID_SETQ_HELP}, {RID_SETR, RID_SETR_HELP}, {RID_SETC, RID_SETC_HELP}
100 : };
101 :
102 : const sal_uInt16 SmElementsControl::aFunctions[][2] =
103 : {
104 : {RID_ABSX, RID_ABSX_HELP}, {RID_FACTX, RID_FACTX_HELP}, {RID_SQRTX, RID_SQRTX_HELP},
105 : {RID_NROOTXY, RID_NROOTXY_HELP}, {RID_RSUPX, RID_RSUPX_HELP}, {RID_EX, RID_EX_HELP},
106 : {RID_LNX, RID_LNX_HELP}, {RID_EXPX, RID_EXPX_HELP}, {RID_LOGX, RID_LOGX_HELP},
107 : {0xFFFF, 0},
108 : {RID_SINX, RID_SINX_HELP}, {RID_COSX, RID_COSX_HELP}, {RID_TANX, RID_TANX_HELP}, {RID_COTX, RID_COTX_HELP},
109 : {RID_SINHX, RID_SINHX_HELP}, {RID_COSHX, RID_COSHX_HELP}, {RID_TANHX, RID_TANHX_HELP},
110 : {RID_COTHX, RID_COTHX_HELP},
111 : {0xFFFF, 0},
112 : {RID_ARCSINX, RID_ARCSINX_HELP}, {RID_ARCCOSX, RID_ARCCOSX_HELP}, {RID_ARCTANX, RID_ARCTANX_HELP},
113 : {RID_ARCCOTX, RID_ARCCOTX_HELP}, {RID_ARSINHX, RID_ARSINHX_HELP}, {RID_ARCOSHX, RID_ARCOSHX_HELP},
114 : {RID_ARTANHX, RID_ARTANHX_HELP}, {RID_ARCOTHX, RID_ARCOTHX_HELP}
115 : };
116 :
117 : const sal_uInt16 SmElementsControl::aOperators[][2] =
118 : {
119 : {RID_LIMX, RID_LIMX_HELP}, {RID_LIM_FROMX, RID_LIM_FROMX_HELP},
120 : {RID_LIM_TOX, RID_LIM_TOX_HELP}, {RID_LIM_FROMTOX, RID_LIM_FROMTOX_HELP},
121 : {0xFFFF, 0},
122 : {RID_SUMX, RID_SUMX_HELP}, {RID_SUM_FROMX, RID_SUM_FROMX_HELP},
123 : {RID_SUM_TOX, RID_SUM_TOX_HELP}, {RID_SUM_FROMTOX, RID_SUM_FROMTOX_HELP},
124 : {0xFFFF, 0},
125 : {RID_PRODX, RID_PRODX_HELP}, {RID_PROD_FROMX, RID_PROD_FROMX_HELP},
126 : {RID_PROD_TOX, RID_PROD_TOX_HELP}, {RID_PROD_FROMTOX, RID_PROD_FROMTOX_HELP},
127 : {0xFFFF, 0},
128 : {RID_COPRODX, RID_COPRODX_HELP}, {RID_COPROD_FROMX, RID_COPROD_FROMX_HELP},
129 : {RID_COPROD_TOX, RID_COPROD_TOX_HELP}, {RID_COPROD_FROMTOX, RID_COPROD_FROMTOX_HELP},
130 : {0xFFFF, 0},
131 : {RID_INTX, RID_INTX_HELP}, {RID_INT_FROMX, RID_INT_FROMX_HELP},
132 : {RID_INT_TOX, RID_INT_TOX_HELP}, {RID_INT_FROMTOX, RID_INT_FROMTOX_HELP},
133 : {0xFFFF, 0},
134 : {RID_IINTX, RID_IINTX_HELP}, {RID_IINT_FROMX, RID_IINT_FROMX_HELP},
135 : {RID_IINT_TOX, RID_IINT_TOX_HELP}, {RID_IINT_FROMTOX, RID_IINT_FROMTOX_HELP},
136 : {0xFFFF, 0},
137 : {RID_IIINTX, RID_IIINTX_HELP}, {RID_IIINT_FROMX, RID_IIINT_FROMX_HELP},
138 : {RID_IIINT_TOX, RID_IIINT_TOX_HELP}, {RID_IIINT_FROMTOX, RID_IIINT_FROMTOX_HELP},
139 : {0xFFFF, 0},
140 : {RID_LINTX, RID_LINTX_HELP}, {RID_LINT_FROMX, RID_LINT_FROMX_HELP},
141 : {RID_LINT_TOX, RID_LINT_TOX_HELP}, {RID_LINT_FROMTOX, RID_LINT_FROMTOX_HELP},
142 : {0xFFFF, 0},
143 : {RID_LLINTX, RID_LINTX_HELP}, {RID_LLINT_FROMX, RID_LLINT_FROMX_HELP},
144 : {RID_LLINT_TOX, RID_LINT_TOX_HELP}, {RID_LLINT_FROMTOX, RID_LLINT_FROMTOX_HELP},
145 : {0xFFFF, 0},
146 : {RID_LLLINTX, RID_LINTX_HELP}, {RID_LLLINT_FROMX, RID_LLLINT_FROMX_HELP},
147 : {RID_LLLINT_TOX, RID_LINT_TOX_HELP}, {RID_LLLINT_FROMTOX, RID_LLLINT_FROMTOX_HELP},
148 : };
149 :
150 : const sal_uInt16 SmElementsControl::aAttributes[][2] =
151 : {
152 : {RID_ACUTEX, RID_ACUTEX_HELP}, {RID_GRAVEX, RID_GRAVEX_HELP}, {RID_BREVEX, RID_BREVEX_HELP},
153 : {RID_CIRCLEX, RID_CIRCLEX_HELP}, {RID_DOTX, RID_DOTX_HELP}, {RID_DDOTX, RID_DDOTX_HELP},
154 : {RID_DDDOTX, RID_DDDOTX_HELP}, {RID_BARX, RID_BARX_HELP}, {RID_VECX, RID_VECX_HELP},
155 : {RID_TILDEX, RID_TILDEX_HELP}, {RID_HATX, RID_HATX_HELP}, {RID_CHECKX, RID_CHECKX_HELP},
156 : {0xFFFF, 0},
157 : {RID_WIDEVECX, RID_WIDEVECX_HELP}, {RID_WIDETILDEX, RID_WIDETILDEX_HELP}, {RID_WIDEHATX, RID_WIDEHATX_HELP},
158 : {RID_OVERLINEX, RID_OVERLINEX_HELP}, {RID_UNDERLINEX, RID_UNDERLINEX_HELP}, {RID_OVERSTRIKEX, RID_OVERSTRIKEX_HELP},
159 : {0xFFFF, 0},
160 : {RID_PHANTOMX, RID_PHANTOMX_HELP}, {RID_BOLDX, RID_BOLDX_HELP}, {RID_ITALX, RID_ITALX_HELP},
161 : {RID_SIZEXY, RID_SIZEXY_HELP}, {RID_FONTXY, RID_FONTXY_HELP},
162 : {0xFFFF, 0},
163 : {RID_COLORX_BLACK, RID_COLORX_BLACK_HELP}, {RID_COLORX_BLUE, RID_COLORX_BLUE_HELP},
164 : {RID_COLORX_GREEN, RID_COLORX_GREEN_HELP}, {RID_COLORX_RED, RID_COLORX_RED_HELP},
165 : {RID_COLORX_CYAN, RID_COLORX_CYAN_HELP}, {RID_COLORX_MAGENTA, RID_COLORX_MAGENTA_HELP},
166 : {RID_COLORX_YELLOW, RID_COLORX_YELLOW_HELP}
167 : };
168 :
169 : const sal_uInt16 SmElementsControl::aBrackets[][2] =
170 : {
171 : {RID_LRGROUPX, RID_LRGROUPX_HELP},
172 : {0xFFFF, 0},
173 : {RID_LRPARENTX, RID_LRPARENTX_HELP}, {RID_LRBRACKETX, RID_LRBRACKETX_HELP},
174 : {RID_LRDBRACKETX, RID_LRDBRACKETX_HELP}, {RID_LRBRACEX, RID_LRBRACEX_HELP},
175 : {RID_LRANGLEX, RID_LRANGLEX_HELP}, {RID_LMRANGLEXY, RID_LMRANGLEXY_HELP},
176 : {RID_LRCEILX, RID_LRCEILX_HELP}, {RID_LRFLOORX, RID_LRFLOORX_HELP},
177 : {RID_LRLINEX, RID_LRLINEX_HELP}, {RID_LRDLINEX, RID_LRDLINEX_HELP},
178 : {0xFFFF, 0},
179 : {RID_SLRPARENTX, RID_SLRPARENTX_HELP}, {RID_SLRBRACKETX, RID_SLRBRACKETX_HELP},
180 : {RID_SLRDBRACKETX, RID_SLRDBRACKETX_HELP}, {RID_SLRBRACEX, RID_SLRBRACEX_HELP},
181 : {RID_SLRANGLEX, RID_SLRANGLEX_HELP}, {RID_SLMRANGLEXY, RID_SLMRANGLEXY_HELP},
182 : {RID_SLRCEILX, RID_SLRCEILX_HELP}, {RID_SLRFLOORX, RID_SLRFLOORX_HELP},
183 : {RID_SLRLINEX, RID_SLRLINEX_HELP}, {RID_SLRDLINEX, RID_SLRDLINEX_HELP},
184 : {0XFFFF, 0},
185 : {RID_XOVERBRACEY, RID_XOVERBRACEY_HELP}, {RID_XUNDERBRACEY, RID_XUNDERBRACEY_HELP},
186 : };
187 :
188 : const sal_uInt16 SmElementsControl::aFormats[][2] =
189 : {
190 : {RID_RSUPX, RID_RSUPX_HELP}, {RID_RSUBX, RID_RSUBX_HELP}, {RID_LSUPX, RID_LSUPX_HELP},
191 : {RID_LSUBX, RID_LSUBX_HELP}, {RID_CSUPX, RID_CSUPX_HELP}, {RID_CSUBX, RID_CSUBX_HELP},
192 : {0xFFFF, 0},
193 : {RID_NEWLINE, RID_NEWLINE_HELP}, {RID_SBLANK, RID_SBLANK_HELP}, {RID_BLANK, RID_BLANK_HELP},
194 : {RID_NOSPACE, RID_NOSPACE_HELP},
195 : {RID_ALIGNLX, RID_ALIGNLX_HELP}, {RID_ALIGNCX, RID_ALIGNCX_HELP}, {RID_ALIGNRX, RID_ALIGNRX_HELP},
196 : {0xFFFF, 0},
197 : {RID_BINOMXY, RID_BINOMXY_HELP}, {RID_STACK, RID_STACK_HELP},
198 : {RID_MATRIX, RID_MATRIX_HELP},
199 : };
200 :
201 : const sal_uInt16 SmElementsControl::aOthers[][2] =
202 : {
203 : {RID_INFINITY, RID_INFINITY_HELP}, {RID_PARTIAL, RID_PARTIAL_HELP}, {RID_NABLA, RID_NABLA_HELP},
204 : {RID_EXISTS, RID_EXISTS_HELP}, {RID_NOTEXISTS, RID_NOTEXISTS_HELP}, {RID_FORALL, RID_FORALL_HELP},
205 : {RID_HBAR, RID_HBAR_HELP}, {RID_LAMBDABAR, RID_LAMBDABAR_HELP}, {RID_RE, RID_RE_HELP},
206 : {RID_IM, RID_IM_HELP}, {RID_WP, RID_WP_HELP},
207 : {0xFFFF, 0},
208 : {RID_LEFTARROW, RID_LEFTARROW_HELP}, {RID_RIGHTARROW, RID_RIGHTARROW_HELP}, {RID_UPARROW, RID_UPARROW_HELP},
209 : {RID_DOWNARROW, RID_DOWNARROW_HELP},
210 : {0xFFFF, 0},
211 : {RID_DOTSLOW, RID_DOTSLOW_HELP}, {RID_DOTSAXIS, RID_DOTSAXIS_HELP}, {RID_DOTSVERT, RID_DOTSVERT_HELP},
212 : {RID_DOTSUP, RID_DOTSUP_HELP}, {RID_DOTSDOWN, RID_DOTSDOWN_HELP}
213 : };
214 :
215 34 : SmElementsControl::SmElementsControl(vcl::Window *pParent, const ResId& rResId)
216 : : Control(pParent, rResId)
217 34 : , mpDocShell(new SmDocShell(SFXOBJECTSHELL_STD_NORMAL))
218 : , maCurrentSetId(0)
219 : , mpCurrentElement(NULL)
220 : , mbVerticalMode(true)
221 68 : , mpScroll(new ScrollBar(this, WB_VERT))
222 : {
223 34 : SetMapMode( MapMode(MAP_100TH_MM) );
224 34 : SetDrawMode( DRAWMODE_DEFAULT );
225 34 : SetLayoutMode( TEXT_LAYOUT_DEFAULT );
226 34 : SetDigitLanguage( LANGUAGE_ENGLISH );
227 :
228 34 : maFormat.SetBaseSize(PixelToLogic(Size(0, SmPtsTo100th_mm(12))));
229 :
230 34 : mpScroll->SetScrollHdl( LINK(this, SmElementsControl, ScrollHdl) );
231 34 : mpScroll->Show();
232 34 : }
233 :
234 68 : SmElementsControl::~SmElementsControl()
235 : {
236 34 : mpDocShell->DoClose();
237 34 : }
238 :
239 66 : void SmElementsControl::setVerticalMode(bool bVerticalMode)
240 : {
241 66 : mbVerticalMode = bVerticalMode;
242 66 : }
243 :
244 17 : void SmElementsControl::Paint(const Rectangle&)
245 : {
246 17 : Push();
247 :
248 17 : bool bOldVisibleState = mpScroll->IsVisible();
249 :
250 17 : sal_Int32 nScrollbarWidth = bOldVisibleState ? GetSettings().GetStyleSettings().GetScrollBarSize() : 0;
251 :
252 17 : sal_Int32 nControlWidth = GetOutputSizePixel().Width() - nScrollbarWidth;
253 17 : sal_Int32 nControlHeight = GetOutputSizePixel().Height();
254 :
255 17 : sal_Int32 boxX = maMaxElementDimensions.Width() + 10;
256 17 : sal_Int32 boxY = maMaxElementDimensions.Height() + 10;
257 :
258 17 : sal_Int32 x = 0;
259 17 : sal_Int32 y = -mpScroll->GetThumbPos();
260 :
261 17 : sal_Int32 perLine = 0;
262 :
263 17 : if (mbVerticalMode)
264 0 : perLine = nControlHeight / boxY;
265 : else
266 17 : perLine = nControlWidth / boxX;
267 :
268 17 : if(perLine <= 0) {
269 0 : perLine = 1;
270 : }
271 :
272 17 : if (mbVerticalMode)
273 0 : boxY = nControlHeight / perLine;
274 : else
275 17 : boxX = nControlWidth / perLine;
276 :
277 357 : for (sal_uInt16 i = 0; i < maElementList.size() ; i++)
278 : {
279 340 : SmElement* element = maElementList[i].get();
280 340 : if (element->isSeparator())
281 : {
282 34 : if (mbVerticalMode)
283 : {
284 0 : x += boxX;
285 0 : y = 0;
286 :
287 : Rectangle aSelectionRectangle(
288 0 : x+5-1, y+5,
289 0 : x+5+1, nControlHeight - 5);
290 :
291 0 : DrawRect(PixelToLogic(aSelectionRectangle));
292 0 : x += 10;
293 : }
294 : else
295 : {
296 34 : x = 0;
297 34 : y += boxY;
298 :
299 : Rectangle aSelectionRectangle(
300 68 : x+5, y+5-1,
301 102 : nControlWidth - 5, y+5+1);
302 :
303 34 : DrawRect(PixelToLogic(aSelectionRectangle));
304 34 : y += 10;
305 : }
306 : }
307 : else
308 : {
309 306 : Size aSizePixel = LogicToPixel(Size(element->getNode()->GetWidth(), element->getNode()->GetHeight()));
310 306 : if(mbVerticalMode)
311 : {
312 0 : if ( y + boxY > nControlHeight)
313 : {
314 0 : x += boxX;
315 0 : y = 0;
316 : }
317 : }
318 : else
319 : {
320 306 : if ( x + boxX > nControlWidth)
321 : {
322 34 : x = 0;
323 34 : y += boxY;
324 : }
325 : }
326 :
327 306 : if (mpCurrentElement == element)
328 : {
329 0 : Push();
330 0 : SetFillColor( Color(230, 230, 230) );
331 0 : SetLineColor( Color(230, 230, 230) );
332 :
333 0 : DrawRect(PixelToLogic(Rectangle(x+2, y+2, x+boxX-2, y+boxY-2)));
334 0 : Pop();
335 : }
336 :
337 306 : Point location(x + ((boxX-aSizePixel.Width())/2), y + ((boxY-aSizePixel.Height())/2));
338 306 : SmDrawingVisitor(*this, PixelToLogic(location), element->getNode().get());
339 :
340 306 : element->mBoxLocation = Point(x,y);
341 306 : element->mBoxSize = Size(boxX, boxY);
342 :
343 306 : if(mbVerticalMode)
344 0 : y += boxY;
345 : else
346 306 : x += boxX;
347 : }
348 : }
349 :
350 17 : sal_Int32 nTotalControlHeight = y + boxY + mpScroll->GetThumbPos();
351 :
352 17 : if (nTotalControlHeight > GetOutputSizePixel().Height())
353 : {
354 0 : mpScroll->SetRangeMax(nTotalControlHeight);
355 0 : mpScroll->SetPosSizePixel(Point(nControlWidth, 0), Size(nScrollbarWidth, nControlHeight));
356 0 : mpScroll->SetVisibleSize(nControlHeight);
357 0 : mpScroll->Show();
358 : }
359 : else
360 : {
361 17 : mpScroll->SetThumbPos(0);
362 17 : mpScroll->Hide();
363 : }
364 :
365 : // If scrollbar visibility changed, we have to go through the
366 : // calculation once more, see nScrollbarWidth
367 17 : if (bOldVisibleState != mpScroll->IsVisible())
368 9 : Invalidate();
369 :
370 17 : Pop();
371 17 : }
372 :
373 0 : void SmElementsControl::MouseMove( const MouseEvent& rMouseEvent )
374 : {
375 0 : mpCurrentElement = NULL;
376 0 : OUString tooltip;
377 0 : if (Rectangle(Point(0, 0), GetOutputSizePixel()).IsInside(rMouseEvent.GetPosPixel()))
378 : {
379 0 : for (sal_uInt16 i = 0; i < maElementList.size() ; i++)
380 : {
381 0 : SmElement* element = maElementList[i].get();
382 0 : Rectangle rect(element->mBoxLocation, element->mBoxSize);
383 0 : if (rect.IsInside(rMouseEvent.GetPosPixel()))
384 : {
385 0 : if (mpCurrentElement != element)
386 : {
387 0 : mpCurrentElement = element;
388 0 : Invalidate();
389 0 : tooltip = element->getHelpText();
390 : }
391 : }
392 : }
393 : }
394 : else
395 : {
396 0 : Control::MouseMove (rMouseEvent);
397 : }
398 :
399 0 : SetQuickHelpText(tooltip);
400 0 : }
401 :
402 0 : void SmElementsControl::MouseButtonDown(const MouseEvent& rMouseEvent)
403 : {
404 0 : GrabFocus();
405 :
406 0 : if (rMouseEvent.IsLeft() && Rectangle(Point(0, 0), GetOutputSizePixel()).IsInside(rMouseEvent.GetPosPixel()))
407 : {
408 0 : for (sal_uInt16 i = 0; i < maElementList.size() ; i++)
409 : {
410 0 : SmElement* element = maElementList[i].get();
411 0 : Rectangle rect(element->mBoxLocation, element->mBoxSize);
412 0 : if (rect.IsInside(rMouseEvent.GetPosPixel()))
413 : {
414 0 : aSelectHdlLink.Call(element);
415 0 : return;
416 : }
417 : }
418 : }
419 : else
420 : {
421 0 : Control::MouseButtonDown (rMouseEvent);
422 : }
423 : }
424 :
425 0 : IMPL_LINK_NOARG( SmElementsControl, ScrollHdl )
426 : {
427 0 : DoScroll(mpScroll->GetDelta());
428 0 : return 0;
429 : }
430 :
431 0 : void SmElementsControl::DoScroll(long nDelta)
432 : {
433 0 : Point aNewPoint = mpScroll->GetPosPixel();
434 0 : Rectangle aRect(Point(), GetOutputSize());
435 0 : aRect.Right() -= mpScroll->GetSizePixel().Width();
436 0 : Scroll( 0, -nDelta, aRect );
437 0 : mpScroll->SetPosPixel(aNewPoint);
438 0 : Invalidate();
439 0 : }
440 :
441 68 : void SmElementsControl::addSeparator()
442 : {
443 68 : SmElementPointer pElement(new SmElementSeparator());
444 68 : maElementList.push_back(pElement);
445 68 : }
446 :
447 612 : void SmElementsControl::addElement(const OUString& aElementVisual, const OUString& aElementSource, const OUString& aHelpText)
448 : {
449 612 : SmNodePointer pNode(SmParser().ParseExpression(aElementVisual));
450 :
451 612 : pNode->Prepare(maFormat, *mpDocShell);
452 612 : pNode->SetSize(Fraction(10,8));
453 612 : pNode->Arrange(*this, maFormat);
454 :
455 612 : Size aSizePixel = LogicToPixel(Size(pNode->GetWidth(), pNode->GetHeight()), MAP_100TH_MM);
456 612 : if (aSizePixel.Width() > maMaxElementDimensions.Width()) {
457 136 : maMaxElementDimensions.Width() = aSizePixel.Width();
458 : }
459 :
460 612 : if (aSizePixel.Height() > maMaxElementDimensions.Height()) {
461 68 : maMaxElementDimensions.Height() = aSizePixel.Height();
462 : }
463 :
464 1224 : SmElementPointer pElement(new SmElement(pNode, aElementSource, aHelpText));
465 1224 : maElementList.push_back(pElement);
466 612 : }
467 :
468 34 : void SmElementsControl::setElementSetId(sal_uInt16 aSetId)
469 : {
470 34 : maCurrentSetId = aSetId;
471 34 : maMaxElementDimensions = Size();
472 34 : build();
473 34 : }
474 :
475 34 : void SmElementsControl::addElements(const sal_uInt16 aElementsArray[][2], sal_uInt16 aElementsArraySize)
476 : {
477 714 : for (sal_uInt16 i = 0; i < aElementsArraySize ; i++)
478 : {
479 680 : sal_uInt16 aElementId = aElementsArray[i][0];
480 680 : sal_uInt16 aElementIdHelp = aElementsArray[i][1];
481 680 : if (aElementId == 0xFFFF) {
482 68 : addSeparator();
483 : } else {
484 612 : if (aElementId == RID_NEWLINE)
485 0 : addElement(OUString( "\xe2\x86\xb5", 3, RTL_TEXTENCODING_UTF8 ), SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
486 612 : else if (aElementId == RID_SBLANK)
487 0 : addElement("\"`\"", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
488 612 : else if (aElementId == RID_BLANK)
489 0 : addElement("\"~\"", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
490 612 : else if (aElementId == RID_PHANTOMX)
491 0 : addElement("\"" + SM_RESSTR(STR_HIDE) +"\"", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
492 612 : else if (aElementId == RID_BOLDX)
493 0 : addElement("bold B", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
494 612 : else if (aElementId == RID_ITALX)
495 0 : addElement("ital I", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
496 612 : else if (aElementId == RID_SIZEXY)
497 0 : addElement("\"" + SM_RESSTR(STR_SIZE) + "\"", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
498 612 : else if (aElementId == RID_FONTXY)
499 0 : addElement("\"" + SM_RESSTR(STR_FONT) + "\"", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
500 612 : else if (aElementId == RID_COLORX_BLACK)
501 0 : addElement("color black { \"" + SM_RESSTR(STR_BLACK) + "\" }", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
502 612 : else if (aElementId == RID_COLORX_BLUE)
503 0 : addElement("color blue { \"" + SM_RESSTR(STR_BLUE) + "\" }", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
504 612 : else if (aElementId == RID_COLORX_GREEN)
505 0 : addElement("color green { \"" + SM_RESSTR(STR_GREEN) + "\" }", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
506 612 : else if (aElementId == RID_COLORX_RED)
507 0 : addElement("color red { \"" + SM_RESSTR(STR_RED) + "\" }", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
508 612 : else if (aElementId == RID_COLORX_CYAN)
509 0 : addElement("color cyan { \"" + SM_RESSTR(STR_CYAN) + "\" }", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
510 612 : else if (aElementId == RID_COLORX_MAGENTA)
511 0 : addElement("color magenta { \"" + SM_RESSTR(STR_MAGENTA) + "\" }", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
512 612 : else if (aElementId == RID_COLORX_YELLOW)
513 0 : addElement("color yellow { \"" + SM_RESSTR(STR_YELLOW) + "\" }", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
514 612 : else if (aElementId == RID_ALIGNLX)
515 0 : addElement("\"" + SM_RESSTR(STR_ALIGN_LEFT) + "\"", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
516 612 : else if (aElementId == RID_ALIGNCX)
517 0 : addElement("\"" + SM_RESSTR(STR_ALIGN_CENTER) + "\"", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
518 612 : else if (aElementId == RID_ALIGNRX)
519 0 : addElement("\"" + SM_RESSTR(STR_ALIGN_RIGHT) + "\"", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
520 :
521 612 : else if (aElementId == RID_SLRPARENTX)
522 0 : addElement("left ( binom{<?>}{<?>} right ) ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
523 612 : else if (aElementId == RID_SLRBRACKETX)
524 0 : addElement("left [ binom{<?>}{<?>} right ] ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
525 612 : else if (aElementId == RID_SLRDBRACKETX)
526 0 : addElement("left ldbracket binom{<?>}{<?>} right rdbracket ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
527 612 : else if (aElementId == RID_SLRBRACEX)
528 0 : addElement("left lbrace binom{<?>}{<?>} right rbrace ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
529 612 : else if (aElementId == RID_SLRANGLEX)
530 0 : addElement("left langle binom{<?>}{<?>} right rangle ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
531 612 : else if (aElementId == RID_SLRCEILX)
532 0 : addElement("left lceil binom{<?>}{<?>} right rceil ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
533 612 : else if (aElementId == RID_SLRFLOORX)
534 0 : addElement("left lfloor binom{<?>}{<?>} right rfloor ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
535 :
536 612 : else if (aElementId == RID_SLRLINEX)
537 0 : addElement("left lline binom{<?>}{<?>} right rline ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
538 612 : else if (aElementId == RID_SLRDLINEX)
539 0 : addElement("left ldline binom{<?>}{<?>} right rdline ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
540 612 : else if (aElementId == RID_SLMRANGLEXY)
541 0 : addElement("left langle binom{<?>}{<?>} mline binom{<?>}{<?>} right rangle ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
542 :
543 612 : else if (aElementId == RID_XOVERBRACEY)
544 0 : addElement("{<?><?><?>} overbrace {<?>} ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
545 612 : else if (aElementId == RID_XUNDERBRACEY)
546 0 : addElement("{<?><?><?>} underbrace {<?>} ", SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
547 : else
548 612 : addElement(SM_RESSTR(aElementId), SM_RESSTR(aElementId), SM_RESSTR(aElementIdHelp));
549 : }
550 : }
551 34 : }
552 :
553 34 : void SmElementsControl::build()
554 : {
555 34 : maElementList.clear();
556 :
557 34 : switch(maCurrentSetId)
558 : {
559 : // we need to divide by 2 because of the matrix of two dimensions
560 : case RID_CATEGORY_UNARY_BINARY_OPERATORS:
561 34 : addElements(aUnaryBinaryOperatorsList, SAL_N_ELEMENTS(aUnaryBinaryOperatorsList));
562 34 : break;
563 : case RID_CATEGORY_RELATIONS:
564 0 : addElements(aRelationsList, SAL_N_ELEMENTS(aRelationsList));
565 0 : break;
566 : case RID_CATEGORY_SET_OPERATIONS:
567 0 : addElements(aSetOperations, SAL_N_ELEMENTS(aSetOperations));
568 0 : break;
569 : case RID_CATEGORY_FUNCTIONS:
570 0 : addElements(aFunctions, SAL_N_ELEMENTS(aFunctions));
571 0 : break;
572 : case RID_CATEGORY_OPERATORS:
573 0 : addElements(aOperators, SAL_N_ELEMENTS(aOperators));
574 0 : break;
575 : case RID_CATEGORY_ATTRIBUTES:
576 0 : addElements(aAttributes, SAL_N_ELEMENTS(aAttributes));
577 0 : break;
578 : case RID_CATEGORY_BRACKETS:
579 0 : addElements(aBrackets, SAL_N_ELEMENTS(aBrackets));
580 0 : break;
581 : case RID_CATEGORY_FORMATS:
582 0 : addElements(aFormats, SAL_N_ELEMENTS(aFormats));
583 0 : break;
584 : case RID_CATEGORY_OTHERS:
585 0 : addElements(aOthers, SAL_N_ELEMENTS(aOthers));
586 0 : break;
587 : case RID_CATEGORY_EXAMPLES:
588 : {
589 0 : OUString aEquation = "C=%pi cdot d = 2 cdot %pi cdot r";
590 0 : addElement(aEquation, aEquation, "");
591 0 : aEquation = "E=mc^2";
592 0 : addElement(aEquation, aEquation, "");
593 0 : aEquation = "a^2 + b^2 = c^2";
594 0 : addElement(aEquation, aEquation, "");
595 0 : aEquation = "f ( x ) = sum from { { i = 0 } } to { infinity } { {f^{(i)}(0)} over {i!} x^i}";
596 0 : addElement(aEquation, aEquation, "");
597 0 : aEquation = "f ( x ) = {1} over {%sigma sqrt{2%pi} }e^-{{(x-%mu)^2} over {2%sigma^2}}";
598 0 : addElement(aEquation, aEquation, "");
599 : }
600 0 : break;
601 : }
602 34 : Invalidate();
603 34 : }
604 :
605 : const sal_uInt16 SmElementsDockingWindow::aCategories[] = {
606 : RID_CATEGORY_UNARY_BINARY_OPERATORS,
607 : RID_CATEGORY_RELATIONS,
608 : RID_CATEGORY_SET_OPERATIONS,
609 : RID_CATEGORY_FUNCTIONS,
610 : RID_CATEGORY_OPERATORS,
611 : RID_CATEGORY_ATTRIBUTES,
612 : RID_CATEGORY_BRACKETS,
613 : RID_CATEGORY_FORMATS,
614 : RID_CATEGORY_OTHERS,
615 : RID_CATEGORY_EXAMPLES
616 : };
617 :
618 34 : SmElementsDockingWindow::SmElementsDockingWindow(SfxBindings* pInputBindings, SfxChildWindow* pChildWindow, vcl::Window* pParent) :
619 : SfxDockingWindow(pInputBindings, pChildWindow, pParent, SmResId(RID_ELEMENTSDOCKINGWINDOW)),
620 : maElementsControl (this, SmResId(1)),
621 34 : maElementListBox (this, SmResId(1))
622 : {
623 34 : maElementsControl.SetBorderStyle( WindowBorderStyle::MONO );
624 :
625 34 : maElementListBox.SetDropDownLineCount( SAL_N_ELEMENTS(aCategories) );
626 :
627 374 : for (sal_uInt16 i = 0; i < SAL_N_ELEMENTS(aCategories) ; i++)
628 : {
629 340 : maElementListBox.InsertEntry(SM_RESSTR(aCategories[i]));
630 : }
631 :
632 34 : maElementListBox.SetSelectHdl(LINK(this, SmElementsDockingWindow, ElementSelectedHandle));
633 :
634 34 : maElementsControl.SetBackground( Color( COL_WHITE ) );
635 34 : maElementsControl.SetTextColor( Color( COL_BLACK ) );
636 34 : maElementsControl.SetSelectHdl(LINK(this, SmElementsDockingWindow, SelectClickHdl));
637 :
638 34 : maElementListBox.SelectEntry(SM_RESSTR(RID_CATEGORY_UNARY_BINARY_OPERATORS));
639 34 : maElementsControl.setElementSetId(RID_CATEGORY_UNARY_BINARY_OPERATORS);
640 :
641 34 : FreeResource();
642 34 : }
643 :
644 68 : SmElementsDockingWindow::~SmElementsDockingWindow ()
645 : {
646 68 : }
647 :
648 0 : void SmElementsDockingWindow::ToggleFloatingMode()
649 : {
650 0 : SfxDockingWindow::ToggleFloatingMode();
651 :
652 0 : if (GetFloatingWindow())
653 0 : GetFloatingWindow()->SetMinOutputSizePixel( Size(100, 100) );
654 :
655 0 : Invalidate();
656 0 : }
657 :
658 0 : void SmElementsDockingWindow::EndDocking( const Rectangle& rReactangle, bool bFloatMode)
659 : {
660 0 : SfxDockingWindow::EndDocking(rReactangle, bFloatMode);
661 0 : bool bVertical = ( GetAlignment() == SFX_ALIGN_TOP || GetAlignment() == SFX_ALIGN_BOTTOM );
662 0 : maElementsControl.setVerticalMode(bVertical);
663 0 : }
664 :
665 0 : IMPL_LINK( SmElementsDockingWindow, SelectClickHdl, SmElement*, pElement)
666 : {
667 0 : SmViewShell* pViewSh = GetView();
668 :
669 0 : if (pViewSh)
670 : {
671 : pViewSh->GetViewFrame()->GetDispatcher()->Execute(
672 : SID_INSERTCOMMANDTEXT, SfxCallMode::RECORD,
673 0 : new SfxStringItem(SID_INSERTCOMMANDTEXT, pElement->getText()), 0L);
674 : }
675 0 : return 0;
676 : }
677 :
678 0 : IMPL_LINK( SmElementsDockingWindow, ElementSelectedHandle, ListBox*, pList)
679 : {
680 0 : for (sal_uInt16 i = 0; i < SAL_N_ELEMENTS(aCategories) ; i++)
681 : {
682 0 : sal_uInt16 aCurrentCategory = aCategories[i];
683 0 : OUString aCurrentCategoryString = SM_RESSTR(aCurrentCategory);
684 0 : if (aCurrentCategoryString == pList->GetSelectEntry())
685 : {
686 0 : maElementsControl.setElementSetId(aCurrentCategory);
687 0 : return 0;
688 : }
689 0 : }
690 0 : return 0;
691 : }
692 :
693 0 : SmViewShell* SmElementsDockingWindow::GetView()
694 : {
695 0 : SfxViewShell *pView = GetBindings().GetDispatcher()->GetFrame()->GetViewShell();
696 0 : return PTR_CAST(SmViewShell, pView);
697 : }
698 :
699 66 : void SmElementsDockingWindow::Resize()
700 : {
701 66 : bool bVertical = ( GetAlignment() == SFX_ALIGN_TOP || GetAlignment() == SFX_ALIGN_BOTTOM );
702 66 : maElementsControl.setVerticalMode(bVertical);
703 :
704 66 : sal_uInt32 aWidth = GetOutputSizePixel().Width();
705 66 : sal_uInt32 aHeight = GetOutputSizePixel().Height();
706 :
707 66 : sal_uInt32 aElementsSetsHeight = 23;
708 66 : sal_uInt32 aPadding = 5;
709 :
710 66 : Rectangle aRect1 = Rectangle(aPadding, aPadding, aWidth - aPadding, aElementsSetsHeight + aPadding);
711 :
712 66 : maElementListBox.SetPosSizePixel(aRect1.TopLeft(), aRect1.GetSize());
713 :
714 66 : Rectangle aRect = Rectangle(aPadding, aElementsSetsHeight + aPadding + aPadding, aWidth - aPadding, aHeight - aPadding);
715 :
716 66 : maElementsControl.SetPosSizePixel(aRect.TopLeft(), aRect.GetSize());
717 :
718 66 : SfxDockingWindow::Resize();
719 66 : Invalidate();
720 66 : }
721 :
722 116 : SFX_IMPL_DOCKINGWINDOW_WITHID(SmElementsDockingWindowWrapper, SID_ELEMENTSDOCKINGWINDOW);
723 :
724 34 : SmElementsDockingWindowWrapper::SmElementsDockingWindowWrapper(
725 : vcl::Window *pParentWindow, sal_uInt16 nId,
726 : SfxBindings *pBindings, SfxChildWinInfo *pInfo) :
727 34 : SfxChildWindow(pParentWindow, nId)
728 : {
729 34 : pWindow = new SmElementsDockingWindow(pBindings, this, pParentWindow);
730 34 : SmElementsDockingWindow* pDialog = (SmElementsDockingWindow*) pWindow;
731 34 : pDialog->SetPosSizePixel(Point(0, 0), Size(300, 0));
732 34 : pDialog->Show();
733 :
734 34 : eChildAlignment = SFX_ALIGN_LEFT;
735 :
736 34 : pDialog->Initialize( pInfo );
737 34 : }
738 :
739 68 : SmElementsDockingWindowWrapper::~SmElementsDockingWindowWrapper()
740 : {
741 140 : }
742 :
743 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|