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