Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / ios / iosinst.cxx
blob65963ef9c09967858824ac536dd36a1c43a4ba46
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <premac.h>
21 #include <UIKit/UIKit.h>
22 #include <postmac.h>
24 #include "ios/iosinst.hxx"
25 #include "headless/svpdummies.hxx"
26 #include "unx/gendata.hxx"
27 #include "quartz/utils.h"
28 #include <vcl/layout.hxx>
29 #include <vcl/settings.hxx>
31 // Totally wrong of course but doesn't seem to harm much in the iOS app.
32 static int viewWidth = 1, viewHeight = 1;
34 class IosSalData : public GenericUnixSalData
36 public:
37 explicit IosSalData(SalInstance *pInstance)
38 : GenericUnixSalData(SAL_DATA_IOS, pInstance)
41 virtual void ErrorTrapPush() {}
42 virtual bool ErrorTrapPop( bool ) { return false; }
45 void IosSalInstance::GetWorkArea( tools::Rectangle& rRect )
47 rRect = tools::Rectangle( Point( 0, 0 ),
48 Size( viewWidth, viewHeight ) );
51 IosSalInstance *IosSalInstance::getInstance()
53 if (!ImplGetSVData())
54 return NULL;
55 IosSalData *pData = static_cast<IosSalData *>(ImplGetSVData()->mpSalData);
56 if (!pData)
57 return NULL;
58 return static_cast<IosSalInstance *>(pData->m_pInstance);
61 IosSalInstance::IosSalInstance( std::unique_ptr<SalYieldMutex> pMutex )
62 : SvpSalInstance( std::move(pMutex) )
66 IosSalInstance::~IosSalInstance()
70 class IosSalSystem : public SvpSalSystem {
71 public:
72 IosSalSystem() : SvpSalSystem() {}
73 virtual ~IosSalSystem() {}
74 virtual int ShowNativeDialog( const OUString& rTitle,
75 const OUString& rMessage,
76 const std::vector< OUString >& rButtons );
79 SalSystem *IosSalInstance::CreateSalSystem()
81 return new IosSalSystem();
84 class IosSalFrame : public SvpSalFrame
86 public:
87 IosSalFrame( IosSalInstance *pInstance,
88 SalFrame *pParent,
89 SalFrameStyleFlags nSalFrameStyle)
90 : SvpSalFrame( pInstance, pParent, nSalFrameStyle )
92 if (pParent == NULL && viewWidth > 1 && viewHeight > 1)
93 SetPosSize(0, 0, viewWidth, viewHeight, SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT);
96 virtual void GetWorkArea( tools::Rectangle& rRect ) override
98 IosSalInstance::getInstance()->GetWorkArea( rRect );
101 virtual void ShowFullScreen( bool, sal_Int32 ) override
103 SetPosSize( 0, 0, viewWidth, viewHeight,
104 SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
107 virtual void UpdateSettings( AllSettings &rSettings ) override
109 // Clobber the UI fonts
110 vcl::Font aFont( "Helvetica", Size( 0, 10 ) );
112 StyleSettings aStyleSet = rSettings.GetStyleSettings();
113 aStyleSet.SetAppFont( aFont );
114 aStyleSet.SetHelpFont( aFont );
115 aStyleSet.SetMenuFont( aFont );
116 aStyleSet.SetToolFont( aFont );
117 aStyleSet.SetLabelFont( aFont );
118 aStyleSet.SetRadioCheckFont( aFont );
119 aStyleSet.SetPushButtonFont( aFont );
120 aStyleSet.SetFieldFont( aFont );
121 aStyleSet.SetIconFont( aFont );
122 aStyleSet.SetTabFont( aFont );
123 aStyleSet.SetGroupFont( aFont );
125 Color aBackgroundColor( 0xff, 0xff, 0xff );
126 aStyleSet.BatchSetBackgrounds( aBackgroundColor, false );
127 aStyleSet.SetMenuColor( aBackgroundColor );
128 aStyleSet.SetMenuBarColor( aBackgroundColor );
129 aStyleSet.SetDialogColor( aBackgroundColor );
131 rSettings.SetStyleSettings( aStyleSet );
135 SalFrame *IosSalInstance::CreateChildFrame( SystemParentData* pParent, SalFrameStyleFlags nStyle )
137 pParent = NULL;
138 return new IosSalFrame( this, NULL, nStyle );
141 SalFrame *IosSalInstance::CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle )
143 return new IosSalFrame( this, pParent, nStyle );
146 void SalAbort( const OUString& rErrorText, bool bDumpCore )
148 (void) bDumpCore;
150 NSLog(@"SalAbort: %s", OUStringToOString(rErrorText, osl_getThreadTextEncoding()).getStr() );
153 const OUString& SalGetDesktopEnvironment()
155 static OUString aEnv( "iOS" );
156 return aEnv;
159 SalData::SalData() :
160 m_pInstance( 0 ),
161 mpFontList( 0 ),
162 mxRGBSpace( CGColorSpaceCreateDeviceRGB() ),
163 mxGraySpace( CGColorSpaceCreateDeviceGray() )
167 SalData::~SalData()
171 // This is our main entry point:
172 SalInstance *CreateSalInstance()
174 IosSalInstance* pInstance = new IosSalInstance( std::make_unique<SvpSalYieldMutex>() );
175 new IosSalData( pInstance );
176 pInstance->AcquireYieldMutex();
177 return pInstance;
180 void DestroySalInstance( SalInstance *pInst )
182 pInst->ReleaseYieldMutexAll();
183 delete pInst;
186 int IosSalSystem::ShowNativeDialog( const OUString& rTitle,
187 const OUString& rMessage,
188 const std::vector< OUString >& rButtons )
190 (void)rButtons;
192 NSLog(@"%@: %@", CreateNSString(rTitle), CreateNSString(rMessage));
194 return 0;
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */