summaryrefslogtreecommitdiff
path: root/sfx2/source/dialog/titledockwin.cxx
blob: 680880229324b8e028c7b76beed21b195324b630 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*************************************************************************
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#include "precompiled_sfx2.hxx"

#include "sfx2/titledockwin.hxx"
#include "sfx2/bindings.hxx"
#include "sfx2/dispatch.hxx"
#include "sfxlocal.hrc"
#include "sfxresid.hxx"

#include <svl/eitem.hxx>

//......................................................................................................................
namespace sfx2
{
//......................................................................................................................

    //==================================================================================================================
    //= TitledDockingWindow
    //==================================================================================================================
    //------------------------------------------------------------------------------------------------------------------
    TitledDockingWindow::TitledDockingWindow( SfxBindings* i_pBindings, SfxChildWindow* i_pChildWindow, Window* i_pParent,
            WinBits i_nStyle )
        :SfxDockingWindow( i_pBindings, i_pChildWindow, i_pParent, i_nStyle )
        ,m_sTitle()
        ,m_aToolbox( this )
        ,m_aContentWindow( this, WB_DIALOGCONTROL )
        ,m_aBorder( 3, 1, 3, 3 )
        ,m_bLayoutPending( false )
        ,m_nTitleBarHeight(0)
    {
        impl_construct();
    }

    //------------------------------------------------------------------------------------------------------------------
    TitledDockingWindow::TitledDockingWindow( SfxBindings* i_pBindings, SfxChildWindow* i_pChildWindow, Window* i_pParent,
            const ResId& i_rResId )
        :SfxDockingWindow( i_pBindings, i_pChildWindow, i_pParent, i_rResId )
        ,m_sTitle()
        ,m_aToolbox( this )
        ,m_aContentWindow( this )
        ,m_aBorder( 3, 1, 3, 3 )
        ,m_bLayoutPending( false )
    {
        impl_construct();
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::impl_construct()
    {
        SetBackground( Wallpaper() );

        m_aToolbox.SetSelectHdl( LINK( this, TitledDockingWindow, OnToolboxItemSelected ) );
        m_aToolbox.SetOutStyle( TOOLBOX_STYLE_FLAT );
        m_aToolbox.SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetDialogColor() ) );
        m_aToolbox.Show();
        impl_resetToolBox();

        m_aContentWindow.Show();
    }

    //------------------------------------------------------------------------------------------------------------------
    TitledDockingWindow::~TitledDockingWindow()
    {
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::SetTitle( const String& i_rTitle )
    {
        m_sTitle = i_rTitle;
        Invalidate();
    }

    //------------------------------------------------------------------------------------------------------------------
    String TitledDockingWindow::GetTitle() const
    {
        return impl_getTitle();
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::SetText( const String& i_rText )
    {
        SfxDockingWindow::SetText( i_rText );
        if ( m_sTitle.Len() == 0 )
            // our text is used as title, too => repaint
            Invalidate();
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::Resize()
    {
        SfxDockingWindow::Resize();
        impl_scheduleLayout();
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::onLayoutDone()
    {
        // not interested in
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::impl_scheduleLayout()
    {
        m_bLayoutPending = true;
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::impl_layout()
    {
        m_bLayoutPending = false;

        m_aToolbox.ShowItem( 1, !IsFloatingMode() );

        const Size aToolBoxSize( m_aToolbox.CalcWindowSizePixel() );
        Size aWindowSize( GetOutputSizePixel() );

        // position the tool box
        m_nTitleBarHeight = GetSettings().GetStyleSettings().GetTitleHeight();
        if ( aToolBoxSize.Height() > m_nTitleBarHeight )
            m_nTitleBarHeight = aToolBoxSize.Height();
        m_aToolbox.SetPosSizePixel(
            Point(
                aWindowSize.Width() - aToolBoxSize.Width(),
                ( m_nTitleBarHeight - aToolBoxSize.Height() ) / 2
            ),
            aToolBoxSize
        );

        // Place the content window.
        if ( m_nTitleBarHeight < aToolBoxSize.Height() )
            m_nTitleBarHeight = aToolBoxSize.Height();
        aWindowSize.Height() -= m_nTitleBarHeight;
        m_aContentWindow.SetPosSizePixel(
            Point( m_aBorder.Left(), m_nTitleBarHeight + m_aBorder.Top() ),
            Size(
                aWindowSize.Width() - m_aBorder.Left() - m_aBorder.Right(),
                aWindowSize.Height() - m_aBorder.Top() - m_aBorder.Bottom()
            )
        );

        onLayoutDone();
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::Paint( const Rectangle& i_rArea )
    {
        if ( m_bLayoutPending )
            impl_layout();

        SfxDockingWindow::Paint( i_rArea );

        Push( PUSH_FONT | PUSH_FILLCOLOR | PUSH_LINECOLOR );

        SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
        SetLineColor();

        // bold font
        Font aFont( GetFont() );
        aFont.SetWeight( WEIGHT_BOLD );
        SetFont( aFont );

        // Set border values.
        Size aWindowSize( GetOutputSizePixel() );
        int nOuterLeft = 0;
        int nInnerLeft = nOuterLeft + m_aBorder.Left() - 1;
        int nOuterRight = aWindowSize.Width() - 1;
        int nInnerRight = nOuterRight - m_aBorder.Right() + 1;
        int nInnerTop = m_nTitleBarHeight + m_aBorder.Top() - 1;
        int nOuterBottom = aWindowSize.Height() - 1;
        int nInnerBottom = nOuterBottom - m_aBorder.Bottom() + 1;

        // Paint title bar background.
        Rectangle aTitleBarBox( Rectangle(
            nOuterLeft,
            0,
            nOuterRight,
            nInnerTop-1
        ) );
        DrawRect( aTitleBarBox );

        if ( nInnerLeft > nOuterLeft )
            DrawRect( Rectangle( nOuterLeft, nInnerTop, nInnerLeft, nInnerBottom ) );
        if ( nOuterRight > nInnerRight )
            DrawRect( Rectangle( nInnerRight, nInnerTop, nOuterRight, nInnerBottom ) );
        if ( nInnerBottom < nOuterBottom )
            DrawRect( Rectangle( nOuterLeft, nInnerBottom, nOuterRight, nOuterBottom ) );

        // Paint bevel border.
        SetFillColor();
        SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
        if ( m_aBorder.Top() > 0 )
            DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerLeft, nInnerBottom ) );
        if ( m_aBorder.Left() > 0 )
            DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerRight, nInnerTop ) );

        SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
        if ( m_aBorder.Bottom() > 0 )
            DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerLeft, nInnerBottom ) );
        if ( m_aBorder.Right() > 0 )
            DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerRight, nInnerTop ) );

        // Paint title bar text.
        SetLineColor( GetSettings().GetStyleSettings().GetActiveTextColor() );
        aTitleBarBox.Left() += 3;
        DrawText( aTitleBarBox, impl_getTitle(), TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );

        // Restore original values of the output device.
        Pop();
    }

    //------------------------------------------------------------------------------------------------------------------
    String TitledDockingWindow::impl_getTitle() const
    {
        return m_sTitle.Len() ? m_sTitle : GetText();
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::impl_resetToolBox()
    {
        m_aToolbox.Clear();

        // Get the closer bitmap and set it as right most button.
        Image aImage( SfxResId( SFX_IMG_CLOSE_DOC ) );
        Image aImageHC( SfxResId( SFX_IMG_CLOSE_DOC_HC ) );
        m_aToolbox.InsertItem( 1,
                GetSettings().GetStyleSettings().GetHighContrastMode()
            ?   aImageHC
            :   aImage
        );
        m_aToolbox.ShowItem( 1 );
    }

    //------------------------------------------------------------------------------------------------------------------
    USHORT TitledDockingWindow::impl_addDropDownToolBoxItem( const String& i_rItemText, const rtl::OString& i_nHelpId, const Link& i_rCallback )
    {
        // Add the menu before the closer button.
        const USHORT nItemCount( m_aToolbox.GetItemCount() );
        const USHORT nItemId( nItemCount + 1 );
        m_aToolbox.InsertItem( nItemId, i_rItemText, TIB_DROPDOWNONLY, nItemCount > 0 ? nItemCount - 1 : TOOLBOX_APPEND );
        m_aToolbox.SetHelpId( nItemId, i_nHelpId );
        m_aToolbox.SetClickHdl( i_rCallback );
        m_aToolbox.SetDropdownClickHdl( i_rCallback );

        // The tool box has likely changed its size. The title bar has to be
        // resized.
        impl_scheduleLayout();
        Invalidate();

        return nItemId;
    }

    //------------------------------------------------------------------------------------------------------------------
    IMPL_LINK( TitledDockingWindow, OnToolboxItemSelected, ToolBox*, pToolBox )
    {
        const USHORT nId = pToolBox->GetCurItemId();

        if ( nId == 1 )
        {
            // the closer
            EndTracking();
            const sal_uInt16 nChildWindowId( GetChildWindow_Impl()->GetType() );
            const SfxBoolItem aVisibility( nChildWindowId, FALSE );
            GetBindings().GetDispatcher()->Execute(
                nChildWindowId,
                SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
                &aVisibility,
                NULL
            );
        }

        return 0;
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::StateChanged( StateChangedType i_nType )
    {
        switch ( i_nType )
        {
            case STATE_CHANGE_INITSHOW:
                impl_scheduleLayout();
                break;
        }
        SfxDockingWindow::StateChanged( i_nType );
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::EndDocking( const Rectangle& i_rRect, BOOL i_bFloatMode )
    {
        SfxDockingWindow::EndDocking( i_rRect, i_bFloatMode );

        if ( m_aEndDockingHdl.IsSet() )
            m_aEndDockingHdl.Call( this );
    }

    //------------------------------------------------------------------------------------------------------------------
    void TitledDockingWindow::DataChanged( const DataChangedEvent& i_rDataChangedEvent )
    {
        SfxDockingWindow::DataChanged( i_rDataChangedEvent );

        switch ( i_rDataChangedEvent.GetType() )
        {
            case DATACHANGED_SETTINGS:
                if ( ( i_rDataChangedEvent.GetFlags() & SETTINGS_STYLE ) == 0)
                    break;
                // else fall through.
            case DATACHANGED_FONTS:
            case DATACHANGED_FONTSUBSTITUTION:
            {
                const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();

                // Font.
                Font aFont = rStyleSettings.GetAppFont();
                if ( IsControlFont() )
                    aFont.Merge( GetControlFont() );
                SetZoomedPointFont( aFont );

                // Color.
                Color aColor;
                if ( IsControlForeground() )
                    aColor = GetControlForeground();
                else
                    aColor = rStyleSettings.GetButtonTextColor();
                SetTextColor( aColor );
                SetTextFillColor();

                impl_scheduleLayout();
                Invalidate();
            }
            break;
        }
    }

//......................................................................................................................
} // namespace sfx2
//......................................................................................................................