diff options
Diffstat (limited to 'sw/source/ui/misc/glosbib.cxx')
-rw-r--r-- | sw/source/ui/misc/glosbib.cxx | 301 |
1 files changed, 144 insertions, 157 deletions
diff --git a/sw/source/ui/misc/glosbib.cxx b/sw/source/ui/misc/glosbib.cxx index 3e8d9a3f7bde..82febac648ed 100644 --- a/sw/source/ui/misc/glosbib.cxx +++ b/sw/source/ui/misc/glosbib.cxx @@ -44,53 +44,55 @@ #define RENAME_TOKEN_DELIM u'\x0001' -SwGlossaryGroupDlg::SwGlossaryGroupDlg(vcl::Window * pParent, +SwGlossaryGroupDlg::SwGlossaryGroupDlg(weld::Window * pParent, std::vector<OUString> const& rPathArr, SwGlossaryHdl *pHdl) - : SvxStandardDialog(pParent, "EditCategoriesDialog", - "modules/swriter/ui/editcategories.ui") + : SfxDialogController(pParent, "modules/swriter/ui/editcategories.ui", + "EditCategoriesDialog") + , m_pParent(pParent) , pGlosHdl(pHdl) + , m_xNameED(m_xBuilder->weld_entry("name")) + , m_xPathLB(m_xBuilder->weld_combo_box("pathlb")) + , m_xGroupTLB(m_xBuilder->weld_tree_view("group")) + , m_xNewPB(m_xBuilder->weld_button("new")) + , m_xDelPB(m_xBuilder->weld_button("delete")) + , m_xRenamePB(m_xBuilder->weld_button("rename")) { - get(m_pPathLB, "pathlb"); - get(m_pNewPB, "new"); - get(m_pDelPB, "delete"); - get(m_pRenamePB, "rename"); - get(m_pNameED, "name"); - get(m_pGroupTLB, "group"); - - const int nAppFontUnits = 130; - long nWidth = LogicToPixel(Size(nAppFontUnits, 0), MapMode(MapUnit::MapAppFont)).Width(); - m_pPathLB->set_width_request(nWidth); + int nWidth = m_xGroupTLB->get_approximate_digit_width() * 34; + m_xPathLB->set_size_request(nWidth, -1); //just has to be something small, real size will be available space - m_pGroupTLB->set_width_request(nWidth); - m_pGroupTLB->set_height_request(GetTextHeight() * 10); + m_xGroupTLB->set_size_request(nWidth, m_xGroupTLB->get_height_rows(10)); - long nTabs[] = { 0, nAppFontUnits }; + std::vector<int> aWidths; + aWidths.push_back(nWidth); + m_xGroupTLB->set_column_fixed_widths(aWidths); + m_xGroupTLB->connect_changed(LINK(this, SwGlossaryGroupDlg, SelectHdl)); - m_pGroupTLB->SetTabs( SAL_N_ELEMENTS(nTabs), nTabs ); - m_pGroupTLB->SetSelectHdl(LINK(this, SwGlossaryGroupDlg, SelectHdl)); - m_pGroupTLB->GetModel()->SetSortMode(SortAscending); - m_pNewPB->SetClickHdl(LINK(this, SwGlossaryGroupDlg, NewHdl)); - m_pDelPB->SetClickHdl(LINK(this, SwGlossaryGroupDlg, DeleteHdl)); - m_pNameED->SetModifyHdl(LINK(this, SwGlossaryGroupDlg, ModifyHdl)); - m_pPathLB->SetSelectHdl(LINK(this, SwGlossaryGroupDlg, ModifyListBoxHdl)); - m_pRenamePB->SetClickHdl(LINK(this, SwGlossaryGroupDlg, RenameHdl)); + m_xNewPB->connect_clicked(LINK(this, SwGlossaryGroupDlg, NewHdl)); + m_xDelPB->connect_clicked(LINK(this, SwGlossaryGroupDlg, DeleteHdl)); + m_xNameED->connect_changed(LINK(this, SwGlossaryGroupDlg, ModifyHdl)); + m_xNameED->connect_insert_text(LINK(this, SwGlossaryGroupDlg, EditInsertTextHdl)); + m_xPathLB->connect_changed(LINK(this, SwGlossaryGroupDlg, ModifyListBoxHdl)); + m_xRenamePB->connect_clicked(LINK(this, SwGlossaryGroupDlg, RenameHdl)); + + m_xNameED->connect_size_allocate(LINK(this, SwGlossaryGroupDlg, EntrySizeAllocHdl)); + m_xPathLB->connect_size_allocate(LINK(this, SwGlossaryGroupDlg, EntrySizeAllocHdl)); for (size_t i = 0; i < rPathArr.size(); ++i) { INetURLObject aTempURL(rPathArr[i]); const OUString sPath = aTempURL.GetMainURL(INetURLObject::DecodeMechanism::WithCharset ); - m_pPathLB->InsertEntry(sPath); - sal_uLong nCaseReadonly = 0; + sal_uInt32 nCaseReadonly = 0; utl::TempFile aTempFile(&sPath); aTempFile.EnableKillingFile(); if(!aTempFile.IsValid()) nCaseReadonly |= PATH_READONLY; else if( SWUnoHelper::UCB_IsCaseSensitiveFileName( aTempFile.GetURL())) nCaseReadonly |= PATH_CASE_SENSITIVE; - m_pPathLB->SetEntryData(i, reinterpret_cast<void*>(nCaseReadonly)); + OUString sId(OUString::number(nCaseReadonly)); + m_xPathLB->append(sId, sPath); } - m_pPathLB->SelectEntryPos(0); - m_pPathLB->Enable(); + m_xPathLB->set_active(0); + m_xPathLB->set_sensitive(true); const size_t nCount = pHdl->GetGroupCnt(); /* tdf#111870 "My AutoText" comes from mytexts.bau but should be translated @@ -108,34 +110,38 @@ SwGlossaryGroupDlg::SwGlossaryGroupDlg(vcl::Window * pParent, pData->sGroupTitle = SwResId(STR_MY_AUTOTEXT); else pData->sGroupTitle = sTitle; - pData->sPath = m_pPathLB->GetEntry(sGroup.getToken(1, GLOS_DELIM).toInt32()); - SvTreeListEntry* pEntry = m_pGroupTLB->InsertEntry(pData->sGroupTitle + "\t" + pData->sPath); - pEntry->SetUserData(pData); + pData->sPath = m_xPathLB->get_text(sGroup.getToken(1, GLOS_DELIM).toInt32()); + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pData))); + m_xGroupTLB->append(sId, pData->sGroupTitle); + int nEntry = m_xGroupTLB->find_id(sId); + m_xGroupTLB->set_text(nEntry, pData->sPath, 1); } - m_pGroupTLB->GetModel()->Resort(); + m_xGroupTLB->make_sorted(); } SwGlossaryGroupDlg::~SwGlossaryGroupDlg() { - disposeOnce(); + int nCount = m_xGroupTLB->n_children(); + for (int i = 0; i < nCount; ++i) + { + GlosBibUserData* pUserData = reinterpret_cast<GlosBibUserData*>(m_xGroupTLB->get_id(i).toInt64()); + delete pUserData; + } } -void SwGlossaryGroupDlg::dispose() +short SwGlossaryGroupDlg::run() { - m_pNameED.clear(); - m_pPathLB.clear(); - m_pGroupTLB.clear(); - m_pNewPB.clear(); - m_pDelPB.clear(); - m_pRenamePB.clear(); - SvxStandardDialog::dispose(); + short nRet = SfxDialogController::run(); + if (nRet == RET_OK) + Apply(); + return nRet; } void SwGlossaryGroupDlg::Apply() { - if(m_pNewPB->IsEnabled()) - NewHdl(m_pNewPB); + if (m_xNewPB->get_sensitive()) + NewHdl(*m_xNewPB); OUString aActGroup = SwGlossaryDlg::GetCurrGroup(); @@ -145,10 +151,9 @@ void SwGlossaryGroupDlg::Apply() if( sDelGroup == aActGroup ) { //when the current group is deleted, the current group has to be relocated - if(m_pGroupTLB->GetEntryCount()) + if (m_xGroupTLB->n_children()) { - SvTreeListEntry* pFirst = m_pGroupTLB->First(); - GlosBibUserData* pUserData = static_cast<GlosBibUserData*>(pFirst->GetUserData()); + GlosBibUserData* pUserData = reinterpret_cast<GlosBibUserData*>(m_xGroupTLB->get_id(0).toInt64()); pGlosHdl->SetCurGroup(pUserData->sGroupName); } } @@ -157,8 +162,7 @@ void SwGlossaryGroupDlg::Apply() + sTitle + SwResId(STR_QUERY_DELETE_GROUP2)); - vcl::Window* pWin = GetParent(); - std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pWin ? pWin->GetFrameWeld() : nullptr, + std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(m_pParent, VclMessageType::Question, VclButtonsType::YesNo, sMsg)); xQueryBox->set_default_response(RET_NO); if (RET_YES == xQueryBox->run()) @@ -189,57 +193,72 @@ void SwGlossaryGroupDlg::Apply() } } -IMPL_LINK_NOARG( SwGlossaryGroupDlg, SelectHdl, SvTreeListBox*, void ) +IMPL_LINK_NOARG( SwGlossaryGroupDlg, SelectHdl, weld::TreeView&, void ) { - m_pNewPB->Enable(false); - SvTreeListEntry* pFirstEntry = m_pGroupTLB->FirstSelected(); - if(pFirstEntry) + m_xNewPB->set_sensitive(false); + int nFirstEntry = m_xGroupTLB->get_selected_index(); + if (nFirstEntry != -1) { - GlosBibUserData* pUserData = static_cast<GlosBibUserData*>(pFirstEntry->GetUserData()); + GlosBibUserData* pUserData = reinterpret_cast<GlosBibUserData*>(m_xGroupTLB->get_id(nFirstEntry).toInt64()); OUString sEntry(pUserData->sGroupName); - OUString sName(m_pNameED->GetText()); + OUString sName(m_xNameED->get_text()); bool bExists = false; - sal_uLong nPos = m_pGroupTLB->GetEntryPos(sName, 0); - if( 0xffffffff > nPos) + int nPos = m_xGroupTLB->find_text(sName); + if (nPos != -1) { - SvTreeListEntry* pEntry = m_pGroupTLB->GetEntry(nPos); - GlosBibUserData* pFoundData = static_cast<GlosBibUserData*>(pEntry->GetUserData()); + GlosBibUserData* pFoundData = reinterpret_cast<GlosBibUserData*>(m_xGroupTLB->get_id(nPos).toInt64()); + fprintf(stderr, "comparing %s and %s\n", + OUStringToOString(pFoundData->sGroupName, RTL_TEXTENCODING_UTF8).getStr(), + OUStringToOString(sEntry, RTL_TEXTENCODING_UTF8).getStr()); bExists = pFoundData->sGroupName == sEntry; } - m_pRenamePB->Enable(!bExists && !sName.isEmpty()); - m_pDelPB->Enable(IsDeleteAllowed(sEntry)); + m_xRenamePB->set_sensitive(!bExists && !sName.isEmpty()); + fprintf(stderr, "one rename %d\n", !bExists && !sName.isEmpty()); + m_xDelPB->set_sensitive(IsDeleteAllowed(sEntry)); } } -IMPL_LINK_NOARG(SwGlossaryGroupDlg, NewHdl, Button*, void) +IMPL_LINK_NOARG(SwGlossaryGroupDlg, NewHdl, weld::Button&, void) { - OUString sGroup = m_pNameED->GetText() + OUString sGroup = m_xNameED->get_text() + OUStringLiteral1(GLOS_DELIM) - + OUString::number(m_pPathLB->GetSelectedEntryPos()); + + OUString::number(m_xPathLB->get_active()); OSL_ENSURE(!pGlosHdl->FindGroupName(sGroup), "group already available!"); m_InsertedArr.push_back(sGroup); - const OUString sTemp(m_pNameED->GetText() + "\t" + m_pPathLB->GetSelectedEntry()); - SvTreeListEntry* pEntry = m_pGroupTLB->InsertEntry(sTemp); GlosBibUserData* pData = new GlosBibUserData; - pData->sPath = m_pPathLB->GetSelectedEntry(); + pData->sPath = m_xPathLB->get_active_text(); pData->sGroupName = sGroup; - pData->sGroupTitle = m_pNameED->GetText(); - pEntry->SetUserData(pData); - m_pGroupTLB->Select(pEntry); - m_pGroupTLB->MakeVisible(pEntry); - m_pGroupTLB->GetModel()->Resort(); + pData->sGroupTitle = m_xNameED->get_text(); + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pData))); + m_xGroupTLB->append(sId, m_xNameED->get_text()); + int nEntry = m_xGroupTLB->find_id(sId); + m_xGroupTLB->set_text(nEntry, pData->sPath, 1); + m_xGroupTLB->select(nEntry); + SelectHdl(*m_xGroupTLB); + m_xGroupTLB->scroll_to_row(nEntry); } -IMPL_LINK( SwGlossaryGroupDlg, DeleteHdl, Button*, pButton, void ) +IMPL_LINK_NOARG(SwGlossaryGroupDlg, EntrySizeAllocHdl, const Size&, void) { - SvTreeListEntry* pEntry = m_pGroupTLB->FirstSelected(); - if(!pEntry) + std::vector<int> aWidths; + int x, y, width, height; + if (m_xPathLB->get_extents_relative_to(*m_xGroupTLB, x, y, width, height)) { - pButton->Enable(false); + aWidths.push_back(x); + m_xGroupTLB->set_column_fixed_widths(aWidths); + } +} + +IMPL_LINK( SwGlossaryGroupDlg, DeleteHdl, weld::Button&, rButton, void ) +{ + int nEntry = m_xGroupTLB->get_selected_index(); + if (nEntry == -1) + { + rButton.set_sensitive(false); return; } - GlosBibUserData* pUserData = static_cast<GlosBibUserData*>(pEntry->GetUserData()); + GlosBibUserData* pUserData = reinterpret_cast<GlosBibUserData*>(m_xGroupTLB->get_id(nEntry).toInt64()); OUString const sEntry(pUserData->sGroupName); // if the name to be deleted is among the new ones - get rid of it bool bDelete = true; @@ -265,23 +284,24 @@ IMPL_LINK( SwGlossaryGroupDlg, DeleteHdl, Button*, pButton, void ) m_RemovedArr.emplace_back(pUserData->sGroupName + "\t" + pUserData->sGroupTitle); } delete pUserData; - m_pGroupTLB->GetModel()->Remove(pEntry); - if(!m_pGroupTLB->First()) - pButton->Enable(false); + m_xGroupTLB->remove(nEntry); + if (!m_xGroupTLB->n_children()) + rButton.set_sensitive(false); //the content must be deleted - otherwise the new handler would be called in Apply() - m_pNameED->SetText(aEmptyOUStr); + m_xNameED->set_text(aEmptyOUStr); + ModifyHdl(*m_xNameED); } -IMPL_LINK_NOARG(SwGlossaryGroupDlg, RenameHdl, Button*, void) +IMPL_LINK_NOARG(SwGlossaryGroupDlg, RenameHdl, weld::Button&, void) { - SvTreeListEntry* pEntry = m_pGroupTLB->FirstSelected(); - GlosBibUserData* pUserData = static_cast<GlosBibUserData*>(pEntry->GetUserData()); + int nEntry = m_xGroupTLB->get_selected_index(); + GlosBibUserData* pUserData = reinterpret_cast<GlosBibUserData*>(m_xGroupTLB->get_id(nEntry).toInt64()); OUString sEntry(pUserData->sGroupName); - const OUString sNewTitle(m_pNameED->GetText()); + const OUString sNewTitle(m_xNameED->get_text()); OUString sNewName = sNewTitle + OUStringLiteral1(GLOS_DELIM) - + OUString::number(m_pPathLB->GetSelectedEntryPos()); + + OUString::number(m_xPathLB->get_active()); OSL_ENSURE(!pGlosHdl->FindGroupName(sNewName), "group already available!"); // if the name to be renamed is among the new ones - replace @@ -299,47 +319,49 @@ IMPL_LINK_NOARG(SwGlossaryGroupDlg, RenameHdl, Button*, void) + OUStringLiteral1(RENAME_TOKEN_DELIM) + sNewTitle; m_RenamedArr.push_back(sEntry); } - delete static_cast<GlosBibUserData*>(pEntry->GetUserData()); - m_pGroupTLB->GetModel()->Remove(pEntry); - pEntry = m_pGroupTLB->InsertEntry(m_pNameED->GetText() + "\t" - + m_pPathLB->GetSelectedEntry()); + delete pUserData; + m_xGroupTLB->remove(nEntry); + GlosBibUserData* pData = new GlosBibUserData; - pData->sPath = m_pPathLB->GetSelectedEntry(); + pData->sPath = m_xPathLB->get_active_text(); pData->sGroupName = sNewName; pData->sGroupTitle = sNewTitle; - pEntry->SetUserData(pData); - m_pGroupTLB->Select(pEntry); - m_pGroupTLB->MakeVisible(pEntry); - m_pGroupTLB->GetModel()->Resort(); + + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pData))); + m_xGroupTLB->append(sId, m_xNameED->get_text()); + nEntry = m_xGroupTLB->find_id(sId); + m_xGroupTLB->set_text(nEntry, m_xPathLB->get_active_text(), 1); + m_xGroupTLB->select(nEntry); + SelectHdl(*m_xGroupTLB); + m_xGroupTLB->scroll_to_row(nEntry); } -IMPL_LINK_NOARG(SwGlossaryGroupDlg, ModifyListBoxHdl, ListBox&, void) +IMPL_LINK_NOARG(SwGlossaryGroupDlg, ModifyListBoxHdl, weld::ComboBox&, void) { - ModifyHdl(*m_pNameED); + ModifyHdl(*m_xNameED); } -IMPL_LINK_NOARG(SwGlossaryGroupDlg, ModifyHdl, Edit&, void) + +IMPL_LINK_NOARG(SwGlossaryGroupDlg, ModifyHdl, weld::Entry&, void) { - OUString sEntry(m_pNameED->GetText()); + OUString sEntry(m_xNameED->get_text()); bool bEnableNew = true; bool bEnableDel = false; - sal_uLong nCaseReadonly = - reinterpret_cast<sal_uLong>(m_pPathLB->GetSelectedEntryData()); + sal_uInt32 nCaseReadonly = m_xPathLB->get_active_id().toUInt32(); bool bDirReadonly = 0 != (nCaseReadonly&PATH_READONLY); - if(sEntry.isEmpty() || bDirReadonly) + if (sEntry.isEmpty() || bDirReadonly) bEnableNew = false; else if(!sEntry.isEmpty()) { - sal_uLong nPos = m_pGroupTLB->GetEntryPos(sEntry, 0); + int nPos = m_xGroupTLB->find_text(sEntry); //if it's not case sensitive you have to search for yourself - if( 0xffffffff == nPos) + if (nPos == -1) { const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore(); - for(sal_uLong i = 0; i < m_pGroupTLB->GetEntryCount(); i++) + for (int i = 0, nEntryCount = m_xGroupTLB->n_children(); i < nEntryCount; ++i) { - OUString sTemp = m_pGroupTLB->GetEntryText( i, 0 ); - nCaseReadonly = reinterpret_cast<sal_uLong>(m_pPathLB->GetEntryData( - m_pPathLB->GetEntryPos(m_pGroupTLB->GetEntryText(i,1)))); + OUString sTemp = m_xGroupTLB->get_text(i, 0); + nCaseReadonly = m_xPathLB->get_id(m_xPathLB->find_text(m_xGroupTLB->get_text(i,1))).toUInt32(); bool bCase = 0 != (nCaseReadonly & PATH_CASE_SENSITIVE); if( !bCase && rSCmp.isEqual( sTemp, sEntry )) @@ -349,23 +371,25 @@ IMPL_LINK_NOARG(SwGlossaryGroupDlg, ModifyHdl, Edit&, void) } } } - if( 0xffffffff > nPos) + if (nPos != -1) { bEnableNew = false; - m_pGroupTLB->Select(m_pGroupTLB->GetEntry( nPos )); - m_pGroupTLB->MakeVisible(m_pGroupTLB->GetEntry( nPos )); + m_xGroupTLB->select(nPos); + m_xGroupTLB->scroll_to_row(nPos); + SelectHdl(*m_xGroupTLB); } } - SvTreeListEntry* pEntry = m_pGroupTLB->FirstSelected(); - if(pEntry) + int nEntry = m_xGroupTLB->get_selected_index(); + if (nEntry != -1) { - GlosBibUserData* pUserData = static_cast<GlosBibUserData*>(pEntry->GetUserData()); + GlosBibUserData* pUserData = reinterpret_cast<GlosBibUserData*>(m_xGroupTLB->get_id(nEntry).toInt64()); bEnableDel = IsDeleteAllowed(pUserData->sGroupName); } - m_pDelPB->Enable(bEnableDel); - m_pNewPB->Enable(bEnableNew); - m_pRenamePB->Enable(bEnableNew && pEntry); + m_xDelPB->set_sensitive(bEnableDel); + m_xNewPB->set_sensitive(bEnableNew); + m_xRenamePB->set_sensitive(bEnableNew && nEntry != -1); + fprintf(stderr, "two rename %d\n", bEnableNew && nEntry != -1); } bool SwGlossaryGroupDlg::IsDeleteAllowed(const OUString &rGroup) @@ -383,47 +407,10 @@ bool SwGlossaryGroupDlg::IsDeleteAllowed(const OUString &rGroup) return bDel; } -void FEdit::KeyInput( const KeyEvent& rKEvent ) -{ - vcl::KeyCode aCode = rKEvent.GetKeyCode(); - if( KEYGROUP_CURSOR == aCode.GetGroup() || - ( KEYGROUP_MISC == aCode.GetGroup() && - KEY_DELETE >= aCode.GetCode() ) || - SVT_SEARCHPATH_DELIMITER != rKEvent.GetCharCode() ) - Edit::KeyInput( rKEvent ); -} - -VCL_BUILDER_FACTORY(FEdit) - -void SwGlossaryGroupTLB::RequestHelp( const HelpEvent& rHEvt ) +IMPL_STATIC_LINK(SwGlossaryGroupDlg, EditInsertTextHdl, OUString&, rText, bool) { - Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() )); - SvTreeListEntry* pEntry = GetEntry( aPos ); - if(pEntry) - { - SvLBoxTab* pTab; - SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab ); - if(pItem) - { - aPos = GetEntryPosition( pEntry ); - Size aSize(pItem->GetSize( this, pEntry )); - aPos.setX( GetTabPos( pEntry, pTab ) ); - - if((aPos.X() + aSize.Width()) > GetSizePixel().Width()) - aSize.setWidth( GetSizePixel().Width() - aPos.X() ); - aPos = OutputToScreenPixel(aPos); - tools::Rectangle aItemRect( aPos, aSize ); - GlosBibUserData* pData = static_cast<GlosBibUserData*>(pEntry->GetUserData()); - const OUString sMsg = pData->sPath + "/" - + pData->sGroupName.getToken(0, GLOS_DELIM) - + SwGlossaries::GetExtension(); - - Help::ShowQuickHelp( this, aItemRect, sMsg, - QuickHelpFlags::Left|QuickHelpFlags::VCenter ); - } - } + rText = rText.replaceAll(OUStringLiteral1(SVT_SEARCHPATH_DELIMITER), ""); + return true; } -VCL_BUILDER_FACTORY(SwGlossaryGroupTLB) - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |