summaryrefslogtreecommitdiff
path: root/vcl/qt5/Qt5Menu.cxx
blob: 65bf726252df99a7c9d7bfe6349301b22e7fea1d (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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "Qt5Frame.hxx"
#include "Qt5Menu.hxx"

#include <QtWidgets/QtWidgets>

#include <vcl/svapp.hxx>

Qt5Menu::Qt5Menu( bool bMenuBar ) :
    mpVCLMenu( nullptr ),
    mpParentSalMenu( nullptr ),
    mpFrame( nullptr ),
    mbMenuBar( bMenuBar )
{
}

Qt5Menu::~Qt5Menu()
{
    maItems.clear();
}

bool Qt5Menu::VisibleMenuBar()
{
    return false;
}

void Qt5Menu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos )
{
    SolarMutexGuard aGuard;
    Qt5MenuItem *pItem = static_cast<Qt5MenuItem*>( pSalMenuItem );

    if ( nPos == MENU_APPEND )
        maItems.push_back( pItem );
    else
        maItems.insert( maItems.begin() + nPos, pItem );

    pItem->mpParentMenu = this;
}

void Qt5Menu::RemoveItem( unsigned nPos )
{
    SolarMutexGuard aGuard;
    maItems.erase( maItems.begin() + nPos );
}

void Qt5Menu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos )
{
    SolarMutexGuard aGuard;
    Qt5MenuItem *pItem = static_cast< Qt5MenuItem* >( pSalMenuItem );
    Qt5Menu *pQSubMenu = static_cast< Qt5Menu* >( pSubMenu );

    if ( pQSubMenu == nullptr )
        return;

    pQSubMenu->mpParentSalMenu = this;
    pItem->mpSubMenu = pQSubMenu;

}

void Qt5Menu::SetFrame( const SalFrame* pFrame )
{
    SolarMutexGuard aGuard;
    assert(mbMenuBar);
    mpFrame = const_cast<Qt5Frame*>( static_cast<const Qt5Frame*>( pFrame ) );

    mpFrame->SetMenu( this );

    QWidget* pWidget = mpFrame->GetQWidget();
    QMainWindow* pMainWindow = dynamic_cast<QMainWindow*>(pWidget);
    if( pMainWindow )
        mpQMenuBar = pMainWindow->menuBar();

    DoFullMenuUpdate( mpVCLMenu );
}

void Qt5Menu::DoFullMenuUpdate( Menu* pMenuBar, QMenu* pParentMenu )
{
    Menu* pVCLMenu = mpVCLMenu;

    if ( mbMenuBar && mpQMenuBar )
        mpQMenuBar->clear();

    for ( sal_Int32 nItem = 0; nItem < static_cast<sal_Int32>(GetItemCount()); nItem++ )
    {
        Qt5MenuItem *pSalMenuItem = GetItemAtPos( nItem );
        sal_uInt16 nId = pSalMenuItem->mnId;
        OUString aText = pVCLMenu->GetItemText( nId );
        QMenu* pQMenu = pParentMenu;
        NativeItemText( aText );

        if (mbMenuBar && mpQMenuBar)
            // top-level menu
            pQMenu = mpQMenuBar->addMenu( toQString(aText) );
        else
        {
            if( pSalMenuItem->mpSubMenu )
                // submenu
                pQMenu = pQMenu->addMenu( toQString(aText) );
            else
                // leaf menu
                pQMenu->addAction( toQString(aText) );
        }

        if ( pSalMenuItem->mpSubMenu != nullptr )
        {
            pMenuBar->HandleMenuActivateEvent(pSalMenuItem->mpSubMenu->GetMenu());
            pSalMenuItem->mpSubMenu->DoFullMenuUpdate( pMenuBar, pQMenu );
            pMenuBar->HandleMenuDeActivateEvent(pSalMenuItem->mpSubMenu->GetMenu());
        }
    }
}

void Qt5Menu::ShowItem( unsigned nPos, bool bCheck )
{
}

void Qt5Menu::CheckItem( unsigned nPos, bool bCheck )
{
}

void Qt5Menu::EnableItem( unsigned nPos, bool bEnable )
{
}

void Qt5Menu::SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const rtl::OUString& rText )
{
}

void Qt5Menu::SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage)
{
}

void Qt5Menu::SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const vcl::KeyCode& rKeyCode, const OUString& rKeyName )
{
}

void Qt5Menu::GetSystemMenuData( SystemMenuData* pData )
{
}

void Qt5Menu::NativeItemText( OUString& rItemText )
{
    rItemText = rItemText.replace( '~', '&' );
}

Qt5MenuItem::Qt5MenuItem( const SalItemParams* pItemData ) :
    mnId( pItemData->nId ),
    mpVCLMenu( pItemData->pMenu ),
    mpParentMenu( nullptr ),
    mpSubMenu( nullptr )
{
}

Qt5MenuItem::~Qt5MenuItem()
{
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */