20 #undef SC_DLLIMPLEMENTATION
24 #include <sfx2/strings.hrc>
26 #include <strings.hrc>
28 #include <globstr.hrc>
41 : GenericDialogController(pParent,
"modules/scalc/ui/autoformattable.ui",
"AutoFormatTableDialog")
42 , aStrTitle(
ScResId(STR_ADD_AUTOFORMAT_TITLE))
43 , aStrLabel(
ScResId(STR_ADD_AUTOFORMAT_LABEL))
44 , aStrClose(
ScResId(STR_BTN_AUTOFORMAT_CLOSE))
45 , aStrDelMsg(
ScResId(STR_DEL_AUTOFORMAT_MSG))
46 , aStrRename(
ScResId(STR_RENAME_AUTOFORMAT_TITLE))
47 , pFormat(pAutoFormat)
48 , pSelFmtData(pSelFormatData)
50 , bCoreDataChanged(false)
52 , m_xLbFormat(m_xBuilder->weld_tree_view(
"formatlb"))
53 , m_xBtnOk(m_xBuilder->weld_button(
"ok"))
54 , m_xBtnCancel(m_xBuilder->weld_button(
"cancel"))
55 , m_xBtnAdd(m_xBuilder->weld_button(
"add"))
56 , m_xBtnRemove(m_xBuilder->weld_button(
"remove"))
57 , m_xBtnRename(m_xBuilder->weld_button(
"rename"))
58 , m_xBtnNumFormat(m_xBuilder->weld_check_button(
"numformatcb"))
59 , m_xBtnBorder(m_xBuilder->weld_check_button(
"bordercb"))
60 , m_xBtnFont(m_xBuilder->weld_check_button(
"fontcb"))
61 , m_xBtnPattern(m_xBuilder->weld_check_button(
"patterncb"))
62 , m_xBtnAlignment(m_xBuilder->weld_check_button(
"alignmentcb"))
63 , m_xBtnAdjust(m_xBuilder->weld_check_button(
"autofitcb"))
64 , m_xWndPreview(new
weld::CustomWeld(*m_xBuilder,
"preview", m_aWndPreview))
68 const int nWidth =
m_xLbFormat->get_approximate_digit_width() * 32;
69 const int nHeight =
m_xLbFormat->get_height_rows(8);
98 for (
const auto& rEntry : *
pFormat)
101 if (pFormat->size() == 1)
135 if (&rBtn == m_xBtnOk.get() || &rBtn == m_xBtnCancel.get())
137 if ( bCoreDataChanged )
146 if ( bCoreDataChanged )
157 bool bCheck = rBtn.get_active();
159 if (&rBtn == m_xBtnNumFormat.get())
161 else if (&rBtn == m_xBtnBorder.get())
163 else if (&rBtn == m_xBtnFont.get())
165 else if (&rBtn == m_xBtnPattern.get())
167 else if (&rBtn == m_xBtnAlignment.get())
169 else if (&rBtn == m_xBtnAdjust.get())
172 if ( !bCoreDataChanged )
174 m_xBtnCancel->set_label(aStrClose);
175 bCoreDataChanged =
true;
178 m_aWndPreview.NotifyChange( pData );
183 if ( bFmtInserted || !pSelFmtData )
186 OUString aStrStandard(
SfxResId(STR_STANDARD) );
187 OUString aFormatName;
199 if ( !aFormatName.isEmpty() && aFormatName != aStrStandard && pFormat->find(aFormatName) == pFormat->end() )
201 std::unique_ptr<ScAutoFormatData> pNewData(
204 pNewData->SetName( aFormatName );
206 bFmtInserted = it != pFormat->end();
210 size_t nPos = std::distance(pFormat->begin(), it);
211 m_xLbFormat->insert_text(nPos, aFormatName);
212 m_xLbFormat->select_text( aFormatName );
213 m_xBtnAdd->set_sensitive(
false);
215 if ( !bCoreDataChanged )
217 m_xBtnCancel->set_label( aStrClose );
218 bCoreDataChanged =
true;
221 SelFmtHdl( *m_xLbFormat );
229 VclMessageType::Error, VclButtonsType::OkCancel,
232 sal_uInt16 nRet = xBox->run();
244 if ( (
nIndex > 0) && (m_xLbFormat->n_children() > 0) )
246 OUString aMsg = aStrDelMsg.getToken( 0,
'#' )
247 + m_xLbFormat->get_selected_text()
248 + aStrDelMsg.getToken( 1,
'#' );
251 VclMessageType::Question, VclButtonsType::YesNo,
253 xQueryBox->set_default_response(
RET_YES);
255 if (
RET_YES == xQueryBox->run())
257 m_xLbFormat->remove(
nIndex);
258 m_xLbFormat->select(
nIndex-1);
261 m_xBtnRemove->set_sensitive(
false);
263 if ( !bCoreDataChanged )
265 m_xBtnCancel->set_label( aStrClose );
266 bCoreDataChanged =
true;
274 SelFmtHdl( *m_xLbFormat );
278 SelFmtHdl( *m_xLbFormat );
287 OUString aFormatName = m_xLbFormat->get_selected_text();
294 bool bFmtRenamed =
false;
297 if (!aFormatName.isEmpty())
300 for (; it != itEnd; ++it)
302 aEntry = it->second->GetName();
303 if (aFormatName == aEntry)
310 m_xLbFormat->remove(
nIndex);
314 it = pFormat->begin();
318 pNewData->SetName( aFormatName );
320 pFormat->insert(std::move(pNewData));
322 m_xLbFormat->freeze();
323 m_xLbFormat->clear();
324 for (it = pFormat->begin(); it != itEnd; ++it)
326 aEntry = it->second->GetName();
327 m_xLbFormat->append_text(aEntry);
331 m_xLbFormat->select_text(aFormatName);
333 if ( !bCoreDataChanged )
335 m_xBtnCancel->set_label( aStrClose );
336 bCoreDataChanged =
true;
339 SelFmtHdl( *m_xLbFormat );
347 VclMessageType::Error, VclButtonsType::OkCancel,
360 nIndex = m_xLbFormat->get_selected_index();
365 m_xBtnRename->set_sensitive(
false);
366 m_xBtnRemove->set_sensitive(
false);
370 m_xBtnRename->set_sensitive(
true);
371 m_xBtnRemove->set_sensitive(
true);
375 m_aWndPreview.NotifyChange(p);
381 return p ? p->
GetName() : OUString();
#define LINK(Instance, Class, Member)
void DetectRTL(const ScViewData &rViewData)
std::unique_ptr< ContentProperties > pData
#define HID_SC_REN_AFMT_NAME
IMPL_LINK_NOARG(ScAutoFormatDlg, DblClkHdl, weld::TreeView &, bool)
void NotifyChange(ScAutoFormatData *pNewData)
#define HID_SC_REN_AFMT_DLG
OUString ScResId(const char *pId)
#define HID_SC_ADD_AUTOFMT
Reference< XExecutableDialog > m_xDialog
IMPL_LINK(ScAutoFormatDlg, CloseHdl, weld::Button &, rBtn, void)
#define HID_SC_AUTOFMT_NAME
static SC_DLLPUBLIC ScAutoFormat * GetOrCreateAutoFormat()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
OUString SfxResId(const char *pId)