24#include <rtl/ustring.hxx>
27#include <osl/diagnose.h>
32#include <sfx2/strings.hrc>
36#include <com/sun/star/util/XStringWidth.hpp>
44#include <objc/objc-runtime.h>
45#include <Cocoa/Cocoa.h>
56#define MI_STARTMODULE 9
61-(void)executeMenuItem: (NSMenuItem*)pItem;
62-(void)dockIconClicked: (NSObject*)pSender;
66-(void)executeMenuItem: (NSMenuItem*)pItem
102-(void)dockIconClicked: (NSObject*)pSender
123 return [[[NSString alloc] initWithCharacters: reinterpret_cast<unichar const *>(rStr.getStr()) length: rStr.getLength()] autorelease];
128struct RecentMenuEntry
136class RecentFilesStringLength :
public ::cppu::WeakImplHelper< css::util::XStringWidth >
139 RecentFilesStringLength() {}
142 sal_Int32 SAL_CALL queryStringWidth(
const OUString& aString )
override
144 return aString.getLength();
156-(void)menuNeedsUpdate:(NSMenu *)menu;
157-(void)executeRecentEntry: (NSMenuItem*)item;
163 if( (self = [super
init]) )
176-(void)menuNeedsUpdate:(NSMenu *)menu
179 int nItems = [menu numberOfItems];
181 [menu removeItemAtIndex: 0];
186 int nPickListMenuItems = ( aHistoryList.size() > 99 ) ? 99 : aHistoryList.size();
189 if( nPickListMenuItems > 0 )
191 for (
int i = 0;
i < nPickListMenuItems;
i++ )
194 RecentMenuEntry aRecentFile;
195 aRecentFile.aURL = rPickListEntry.
sURL;
196 aRecentFile.aFilter = rPickListEntry.
sFilter;
197 aRecentFile.aTitle = rPickListEntry.
sTitle;
198 aRecentFile.aPassword = rPickListEntry.
sPassword;
209 if (
aURL.GetProtocol() == INetProtocol::File )
213 OUString aSystemPath(
aURL.getFSysPath( FSysStyle::Detect ) );
214 OUString aCompactedSystemPath;
216 oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46,
nullptr );
218 aMenuTitle = aCompactedSystemPath;
220 aMenuTitle = aSystemPath;
225 css::uno::Reference< css::util::XStringWidth > xStringLength(
new RecentFilesStringLength() );
229 NSMenuItem* pNewItem = [[NSMenuItem alloc] initWithTitle: getAutoreleasedString( aMenuTitle )
230 action: @selector(executeRecentEntry:)
232 [pNewItem setTag: i];
233 [pNewItem setTarget: self];
234 [pNewItem setEnabled: YES];
235 [menu addItem: pNewItem];
236 [pNewItem autorelease];
240-(void)executeRecentEntry: (NSMenuItem*)item
242 sal_Int32
nIndex = [item tag];
243 if( ( nIndex >= 0 ) && ( nIndex <
static_cast<sal_Int32
>(
m_pRecentFilesItems->size() ) ) )
245 const RecentMenuEntry& rRecentFile = (*m_pRecentFilesItems)[ nIndex ];
246 int NUM_OF_PICKLIST_ARGS = 3;
247 css::uno::Sequence< css::beans::PropertyValue > aArgsList( NUM_OF_PICKLIST_ARGS );
248 css::beans::PropertyValue* pArgsList = aArgsList.getArray();
250 pArgsList[0].Name =
"Referer";
251 pArgsList[0].Value <<= OUString(
"private:user" );
254 pArgsList[1].Name =
"AsTemplate";
255 pArgsList[1].Value <<=
false;
257 OUString aFilter( rRecentFile.aFilter );
258 sal_Int32
nPos = aFilter.indexOf(
'|' );
261 OUString aFilterOptions;
263 if (
nPos < ( aFilter.getLength() - 1 ) )
264 aFilterOptions = aFilter.copy(
nPos+1 );
266 pArgsList[2].Name =
"FilterOptions";
267 pArgsList[2].Value <<= aFilterOptions;
269 aFilter = aFilter.copy( 0,
nPos-1 );
270 aArgsList.realloc( ++NUM_OF_PICKLIST_ARGS );
271 pArgsList = aArgsList.getArray();
274 pArgsList[NUM_OF_PICKLIST_ARGS-1].Name =
"FilterName";
275 pArgsList[NUM_OF_PICKLIST_ARGS-1].Value <<= aFilter;
284static OUString
getShortCut(
const OUString& i_rTitle )
290 OUString aShortcut( i_rTitle.copy(
nIndex, 1 ).toAsciiLowerCase() );
294 aKeyEquiv = aShortcut;
302static void appendMenuItem( NSMenu* i_pMenu, NSMenu* i_pDockMenu,
const OUString& i_rTitle,
int i_nTag,
const OUString& i_rKeyEquiv )
304 if( ! i_rTitle.getLength() )
307 NSMenuItem* pItem = [[NSMenuItem alloc] initWithTitle: getAutoreleasedString( i_rTitle )
308 action: @selector(executeMenuItem:)
309 keyEquivalent: (i_rKeyEquiv.getLength() ? getAutoreleasedString( i_rKeyEquiv ) : @"")
311 [pItem setTag: i_nTag];
312 [pItem setTarget: pExecute];
313 [pItem setEnabled: YES];
314 [i_pMenu addItem: pItem];
319 pItem = [[NSMenuItem alloc] initWithTitle: getAutoreleasedString( i_rTitle )
320 action: @selector(executeMenuItem:)
323 [pItem setTag: i_nTag];
324 [pItem setTarget: pExecute];
325 [pItem setEnabled: YES];
326 [i_pDockMenu addItem: pItem];
335 NSMenuItem* pItem = [i_pMenu addItemWithTitle: getAutoreleasedString( i_rTitle )
336 action: @selector(executeMenuItem:)
339 [pItem setEnabled: YES];
340 NSMenu* pRecentMenu = [[NSMenu alloc] initWithTitle: getAutoreleasedString( i_rTitle ) ];
342 [pRecentMenu setDelegate: pRecentDelegate];
344 [pRecentMenu setAutoenablesItems: NO];
345 [pItem setSubmenu: pRecentMenu];
357 if( ! pShutdownIcon )
361 pShutdownIcon->
SetVeto(
true );
366 if( [NSApp respondsToSelector:
@selector(addFallbackMenuItem:)] )
371 pDefMenu = [[NSMenuItem alloc] initWithTitle: getAutoreleasedString( SfxResId(STR_QUICKSTART_FILE) ) action: nullptr keyEquivalent: @""];
372 pDockSubMenu = [[NSMenuItem alloc] initWithTitle: getAutoreleasedString( SfxResId(STR_QUICKSTART_FILE) ) action: nullptr keyEquivalent: @""];
373 NSMenu* pMenu = [[NSMenu alloc] initWithTitle: getAutoreleasedString( SfxResId(STR_QUICKSTART_FILE) )];
374 [pMenu setAutoenablesItems: NO];
375 NSMenu* pDockMenu = [[NSMenu alloc] initWithTitle: getAutoreleasedString( SfxResId(STR_QUICKSTART_FILE) )];
376 [pDockMenu setAutoenablesItems: NO];
380 std::set< OUString > aFileNewAppsAvailable;
385 if ( !newMenuProp.sURL.isEmpty() )
386 aFileNewAppsAvailable.insert( newMenuProp.sURL );
390 struct MenuEntryDescriptor
394 rtl::OUStringConstExpr sURLDescription;
395 }
static const aMenuItems[] =
409 if( [NSApp respondsToSelector:
@selector(setDockIconClickHandler:)] )
410 [NSApp performSelector:@selector(setDockIconClickHandler:) withObject: pExecute];
412 OSL_FAIL(
"setDockIconClickHandler selector failed on NSApp" );
423 const OUString& sURL( aMenuItems[
i].sURLDescription );
425 if ( aFileNewAppsAvailable.find( sURL ) == aFileNewAppsAvailable.end() )
440 OUString aTitle(
SfxResId(STR_QUICKSTART_FROMTEMPLATE) );
443 aTitle =
SfxResId(STR_QUICKSTART_FILEOPEN);
447 [pDefMenu setSubmenu: pMenu];
448 [NSApp performSelector:@selector(addFallbackMenuItem:) withObject: pDefMenu];
450 if( [NSApp respondsToSelector:
@selector(addDockMenuItem:)] )
452 [pDockSubMenu setSubmenu: pDockMenu];
454 [NSApp performSelector:@selector(addDockMenuItem:) withObject: pDockSubMenu];
457 OSL_FAIL(
"addDockMenuItem selector failed on NSApp" );
460 OSL_FAIL(
"addFallbackMenuItem selector failed on NSApp" );
static bool IsQuickstarterInstalled()
static ShutdownIcon * getInstance()
static void FromTemplate()
static void addTerminateListener()
static OUString GetUrlDescription(std::u16string_view aUrl)
static void OpenURL(const OUString &aURL, const OUString &rTarget, const css::uno::Sequence< css::beans::PropertyValue > &=css::uno::Sequence< css::beans::PropertyValue >(0))
bool IsModuleInstalled(EModule eModule) const
#define SAL_N_ELEMENTS(arr)
std::vector< HistoryItem > GetList(EHistoryType eHistory)
static void init(struct DocumentMetadataAccess_Impl &i_rImpl)
init Impl struct
OUString SfxResId(TranslateId aId)
constexpr OUStringLiteral DRAW_URL
constexpr OUStringLiteral IMPRESS_URL
constexpr OUStringLiteral MATH_URL
constexpr OUStringLiteral STARTMODULE_URL
constexpr OUStringLiteral CALC_URL
constexpr OUStringLiteral BASE_URL
constexpr OUStringLiteral WRITER_URL
constexpr OUStringLiteral IMPRESS_WIZARD_URL
static NSString * getAutoreleasedString(const OUString &rStr)
static NSMenuItem * pDockSubMenu
static void appendRecentMenu(NSMenu *i_pMenu, const OUString &i_rTitle)
static RecentMenuDelegate * pRecentDelegate
static OUString getShortCut(const OUString &i_rTitle)
void SAL_DLLPUBLIC_EXPORT aqua_shutdown_systray()
static std::set< OUString > aShortcuts
static void appendMenuItem(NSMenu *i_pMenu, NSMenu *i_pDockMenu, const OUString &i_rTitle, int i_nTag, const OUString &i_rKeyEquiv)
static NSMenuItem * pDefMenu
static QSMenuExecute * pExecute