Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/window/tabdlg.cxx
Line
Count
Source
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 <vcl/toolkit/fixed.hxx>
21
#include <vcl/layout.hxx>
22
#include <vcl/tabctrl.hxx>
23
#include <vcl/toolkit/tabdlg.hxx>
24
#include <vcl/tabpage.hxx>
25
26
void TabDialog::ImplInitTabDialogData()
27
0
{
28
0
    mpFixedLine     = nullptr;
29
0
    mbPosControls   = true;
30
0
}
31
32
void TabDialog::ImplPosControls()
33
0
{
34
0
    if (isLayoutEnabled())
35
0
        return;
36
37
0
    Size        aCtrlSize( IMPL_MINSIZE_BUTTON_WIDTH, IMPL_MINSIZE_BUTTON_HEIGHT );
38
0
    tools::Long        nDownCtrl = 0;
39
0
    tools::Long        nOffY = 0;
40
0
    vcl::Window*     pTabControl = nullptr;
41
42
0
    vcl::Window* pChild = GetWindow( GetWindowType::FirstChild );
43
0
    while ( pChild )
44
0
    {
45
0
        if ( pChild->IsVisible() )
46
0
        {
47
0
            if (pChild->GetType() == WindowType::TABCONTROL || isContainerWindow(*pChild))
48
0
                pTabControl = pChild;
49
0
            else if ( pTabControl )
50
0
            {
51
0
                Size aOptimalSize(pChild->get_preferred_size());
52
0
                tools::Long nTxtWidth = aOptimalSize.Width();
53
0
                if ( nTxtWidth > aCtrlSize.Width() )
54
0
                    aCtrlSize.setWidth( nTxtWidth );
55
0
                tools::Long nTxtHeight = aOptimalSize.Height();
56
0
                if ( nTxtHeight > aCtrlSize.Height() )
57
0
                    aCtrlSize.setHeight( nTxtHeight );
58
0
                nDownCtrl++;
59
0
            }
60
0
            else
61
0
            {
62
0
                tools::Long nHeight = pChild->GetSizePixel().Height();
63
0
                if ( nHeight > nOffY )
64
0
                    nOffY = nHeight;
65
0
            }
66
0
        }
67
68
0
        pChild = pChild->GetWindow( GetWindowType::Next );
69
0
    }
70
71
    // do we have a TabControl ?
72
0
    if ( pTabControl )
73
0
    {
74
        // adapt offset for other controls by an extra distance
75
0
        if ( nOffY )
76
0
            nOffY += IMPL_DIALOG_BAR_OFFSET*2 + 2;
77
78
0
        Point   aTabOffset( IMPL_DIALOG_OFFSET, IMPL_DIALOG_OFFSET+nOffY );
79
80
0
        if (isContainerWindow(*pTabControl))
81
0
            pTabControl->SetSizePixel(pTabControl->get_preferred_size());
82
83
0
        Size    aTabSize = pTabControl->GetSizePixel();
84
85
0
        Size    aDlgSize( aTabSize.Width() + IMPL_DIALOG_OFFSET*2,
86
0
                          aTabSize.Height() + IMPL_DIALOG_OFFSET*2 + nOffY );
87
88
        // adapt positioning
89
0
        pTabControl->SetPosPixel( aTabOffset );
90
91
        // position all other Children
92
0
        bool bTabCtrl   = false;
93
0
        int  nLines     = 0;
94
0
        tools::Long nX;
95
0
        tools::Long nY         = aDlgSize.Height();
96
0
        tools::Long nTopX      = IMPL_DIALOG_OFFSET;
97
98
        // all buttons are right aligned under Windows 95
99
0
        nX = IMPL_DIALOG_OFFSET;
100
0
        tools::Long nCtrlBarWidth = ((aCtrlSize.Width()+IMPL_DIALOG_OFFSET)*nDownCtrl)-IMPL_DIALOG_OFFSET;
101
0
        if ( nCtrlBarWidth <= aTabSize.Width() )
102
0
            nX = aTabSize.Width() - nCtrlBarWidth + IMPL_DIALOG_OFFSET;
103
104
0
        vcl::Window* pChild2 = GetWindow( GetWindowType::FirstChild );
105
0
        while ( pChild2 )
106
0
        {
107
0
            if ( pChild2->IsVisible() )
108
0
            {
109
0
                if ( pChild2 == pTabControl )
110
0
                    bTabCtrl = true;
111
0
                else if ( bTabCtrl )
112
0
                {
113
0
                    if ( !nLines )
114
0
                        nLines = 1;
115
116
0
                    if ( nX+aCtrlSize.Width()-IMPL_DIALOG_OFFSET > aTabSize.Width() )
117
0
                    {
118
0
                        nY += aCtrlSize.Height()+IMPL_DIALOG_OFFSET;
119
0
                        nX  = IMPL_DIALOG_OFFSET;
120
0
                        nLines++;
121
0
                    }
122
123
0
                    pChild2->SetPosSizePixel( Point( nX, nY ), aCtrlSize );
124
0
                    nX += aCtrlSize.Width()+IMPL_DIALOG_OFFSET;
125
0
                }
126
0
                else
127
0
                {
128
0
                    Size aChildSize = pChild2->GetSizePixel();
129
0
                    pChild2->SetPosPixel( Point( nTopX, (nOffY-aChildSize.Height())/2 ) );
130
0
                    nTopX += aChildSize.Width()+2;
131
0
                }
132
0
            }
133
134
0
            pChild2 = pChild2->GetWindow( GetWindowType::Next );
135
0
        }
136
137
0
        aDlgSize.AdjustHeight(nLines * (aCtrlSize.Height()+IMPL_DIALOG_OFFSET) );
138
0
        SetOutputSizePixel( aDlgSize );
139
0
    }
140
141
    // store offset
142
0
    if ( nOffY )
143
0
    {
144
0
        Size aDlgSize = GetOutputSizePixel();
145
0
        if ( !mpFixedLine )
146
0
            mpFixedLine = VclPtr<FixedLine>::Create( this );
147
0
        mpFixedLine->SetPosSizePixel( Point( 0, nOffY ),
148
0
                                      Size( aDlgSize.Width(), 2 ) );
149
0
        mpFixedLine->Show();
150
0
    }
151
152
0
    mbPosControls = false;
153
0
}
154
155
TabDialog::TabDialog( vcl::Window* pParent, WinBits nStyle ) :
156
0
    Dialog( WindowType::TABDIALOG )
157
0
{
158
0
    ImplInitTabDialogData();
159
0
    ImplInitDialog( pParent, nStyle );
160
0
}
Unexecuted instantiation: TabDialog::TabDialog(vcl::Window*, long)
Unexecuted instantiation: TabDialog::TabDialog(vcl::Window*, long)
161
162
TabDialog::~TabDialog()
163
0
{
164
0
    disposeOnce();
165
0
}
166
167
void TabDialog::dispose()
168
0
{
169
0
    mpFixedLine.disposeAndClear();
170
0
    Dialog::dispose();
171
0
}
172
173
void TabDialog::StateChanged( StateChangedType nType )
174
0
{
175
0
    if ( nType == StateChangedType::InitShow )
176
0
    {
177
        // Calculate the Layout only for the initialized state
178
0
        if ( mbPosControls )
179
0
            ImplPosControls();
180
0
    }
181
0
    Dialog::StateChanged( nType );
182
0
}
183
184
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */