Line data Source code
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 "menuwindow.hxx"
21 : #include "menuitemlist.hxx"
22 :
23 : #include <vcl/help.hxx>
24 : #include <vcl/menu.hxx>
25 : #include <vcl/settings.hxx>
26 : #include <vcl/svapp.hxx>
27 : #include <vcl/window.hxx>
28 :
29 5496 : void MenuWindow::ImplInitMenuWindow(vcl::Window* pWin, bool bFont, bool bMenuBar)
30 : {
31 5496 : const StyleSettings& rStyleSettings = pWin->GetSettings().GetStyleSettings();
32 :
33 5496 : if ( bFont )
34 5496 : pWin->SetPointFont( rStyleSettings.GetMenuFont() );
35 5496 : if( bMenuBar )
36 : {
37 5480 : const BitmapEx& rPersonaBitmap = Application::GetSettings().GetStyleSettings().GetPersonaHeader();
38 5480 : if ( !rPersonaBitmap.IsEmpty() )
39 : {
40 0 : Wallpaper aWallpaper( rPersonaBitmap );
41 0 : aWallpaper.SetStyle( WALLPAPER_TOPRIGHT );
42 0 : aWallpaper.SetColor( Application::GetSettings().GetStyleSettings().GetWorkspaceColor() );
43 :
44 0 : pWin->SetBackground( aWallpaper );
45 0 : pWin->SetPaintTransparent( false );
46 0 : pWin->SetParentClipMode( 0 );
47 : }
48 5480 : else if ( pWin->IsNativeControlSupported( CTRL_MENUBAR, PART_ENTIRE_CONTROL ) )
49 : {
50 0 : pWin->SetBackground(); // background will be drawn by NWF
51 : }
52 : else
53 : {
54 5480 : Wallpaper aWallpaper;
55 5480 : aWallpaper.SetStyle( WALLPAPER_APPLICATIONGRADIENT );
56 5480 : pWin->SetBackground( aWallpaper );
57 5480 : pWin->SetPaintTransparent( false );
58 5480 : pWin->SetParentClipMode( 0 );
59 5480 : }
60 : }
61 : else
62 : {
63 16 : if( pWin->IsNativeControlSupported( CTRL_MENU_POPUP, PART_ENTIRE_CONTROL ) )
64 : {
65 0 : pWin->SetBackground(); // background will be drawn by NWF
66 : }
67 : else
68 16 : pWin->SetBackground( Wallpaper( rStyleSettings.GetMenuColor() ) );
69 : }
70 :
71 5496 : if ( bMenuBar )
72 5480 : pWin->SetTextColor( rStyleSettings.GetMenuBarTextColor() );
73 : else
74 16 : pWin->SetTextColor( rStyleSettings.GetMenuTextColor() );
75 5496 : pWin->SetTextFillColor();
76 5496 : pWin->SetLineColor();
77 5496 : }
78 :
79 0 : static sal_uLong ImplChangeTipTimeout( sal_uLong nTimeout, vcl::Window *pWindow )
80 : {
81 0 : AllSettings aAllSettings( pWindow->GetSettings() );
82 0 : HelpSettings aHelpSettings( aAllSettings.GetHelpSettings() );
83 0 : sal_uLong nRet = aHelpSettings.GetTipTimeout();
84 0 : aHelpSettings.SetTipTimeout( nTimeout );
85 0 : aAllSettings.SetHelpSettings( aHelpSettings );
86 0 : pWindow->SetSettings( aAllSettings );
87 0 : return nRet;
88 : }
89 :
90 0 : bool MenuWindow::ImplHandleHelpEvent(vcl::Window* pMenuWindow, Menu* pMenu, sal_uInt16 nHighlightedItem,
91 : const HelpEvent& rHEvt, const Rectangle &rHighlightRect)
92 : {
93 0 : if( ! pMenu )
94 0 : return false;
95 :
96 0 : bool bDone = false;
97 0 : sal_uInt16 nId = 0;
98 :
99 0 : if ( nHighlightedItem != ITEMPOS_INVALID )
100 : {
101 0 : MenuItemData* pItemData = pMenu->GetItemList()->GetDataFromPos( nHighlightedItem );
102 0 : if ( pItemData )
103 0 : nId = pItemData->nId;
104 : }
105 :
106 0 : if ( ( rHEvt.GetMode() & HELPMODE_BALLOON ) && pMenuWindow )
107 : {
108 0 : Point aPos;
109 0 : if( rHEvt.KeyboardActivated() )
110 0 : aPos = rHighlightRect.Center();
111 : else
112 0 : aPos = rHEvt.GetMousePosPixel();
113 :
114 0 : Rectangle aRect( aPos, Size() );
115 0 : if (!pMenu->GetHelpText(nId).isEmpty())
116 0 : Help::ShowBalloon( pMenuWindow, aPos, pMenu->GetHelpText( nId ) );
117 : else
118 : {
119 : // give user a chance to read the full filename
120 0 : sal_uLong oldTimeout=ImplChangeTipTimeout( 60000, pMenuWindow );
121 : // call always, even when strlen==0 to correctly remove tip
122 0 : Help::ShowQuickHelp( pMenuWindow, aRect, pMenu->GetTipHelpText( nId ) );
123 0 : ImplChangeTipTimeout( oldTimeout, pMenuWindow );
124 : }
125 0 : bDone = true;
126 : }
127 0 : else if ( ( rHEvt.GetMode() & HELPMODE_QUICK ) && pMenuWindow )
128 : {
129 0 : Point aPos = rHEvt.GetMousePosPixel();
130 0 : Rectangle aRect( aPos, Size() );
131 : // give user a chance to read the full filename
132 0 : sal_uLong oldTimeout=ImplChangeTipTimeout( 60000, pMenuWindow );
133 : // call always, even when strlen==0 to correctly remove tip
134 0 : Help::ShowQuickHelp( pMenuWindow, aRect, pMenu->GetTipHelpText( nId ) );
135 0 : ImplChangeTipTimeout( oldTimeout, pMenuWindow );
136 0 : bDone = true;
137 : }
138 0 : else if ( rHEvt.GetMode() & (HELPMODE_CONTEXT | HELPMODE_EXTENDED) )
139 : {
140 : // is help in the application selected
141 0 : Help* pHelp = Application::GetHelp();
142 0 : if ( pHelp )
143 : {
144 : // is an id available, then call help with the id, otherwise
145 : // use help-index
146 0 : OUString aCommand = pMenu->GetItemCommand( nId );
147 0 : OString aHelpId( pMenu->GetHelpId( nId ) );
148 0 : if( aHelpId.isEmpty() )
149 0 : aHelpId = OOO_HELP_INDEX;
150 :
151 0 : if ( !aCommand.isEmpty() )
152 0 : pHelp->Start( aCommand, NULL );
153 : else
154 0 : pHelp->Start( OStringToOUString( aHelpId, RTL_TEXTENCODING_UTF8 ), NULL );
155 : }
156 0 : bDone = true;
157 : }
158 0 : return bDone;
159 1233 : }
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|