26#include <com/sun/star/awt/PopupMenu.hpp>
27#include <com/sun/star/awt/PopupMenuDirection.hpp>
32#include <com/sun/star/document/XDocumentLanguages.hpp>
33#include <com/sun/star/lang/XServiceInfo.hpp>
34#include <com/sun/star/i18n/ScriptType.hpp>
35#include <com/sun/star/ui/XStatusbarItem.hpp>
37#include <com/sun/star/frame/XFrame.hpp>
39#include <com/sun/star/awt/Command.hpp>
44#include <rtl/ustrbuf.hxx>
49using namespace ::
cppu;
51using namespace css::uno;
52using namespace css::lang;
53using namespace css::frame;
54using namespace css::i18n;
55using namespace css::document;
60class LangSelectionStatusbarController:
64 explicit LangSelectionStatusbarController(
const css::uno::Reference< css::uno::XComponentContext >& xContext );
65 LangSelectionStatusbarController(
const LangSelectionStatusbarController&) =
delete;
66 LangSelectionStatusbarController& operator=(
const LangSelectionStatusbarController&) =
delete;
69 virtual void SAL_CALL
initialize(
const css::uno::Sequence< css::uno::Any >& aArguments )
override;
72 virtual void SAL_CALL
statusChanged(
const css::frame::FeatureStateEvent& Event )
override;
75 virtual void SAL_CALL
command(
const css::awt::Point& aPos,
78 const css::uno::Any& aData )
override;
79 virtual void SAL_CALL
click(
const css::awt::Point& aPos )
override;
82 virtual ~LangSelectionStatusbarController()
override {}
87 OUString m_aKeyboardLang;
88 OUString m_aGuessedTextLang;
92 void LangMenu(
const css::awt::Point& aPos );
95LangSelectionStatusbarController::LangSelectionStatusbarController(
const uno::Reference< uno::XComponentContext >& xContext ) :
96 svt::StatusbarController( xContext,
uno::
Reference< frame::XFrame >(), OUString(), 0 ),
99 m_aLangGuessHelper( xContext )
103void SAL_CALL LangSelectionStatusbarController::initialize(
const css::uno::Sequence< css::uno::Any >& aArguments )
109 if ( m_xStatusbarItem.is() )
111 m_xStatusbarItem->setText(
FwkResId(STR_LANGSTATUS_MULTIPLE_LANGUAGES) );
112 m_xStatusbarItem->setQuickHelpText(
FwkResId(STR_LANGSTATUS_HINT));
116void LangSelectionStatusbarController::LangMenu(
117 const css::awt::Point& aPos )
122 const Reference<XServiceInfo> xService(
m_xFrame->getController()->getModel(), UNO_QUERY);
123 bool bCalc = xService.is() && xService->supportsService(
"com.sun.star.sheet.SpreadsheetDocument");
124 bool bWriter = xService.is() && xService->supportsService(
"com.sun.star.text.GenericTextDocument");
126 Reference< awt::XPopupMenu > xPopupMenu( awt::PopupMenu::create(
m_xContext ) );
128 Reference< awt::XPopupMenu > subPopupMenu( awt::PopupMenu::create(
m_xContext ) );
131 std::set< OUString > aLangItems;
133 m_nScriptType, m_aCurLang, m_aKeyboardLang, m_aGuessedTextLang );
137 static constexpr OUStringLiteral sAsterisk(u
"*");
139 std::map< sal_Int16, OUString > aLangMap;
140 for (
auto const& langItem : aLangItems)
142 if ( langItem != sNone &&
143 langItem != sAsterisk &&
147 "fwk.uielement",
"nItemId outside of expected range!" );
148 xPopupMenu->insertItem( nItemId, langItem, 0, nItemId );
149 if ( langItem == m_aCurLang )
152 xPopupMenu->checkItem( nItemId,
true );
154 aLangMap[ nItemId ] = langItem;
162 if ( sNone == m_aCurLang )
169 for (
auto const& langItem : aLangItems)
171 if( langItem != sNone &&
172 langItem != sAsterisk &&
176 "fwk.uielement",
"nItemId outside of expected range!" );
177 subPopupMenu->insertItem( nItemId, langItem, 0, nItemId );
178 aLangMap[nItemId] = langItem;
194 if ( sNone == m_aCurLang )
202 Reference< awt::XWindowPeer > xParent( m_xParentWindow, UNO_QUERY );
203 css::awt::Rectangle aRect( aPos.X, aPos.Y, 0, 0 );
204 sal_Int16
nId = xPopupMenu->execute( xParent, aRect, css::awt::PopupMenuDirection::EXECUTE_UP+16 );
209 OUStringBuffer aBuff;
211 const OUString aSelectedLang = aLangMap[
nId];
216 aBuff.append(
".uno:LanguageStatus?Language:string=Current_" );
218 aBuff.append(
".uno:LanguageStatus?Language:string=Default_" );
220 aBuff.append( aSelectedLang );
225 aBuff.append(
".uno:LanguageStatus?Language:string=Current_LANGUAGE_NONE" );
230 aBuff.append(
".uno:LanguageStatus?Language:string=Current_RESET_LANGUAGES" );
235 aBuff.append(
".uno:FontDialog?Page:string=font" );
239 aBuff.append(
".uno:LanguageStatus?Language:string=Default_LANGUAGE_NONE" );
243 aBuff.append(
".uno:LanguageStatus?Language:string=Default_RESET_LANGUAGES" );
248 aBuff.append(
".uno:FormatCellDialog" );
250 aBuff.append(
".uno:LanguageStatus?Language:string=*" );
254 aBuff.append(
".uno:LanguageStatus?Language:string=Paragraph_" + aSelectedLang );
259 aBuff.append(
".uno:LanguageStatus?Language:string=Paragraph_LANGUAGE_NONE" );
264 aBuff.append(
".uno:LanguageStatus?Language:string=Paragraph_RESET_LANGUAGES" );
269 aBuff.append(
".uno:FontDialogForParagraph" );
272 const Sequence< beans::PropertyValue > aDummyArgs;
273 execute( aBuff.makeStringAndClear(), aDummyArgs );
276void SAL_CALL LangSelectionStatusbarController::command(
277 const css::awt::Point& aPos,
278 ::sal_Int32 nCommand,
280 const css::uno::Any& )
282 if ( nCommand & ::awt::Command::CONTEXTMENU )
288void SAL_CALL LangSelectionStatusbarController::click(
289 const css::awt::Point& aPos )
295void SAL_CALL LangSelectionStatusbarController::statusChanged(
const FeatureStateEvent& Event )
310 m_nScriptType = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
312 if ( !m_xStatusbarItem.is() )
316 Sequence< OUString >
aSeq;
318 if ( Event.State >>= aStrValue )
320 m_xStatusbarItem->setText( aStrValue );
321 m_xStatusbarItem->setQuickHelpText(
FwkResId(STR_LANGSTATUS_HINT));
322 m_aCurLang = aStrValue;
324 else if ( Event.State >>= aSeq )
326 if (
aSeq.getLength() == 4 )
328 OUString aStatusText =
aSeq[0];
329 if (aStatusText ==
"*")
331 aStatusText =
FwkResId(STR_LANGSTATUS_MULTIPLE_LANGUAGES);
333 m_xStatusbarItem->setText( aStatusText );
334 m_xStatusbarItem->setQuickHelpText(
FwkResId(STR_LANGSTATUS_HINT));
338 m_aCurLang =
aSeq[0];
340 m_aKeyboardLang =
aSeq[2];
341 m_aGuessedTextLang =
aSeq[3];
344 else if ( !Event.State.hasValue() )
346 m_xStatusbarItem->setText( OUString() );
347 m_xStatusbarItem->setQuickHelpText(u
"");
354extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
356 css::uno::XComponentContext *context,
357 css::uno::Sequence<css::uno::Any>
const &)
359 return cppu::acquire(
new LangSelectionStatusbarController(context));
css::uno::Reference< css::lang::XComponent > m_xFrame
static OUString GetLanguageString(const LanguageType eType)
virtual void SAL_CALL command(const css::awt::Point &aPos, ::sal_Int32 nCommand, sal_Bool bMouseEvent, const css::uno::Any &aData) override
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &Event) override
virtual void SAL_CALL click(const css::awt::Point &aPos) override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
OUString FwkResId(TranslateId aId)
css::uno::Reference< css::uno::XComponentContext > m_xContext
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_framework_LangSelectionStatusbarController_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Sequence< sal_Int8 > aSeq
#define SAL_WARN_IF(condition, area, stream)
@ MID_LANG_PARA_SEPARATOR
void FillLangItems(std::set< OUString > &rLangItems, const uno::Reference< frame::XFrame > &rxFrame, const LanguageGuessingHelper &rLangGuessHelper, SvtScriptType nScriptType, const OUString &rCurLang, const OUString &rKeyboardLang, const OUString &rGuessedTextLang)
constexpr OUStringLiteral sNone