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