20#undef SC_DLLIMPLEMENTATION
24#include <sfx2/strings.hrc>
42 : GenericDialogController(pParent,
"modules/scalc/ui/autoformattable.ui",
"AutoFormatTableDialog")
43 , aStrTitle(
ScResId(STR_ADD_AUTOFORMAT_TITLE))
44 , aStrLabel(
ScResId(STR_ADD_AUTOFORMAT_LABEL))
45 , aStrClose(
ScResId(STR_BTN_AUTOFORMAT_CLOSE))
46 , aStrDelMsg(
ScResId(STR_DEL_AUTOFORMAT_MSG))
47 , aStrRename(
ScResId(STR_RENAME_AUTOFORMAT_TITLE))
48 , pFormat(pAutoFormat)
49 , pSelFmtData(pSelFormatData)
51 , bCoreDataChanged(false)
53 , m_xLbFormat(m_xBuilder->weld_tree_view(
"formatlb"))
54 , m_xBtnOk(m_xBuilder->weld_button(
"ok"))
55 , m_xBtnCancel(m_xBuilder->weld_button(
"cancel"))
56 , m_xBtnAdd(m_xBuilder->weld_button(
"add"))
57 , m_xBtnRemove(m_xBuilder->weld_button(
"remove"))
58 , m_xBtnRename(m_xBuilder->weld_button(
"rename"))
59 , m_xBtnNumFormat(m_xBuilder->weld_check_button(
"numformatcb"))
60 , m_xBtnBorder(m_xBuilder->weld_check_button(
"bordercb"))
61 , m_xBtnFont(m_xBuilder->weld_check_button(
"fontcb"))
62 , m_xBtnPattern(m_xBuilder->weld_check_button(
"patterncb"))
63 , m_xBtnAlignment(m_xBuilder->weld_check_button(
"alignmentcb"))
64 , m_xBtnAdjust(m_xBuilder->weld_check_button(
"autofitcb"))
65 , m_xWndPreview(new
weld::CustomWeld(*m_xBuilder,
"preview", m_aWndPreview))
69 const int nWidth =
m_xLbFormat->get_approximate_digit_width() * 32;
70 const int nHeight =
m_xLbFormat->get_height_rows(8);
99 for (
const auto& rEntry : *
pFormat)
100 m_xLbFormat->append_text(rEntry.second->GetName());
136 if (&rBtn == m_xBtnOk.get() || &rBtn == m_xBtnCancel.get())
138 if ( bCoreDataChanged )
147 if ( bCoreDataChanged )
158 bool bCheck = rBtn.get_active();
160 if (&rBtn == m_xBtnNumFormat.get())
161 pData->SetIncludeValueFormat( bCheck );
162 else if (&rBtn == m_xBtnBorder.get())
163 pData->SetIncludeFrame( bCheck );
164 else if (&rBtn == m_xBtnFont.get())
165 pData->SetIncludeFont( bCheck );
166 else if (&rBtn == m_xBtnPattern.get())
167 pData->SetIncludeBackground( bCheck );
168 else if (&rBtn == m_xBtnAlignment.get())
169 pData->SetIncludeJustify( bCheck );
170 else if (&rBtn == m_xBtnAdjust.get())
171 pData->SetIncludeWidthHeight( bCheck );
173 if ( !bCoreDataChanged )
175 m_xBtnCancel->set_label(aStrClose);
176 bCoreDataChanged =
true;
179 m_aWndPreview.NotifyChange(
pData );
184 if ( bFmtInserted || !pSelFmtData )
187 OUString aStrStandard(
SfxResId(STR_STANDARD) );
188 OUString aFormatName;
200 if ( !aFormatName.isEmpty() && aFormatName != aStrStandard && pFormat->find(aFormatName) == pFormat->end() )
202 std::unique_ptr<ScAutoFormatData> pNewData(
205 pNewData->SetName( aFormatName );
207 bFmtInserted = it != pFormat->end();
211 size_t nPos = std::distance(pFormat->begin(), it);
212 m_xLbFormat->insert_text(
nPos, aFormatName);
213 m_xLbFormat->select_text( aFormatName );
214 m_xBtnAdd->set_sensitive(
false);
216 if ( !bCoreDataChanged )
218 m_xBtnCancel->set_label( aStrClose );
219 bCoreDataChanged =
true;
222 SelFmtHdl( *m_xLbFormat );
230 VclMessageType::Error, VclButtonsType::OkCancel,
233 sal_uInt16 nRet = xBox->run();
245 if ( (
nIndex > 0) && (m_xLbFormat->n_children() > 0) )
248 + m_xLbFormat->get_selected_text()
252 VclMessageType::Question, VclButtonsType::YesNo,
254 xQueryBox->set_default_response(
RET_YES);
256 if (
RET_YES == xQueryBox->run())
258 m_xLbFormat->remove(
nIndex);
259 m_xLbFormat->select(
nIndex-1);
262 m_xBtnRemove->set_sensitive(
false);
264 if ( !bCoreDataChanged )
266 m_xBtnCancel->set_label( aStrClose );
267 bCoreDataChanged =
true;
275 SelFmtHdl( *m_xLbFormat );
279 SelFmtHdl( *m_xLbFormat );
288 OUString aFormatName = m_xLbFormat->get_selected_text();
295 bool bFmtRenamed =
false;
298 if (!aFormatName.isEmpty())
301 for (; it != itEnd; ++it)
303 aEntry = it->second->GetName();
304 if (aFormatName == aEntry)
311 m_xLbFormat->remove(
nIndex);
315 it = pFormat->begin();
319 pNewData->SetName( aFormatName );
321 pFormat->insert(std::move(pNewData));
323 m_xLbFormat->freeze();
324 m_xLbFormat->clear();
325 for (it = pFormat->begin(); it != itEnd; ++it)
327 aEntry = it->second->GetName();
328 m_xLbFormat->append_text(aEntry);
332 m_xLbFormat->select_text(aFormatName);
334 if ( !bCoreDataChanged )
336 m_xBtnCancel->set_label( aStrClose );
337 bCoreDataChanged =
true;
340 SelFmtHdl( *m_xLbFormat );
348 VclMessageType::Error, VclButtonsType::OkCancel,
361 nIndex = m_xLbFormat->get_selected_index();
366 m_xBtnRename->set_sensitive(
false);
367 m_xBtnRemove->set_sensitive(
false);
371 m_xBtnRename->set_sensitive(
true);
372 m_xBtnRemove->set_sensitive(
true);
376 m_aWndPreview.NotifyChange(
p);
382 return p ?
p->GetName() : OUString();
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
void NotifyChange(ScAutoFormatData *pNewData)
void DetectRTL(const ScViewData &rViewData)
static SC_DLLPUBLIC ScAutoFormat * GetOrCreateAutoFormat()
constexpr OUStringLiteral HID_SC_ADD_AUTOFMT
constexpr OUStringLiteral HID_SC_REN_AFMT_DLG
constexpr OUStringLiteral HID_SC_AUTOFMT_NAME
constexpr OUStringLiteral HID_SC_REN_AFMT_NAME
#define LINK(Instance, Class, Member)
std::unique_ptr< sal_Int32[]> pData
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OUString ScResId(TranslateId aId)
IMPL_LINK(ScAutoFormatDlg, CloseHdl, weld::Button &, rBtn, void)
IMPL_LINK_NOARG(ScAutoFormatDlg, DblClkHdl, weld::TreeView &, bool)
SFX2_DLLPUBLIC OUString SfxResId(TranslateId aId)