summaryrefslogtreecommitdiff
path: root/sd/source/ui/view/ViewTabBar.cxx
blob: 6326e42f2c730713cdbe6dc84caebc8c0574c623 (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
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ViewTabBar.cxx,v $
 *
 *  $Revision: 1.11 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-12 19:09:37 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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 for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"
#include "ViewTabBar.hxx"

#define USE_TAB_CONTROL

#include "ViewShell.hxx"
#include "PaneManager.hxx"
#include "ViewShellBase.hxx"
#include "DrawViewShell.hxx"
#include "FrameView.hxx"
#include "sdresid.hxx"
#include "strings.hrc"
#include "helpids.h"
#ifndef SD_CLIENT_HXX
#include "Client.hxx"
#endif
#include <vcl/tabpage.hxx>

namespace {

enum ViewTabBarEntry {
    VTBE_FIRST = 1,
    VTBE_EDIT_VIEW = VTBE_FIRST,
    VTBE_OUTLINE_VIEW,
    VTBE_NOTES_VIEW,
    VTBE_HANDOUT_VIEW,
    VTBE_SLIDE_VIEW,
    VTBE_LAST = VTBE_SLIDE_VIEW
};

} // end of anonymous namespace




namespace sd {

class ViewTabPage : public TabPage
{
public:
    ViewTabPage (Window* pParent) : TabPage(pParent) {}
    virtual void Resize (void)
    { SetPosSizePixel(Point(0,0),GetParent()->GetOutputSizePixel()); }
};

ViewTabBar::ViewTabBar (ViewShellBase& rViewShellBase, Window* pParent)
    : TabControl (pParent),
      mrViewShellBase (rViewShellBase)
{
    // Add tabs for the views that can be displayed in the center pane.
    InsertPage (VTBE_EDIT_VIEW,
        String (SdResId (STR_DRAW_MODE)));
    InsertPage (VTBE_OUTLINE_VIEW,
        String (SdResId (STR_OUTLINE_MODE)));
    InsertPage (VTBE_NOTES_VIEW,
        String (SdResId (STR_NOTES_MODE)));
    InsertPage (VTBE_HANDOUT_VIEW,
        String (SdResId (STR_HANDOUT_MODE)));
    InsertPage (VTBE_SLIDE_VIEW,
        String (SdResId (STR_SLIDE_MODE)));

    // Set one new tab page for all tab entries.  We need it only to
    // determine the height of the tab bar.
    TabPage* pTabPage = new TabPage (this);
    for (USHORT nIndex=VTBE_FIRST; nIndex<=VTBE_LAST; nIndex++)
    {
        SetTabPage (nIndex, pTabPage);
        pTabPage->Hide();
    }

    // add some space before the tabitems
    SetItemsOffset( Point( 5, 3) );

    // Set help texts.
    SetHelpId (VTBE_EDIT_VIEW, HID_SD_BTN_DRAW);
    SetHelpId (VTBE_SLIDE_VIEW, HID_SD_BTN_SLIDE);
    SetHelpId (VTBE_OUTLINE_VIEW, HID_SD_BTN_OUTLINE);
    SetHelpId (VTBE_NOTES_VIEW, HID_SD_BTN_NOTES);
    SetHelpId (VTBE_HANDOUT_VIEW, HID_SD_BTN_HANDOUT);

    // Register as listener at the view shell base.
    mrViewShellBase.GetPaneManager().AddEventListener (
        LINK(this, ViewTabBar, ViewShellBaseEventHandler));
}




ViewTabBar::~ViewTabBar (void)
{
    // Set all references to the one tab page to NULL and delete the page.
    TabPage* pTabPage = GetTabPage (VTBE_FIRST);
    for (USHORT nIndex=VTBE_FIRST; nIndex<=VTBE_LAST; nIndex++)
    {
        SetTabPage (nIndex, NULL);
    }
    delete pTabPage;

    // Tell the view shell base that we are not able to listen anymore.
    mrViewShellBase.GetPaneManager().RemoveEventListener (
        LINK(this, ViewTabBar, ViewShellBaseEventHandler));
}




void ViewTabBar::ActivatePage (void)
{
    Client* pIPClient = dynamic_cast<Client*>(mrViewShellBase.GetIPClient());
    if (pIPClient==NULL || ! pIPClient->IsObjectInPlaceActive())
    {
        // Call the parent so that the correct tab is highlighted.
        TabControl::ActivatePage ();
        ViewShell::ShellType eType (
            mrViewShellBase.GetPaneManager().GetViewShellType(
                PaneManager::PT_CENTER));
        PageKind ePageKind (PK_STANDARD);
        switch (GetCurPageId())
        {
            case VTBE_EDIT_VIEW:
                eType = ViewShell::ST_IMPRESS;
                ePageKind = PK_STANDARD;
                break;

            case VTBE_OUTLINE_VIEW:
                eType = ViewShell::ST_OUTLINE;
                break;

            case VTBE_NOTES_VIEW:
                eType = ViewShell::ST_NOTES;
                ePageKind = PK_NOTES;
                break;

            case VTBE_HANDOUT_VIEW:
                eType = ViewShell::ST_HANDOUT;
                ePageKind = PK_HANDOUT;
                break;

            case VTBE_SLIDE_VIEW:
                eType = ViewShell::ST_SLIDE_SORTER;
                break;

            default:
                eType = ViewShell::ST_NONE;
                break;
        }

        ViewShell* pViewShell = mrViewShellBase.GetMainViewShell();
        if (pViewShell != NULL)
        {
            FrameView* pFrameView = pViewShell->GetFrameView();
            if (pFrameView != NULL)
            {
                pFrameView->SetViewShEditMode (EM_PAGE, pFrameView->GetPageKind());
                DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pViewShell);
                if (pDrawViewShell != NULL)
                {
                    pFrameView->SetLayerMode (pDrawViewShell->IsLayerModeActive());
                    pFrameView->SetViewShEditMode(EM_PAGE, ePageKind);
                }
            }
        }
        mrViewShellBase.GetPaneManager().RequestMainViewShellChange (eType);
    }
    else
    {
        // When we run into this else branch then we have an active OLE
        // object.  We ignore the request to switch views.  Additionally we
        // put the active tab back to the one for the current view.
        ViewTabBarEntry eActiveView = VTBE_EDIT_VIEW;
        switch (mrViewShellBase.GetPaneManager().GetViewShellType (
            PaneManager::PT_CENTER))
        {
            case ViewShell::ST_DRAW:
            case ViewShell::ST_IMPRESS:
                eActiveView = VTBE_EDIT_VIEW;
                break;

            case ViewShell::ST_OUTLINE:
                eActiveView = VTBE_OUTLINE_VIEW;
                break;

            case ViewShell::ST_SLIDE_SORTER:
                eActiveView = VTBE_SLIDE_VIEW;
                break;

            case ViewShell::ST_NOTES:
                eActiveView = VTBE_NOTES_VIEW;
                break;

            case ViewShell::ST_HANDOUT:
                eActiveView = VTBE_HANDOUT_VIEW;
                break;
            default:
                break;
        }
        SetCurPageId ((USHORT)eActiveView);
        TabControl::ActivatePage ();
    }
}




void ViewTabBar::Paint (const Rectangle& rRect)
{
    Color aOriginalFillColor (GetFillColor());
    Color aOriginalLineColor (GetLineColor());

    // Because the actual window background is transparent--to avoid
    // flickering due to multiple background paintings by this and by child
    // windows--we have to paint the background for this control
    // explicitly: the actual control is not painted over its whole bounding
    // box.
    SetFillColor (GetSettings().GetStyleSettings().GetDialogColor());
    SetLineColor ();
    DrawRect (rRect);
    TabControl::Paint (rRect);

    SetFillColor (aOriginalFillColor);
    SetLineColor (aOriginalLineColor);
}




int ViewTabBar::GetHeight (void)
{
    int nHeight (0);

    TabPage* pActivePage (GetTabPage(GetCurPageId()));
    if (pActivePage!=NULL && IsReallyVisible())
        nHeight = pActivePage->GetPosPixel().Y();

    if (nHeight <= 0)
        // Using a default when the real height can not be determined.  To
        // get correct height this method should be called when the control
        // is visible.
        nHeight = 21;

    return nHeight;
}




IMPL_LINK(ViewTabBar, ViewShellBaseEventHandler, PaneManagerEvent*, pEvent)
{
    if (pEvent->meEventId == PaneManagerEvent::EID_VIEW_SHELL_ADDED
        && pEvent->mePane == PaneManager::PT_CENTER)
    {
        // Select the tab of the currently active view.
        ViewTabBarEntry eActiveView = VTBE_EDIT_VIEW;
        switch (mrViewShellBase.GetPaneManager().GetViewShellType (
            PaneManager::PT_CENTER))
        {
            case ViewShell::ST_DRAW:
            case ViewShell::ST_IMPRESS:
                eActiveView = VTBE_EDIT_VIEW;
                break;

            case ViewShell::ST_OUTLINE:
                eActiveView = VTBE_OUTLINE_VIEW;
                break;

            case ViewShell::ST_SLIDE_SORTER:
                eActiveView = VTBE_SLIDE_VIEW;
                break;

            case ViewShell::ST_NOTES:
                eActiveView = VTBE_NOTES_VIEW;
                break;

            case ViewShell::ST_HANDOUT:
                eActiveView = VTBE_HANDOUT_VIEW;
                break;
            default:
                break;
        }
        SetCurPageId ((USHORT)eActiveView);
    }

    return 0;
}


} // end of namespace sd