1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_starmath.hxx"
32 #include <rtl/logfile.hxx>
33 #include <svl/eitem.hxx>
34 #include <sfx2/app.hxx>
35 #include <svl/intitem.hxx>
36 #include <svtools/imgdef.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <sfx2/imgmgr.hxx>
39 #include <vcl/wrkwin.hxx>
40 #include "toolbox.hxx"
42 #include "starmath.hrc"
45 #include "toolbox.hrc"
50 ////////////////////////////////////////////////////////////
52 static USHORT
GetImageListRID( USHORT nCategoryRID
, BOOL bHighContrast
)
57 case RID_UNBINOPS_CAT
: nRes
= RID_IL_UNBINOPS
; break;
58 case RID_RELATIONS_CAT
: nRes
= RID_IL_RELATIONS
; break;
59 case RID_SETOPERATIONS_CAT
: nRes
= RID_IL_SETOPERATIONS
; break;
60 case RID_FUNCTIONS_CAT
: nRes
= RID_IL_FUNCTIONS
; break;
61 case RID_OPERATORS_CAT
: nRes
= RID_IL_OPERATORS
; break;
62 case RID_ATTRIBUTES_CAT
: nRes
= RID_IL_ATTRIBUTES
; break;
63 case RID_BRACKETS_CAT
: nRes
= RID_IL_BRACKETS
; break;
64 case RID_FORMAT_CAT
: nRes
= RID_IL_FORMAT
; break;
65 case RID_MISC_CAT
: nRes
= RID_IL_MISC
; break;
67 DBG_ERROR( "unkown category" );
69 if (nRes
!= 0xFFFF && bHighContrast
)
70 ++nRes
; //! the resource ID for the high contrast image list is just +1 compared to the regular ones
75 static sal_Int16
GetToolBoxCategoriesIndex( USHORT nCategoryRID
)
80 case RID_UNBINOPS_CAT
: nIdx
= 0; break;
81 case RID_RELATIONS_CAT
: nIdx
= 1; break;
82 case RID_SETOPERATIONS_CAT
: nIdx
= 2; break;
83 case RID_FUNCTIONS_CAT
: nIdx
= 3; break;
84 case RID_OPERATORS_CAT
: nIdx
= 4; break;
85 case RID_ATTRIBUTES_CAT
: nIdx
= 5; break;
86 case RID_BRACKETS_CAT
: nIdx
= 6; break;
87 case RID_FORMAT_CAT
: nIdx
= 7; break;
88 case RID_MISC_CAT
: nIdx
= 8; break;
96 static USHORT
GetCategoryRID( USHORT nResId
)
101 case RID_IL_UNBINOPS
:
102 case RID_ILH_UNBINOPS
: nRes
= RID_UNBINOPS_CAT
; break;
103 case RID_IL_RELATIONS
:
104 case RID_ILH_RELATIONS
: nRes
= RID_RELATIONS_CAT
; break;
105 case RID_IL_SETOPERATIONS
:
106 case RID_ILH_SETOPERATIONS
: nRes
= RID_SETOPERATIONS_CAT
; break;
107 case RID_IL_FUNCTIONS
:
108 case RID_ILH_FUNCTIONS
: nRes
= RID_FUNCTIONS_CAT
; break;
109 case RID_IL_OPERATORS
:
110 case RID_ILH_OPERATORS
: nRes
= RID_OPERATORS_CAT
; break;
111 case RID_IL_ATTRIBUTES
:
112 case RID_ILH_ATTRIBUTES
: nRes
= RID_ATTRIBUTES_CAT
; break;
113 case RID_IL_BRACKETS
:
114 case RID_ILH_BRACKETS
: nRes
= RID_BRACKETS_CAT
; break;
116 case RID_ILH_FORMAT
: nRes
= RID_FORMAT_CAT
; break;
118 case RID_ILH_MISC
: nRes
= RID_MISC_CAT
; break;
120 if (nResId
!= RID_IL_CATALOG
&& nResId
!= RID_ILH_CATALOG
)
122 #if OSL_DEBUG_LEVEL > 1
123 DBG_ERROR( "unkown category" );
131 ////////////////////////////////////////////////////////////
134 SmToolBoxWindow::SmToolBoxWindow(SfxBindings
*pTmpBindings
,
135 SfxChildWindow
*pChildWindow
,
137 SfxFloatingWindow(pTmpBindings
, pChildWindow
, pParent
, SmResId(RID_TOOLBOXWINDOW
)),
138 aToolBoxCat(this, SmResId(NUM_TBX_CATEGORIES
+ 1)),
139 aToolBoxCat_Delim(this, SmResId( FL_TOOLBOX_CAT_DELIM
))
141 RTL_LOGFILE_CONTEXT( aLog
, "starmath: SmToolBoxWindow::SmToolBoxWindow" );
143 // allow for cursor travelling between toolbox and sub-categories
144 SetStyle( GetStyle() | WB_DIALOGCONTROL
);
146 nActiveCategoryRID
= sal::static_int_cast
< USHORT
>(-1);
148 aToolBoxCat
.SetClickHdl(LINK(this, SmToolBoxWindow
, CategoryClickHdl
));
151 for (i
= 0; i
< NUM_TBX_CATEGORIES
; i
++)
153 ToolBox
*pBox
= new ToolBox(this, SmResId (i
+1));
154 vToolBoxCategories
[i
] = pBox
;
155 pBox
->SetSelectHdl(LINK(this, SmToolBoxWindow
, CmdSelectHdl
));
157 pToolBoxCmd
= vToolBoxCategories
[0];
159 for (i
= 0; i
<= NUM_TBX_CATEGORIES
; ++i
)
167 ApplyImageLists( RID_UNBINOPS_CAT
);
168 SetCategory( RID_UNBINOPS_CAT
);
171 SmToolBoxWindow::~SmToolBoxWindow()
174 for (i
= 0; i
< NUM_TBX_CATEGORIES
; i
++)
176 ToolBox
*pBox
= vToolBoxCategories
[i
];
179 for (i
= 0; i
< NUM_TBX_CATEGORIES
+ 1; ++i
)
181 delete aImageLists
[i
];
182 delete aImageListsH
[i
];
187 SmViewShell
* SmToolBoxWindow::GetView()
189 SfxViewShell
*pView
= GetBindings().GetDispatcher()->GetFrame()->GetViewShell();
190 return PTR_CAST(SmViewShell
, pView
);
194 const ImageList
* SmToolBoxWindow::GetImageList( USHORT nResId
, BOOL bHighContrast
)
196 // creates the image list via its resource id and stores that
197 // list for later use in the respective array.
199 const ImageList
*pIL
= 0;
202 USHORT nCategoryRID
= GetCategoryRID( nResId
);
203 sal_Int16 nIndex
= GetToolBoxCategoriesIndex( nCategoryRID
);
204 if (nIndex
== -1 && (nResId
== RID_IL_CATALOG
|| nResId
== RID_ILH_CATALOG
))
205 nIndex
= NUM_TBX_CATEGORIES
;
209 ImageList
**pImgList
= bHighContrast
? aImageListsH
: aImageLists
;
210 if (!pImgList
[ nIndex
])
211 pImgList
[ nIndex
] = new ImageList( SmResId(nResId
) );
212 pIL
= pImgList
[ nIndex
];
215 DBG_ASSERT( pIL
, "image list not found!" );
220 void SmToolBoxWindow::ApplyImageLists( USHORT nCategoryRID
)
222 BOOL bHighContrast
= GetSettings().GetStyleSettings().GetHighContrastMode();
224 // set image list for toolbox 'catalog'
225 const ImageList
*pImageList
= GetImageList( bHighContrast
? RID_ILH_CATALOG
: RID_IL_CATALOG
, bHighContrast
);
226 DBG_ASSERT( pImageList
, "image list missing" );
228 aToolBoxCat
.SetImageList( *pImageList
);
230 // set image list for active (visible) category of 'catalog'
231 sal_Int16 nIdx
= GetToolBoxCategoriesIndex( nCategoryRID
);
232 USHORT nResId
= GetImageListRID( nCategoryRID
, bHighContrast
);
233 pImageList
= GetImageList( nResId
, bHighContrast
);
234 DBG_ASSERT( pImageList
&& nIdx
>= 0, "image list or index missing" );
235 if (pImageList
&& nIdx
>= 0)
236 vToolBoxCategories
[ nIdx
]->SetImageList( *pImageList
);
239 void SmToolBoxWindow::DataChanged( const DataChangedEvent
&rEvt
)
241 if ( (rEvt
.GetType() == DATACHANGED_SETTINGS
) && (rEvt
.GetFlags() & SETTINGS_STYLE
) )
242 ApplyImageLists( nActiveCategoryRID
);
244 SfxFloatingWindow::DataChanged( rEvt
);
247 void SmToolBoxWindow::StateChanged( StateChangedType nStateChange
)
249 static BOOL bSetPosition
= TRUE
;
250 if (STATE_CHANGE_INITSHOW
== nStateChange
)
252 // calculate initial position to be used after creation of the window...
253 AdjustPosSize( bSetPosition
);
254 bSetPosition
= FALSE
;
256 SetCategory(RID_UNBINOPS_CAT
);
258 //... otherwise the base class will remember the last position of the window
259 SfxFloatingWindow::StateChanged( nStateChange
);
263 void SmToolBoxWindow::AdjustPosSize( BOOL bSetPos
)
265 Size
aCatSize( aToolBoxCat
.CalcWindowSizePixel( 2 ) );
266 Size
aCmdSize( pToolBoxCmd
->CalcWindowSizePixel( 5 ) );
267 DBG_ASSERT( aCatSize
.Width() == aCmdSize
.Width(), "width mismatch" );
270 aToolBoxCat
.SetPosPixel( Point(0, 3) );
271 aToolBoxCat
.SetSizePixel( aCatSize
);
272 // settings for catalog / category delimiter
273 Point
aP( aToolBoxCat_Delim
.GetPosPixel() );
275 aToolBoxCat_Delim
.SetPosPixel( aP
);
276 Size
aS( aCatSize
.Width() - 10, 10 );
277 aToolBoxCat_Delim
.SetSizePixel( aS
);
280 aP
.Y() += aToolBoxCat_Delim
.GetSizePixel().Height();
281 for (int i
= 0; i
< NUM_TBX_CATEGORIES
; i
++)
283 vToolBoxCategories
[i
]->SetPosPixel( aP
);
284 vToolBoxCategories
[i
]->SetSizePixel( aCmdSize
);
286 // main window settings
287 Size
aWndSize ( aCatSize
.Width(), pToolBoxCmd
->GetPosPixel().Y() + pToolBoxCmd
->GetSizePixel().Height() + 3);
288 SetOutputSizePixel( aWndSize
);
292 SmViewShell
*pView
= GetView();
293 DBG_ASSERT( pView
, "view shell missing" );
294 Point
aPos( 50, 75 );
297 SmGraphicWindow
&rWin
= pView
->GetGraphicWindow();
298 aPos
= Point( rWin
.OutputToScreenPixel(
299 Point( rWin
.GetSizePixel().Width() - aWndSize
.Width(), 0) ) );
310 BOOL
SmToolBoxWindow::Close()
312 SmViewShell
*pViewSh
= GetView();
314 pViewSh
->GetViewFrame()->GetDispatcher()->Execute(
315 SID_TOOLBOX
, SFX_CALLMODE_STANDARD
,
316 new SfxBoolItem(SID_TOOLBOX
, FALSE
), 0L);
320 void SmToolBoxWindow::GetFocus()
322 // give focus to category toolbox
323 // (allow for cursor travelling when a category is selected with the mouse)
324 aToolBoxCat
.GrabFocus();
327 void SmToolBoxWindow::SetCategory(USHORT nCategoryRID
)
329 if (nCategoryRID
!= nActiveCategoryRID
)
331 ApplyImageLists( nCategoryRID
);
334 // check for valid resource id
335 switch (nCategoryRID
)
337 case RID_UNBINOPS_CAT
: nLines
= 4; break;
338 case RID_RELATIONS_CAT
: nLines
= 5; break;
339 case RID_SETOPERATIONS_CAT
: nLines
= 5; break;
340 case RID_FUNCTIONS_CAT
: nLines
= 5; break;
341 case RID_OPERATORS_CAT
: nLines
= 3; break;
342 case RID_ATTRIBUTES_CAT
: nLines
= 5; break;
343 case RID_MISC_CAT
: nLines
= 4; break;
344 case RID_BRACKETS_CAT
: nLines
= 5; break;
345 case RID_FORMAT_CAT
: nLines
= 3; break;
347 // nothing to be done
353 sal_Int16 nIdx
= GetToolBoxCategoriesIndex( nCategoryRID
);
354 DBG_ASSERT( nIdx
>= 0, "unkown category" );
356 pToolBoxCmd
= vToolBoxCategories
[nIdx
];
358 // calculate actual size of window to use
359 Size
aCatSize( aToolBoxCat
.CalcWindowSizePixel( 2 ) );
360 Size
aCmdSize( pToolBoxCmd
->CalcWindowSizePixel( nLines
) );
361 DBG_ASSERT( aCatSize
.Width() == aCmdSize
.Width(), "width mismatch" );
362 // main window settings
363 Size
aWndSize ( aCatSize
.Width(), pToolBoxCmd
->GetPosPixel().Y() + aCmdSize
.Height() + 3);
364 SetOutputSizePixel( aWndSize
);
366 if (nActiveCategoryRID
)
367 aToolBoxCat
.CheckItem(nActiveCategoryRID
, FALSE
);
368 nActiveCategoryRID
= nCategoryRID
;
369 aToolBoxCat
.CheckItem(nActiveCategoryRID
, TRUE
);
376 IMPL_LINK_INLINE_START( SmToolBoxWindow
, CategoryClickHdl
, ToolBox
*, pToolBox
)
378 int nItemId
= pToolBox
->GetCurItemId();
380 SetCategory( sal::static_int_cast
< USHORT
>(nItemId
) );
383 IMPL_LINK_INLINE_END( SmToolBoxWindow
, CategoryClickHdl
, ToolBox
*, pToolBox
)
386 IMPL_LINK_INLINE_START( SmToolBoxWindow
, CmdSelectHdl
, ToolBox
*, pToolBox
)
388 SmViewShell
*pViewSh
= GetView();
390 pViewSh
->GetViewFrame()->GetDispatcher()->Execute(
391 SID_INSERTCOMMAND
, SFX_CALLMODE_STANDARD
,
392 new SfxInt16Item(SID_INSERTCOMMAND
, pToolBox
->GetCurItemId()), 0L);
395 IMPL_LINK_INLINE_END( SmToolBoxWindow
, CmdSelectHdl
, ToolBox
*, pToolBox
)
398 /**************************************************************************/
400 SFX_IMPL_FLOATINGWINDOW(SmToolBoxWrapper
, SID_TOOLBOXWINDOW
);
402 SmToolBoxWrapper::SmToolBoxWrapper(Window
*pParentWindow
,
403 USHORT nId
, SfxBindings
* pBindings
,
404 SfxChildWinInfo
*pInfo
) :
405 SfxChildWindow(pParentWindow
, nId
)
407 eChildAlignment
= SFX_ALIGN_NOALIGNMENT
;
409 pWindow
= new SmToolBoxWindow(pBindings
, this, pParentWindow
);
410 ((SfxFloatingWindow
*)pWindow
)->Initialize(pInfo
);