LibreOffice Module vcl (master)  1
menu.cxx
Go to the documentation of this file.
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 <tools/diagnose_ex.h>
21 #include <sal/log.hxx>
22 
23 #include <comphelper/lok.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/mnemonic.hxx>
26 #include <vcl/image.hxx>
27 #include <vcl/event.hxx>
28 #include <vcl/help.hxx>
29 #include <vcl/floatwin.hxx>
30 #include <vcl/decoview.hxx>
31 #include <vcl/menu.hxx>
32 #include <vcl/taskpanelist.hxx>
33 #include <vcl/controllayout.hxx>
34 #include <vcl/settings.hxx>
36 
37 #include <salinst.hxx>
38 #include <svdata.hxx>
39 #include <strings.hrc>
40 #include <window.h>
41 #include <salmenu.hxx>
42 #include <salframe.hxx>
43 
44 #include "menubarwindow.hxx"
45 #include "menufloatingwindow.hxx"
46 #include "menuitemlist.hxx"
47 
48 #include <com/sun/star/uno/Reference.h>
49 #include <com/sun/star/lang/XComponent.hpp>
50 #include <com/sun/star/accessibility/XAccessible.hpp>
51 #include <vcl/toolkit/unowrap.hxx>
52 
53 #include <vcl/configsettings.hxx>
54 
55 #include <map>
56 #include <string_view>
57 #include <vector>
58 
59 namespace vcl
60 {
61 
63 {
64  std::vector< sal_uInt16 > m_aLineItemIds;
65  std::map< sal_uInt16, tools::Rectangle > m_aVisibleItemBoundRects;
66 };
67 
68 }
69 
70 using namespace vcl;
71 
72 #define EXTRAITEMHEIGHT 4
73 #define SPACE_AROUND_TITLE 4
74 
75 static bool ImplAccelDisabled()
76 {
77  // display of accelerator strings may be suppressed via configuration
78  static int nAccelDisabled = -1;
79 
80  if( nAccelDisabled == -1 )
81  {
82  OUString aStr =
84  getValue( "Menu", "SuppressAccelerators" );
85  nAccelDisabled = aStr.equalsIgnoreAsciiCase("true") ? 1 : 0;
86  }
87  return nAccelDisabled == 1;
88 }
89 
90 static void ImplSetMenuItemData( MenuItemData* pData )
91 {
92  // convert data
93  if ( !pData->aImage )
94  pData->eType = MenuItemType::STRING;
95  else if ( pData->aText.isEmpty() )
96  pData->eType = MenuItemType::IMAGE;
97  else
99 }
100 
101 namespace {
102 
103 void ImplClosePopupToolBox( const VclPtr<vcl::Window>& pWin )
104 {
105  if ( pWin->GetType() == WindowType::TOOLBOX && ImplGetDockingManager()->IsInPopupMode( pWin ) )
106  {
108  if ( pWrapper && pWrapper->GetFloatingWindow() )
110  }
111 }
112 
113 // TODO: Move to common code with the same function in toolbox
114 // Draw the ">>" - more indicator at the coordinates
115 void lclDrawMoreIndicator(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
116 {
118  rRenderContext.SetLineColor();
119 
120  if (rRenderContext.GetSettings().GetStyleSettings().GetFaceColor().IsDark())
121  rRenderContext.SetFillColor(COL_WHITE);
122  else
123  rRenderContext.SetFillColor(COL_BLACK);
124  float fScaleFactor = rRenderContext.GetDPIScaleFactor();
125 
126  int linewidth = 1 * fScaleFactor;
127  int space = 4 * fScaleFactor;
128 
129  long width = 8 * fScaleFactor;
130  long height = 5 * fScaleFactor;
131 
132  //Keep odd b/c drawing code works better
133  if ( height % 2 == 0 )
134  height--;
135 
136  long heightOrig = height;
137 
138  long x = rRect.Left() + (rRect.getWidth() - width)/2 + 1;
139  long y = rRect.Top() + (rRect.getHeight() - height)/2 + 1;
140  while( height >= 1)
141  {
142  rRenderContext.DrawRect( tools::Rectangle( x, y, x + linewidth, y ) );
143  x += space;
144  rRenderContext.DrawRect( tools::Rectangle( x, y, x + linewidth, y ) );
145  x -= space;
146  y++;
147  if( height <= heightOrig / 2 + 1) x--;
148  else x++;
149  height--;
150  }
151  rRenderContext.Pop();
152 }
153 
154 } // end anonymous namespace
155 
156 
158  : mpFirstDel(nullptr),
159  pItemList(new MenuItemList),
160  pStartedFrom(nullptr),
161  pWindow(nullptr),
162  nTitleHeight(0),
163  nEventId(nullptr),
164  mnHighlightedItemPos(ITEMPOS_INVALID),
165  nMenuFlags(MenuFlags::NONE),
166  nSelectedId(0),
167  nImgOrChkPos(0),
168  nTextPos(0),
169  bCanceled(false),
170  bInCallback(false),
171  bKilled(false)
172 {
173 }
174 
176 {
177  disposeOnce();
178 }
179 
181 {
183 
184  // at the window free the reference to the accessible component
185  // and make sure the MenuFloatingWindow knows about our destruction
186  if ( pWindow )
187  {
188  MenuFloatingWindow* pFloat = static_cast<MenuFloatingWindow*>(pWindow.get());
189  if( pFloat->pMenu.get() == this )
190  pFloat->pMenu.clear();
191  pWindow->SetAccessible( css::uno::Reference< css::accessibility::XAccessible >() );
192  }
193 
194  // dispose accessible components
195  if ( mxAccessible.is() )
196  {
197  css::uno::Reference< css::lang::XComponent> xComponent( mxAccessible, css::uno::UNO_QUERY );
198  if ( xComponent.is() )
199  xComponent->dispose();
200  }
201 
202  if ( nEventId )
204 
205  // Notify deletion of this menu
206  ImplMenuDelData* pDelData = mpFirstDel;
207  while ( pDelData )
208  {
209  pDelData->mpMenu = nullptr;
210  pDelData = pDelData->mpNext;
211  }
212 
213  bKilled = true;
214 
215  pItemList->Clear();
216  mpLayoutData.reset();
217 
218  // Native-support: destroy SalMenu
220 
222  pWindow.clear();
224 }
225 
227 {
228  MnemonicGenerator aMnemonicGenerator;
229  size_t n;
230  for ( n = 0; n < pItemList->size(); n++ )
231  {
232  MenuItemData* pData = pItemList->GetDataFromPos( n );
233  if ( ! (pData->nBits & MenuItemBits::NOSELECT ) )
234  aMnemonicGenerator.RegisterMnemonic( pData->aText );
235  }
236  for ( n = 0; n < pItemList->size(); n++ )
237  {
238  MenuItemData* pData = pItemList->GetDataFromPos( n );
239  if ( ! (pData->nBits & MenuItemBits::NOSELECT ) )
240  pData->aText = aMnemonicGenerator.CreateMnemonic( pData->aText );
241  }
242 }
243 
245 {
246  bInCallback = true;
247 
248  ImplMenuDelData aDelData( this );
249 
251 
252  if( !aDelData.isDeleted() )
253  {
254  if ( !aActivateHdl.Call( this ) )
255  {
256  if( !aDelData.isDeleted() )
257  {
258  Menu* pStartMenu = ImplGetStartMenu();
259  if ( pStartMenu && ( pStartMenu != this ) )
260  {
261  pStartMenu->bInCallback = true;
262  // MT 11/01: Call EventListener here? I don't know...
263  pStartMenu->aActivateHdl.Call( this );
264  pStartMenu->bInCallback = false;
265  }
266  }
267  }
268  bInCallback = false;
269  }
270 
271  if (!aDelData.isDeleted() && !(nMenuFlags & MenuFlags::NoAutoMnemonics))
273 }
274 
276 {
277  for ( size_t n = pItemList->size(); n; )
278  {
279  MenuItemData* pData = pItemList->GetDataFromPos( --n );
280  if ( pData->bIsTemporary )
281  {
282  if ( ImplGetSalMenu() )
283  ImplGetSalMenu()->RemoveItem( n );
284 
285  pItemList->Remove( n );
286  }
287  }
288 
289  bInCallback = true;
290 
291  ImplMenuDelData aDelData( this );
292 
293  Menu* pStartMenu = ImplGetStartMenu();
295 
296  if( !aDelData.isDeleted() )
297  {
298  if ( !aDeactivateHdl.Call( this ) )
299  {
300  if( !aDelData.isDeleted() )
301  {
302  if ( pStartMenu && ( pStartMenu != this ) )
303  {
304  pStartMenu->bInCallback = true;
305  pStartMenu->aDeactivateHdl.Call( this );
306  pStartMenu->bInCallback = false;
307  }
308  }
309  }
310  }
311 
312  if( !aDelData.isDeleted() )
313  {
314  bInCallback = false;
315  }
316 }
317 
319 {
321  if ( pData && (pData->nBits & MenuItemBits::AUTOCHECK) )
322  {
323  bool bChecked = IsItemChecked( nSelectedId );
324  if ( pData->nBits & MenuItemBits::RADIOCHECK )
325  {
326  if ( !bChecked )
328  }
329  else
330  CheckItem( nSelectedId, !bChecked );
331  }
332 
333  // call select
334  ImplSVData* pSVData = ImplGetSVData();
335  pSVData->maAppData.mpActivePopupMenu = nullptr; // if new execute in select()
336  nEventId = Application::PostUserEvent( LINK( this, Menu, ImplCallSelect ) );
337 }
338 
340 {
341  ImplMenuDelData aDelData( this );
342 
344  if (aDelData.isDeleted())
345  return;
346  if (aSelectHdl.Call(this))
347  return;
348  if (aDelData.isDeleted())
349  return;
350  Menu* pStartMenu = ImplGetStartMenu();
351  if (!pStartMenu || (pStartMenu == this))
352  return;
353  pStartMenu->nSelectedId = nSelectedId;
354  pStartMenu->sSelectedIdent = sSelectedIdent;
355  pStartMenu->aSelectHdl.Call( this );
356 }
357 
358 #if defined(MACOSX)
359 void Menu::ImplSelectWithStart( Menu* pSMenu )
360 {
361  auto pOldStartedFrom = pStartedFrom;
362  pStartedFrom = pSMenu;
363  auto pOldStartedStarted = pOldStartedFrom ? pOldStartedFrom->pStartedFrom : VclPtr<Menu>();
364  Select();
365  if( pOldStartedFrom )
366  pOldStartedFrom->pStartedFrom = pOldStartedStarted;
367  pStartedFrom = pOldStartedFrom;
368 }
369 #endif
370 
371 void Menu::ImplCallEventListeners( VclEventId nEvent, sal_uInt16 nPos )
372 {
373  ImplMenuDelData aDelData( this );
374 
375  VclMenuEvent aEvent( this, nEvent, nPos );
376 
377  // This is needed by atk accessibility bridge
378  if ( nEvent == VclEventId::MenuHighlight )
379  {
381  }
382 
383  if ( !aDelData.isDeleted() )
384  {
385  // Copy the list, because this can be destroyed when calling a Link...
386  std::list<Link<VclMenuEvent&,void>> aCopy( maEventListeners );
387  for ( const auto& rLink : aCopy )
388  {
389  if( std::find(maEventListeners.begin(), maEventListeners.end(), rLink) != maEventListeners.end() )
390  rLink.Call( aEvent );
391  }
392  }
393 }
394 
396 {
397  maEventListeners.push_back( rEventListener );
398 }
399 
401 {
402  maEventListeners.remove( rEventListener );
403 }
404 
406  const OUString& rStr, Menu* pMenu,
407  size_t nPos, const OString &rIdent)
408 {
409  // put Item in MenuItemList
410  MenuItemData* pData = pItemList->Insert(nId, MenuItemType::STRING,
411  nBits, rStr, pMenu, nPos, rIdent);
412 
413  // update native menu
414  if (ImplGetSalMenu() && pData->pSalMenuItem)
415  ImplGetSalMenu()->InsertItem(pData->pSalMenuItem.get(), nPos);
416 
417  return pData;
418 }
419 
420 void Menu::InsertItem(sal_uInt16 nItemId, const OUString& rStr, MenuItemBits nItemBits,
421  const OString &rIdent, sal_uInt16 nPos)
422 {
423  SAL_WARN_IF( !nItemId, "vcl", "Menu::InsertItem(): ItemId == 0" );
424  SAL_WARN_IF( GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND, "vcl",
425  "Menu::InsertItem(): ItemId already exists" );
426 
427  // if Position > ItemCount, append
428  if ( nPos >= pItemList->size() )
429  nPos = MENU_APPEND;
430 
431  // put Item in MenuItemList
432  NbcInsertItem(nItemId, nItemBits, rStr, this, nPos, rIdent);
433 
434  vcl::Window* pWin = ImplGetWindow();
435  mpLayoutData.reset();
436  if ( pWin )
437  {
438  ImplCalcSize( pWin );
439  if ( pWin->IsVisible() )
440  pWin->Invalidate();
441  }
443 }
444 
445 void Menu::InsertItem(sal_uInt16 nItemId, const Image& rImage,
446  MenuItemBits nItemBits, const OString &rIdent, sal_uInt16 nPos)
447 {
448  InsertItem(nItemId, OUString(), nItemBits, rIdent, nPos);
449  SetItemImage( nItemId, rImage );
450 }
451 
452 void Menu::InsertItem(sal_uInt16 nItemId, const OUString& rStr,
453  const Image& rImage, MenuItemBits nItemBits,
454  const OString &rIdent, sal_uInt16 nPos)
455 {
456  InsertItem(nItemId, rStr, nItemBits, rIdent, nPos);
457  SetItemImage( nItemId, rImage );
458 }
459 
460 void Menu::InsertItem(const OUString& rCommand, const css::uno::Reference<css::frame::XFrame>& rFrame)
461 {
462  sal_uInt16 nItemId = GetItemCount() + 1;
463 
464  if (rFrame.is())
465  {
466  OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(rFrame));
467  OUString aLabel(CommandInfoProvider::GetPopupLabelForCommand(rCommand, aModuleName));
468  OUString aTooltip(CommandInfoProvider::GetTooltipForCommand(rCommand, rFrame));
469  Image aImage(CommandInfoProvider::GetImageForCommand(rCommand, rFrame));
470 
471  InsertItem(nItemId, aLabel, aImage);
472  SetHelpText(nItemId, aTooltip);
473  }
474  else
475  InsertItem(nItemId, OUString());
476 
477  SetItemCommand(nItemId, rCommand);
478 }
479 
480 
481 void Menu::InsertSeparator(const OString &rIdent, sal_uInt16 nPos)
482 {
483  // do nothing if it's a menu bar
484  if (IsMenuBar())
485  return;
486 
487  // if position > ItemCount, append
488  if ( nPos >= pItemList->size() )
489  nPos = MENU_APPEND;
490 
491  // put separator in item list
492  pItemList->InsertSeparator(rIdent, nPos);
493 
494  // update native menu
495  size_t itemPos = ( nPos != MENU_APPEND ) ? nPos : pItemList->size() - 1;
496  MenuItemData *pData = pItemList->GetDataFromPos( itemPos );
497  if( ImplGetSalMenu() && pData && pData->pSalMenuItem )
498  ImplGetSalMenu()->InsertItem( pData->pSalMenuItem.get(), nPos );
499 
500  mpLayoutData.reset();
501 
503 }
504 
505 void Menu::RemoveItem( sal_uInt16 nPos )
506 {
507  bool bRemove = false;
508 
509  if ( nPos < GetItemCount() )
510  {
511  // update native menu
512  if( ImplGetSalMenu() )
513  ImplGetSalMenu()->RemoveItem( nPos );
514 
515  pItemList->Remove( nPos );
516  bRemove = true;
517  }
518 
519  vcl::Window* pWin = ImplGetWindow();
520  if ( pWin )
521  {
522  ImplCalcSize( pWin );
523  if ( pWin->IsVisible() )
524  pWin->Invalidate();
525  }
526  mpLayoutData.reset();
527 
528  if ( bRemove )
530 }
531 
532 static void ImplCopyItem( Menu* pThis, const Menu& rMenu, sal_uInt16 nPos, sal_uInt16 nNewPos )
533 {
534  MenuItemType eType = rMenu.GetItemType( nPos );
535 
536  if ( eType == MenuItemType::DONTKNOW )
537  return;
538 
539  if ( eType == MenuItemType::SEPARATOR )
540  pThis->InsertSeparator( OString(), nNewPos );
541  else
542  {
543  sal_uInt16 nId = rMenu.GetItemId( nPos );
544 
545  SAL_WARN_IF( pThis->GetItemPos( nId ) != MENU_ITEM_NOTFOUND, "vcl",
546  "Menu::CopyItem(): ItemId already exists" );
547 
548  MenuItemData* pData = rMenu.GetItemList()->GetData( nId );
549 
550  if (!pData)
551  return;
552 
553  if ( eType == MenuItemType::STRINGIMAGE )
554  pThis->InsertItem( nId, pData->aText, pData->aImage, pData->nBits, pData->sIdent, nNewPos );
555  else if ( eType == MenuItemType::STRING )
556  pThis->InsertItem( nId, pData->aText, pData->nBits, pData->sIdent, nNewPos );
557  else
558  pThis->InsertItem( nId, pData->aImage, pData->nBits, pData->sIdent, nNewPos );
559 
560  if ( rMenu.IsItemChecked( nId ) )
561  pThis->CheckItem( nId );
562  if ( !rMenu.IsItemEnabled( nId ) )
563  pThis->EnableItem( nId, false );
564  pThis->SetHelpId( nId, pData->aHelpId );
565  pThis->SetHelpText( nId, pData->aHelpText );
566  pThis->SetAccelKey( nId, pData->aAccelKey );
567  pThis->SetItemCommand( nId, pData->aCommandStr );
568  pThis->SetHelpCommand( nId, pData->aHelpCommandStr );
569 
570  PopupMenu* pSubMenu = rMenu.GetPopupMenu( nId );
571  if ( pSubMenu )
572  {
573  // create auto-copy
574  VclPtr<PopupMenu> pNewMenu = VclPtr<PopupMenu>::Create( *pSubMenu );
575  pThis->SetPopupMenu( nId, pNewMenu );
576  }
577  }
578 }
579 
581 {
582  for ( sal_uInt16 i = GetItemCount(); i; i-- )
583  RemoveItem( 0 );
584 }
585 
586 sal_uInt16 Menu::GetItemCount() const
587 {
588  return static_cast<sal_uInt16>(pItemList->size());
589 }
590 
592 {
593  sal_uInt16 nItems = 0;
594  for ( size_t n = pItemList->size(); n; )
595  {
596  if ( ImplIsVisible( --n ) )
597  nItems++;
598  }
599  return nItems;
600 }
601 
602 sal_uInt16 Menu::ImplGetFirstVisible() const
603 {
604  for ( size_t n = 0; n < pItemList->size(); n++ )
605  {
606  if ( ImplIsVisible( n ) )
607  return n;
608  }
609  return ITEMPOS_INVALID;
610 }
611 
612 sal_uInt16 Menu::ImplGetPrevVisible( sal_uInt16 nPos ) const
613 {
614  for ( size_t n = nPos; n; )
615  {
616  if (ImplIsVisible(--n))
617  return n;
618  }
619  return ITEMPOS_INVALID;
620 }
621 
622 sal_uInt16 Menu::ImplGetNextVisible( sal_uInt16 nPos ) const
623 {
624  for ( size_t n = nPos+1; n < pItemList->size(); n++ )
625  {
626  if ( ImplIsVisible( n ) )
627  return n;
628  }
629  return ITEMPOS_INVALID;
630 }
631 
632 sal_uInt16 Menu::GetItemId(sal_uInt16 nPos) const
633 {
634  MenuItemData* pData = pItemList->GetDataFromPos( nPos );
635 
636  if ( pData )
637  return pData->nId;
638  else
639  return 0;
640 }
641 
642 sal_uInt16 Menu::GetItemId(const OString &rIdent) const
643 {
644  for (size_t n = 0; n < pItemList->size(); ++n)
645  {
646  MenuItemData* pData = pItemList->GetDataFromPos(n);
647  if (pData && pData->sIdent == rIdent)
648  return pData->nId;
649  }
650  return MENU_ITEM_NOTFOUND;
651 }
652 
653 sal_uInt16 Menu::GetItemPos( sal_uInt16 nItemId ) const
654 {
655  size_t nPos;
656  MenuItemData* pData = pItemList->GetData( nItemId, nPos );
657 
658  if ( pData )
659  return static_cast<sal_uInt16>(nPos);
660  else
661  return MENU_ITEM_NOTFOUND;
662 }
663 
664 MenuItemType Menu::GetItemType( sal_uInt16 nPos ) const
665 {
666  MenuItemData* pData = pItemList->GetDataFromPos( nPos );
667 
668  if ( pData )
669  return pData->eType;
670  else
671  return MenuItemType::DONTKNOW;
672 }
673 
674 OString Menu::GetItemIdent(sal_uInt16 nId) const
675 {
676  const MenuItemData* pData = pItemList->GetData(nId);
677  return pData ? pData->sIdent : OString();
678 }
679 
680 void Menu::SetItemBits( sal_uInt16 nItemId, MenuItemBits nBits )
681 {
682  size_t nPos;
683  MenuItemData* pData = pItemList->GetData(nItemId, nPos);
684 
685  if (pData && (pData->nBits != nBits))
686  {
687  pData->nBits = nBits;
688 
689  // update native menu
690  if (ImplGetSalMenu())
691  ImplGetSalMenu()->SetItemBits(nPos, nBits);
692  }
693 }
694 
695 MenuItemBits Menu::GetItemBits( sal_uInt16 nItemId ) const
696 {
698  MenuItemData* pData = pItemList->GetData( nItemId );
699  if ( pData )
700  nBits = pData->nBits;
701  return nBits;
702 }
703 
704 void Menu::SetUserValue(sal_uInt16 nItemId, void* nUserValue, MenuUserDataReleaseFunction aFunc)
705 {
706  MenuItemData* pData = pItemList->GetData(nItemId);
707  if (pData)
708  {
709  if (pData->aUserValueReleaseFunc)
710  pData->aUserValueReleaseFunc(pData->nUserValue);
711  pData->aUserValueReleaseFunc = aFunc;
712  pData->nUserValue = nUserValue;
713  }
714 }
715 
716 void* Menu::GetUserValue( sal_uInt16 nItemId ) const
717 {
718  MenuItemData* pData = pItemList->GetData( nItemId );
719  return pData ? pData->nUserValue : nullptr;
720 }
721 
722 void Menu::SetPopupMenu( sal_uInt16 nItemId, PopupMenu* pMenu )
723 {
724  size_t nPos;
725  MenuItemData* pData = pItemList->GetData( nItemId, nPos );
726 
727  // Item does not exist -> return NULL
728  if ( !pData )
729  return;
730 
731  // same menu, nothing to do
732  if ( static_cast<PopupMenu*>(pData->pSubMenu.get()) == pMenu )
733  return;
734 
735  // remove old menu
736  auto oldSubMenu = pData->pSubMenu;
737 
738  // data exchange
739  pData->pSubMenu = pMenu;
740 
741  // #112023# Make sure pStartedFrom does not point to invalid (old) data
742  if ( pData->pSubMenu )
743  pData->pSubMenu->pStartedFrom = nullptr;
744 
745  // set native submenu
746  if( ImplGetSalMenu() && pData->pSalMenuItem )
747  {
748  if( pMenu )
749  ImplGetSalMenu()->SetSubMenu( pData->pSalMenuItem.get(), pMenu->ImplGetSalMenu(), nPos );
750  else
751  ImplGetSalMenu()->SetSubMenu( pData->pSalMenuItem.get(), nullptr, nPos );
752  }
753 
754  oldSubMenu.disposeAndClear();
755 
757 }
758 
759 PopupMenu* Menu::GetPopupMenu( sal_uInt16 nItemId ) const
760 {
761  MenuItemData* pData = pItemList->GetData( nItemId );
762 
763  if ( pData )
764  return static_cast<PopupMenu*>(pData->pSubMenu.get());
765  else
766  return nullptr;
767 }
768 
769 void Menu::SetAccelKey( sal_uInt16 nItemId, const KeyCode& rKeyCode )
770 {
771  size_t nPos;
772  MenuItemData* pData = pItemList->GetData( nItemId, nPos );
773 
774  if ( !pData )
775  return;
776 
777  if ( pData->aAccelKey == rKeyCode )
778  return;
779 
780  pData->aAccelKey = rKeyCode;
781 
782  // update native menu
783  if( ImplGetSalMenu() && pData->pSalMenuItem )
784  ImplGetSalMenu()->SetAccelerator( nPos, pData->pSalMenuItem.get(), rKeyCode, rKeyCode.GetName() );
785 }
786 
787 KeyCode Menu::GetAccelKey( sal_uInt16 nItemId ) const
788 {
789  MenuItemData* pData = pItemList->GetData( nItemId );
790 
791  if ( pData )
792  return pData->aAccelKey;
793  else
794  return KeyCode();
795 }
796 
797 KeyEvent Menu::GetActivationKey( sal_uInt16 nItemId ) const
798 {
799  KeyEvent aRet;
800  MenuItemData* pData = pItemList->GetData( nItemId );
801  if( pData )
802  {
803  sal_Int32 nPos = pData->aText.indexOf( '~' );
804  if( nPos != -1 && nPos < pData->aText.getLength()-1 )
805  {
806  sal_uInt16 nCode = 0;
807  sal_Unicode cAccel = pData->aText[nPos+1];
808  if( cAccel >= 'a' && cAccel <= 'z' )
809  nCode = KEY_A + (cAccel-'a');
810  else if( cAccel >= 'A' && cAccel <= 'Z' )
811  nCode = KEY_A + (cAccel-'A');
812  else if( cAccel >= '0' && cAccel <= '9' )
813  nCode = KEY_0 + (cAccel-'0');
814 
815  aRet = KeyEvent( cAccel, KeyCode( nCode, KEY_MOD2 ) );
816  }
817 
818  }
819  return aRet;
820 }
821 
822 void Menu::CheckItem( sal_uInt16 nItemId, bool bCheck )
823 {
824  size_t nPos;
825  MenuItemData* pData = pItemList->GetData( nItemId, nPos );
826 
827  if ( !pData || pData->bChecked == bCheck )
828  return;
829 
830  // if radio-check, then uncheck previous
831  if ( bCheck && (pData->nBits & MenuItemBits::AUTOCHECK) &&
832  (pData->nBits & MenuItemBits::RADIOCHECK) )
833  {
834  MenuItemData* pGroupData;
835  sal_uInt16 nGroupPos;
836  sal_uInt16 nItemCount = GetItemCount();
837  bool bFound = false;
838 
839  nGroupPos = nPos;
840  while ( nGroupPos )
841  {
842  pGroupData = pItemList->GetDataFromPos( nGroupPos-1 );
843  if ( pGroupData->nBits & MenuItemBits::RADIOCHECK )
844  {
845  if ( IsItemChecked( pGroupData->nId ) )
846  {
847  CheckItem( pGroupData->nId, false );
848  bFound = true;
849  break;
850  }
851  }
852  else
853  break;
854  nGroupPos--;
855  }
856 
857  if ( !bFound )
858  {
859  nGroupPos = nPos+1;
860  while ( nGroupPos < nItemCount )
861  {
862  pGroupData = pItemList->GetDataFromPos( nGroupPos );
863  if ( pGroupData->nBits & MenuItemBits::RADIOCHECK )
864  {
865  if ( IsItemChecked( pGroupData->nId ) )
866  {
867  CheckItem( pGroupData->nId, false );
868  break;
869  }
870  }
871  else
872  break;
873  nGroupPos++;
874  }
875  }
876  }
877 
878  pData->bChecked = bCheck;
879 
880  // update native menu
881  if( ImplGetSalMenu() )
882  ImplGetSalMenu()->CheckItem( nPos, bCheck );
883 
885 }
886 
887 void Menu::CheckItem( const OString &rIdent , bool bCheck )
888 {
889  CheckItem( GetItemId( rIdent ), bCheck );
890 }
891 
892 bool Menu::IsItemChecked( sal_uInt16 nItemId ) const
893 {
894  size_t nPos;
895  MenuItemData* pData = pItemList->GetData( nItemId, nPos );
896 
897  if ( !pData )
898  return false;
899 
900  return pData->bChecked;
901 }
902 
903 void Menu::EnableItem( sal_uInt16 nItemId, bool bEnable )
904 {
905  size_t nPos;
906  MenuItemData* pItemData = pItemList->GetData( nItemId, nPos );
907 
908  if ( pItemData && ( pItemData->bEnabled != bEnable ) )
909  {
910  pItemData->bEnabled = bEnable;
911 
912  vcl::Window* pWin = ImplGetWindow();
913  if ( pWin && pWin->IsVisible() )
914  {
915  SAL_WARN_IF(!IsMenuBar(), "vcl", "Menu::EnableItem - Popup visible!" );
916  long nX = 0;
917  size_t nCount = pItemList->size();
918  for ( size_t n = 0; n < nCount; n++ )
919  {
920  MenuItemData* pData = pItemList->GetDataFromPos( n );
921  if ( n == nPos )
922  {
923  pWin->Invalidate( tools::Rectangle( Point( nX, 0 ), Size( pData->aSz.Width(), pData->aSz.Height() ) ) );
924  break;
925  }
926  nX += pData->aSz.Width();
927  }
928  }
929  // update native menu
930  if( ImplGetSalMenu() )
931  ImplGetSalMenu()->EnableItem( nPos, bEnable );
932 
934  }
935 }
936 
937 bool Menu::IsItemEnabled( sal_uInt16 nItemId ) const
938 {
939  size_t nPos;
940  MenuItemData* pData = pItemList->GetData( nItemId, nPos );
941 
942  if ( !pData )
943  return false;
944 
945  return pData->bEnabled;
946 }
947 
948 void Menu::ShowItem( sal_uInt16 nItemId, bool bVisible )
949 {
950  size_t nPos;
951  MenuItemData* pData = pItemList->GetData( nItemId, nPos );
952 
953  SAL_WARN_IF(IsMenuBar(), "vcl", "Menu::ShowItem - ignored for menu bar entries!");
954  if (!IsMenuBar()&& pData && (pData->bVisible != bVisible))
955  {
956  vcl::Window* pWin = ImplGetWindow();
957  if ( pWin && pWin->IsVisible() )
958  {
959  SAL_WARN( "vcl", "Menu::ShowItem - ignored for visible popups!" );
960  return;
961  }
962  pData->bVisible = bVisible;
963 
964  // update native menu
965  if( ImplGetSalMenu() )
966  ImplGetSalMenu()->ShowItem( nPos, bVisible );
967  }
968 }
969 
970 void Menu::SetItemText( sal_uInt16 nItemId, const OUString& rStr )
971 {
972  size_t nPos;
973  MenuItemData* pData = pItemList->GetData( nItemId, nPos );
974 
975  if ( !pData )
976  return;
977 
978  if ( rStr != pData->aText )
979  {
980  pData->aText = rStr;
981  // Clear layout for aText.
982  pData->aTextGlyphs.Invalidate();
983  ImplSetMenuItemData( pData );
984  // update native menu
985  if( ImplGetSalMenu() && pData->pSalMenuItem )
986  ImplGetSalMenu()->SetItemText( nPos, pData->pSalMenuItem.get(), rStr );
987 
988  vcl::Window* pWin = ImplGetWindow();
989  mpLayoutData.reset();
990  if (pWin && IsMenuBar())
991  {
992  ImplCalcSize( pWin );
993  if ( pWin->IsVisible() )
994  pWin->Invalidate();
995  }
996 
998  }
999 }
1000 
1001 OUString Menu::GetItemText( sal_uInt16 nItemId ) const
1002 {
1003  size_t nPos;
1004  MenuItemData* pData = pItemList->GetData( nItemId, nPos );
1005 
1006  if ( pData )
1007  return pData->aText;
1008 
1009  return OUString();
1010 }
1011 
1012 void Menu::SetItemImage( sal_uInt16 nItemId, const Image& rImage )
1013 {
1014  size_t nPos;
1015  MenuItemData* pData = pItemList->GetData( nItemId, nPos );
1016 
1017  if ( !pData )
1018  return;
1019 
1020  pData->aImage = rImage;
1021  ImplSetMenuItemData( pData );
1022 
1023  // update native menu
1024  if( ImplGetSalMenu() && pData->pSalMenuItem )
1025  ImplGetSalMenu()->SetItemImage( nPos, pData->pSalMenuItem.get(), rImage );
1026 }
1027 
1028 Image Menu::GetItemImage( sal_uInt16 nItemId ) const
1029 {
1030  MenuItemData* pData = pItemList->GetData( nItemId );
1031 
1032  if ( pData )
1033  return pData->aImage;
1034  else
1035  return Image();
1036 }
1037 
1038 void Menu::SetItemCommand( sal_uInt16 nItemId, const OUString& rCommand )
1039 {
1040  size_t nPos;
1041  MenuItemData* pData = pItemList->GetData( nItemId, nPos );
1042 
1043  if ( pData )
1044  pData->aCommandStr = rCommand;
1045 }
1046 
1047 OUString Menu::GetItemCommand( sal_uInt16 nItemId ) const
1048 {
1049  MenuItemData* pData = pItemList->GetData( nItemId );
1050 
1051  if (pData)
1052  return pData->aCommandStr;
1053 
1054  return OUString();
1055 }
1056 
1057 void Menu::SetHelpCommand( sal_uInt16 nItemId, const OUString& rStr )
1058 {
1059  MenuItemData* pData = pItemList->GetData( nItemId );
1060 
1061  if ( pData )
1062  pData->aHelpCommandStr = rStr;
1063 }
1064 
1065 OUString Menu::GetHelpCommand( sal_uInt16 nItemId ) const
1066 {
1067  MenuItemData* pData = pItemList->GetData( nItemId );
1068 
1069  if ( pData )
1070  return pData->aHelpCommandStr;
1071 
1072  return OUString();
1073 }
1074 
1075 void Menu::SetHelpText( sal_uInt16 nItemId, const OUString& rStr )
1076 {
1077  MenuItemData* pData = pItemList->GetData( nItemId );
1078 
1079  if ( pData )
1080  pData->aHelpText = rStr;
1081 }
1082 
1083 OUString Menu::ImplGetHelpText( sal_uInt16 nItemId ) const
1084 {
1085  MenuItemData* pData = pItemList->GetData( nItemId );
1086 
1087  if ( pData && pData->aHelpText.isEmpty() &&
1088  (( !pData->aHelpId.isEmpty() ) || ( !pData->aCommandStr.isEmpty() )))
1089  {
1090  Help* pHelp = Application::GetHelp();
1091  if ( pHelp )
1092  {
1093  if (!pData->aCommandStr.isEmpty())
1094  pData->aHelpText = pHelp->GetHelpText( pData->aCommandStr, static_cast<weld::Widget*>(nullptr) );
1095  if (pData->aHelpText.isEmpty() && !pData->aHelpId.isEmpty())
1096  pData->aHelpText = pHelp->GetHelpText( OStringToOUString( pData->aHelpId, RTL_TEXTENCODING_UTF8 ), static_cast<weld::Widget*>(nullptr) );
1097  }
1098  }
1099 
1100  return OUString();
1101 }
1102 
1103 OUString Menu::GetHelpText( sal_uInt16 nItemId ) const
1104 {
1105  return ImplGetHelpText( nItemId );
1106 }
1107 
1108 void Menu::SetTipHelpText( sal_uInt16 nItemId, const OUString& rStr )
1109 {
1110  MenuItemData* pData = pItemList->GetData( nItemId );
1111 
1112  if ( pData )
1113  pData->aTipHelpText = rStr;
1114 }
1115 
1116 OUString Menu::GetTipHelpText( sal_uInt16 nItemId ) const
1117 {
1118  MenuItemData* pData = pItemList->GetData( nItemId );
1119 
1120  if ( pData )
1121  return pData->aTipHelpText;
1122 
1123  return OUString();
1124 }
1125 
1126 void Menu::SetHelpId( sal_uInt16 nItemId, const OString& rHelpId )
1127 {
1128  MenuItemData* pData = pItemList->GetData( nItemId );
1129 
1130  if ( pData )
1131  pData->aHelpId = rHelpId;
1132 }
1133 
1134 OString Menu::GetHelpId( sal_uInt16 nItemId ) const
1135 {
1136  OString aRet;
1137 
1138  MenuItemData* pData = pItemList->GetData( nItemId );
1139 
1140  if ( pData )
1141  {
1142  if ( !pData->aHelpId.isEmpty() )
1143  aRet = pData->aHelpId;
1144  else
1145  aRet = OUStringToOString( pData->aCommandStr, RTL_TEXTENCODING_UTF8 );
1146  }
1147 
1148  return aRet;
1149 }
1150 
1151 Menu& Menu::operator=( const Menu& rMenu )
1152 {
1153  if(this == &rMenu)
1154  return *this;
1155 
1156  // clean up
1157  Clear();
1158 
1159  // copy items
1160  sal_uInt16 nCount = rMenu.GetItemCount();
1161  for ( sal_uInt16 i = 0; i < nCount; i++ )
1162  ImplCopyItem( this, rMenu, i, MENU_APPEND );
1163 
1164  aActivateHdl = rMenu.aActivateHdl;
1166  aSelectHdl = rMenu.aSelectHdl;
1167  aTitleText = rMenu.aTitleText;
1168  nTitleHeight = rMenu.nTitleHeight;
1169 
1170  return *this;
1171 }
1172 
1173 // Returns true if the item is completely hidden on the GUI and shouldn't
1174 // be possible to interact with
1175 bool Menu::ImplCurrentlyHiddenOnGUI(sal_uInt16 nPos) const
1176 {
1177  MenuItemData* pData = pItemList->GetDataFromPos(nPos);
1178  if (pData)
1179  {
1180  MenuItemData* pPreviousData = pItemList->GetDataFromPos( nPos - 1 );
1181  if (pPreviousData && pPreviousData->bHiddenOnGUI)
1182  {
1183  return true;
1184  }
1185  }
1186  return false;
1187 }
1188 
1189 bool Menu::ImplIsVisible( sal_uInt16 nPos ) const
1190 {
1191  bool bVisible = true;
1192 
1193  MenuItemData* pData = pItemList->GetDataFromPos( nPos );
1194  // check general visibility first
1195  if( pData && !pData->bVisible )
1196  bVisible = false;
1197 
1198  if ( bVisible && pData && pData->eType == MenuItemType::SEPARATOR )
1199  {
1200  if( nPos == 0 ) // no separator should be shown at the very beginning
1201  bVisible = false;
1202  else
1203  {
1204  // always avoid adjacent separators
1205  size_t nCount = pItemList->size();
1206  size_t n;
1207  MenuItemData* pNextData = nullptr;
1208  // search next visible item
1209  for( n = nPos + 1; n < nCount; n++ )
1210  {
1211  pNextData = pItemList->GetDataFromPos( n );
1212  if( pNextData && pNextData->bVisible )
1213  {
1214  if( pNextData->eType == MenuItemType::SEPARATOR || ImplIsVisible(n) )
1215  break;
1216  }
1217  }
1218  if( n == nCount ) // no next visible item
1219  bVisible = false;
1220  // check for separator
1221  if( pNextData && pNextData->bVisible && pNextData->eType == MenuItemType::SEPARATOR )
1222  bVisible = false;
1223 
1224  if( bVisible )
1225  {
1226  for( n = nPos; n > 0; n-- )
1227  {
1228  pNextData = pItemList->GetDataFromPos( n-1 );
1229  if( pNextData && pNextData->bVisible )
1230  {
1231  if( pNextData->eType != MenuItemType::SEPARATOR && ImplIsVisible(n-1) )
1232  break;
1233  }
1234  }
1235  if( n == 0 ) // no previous visible item
1236  bVisible = false;
1237  }
1238  }
1239  }
1240 
1241  // not allowed for menubar, as I do not know
1242  // whether a menu-entry will disappear or will appear
1243  if (bVisible && !IsMenuBar() && (nMenuFlags & MenuFlags::HideDisabledEntries) &&
1245  {
1246  if( !pData ) // e.g. nPos == ITEMPOS_INVALID
1247  bVisible = false;
1248  else if ( pData->eType != MenuItemType::SEPARATOR ) // separators handled above
1249  {
1250  // tdf#86850 Always display clipboard functions
1251  if ( pData->aCommandStr == ".uno:Cut" || pData->aCommandStr == ".uno:Copy" || pData->aCommandStr == ".uno:Paste" )
1252  bVisible = true;
1253  else
1254  // bVisible = pData->bEnabled && ( !pData->pSubMenu || pData->pSubMenu->HasValidEntries( true ) );
1255  bVisible = pData->bEnabled; // do not check submenus as they might be filled at Activate().
1256  }
1257  }
1258 
1259  return bVisible;
1260 }
1261 
1262 bool Menu::IsItemPosVisible( sal_uInt16 nItemPos ) const
1263 {
1264  return IsMenuVisible() && ImplIsVisible( nItemPos );
1265 }
1266 
1268 {
1269  return pWindow && pWindow->IsReallyVisible();
1270 }
1271 
1272 bool Menu::ImplIsSelectable( sal_uInt16 nPos ) const
1273 {
1274  bool bSelectable = true;
1275 
1276  MenuItemData* pData = pItemList->GetDataFromPos( nPos );
1277  // check general visibility first
1278  if ( pData && ( pData->nBits & MenuItemBits::NOSELECT ) )
1279  bSelectable = false;
1280 
1281  return bSelectable;
1282 }
1283 
1284 css::uno::Reference<css::accessibility::XAccessible> Menu::GetAccessible()
1285 {
1286  // Since PopupMenu are sometimes shared by different instances of MenuBar, the mxAccessible member gets
1287  // overwritten and may contain a disposed object when the initial menubar gets set again. So use the
1288  // mxAccessible member only for sub menus.
1289  if ( pStartedFrom )
1290  {
1291  for ( sal_uInt16 i = 0, nCount = pStartedFrom->GetItemCount(); i < nCount; ++i )
1292  {
1293  sal_uInt16 nItemId = pStartedFrom->GetItemId( i );
1294  if ( static_cast< Menu* >( pStartedFrom->GetPopupMenu( nItemId ) ) == this )
1295  {
1296  css::uno::Reference<css::accessibility::XAccessible> xParent = pStartedFrom->GetAccessible();
1297  if ( xParent.is() )
1298  {
1299  css::uno::Reference<css::accessibility::XAccessibleContext> xParentContext( xParent->getAccessibleContext() );
1300  if (xParentContext.is())
1301  return xParentContext->getAccessibleChild( i );
1302  }
1303  }
1304  }
1305  }
1306  else if ( !mxAccessible.is() )
1307  {
1309  if ( pWrapper )
1310  mxAccessible = pWrapper->CreateAccessible(this, IsMenuBar());
1311  }
1312 
1313  return mxAccessible;
1314 }
1315 
1316 void Menu::SetAccessible(const css::uno::Reference<css::accessibility::XAccessible>& rxAccessible )
1317 {
1318  mxAccessible = rxAccessible;
1319 }
1320 
1321 Size Menu::ImplGetNativeCheckAndRadioSize(vcl::RenderContext const & rRenderContext, long& rCheckHeight, long& rRadioHeight ) const
1322 {
1323  long nCheckWidth = 0, nRadioWidth = 0;
1324  rCheckHeight = rRadioHeight = 0;
1325 
1326  if (!IsMenuBar())
1327  {
1328  ImplControlValue aVal;
1329  tools::Rectangle aNativeBounds;
1330  tools::Rectangle aNativeContent;
1331 
1332  tools::Rectangle aCtrlRegion(tools::Rectangle(Point(), Size(100, 15)));
1334  {
1336  aCtrlRegion, ControlState::ENABLED, aVal,
1337  aNativeBounds, aNativeContent))
1338  {
1339  rCheckHeight = aNativeBounds.GetHeight();
1340  nCheckWidth = aNativeContent.GetWidth();
1341  }
1342  }
1344  {
1346  aCtrlRegion, ControlState::ENABLED, aVal,
1347  aNativeBounds, aNativeContent))
1348  {
1349  rRadioHeight = aNativeBounds.GetHeight();
1350  nRadioWidth = aNativeContent.GetWidth();
1351  }
1352  }
1353  }
1354  return Size(std::max(nCheckWidth, nRadioWidth), std::max(rCheckHeight, rRadioHeight));
1355 }
1356 
1357 bool Menu::ImplGetNativeSubmenuArrowSize(vcl::RenderContext const & rRenderContext, Size& rArrowSize, long& rArrowSpacing)
1358 {
1359  ImplControlValue aVal;
1360  tools::Rectangle aNativeBounds;
1361  tools::Rectangle aNativeContent;
1362  tools::Rectangle aCtrlRegion(tools::Rectangle(Point(), Size(100, 15)));
1364  {
1366  aCtrlRegion, ControlState::ENABLED,
1367  aVal, aNativeBounds, aNativeContent))
1368  {
1369  Size aSize(aNativeContent.GetWidth(), aNativeContent.GetHeight());
1370  rArrowSize = aSize;
1371  rArrowSpacing = aNativeBounds.GetWidth() - aNativeContent.GetWidth();
1372  return true;
1373  }
1374  }
1375  return false;
1376 }
1377 
1379 {
1380  SAL_WARN_IF( rDel.mpMenu, "vcl", "Menu::ImplAddDel(): cannot add ImplMenuDelData twice !" );
1381  if( !rDel.mpMenu )
1382  {
1383  rDel.mpMenu = this;
1384  rDel.mpNext = mpFirstDel;
1385  mpFirstDel = &rDel;
1386  }
1387 }
1388 
1390 {
1391  rDel.mpMenu = nullptr;
1392  if ( mpFirstDel == &rDel )
1393  {
1394  mpFirstDel = rDel.mpNext;
1395  }
1396  else
1397  {
1398  ImplMenuDelData* pData = mpFirstDel;
1399  while ( pData && (pData->mpNext != &rDel) )
1400  pData = pData->mpNext;
1401 
1402  SAL_WARN_IF( !pData, "vcl", "Menu::ImplRemoveDel(): ImplMenuDelData not registered !" );
1403  if( pData )
1404  pData->mpNext = rDel.mpNext;
1405  }
1406 }
1407 
1409 {
1410  // | Check/Radio/Image| Text| Accel/Popup|
1411 
1412  // for symbols: nFontHeight x nFontHeight
1413  long nFontHeight = pWin->GetTextHeight();
1414  long nExtra = nFontHeight/4;
1415 
1416  long nMinMenuItemHeight = nFontHeight;
1417  long nCheckHeight = 0, nRadioHeight = 0;
1418  Size aMaxSize = ImplGetNativeCheckAndRadioSize(*pWin, nCheckHeight, nRadioHeight); // FIXME
1419  if( aMaxSize.Height() > nMinMenuItemHeight )
1420  nMinMenuItemHeight = aMaxSize.Height();
1421 
1422  Size aMaxImgSz;
1423 
1424  const StyleSettings& rSettings = pWin->GetSettings().GetStyleSettings();
1425  if ( rSettings.GetUseImagesInMenus() )
1426  {
1427  if ( 16 > nMinMenuItemHeight )
1428  nMinMenuItemHeight = 16;
1429  for ( size_t i = pItemList->size(); i; )
1430  {
1431  MenuItemData* pData = pItemList->GetDataFromPos( --i );
1432  if ( ImplIsVisible( i )
1433  && ( ( pData->eType == MenuItemType::IMAGE )
1434  || ( pData->eType == MenuItemType::STRINGIMAGE )
1435  )
1436  )
1437  {
1438  Size aImgSz = pData->aImage.GetSizePixel();
1439  if ( aImgSz.Height() > aMaxImgSz.Height() )
1440  aMaxImgSz.setHeight( aImgSz.Height() );
1441  if ( aImgSz.Height() > nMinMenuItemHeight )
1442  nMinMenuItemHeight = aImgSz.Height();
1443  break;
1444  }
1445  }
1446  }
1447 
1448  Size aSz;
1449  long nCheckWidth = 0;
1450  long nMaxWidth = 0;
1451 
1452  for ( size_t n = pItemList->size(); n; )
1453  {
1454  MenuItemData* pData = pItemList->GetDataFromPos( --n );
1455 
1456  pData->aSz.setHeight( 0 );
1457  pData->aSz.setWidth( 0 );
1458 
1459  if ( ImplIsVisible( n ) )
1460  {
1461  long nWidth = 0;
1462 
1463  // Separator
1464  if (!IsMenuBar()&& (pData->eType == MenuItemType::SEPARATOR))
1465  {
1466  //Useless: SAL_WARN_IF( IsMenuBar(), "vcl", "Separator in MenuBar ?! " );
1467  pData->aSz.setHeight( 4 );
1468  }
1469 
1470  // Image:
1471  if (!IsMenuBar() && ((pData->eType == MenuItemType::IMAGE) || (pData->eType == MenuItemType::STRINGIMAGE)))
1472  {
1473  Size aImgSz = pData->aImage.GetSizePixel();
1474 
1475  aImgSz.AdjustHeight(4 ); // add a border for native marks
1476  aImgSz.AdjustWidth(4 ); // add a border for native marks
1477  if ( aImgSz.Width() > aMaxImgSz.Width() )
1478  aMaxImgSz.setWidth( aImgSz.Width() );
1479  if ( aImgSz.Height() > aMaxImgSz.Height() )
1480  aMaxImgSz.setHeight( aImgSz.Height() );
1481  if ( aImgSz.Height() > pData->aSz.Height() )
1482  pData->aSz.setHeight( aImgSz.Height() );
1483  }
1484 
1485  // Check Buttons:
1486  if (!IsMenuBar() && pData->HasCheck())
1487  {
1488  nCheckWidth = aMaxSize.Width();
1489  // checks / images take the same place
1490  if( ! ( ( pData->eType == MenuItemType::IMAGE ) || ( pData->eType == MenuItemType::STRINGIMAGE ) ) )
1491  nWidth += nCheckWidth + nExtra * 2;
1492  }
1493 
1494  // Text:
1495  if ( (pData->eType == MenuItemType::STRING) || (pData->eType == MenuItemType::STRINGIMAGE) )
1496  {
1497  const SalLayoutGlyphs* pGlyphs = pData->GetTextGlyphs(pWin);
1498  long nTextWidth = pWin->GetCtrlTextWidth(pData->aText, pGlyphs);
1499  long nTextHeight = pWin->GetTextHeight();
1500 
1501  if (IsMenuBar())
1502  {
1503  if ( nTextHeight > pData->aSz.Height() )
1504  pData->aSz.setHeight( nTextHeight );
1505 
1506  pData->aSz.setWidth( nTextWidth + 4*nExtra );
1507  aSz.AdjustWidth(pData->aSz.Width() );
1508  }
1509  else
1510  pData->aSz.setHeight( std::max( std::max( nTextHeight, pData->aSz.Height() ), nMinMenuItemHeight ) );
1511 
1512  nWidth += nTextWidth;
1513  }
1514 
1515  // Accel
1516  if (!IsMenuBar()&& pData->aAccelKey.GetCode() && !ImplAccelDisabled())
1517  {
1518  OUString aName = pData->aAccelKey.GetName();
1519  long nAccWidth = pWin->GetTextWidth( aName );
1520  nAccWidth += nExtra;
1521  nWidth += nAccWidth;
1522  }
1523 
1524  // SubMenu?
1525  if (!IsMenuBar() && pData->pSubMenu)
1526  {
1527  if ( nFontHeight > nWidth )
1528  nWidth += nFontHeight;
1529 
1530  pData->aSz.setHeight( std::max( std::max( nFontHeight, pData->aSz.Height() ), nMinMenuItemHeight ) );
1531  }
1532 
1533  pData->aSz.AdjustHeight(EXTRAITEMHEIGHT ); // little bit more distance
1534 
1535  if (!IsMenuBar())
1536  aSz.AdjustHeight(pData->aSz.Height() );
1537 
1538  if ( nWidth > nMaxWidth )
1539  nMaxWidth = nWidth;
1540 
1541  }
1542  }
1543 
1544  // Additional space for title
1545  nTitleHeight = 0;
1546  if (!IsMenuBar() && aTitleText.getLength() > 0) {
1547  // Set expected font
1548  pWin->Push(PushFlags::FONT);
1549  vcl::Font aFont = pWin->GetFont();
1550  aFont.SetWeight(WEIGHT_BOLD);
1551  pWin->SetFont(aFont);
1552 
1553  // Compute text bounding box
1554  tools::Rectangle aTextBoundRect;
1555  pWin->GetTextBoundRect(aTextBoundRect, aTitleText);
1556 
1557  // Vertically, one height of char + extra space for decoration
1558  nTitleHeight = aTextBoundRect.GetSize().Height() + 4 * SPACE_AROUND_TITLE ;
1559  aSz.AdjustHeight(nTitleHeight );
1560 
1561  long nWidth = aTextBoundRect.GetSize().Width() + 4 * SPACE_AROUND_TITLE;
1562  pWin->Pop();
1563  if ( nWidth > nMaxWidth )
1564  nMaxWidth = nWidth;
1565  }
1566 
1567  if (!IsMenuBar())
1568  {
1569  // popup menus should not be wider than half the screen
1570  // except on rather small screens
1571  // TODO: move GetScreenNumber from SystemWindow to Window ?
1572  // currently we rely on internal privileges
1573  unsigned int nDisplayScreen = pWin->ImplGetWindowImpl()->mpFrame->maGeometry.nDisplayScreenNumber;
1574  tools::Rectangle aDispRect( Application::GetScreenPosSizePixel( nDisplayScreen ) );
1575  long nScreenWidth = aDispRect.GetWidth() >= 800 ? aDispRect.GetWidth() : 800;
1576  if( nMaxWidth > nScreenWidth/2 )
1577  nMaxWidth = nScreenWidth/2;
1578 
1579  sal_uInt16 gfxExtra = static_cast<sal_uInt16>(std::max( nExtra, 7L )); // #107710# increase space between checkmarks/images/text
1580  nImgOrChkPos = static_cast<sal_uInt16>(nExtra);
1581  long nImgOrChkWidth = 0;
1582  if( aMaxSize.Height() > 0 ) // NWF case
1583  nImgOrChkWidth = aMaxSize.Height() + nExtra;
1584  else // non NWF case
1585  nImgOrChkWidth = nFontHeight/2 + gfxExtra;
1586  nImgOrChkWidth = std::max( nImgOrChkWidth, aMaxImgSz.Width() + gfxExtra );
1587  nTextPos = static_cast<sal_uInt16>(nImgOrChkPos + nImgOrChkWidth);
1588  nTextPos = nTextPos + gfxExtra;
1589 
1590  aSz.setWidth( nTextPos + nMaxWidth + nExtra );
1591  aSz.AdjustWidth(4*nExtra ); // a _little_ more ...
1592 
1593  aSz.AdjustWidth(2*ImplGetSVData()->maNWFData.mnMenuFormatBorderX );
1594  aSz.AdjustHeight(2*ImplGetSVData()->maNWFData.mnMenuFormatBorderY );
1595  }
1596  else
1597  {
1598  nTextPos = static_cast<sal_uInt16>(2*nExtra);
1599  aSz.setHeight( nFontHeight+6 );
1600 
1601  // get menubar height from native methods if supported
1603  {
1604  ImplControlValue aVal;
1605  tools::Rectangle aNativeBounds;
1606  tools::Rectangle aNativeContent;
1607  Point tmp( 0, 0 );
1608  tools::Rectangle aCtrlRegion( tmp, Size( 100, 15 ) );
1611  aCtrlRegion,
1613  aVal,
1614  aNativeBounds,
1615  aNativeContent )
1616  )
1617  {
1618  int nNativeHeight = aNativeBounds.GetHeight();
1619  if( nNativeHeight > aSz.Height() )
1620  aSz.setHeight( nNativeHeight );
1621  }
1622  }
1623 
1624  // account for the size of the close button, which actually is a toolbox
1625  // due to NWF this is variable
1626  long nCloseButtonHeight = static_cast<MenuBarWindow*>(pWindow.get())->MinCloseButtonSize().Height();
1627  if (aSz.Height() < nCloseButtonHeight)
1628  aSz.setHeight( nCloseButtonHeight );
1629  }
1630 
1631  return aSz;
1632 }
1633 
1634 static void ImplPaintCheckBackground(vcl::RenderContext & rRenderContext, vcl::Window const & rWindow, const tools::Rectangle& i_rRect, bool i_bHighlight)
1635 {
1636  bool bNativeOk = false;
1638  {
1639  ImplControlValue aControlValue;
1640  aControlValue.setTristateVal(ButtonValue::On);
1641 
1642  bNativeOk = rRenderContext.DrawNativeControl(ControlType::Toolbar, ControlPart::Button,
1643  i_rRect,
1645  aControlValue,
1646  OUString());
1647  }
1648 
1649  if (!bNativeOk)
1650  {
1651  const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
1652  Color aColor( i_bHighlight ? rSettings.GetMenuHighlightTextColor() : rSettings.GetHighlightColor() );
1653  RenderTools::DrawSelectionBackground(rRenderContext, rWindow, i_rRect, 0, i_bHighlight, true, false, nullptr, 2, &aColor);
1654  }
1655 }
1656 
1657 static OUString getShortenedString( const OUString& i_rLong, vcl::RenderContext const & rRenderContext, long i_nMaxWidth )
1658 {
1659  sal_Int32 nPos = -1;
1660  OUString aNonMnem(OutputDevice::GetNonMnemonicString(i_rLong, nPos));
1661  aNonMnem = rRenderContext.GetEllipsisString( aNonMnem, i_nMaxWidth, DrawTextFlags::CenterEllipsis);
1662  // re-insert mnemonic
1663  if (nPos != -1)
1664  {
1665  if (nPos < aNonMnem.getLength() && i_rLong[nPos+1] == aNonMnem[nPos])
1666  {
1667  OUStringBuffer aBuf( i_rLong.getLength() );
1668  aBuf.append( std::u16string_view(aNonMnem).substr(0, nPos) );
1669  aBuf.append( '~' );
1670  aBuf.append( std::u16string_view(aNonMnem).substr(nPos) );
1671  aNonMnem = aBuf.makeStringAndClear();
1672  }
1673  }
1674  return aNonMnem;
1675 }
1676 
1677 void Menu::ImplPaintMenuTitle(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) const
1678 {
1679  // Save previous graphical settings, set new one
1680  rRenderContext.Push(PushFlags::FONT | PushFlags::FILLCOLOR);
1681  Wallpaper aOldBackground = rRenderContext.GetBackground();
1682 
1683  Color aBackgroundColor = rRenderContext.GetSettings().GetStyleSettings().GetMenuBarColor();
1684  rRenderContext.SetBackground(Wallpaper(aBackgroundColor));
1685  rRenderContext.SetFillColor(aBackgroundColor);
1686  vcl::Font aFont = rRenderContext.GetFont();
1687  aFont.SetWeight(WEIGHT_BOLD);
1688  rRenderContext.SetFont(aFont);
1689 
1690  // Draw background rectangle
1691  tools::Rectangle aBgRect(rRect);
1692  int nOuterSpaceX = ImplGetSVData()->maNWFData.mnMenuFormatBorderX;
1693  aBgRect.setX(aBgRect.getX() + SPACE_AROUND_TITLE);
1694  aBgRect.setWidth(aBgRect.getWidth() - 2 * SPACE_AROUND_TITLE - 2 * nOuterSpaceX);
1695  aBgRect.setY(aBgRect.getY() + SPACE_AROUND_TITLE);
1696  aBgRect.setHeight(nTitleHeight - 2 * SPACE_AROUND_TITLE);
1697  rRenderContext.DrawRect(aBgRect);
1698 
1699  // Draw the text centered
1700  Point aTextTopLeft(aBgRect.TopLeft());
1701  tools::Rectangle aTextBoundRect;
1702  rRenderContext.GetTextBoundRect( aTextBoundRect, aTitleText );
1703  aTextTopLeft.AdjustX((aBgRect.getWidth() - aTextBoundRect.GetSize().Width()) / 2 );
1704  aTextTopLeft.AdjustY((aBgRect.GetHeight() - aTextBoundRect.GetSize().Height()) / 2
1705  - aTextBoundRect.TopLeft().Y() );
1706  rRenderContext.DrawText(aTextTopLeft, aTitleText, 0, aTitleText.getLength());
1707 
1708  // Restore
1709  rRenderContext.Pop();
1710  rRenderContext.SetBackground(aOldBackground);
1711 }
1712 
1713 void Menu::ImplPaint(vcl::RenderContext& rRenderContext, Size const & rSize,
1714  sal_uInt16 nBorder, long nStartY, MenuItemData const * pThisItemOnly,
1715  bool bHighlighted, bool bLayout, bool bRollover) const
1716 {
1717  // for symbols: nFontHeight x nFontHeight
1718  long nFontHeight = rRenderContext.GetTextHeight();
1719  long nExtra = nFontHeight / 4;
1720 
1721  long nCheckHeight = 0, nRadioHeight = 0;
1722  ImplGetNativeCheckAndRadioSize(rRenderContext, nCheckHeight, nRadioHeight);
1723 
1724  DecorationView aDecoView(&rRenderContext);
1725  const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
1726 
1727  Point aTopLeft, aTmpPos;
1728 
1729  int nOuterSpaceX = 0;
1730  if (!IsMenuBar())
1731  {
1732  nOuterSpaceX = ImplGetSVData()->maNWFData.mnMenuFormatBorderX;
1733  aTopLeft.AdjustX(nOuterSpaceX );
1734  aTopLeft.AdjustY(ImplGetSVData()->maNWFData.mnMenuFormatBorderY );
1735  }
1736 
1737  // for the computations, use size of the underlying window, not of RenderContext
1738  Size aOutSz(rSize);
1739 
1740  size_t nCount = pItemList->size();
1741  if (bLayout)
1742  mpLayoutData->m_aVisibleItemBoundRects.clear();
1743 
1744  // Paint title
1745  if (!pThisItemOnly && !IsMenuBar() && nTitleHeight > 0)
1746  ImplPaintMenuTitle(rRenderContext, tools::Rectangle(aTopLeft, aOutSz));
1747 
1748  bool bHiddenItems = false; // are any items on the GUI hidden
1749 
1750  for (size_t n = 0; n < nCount; n++)
1751  {
1752  MenuItemData* pData = pItemList->GetDataFromPos( n );
1753  if (ImplIsVisible(n) && (!pThisItemOnly || (pData == pThisItemOnly)))
1754  {
1755  if (pThisItemOnly)
1756  {
1757  if (IsMenuBar())
1758  {
1759  if (!ImplGetSVData()->maNWFData.mbRolloverMenubar)
1760  {
1761  if (bRollover)
1762  rRenderContext.SetTextColor(rSettings.GetMenuBarRolloverTextColor());
1763  else if (bHighlighted)
1764  rRenderContext.SetTextColor(rSettings.GetMenuBarHighlightTextColor());
1765  }
1766  else
1767  {
1768  if (bHighlighted)
1769  rRenderContext.SetTextColor(rSettings.GetMenuBarHighlightTextColor());
1770  else if (bRollover)
1771  rRenderContext.SetTextColor(rSettings.GetMenuBarRolloverTextColor());
1772  }
1773  if (!bRollover && !bHighlighted)
1774  rRenderContext.SetTextColor(rSettings.GetMenuBarTextColor());
1775  }
1776  else if (bHighlighted)
1777  rRenderContext.SetTextColor(rSettings.GetMenuHighlightTextColor());
1778  }
1779 
1780  Point aPos(aTopLeft);
1781  aPos.AdjustY(nBorder );
1782  aPos.AdjustY(nStartY );
1783 
1784  if (aPos.Y() >= 0)
1785  {
1786  long nTextOffsetY = (pData->aSz.Height() - nFontHeight) / 2;
1787  if (IsMenuBar())
1788  nTextOffsetY += (aOutSz.Height()-pData->aSz.Height()) / 2;
1789  DrawTextFlags nTextStyle = DrawTextFlags::NONE;
1790  DrawSymbolFlags nSymbolStyle = DrawSymbolFlags::NONE;
1791  DrawImageFlags nImageStyle = DrawImageFlags::NONE;
1792 
1793  // submenus without items are not disabled when no items are
1794  // contained. The application itself should check for this!
1795  // Otherwise it could happen entries are disabled due to
1796  // asynchronous loading
1797  if (!pData->bEnabled || !pWindow->IsEnabled())
1798  {
1799  nTextStyle |= DrawTextFlags::Disable;
1800  nSymbolStyle |= DrawSymbolFlags::Disable;
1801  nImageStyle |= DrawImageFlags::Disable;
1802  }
1803 
1804  // Separator
1805  if (!bLayout && !IsMenuBar() && (pData->eType == MenuItemType::SEPARATOR))
1806  {
1807  bool bNativeOk = false;
1809  {
1811  if (pData->bEnabled && pWindow->IsEnabled())
1812  nState |= ControlState::ENABLED;
1813  if (bHighlighted)
1814  nState |= ControlState::SELECTED;
1816  Point aMpos (aPos);
1817  aMpos.AdjustX(nSepPad );
1818  Size aSz(pData->aSz);
1819  aSz.setWidth( aOutSz.Width() - 2*nOuterSpaceX - 2 * nSepPad );
1820  tools::Rectangle aItemRect(aMpos, aSz);
1821  MenupopupValue aVal(nTextPos - GUTTERBORDER, aItemRect);
1823  aItemRect, nState, aVal, OUString());
1824  }
1825  if (!bNativeOk)
1826  {
1827  aTmpPos.setY( aPos.Y() + ((pData->aSz.Height() - 2) / 2) );
1828  aTmpPos.setX( aPos.X() + 2 + nOuterSpaceX );
1829  rRenderContext.SetLineColor(rSettings.GetShadowColor());
1830  rRenderContext.DrawLine(aTmpPos, Point(aOutSz.Width() - 3 - 2 * nOuterSpaceX, aTmpPos.Y()));
1831  aTmpPos.AdjustY( 1 );
1832  rRenderContext.SetLineColor(rSettings.GetLightColor());
1833  rRenderContext.DrawLine(aTmpPos, Point(aOutSz.Width() - 3 - 2 * nOuterSpaceX, aTmpPos.Y()));
1834  rRenderContext.SetLineColor();
1835  }
1836  }
1837 
1838  tools::Rectangle aOuterCheckRect(Point(aPos.X()+nImgOrChkPos, aPos.Y()),
1839  Size(pData->aSz.Height(), pData->aSz.Height()));
1840  aOuterCheckRect.AdjustLeft(1 );
1841  aOuterCheckRect.AdjustRight( -1 );
1842  aOuterCheckRect.AdjustTop(1 );
1843  aOuterCheckRect.AdjustBottom( -1 );
1844 
1845  // CheckMark
1846  if (!bLayout && !IsMenuBar() && pData->HasCheck())
1847  {
1848  // draw selection transparent marker if checked
1849  // onto that either a checkmark or the item image
1850  // will be painted
1851  // however do not do this if native checks will be painted since
1852  // the selection color too often does not fit the theme's check and/or radio
1853 
1854  if( !((pData->eType == MenuItemType::IMAGE) || (pData->eType == MenuItemType::STRINGIMAGE)))
1855  {
1857  (pData->nBits & MenuItemBits::RADIOCHECK)
1860  {
1861  ControlPart nPart = ((pData->nBits & MenuItemBits::RADIOCHECK)
1862  ? ControlPart::MenuItemRadioMark
1864 
1866 
1867  if (pData->bChecked)
1868  nState |= ControlState::PRESSED;
1869 
1870  if (pData->bEnabled && pWindow->IsEnabled())
1871  nState |= ControlState::ENABLED;
1872 
1873  if (bHighlighted)
1874  nState |= ControlState::SELECTED;
1875 
1876  long nCtrlHeight = (pData->nBits & MenuItemBits::RADIOCHECK) ? nCheckHeight : nRadioHeight;
1877  aTmpPos.setX( aOuterCheckRect.Left() + (aOuterCheckRect.GetWidth() - nCtrlHeight) / 2 );
1878  aTmpPos.setY( aOuterCheckRect.Top() + (aOuterCheckRect.GetHeight() - nCtrlHeight) / 2 );
1879 
1880  tools::Rectangle aCheckRect(aTmpPos, Size(nCtrlHeight, nCtrlHeight));
1881  Size aSz(pData->aSz);
1882  aSz.setWidth( aOutSz.Width() - 2 * nOuterSpaceX );
1883  tools::Rectangle aItemRect(aPos, aSz);
1884  MenupopupValue aVal(nTextPos - GUTTERBORDER, aItemRect);
1885  rRenderContext.DrawNativeControl(ControlType::MenuPopup, nPart, aCheckRect,
1886  nState, aVal, OUString());
1887  }
1888  else if (pData->bChecked) // by default do nothing for unchecked items
1889  {
1890  ImplPaintCheckBackground(rRenderContext, *pWindow, aOuterCheckRect, pThisItemOnly && bHighlighted);
1891 
1893  Size aSymbolSize;
1894  if (pData->nBits & MenuItemBits::RADIOCHECK)
1895  {
1896  eSymbol = SymbolType::RADIOCHECKMARK;
1897  aSymbolSize = Size(nFontHeight / 2, nFontHeight / 2);
1898  }
1899  else
1900  {
1901  eSymbol = SymbolType::CHECKMARK;
1902  aSymbolSize = Size((nFontHeight * 25) / 40, nFontHeight / 2);
1903  }
1904  aTmpPos.setX( aOuterCheckRect.Left() + (aOuterCheckRect.GetWidth() - aSymbolSize.Width()) / 2 );
1905  aTmpPos.setY( aOuterCheckRect.Top() + (aOuterCheckRect.GetHeight() - aSymbolSize.Height()) / 2 );
1906  tools::Rectangle aRect(aTmpPos, aSymbolSize);
1907  aDecoView.DrawSymbol(aRect, eSymbol, rRenderContext.GetTextColor(), nSymbolStyle);
1908  }
1909  }
1910  }
1911 
1912  // Image:
1913  if (!bLayout && !IsMenuBar() && ((pData->eType == MenuItemType::IMAGE) || (pData->eType == MenuItemType::STRINGIMAGE)))
1914  {
1915  // Don't render an image for a check thing
1916  if (pData->bChecked)
1917  ImplPaintCheckBackground(rRenderContext, *pWindow, aOuterCheckRect, pThisItemOnly && bHighlighted);
1918 
1919  Image aImage = pData->aImage;
1920 
1921  aTmpPos = aOuterCheckRect.TopLeft();
1922  aTmpPos.AdjustX((aOuterCheckRect.GetWidth() - aImage.GetSizePixel().Width()) / 2 );
1923  aTmpPos.AdjustY((aOuterCheckRect.GetHeight() - aImage.GetSizePixel().Height()) / 2 );
1924  rRenderContext.DrawImage(aTmpPos, aImage, nImageStyle);
1925  }
1926 
1927  // Text:
1928  if ((pData->eType == MenuItemType::STRING ) || (pData->eType == MenuItemType::STRINGIMAGE))
1929  {
1930  aTmpPos.setX( aPos.X() + nTextPos );
1931  aTmpPos.setY( aPos.Y() );
1932  aTmpPos.AdjustY(nTextOffsetY );
1933  DrawTextFlags nStyle = nTextStyle | DrawTextFlags::Mnemonic;
1934 
1935  const Menu *pMenu = this;
1936  while (!pMenu->IsMenuBar() && pMenu->pStartedFrom)
1937  pMenu = pMenu->pStartedFrom;
1938  if (pMenu->IsMenuBar() && static_cast<MenuBarWindow*>(pMenu->pWindow.get())->GetMBWHideAccel())
1939  nStyle |= DrawTextFlags::HideMnemonic;
1940 
1941  if (pData->bIsTemporary)
1942  nStyle |= DrawTextFlags::Disable;
1943  MetricVector* pVector = bLayout ? &mpLayoutData->m_aUnicodeBoundRects : nullptr;
1944  OUString* pDisplayText = bLayout ? &mpLayoutData->m_aDisplayText : nullptr;
1945  if (bLayout)
1946  {
1947  mpLayoutData->m_aLineIndices.push_back(mpLayoutData->m_aDisplayText.getLength());
1948  mpLayoutData->m_aLineItemIds.push_back(pData->nId);
1949  }
1950  // #i47946# with NWF painted menus the background is transparent
1951  // since DrawCtrlText can depend on the background (e.g. for
1952  // DrawTextFlags::Disable), temporarily set a background which
1953  // hopefully matches the NWF background since it is read
1954  // from the system style settings
1955  bool bSetTmpBackground = !rRenderContext.IsBackground()
1957  if (bSetTmpBackground)
1958  {
1959  Color aBg = IsMenuBar() ? rRenderContext.GetSettings().GetStyleSettings().GetMenuBarColor()
1960  : rRenderContext.GetSettings().GetStyleSettings().GetMenuColor();
1961  rRenderContext.SetBackground(Wallpaper(aBg));
1962  }
1963  // how much space is there for the text?
1964  long nMaxItemTextWidth = aOutSz.Width() - aTmpPos.X() - nExtra - nOuterSpaceX;
1965  if (!IsMenuBar() && pData->aAccelKey.GetCode() && !ImplAccelDisabled())
1966  {
1967  OUString aAccText = pData->aAccelKey.GetName();
1968  nMaxItemTextWidth -= rRenderContext.GetTextWidth(aAccText) + 3 * nExtra;
1969  }
1970  if (!IsMenuBar() && pData->pSubMenu)
1971  {
1972  nMaxItemTextWidth -= nFontHeight - nExtra;
1973  }
1974 
1975  OUString aItemText(pData->aText);
1976  pData->bHiddenOnGUI = false;
1977 
1978  if (IsMenuBar()) // In case of menubar if we are out of bounds we shouldn't paint the item
1979  {
1980  if (nMaxItemTextWidth < rRenderContext.GetTextWidth(aItemText))
1981  {
1982  aItemText = "";
1983  pData->bHiddenOnGUI = true;
1984  bHiddenItems = true;
1985  }
1986  }
1987  else
1988  {
1989  aItemText = getShortenedString(aItemText, rRenderContext, nMaxItemTextWidth);
1990  pData->bHiddenOnGUI = false;
1991  }
1992 
1993  const SalLayoutGlyphs* pGlyphs = pData->GetTextGlyphs(&rRenderContext);
1994  if (aItemText != pData->aText)
1995  // Can't use pre-computed glyphs, item text was
1996  // changed.
1997  pGlyphs = nullptr;
1998  rRenderContext.DrawCtrlText(aTmpPos, aItemText, 0, aItemText.getLength(),
1999  nStyle, pVector, pDisplayText, pGlyphs);
2000  if (bSetTmpBackground)
2001  rRenderContext.SetBackground();
2002  }
2003 
2004  // Accel
2005  if (!bLayout && !IsMenuBar() && pData->aAccelKey.GetCode() && !ImplAccelDisabled())
2006  {
2007  OUString aAccText = pData->aAccelKey.GetName();
2008  aTmpPos.setX( aOutSz.Width() - rRenderContext.GetTextWidth(aAccText) );
2009  aTmpPos.AdjustX( -(4 * nExtra) );
2010 
2011  aTmpPos.AdjustX( -nOuterSpaceX );
2012  aTmpPos.setY( aPos.Y() );
2013  aTmpPos.AdjustY(nTextOffsetY );
2014  rRenderContext.DrawCtrlText(aTmpPos, aAccText, 0, aAccText.getLength(), nTextStyle);
2015  }
2016 
2017  // SubMenu?
2018  if (!bLayout && !IsMenuBar() && pData->pSubMenu)
2019  {
2020  bool bNativeOk = false;
2022  {
2024  Size aTmpSz(0, 0);
2025  long aSpacing = 0;
2026 
2027  if (!ImplGetNativeSubmenuArrowSize(rRenderContext, aTmpSz, aSpacing))
2028  {
2029  aTmpSz = Size(nFontHeight, nFontHeight);
2030  aSpacing = nOuterSpaceX;
2031  }
2032 
2033  if (pData->bEnabled && pWindow->IsEnabled())
2034  nState |= ControlState::ENABLED;
2035  if (bHighlighted)
2036  nState |= ControlState::SELECTED;
2037 
2038  aTmpPos.setX( aOutSz.Width() - aTmpSz.Width() - aSpacing - nOuterSpaceX );
2039  aTmpPos.setY( aPos.Y() + ( pData->aSz.Height() - aTmpSz.Height() ) / 2 );
2040  aTmpPos.AdjustY(nExtra / 2 );
2041 
2042  tools::Rectangle aItemRect(aTmpPos, aTmpSz);
2043  MenupopupValue aVal(nTextPos - GUTTERBORDER, aItemRect);
2045  aItemRect, nState, aVal, OUString());
2046  }
2047  if (!bNativeOk)
2048  {
2049  aTmpPos.setX( aOutSz.Width() - nFontHeight + nExtra - nOuterSpaceX );
2050  aTmpPos.setY( aPos.Y() );
2051  aTmpPos.AdjustY(nExtra/2 );
2052  aTmpPos.AdjustY((pData->aSz.Height() / 2) - (nFontHeight / 4) );
2053  if (pData->nBits & MenuItemBits::POPUPSELECT)
2054  {
2055  rRenderContext.SetTextColor(rSettings.GetMenuTextColor());
2056  Point aTmpPos2(aPos);
2057  aTmpPos2.setX( aOutSz.Width() - nFontHeight - nFontHeight/4 );
2058  aDecoView.DrawFrame(tools::Rectangle(aTmpPos2, Size(nFontHeight + nFontHeight / 4,
2059  pData->aSz.Height())),
2061  }
2062  aDecoView.DrawSymbol(tools::Rectangle(aTmpPos, Size(nFontHeight / 2, nFontHeight / 2)),
2063  SymbolType::SPIN_RIGHT, rRenderContext.GetTextColor(), nSymbolStyle);
2064  }
2065  }
2066 
2067  if (pThisItemOnly && bHighlighted)
2068  {
2069  // This restores the normal menu or menu bar text
2070  // color for when it is no longer highlighted.
2071  if (IsMenuBar())
2072  rRenderContext.SetTextColor(rSettings.GetMenuBarTextColor());
2073  else
2074  rRenderContext.SetTextColor(rSettings.GetMenuTextColor());
2075  }
2076  }
2077  if( bLayout )
2078  {
2079  if (!IsMenuBar())
2080  mpLayoutData->m_aVisibleItemBoundRects[ n ] = tools::Rectangle(aTopLeft, Size(aOutSz.Width(), pData->aSz.Height()));
2081  else
2082  mpLayoutData->m_aVisibleItemBoundRects[ n ] = tools::Rectangle(aTopLeft, pData->aSz);
2083  }
2084  }
2085 
2086  if (!IsMenuBar())
2087  aTopLeft.AdjustY(pData->aSz.Height() );
2088  else
2089  aTopLeft.AdjustX(pData->aSz.Width() );
2090  }
2091 
2092  // draw "more" (">>") indicator if some items have been hidden as they go out of visible area
2093  if (bHiddenItems)
2094  {
2095  sal_Int32 nSize = nFontHeight;
2096  tools::Rectangle aRectangle(Point(aOutSz.Width() - nSize, (aOutSz.Height() / 2) - (nSize / 2)), Size(nSize, nSize));
2097  lclDrawMoreIndicator(rRenderContext, aRectangle);
2098  }
2099 }
2100 
2102 {
2103  Menu* pStart = this;
2104  while ( pStart && pStart->pStartedFrom && ( pStart->pStartedFrom != pStart ) )
2105  pStart = pStart->pStartedFrom;
2106  return pStart;
2107 }
2108 
2109 void Menu::ImplCallHighlight(sal_uInt16 nItem)
2110 {
2111  ImplMenuDelData aDelData( this );
2112 
2113  nSelectedId = 0;
2114  sSelectedIdent.clear();
2115  MenuItemData* pData = pItemList->GetDataFromPos(nItem);
2116  if (pData)
2117  {
2118  nSelectedId = pData->nId;
2119  sSelectedIdent = pData->sIdent;
2120  }
2122 
2123  if( !aDelData.isDeleted() )
2124  {
2125  nSelectedId = 0;
2126  sSelectedIdent.clear();
2127  }
2128 }
2129 
2130 IMPL_LINK_NOARG(Menu, ImplCallSelect, void*, void)
2131 {
2132  nEventId = nullptr;
2133  Select();
2134 }
2135 
2137 {
2138  Menu* pSelMenu = nEventId ? this : nullptr;
2139 
2140  for ( size_t n = GetItemList()->size(); n && !pSelMenu; )
2141  {
2142  MenuItemData* pData = GetItemList()->GetDataFromPos( --n );
2143 
2144  if ( pData->pSubMenu )
2145  pSelMenu = pData->pSubMenu->ImplFindSelectMenu();
2146  }
2147 
2148  return pSelMenu;
2149 }
2150 
2151 Menu* Menu::ImplFindMenu( sal_uInt16 nItemId )
2152 {
2153  Menu* pSelMenu = nullptr;
2154 
2155  for ( size_t n = GetItemList()->size(); n && !pSelMenu; )
2156  {
2157  MenuItemData* pData = GetItemList()->GetDataFromPos( --n );
2158 
2159  if( pData->nId == nItemId )
2160  pSelMenu = this;
2161  else if ( pData->pSubMenu )
2162  pSelMenu = pData->pSubMenu->ImplFindMenu( nItemId );
2163  }
2164 
2165  return pSelMenu;
2166 }
2167 
2168 void Menu::RemoveDisabledEntries( bool bCheckPopups, bool bRemoveEmptyPopups )
2169 {
2170  for ( sal_uInt16 n = 0; n < GetItemCount(); n++ )
2171  {
2172  bool bRemove = false;
2173  MenuItemData* pItem = pItemList->GetDataFromPos( n );
2174  if ( pItem->eType == MenuItemType::SEPARATOR )
2175  {
2176  if ( !n || ( GetItemType( n-1 ) == MenuItemType::SEPARATOR ) )
2177  bRemove = true;
2178  }
2179  else
2180  bRemove = !pItem->bEnabled;
2181 
2182  if ( bCheckPopups && pItem->pSubMenu )
2183  {
2184  pItem->pSubMenu->RemoveDisabledEntries();
2185  if ( bRemoveEmptyPopups && !pItem->pSubMenu->GetItemCount() )
2186  bRemove = true;
2187  }
2188 
2189  if ( bRemove )
2190  RemoveItem( n-- );
2191  }
2192 
2193  if ( GetItemCount() )
2194  {
2195  sal_uInt16 nLast = GetItemCount() - 1;
2196  MenuItemData* pItem = pItemList->GetDataFromPos( nLast );
2197  if ( pItem->eType == MenuItemType::SEPARATOR )
2198  RemoveItem( nLast );
2199  }
2200  mpLayoutData.reset();
2201 }
2202 
2204 {
2205  if ( ImplGetSalMenu() )
2206  ImplGetSalMenu()->Update();
2207 }
2208 
2210 {
2211 }
2212 
2214 {
2215  mpLayoutData.reset();
2216 }
2217 
2219 {
2220  if (pWindow && pWindow->IsReallyVisible())
2221  {
2222  mpLayoutData.reset(new MenuLayoutData);
2223  if (IsMenuBar())
2224  {
2225  ImplPaint(*pWindow, pWindow->GetOutputSizePixel(), 0, 0, nullptr, false, true); // FIXME
2226  }
2227  else
2228  {
2229  MenuFloatingWindow* pFloat = static_cast<MenuFloatingWindow*>(pWindow.get());
2231  nullptr, false, true); //FIXME
2232  }
2233  }
2234 }
2235 
2236 tools::Rectangle Menu::GetCharacterBounds( sal_uInt16 nItemID, long nIndex ) const
2237 {
2238  long nItemIndex = -1;
2239  if( ! mpLayoutData )
2241  if( mpLayoutData )
2242  {
2243  for( size_t i = 0; i < mpLayoutData->m_aLineItemIds.size(); i++ )
2244  {
2245  if( mpLayoutData->m_aLineItemIds[i] == nItemID )
2246  {
2247  nItemIndex = mpLayoutData->m_aLineIndices[i];
2248  break;
2249  }
2250  }
2251  }
2252  return (mpLayoutData && nItemIndex != -1) ? mpLayoutData->GetCharacterBounds( nItemIndex+nIndex ) : tools::Rectangle();
2253 }
2254 
2255 long Menu::GetIndexForPoint( const Point& rPoint, sal_uInt16& rItemID ) const
2256 {
2257  long nIndex = -1;
2258  rItemID = 0;
2259  if( ! mpLayoutData )
2261  if( mpLayoutData )
2262  {
2263  nIndex = mpLayoutData->GetIndexForPoint( rPoint );
2264  for( size_t i = 0; i < mpLayoutData->m_aLineIndices.size(); i++ )
2265  {
2266  if( mpLayoutData->m_aLineIndices[i] <= nIndex &&
2267  (i == mpLayoutData->m_aLineIndices.size()-1 || mpLayoutData->m_aLineIndices[i+1] > nIndex) )
2268  {
2269  // make index relative to item
2270  nIndex -= mpLayoutData->m_aLineIndices[i];
2271  rItemID = mpLayoutData->m_aLineItemIds[i];
2272  break;
2273  }
2274  }
2275  }
2276  return nIndex;
2277 }
2278 
2280 {
2281  tools::Rectangle aRet;
2282 
2283  if (!mpLayoutData )
2285  if (mpLayoutData)
2286  {
2287  std::map< sal_uInt16, tools::Rectangle >::const_iterator it = mpLayoutData->m_aVisibleItemBoundRects.find( nPos );
2288  if( it != mpLayoutData->m_aVisibleItemBoundRects.end() )
2289  aRet = it->second;
2290  }
2291  return aRet;
2292 }
2293 
2294 OUString Menu::GetAccessibleName( sal_uInt16 nItemId ) const
2295 {
2296  MenuItemData* pData = pItemList->GetData( nItemId );
2297 
2298  if ( pData )
2299  return pData->aAccessibleName;
2300 
2301  return OUString();
2302 }
2303 
2305 {
2306  mpSalMenu.reset();
2307 }
2308 
2310 {
2311  Menu* pMenu = const_cast<Menu*>(this);
2312  if( pData && pMenu->ImplGetSalMenu() )
2313  {
2314  pMenu->ImplGetSalMenu()->GetSystemMenuData( pData );
2315  }
2316 }
2317 
2318 bool Menu::IsHighlighted( sal_uInt16 nItemPos ) const
2319 {
2320  bool bRet = false;
2321 
2322  if( pWindow )
2323  {
2324  if (IsMenuBar())
2325  bRet = ( nItemPos == static_cast< MenuBarWindow * > (pWindow.get())->GetHighlightedItem() );
2326  else
2327  bRet = ( nItemPos == static_cast< MenuFloatingWindow * > (pWindow.get())->GetHighlightedItem() );
2328  }
2329 
2330  return bRet;
2331 }
2332 
2333 void Menu::HighlightItem( sal_uInt16 nItemPos )
2334 {
2335  if ( pWindow )
2336  {
2337  if (IsMenuBar())
2338  {
2339  MenuBarWindow* pMenuWin = static_cast< MenuBarWindow* >( pWindow.get() );
2340  pMenuWin->SetAutoPopup( false );
2341  pMenuWin->ChangeHighlightItem( nItemPos, false );
2342  }
2343  else
2344  {
2345  static_cast< MenuFloatingWindow* >( pWindow.get() )->ChangeHighlightItem( nItemPos, false );
2346  }
2347  }
2348 }
2349 
2351 {
2352  // so far just a dynamic_cast, hopefully to be turned into something saner
2353  // at some stage
2354  MenuBarWindow *pWin = dynamic_cast<MenuBarWindow*>(pWindow.get());
2355  //either there is no window (fdo#87663) or it is a MenuBarWindow
2356  assert(!pWindow || pWin);
2357  return pWin;
2358 }
2359 
2361  : Menu(),
2362  mbCloseBtnVisible(false),
2363  mbFloatBtnVisible(false),
2364  mbHideBtnVisible(false),
2365  mbDisplayable(true)
2366 {
2367  mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(true, this);
2368 }
2369 
2370 MenuBar::MenuBar( const MenuBar& rMenu )
2371  : Menu(),
2372  mbCloseBtnVisible(false),
2373  mbFloatBtnVisible(false),
2374  mbHideBtnVisible(false),
2375  mbDisplayable(true)
2376 {
2377  mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(true, this);
2378  *this = rMenu;
2379 }
2380 
2382 {
2383  disposeOnce();
2384 }
2385 
2387 {
2388  ImplDestroy( this, true );
2389  Menu::dispose();
2390 }
2391 
2393 {
2394  MenuBarWindow* pMenuWin = getMenuBarWindow();
2395  if (!pMenuWin)
2396  return;
2397  pMenuWin->PopupClosed(pMenu);
2398 }
2399 
2401 {
2402  pWindow->KeyInput(rEvent);
2403 }
2404 
2406 {
2408 }
2409 
2410 void MenuBar::ShowButtons( bool bClose, bool bFloat, bool bHide )
2411 {
2412  if ((bClose != mbCloseBtnVisible) ||
2413  (bFloat != mbFloatBtnVisible) ||
2414  (bHide != mbHideBtnVisible))
2415  {
2416  mbCloseBtnVisible = bClose;
2417  mbFloatBtnVisible = bFloat;
2418  mbHideBtnVisible = bHide;
2419  MenuBarWindow* pMenuWin = getMenuBarWindow();
2420  if (pMenuWin)
2421  pMenuWin->ShowButtons(bClose, bFloat, bHide);
2422  }
2423 }
2424 
2426 {
2427  MenuBarWindow* pMenuWin = getMenuBarWindow();
2428  if (pMenuWin)
2429  pMenuWin->LayoutChanged();
2430 }
2431 
2432 void MenuBar::SetDisplayable( bool bDisplayable )
2433 {
2434  if( bDisplayable != mbDisplayable )
2435  {
2436  if ( ImplGetSalMenu() )
2437  ImplGetSalMenu()->ShowMenuBar( bDisplayable );
2438 
2439  mbDisplayable = bDisplayable;
2440  LayoutChanged();
2441  }
2442 }
2443 
2445 {
2446  VclPtr<MenuBarWindow> pMenuBarWindow = dynamic_cast<MenuBarWindow*>(pWindow);
2447  if (!pMenuBarWindow)
2448  {
2449  pWindow = pMenuBarWindow = VclPtr<MenuBarWindow>::Create( pParent );
2450  }
2451 
2452  pMenu->pStartedFrom = nullptr;
2453  pMenu->pWindow = pWindow;
2454  pMenuBarWindow->SetMenu(pMenu);
2455  long nHeight = pWindow ? pMenu->ImplCalcSize(pWindow).Height() : 0;
2456 
2457  // depending on the native implementation or the displayable flag
2458  // the menubar windows is suppressed (ie, height=0)
2459  if (!pMenu->IsDisplayable() || (pMenu->ImplGetSalMenu() && pMenu->ImplGetSalMenu()->VisibleMenuBar()))
2460  {
2461  nHeight = 0;
2462  }
2463 
2464  pMenuBarWindow->SetHeight(nHeight);
2465  return pWindow;
2466 }
2467 
2468 void MenuBar::ImplDestroy( MenuBar* pMenu, bool bDelete )
2469 {
2470  vcl::Window *pWindow = pMenu->ImplGetWindow();
2471  if (pWindow && bDelete)
2472  {
2473  MenuBarWindow* pMenuWin = pMenu->getMenuBarWindow();
2474  if (pMenuWin)
2475  pMenuWin->KillActivePopup();
2476  pWindow->disposeOnce();
2477  }
2478  pMenu->pWindow = nullptr;
2479 }
2480 
2482 {
2483  // No keyboard processing when our menubar is invisible
2484  if (!IsDisplayable())
2485  return false;
2486 
2487  // No keyboard processing when system handles the menu.
2488  SalMenu *pNativeMenu = ImplGetSalMenu();
2489  if (pNativeMenu && pNativeMenu->VisibleMenuBar())
2490  {
2491  // Except when the event is the F6 cycle pane event and we can put our
2492  // focus into it (i.e. the gtk3 menubar case but not the mac/unity case
2493  // where it's not part of the application window)
2494  if (!TaskPaneList::IsCycleKey(rKEvent.GetKeyCode()))
2495  return false;
2496  if (!pNativeMenu->CanGetFocus())
2497  return false;
2498  }
2499 
2500  bool bDone = false;
2501  // check for enabled, if this method is called from another window...
2502  vcl::Window* pWin = ImplGetWindow();
2503  if (pWin && pWin->IsEnabled() && pWin->IsInputEnabled() && !pWin->IsInModalMode())
2504  {
2505  MenuBarWindow* pMenuWin = getMenuBarWindow();
2506  bDone = pMenuWin && pMenuWin->HandleKeyEvent(rKEvent, false/*bFromMenu*/);
2507  }
2508  return bDone;
2509 }
2510 
2512 {
2513  // No keyboard processing when system handles the menu or our menubar is invisible
2514  if( !IsDisplayable() ||
2515  ( ImplGetSalMenu() && ImplGetSalMenu()->VisibleMenuBar() ) )
2516  return false;
2517 
2518  // check for enabled, if this method is called from another window...
2519  MenuBarWindow* pWin = static_cast<MenuBarWindow*>(ImplGetWindow());
2520  if ( pWin && pWin->IsEnabled() && pWin->IsInputEnabled() && ! pWin->IsInModalMode() )
2521  {
2523  {
2524  const CommandModKeyData* pCData = rCEvent.GetModKeyData ();
2525  if (pWin->m_nHighlightedItem == ITEMPOS_INVALID)
2526  {
2527  if (pCData && pCData->IsMod2() && pCData->IsDown())
2528  pWin->SetMBWHideAccel(false);
2529  else
2530  pWin->SetMBWHideAccel(true);
2532  }
2533  return true;
2534  }
2535  }
2536  return false;
2537 }
2538 
2539 void MenuBar::SelectItem(sal_uInt16 nId)
2540 {
2541  if (pWindow)
2542  {
2543  pWindow->GrabFocus();
2544  nId = GetItemPos( nId );
2545 
2546  MenuBarWindow* pMenuWin = getMenuBarWindow();
2547  if (pMenuWin)
2548  {
2549  // #99705# popup the selected menu
2550  pMenuWin->SetAutoPopup( true );
2551  if (ITEMPOS_INVALID != pMenuWin->GetHighlightedItem())
2552  {
2553  pMenuWin->KillActivePopup();
2554  pMenuWin->ChangeHighlightItem( ITEMPOS_INVALID, false );
2555  }
2556  if (nId != ITEMPOS_INVALID)
2557  pMenuWin->ChangeHighlightItem( nId, false );
2558  }
2559  }
2560 }
2561 
2562 // handler for native menu selection and command events
2564 {
2565  if( pMenu )
2566  {
2567  ImplMenuDelData aDelData( this );
2568 
2569  pMenu->pStartedFrom = const_cast<Menu*>(this);
2570  pMenu->bInCallback = true;
2571  pMenu->Activate();
2572 
2573  if( !aDelData.isDeleted() )
2574  pMenu->bInCallback = false;
2575  }
2576  return true;
2577 }
2578 
2580 {
2581  if( pMenu )
2582  {
2583  ImplMenuDelData aDelData( this );
2584 
2585  pMenu->pStartedFrom = const_cast<Menu*>(this);
2586  pMenu->bInCallback = true;
2587  pMenu->Deactivate();
2588  if( !aDelData.isDeleted() )
2589  pMenu->bInCallback = false;
2590  }
2591  return true;
2592 }
2593 
2594 bool MenuBar::HandleMenuHighlightEvent( Menu *pMenu, sal_uInt16 nHighlightEventId ) const
2595 {
2596  if( !pMenu )
2597  pMenu = const_cast<MenuBar*>(this)->ImplFindMenu(nHighlightEventId);
2598  if( pMenu )
2599  {
2600  ImplMenuDelData aDelData( pMenu );
2601 
2604 
2605  if( !aDelData.isDeleted() )
2606  {
2607  pMenu->mnHighlightedItemPos = pMenu->GetItemPos( nHighlightEventId );
2608  pMenu->nSelectedId = nHighlightEventId;
2609  pMenu->sSelectedIdent = pMenu->GetItemIdent( nHighlightEventId );
2610  pMenu->pStartedFrom = const_cast<MenuBar*>(this);
2611  pMenu->ImplCallHighlight( pMenu->mnHighlightedItemPos );
2612  }
2613  return true;
2614  }
2615  else
2616  return false;
2617 }
2618 
2619 bool Menu::HandleMenuCommandEvent( Menu *pMenu, sal_uInt16 nCommandEventId ) const
2620 {
2621  if( !pMenu )
2622  pMenu = const_cast<Menu*>(this)->ImplFindMenu(nCommandEventId);
2623  if( pMenu )
2624  {
2625  pMenu->nSelectedId = nCommandEventId;
2626  pMenu->sSelectedIdent = pMenu->GetItemIdent(nCommandEventId);
2627  pMenu->pStartedFrom = const_cast<Menu*>(this);
2628  pMenu->ImplSelect();
2629  return true;
2630  }
2631  else
2632  return false;
2633 }
2634 
2635 sal_uInt16 MenuBar::AddMenuBarButton( const Image& i_rImage, const Link<MenuBar::MenuBarButtonCallbackArg&,bool>& i_rLink, const OUString& i_rToolTip )
2636 {
2637  MenuBarWindow* pMenuWin = getMenuBarWindow();
2638  return pMenuWin ? pMenuWin->AddMenuBarButton(i_rImage, i_rLink, i_rToolTip) : 0;
2639 }
2640 
2642 {
2643  MenuBarWindow* pMenuWin = getMenuBarWindow();
2644  if (!pMenuWin)
2645  return;
2646  pMenuWin->SetMenuBarButtonHighlightHdl(nId, rLink);
2647 }
2648 
2649 void MenuBar::RemoveMenuBarButton( sal_uInt16 nId )
2650 {
2651  MenuBarWindow* pMenuWin = getMenuBarWindow();
2652  if (!pMenuWin)
2653  return;
2654  pMenuWin->RemoveMenuBarButton(nId);
2655 }
2656 
2658 {
2659  MenuBarWindow* pMenuWin = getMenuBarWindow();
2660  return pMenuWin ? pMenuWin->GetMenuBarButtonRectPixel(nId) : tools::Rectangle();
2661 }
2662 
2663 bool MenuBar::HandleMenuButtonEvent( sal_uInt16 i_nButtonId )
2664 {
2665  MenuBarWindow* pMenuWin = getMenuBarWindow();
2666  return pMenuWin && pMenuWin->HandleMenuButtonEvent(i_nButtonId);
2667 }
2668 
2670 {
2671  MenuBar* pMenuBar = const_cast<MenuBar*>(this);
2672  const SalMenu *pNativeMenu = pMenuBar->ImplGetSalMenu();
2673  int nMenubarHeight;
2674  if (pNativeMenu)
2675  nMenubarHeight = pNativeMenu->GetMenuBarHeight();
2676  else
2677  {
2678  vcl::Window* pMenubarWin = GetWindow();
2679  nMenubarHeight = pMenubarWin ? pMenubarWin->GetOutputHeightPixel() : 0;
2680  }
2681  return nMenubarHeight;
2682 }
2683 
2684 // bool PopupMenu::bAnyPopupInExecute = false;
2685 
2687  return static_cast<MenuFloatingWindow *>(Menu::ImplGetWindow());
2688 }
2689 
2691  : mpLOKNotifier(nullptr)
2692 {
2693  mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(false, this);
2694 }
2695 
2697  : Menu(),
2698  mpLOKNotifier(nullptr)
2699 {
2700  mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(false, this);
2701  *this = rMenu;
2702 }
2703 
2705 {
2706  disposeOnce();
2707 }
2708 
2710 {
2711  MenuFloatingWindow* p = dynamic_cast<MenuFloatingWindow*>(ImplGetWindow());
2712  PopupMenu *pPopup = dynamic_cast<PopupMenu*>(pMenu);
2713  if (p && pPopup)
2714  p->KillActivePopup(pPopup);
2715 }
2716 
2718 {
2719  return GetActivePopupMenu() != nullptr;
2720 }
2721 
2723 {
2724  ImplSVData* pSVData = ImplGetSVData();
2725  return pSVData->maAppData.mpActivePopupMenu;
2726 }
2727 
2729 {
2730  if ( ImplGetWindow() )
2732 }
2733 
2734 void PopupMenu::SelectItem(sal_uInt16 nId)
2735 {
2736  if ( ImplGetWindow() )
2737  {
2738  if( nId != ITEMPOS_INVALID )
2739  {
2740  size_t nPos = 0;
2741  MenuItemData* pData = GetItemList()->GetData( nId, nPos );
2742  if (pData && pData->pSubMenu)
2743  ImplGetFloatingWindow()->ChangeHighlightItem( nPos, true );
2744  else
2746  }
2747  else
2748  {
2750  pFloat->GrabFocus();
2751 
2752  for( size_t nPos = 0; nPos < GetItemList()->size(); nPos++ )
2753  {
2755  if( pData->pSubMenu )
2756  {
2757  pFloat->KillActivePopup();
2758  }
2759  }
2760  pFloat->ChangeHighlightItem( ITEMPOS_INVALID, false );
2761  }
2762  }
2763 }
2764 
2765 void PopupMenu::SetSelectedEntry( sal_uInt16 nId )
2766 {
2767  nSelectedId = nId;
2769 }
2770 
2771 sal_uInt16 PopupMenu::Execute( vcl::Window* pExecWindow, const Point& rPopupPos )
2772 {
2773  return Execute( pExecWindow, tools::Rectangle( rPopupPos, rPopupPos ), PopupMenuFlags::ExecuteDown );
2774 }
2775 
2776 sal_uInt16 PopupMenu::Execute( vcl::Window* pExecWindow, const tools::Rectangle& rRect, PopupMenuFlags nFlags )
2777 {
2778  ENSURE_OR_RETURN( pExecWindow, "PopupMenu::Execute: need a non-NULL window!", 0 );
2779 
2780  FloatWinPopupFlags nPopupModeFlags = FloatWinPopupFlags::NONE;
2781  if ( nFlags & PopupMenuFlags::ExecuteDown )
2782  nPopupModeFlags = FloatWinPopupFlags::Down;
2783  else if ( nFlags & PopupMenuFlags::ExecuteUp )
2784  nPopupModeFlags = FloatWinPopupFlags::Up;
2785  else if ( nFlags & PopupMenuFlags::ExecuteLeft )
2786  nPopupModeFlags = FloatWinPopupFlags::Left;
2787  else if ( nFlags & PopupMenuFlags::ExecuteRight )
2788  nPopupModeFlags = FloatWinPopupFlags::Right;
2789  else
2790  nPopupModeFlags = FloatWinPopupFlags::Down;
2791 
2792  if (nFlags & PopupMenuFlags::NoMouseUpClose ) // allow popup menus to stay open on mouse button up
2793  nPopupModeFlags |= FloatWinPopupFlags::NoMouseUpClose; // useful if the menu was opened on mousebutton down (eg toolbox configuration)
2794 
2795  if (nFlags & PopupMenuFlags::NoHorzPlacement)
2796  nPopupModeFlags |= FloatWinPopupFlags::NoHorzPlacement;
2797 
2798  return ImplExecute( pExecWindow, rRect, nPopupModeFlags, nullptr, false );
2799 }
2800 
2802 {
2803  // is there still Select?
2804  Menu* pSelect = ImplFindSelectMenu();
2805  if (pSelect)
2806  {
2807  // Select should be called prior to leaving execute in a popup menu!
2809  pSelect->nEventId = nullptr;
2810  pSelect->Select();
2811  }
2812 }
2813 
2814 sal_uInt16 PopupMenu::ImplExecute( const VclPtr<vcl::Window>& pW, const tools::Rectangle& rRect, FloatWinPopupFlags nPopupModeFlags, Menu* pSFrom, bool bPreSelectFirst )
2815 {
2816  if ( !pSFrom && ( PopupMenu::IsInExecute() || !GetItemCount() ) )
2817  return 0;
2818 
2819  // set the flag to hide or show accelerators in the menu depending on whether the menu was launched by mouse or keyboard shortcut
2820  if( pSFrom && pSFrom->IsMenuBar())
2821  {
2822  auto pMenuBarWindow = static_cast<MenuBarWindow*>(pSFrom->pWindow.get());
2823  pMenuBarWindow->SetMBWHideAccel( !(pMenuBarWindow->GetMBWMenuKey()) );
2824  }
2825 
2826  mpLayoutData.reset();
2827 
2828  ImplSVData* pSVData = ImplGetSVData();
2829 
2830  pStartedFrom = pSFrom;
2831  nSelectedId = 0;
2832  sSelectedIdent.clear();
2833  bCanceled = false;
2834 
2835  VclPtr<vcl::Window> xFocusId;
2836  bool bRealExecute = false;
2837  if ( !pStartedFrom )
2838  {
2839  pSVData->maWinData.mbNoDeactivate = true;
2840  xFocusId = Window::SaveFocus();
2841  bRealExecute = true;
2842  }
2843  else
2844  {
2845  // assure that only one menu is open at a time
2846  if (pStartedFrom->IsMenuBar() && pSVData->maWinData.mpFirstFloat)
2848  }
2849 
2850  SAL_WARN_IF( ImplGetWindow(), "vcl", "Win?!" );
2851  tools::Rectangle aRect( rRect );
2852  aRect.SetPos( pW->OutputToScreenPixel( aRect.TopLeft() ) );
2853 
2854  if (bRealExecute)
2855  nPopupModeFlags |= FloatWinPopupFlags::NewLevel;
2857 
2858  bInCallback = true; // set it here, if Activate overridden
2859  Activate();
2860  bInCallback = false;
2861 
2862  if ( pW->IsDisposed() )
2863  return 0; // Error
2864 
2865  if ( bCanceled || bKilled )
2866  return 0;
2867 
2868  if ( !GetItemCount() )
2869  return 0;
2870 
2871  // The flag MenuFlags::HideDisabledEntries is inherited.
2872  if ( pSFrom )
2873  {
2876  else
2878  }
2879  else
2880  // #102790# context menus shall never show disabled entries
2882 
2883  sal_uInt16 nVisibleEntries = ImplGetVisibleItemCount();
2884  if ( !nVisibleEntries )
2885  {
2886  OUString aTmpEntryText(VclResId(SV_RESID_STRING_NOSELECTIONPOSSIBLE));
2887 
2888  MenuItemData* pData = NbcInsertItem(0xFFFF, MenuItemBits::NONE, aTmpEntryText, nullptr, 0xFFFF, OString());
2889  size_t nPos = 0;
2890  pData = pItemList->GetData( pData->nId, nPos );
2891  assert(pData);
2892  if (pData)
2893  {
2894  pData->bIsTemporary = true;
2895  }
2897  }
2898 
2902 
2903  if( pSVData->maNWFData.mbFlatMenu )
2905  else
2907  pWindow = pWin;
2908 
2909  Size aSz = ImplCalcSize( pWin );
2910 
2911  tools::Rectangle aDesktopRect(pWin->GetDesktopRectPixel());
2913  {
2915  if( ! pDeskW )
2916  pDeskW = pWindow;
2917  Point aDesktopTL( pDeskW->OutputToAbsoluteScreenPixel( aRect.TopLeft() ) );
2918  aDesktopRect = Application::GetScreenPosSizePixel(
2919  Application::GetBestScreen( tools::Rectangle( aDesktopTL, aRect.GetSize() ) ));
2920  }
2921 
2922  long nMaxHeight = aDesktopRect.GetHeight();
2923 
2924  //rhbz#1021915. If a menu won't fit in the desired location the default
2925  //mode is to place it somewhere it will fit. e.g. above, left, right. For
2926  //some cases, e.g. menubars, it's desirable to limit the options to
2927  //above/below and force the menu to scroll if it won't fit
2928  if (nPopupModeFlags & FloatWinPopupFlags::NoHorzPlacement)
2929  {
2930  vcl::Window* pRef = pWin;
2931  if ( pRef->GetParent() )
2932  pRef = pRef->GetParent();
2933 
2934  tools::Rectangle devRect( pRef->OutputToAbsoluteScreenPixel( aRect.TopLeft() ),
2935  pRef->OutputToAbsoluteScreenPixel( aRect.BottomRight() ) );
2936 
2937  long nHeightAbove = devRect.Top() - aDesktopRect.Top();
2938  long nHeightBelow = aDesktopRect.Bottom() - devRect.Bottom();
2939  nMaxHeight = std::min(nMaxHeight, std::max(nHeightAbove, nHeightBelow));
2940  }
2941 
2943  nMaxHeight -= pW->GetSizePixel().Height();
2944  sal_Int32 nLeft, nTop, nRight, nBottom;
2945  pWindow->GetBorder( nLeft, nTop, nRight, nBottom );
2946  nMaxHeight -= nTop+nBottom;
2947  if ( aSz.Height() > nMaxHeight )
2948  {
2949  pWin->EnableScrollMenu( true );
2950  sal_uInt16 nStart = ImplGetFirstVisible();
2951  sal_uInt16 nEntries = ImplCalcVisEntries( nMaxHeight, nStart );
2952  aSz.setHeight( ImplCalcHeight( nEntries ) );
2953  }
2954 
2955  // tdf#126054 hold this until after function completes
2956  VclPtr<PopupMenu> m_xThis(this);
2957 
2958  pWin->SetFocusId( xFocusId );
2959  pWin->SetOutputSizePixel( aSz );
2960  if ( GetItemCount() )
2961  {
2962  SalMenu* pMenu = ImplGetSalMenu();
2963  if( pMenu && bRealExecute && pMenu->ShowNativePopupMenu( pWin, aRect, nPopupModeFlags | FloatWinPopupFlags::GrabFocus ) )
2964  {
2965  pWin->StopExecute();
2966  pWin->doShutdown();
2969  ImplClosePopupToolBox(pW);
2971  return nSelectedId;
2972  }
2973  else
2974  {
2975  pWin->StartPopupMode( aRect, nPopupModeFlags | FloatWinPopupFlags::GrabFocus );
2976  }
2977  if( pSFrom )
2978  {
2979  sal_uInt16 aPos;
2980  if (pSFrom->IsMenuBar())
2981  aPos = static_cast<MenuBarWindow *>(pSFrom->pWindow.get())->GetHighlightedItem();
2982  else
2983  aPos = static_cast<MenuFloatingWindow *>(pSFrom->pWindow.get())->GetHighlightedItem();
2984 
2985  pWin->SetPosInParent( aPos ); // store position to be sent in SUBMENUDEACTIVATE
2987  }
2988  }
2989  if ( bPreSelectFirst )
2990  {
2991  size_t nCount = pItemList->size();
2992  for ( size_t n = 0; n < nCount; n++ )
2993  {
2994  MenuItemData* pData = pItemList->GetDataFromPos( n );
2995  if ( ( pData->bEnabled
2997  )
2998  && ( pData->eType != MenuItemType::SEPARATOR )
2999  && ImplIsVisible( n )
3000  && ImplIsSelectable( n )
3001  )
3002  {
3003  pWin->ChangeHighlightItem( n, false );
3004  break;
3005  }
3006  }
3007  }
3008  if ( bRealExecute )
3009  {
3010  pWin->Execute();
3011  if (pWin->IsDisposed())
3012  return 0;
3013 
3014  xFocusId = pWin->GetFocusId();
3015  assert(xFocusId == nullptr && "Focus should already be restored by MenuFloatingWindow::End");
3017 
3018  if ( nSelectedId ) // then clean up .. ( otherwise done by TH )
3019  {
3020  PopupMenu* pSub = pWin->GetActivePopup();
3021  while ( pSub )
3022  {
3024  pSub = pSub->ImplGetFloatingWindow()->GetActivePopup();
3025  }
3026  }
3027  pWin->doShutdown();
3030  ImplClosePopupToolBox(pW);
3032  }
3033 
3034  return bRealExecute ? nSelectedId : 0;
3035 }
3036 
3037 sal_uInt16 PopupMenu::ImplCalcVisEntries( long nMaxHeight, sal_uInt16 nStartEntry, sal_uInt16* pLastVisible ) const
3038 {
3039  nMaxHeight -= 2 * ImplGetFloatingWindow()->GetScrollerHeight();
3040 
3041  long nHeight = 0;
3042  size_t nEntries = pItemList->size();
3043  sal_uInt16 nVisEntries = 0;
3044 
3045  if ( pLastVisible )
3046  *pLastVisible = 0;
3047 
3048  for ( size_t n = nStartEntry; n < nEntries; n++ )
3049  {
3050  if ( ImplIsVisible( n ) )
3051  {
3052  MenuItemData* pData = pItemList->GetDataFromPos( n );
3053  nHeight += pData->aSz.Height();
3054  if ( nHeight > nMaxHeight )
3055  break;
3056 
3057  if ( pLastVisible )
3058  *pLastVisible = n;
3059  nVisEntries++;
3060  }
3061  }
3062  return nVisEntries;
3063 }
3064 
3065 long PopupMenu::ImplCalcHeight( sal_uInt16 nEntries ) const
3066 {
3067  long nHeight = 0;
3068 
3069  sal_uInt16 nFound = 0;
3070  for ( size_t n = 0; ( nFound < nEntries ) && ( n < pItemList->size() ); n++ )
3071  {
3072  if ( ImplIsVisible( static_cast<sal_uInt16>(n) ) )
3073  {
3074  MenuItemData* pData = pItemList->GetDataFromPos( n );
3075  nHeight += pData->aSz.Height();
3076  nFound++;
3077  }
3078  }
3079 
3080  nHeight += 2*ImplGetFloatingWindow()->GetScrollerHeight();
3081 
3082  return nHeight;
3083 }
3084 
3086 : mpNext( nullptr )
3087 , mpMenu( nullptr )
3088 {
3089  if( pMenu )
3090  const_cast< Menu* >( pMenu )->ImplAddDel( *this );
3091 }
3092 
3094 {
3095  if( mpMenu )
3096  const_cast< Menu* >( mpMenu.get() )->ImplRemoveDel( *this );
3097 }
3098 
3099 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString const aAccessibleName
void RemoveItem(sal_uInt16 nPos)
Definition: menu.cxx:505
Point TopLeft() const
OString GetHelpId(sal_uInt16 nItemId) const
Definition: menu.cxx:1134
long getHeight() const
long Width() const
VclPtr< Menu > pSubMenu
Size GetSizePixel() const
Definition: Image.cxx:75
const Color & GetTextColor() const
Definition: outdev.hxx:1110
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
Definition: text.cxx:779
void SetPos(const Point &rPoint)
tools::Rectangle GetMenuBarButtonRectPixel(sal_uInt16 nId)
const Color & GetShadowColor() const
void UpdateNativeMenu()
Definition: menu.cxx:2203
void Clear()
Definition: menu.cxx:580
bool IsInputEnabled() const
Definition: window2.cxx:1121
OUString GetEllipsisString(const OUString &rStr, long nMaxWidth, DrawTextFlags nStyle=DrawTextFlags::EndEllipsis) const
Definition: text.cxx:1918
void Deactivate()
Definition: menu.cxx:275
bool HandleMenuButtonEvent(sal_uInt16 nEventId)
Definition: menu.cxx:2663
long GetWidth() const
bool IsItemChecked(sal_uInt16 nItemId) const
Definition: menu.cxx:892
const Wallpaper & GetBackground() const
Definition: outdev.hxx:631
PopupMenu * GetPopupMenu(sal_uInt16 nItemId) const
Definition: menu.cxx:759
void StartPopupMode(const tools::Rectangle &rRect, FloatWinPopupFlags nFlags)
Definition: floatwin.cxx:721
void SetItemBits(sal_uInt16 nItemId, MenuItemBits nBits)
Definition: menu.cxx:680
void SetItemImage(sal_uInt16 nItemId, const Image &rImage)
Definition: menu.cxx:1012
int mnMenuSeparatorBorderX
Definition: svdata.hxx:269
SAL_DLLPRIVATE void ImplPaintMenuTitle(vcl::RenderContext &, const tools::Rectangle &rRect) const
Definition: menu.cxx:1677
void setHeight(long n)
SAL_DLLPRIVATE void ImplFlushPendingSelect()
Definition: menu.cxx:2801
WinBits const WB_SYSTEMWINDOW
bool IsMod2() const
long GetHeight() const
MenuItemType
Definition: vclenum.hxx:30
bool bCanceled
Terminated during a callback.
Definition: menu.hxx:155
void DrawImage(const Point &rPos, const Image &rImage, DrawImageFlags nStyle=DrawImageFlags::NONE)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::vector< tools::Rectangle > MetricVector
Definition: outdev.hxx:139
css::uno::Reference< css::accessibility::XAccessible > GetAccessible()
Definition: menu.cxx:1284
void ChangeHighlightItem(sal_uInt16 n, bool bStartPopupTimer)
bool DrawNativeControl(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, const OUString &aCaption)
Request rendering of a particular control and/or part.
void ShowButtons(bool bClose, bool bFloat, bool bHide)
Definition: menu.cxx:2410
SAL_DLLPRIVATE void ImplKillLayoutData() const
Definition: menu.cxx:2213
const Color & GetMenuBarTextColor() const
long AdjustWidth(long n)
int mnMenuFormatBorderX
Definition: svdata.hxx:267
long AdjustX(long nHorzMove)
bool GetNativeControlRegion(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, tools::Rectangle &rNativeBoundingRegion, tools::Rectangle &rNativeContentRegion) const
Query the native control's actual drawing region (including adornment)
SAL_DLLPRIVATE bool ImplCurrentlyHiddenOnGUI(sal_uInt16 nPos) const
Definition: menu.cxx:1175
virtual void ClosePopup(Menu *pMenu) override
Close the 'pStartedFrom' menu window.
Definition: menu.cxx:2392
vcl::KeyCode aAccelKey
virtual void SelectItem(sal_uInt16 nId) override
Definition: menu.cxx:2539
OUString GetPopupLabelForCommand(const OUString &rsCommandName, const OUString &rsModuleName)
void SetHelpId(sal_uInt16 nItemId, const OString &rHelpId)
Definition: menu.cxx:1126
long Height() const
Definition: help.hxx:60
void AddEventListener(const Link< VclMenuEvent &, void > &rEventListener)
Definition: menu.cxx:395
static Help * GetHelp()
Gets the application's help.
Definition: svapp.cxx:1318
SalLayoutGlyphs aTextGlyphs
Text layout of aText.
void PopupClosed(Menu const *pMenu)
SAL_DLLPRIVATE MenuItemData * NbcInsertItem(sal_uInt16 nId, MenuItemBits nBits, const OUString &rStr, Menu *pMenu, size_t nPos, const OString &rIdent)
Definition: menu.cxx:405
void DrawCtrlText(const Point &rPos, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, DrawTextFlags nStyle=DrawTextFlags::Mnemonic, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pGlyphs=nullptr)
Definition: text.cxx:2052
bool mbNoDeactivate
Definition: svdata.hxx:216
long getWidth() const
bool IsBackground() const
Definition: outdev.hxx:634
OUString aHelpText
long AdjustLeft(long nHorzMoveDelta)
MenuItemBits GetItemBits(sal_uInt16 nItemId) const
Definition: menu.cxx:695
ImplSVAppData maAppData
Definition: svdata.hxx:352
SAL_DLLPRIVATE void ImplRemoveDel(ImplMenuDelData &rDel)
Definition: menu.cxx:1389
virtual ~Menu() override
Definition: menu.cxx:175
void disposeAndClear()
Definition: vclptr.hxx:200
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:705
VclPtr< PopupMenu > mpActivePopupMenu
Definition: svdata.hxx:143
virtual void ShowItem(unsigned nPos, bool bShow)
Definition: salmenu.hxx:88
const Color & GetFaceColor() const
static bool IsCycleKey(const vcl::KeyCode &rKeyCode)
void DrawFrame(const tools::Rectangle &rRect, const Color &rLeftTopColor, const Color &rRightBottomColor)
Definition: decoview.cxx:848
ImplSVNWFData maNWFData
Definition: svdata.hxx:357
bool isDeleted() const
Definition: menu.hxx:116
virtual void SetItemImage(unsigned nPos, SalMenuItem *pSalMenuItem, const Image &rImage)=0
Link< Menu *, bool > aSelectHdl
Definition: menu.hxx:138
css::beans::Optional< css::uno::Any > getValue(OUString const &id)
PopupMenu * GetActivePopup() const
virtual Size GetSizePixel() const
Definition: window.cxx:2364
#define KEY_0
Definition: keycodes.hxx:45
aBuf
SAL_DLLPRIVATE WindowImpl * ImplGetWindowImpl() const
Definition: window.hxx:552
void SetWeight(FontWeight)
Definition: font/font.cxx:214
sal_Int16 nId
void SetLOKNotifier(const vcl::ILibreOfficeKitNotifier *pNotifier, bool bParent=false)
Interface to register for dialog / window tunneling.
Definition: window.cxx:3168
SAL_DLLPRIVATE void ImplCallEventListeners(VclEventId nEvent, sal_uInt16 nPos)
Definition: menu.cxx:371
Link< Menu *, bool > aDeactivateHdl
Definition: menu.hxx:137
void ChangeHighlightItem(sal_uInt16 n, bool bSelectPopupEntry, bool bAllowRestoreFocus=true, bool bDefaultToDocument=true)
void SetSelectedEntry(sal_uInt16 nId)
Definition: menu.cxx:2765
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
Post a user event to the default window.
Definition: svapp.cxx:997
SAL_DLLPRIVATE bool ImplHandleCmdEvent(const CommandEvent &rCEvent)
Definition: menu.cxx:2511
void ShowButtons(bool bClose, bool bFloat, bool bHide)
void SetAutoPopup(bool bAuto)
sal_uInt16 GetCode() const
Definition: keycod.hxx:53
static bool IsUnifiedDisplay()
Determines if the screens that make up a display are separate or form one large display area...
Definition: svapp.cxx:1191
void setTristateVal(ButtonValue nTristate)
sal_uInt16 GetItemPos(sal_uInt16 nItemId) const
Definition: menu.cxx:653
sal_uInt16 Execute(vcl::Window *pWindow, const Point &rPopupPos)
Definition: menu.cxx:2771
tools::Rectangle GetDesktopRectPixel() const
Definition: window.cxx:2811
VclPtr< vcl::Window > pWindow
Definition: menu.hxx:134
OUString CreateMnemonic(const OUString &rKey)
Definition: mnemonic.cxx:116
bool IsDown() const
bool HandleMenuHighlightEvent(Menu *pMenu, sal_uInt16 nEventId) const
Definition: menu.cxx:2594
void SetHelpText(sal_uInt16 nItemId, const OUString &rString)
Definition: menu.cxx:1075
const CommandModKeyData * GetModKeyData() const
long getY() const
void KillActivePopup()
float x
SAL_DLLPRIVATE sal_uInt16 ImplCalcVisEntries(long nMaxHeight, sal_uInt16 nStartEntry, sal_uInt16 *pLastVisible=nullptr) const
Definition: menu.cxx:3037
void LayoutChanged()
Definition: menu.cxx:2425
void SetTipHelpText(sal_uInt16 nItemId, const OUString &rString)
Definition: menu.cxx:1108
OUString aTitleText
Definition: menu.hxx:142
long AdjustHeight(long n)
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
VclPtr< Menu > pStartedFrom
Definition: menu.hxx:133
std::list< Link< VclMenuEvent &, void > > maEventListeners
Definition: menu.hxx:140
const Color & GetHighlightColor() const
MenuItemBits
Definition: vclenum.hxx:32
bool GetTextBoundRect(tools::Rectangle &rRect, const OUString &rStr, sal_Int32 nBase=0, sal_Int32 nIndex=0, sal_Int32 nLen=-1, sal_uLong nLayoutWidth=0, const long *pDXArray=nullptr, const SalLayoutGlyphs *pGlyphs=nullptr) const
Return the exact bounding rectangle of rStr.
Definition: text.cxx:2309
long AdjustBottom(long nVertMoveDelta)
static SAL_DLLPRIVATE VclPtr< vcl::Window > ImplCreate(vcl::Window *pParent, vcl::Window *pWindow, MenuBar *pMenu)
Definition: menu.cxx:2444
const Color & GetMenuHighlightTextColor() const
OString sSelectedIdent
Definition: menu.hxx:149
SAL_DLLPRIVATE Size ImplCalcSize(vcl::Window *pWin)
Definition: menu.cxx:1408
sal_uInt16 nImgOrChkPos
Definition: menu.hxx:152
WEIGHT_BOLD
sal_uInt16 nTextPos
Definition: menu.hxx:153
sal_uInt16 sal_Unicode
void SetBackground()
OUString aCommandStr
WindowBorderStyle GetBorderStyle() const
Definition: window.cxx:1997
SAL_DLLPRIVATE OUString ImplGetHelpText(sal_uInt16 nItemId) const
Definition: menu.cxx:1083
void CreateAutoMnemonics()
Definition: menu.cxx:226
#define KEY_MOD2
Definition: keycodes.hxx:32
SymbolType
Definition: vclenum.hxx:73
void setX(long nX)
const vcl::Font & GetFont() const
Definition: outdev.hxx:637
EdgeEntry * mpNext
void * nUserValue
ImplMenuDelData * mpNext
Definition: menu.hxx:110
bool IsHighlighted(sal_uInt16 nItemPos) const
Definition: menu.cxx:2318
SAL_DLLPRIVATE Menu * ImplFindMenu(sal_uInt16 nId)
Definition: menu.cxx:2151
virtual void ClosePopup(Menu *pMenu) override
Close the 'pStartedFrom' menu window.
Definition: menu.cxx:2709
MenuItemType GetItemType(sal_uInt16 nPos) const
Definition: menu.cxx:664
Class that implements the actual window of the floating menu.
void SetItemCommand(sal_uInt16 nItemId, const OUString &rCommand)
Definition: menu.cxx:1038
bool mbFloatBtnVisible
Definition: menu.hxx:396
void SetUserValue(sal_uInt16 nItemId, void *nUserValue, MenuUserDataReleaseFunction aFunc=nullptr)
Definition: menu.cxx:704
const Color & GetLightColor() const
virtual void Update()
Definition: salmenu.hxx:82
tools::Rectangle GetCharacterBounds(sal_uInt16 nItemId, long nIndex) const
Definition: menu.cxx:2236
VclEventId
Definition: vclevent.hxx:41
OUString GetItemCommand(sal_uInt16 nItemId) const
Definition: menu.cxx:1047
void SetMenuBarButtonHighlightHdl(sal_uInt16 nId, const Link< MenuBar::MenuBarButtonCallbackArg &, bool > &)
Definition: menu.cxx:2641
void SetBorderStyle(WindowBorderStyle nBorderStyle)
Definition: window.cxx:1957
#define KEY_A
Definition: keycodes.hxx:56
virtual void SetOutputSizePixel(const Size &rNewSize)
Definition: window2.cxx:1268
long Top() const
void InsertSeparator(const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
Definition: menu.cxx:481
void SetAccessible(const css::uno::Reference< css::accessibility::XAccessible > &)
std::map< sal_uInt16, tools::Rectangle > m_aVisibleItemBoundRects
Definition: menu.cxx:65
long getX() const
SAL_DLLPRIVATE SalMenu * ImplGetSalMenu()
Definition: menu.hxx:185
OUString aTipHelpText
void setY(long nY)
void DrawLine(const Point &rStartPt, const Point &rEndPt)
Definition: line.cxx:88
bool IsItemEnabled(sal_uInt16 nItemId) const
Definition: menu.cxx:937
const Color & GetMenuTextColor() const
if(nullptr==pCandidateA||nullptr==pCandidateB)
Menu()
The Menu constructor is protected.
Definition: menu.cxx:157
void setWidth(long n)
static void ImplCallEventListeners(VclSimpleEvent &rEvent)
Send event to all VCL application event listeners.
Definition: svapp.cxx:759
void KillActivePopup(PopupMenu *pThisOnly=nullptr)
bool mbAutoAccel
Definition: svdata.hxx:293
SAL_DLLPRIVATE sal_uInt16 ImplGetNextVisible(sal_uInt16 nPos) const
Definition: menu.cxx:622
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:32
virtual int GetMenuBarHeight() const
Definition: salvtables.cxx:218
css::uno::Reference< css::lang::XComponent > xComponent
std::vector< sal_uInt16 > m_aLineItemIds
Definition: menu.cxx:64
const Color & GetMenuColor() const
float y
virtual void SetItemText(unsigned nPos, SalMenuItem *pSalMenuItem, const OUString &rText)=0
void SetPopupMenu(sal_uInt16 nItemId, PopupMenu *pMenu)
Definition: menu.cxx:722
Class that implements the actual window of the menu bar.
const vcl::ILibreOfficeKitNotifier * mpLOKNotifier
To emit the LOK callbacks eg. for dialog tunneling.
Definition: menu.hxx:490
bool IsDisplayable() const
Definition: menu.hxx:450
OString aHelpId
bool HasCheck() const
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
Remove user event based on event ID.
Definition: svapp.cxx:1025
void SetMBWHideAccel(bool val)
Point BottomRight() const
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:67
NONE
void SetLineColor()
void clear()
Definition: vclptr.hxx:190
virtual OUString GetHelpText(const OUString &aHelpURL, const vcl::Window *pWindow)
Definition: help.cxx:67
int GetMenuBarHeight() const
Definition: menu.cxx:2669
SAL_DLLPRIVATE bool ImplHandleKeyEvent(const KeyEvent &rKEvent)
Definition: menu.cxx:2481
static tools::Rectangle GetScreenPosSizePixel(unsigned int nScreen)
Get a screen's rectangular area.
Definition: svapp.cxx:1226
sal_uInt16 GetCurItemId() const
Definition: menu.hxx:265
sal_uInt16 nId
OUString GetModuleIdentifier(const Reference< frame::XFrame > &rxFrame)
SAL_DLLPRIVATE Size ImplGetNativeCheckAndRadioSize(vcl::RenderContext const &rRenderContext, long &rCheckHeight, long &rRadioHeight) const
Definition: menu.cxx:1321
ImplMenuDelData(const Menu *)
Definition: menu.cxx:3085
std::unique_ptr< MenuItemList > pItemList
Definition: menu.hxx:132
long AdjustY(long nVertMove)
const VclPtr< vcl::Window > & GetFocusId() const
const Color & GetMenuBarColor() const
bool bInCallback
In Activate/Deactivate.
Definition: menu.hxx:156
void setY(long y)
void SetMenu(MenuBar *pMenu)
Menu & operator=(const Menu &rMenu)
Definition: menu.cxx:1151
bool IsDark() const
bool HandleMenuDeActivateEvent(Menu *pMenu) const
Definition: menu.cxx:2579
virtual bool CanGetFocus() const
Definition: salmenu.hxx:84
static PopupMenu * GetActivePopupMenu()
Definition: menu.cxx:2722
ImplDockingWindowWrapper.
Definition: dockwin.hxx:70
SAL_DLLPRIVATE void ImplAddDel(ImplMenuDelData &rDel)
Definition: menu.cxx:1378
bool HandleMenuButtonEvent(sal_uInt16 i_nButtonId)
int i
VclPtr< const Menu > mpMenu
Definition: menu.hxx:111
sal_uInt16 GetItemId(sal_uInt16 nPos) const
Definition: menu.cxx:632
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1153
const Color & GetMenuBarHighlightTextColor() const
MenuItemType eType
Image GetItemImage(sal_uInt16 nItemId) const
Definition: menu.cxx:1028
bool HandleMenuActivateEvent(Menu *pMenu) const
Definition: menu.cxx:2563
void SetFillColor()
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
#define ENSURE_OR_RETURN(c, m, r)
CommandEventId GetCommand() const
sal_uInt16 GetScrollerHeight() const
SAL_DLLPRIVATE bool ImplIsSelectable(sal_uInt16 nPos) const
Definition: menu.cxx:1272
void SetTextColor(const Color &rColor)
Definition: text.cxx:662
long Bottom() const
sal_uInt16 AddMenuBarButton(const Image &, const Link< MenuBar::MenuBarButtonCallbackArg &, bool > &, const OUString &)
Definition: menu.cxx:2635
bool IsInModalMode() const
A window is in modal mode if one of its children or subchildren is a running modal window (a modal di...
Definition: window.cxx:3455
DrawSymbolFlags
Definition: decoview.hxx:34
PopupMenu()
Definition: menu.cxx:2690
SAL_DLLPRIVATE Menu * ImplFindSelectMenu()
Definition: menu.cxx:2136
SalFrameGeometry maGeometry
absolute, unmirrored values
Definition: salframe.hxx:127
OUString GetName(vcl::Window *pWindow=nullptr) const
Definition: keycod.cxx:78
size
SAL_DLLPRIVATE sal_uInt16 ImplGetPrevVisible(sal_uInt16 nPos) const
Definition: menu.cxx:612
virtual ~PopupMenu() override
Definition: menu.cxx:2704
bool mbHideBtnVisible
Definition: menu.hxx:397
virtual void RemoveItem(unsigned nPos)=0
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
bool IsItemPosVisible(sal_uInt16 nItemPos) const
Definition: menu.cxx:1262
Size GetOutputSizePixel() const
Definition: outdev.hxx:441
SAL_DLLPRIVATE bool ImplIsVisible(sal_uInt16 nPos) const
Definition: menu.cxx:1189
DrawTextFlags
Definition: outdev.hxx:144
static unsigned int GetScreenCount()
Get the number of screens available for the display.
Definition: svapp.cxx:1185
MenuItemList * GetItemList() const
Definition: menu.hxx:350
static SAL_DLLPRIVATE unsigned int GetBestScreen(const tools::Rectangle &)
Get the "best" screen.
Definition: svapp.cxx:1243
virtual void ShowMenuBar(bool)
Definition: salmenu.hxx:66
sal_uInt16 GetHighlightedItem() const
DocumentType const eType
std::unique_ptr< SalMenuItem > pSalMenuItem
tools::Rectangle GetBoundingRectangle(sal_uInt16 nItemPos) const
Definition: menu.cxx:2279
FloatWinPopupFlags
Definition: floatwin.hxx:31
void GrabFocus()
Definition: window.cxx:2980
SAL_DLLPRIVATE Menu * ImplGetStartMenu()
Definition: menu.cxx:2101
long GetTextHeight() const
Height where any character of the current font fits; in logic coordinates.
Definition: text.cxx:888
vcl::Window * GetParent() const
Definition: window2.cxx:1091
SalLayoutGlyphs * GetTextGlyphs(const OutputDevice *pOutputDevice)
Computes aText's text layout (glyphs), cached in aTextGlyphs.
long X() const
virtual void EnableItem(unsigned nPos, bool bEnable)=0
void SetParentToDefaultWindow()
Definition: window.cxx:1751
SAL_DLLPRIVATE sal_uInt16 ImplGetFirstVisible() const
Definition: menu.cxx:602
Point OutputToAbsoluteScreenPixel(const Point &rPos) const
Definition: window.cxx:2867
void SetPosInParent(sal_uInt16 nPos)
Size GetSize() const
OUString GetItemText(sal_uInt16 nItemId) const
Definition: menu.cxx:1001
SAL_DLLPRIVATE vcl::Window * ImplGetWindow() const
Definition: menu.hxx:213
bool mbCloseBtnVisible
Definition: menu.hxx:395
static bool IsInExecute()
Definition: menu.cxx:2717
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
Definition: menu.cxx:903
SalFrame * mpFrame
Definition: window.h:225
float GetDPIScaleFactor() const
Definition: outdev.hxx:512
OUString GetHelpCommand(sal_uInt16 nItemId) const
Definition: menu.cxx:1065
void CheckItem(sal_uInt16 nItemId, bool bCheck=true)
Definition: menu.cxx:822
virtual void MenuBarKeyInput(const KeyEvent &rEvent) override
Forward the KeyInput call to the MenuBar.
Definition: menu.cxx:2400
void HighlightItem(sal_uInt16 nItemPos)
Definition: menu.cxx:2333
bool IsInPopupMode(const vcl::Window *pWin)
Definition: dockmgr.cxx:352
virtual void dispose()
virtual void SetItemBits(unsigned, MenuItemBits)
Definition: salmenu.hxx:71
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1035
SAL_DLLPRIVATE void ImplPaint(vcl::RenderContext &rRenderContext, Size const &rSize, sal_uInt16 nBorder, long nOffY=0, MenuItemData const *pThisDataOnly=nullptr, bool bHighlighted=false, bool bLayout=false, bool bRollover=false) const
Definition: menu.cxx:1713
SAL_DLLPRIVATE void ImplEndPopupMode(FloatWinPopupEndFlags nFlags, const VclPtr< vcl::Window > &xFocusId)
Definition: floatwin.cxx:813
OUString aHelpCommandStr
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1767
bool mbDisplayable
Definition: menu.hxx:398
ImplSVWinData maWinData
Definition: svdata.hxx:354
void GetBorder(sal_Int32 &rLeftBorder, sal_Int32 &rTopBorder, sal_Int32 &rRightBorder, sal_Int32 &rBottomBorder) const
Definition: window.cxx:2386
SAL_DLLPRIVATE void ImplSelect()
Definition: menu.cxx:318
std::unique_ptr< vcl::MenuLayoutData > mpLayoutData
Definition: menu.hxx:160
void RemoveMenuBarButton(sal_uInt16 nId)
long GetCtrlTextWidth(const OUString &rStr, const SalLayoutGlyphs *pLayoutCache=nullptr) const
Definition: text.cxx:2196
A construction helper for a temporary VclPtr.
Definition: vclptr.hxx:275
void InsertItem(sal_uInt16 nItemId, const OUString &rStr, MenuItemBits nItemBits=MenuItemBits::NONE, const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
Definition: menu.cxx:420
OUString GetTipHelpText(sal_uInt16 nItemId) const
Definition: menu.cxx:1116
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:53
MenuItemData * GetDataFromPos(size_t nPos) const
Definition: menu.hxx:121
virtual void MenuBarKeyInput(const KeyEvent &rEvent)
Forward the KeyInput call to the MenuBar.
Definition: menu.cxx:2209
void SetHelpCommand(sal_uInt16 nItemId, const OUString &rString)
Definition: menu.cxx:1057
KeyEvent GetActivationKey(sal_uInt16 nItemId) const
Definition: menu.cxx:797
virtual void SetAccelerator(unsigned nPos, SalMenuItem *pSalMenuItem, const vcl::KeyCode &rKeyCode, const OUString &rKeyName)=0
void GetSystemMenuData(SystemMenuData *pData) const
Definition: menu.cxx:2309
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible(Menu *pMenu, bool bIsMenuBar)=0
void EndExecute()
Definition: menu.cxx:2728
OString sIdent
long AdjustRight(long nHorzMoveDelta)
virtual void CheckItem(unsigned nPos, bool bCheck)=0
DockingManager * ImplGetDockingManager()
Definition: svdata.cxx:299
long GetOutputHeightPixel() const
Definition: outdev.hxx:444
void RemoveEventListener(const Link< VclMenuEvent &, void > &rEventListener)
Definition: menu.cxx:400
virtual bool ShowNativePopupMenu(FloatingWindow *pWin, const tools::Rectangle &rRect, FloatWinPopupFlags nFlags)
Definition: salvtables.cxx:195
void * GetUserValue(sal_uInt16 nItemId) const
Definition: menu.cxx:716
void SetFocusId(const VclPtr< vcl::Window > &xId)
void SetAccessible(const css::uno::Reference< css::accessibility::XAccessible > &rxAccessible)
Definition: menu.cxx:1316
bool GetUseImagesInMenus() const
void Activate()
Definition: menu.cxx:244
#define SAL_WARN_IF(condition, area, stream)
SAL_DLLPRIVATE sal_uInt16 ImplGetVisibleItemCount() const
Definition: menu.cxx:591
WinBits const WB_BORDER
void SetDisplayable(bool bDisplayable)
Definition: menu.cxx:2432
vcl::Window * GetWindow() const
Definition: menu.hxx:377
MenuUserDataReleaseFunction aUserValueReleaseFunc
virtual bool IsMenuBar() const =0
void SetFont(const vcl::Font &rNewFont)
bool mbFlatMenu
Definition: svdata.hxx:278
SAL_DLLPRIVATE void ImplFillLayoutData() const
Definition: menu.cxx:2218
sal_uInt16 AddMenuBarButton(const Image &, const Link< MenuBar::MenuBarButtonCallbackArg &, bool > &, const OUString &)
Add an arbitrary button to the menubar that will appear next to the close button. ...
void ShowItem(sal_uInt16 nItemId, bool bVisible=true)
Definition: menu.cxx:948
ImplMenuDelData * mpFirstDel
Definition: menu.hxx:131
bool IsVisible() const
Definition: window2.cxx:1096
#define gfxExtra
ImplDockingWindowWrapper * GetDockingWindowWrapper(const vcl::Window *pWin)
Definition: dockmgr.cxx:274
sal_uInt16 GetItemCount() const
Definition: menu.cxx:586
Definition: image.hxx:51
sal_uInt16 nSelectedId
Definition: menu.hxx:148
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
MenuItemData * GetData(sal_uInt16 nSVId, size_t &rPos) const
sal_uInt16 nTitleHeight
Definition: menu.hxx:143
void SetMenuBarButtonHighlightHdl(sal_uInt16 nId, const Link< MenuBar::MenuBarButtonCallbackArg &, bool > &)
SAL_DLLPRIVATE void ImplClearSalMenu()
Definition: menu.cxx:2304
long AdjustTop(long nVertMoveDelta)
FloatingWindow * GetFloatingWindow() const
Definition: dockwin.hxx:155
OUString GetHelpText(sal_uInt16 nItemId) const
Definition: menu.cxx:1103
sal_uInt16 mnHighlightedItemPos
Definition: menu.hxx:146
void SetAccelKey(sal_uInt16 nItemId, const vcl::KeyCode &rKeyCode)
Definition: menu.cxx:769
OUString GetTooltipForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame)
bool GetSkipDisabledInMenus() const
long Left() const
vcl::KeyCode GetAccelKey(sal_uInt16 nItemId) const
Definition: menu.cxx:787
long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
Width of the text.
Definition: text.cxx:877
virtual void InsertItem(SalMenuItem *pSalMenuItem, unsigned nPos)=0
VclPtr< FloatingWindow > mpFirstFloat
Definition: svdata.hxx:204
SAL_DLLPRIVATE MenuFloatingWindow * ImplGetFloatingWindow() const
Definition: menu.cxx:2686
bool IsDisposed() const
Definition: window.cxx:135
void SetHeight(long nHeight)
virtual std::unique_ptr< SalMenu > CreateMenu(bool bMenuBar, Menu *pMenu)
Definition: salvtables.cxx:130
std::unique_ptr< SalMenu > mpSalMenu
Definition: menu.hxx:161
OString const aName
SAL_DLLPRIVATE long ImplCalcHeight(sal_uInt16 nEntries) const
Definition: menu.cxx:3065
WindowType GetType() const
Definition: window2.cxx:968
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
bool IsEnabled() const
Definition: window2.cxx:1116
#define SAL_WARN(area, stream)
SAL_DLLPRIVATE void ImplCallHighlight(sal_uInt16 nHighlightItem)
Definition: menu.cxx:2109
void DrawSymbol(const tools::Rectangle &rRect, SymbolType eType, const Color &rColor, DrawSymbolFlags nStyle=DrawSymbolFlags::NONE)
Definition: decoview.cxx:805
OUString aText
OUString VclResId(const char *pId)
Definition: svdata.cxx:258
css::uno::Reference< css::accessibility::XAccessible > mxAccessible
Definition: menu.hxx:159
static SAL_DLLPRIVATE bool ImplGetNativeSubmenuArrowSize(vcl::RenderContext const &rRenderContext, Size &rArrowSize, long &rArrowSpacing)
Definition: menu.cxx:1357
ImplSVEvent * nEventId
Definition: menu.hxx:145
virtual void GetSystemMenuData(SystemMenuData *pData)=0
MenuBar()
Definition: menu.cxx:2360
Point OutputToScreenPixel(const Point &rPos) const
Definition: window.cxx:2818
tools::Rectangle GetMenuBarButtonRectPixel(sal_uInt16 nId)
Definition: menu.cxx:2657
static UnoWrapperBase * GetUnoWrapper(bool bCreateIfNotExists=true)
Get the application's UNO wrapper object.
Definition: svapp.cxx:1433
virtual void SelectItem(sal_uInt16 nId) override
Definition: menu.cxx:2734
void setX(long x)
virtual void SetSubMenu(SalMenuItem *pSalMenuItem, SalMenu *pSubMenu, unsigned nPos)=0
void RemoveDisabledEntries(bool bCheckPopups=true, bool bRemoveEmptyPopups=false)
Definition: menu.cxx:2168
static SettingsConfigItem * get()
bool HandleMenuCommandEvent(Menu *pMenu, sal_uInt16 nEventId) const
Definition: menu.cxx:2619
bool IsReallyVisible() const
Definition: window2.cxx:1101
const Color & GetMenuBarRolloverTextColor() const
virtual ~MenuBar() override
Definition: menu.cxx:2381
static OUString GetNonMnemonicString(const OUString &rStr, sal_Int32 &rMnemonicPos)
Definition: text.cxx:2213
Link< Menu *, bool > aActivateHdl
Definition: menu.hxx:136
void Push(PushFlags nFlags=PushFlags::ALL)
Definition: outdevstate.cxx:60
SAL_DLLPRIVATE sal_uInt16 ImplExecute(const VclPtr< vcl::Window > &pW, const tools::Rectangle &rRect, FloatWinPopupFlags nPopupModeFlags, Menu *pSFrom, bool bPreSelectFirst)
Definition: menu.cxx:2814
OString GetItemIdent(sal_uInt16 nItemId) const
Definition: menu.cxx:674
sal_Int32 nPos
OUString GetAccessibleName(sal_uInt16 nItemId) const
Definition: menu.cxx:2294
void setWidth(long nWidth)
void RegisterMnemonic(const OUString &rKey)
Definition: mnemonic.cxx:76
void EndPopupMode(FloatWinPopupEndFlags nFlags=FloatWinPopupEndFlags::NONE)
Definition: floatwin.cxx:886
bool bKilled
Killed.
Definition: menu.hxx:157
DrawImageFlags
Definition: outdev.hxx:172
aStr
long GetIndexForPoint(const Point &rPoint, sal_uInt16 &rItemID) const
Definition: menu.cxx:2255
long ImplGetStartY() const
Get a negative pixel offset for an offset menu.
virtual void dispose() override
Definition: menu.cxx:180
virtual bool VisibleMenuBar()=0
bool IsMenuVisible() const
Definition: menu.cxx:1267
SalInstance * mpDefInst
Definition: svdata.hxx:341
MenuFlags nMenuFlags
Definition: menu.hxx:147
unsigned int nDisplayScreenNumber
Definition: salgeom.hxx:37
void RemoveMenuBarButton(sal_uInt16 nId)
Definition: menu.cxx:2649
long Y() const
virtual void Select()
Definition: menu.cxx:339
virtual void dispose() override
Definition: menu.cxx:2386
void ShowCloseButton(bool bShow)
Definition: menu.cxx:2405
sal_uInt16 m_nHighlightedItem
MenuBarWindow * getMenuBarWindow()
Return the MenuBarWindow.
Definition: menu.cxx:2350
void SetItemText(sal_uInt16 nItemId, const OUString &rStr)
Definition: menu.cxx:970
bool HandleKeyEvent(const KeyEvent &rKEvent, bool bFromMenu=true)
MenuItemBits nBits
void setHeight(long nHeight)
static SAL_DLLPRIVATE void ImplDestroy(MenuBar *pMenu, bool bDelete)
Definition: menu.cxx:2468