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